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