Salome HOME
a76cf177ea7b2d0c2da16abb4aa5d428a5a9b59f
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 #include <Standard_Stream.hxx>
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) 
186   {
187     theDescription = CORBA::string_dup("null");
188     return 0;
189   }
190
191   //Get the reference shape
192   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
193     (theShape->GetStudyID(), theShape->GetEntry());
194
195   if (aShape.IsNull())
196   {
197     theDescription = CORBA::string_dup("null2");
198     return 0;
199   }
200
201   // Get shape parameters
202   TCollection_AsciiString aDump;
203   if (GetOperations()->CheckShape(aShape, aDump))
204   {
205     theDescription = CORBA::string_dup("OK");
206     return 1;
207   }
208   theDescription = CORBA::string_dup(aDump.ToCString());
209   return 0;
210 }
211
212 //=============================================================================
213 /*!
214  *  WhatIs
215  */
216 //=============================================================================
217 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
218 {
219   //Set a not done flag
220   GetOperations()->SetNotDone();
221
222   if (theShape == NULL) return NULL;
223
224   //Get the reference shape
225   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
226     (theShape->GetStudyID(), theShape->GetEntry());
227
228   if (aShape.IsNull()) return NULL;
229
230   // Get shape parameters
231   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
232   return strdup(aDescription.ToCString());
233 }
234
235 //=============================================================================
236 /*!
237  *  GetMinDistance
238  */
239 //=============================================================================
240 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
241   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
242    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
243    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
244 {
245   //Set a not done flag
246   GetOperations()->SetNotDone();
247
248   if (theShape1 == NULL || theShape2 == NULL) return -1.0;
249
250   //Get the reference shape
251   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
252     (theShape1->GetStudyID(), theShape1->GetEntry());
253   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
254     (theShape2->GetStudyID(), theShape2->GetEntry());
255
256   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
257
258   // Get shape parameters
259   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
260 }
261
262 //=============================================================================
263 /*!
264  *  PointCoordinates
265  */
266 //=============================================================================
267 void GEOM_IMeasureOperations_i::PointCoordinates(
268   GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
269
270 {
271   //Set a not done flag
272   GetOperations()->SetNotDone();
273
274   if ( theShape->_is_nil() )
275     return;
276
277   //Get the reference shape
278   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
279     theShape->GetStudyID(), theShape->GetEntry() );
280
281   if ( aShape.IsNull() )
282     return;
283
284   // Get shape parameters
285   GetOperations()->PointCoordinates( aShape, X, Y, Z );
286 }