| 1 | // 04/01/00 : implantation de la persistance par classe deleguee - Guy Le Meur | 
|---|
| 2 |  | 
|---|
| 3 | #include "spherepos.h" | 
|---|
| 4 | #include "datatype.h" | 
|---|
| 5 | #include <typeinfo> | 
|---|
| 6 |  | 
|---|
| 7 | static char *head_spherepos_cc_ = "$Header: /Users/garnier/temp/CVSSophya/SophyaLib/SkyMap/spherepos.cc,v 1.2 2002-04-26 16:48:22 ansari Exp $"; | 
|---|
| 8 |  | 
|---|
| 9 |  | 
|---|
| 10 | //................. SphereCoordSys class ................. | 
|---|
| 11 |  | 
|---|
| 12 | SphereCoordSys::SphereCoordSys(){ | 
|---|
| 13 | id_ = SphereCoordSys_NEUTRAL; | 
|---|
| 14 | description_ = "NEUTRAL SphereCoordSystem"; | 
|---|
| 15 | } | 
|---|
| 16 | SphereCoordSys::SphereCoordSys(const SphereCoordSys& a ) | 
|---|
| 17 | { | 
|---|
| 18 | id_ = a.id_; | 
|---|
| 19 | description_ = a.description_; | 
|---|
| 20 | } | 
|---|
| 21 |  | 
|---|
| 22 | SphereCoordSys::SphereCoordSys(int id, const string& description){ | 
|---|
| 23 | id_ = id; | 
|---|
| 24 | description_ = description; | 
|---|
| 25 | } | 
|---|
| 26 |  | 
|---|
| 27 | SphereCoordSys::~SphereCoordSys() | 
|---|
| 28 | { | 
|---|
| 29 | } | 
|---|
| 30 | SphereCoordSys& SphereCoordSys::operator = (const SphereCoordSys& a) | 
|---|
| 31 | { | 
|---|
| 32 | id_ = a.id_; | 
|---|
| 33 | description_ = a.description_; | 
|---|
| 34 | return *this; | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 |  | 
|---|
| 38 | //////////////////////////////////////////////////////////////// | 
|---|
| 39 | // ------------------------------------------------------------------------- | 
|---|
| 40 | //   Les objets delegues pour la gestion de persistance | 
|---|
| 41 | // ------------------------------------------------------------------------- | 
|---|
| 42 |  | 
|---|
| 43 | FIO_SphereCoordSys::FIO_SphereCoordSys() | 
|---|
| 44 | { | 
|---|
| 45 | dobj=new SphereCoordSys; | 
|---|
| 46 | ownobj=true; | 
|---|
| 47 | } | 
|---|
| 48 | FIO_SphereCoordSys::FIO_SphereCoordSys(string const & filename) | 
|---|
| 49 | { | 
|---|
| 50 | dobj=new SphereCoordSys; | 
|---|
| 51 | ownobj=true; | 
|---|
| 52 | Read(filename); | 
|---|
| 53 | } | 
|---|
| 54 | FIO_SphereCoordSys::FIO_SphereCoordSys(const SphereCoordSys & obj) | 
|---|
| 55 | { | 
|---|
| 56 | dobj = new SphereCoordSys(obj); | 
|---|
| 57 | ownobj=true; | 
|---|
| 58 | } | 
|---|
| 59 | FIO_SphereCoordSys::FIO_SphereCoordSys(SphereCoordSys * obj) | 
|---|
| 60 | { | 
|---|
| 61 | dobj = obj; | 
|---|
| 62 | ownobj=false; | 
|---|
| 63 | } | 
|---|
| 64 | FIO_SphereCoordSys::~FIO_SphereCoordSys() | 
|---|
| 65 | { | 
|---|
| 66 | if (ownobj && dobj) delete dobj; | 
|---|
| 67 | } | 
|---|
| 68 | AnyDataObj* FIO_SphereCoordSys::DataObj() | 
|---|
| 69 | { | 
|---|
| 70 | return(dobj); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | void  FIO_SphereCoordSys::SetDataObj(AnyDataObj & o) | 
|---|
| 74 | { | 
|---|
| 75 | SphereCoordSys * po = dynamic_cast<SphereCoordSys *>(&o); | 
|---|
| 76 | if (po == NULL) { | 
|---|
| 77 | char buff[160]; | 
|---|
| 78 | sprintf(buff,"FIO_SphereCoordSys::SetDataObj(%s) - Object type  error ! ", | 
|---|
| 79 | typeid(o).name()); | 
|---|
| 80 | throw TypeMismatchExc(PExcLongMessage(buff)); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | if (ownobj && dobj) delete dobj; | 
|---|
| 84 | dobj = po; ownobj = false; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 |  | 
|---|
| 88 | void  FIO_SphereCoordSys::ReadSelf(PInPersist& is) | 
|---|
| 89 | { | 
|---|
| 90 | uint_8 itab[3]; | 
|---|
| 91 | string description; | 
|---|
| 92 | is.Get(itab, 3); | 
|---|
| 93 | is.GetStr(description); | 
|---|
| 94 | if (dobj == NULL) dobj = new SphereCoordSys(itab[1], description); | 
|---|
| 95 | else *dobj= SphereCoordSys(itab[1], description); | 
|---|
| 96 | } | 
|---|
| 97 | void       FIO_SphereCoordSys::WriteSelf(POutPersist& os) const | 
|---|
| 98 | { | 
|---|
| 99 | if (dobj == NULL)   return;  // Attention - $CHECK$ Guy 04/01/00 | 
|---|
| 100 | //  On ecrit 3 uint_8 | 
|---|
| 101 | //  0 : Numero de version,  1 : Id,  2  reserve a l | 
|---|
| 102 | uint_8 itab[3]; | 
|---|
| 103 | itab[0] = 1; | 
|---|
| 104 | itab[1] = dobj->Id(); | 
|---|
| 105 | itab[2] = 0; | 
|---|
| 106 | os.Put(itab, 3); | 
|---|
| 107 | os.PutStr(dobj->description()); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | //................. SpherePosition class ................. | 
|---|
| 113 |  | 
|---|
| 114 | SpherePosition::SpherePosition() | 
|---|
| 115 | : UnitVector() | 
|---|
| 116 | { | 
|---|
| 117 | cs_ = new SphereCoordSys; | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | SpherePosition::SpherePosition(double theta, double phi, SphereCoordSys* cs) | 
|---|
| 121 | : UnitVector(theta, phi) | 
|---|
| 122 | { | 
|---|
| 123 | if (cs == NULL) cs_ = new SphereCoordSys; | 
|---|
| 124 | else cs_ = cs; | 
|---|
| 125 | } | 
|---|
| 126 |  | 
|---|
| 127 | SpherePosition::SpherePosition(double x, double y, double z, SphereCoordSys* cs) | 
|---|
| 128 | : UnitVector(x, y, z) | 
|---|
| 129 | { | 
|---|
| 130 | if (cs == NULL) cs_ = new SphereCoordSys; | 
|---|
| 131 | else cs_ = cs; | 
|---|
| 132 | } | 
|---|
| 133 |  | 
|---|
| 134 | SpherePosition::~SpherePosition() | 
|---|
| 135 | { | 
|---|
| 136 | if (cs_) delete cs_; | 
|---|
| 137 | } | 
|---|
| 138 |  | 
|---|
| 139 | UnitVector SpherePosition::Transform(const SphereCoordSys& /*cs*/) const | 
|---|
| 140 | { | 
|---|
| 141 | return(*this); | 
|---|
| 142 | } | 
|---|
| 143 |  | 
|---|
| 144 | double SpherePosition::Separation(const SpherePosition& gamma) const | 
|---|
| 145 | { | 
|---|
| 146 | return(this->SepAngle(gamma)); | 
|---|
| 147 | } | 
|---|