Salome HOME
PAL12781: EDF: different result between Working Plane and LCS. Implement and use...
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 //
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
8 //
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IMeasureOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
29
30 //=============================================================================
31 /*!
32  *   constructor:
33  */
34 //=============================================================================
35 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
36                                                     GEOM::GEOM_Gen_ptr theEngine,
37                                                     ::GEOMImpl_IMeasureOperations* theImpl)
38 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
39 {
40   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
41 }
42
43 //=============================================================================
44 /*!
45  *  destructor
46  */
47 //=============================================================================
48 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
49 {
50   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
51 }
52
53
54 //=============================================================================
55 /*!
56  *  GetPosition
57  */
58 //=============================================================================
59 void GEOM_IMeasureOperations_i::GetPosition
60                  (GEOM::GEOM_Object_ptr theShape,
61                   CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
62                   CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
63                   CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
64 {
65   //Set a not done flag
66   GetOperations()->SetNotDone();
67
68   //Set default values: global CS
69   Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
70   Zz = Xx = 1.;
71
72   if (theShape == NULL) return;
73
74   //Get the reference shape
75   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
76     (theShape->GetStudyID(), theShape->GetEntry());
77
78   if (aShape.IsNull()) return;
79
80   // Get shape parameters
81   GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
82 }
83
84 //=============================================================================
85 /*!
86  *  GetCentreOfMass
87  */
88 //=============================================================================
89 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
90                                               (GEOM::GEOM_Object_ptr theShape)
91 {
92   GEOM::GEOM_Object_var aGEOMObject;
93
94   //Set a not done flag
95   GetOperations()->SetNotDone();
96
97   if (theShape == NULL) return aGEOMObject._retn();
98
99   //Get the reference shape
100   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
101     (theShape->GetStudyID(), theShape->GetEntry());
102
103   if (aShape.IsNull()) return aGEOMObject._retn();
104
105   // Make Point - centre of mass of theShape
106   Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
107   if (!GetOperations()->IsDone() || anObject.IsNull())
108     return aGEOMObject._retn();
109
110   return GetObject(anObject);
111 }
112
113 //=============================================================================
114 /*!
115  *  GetBasicProperties
116  */
117 //=============================================================================
118 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
119                                                     CORBA::Double& theLength,
120                                                     CORBA::Double& theSurfArea,
121                                                     CORBA::Double& theVolume)
122 {
123   //Set a not done flag
124   GetOperations()->SetNotDone();
125
126   if (theShape == NULL) return;
127
128   //Get the reference shape
129   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
130     (theShape->GetStudyID(), theShape->GetEntry());
131
132   if (aShape.IsNull()) return;
133
134   // Get shape parameters
135   GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
136 }
137
138 //=============================================================================
139 /*!
140  *  GetInertia
141  */
142 //=============================================================================
143 void GEOM_IMeasureOperations_i::GetInertia
144   (GEOM::GEOM_Object_ptr theShape,
145    CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
146    CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
147    CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
148    CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
149 {
150   //Set a not done flag
151   GetOperations()->SetNotDone();
152
153   if (theShape == NULL) return;
154
155   //Get the reference shape
156   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
157     (theShape->GetStudyID(), theShape->GetEntry());
158
159   if (aShape.IsNull()) return;
160
161   // Get shape parameters
162   GetOperations()->GetInertia(aShape,
163                               I11, I12, I13,
164                               I21, I22, I23,
165                               I31, I32, I33,
166                               Ix , Iy , Iz);
167 }
168
169 //=============================================================================
170 /*!
171  *  GetBoundingBox
172  */
173 //=============================================================================
174 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
175                                                 CORBA::Double& Xmin, CORBA::Double& Xmax,
176                                                 CORBA::Double& Ymin, CORBA::Double& Ymax,
177                                                 CORBA::Double& Zmin, CORBA::Double& Zmax)
178 {
179   //Set a not done flag
180   GetOperations()->SetNotDone();
181
182   if (theShape == NULL) return;
183
184   //Get the reference shape
185   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
186     (theShape->GetStudyID(), theShape->GetEntry());
187
188   if (aShape.IsNull()) return;
189
190   // Get shape parameters
191   GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
192 }
193
194 //=============================================================================
195 /*!
196  *  GetTolerance
197  */
198 //=============================================================================
199 void GEOM_IMeasureOperations_i::GetTolerance
200                                 (GEOM::GEOM_Object_ptr theShape,
201                                  CORBA::Double& FaceMin, CORBA::Double& FaceMax,
202                                  CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
203                                  CORBA::Double& VertMin, CORBA::Double& VertMax)
204 {
205   //Set a not done flag
206   GetOperations()->SetNotDone();
207
208   if (theShape == NULL) return;
209
210   //Get the reference shape
211   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
212     (theShape->GetStudyID(), theShape->GetEntry());
213
214   if (aShape.IsNull()) return;
215
216   // Get shape parameters
217   GetOperations()->GetTolerance(aShape,
218                                 FaceMin, FaceMax,
219                                 EdgeMin, EdgeMax,
220                                 VertMin, VertMax);
221 }
222
223 //=============================================================================
224 /*!
225  *  CheckShape
226  */
227 //=============================================================================
228 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
229                                                       CORBA::String_out     theDescription)
230 {
231   //Set a not done flag
232   GetOperations()->SetNotDone();
233
234   if (theShape == NULL)
235   {
236     theDescription = CORBA::string_dup("null");
237     return 0;
238   }
239
240   //Get the reference shape
241   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
242     (theShape->GetStudyID(), theShape->GetEntry());
243
244   if (aShape.IsNull())
245   {
246     theDescription = CORBA::string_dup("null2");
247     return 0;
248   }
249
250   // Get shape parameters
251   TCollection_AsciiString aDump;
252   if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
253   {
254     theDescription = CORBA::string_dup("OK");
255     return 1;
256   }
257   theDescription = CORBA::string_dup(aDump.ToCString());
258   return 0;
259 }
260
261 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
262                                                                   CORBA::String_out     theDescription)
263 {
264   //Set a not done flag
265   GetOperations()->SetNotDone();
266
267   if (theShape == NULL)
268   {
269     theDescription = CORBA::string_dup("null");
270     return 0;
271   }
272
273   //Get the reference shape
274   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
275     (theShape->GetStudyID(), theShape->GetEntry());
276
277   if (aShape.IsNull())
278   {
279     theDescription = CORBA::string_dup("null2");
280     return 0;
281   }
282
283   // Get shape parameters
284   TCollection_AsciiString aDump;
285   if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
286   {
287     theDescription = CORBA::string_dup("OK");
288     return 1;
289   }
290   theDescription = CORBA::string_dup(aDump.ToCString());
291   return 0;
292 }
293
294 //=============================================================================
295 /*!
296  *  WhatIs
297  */
298 //=============================================================================
299 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
300 {
301   //Set a not done flag
302   GetOperations()->SetNotDone();
303
304   if (theShape == NULL) return NULL;
305
306   //Get the reference shape
307   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
308     (theShape->GetStudyID(), theShape->GetEntry());
309
310   if (aShape.IsNull()) return NULL;
311
312   // Get shape parameters
313   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
314   return CORBA::string_dup(aDescription.ToCString());
315 }
316
317 //=============================================================================
318 /*!
319  *  GetMinDistance
320  */
321 //=============================================================================
322 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
323   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
324    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
325    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
326 {
327   //Set a not done flag
328   GetOperations()->SetNotDone();
329
330   if (theShape1 == NULL || theShape2 == NULL) return -1.0;
331
332   //Get the reference shape
333   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
334     (theShape1->GetStudyID(), theShape1->GetEntry());
335   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
336     (theShape2->GetStudyID(), theShape2->GetEntry());
337
338   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
339
340   // Get shape parameters
341   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
342 }
343
344 //=============================================================================
345 /*!
346  *  PointCoordinates
347  */
348 //=============================================================================
349 void GEOM_IMeasureOperations_i::PointCoordinates(
350   GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
351
352 {
353   //Set a not done flag
354   GetOperations()->SetNotDone();
355
356   if ( theShape->_is_nil() )
357     return;
358
359   //Get the reference shape
360   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
361     theShape->GetStudyID(), theShape->GetEntry() );
362
363   if ( aShape.IsNull() )
364     return;
365
366   // Get shape parameters
367   GetOperations()->PointCoordinates( aShape, X, Y, Z );
368 }