1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include "GEOM_IMeasureOperations_i.hh"
25 #include "utilities.h"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 //=============================================================================
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)
41 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
44 //=============================================================================
48 //=============================================================================
49 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
51 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
54 //=============================================================================
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)
64 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
66 // allocate the CORBA arrays
67 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
68 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
70 //Get the reference shape
71 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
72 (theShape->GetStudyID(), theShape->GetEntry());
74 if (!aShape.IsNull()) {
75 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
76 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
78 // Detect kind of shape and parameters
79 aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
81 int nbInts = anIntegers->Length();
82 int nbDbls = aDoubles->Length();
84 anIntegersArray->length(nbInts);
85 aDoublesArray->length(nbDbls);
87 for (int ii = 0; ii < nbInts; ii++) {
88 anIntegersArray[ii] = anIntegers->Value(ii + 1);
90 for (int id = 0; id < nbDbls; id++) {
91 aDoublesArray[id] = aDoubles->Value(id + 1);
95 // initialize out-parameters with local arrays
96 theIntegers = anIntegersArray._retn();
97 theDoubles = aDoublesArray._retn();
98 return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
101 //=============================================================================
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)
112 //Set a not done flag
113 GetOperations()->SetNotDone();
115 //Set default values: global CS
116 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
119 if (theShape == NULL) return;
121 //Get the reference shape
122 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
123 (theShape->GetStudyID(), theShape->GetEntry());
125 if (aShape.IsNull()) return;
127 // Get shape parameters
128 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
131 //=============================================================================
135 //=============================================================================
136 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
137 (GEOM::GEOM_Object_ptr theShape)
139 GEOM::GEOM_Object_var aGEOMObject;
141 //Set a not done flag
142 GetOperations()->SetNotDone();
144 if (theShape == NULL) return aGEOMObject._retn();
146 //Get the reference shape
147 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
148 (theShape->GetStudyID(), theShape->GetEntry());
150 if (aShape.IsNull()) return aGEOMObject._retn();
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();
157 return GetObject(anObject);
160 //=============================================================================
164 //=============================================================================
165 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
166 CORBA::Double& theLength,
167 CORBA::Double& theSurfArea,
168 CORBA::Double& theVolume)
170 //Set a not done flag
171 GetOperations()->SetNotDone();
173 if (theShape == NULL) return;
175 //Get the reference shape
176 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
177 (theShape->GetStudyID(), theShape->GetEntry());
179 if (aShape.IsNull()) return;
181 // Get shape parameters
182 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
185 //=============================================================================
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)
197 //Set a not done flag
198 GetOperations()->SetNotDone();
200 if (theShape == NULL) return;
202 //Get the reference shape
203 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
204 (theShape->GetStudyID(), theShape->GetEntry());
206 if (aShape.IsNull()) return;
208 // Get shape parameters
209 GetOperations()->GetInertia(aShape,
216 //=============================================================================
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)
226 //Set a not done flag
227 GetOperations()->SetNotDone();
229 if (theShape == NULL) return;
231 //Get the reference shape
232 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
233 (theShape->GetStudyID(), theShape->GetEntry());
235 if (aShape.IsNull()) return;
237 // Get shape parameters
238 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
241 //=============================================================================
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)
252 //Set a not done flag
253 GetOperations()->SetNotDone();
255 if (theShape == NULL) return;
257 //Get the reference shape
258 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
259 (theShape->GetStudyID(), theShape->GetEntry());
261 if (aShape.IsNull()) return;
263 // Get shape parameters
264 GetOperations()->GetTolerance(aShape,
270 //=============================================================================
274 //=============================================================================
275 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
276 CORBA::String_out theDescription)
278 //Set a not done flag
279 GetOperations()->SetNotDone();
281 if (theShape == NULL)
283 theDescription = CORBA::string_dup("null");
287 //Get the reference shape
288 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
289 (theShape->GetStudyID(), theShape->GetEntry());
293 theDescription = CORBA::string_dup("null2");
297 // Get shape parameters
298 TCollection_AsciiString aDump;
299 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
301 theDescription = CORBA::string_dup("OK");
304 theDescription = CORBA::string_dup(aDump.ToCString());
308 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
309 CORBA::String_out theDescription)
311 //Set a not done flag
312 GetOperations()->SetNotDone();
314 if (theShape == NULL)
316 theDescription = CORBA::string_dup("null");
320 //Get the reference shape
321 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
322 (theShape->GetStudyID(), theShape->GetEntry());
326 theDescription = CORBA::string_dup("null2");
330 // Get shape parameters
331 TCollection_AsciiString aDump;
332 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
334 theDescription = CORBA::string_dup("OK");
337 theDescription = CORBA::string_dup(aDump.ToCString());
341 //=============================================================================
345 //=============================================================================
346 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
348 //Set a not done flag
349 GetOperations()->SetNotDone();
351 if (theShape == NULL) return NULL;
353 //Get the reference shape
354 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
355 (theShape->GetStudyID(), theShape->GetEntry());
357 if (aShape.IsNull()) return NULL;
359 // Get shape parameters
360 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
361 return CORBA::string_dup(aDescription.ToCString());
364 //=============================================================================
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)
374 //Set a not done flag
375 GetOperations()->SetNotDone();
377 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
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());
385 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
387 // Get shape parameters
388 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
391 //=============================================================================
395 //=============================================================================
396 void GEOM_IMeasureOperations_i::PointCoordinates (GEOM::GEOM_Object_ptr theShape,
397 CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z)
400 //Set a not done flag
401 GetOperations()->SetNotDone();
403 if ( theShape->_is_nil() )
406 //Get the reference shape
407 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
408 theShape->GetStudyID(), theShape->GetEntry() );
410 if ( aShape.IsNull() )
413 // Get shape parameters
414 GetOperations()->PointCoordinates( aShape, X, Y, Z );
417 //=============================================================================
421 //=============================================================================
422 CORBA::Double GEOM_IMeasureOperations_i::GetAngle (GEOM::GEOM_Object_ptr theShape1,
423 GEOM::GEOM_Object_ptr theShape2)
425 //Set a not done flag
426 GetOperations()->SetNotDone();
428 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
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());
436 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
439 return GetOperations()->GetAngle(aShape1, aShape2);