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");
54 //=============================================================================
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)
66 GetOperations()->SetNotDone();
68 //Set default values: global CS
69 Ox = Oy = Oz = Zx = Zy = Xy = Xz = 0.;
72 if (theShape == NULL) return;
74 //Get the reference shape
75 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
76 (theShape->GetStudyID(), theShape->GetEntry());
78 if (aShape.IsNull()) return;
80 // Get shape parameters
81 GetOperations()->GetPosition(aShape, Ox,Oy,Oz, Zx,Zy,Zz, Xx,Xy,Xz);
84 //=============================================================================
88 //=============================================================================
89 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
90 (GEOM::GEOM_Object_ptr theShape)
92 GEOM::GEOM_Object_var aGEOMObject;
95 GetOperations()->SetNotDone();
97 if (theShape == NULL) return aGEOMObject._retn();
99 //Get the reference shape
100 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
101 (theShape->GetStudyID(), theShape->GetEntry());
103 if (aShape.IsNull()) return aGEOMObject._retn();
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();
110 return GetObject(anObject);
113 //=============================================================================
117 //=============================================================================
118 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
119 CORBA::Double& theLength,
120 CORBA::Double& theSurfArea,
121 CORBA::Double& theVolume)
123 //Set a not done flag
124 GetOperations()->SetNotDone();
126 if (theShape == NULL) return;
128 //Get the reference shape
129 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
130 (theShape->GetStudyID(), theShape->GetEntry());
132 if (aShape.IsNull()) return;
134 // Get shape parameters
135 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
138 //=============================================================================
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)
150 //Set a not done flag
151 GetOperations()->SetNotDone();
153 if (theShape == NULL) return;
155 //Get the reference shape
156 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
157 (theShape->GetStudyID(), theShape->GetEntry());
159 if (aShape.IsNull()) return;
161 // Get shape parameters
162 GetOperations()->GetInertia(aShape,
169 //=============================================================================
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)
179 //Set a not done flag
180 GetOperations()->SetNotDone();
182 if (theShape == NULL) return;
184 //Get the reference shape
185 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
186 (theShape->GetStudyID(), theShape->GetEntry());
188 if (aShape.IsNull()) return;
190 // Get shape parameters
191 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
194 //=============================================================================
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)
205 //Set a not done flag
206 GetOperations()->SetNotDone();
208 if (theShape == NULL) return;
210 //Get the reference shape
211 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
212 (theShape->GetStudyID(), theShape->GetEntry());
214 if (aShape.IsNull()) return;
216 // Get shape parameters
217 GetOperations()->GetTolerance(aShape,
223 //=============================================================================
227 //=============================================================================
228 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
229 CORBA::String_out theDescription)
231 //Set a not done flag
232 GetOperations()->SetNotDone();
234 if (theShape == NULL)
236 theDescription = CORBA::string_dup("null");
240 //Get the reference shape
241 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
242 (theShape->GetStudyID(), theShape->GetEntry());
246 theDescription = CORBA::string_dup("null2");
250 // Get shape parameters
251 TCollection_AsciiString aDump;
252 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
254 theDescription = CORBA::string_dup("OK");
257 theDescription = CORBA::string_dup(aDump.ToCString());
261 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
262 CORBA::String_out theDescription)
264 //Set a not done flag
265 GetOperations()->SetNotDone();
267 if (theShape == NULL)
269 theDescription = CORBA::string_dup("null");
273 //Get the reference shape
274 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
275 (theShape->GetStudyID(), theShape->GetEntry());
279 theDescription = CORBA::string_dup("null2");
283 // Get shape parameters
284 TCollection_AsciiString aDump;
285 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
287 theDescription = CORBA::string_dup("OK");
290 theDescription = CORBA::string_dup(aDump.ToCString());
294 //=============================================================================
298 //=============================================================================
299 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
301 //Set a not done flag
302 GetOperations()->SetNotDone();
304 if (theShape == NULL) return NULL;
306 //Get the reference shape
307 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
308 (theShape->GetStudyID(), theShape->GetEntry());
310 if (aShape.IsNull()) return NULL;
312 // Get shape parameters
313 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
314 return CORBA::string_dup(aDescription.ToCString());
317 //=============================================================================
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)
327 //Set a not done flag
328 GetOperations()->SetNotDone();
330 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
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());
338 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
340 // Get shape parameters
341 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
344 //=============================================================================
348 //=============================================================================
349 void GEOM_IMeasureOperations_i::PointCoordinates(
350 GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
353 //Set a not done flag
354 GetOperations()->SetNotDone();
356 if ( theShape->_is_nil() )
359 //Get the reference shape
360 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
361 theShape->GetStudyID(), theShape->GetEntry() );
363 if ( aShape.IsNull() )
366 // Get shape parameters
367 GetOperations()->PointCoordinates( aShape, X, Y, Z );