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/
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, aDump))
224 theDescription = CORBA::string_dup("OK");
227 theDescription = CORBA::string_dup(aDump.ToCString());
231 //=============================================================================
235 //=============================================================================
236 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
238 //Set a not done flag
239 GetOperations()->SetNotDone();
241 if (theShape == NULL) return NULL;
243 //Get the reference shape
244 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
245 (theShape->GetStudyID(), theShape->GetEntry());
247 if (aShape.IsNull()) return NULL;
249 // Get shape parameters
250 TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
251 return strdup(aDescription.ToCString());
254 //=============================================================================
258 //=============================================================================
259 CORBA::Double GEOM_IMeasureOperations_i::GetMinDistance
260 (GEOM::GEOM_Object_ptr theShape1, GEOM::GEOM_Object_ptr theShape2,
261 CORBA::Double& X1, CORBA::Double& Y1, CORBA::Double& Z1,
262 CORBA::Double& X2, CORBA::Double& Y2, CORBA::Double& Z2)
264 //Set a not done flag
265 GetOperations()->SetNotDone();
267 if (theShape1 == NULL || theShape2 == NULL) return -1.0;
269 //Get the reference shape
270 Handle(GEOM_Object) aShape1 = GetOperations()->GetEngine()->GetObject
271 (theShape1->GetStudyID(), theShape1->GetEntry());
272 Handle(GEOM_Object) aShape2 = GetOperations()->GetEngine()->GetObject
273 (theShape2->GetStudyID(), theShape2->GetEntry());
275 if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
277 // Get shape parameters
278 return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
281 //=============================================================================
285 //=============================================================================
286 void GEOM_IMeasureOperations_i::PointCoordinates(
287 GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
290 //Set a not done flag
291 GetOperations()->SetNotDone();
293 if ( theShape->_is_nil() )
296 //Get the reference shape
297 Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
298 theShape->GetStudyID(), theShape->GetEntry() );
300 if ( aShape.IsNull() )
303 // Get shape parameters
304 GetOperations()->PointCoordinates( aShape, X, Y, Z );