Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/geom.git] / src / GEOM_I / GEOM_IMeasureOperations_i.cc
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 #include <Standard_Stream.hxx>
21
22 #include "GEOM_IMeasureOperations_i.hh"
23
24 #include "utilities.h"
25 #include "OpUtil.hxx"
26
27 #include "GEOM_Engine.hxx"
28 #include "GEOM_Object.hxx"
29
30 //=============================================================================
31 /*!
32  *   constructor:
33  */
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)
39 {
40   MESSAGE("GEOM_IMeasureOperations_i::GEOM_IMeasureOperations_i");
41 }
42
43 //=============================================================================
44 /*!
45  *  destructor
46  */
47 //=============================================================================
48 GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i()
49 {
50   MESSAGE("GEOM_IMeasureOperations_i::~GEOM_IMeasureOperations_i");
51 }
52
53
54 //=============================================================================
55 /*!
56  *  GetCentreOfMass
57  */
58 //=============================================================================
59 GEOM::GEOM_Object_ptr GEOM_IMeasureOperations_i::GetCentreOfMass
60                                               (GEOM::GEOM_Object_ptr theShape)
61 {
62   GEOM::GEOM_Object_var aGEOMObject;
63
64   //Set a not done flag
65   GetOperations()->SetNotDone();
66
67   if (theShape == NULL) return aGEOMObject._retn();
68
69   //Get the reference shape
70   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
71     (theShape->GetStudyID(), theShape->GetEntry());
72
73   if (aShape.IsNull()) return aGEOMObject._retn();
74
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();
79
80   return GetObject(anObject);
81 }
82
83 //=============================================================================
84 /*!
85  *  GetBasicProperties
86  */
87 //=============================================================================
88 void GEOM_IMeasureOperations_i::GetBasicProperties (GEOM::GEOM_Object_ptr theShape,
89                                                     CORBA::Double& theLength,
90                                                     CORBA::Double& theSurfArea,
91                                                     CORBA::Double& theVolume)
92 {
93   //Set a not done flag
94   GetOperations()->SetNotDone();
95
96   if (theShape == NULL) return;
97
98   //Get the reference shape
99   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
100     (theShape->GetStudyID(), theShape->GetEntry());
101
102   if (aShape.IsNull()) return;
103
104   // Get shape parameters
105   GetOperations()->GetBasicProperties(aShape, theLength, theSurfArea, theVolume);
106 }
107
108 //=============================================================================
109 /*!
110  *  GetInertia
111  */
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)
119 {
120   //Set a not done flag
121   GetOperations()->SetNotDone();
122
123   if (theShape == NULL) return;
124
125   //Get the reference shape
126   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
127     (theShape->GetStudyID(), theShape->GetEntry());
128
129   if (aShape.IsNull()) return;
130
131   // Get shape parameters
132   GetOperations()->GetInertia(aShape,
133                               I11, I12, I13,
134                               I21, I22, I23,
135                               I31, I32, I33,
136                               Ix , Iy , Iz);
137 }
138
139 //=============================================================================
140 /*!
141  *  GetBoundingBox
142  */
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)
148 {
149   //Set a not done flag
150   GetOperations()->SetNotDone();
151
152   if (theShape == NULL) return;
153
154   //Get the reference shape
155   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
156     (theShape->GetStudyID(), theShape->GetEntry());
157
158   if (aShape.IsNull()) return;
159
160   // Get shape parameters
161   GetOperations()->GetBoundingBox(aShape, Xmin, Xmax, Ymin, Ymax, Zmin, Zmax);
162 }
163
164 //=============================================================================
165 /*!
166  *  GetTolerance
167  */
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)
174 {
175   //Set a not done flag
176   GetOperations()->SetNotDone();
177
178   if (theShape == NULL) return;
179
180   //Get the reference shape
181   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
182     (theShape->GetStudyID(), theShape->GetEntry());
183
184   if (aShape.IsNull()) return;
185
186   // Get shape parameters
187   GetOperations()->GetTolerance(aShape,
188                                 FaceMin, FaceMax,
189                                 EdgeMin, EdgeMax,
190                                 VertMin, VertMax);
191 }
192
193 //=============================================================================
194 /*!
195  *  CheckShape
196  */
197 //=============================================================================
198 CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape,
199                                                       CORBA::String_out     theDescription)
200 {
201   //Set a not done flag
202   GetOperations()->SetNotDone();
203
204   if (theShape == NULL) 
205   {
206     theDescription = CORBA::string_dup("null");
207     return 0;
208   }
209
210   //Get the reference shape
211   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
212     (theShape->GetStudyID(), theShape->GetEntry());
213
214   if (aShape.IsNull())
215   {
216     theDescription = CORBA::string_dup("null2");
217     return 0;
218   }
219
220   // Get shape parameters
221   TCollection_AsciiString aDump;
222   if (GetOperations()->CheckShape(aShape, aDump))
223   {
224     theDescription = CORBA::string_dup("OK");
225     return 1;
226   }
227   theDescription = CORBA::string_dup(aDump.ToCString());
228   return 0;
229 }
230
231 //=============================================================================
232 /*!
233  *  WhatIs
234  */
235 //=============================================================================
236 char* GEOM_IMeasureOperations_i::WhatIs (GEOM::GEOM_Object_ptr theShape)
237 {
238   //Set a not done flag
239   GetOperations()->SetNotDone();
240
241   if (theShape == NULL) return NULL;
242
243   //Get the reference shape
244   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject
245     (theShape->GetStudyID(), theShape->GetEntry());
246
247   if (aShape.IsNull()) return NULL;
248
249   // Get shape parameters
250   TCollection_AsciiString aDescription = GetOperations()->WhatIs(aShape);
251   return CORBA::string_dup(aDescription.ToCString());
252 }
253
254 //=============================================================================
255 /*!
256  *  GetMinDistance
257  */
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)
263 {
264   //Set a not done flag
265   GetOperations()->SetNotDone();
266
267   if (theShape1 == NULL || theShape2 == NULL) return -1.0;
268
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());
274
275   if (aShape1.IsNull() || aShape2.IsNull()) return -1.0;
276
277   // Get shape parameters
278   return GetOperations()->GetMinDistance(aShape1, aShape2, X1, Y1, Z1, X2, Y2, Z2);
279 }
280
281 //=============================================================================
282 /*!
283  *  PointCoordinates
284  */
285 //=============================================================================
286 void GEOM_IMeasureOperations_i::PointCoordinates(
287   GEOM::GEOM_Object_ptr theShape, CORBA::Double& X, CORBA::Double& Y, CORBA::Double& Z )
288
289 {
290   //Set a not done flag
291   GetOperations()->SetNotDone();
292
293   if ( theShape->_is_nil() )
294     return;
295
296   //Get the reference shape
297   Handle(GEOM_Object) aShape = GetOperations()->GetEngine()->GetObject(
298     theShape->GetStudyID(), theShape->GetEntry() );
299
300   if ( aShape.IsNull() )
301     return;
302
303   // Get shape parameters
304   GetOperations()->PointCoordinates( aShape, X, Y, Z );
305 }