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
20 #include <Standard_Stream.hxx>
22 #include "GEOM_IMeasureOperations_i.hh"
24 #include "utilities.h"
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
30 //=============================================================================
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)
40 MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
43 //=============================================================================
47 //=============================================================================
48 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
50 MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
53 //=============================================================================
57 //=============================================================================
58 GEOM::GEOM_IKindOfShape::shape_kind GEOM_IMeasureOperations_i::KindOfShape
59 (GEOM::GEOM_Object_ptr theShape,
60 GEOM::ListOfLong_out theIntegers,
61 GEOM::ListOfDouble_out theDoubles)
63 GEOMImpl_IMeasureOperations::ShapeKind aKind = GEOMImpl_IMeasureOperations::SK_NO_SHAPE;
65 // allocate the CORBA arrays
66 GEOM::ListOfLong_var anIntegersArray = new GEOM::ListOfLong();
67 GEOM::ListOfDouble_var aDoublesArray = new GEOM::ListOfDouble();
69 //Get the reference shape
70 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
71 (theShape->GetStudyID(), theShape->GetEntry());
73 if (!aShape.IsNull()) {
74 Handle(TColStd_HSequenceOfInteger) anIntegers = new TColStd_HSequenceOfInteger;
75 Handle(TColStd_HSequenceOfReal) aDoubles = new TColStd_HSequenceOfReal;
77 // Detect kind of shape and parameters
78 aKind = GetOperations()->KindOfShape(aShape, anIntegers, aDoubles);
80 int nbInts = anIntegers->Length();
81 int nbDbls = aDoubles->Length();
83 anIntegersArray->length(nbInts);
84 aDoublesArray->length(nbDbls);
86 for (int ii = 0; ii < nbInts; ii++) {
87 anIntegersArray[ii] = anIntegers->Value(ii + 1);
89 for (int id = 0; id < nbDbls; id++) {
90 aDoublesArray[id] = aDoubles->Value(id + 1);
94 // initialize out-parameters with local arrays
95 theIntegers = anIntegersArray._retn();
96 theDoubles = aDoublesArray._retn();
97 return (GEOM::GEOM_IKindOfShape::shape_kind)aKind;
100 //=============================================================================
104 //=============================================================================
105 void GEOM_IMeasureOperations_i::GetPosition
106 (GEOM::GEOM_Object_ptr theShape,
107 CORBA::Double& Ox, CORBA::Double& Oy, CORBA::Double& Oz,
108 CORBA::Double& Zx, CORBA::Double& Zy, CORBA::Double& Zz,
109 CORBA::Double& Xx, CORBA::Double& Xy, CORBA::Double& Xz)
111 //Set a not done flag
112 GetOperations()->SetNotDone();
114 //Set default values: global CS
115 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
118 if (theShape == NULL) return;
120 //Get the reference shape
121 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
122 (theShape->GetStudyID(), theShape->GetEntry());
124 if (aShape.IsNull()) return;
126 // Get shape parameters
127 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
130 //=============================================================================
134 //=============================================================================
135 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
136 (GEOM::GEOM_Object_ptr theShape)
138 GEOM::GEOM_Object_var aGEOMObject;
140 //Set a not done flag
141 GetOperations()->SetNotDone();
143 if (theShape == NULL) return aGEOMObject._retn();
145 //Get the reference shape
146 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
147 (theShape->GetStudyID(), theShape->GetEntry());
149 if (aShape.IsNull()) return aGEOMObject._retn();
151 // Make Point - centre of mass of theShape
152 Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
153 if (!GetOperations()->IsDone() || anObject.IsNull())
154 return aGEOMObject._retn();
156 return GetObject(anObject);
159 //=============================================================================
163 //=============================================================================
164 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
165 CORBA::Double& theLength,
166 CORBA::Double& theSurfArea,
167 CORBA::Double& theVolume)
169 //Set a not done flag
170 GetOperations()->SetNotDone();
172 if (theShape == NULL) return;
174 //Get the reference shape
175 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
176 (theShape->GetStudyID(), theShape->GetEntry());
178 if (aShape.IsNull()) return;
180 // Get shape parameters
181 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
184 //=============================================================================
188 //=============================================================================
189 void GEOM_IMeasureOperations_i::GetInertia
190 (GEOM::GEOM_Object_ptr theShape,
191 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
192 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
193 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
194 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
196 //Set a not done flag
197 GetOperations()->SetNotDone();
199 if (theShape == NULL) return;
201 //Get the reference shape
202 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
203 (theShape->GetStudyID(), theShape->GetEntry());
205 if (aShape.IsNull()) return;
207 // Get shape parameters
208 GetOperations()->GetInertia(aShape,
215 //=============================================================================
219 //=============================================================================
220 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
221 CORBA::Double& Xmin, CORBA::Double& Xmax,
222 CORBA::Double& Ymin, CORBA::Double& Ymax,
223 CORBA::Double& Zmin, CORBA::Double& Zmax)
225 //Set a not done flag
226 GetOperations()->SetNotDone();
228 if (theShape == NULL) return;
230 //Get the reference shape
231 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
232 (theShape->GetStudyID(), theShape->GetEntry());
234 if (aShape.IsNull()) return;
236 // Get shape parameters
237 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
240 //=============================================================================
244 //=============================================================================
245 void GEOM_IMeasureOperations_i::GetTolerance
246 (GEOM::GEOM_Object_ptr theShape,
247 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
248 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
249 CORBA::Double& VertMin, CORBA::Double& VertMax)
251 //Set a not done flag
252 GetOperations()->SetNotDone();
254 if (theShape == NULL) return;
256 //Get the reference shape
257 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
258 (theShape->GetStudyID(), theShape->GetEntry());
260 if (aShape.IsNull()) return;
262 // Get shape parameters
263 GetOperations()->GetTolerance(aShape,
269 //=============================================================================
273 //=============================================================================
274 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
275 CORBA::String_out theDescription)
277 //Set a not done flag
278 GetOperations()->SetNotDone();
280 if (theShape == NULL)
282 theDescription = CORBA::string_dup("null");
286 //Get the reference shape
287 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
288 (theShape->GetStudyID(), theShape->GetEntry());
292 theDescription = CORBA::string_dup("null2");
296 // Get shape parameters
297 TCollection_AsciiString aDump;
298 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
300 theDescription = CORBA::string_dup("OK");
303 theDescription = CORBA::string_dup(aDump.ToCString());
307 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
308 CORBA::String_out theDescription)
310 //Set a not done flag
311 GetOperations()->SetNotDone();
313 if (theShape == NULL)
315 theDescription = CORBA::string_dup("null");
319 //Get the reference shape
320 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
321 (theShape->GetStudyID(), theShape->GetEntry());
325 theDescription = CORBA::string_dup("null2");
329 // Get shape parameters
330 TCollection_AsciiString aDump;
331 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
333 theDescription = CORBA::string_dup("OK");
336 theDescription = CORBA::string_dup(aDump.ToCString());
340 //=============================================================================
344 //=============================================================================
345 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
347 //Set a not done flag
348 GetOperations()->SetNotDone();
350 if (theShape == NULL) return NULL;
352 //Get the reference shape
353 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
354 (theShape->GetStudyID(), theShape->GetEntry());
356 if (aShape.IsNull()) return NULL;
358 // Get shape parameters
359 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
360 return CORBA::string_dup(aDescription.ToCString());
363 //=============================================================================
367 //=============================================================================
368 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
369 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
370 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
371 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
373 //Set a not done flag
374 GetOperations()->SetNotDone();
376 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
378 //Get the reference shape
379 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
380 (theShape1->GetStudyID(), theShape1->GetEntry());
381 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
382 (theShape2->GetStudyID(), theShape2->GetEntry());
384 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
386 // Get shape parameters
387 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
390 //=============================================================================
394 //=============================================================================
395 void GEOM_IMeasureOperations_i::PointCoordinates(
396 GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
399 //Set a not done flag
400 GetOperations()->SetNotDone();
402 if ( theShape->_is_nil() )
405 //Get the reference shape
406 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
407 theShape->GetStudyID(), theShape->GetEntry() );
409 if ( aShape.IsNull() )
412 // Get shape parameters
413 GetOperations()->PointCoordinates( aShape, X, Y, Z );