source: Sophya/trunk/SophyaLib/SkyMap/spherepos.cc@ 2808

Last change on this file since 2808 was 2615, checked in by cmv, 21 years ago

using namespace sophya enleve de machdefs.h, nouveau sopnamsp.h cmv 10/09/2004

File size: 3.4 KB
RevLine 
[764]1// 04/01/00 : implantation de la persistance par classe deleguee - Guy Le Meur
2
[2615]3#include "sopnamsp.h"
[764]4#include "spherepos.h"
[1967]5#include "datatype.h"
6#include <typeinfo>
[764]7
[2615]8static char *head_spherepos_cc_ = "$Header: /Users/garnier/temp/CVSSophya/SophyaLib/SkyMap/spherepos.cc,v 1.3 2004-09-10 09:54:31 cmv Exp $";
[764]9
10
11//................. SphereCoordSys class .................
12
13SphereCoordSys::SphereCoordSys(){
14 id_ = SphereCoordSys_NEUTRAL;
15 description_ = "NEUTRAL SphereCoordSystem";
16}
17SphereCoordSys::SphereCoordSys(const SphereCoordSys& a )
18{
19 id_ = a.id_;
20 description_ = a.description_;
21}
22
23SphereCoordSys::SphereCoordSys(int id, const string& description){
24 id_ = id;
25 description_ = description;
26}
27
28SphereCoordSys::~SphereCoordSys()
29{
30}
31SphereCoordSys& 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
44FIO_SphereCoordSys::FIO_SphereCoordSys()
45 {
46 dobj=new SphereCoordSys;
47 ownobj=true;
48 }
49FIO_SphereCoordSys::FIO_SphereCoordSys(string const & filename)
50 {
51 dobj=new SphereCoordSys;
52 ownobj=true;
53 Read(filename);
54 }
55FIO_SphereCoordSys::FIO_SphereCoordSys(const SphereCoordSys & obj)
56 {
57 dobj = new SphereCoordSys(obj);
58 ownobj=true;
59 }
60FIO_SphereCoordSys::FIO_SphereCoordSys(SphereCoordSys * obj)
61 {
62 dobj = obj;
63 ownobj=false;
64 }
65FIO_SphereCoordSys::~FIO_SphereCoordSys()
66 {
67 if (ownobj && dobj) delete dobj;
68 }
69AnyDataObj* FIO_SphereCoordSys::DataObj()
70 {
71 return(dobj);
72 }
73
74void FIO_SphereCoordSys::SetDataObj(AnyDataObj & o)
75{
76 SphereCoordSys * po = dynamic_cast<SphereCoordSys *>(&o);
[1967]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
[764]84 if (ownobj && dobj) delete dobj;
85 dobj = po; ownobj = false;
86}
87
88
89void FIO_SphereCoordSys::ReadSelf(PInPersist& is)
90 {
91uint_8 itab[3];
92 string description;
93is.Get(itab, 3);
94is.GetStr(description);
95if (dobj == NULL) dobj = new SphereCoordSys(itab[1], description);
96 else *dobj= SphereCoordSys(itab[1], description);
97 }
98void FIO_SphereCoordSys::WriteSelf(POutPersist& os) const
99{
100if (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
103uint_8 itab[3];
104itab[0] = 1;
105itab[1] = dobj->Id();
106itab[2] = 0;
107os.Put(itab, 3);
108os.PutStr(dobj->description());
109}
110
111
112
113//................. SpherePosition class .................
114
115SpherePosition::SpherePosition()
116 : UnitVector()
117{
118 cs_ = new SphereCoordSys;
119}
120
121SpherePosition::SpherePosition(double theta, double phi, SphereCoordSys* cs)
122 : UnitVector(theta, phi)
123{
124if (cs == NULL) cs_ = new SphereCoordSys;
125else cs_ = cs;
126}
127
128SpherePosition::SpherePosition(double x, double y, double z, SphereCoordSys* cs)
129 : UnitVector(x, y, z)
130{
131if (cs == NULL) cs_ = new SphereCoordSys;
132else cs_ = cs;
133}
134
135SpherePosition::~SpherePosition()
136{
137if (cs_) delete cs_;
138}
139
140UnitVector SpherePosition::Transform(const SphereCoordSys& /*cs*/) const
141{
142return(*this);
143}
144
145double SpherePosition::Separation(const SpherePosition& gamma) const
146{
147return(this->SepAngle(gamma));
148}
Note: See TracBrowser for help on using the repository browser.