Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 using namespace std;
2
3 #include "GEOM_IMeasureOperations_i.hh"
4
5 #include "utilities.h"
6 #include "OpUtil.hxx"
7
8 #include "GEOM_Engine.hxx"
9 #include "GEOM_Object.hxx"
10
11 //=============================================================================
12 /*!
13  *   constructor:
14  */
15 //=============================================================================
16 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
17                                                     GEOM::GEOM_Gen_ptr theEngine,
18                                                     ::GEOMImpl_IMeasureOperations* theImpl)
19 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
20 {
21   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
22 }
23
24 //=============================================================================
25 /*!
26  *  destructor
27  */
28 //=============================================================================
29 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
30 {
31   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
32 }
33
34
35 //=============================================================================
36 /*!
37  *  GetCentreOfMass
38  */
39 //=============================================================================
40 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
41                                               (GEOM::GEOM_Object_ptr theShape)
42 {
43   GEOM::GEOM_Object_var aGEOMObject;
44
45   //Set a not done flag
46   GetOperations()->SetNotDone();
47
48   if (theShape == NULL) return aGEOMObject._retn();
49
50   //Get the reference shape
51   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
52     (theShape->GetStudyID(), theShape->GetEntry());
53
54   if (aShape.IsNull()) return aGEOMObject._retn();
55
56   // Make Point - centre of mass of theShape
57   Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
58   if (!GetOperations()->IsDone() || anObject.IsNull())
59     return aGEOMObject._retn();
60
61   return GetObject(anObject);
62 }
63
64 //=============================================================================
65 /*!
66  *  GetBasicProperties
67  */
68 //=============================================================================
69 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
70                                                     CORBA::Double& theLength,
71                                                     CORBA::Double& theSurfArea,
72                                                     CORBA::Double& theVolume)
73 {
74   //Set a not done flag
75   GetOperations()->SetNotDone();
76
77   if (theShape == NULL) return;
78
79   //Get the reference shape
80   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
81     (theShape->GetStudyID(), theShape->GetEntry());
82
83   if (aShape.IsNull()) return;
84
85   // Get shape parameters
86   GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
87 }
88
89 //=============================================================================
90 /*!
91  *  GetInertia
92  */
93 //=============================================================================
94 void GEOM_IMeasureOperations_i::GetInertia
95   (GEOM::GEOM_Object_ptr theShape,
96    CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
97    CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
98    CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
99    CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
100 {
101   //Set a not done flag
102   GetOperations()->SetNotDone();
103
104   if (theShape == NULL) return;
105
106   //Get the reference shape
107   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
108     (theShape->GetStudyID(), theShape->GetEntry());
109
110   if (aShape.IsNull()) return;
111
112   // Get shape parameters
113   GetOperations()->GetInertia(aShape,
114                               I11, I12, I13,
115                               I21, I22, I23,
116                               I31, I32, I33,
117                               Ix , Iy , Iz);
118 }
119
120 //=============================================================================
121 /*!
122  *  GetBoundingBox
123  */
124 //=============================================================================
125 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
126                                                 CORBA::Double& Xmin, CORBA::Double& Xmax,
127                                                 CORBA::Double& Ymin, CORBA::Double& Ymax,
128                                                 CORBA::Double& Zmin, CORBA::Double& Zmax)
129 {
130   //Set a not done flag
131   GetOperations()->SetNotDone();
132
133   if (theShape == NULL) return;
134
135   //Get the reference shape
136   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
137     (theShape->GetStudyID(), theShape->GetEntry());
138
139   if (aShape.IsNull()) return;
140
141   // Get shape parameters
142   GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
143 }
144
145 //=============================================================================
146 /*!
147  *  GetTolerance
148  */
149 //=============================================================================
150 void GEOM_IMeasureOperations_i::GetTolerance
151                                 (GEOM::GEOM_Object_ptr theShape,
152                                  CORBA::Double& FaceMin, CORBA::Double& FaceMax,
153                                  CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
154                                  CORBA::Double& VertMin, CORBA::Double& VertMax)
155 {
156   //Set a not done flag
157   GetOperations()->SetNotDone();
158
159   if (theShape == NULL) return;
160
161   //Get the reference shape
162   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
163     (theShape->GetStudyID(), theShape->GetEntry());
164
165   if (aShape.IsNull()) return;
166
167   // Get shape parameters
168   GetOperations()->GetTolerance(aShape,
169                                 FaceMin, FaceMax,
170                                 EdgeMin, EdgeMax,
171                                 VertMin, VertMax);
172 }
173
174 //=============================================================================
175 /*!
176  *  CheckShape
177  */
178 //=============================================================================
179 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
180                                                       CORBA::String_out     theDescription)
181 {
182   //Set a not done flag
183   GetOperations()->SetNotDone();
184
185   if (theShape == NULL) return 0;
186
187   //Get the reference shape
188   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
189     (theShape->GetStudyID(), theShape->GetEntry());
190
191   if (aShape.IsNull()) return 0;
192
193   // Get shape parameters
194   TCollection_AsciiString aDump;
195   if (GetOperations()->CheckShape(aShape, aDump)) return 1;
196
197   theDescription = CORBA::string_dup(aDump.ToCString());
198   return 0;
199 }
200
201 //=============================================================================
202 /*!
203  *  WhatIs
204  */
205 //=============================================================================
206 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
207 {
208   //Set a not done flag
209   GetOperations()->SetNotDone();
210
211   if (theShape == NULL) return NULL;
212
213   //Get the reference shape
214   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
215     (theShape->GetStudyID(), theShape->GetEntry());
216
217   if (aShape.IsNull()) return NULL;
218
219   // Get shape parameters
220   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
221   return strdup(aDescription.ToCString());
222 }
223
224 //=============================================================================
225 /*!
226  *  GetMinDistance
227  */
228 //=============================================================================
229 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
230   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
231    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
232    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
233 {
234   //Set a not done flag
235   GetOperations()->SetNotDone();
236
237   if (theShape1 == NULL || theShape2 == NULL) return -1.0;
238
239   //Get the reference shape
240   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
241     (theShape1->GetStudyID(), theShape1->GetEntry());
242   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
243     (theShape2->GetStudyID(), theShape2->GetEntry());
244
245   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
246
247   // Get shape parameters
248   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
249 }
250
251 //=============================================================================
252 /*!
253  *  PointCoordinates
254  */
255 //=============================================================================
256 void GEOM_IMeasureOperations_i::PointCoordinates(
257   GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
258
259 {
260   //Set a not done flag
261   GetOperations()->SetNotDone();
262
263   if ( theShape->_is_nil() )
264     return;
265
266   //Get the reference shape
267   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
268     theShape->GetStudyID(), theShape->GetEntry() );
269
270   if ( aShape.IsNull() )
271     return;
272
273   // Get shape parameters
274   GetOperations()->PointCoordinates( aShape, X, Y, Z );
275 }