]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IHealingOperations_i.cc
Salome HOME
Improve CheckShape function
[modules/geom.git] / src / GEOM_I / GEOM_IHealingOperations_i.cc
1 #include <Standard_Stream.hxx>
2
3 #include <list>
4
5 #include "GEOM_IHealingOperations_i.hh"
6 #include "GEOM_Engine.hxx"
7 #include "GEOM_Object.hxx"
8
9 #include "utilities.h"
10 #include "OpUtil.hxx"
11 #include "Utils_ExceptHandlers.hxx"
12
13 #include <TColStd_HSequenceOfTransient.hxx>
14
15 //=============================================================================
16 /*!
17  *   constructor:
18  */
19 //=============================================================================
20
21 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
22                                                       GEOM::GEOM_Gen_ptr theEngine,
23                                                       ::GEOMImpl_IHealingOperations* theImpl)
24 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
25 {
26   MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
27 }
28
29 //=============================================================================
30 /*!
31  *  destructor
32  */
33 //=============================================================================
34
35 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
36 {
37   MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
38 }
39
40 //=============================================================================
41 /*!
42  *  Convert
43  */
44 //=============================================================================
45 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
46                                           (const GEOM::short_array& theInArray)
47 {
48   Handle(TColStd_HArray1OfInteger) anOutArray;
49   int n = theInArray.length();
50   if ( n <= 0 )
51     return anOutArray;
52   anOutArray = new TColStd_HArray1OfInteger( 1, n );
53   for (int i = 0; i < n; i++)
54     anOutArray->SetValue( i+1, theInArray[i] );
55   return anOutArray;
56 }
57
58 //=============================================================================
59 /*!
60  *  Convert
61  */
62 //=============================================================================
63 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
64                                          (const GEOM::string_array& theInArray)
65 {
66   Handle(TColStd_HArray1OfExtendedString) anOutArray;
67   int n = theInArray.length();
68   if ( n <= 0 )
69     return anOutArray;
70   anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
71   char* str;
72   for ( int i = 0; i < n; i++ )
73   {
74     str = CORBA::string_dup( theInArray[i] );
75     anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
76   }
77   return anOutArray;
78 }
79
80 //=============================================================================
81 /*!
82  *  ProcessShape
83  */
84 //=============================================================================
85 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
86                                                                const GEOM::string_array& theOperations,
87                                                                const GEOM::string_array& theParams,
88                                                                const GEOM::string_array& theValues)
89 {
90   GEOM::GEOM_Object_var aGEOMObject;
91
92   // Set a not done flag
93   GetOperations()->SetNotDone();
94
95   // Check parameters
96   if ( CORBA::is_nil(theObject) )
97     return aGEOMObject._retn();
98
99   // Check if theOperations has more than 0 elements and theParams and theValues have the same length
100 //  if ( theOperations.length() <= 0 || theParams.length() != theValues.length() )
101 //    return aGEOMObject._retn();
102
103   // Get the object itself
104   Handle(GEOM_Object) anObject =
105     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
106   if ( anObject.IsNull() )
107     return aGEOMObject._retn();
108
109   // Perform
110   Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
111     Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
112   if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
113     return aGEOMObject._retn();
114
115   return GetObject( aNewObject );
116 }
117
118 //=============================================================================
119 /*!
120  *  GetShapeProcessParameters
121  */
122 //=============================================================================
123 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
124                                                           GEOM::string_array_out theParams,
125                                                           GEOM::string_array_out theValues)
126 {
127   GEOM::string_array_var anOpArray = new GEOM::string_array();
128   GEOM::string_array_var aParArray = new GEOM::string_array();
129   GEOM::string_array_var aValArray = new GEOM::string_array();
130
131   // retrieve the values as stl-lists
132   list<string> operationsList, paramsList, valuesList;
133   GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
134   const int opSize = operationsList.size(),
135   parSize = paramsList.size(),
136   valSize = valuesList.size();
137
138   if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
139     // allocate the CORBA arrays, sizes == returned lists' sizes
140     anOpArray->length(opSize);
141     aParArray->length(parSize);
142     aValArray->length(valSize);
143
144     // fill the local CORBA arrays with values from lists
145     list<string>::iterator opIt, parIt, valIt;
146     int i = 0;
147     for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
148       anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
149
150     for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
151           parIt != paramsList.end(); i++, ++parIt,++valIt ) {
152       aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
153       aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
154     }
155   }
156
157   // initialize out-parameters with local arrays
158   theOperations = anOpArray._retn();
159   theParams = aParArray._retn();
160   theValues = aValArray._retn();
161 }
162
163 //=============================================================================
164 /*!
165  *  GetOperatorParameters
166  */
167 //=============================================================================
168 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,  
169                                                        GEOM::string_array_out theParams, 
170                                                        GEOM::string_array_out theValues)
171 {
172   GEOM::string_array_var aParArray = new GEOM::string_array();
173   GEOM::string_array_var aValArray = new GEOM::string_array();
174
175   // retrieve the values as stl-lists
176   list<string> paramsList, valuesList;
177   if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
178     const int parSize = paramsList.size(), valSize = valuesList.size();
179
180     if ( parSize == valSize ) {
181       aParArray->length(parSize);
182       aValArray->length(valSize);
183
184       // fill the local CORBA arrays with values from lists
185       list<string>::iterator parIt, valIt;
186       int i;
187       for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
188             parIt != paramsList.end(); i++, ++parIt,++valIt ) {
189         aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
190         aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
191       }
192     }
193   }
194
195   // initialize out-parameters with local arrays
196   theParams = aParArray._retn();
197   theValues = aValArray._retn();
198 }
199
200 //=============================================================================
201 /*!
202  *  SuppressFaces
203  */
204 //=============================================================================
205 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
206                                                                 const GEOM::short_array& theFaces)
207 {
208   GEOM::GEOM_Object_var aGEOMObject;
209
210   // Set a not done flag
211   GetOperations()->SetNotDone();
212
213   // Check parameters
214   if ( CORBA::is_nil(theObject) ) // if theFaces is empty - it's OK, it means that ALL faces must be removed
215     return aGEOMObject._retn();
216
217   // Get the object itself
218   Handle(GEOM_Object) anObject =
219     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
220   if (anObject.IsNull())
221     return aGEOMObject._retn();
222
223   // Perform
224   Handle(GEOM_Object) aNewObject =
225     GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
226   if (!GetOperations()->IsDone() || aNewObject.IsNull())
227     return aGEOMObject._retn();
228
229   return  GetObject( aNewObject );
230 }
231
232 //=============================================================================
233 /*!
234  *  CloseContour
235  */
236 //=============================================================================
237 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
238                                                                const GEOM::short_array& theWires,
239                                                                CORBA::Boolean isCommonVertex)
240 {
241   GEOM::GEOM_Object_var aGEOMObject;
242
243   // Set a not done flag
244   GetOperations()->SetNotDone();
245
246   // Check parameters
247   if ( CORBA::is_nil(theObject) )
248     return aGEOMObject._retn();
249
250   // Get the object itself
251   Handle(GEOM_Object) anObject =
252     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
253   if (anObject.IsNull())
254     return aGEOMObject._retn();
255
256   // Perform
257   Handle(GEOM_Object) aNewObject =
258     GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
259   if (!GetOperations()->IsDone() || aNewObject.IsNull())
260     return aGEOMObject._retn();
261
262   return GetObject(aNewObject);
263 }
264
265 //=============================================================================
266 /*!
267  *  RemoveIntWires
268  */
269 //=============================================================================
270 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
271                                                                  const GEOM::short_array& theWires)
272 {
273   GEOM::GEOM_Object_var aGEOMObject;
274
275   // Set a not done flag
276   GetOperations()->SetNotDone();
277
278   // Check parameters
279   if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
280     return aGEOMObject._retn();
281
282   // Get the object itself
283   Handle(GEOM_Object) anObject =
284     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
285   if (anObject.IsNull())
286     return aGEOMObject._retn();
287
288   // Perform
289   Handle(GEOM_Object) aNewObject =
290     GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
291   if (!GetOperations()->IsDone() || aNewObject.IsNull())
292     return aGEOMObject._retn();
293
294   return GetObject(aNewObject);
295 }
296
297 //=============================================================================
298 /*!
299  *  FillHoles
300  */
301 //=============================================================================
302 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
303                                                             const GEOM::short_array& theWires)
304 {
305   GEOM::GEOM_Object_var aGEOMObject;
306
307   // Set a not done flag
308   GetOperations()->SetNotDone();
309
310   // Check parameters
311   if ( CORBA::is_nil(theObject) ) // if theWires is empty - it's OK, it means that ALL wires should be removed
312     return aGEOMObject._retn();
313
314   // Get the object itself
315   Handle(GEOM_Object) anObject =
316     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
317   if (anObject.IsNull())
318     return aGEOMObject._retn();
319
320   // Perform
321   Handle(GEOM_Object) aNewObject =
322     GetOperations()->FillHoles( anObject, Convert( theWires ) );
323   if (!GetOperations()->IsDone() || aNewObject.IsNull())
324     return aGEOMObject._retn();
325
326   return GetObject(aNewObject);
327 }
328
329 //=============================================================================
330 /*!
331  *  Sew
332  */
333 //=============================================================================
334 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
335                                                       CORBA::Double theTolerance)
336 {
337   GEOM::GEOM_Object_var aGEOMObject;
338
339   // Set a not done flag
340   GetOperations()->SetNotDone();
341
342   // Check parameters
343   if ( CORBA::is_nil(theObject) || theTolerance < 0 )
344     return aGEOMObject._retn();
345
346   // Get the object itself
347   Handle(GEOM_Object) anObject =
348     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
349   if (anObject.IsNull())
350     return aGEOMObject._retn();
351
352   // Perform
353   Handle(GEOM_Object) aNewObject =
354     GetOperations()->Sew( anObject, theTolerance );
355   if (!GetOperations()->IsDone() || aNewObject.IsNull())
356     return aGEOMObject._retn();
357
358   return GetObject(aNewObject);
359 }
360
361 //=============================================================================
362 /*!
363  *  DivideEdge
364  */
365 //=============================================================================
366 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
367                                                              CORBA::Short theIndex,
368                                                              CORBA::Double theValue,
369                                                              CORBA::Boolean isByParameter)
370 {
371   GEOM::GEOM_Object_var aGEOMObject;
372
373   // Set a not done flag
374   GetOperations()->SetNotDone();
375
376   // Check parameters
377   if ( CORBA::is_nil(theObject) || theValue < 0 || theValue > 1 )
378     return aGEOMObject._retn();
379
380   // Get the object itself
381   Handle(GEOM_Object) anObject =
382     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
383   if (anObject.IsNull())
384     return aGEOMObject._retn();
385
386   // Perform
387   Handle(GEOM_Object) aNewObject =
388     GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
389   if (!GetOperations()->IsDone() || aNewObject.IsNull())
390     return aGEOMObject._retn();
391
392   return GetObject(aNewObject);
393 }
394
395 //=============================================================================
396 /*!
397  *  GetFreeBoundary
398  */
399 //=============================================================================
400 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
401                                                             GEOM::ListOfGO_out theClosedWires,
402                                                             GEOM::ListOfGO_out theOpenWires )
403 {
404   theClosedWires = new GEOM::ListOfGO;
405   theOpenWires = new GEOM::ListOfGO;
406
407   // Set a not done flag
408   GetOperations()->SetNotDone();
409
410   if ( CORBA::is_nil(theObject) )
411         return false;
412
413   // Get the object itself
414   Handle(GEOM_Object) anObject =
415     GetOperations()->GetEngine()->GetObject(theObject->GetStudyID(), theObject->GetEntry());
416   if (anObject.IsNull())
417     return false;
418
419   Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
420   Handle(TColStd_HSequenceOfTransient) anOpen  = new TColStd_HSequenceOfTransient();
421   bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
422
423   if ( !GetOperations()->IsDone() || !res )
424         return false;
425
426   int i, n = aClosed->Length();
427   theClosedWires->length( n );
428   for ( i = 1; i <= n; i++ )
429     (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
430
431   n = anOpen->Length();
432   theOpenWires->length( n );
433   for ( i = 1, n = anOpen->Length(); i <= n; i++ )
434     (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
435
436   return true;
437 }