]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IMeasureOperations_i.cc
Salome HOME
NPAL16559: EDF507: Implementation of a more advanced system of measurement.
[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
21 #include <Standard_Stream.hxx>
22
23 #include "GEOM_IMeasureOperations_i.hh"
24
25 #include "utilities.h"
26 #include "OpUtil.hxx"
27
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 //=============================================================================
32 /*!
33  *   constructor:
34  */
35 //=============================================================================
36 GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i (PortableServer::POA_ptr thePOA,
37                                                     GEOM::GEOM_Gen_ptr theEngine,
38                                                     ::GEOMImpl_IMeasureOperations* theImpl)
39 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
40 {
41   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
42 }
43
44 //=============================================================================
45 /*!
46  *  destructor
47  */
48 //=============================================================================
49 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
50 {
51   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
52 }
53
54 //=============================================================================
55 /*!
56  *  KindOfShape
57  */
58 //=============================================================================
59 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
60                                    (GEOM::GEOM_Object_ptr  theShape,
61                                     GEOM::ListOfLong_out   theIntegers,
62                                     GEOM::ListOfDouble_out theDoubles)
63 {
64   GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
65
66   // allocate the CORBA arrays
67   GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
68   GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
69
70   //Get the reference shape
71   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
72     (theShape->GetStudyID(), theShape->GetEntry());
73
74   if (!aShape.IsNull()) {
75     Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
76     Handle(TColStd_HSequenceOfReal)    aDoubles   = new TColStd_HSequenceOfReal;
77
78     // Detect kind of shape and parameters
79     aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
80
81     int nbInts = anIntegers->Length();
82     int nbDbls = aDoubles->Length();
83
84     anIntegersArray->length(nbInts);
85     aDoublesArray->length(nbDbls);
86
87     for (int ii = 0; ii < nbInts; ii++) {
88       anIntegersArray[ii] = anIntegers->Value(ii + 1);
89     }
90     for (int id = 0; id < nbDbls; id++) {
91       aDoublesArray[id] = aDoubles->Value(id + 1);
92     }
93   }
94
95   // initialize out-parameters with local arrays
96   theIntegers = anIntegersArray._retn();
97   theDoubles  = aDoublesArray._retn();
98   return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
99 }
100
101 //=============================================================================
102 /*!
103  *  GetPosition
104  */
105 //=============================================================================
106 void GEOM_IMeasureOperations_i::GetPosition
107                  (GEOM::GEOM_Object_ptr theShape,
108                   CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
109                   CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
110                   CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
111 {
112   //Set a not done flag
113   GetOperations()->SetNotDone();
114
115   //Set default values: global CS
116   Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
117   Zz = Xx = 1.;
118
119   if (theShape == NULL) return;
120
121   //Get the reference shape
122   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
123     (theShape->GetStudyID(), theShape->GetEntry());
124
125   if (aShape.IsNull()) return;
126
127   // Get shape parameters
128   GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
129 }
130
131 //=============================================================================
132 /*!
133  *  GetCentreOfMass
134  */
135 //=============================================================================
136 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
137                                               (GEOM::GEOM_Object_ptr theShape)
138 {
139   GEOM::GEOM_Object_var aGEOMObject;
140
141   //Set a not done flag
142   GetOperations()->SetNotDone();
143
144   if (theShape == NULL) return aGEOMObject._retn();
145
146   //Get the reference shape
147   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
148     (theShape->GetStudyID(), theShape->GetEntry());
149
150   if (aShape.IsNull()) return aGEOMObject._retn();
151
152   // Make Point - centre of mass of theShape
153   Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
154   if (!GetOperations()->IsDone() || anObject.IsNull())
155     return aGEOMObject._retn();
156
157   return GetObject(anObject);
158 }
159
160 //=============================================================================
161 /*!
162  *  GetBasicProperties
163  */
164 //=============================================================================
165 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
166                                                     CORBA::Double& theLength,
167                                                     CORBA::Double& theSurfArea,
168                                                     CORBA::Double& theVolume)
169 {
170   //Set a not done flag
171   GetOperations()->SetNotDone();
172
173   if (theShape == NULL) return;
174
175   //Get the reference shape
176   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
177     (theShape->GetStudyID(), theShape->GetEntry());
178
179   if (aShape.IsNull()) return;
180
181   // Get shape parameters
182   GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
183 }
184
185 //=============================================================================
186 /*!
187  *  GetInertia
188  */
189 //=============================================================================
190 void GEOM_IMeasureOperations_i::GetInertia
191   (GEOM::GEOM_Object_ptr theShape,
192    CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
193    CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
194    CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
195    CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
196 {
197   //Set a not done flag
198   GetOperations()->SetNotDone();
199
200   if (theShape == NULL) return;
201
202   //Get the reference shape
203   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
204     (theShape->GetStudyID(), theShape->GetEntry());
205
206   if (aShape.IsNull()) return;
207
208   // Get shape parameters
209   GetOperations()->GetInertia(aShape,
210                               I11, I12, I13,
211                               I21, I22, I23,
212                               I31, I32, I33,
213                               Ix , Iy , Iz);
214 }
215
216 //=============================================================================
217 /*!
218  *  GetBoundingBox
219  */
220 //=============================================================================
221 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
222                                                 CORBA::Double& Xmin, CORBA::Double& Xmax,
223                                                 CORBA::Double& Ymin, CORBA::Double& Ymax,
224                                                 CORBA::Double& Zmin, CORBA::Double& Zmax)
225 {
226   //Set a not done flag
227   GetOperations()->SetNotDone();
228
229   if (theShape == NULL) return;
230
231   //Get the reference shape
232   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
233     (theShape->GetStudyID(), theShape->GetEntry());
234
235   if (aShape.IsNull()) return;
236
237   // Get shape parameters
238   GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
239 }
240
241 //=============================================================================
242 /*!
243  *  GetTolerance
244  */
245 //=============================================================================
246 void GEOM_IMeasureOperations_i::GetTolerance
247                                 (GEOM::GEOM_Object_ptr theShape,
248                                  CORBA::Double& FaceMin, CORBA::Double& FaceMax,
249                                  CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
250                                  CORBA::Double& VertMin, CORBA::Double& VertMax)
251 {
252   //Set a not done flag
253   GetOperations()->SetNotDone();
254
255   if (theShape == NULL) return;
256
257   //Get the reference shape
258   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
259     (theShape->GetStudyID(), theShape->GetEntry());
260
261   if (aShape.IsNull()) return;
262
263   // Get shape parameters
264   GetOperations()->GetTolerance(aShape,
265                                 FaceMin, FaceMax,
266                                 EdgeMin, EdgeMax,
267                                 VertMin, VertMax);
268 }
269
270 //=============================================================================
271 /*!
272  *  CheckShape
273  */
274 //=============================================================================
275 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
276                                                       CORBA::String_out     theDescription)
277 {
278   //Set a not done flag
279   GetOperations()->SetNotDone();
280
281   if (theShape == NULL)
282   {
283     theDescription = CORBA::string_dup("null");
284     return 0;
285   }
286
287   //Get the reference shape
288   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
289     (theShape->GetStudyID(), theShape->GetEntry());
290
291   if (aShape.IsNull())
292   {
293     theDescription = CORBA::string_dup("null2");
294     return 0;
295   }
296
297   // Get shape parameters
298   TCollection_AsciiString aDump;
299   if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
300   {
301     theDescription = CORBA::string_dup("OK");
302     return 1;
303   }
304   theDescription = CORBA::string_dup(aDump.ToCString());
305   return 0;
306 }
307
308 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
309                                                                   CORBA::String_out     theDescription)
310 {
311   //Set a not done flag
312   GetOperations()->SetNotDone();
313
314   if (theShape == NULL)
315   {
316     theDescription = CORBA::string_dup("null");
317     return 0;
318   }
319
320   //Get the reference shape
321   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
322     (theShape->GetStudyID(), theShape->GetEntry());
323
324   if (aShape.IsNull())
325   {
326     theDescription = CORBA::string_dup("null2");
327     return 0;
328   }
329
330   // Get shape parameters
331   TCollection_AsciiString aDump;
332   if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
333   {
334     theDescription = CORBA::string_dup("OK");
335     return 1;
336   }
337   theDescription = CORBA::string_dup(aDump.ToCString());
338   return 0;
339 }
340
341 //=============================================================================
342 /*!
343  *  WhatIs
344  */
345 //=============================================================================
346 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
347 {
348   //Set a not done flag
349   GetOperations()->SetNotDone();
350
351   if (theShape == NULL) return NULL;
352
353   //Get the reference shape
354   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
355     (theShape->GetStudyID(), theShape->GetEntry());
356
357   if (aShape.IsNull()) return NULL;
358
359   // Get shape parameters
360   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
361   return CORBA::string_dup(aDescription.ToCString());
362 }
363
364 //=============================================================================
365 /*!
366  *  GetMinDistance
367  */
368 //=============================================================================
369 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
370   (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
371    CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
372    CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
373 {
374   //Set a not done flag
375   GetOperations()->SetNotDone();
376
377   if (theShape1 == NULL || theShape2 == NULL) return -1.0;
378
379   //Get the reference shape
380   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
381     (theShape1->GetStudyID(), theShape1->GetEntry());
382   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
383     (theShape2->GetStudyID(), theShape2->GetEntry());
384
385   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
386
387   // Get shape parameters
388   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
389 }
390
391 //=============================================================================
392 /*!
393  *  PointCoordinates
394  */
395 //=============================================================================
396 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
397                                                   CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
398
399 {
400   //Set a not done flag
401   GetOperations()->SetNotDone();
402
403   if ( theShape->_is_nil() )
404     return;
405
406   //Get the reference shape
407   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
408     theShape->GetStudyID(), theShape->GetEntry() );
409
410   if ( aShape.IsNull() )
411     return;
412
413   // Get shape parameters
414   GetOperations()->PointCoordinates( aShape, X, Y, Z );
415 }
416
417 //=============================================================================
418 /*!
419  *  GetAngle
420  */
421 //=============================================================================
422 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
423                                                    GEOM::GEOM_Object_ptr theShape2)
424 {
425   //Set a not done flag
426   GetOperations()->SetNotDone();
427
428   if (theShape1 == NULL || theShape2 == NULL) return -1.0;
429
430   //Get the reference shapes
431   Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
432     (theShape1->GetStudyID(), theShape1->GetEntry());
433   Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
434     (theShape2->GetStudyID(), theShape2->GetEntry());
435
436   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
437
438   // Get the angle
439   return GetOperations()->GetAngle(aShape1, aShape2);
440 }