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 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
60 (GEOM::GEOM_Object_ptr theShape)
62 GEOM::GEOM_Object_var aGEOMObject;
65 GetOperations()->SetNotDone();
67 if (theShape == NULL) return aGEOMObject._retn();
69 //Get the reference shape
70 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
71 (theShape->GetStudyID(), theShape->GetEntry());
73 if (aShape.IsNull()) return aGEOMObject._retn();
75 // Make Point - centre of mass of theShape
76 Handle(GEOM_Object) anObject = GetOperations()->GetCentreOfMass(aShape);
77 if (!GetOperations()->IsDone() || anObject.IsNull())
78 return aGEOMObject._retn();
80 return GetObject(anObject);
83 //=============================================================================
87 //=============================================================================
88 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
89 CORBA::Double& theLength,
90 CORBA::Double& theSurfArea,
91 CORBA::Double& theVolume)
94 GetOperations()->SetNotDone();
96 if (theShape == NULL) return;
98 //Get the reference shape
99 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
100 (theShape->GetStudyID(), theShape->GetEntry());
102 if (aShape.IsNull()) return;
104 // Get shape parameters
105 GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
108 //=============================================================================
112 //=============================================================================
113 void GEOM_IMeasureOperations_i::GetInertia
114 (GEOM::GEOM_Object_ptr theShape,
115 CORBA::Double& I11, CORBA::Double& I12, CORBA::Double& I13,
116 CORBA::Double& I21, CORBA::Double& I22, CORBA::Double& I23,
117 CORBA::Double& I31, CORBA::Double& I32, CORBA::Double& I33,
118 CORBA::Double& Ix , CORBA::Double& Iy , CORBA::Double& Iz)
120 //Set a not done flag
121 GetOperations()->SetNotDone();
123 if (theShape == NULL) return;
125 //Get the reference shape
126 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
127 (theShape->GetStudyID(), theShape->GetEntry());
129 if (aShape.IsNull()) return;
131 // Get shape parameters
132 GetOperations()->GetInertia(aShape,
139 //=============================================================================
143 //=============================================================================
144 void GEOM_IMeasureOperations_i::GetBoundingBox (GEOM::GEOM_Object_ptr theShape,
145 CORBA::Double& Xmin, CORBA::Double& Xmax,
146 CORBA::Double& Ymin, CORBA::Double& Ymax,
147 CORBA::Double& Zmin, CORBA::Double& Zmax)
149 //Set a not done flag
150 GetOperations()->SetNotDone();
152 if (theShape == NULL) return;
154 //Get the reference shape
155 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
156 (theShape->GetStudyID(), theShape->GetEntry());
158 if (aShape.IsNull()) return;
160 // Get shape parameters
161 GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
164 //=============================================================================
168 //=============================================================================
169 void GEOM_IMeasureOperations_i::GetTolerance
170 (GEOM::GEOM_Object_ptr theShape,
171 CORBA::Double& FaceMin, CORBA::Double& FaceMax,
172 CORBA::Double& EdgeMin, CORBA::Double& EdgeMax,
173 CORBA::Double& VertMin, CORBA::Double& VertMax)
175 //Set a not done flag
176 GetOperations()->SetNotDone();
178 if (theShape == NULL) return;
180 //Get the reference shape
181 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
182 (theShape->GetStudyID(), theShape->GetEntry());
184 if (aShape.IsNull()) return;
186 // Get shape parameters
187 GetOperations()->GetTolerance(aShape,
193 //=============================================================================
197 //=============================================================================
198 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
199 CORBA::String_out theDescription)
201 //Set a not done flag
202 GetOperations()->SetNotDone();
204 if (theShape == NULL)
206 theDescription = CORBA::string_dup("null");
210 //Get the reference shape
211 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
212 (theShape->GetStudyID(), theShape->GetEntry());
216 theDescription = CORBA::string_dup("null2");
220 // Get shape parameters
221 TCollection_AsciiString aDump;
222 if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump))
224 theDescription = CORBA::string_dup("OK");
227 theDescription = CORBA::string_dup(aDump.ToCString());
231 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape,
232 CORBA::String_out theDescription)
234 //Set a not done flag
235 GetOperations()->SetNotDone();
237 if (theShape == NULL)
239 theDescription = CORBA::string_dup("null");
243 //Get the reference shape
244 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
245 (theShape->GetStudyID(), theShape->GetEntry());
249 theDescription = CORBA::string_dup("null2");
253 // Get shape parameters
254 TCollection_AsciiString aDump;
255 if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump))
257 theDescription = CORBA::string_dup("OK");
260 theDescription = CORBA::string_dup(aDump.ToCString());
264 //=============================================================================
268 //=============================================================================
269 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
271 //Set a not done flag
272 GetOperations()->SetNotDone();
274 if (theShape == NULL) return NULL;
276 //Get the reference shape
277 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
278 (theShape->GetStudyID(), theShape->GetEntry());
280 if (aShape.IsNull()) return NULL;
282 // Get shape parameters
283 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
284 return CORBA::string_dup(aDescription.ToCString());
287 //=============================================================================
291 //=============================================================================
292 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
293 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
294 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
295 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
297 //Set a not done flag
298 GetOperations()->SetNotDone();
300 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
302 //Get the reference shape
303 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
304 (theShape1->GetStudyID(), theShape1->GetEntry());
305 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
306 (theShape2->GetStudyID(), theShape2->GetEntry());
308 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
310 // Get shape parameters
311 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
314 //=============================================================================
318 //=============================================================================
319 void GEOM_IMeasureOperations_i::PointCoordinates(
320 GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
323 //Set a not done flag
324 GetOperations()->SetNotDone();
326 if ( theShape->_is_nil() )
329 //Get the reference shape
330 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
331 theShape->GetStudyID(), theShape->GetEntry() );
333 if ( aShape.IsNull() )
336 // Get shape parameters
337 GetOperations()->PointCoordinates( aShape, X, Y, Z );