]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IHealingOperations_i.cc
Salome HOME
0021684: EDF 2221 : Display the arguments and the name of the operations
[modules/geom.git] / src / GEOM_I / GEOM_IHealingOperations_i.cc
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include <Standard_Stream.hxx>
24
25 #include <list>
26
27 #include "GEOM_IHealingOperations_i.hh"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
30
31 #include "utilities.h"
32 #include "OpUtil.hxx"
33 #include "Utils_ExceptHandlers.hxx"
34 #include <Basics_Utils.hxx>
35
36 #include <TColStd_HSequenceOfTransient.hxx>
37
38 //=============================================================================
39 /*!
40  *   constructor:
41  */
42 //=============================================================================
43
44 GEOM_IHealingOperations_i::GEOM_IHealingOperations_i (PortableServer::POA_ptr thePOA,
45                                                       GEOM::GEOM_Gen_ptr theEngine,
46                                                       ::GEOMImpl_IHealingOperations* theImpl)
47 :GEOM_IOperations_i(thePOA, theEngine, theImpl)
48 {
49   MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
50 }
51
52 //=============================================================================
53 /*!
54  *  destructor
55  */
56 //=============================================================================
57
58 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
59 {
60   MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
61 }
62
63 //=============================================================================
64 /*!
65  *  Convert
66  */
67 //=============================================================================
68 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
69                                           (const GEOM::short_array& theInArray)
70 {
71   Handle(TColStd_HArray1OfInteger) anOutArray;
72   int n = theInArray.length();
73   if ( n <= 0 )
74     return anOutArray;
75   anOutArray = new TColStd_HArray1OfInteger( 1, n );
76   for (int i = 0; i < n; i++)
77     anOutArray->SetValue( i+1, theInArray[i] );
78   return anOutArray;
79 }
80
81 //=============================================================================
82 /*!
83  *  Convert
84  */
85 //=============================================================================
86 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
87                                          (const GEOM::string_array& theInArray)
88 {
89   Handle(TColStd_HArray1OfExtendedString) anOutArray;
90   int n = theInArray.length();
91   if ( n <= 0 )
92     return anOutArray;
93   anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
94   char* str;
95   for ( int i = 0; i < n; i++ )
96   {
97     str = CORBA::string_dup( theInArray[i] );
98     anOutArray->SetValue( i+1, TCollection_ExtendedString( str ) );
99   }
100   return anOutArray;
101 }
102
103 //=============================================================================
104 /*!
105  *  ProcessShape
106  */
107 //=============================================================================
108 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
109                                                                const GEOM::string_array& theOperations,
110                                                                const GEOM::string_array& theParams,
111                                                                const GEOM::string_array& theValues)
112 {
113   Kernel_Utils::Localizer loc;
114
115   GEOM::GEOM_Object_var aGEOMObject;
116
117   // Set a not done flag
118   GetOperations()->SetNotDone();
119
120   // Check if theOperations has more than 0 elements and theParams and theValues have the same length
121   //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
122   //  return aGEOMObject._retn();
123
124   // Get the object itself
125   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
126   if (anObject.IsNull())
127     return aGEOMObject._retn();
128
129   // Perform
130   Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
131     Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
132   if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
133     return aGEOMObject._retn();
134
135   return GetObject( aNewObject );
136 }
137
138 //=============================================================================
139 /*!
140  *  GetShapeProcessParameters
141  */
142 //=============================================================================
143 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
144                                                           GEOM::string_array_out theParams,
145                                                           GEOM::string_array_out theValues)
146 {
147   GEOM::string_array_var anOpArray = new GEOM::string_array();
148   GEOM::string_array_var aParArray = new GEOM::string_array();
149   GEOM::string_array_var aValArray = new GEOM::string_array();
150
151   // retrieve the values as stl-lists
152   std::list<std::string> operationsList, paramsList, valuesList;
153   GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
154   const int opSize = operationsList.size(),
155   parSize = paramsList.size(),
156   valSize = valuesList.size();
157
158   if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
159     // allocate the CORBA arrays, sizes == returned lists' sizes
160     anOpArray->length(opSize);
161     aParArray->length(parSize);
162     aValArray->length(valSize);
163
164     // fill the local CORBA arrays with values from lists
165     std::list<std::string>::iterator opIt, parIt, valIt;
166     int i = 0;
167     for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
168       anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
169
170     for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
171           parIt != paramsList.end(); i++, ++parIt,++valIt ) {
172       aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
173       aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
174     }
175   }
176
177   // initialize out-parameters with local arrays
178   theOperations = anOpArray._retn();
179   theParams = aParArray._retn();
180   theValues = aValArray._retn();
181 }
182
183 //=============================================================================
184 /*!
185  *  GetOperatorParameters
186  */
187 //=============================================================================
188 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
189                                                        GEOM::string_array_out theParams,
190                                                        GEOM::string_array_out theValues)
191 {
192   GEOM::string_array_var aParArray = new GEOM::string_array();
193   GEOM::string_array_var aValArray = new GEOM::string_array();
194
195   // retrieve the values as stl-lists
196   std::list<std::string> paramsList, valuesList;
197   if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
198     const int parSize = paramsList.size(), valSize = valuesList.size();
199
200     if ( parSize == valSize ) {
201       aParArray->length(parSize);
202       aValArray->length(valSize);
203
204       // fill the local CORBA arrays with values from lists
205       std::list<std::string>::iterator parIt, valIt;
206       int i;
207       for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
208             parIt != paramsList.end(); i++, ++parIt,++valIt ) {
209         aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
210         aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
211       }
212     }
213   }
214
215   // initialize out-parameters with local arrays
216   theParams = aParArray._retn();
217   theValues = aValArray._retn();
218 }
219
220 //=============================================================================
221 /*!
222  *  SuppressFaces
223  */
224 //=============================================================================
225 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
226                                                                 const GEOM::short_array& theFaces)
227 {
228   GEOM::GEOM_Object_var aGEOMObject;
229
230   // Set a not done flag
231   GetOperations()->SetNotDone();
232
233   // Get the object itself
234   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
235   if (anObject.IsNull())
236     return aGEOMObject._retn();
237
238   // if theFaces is empty - it's OK, it means that ALL faces must be removed
239
240   // Perform
241   Handle(GEOM_Object) aNewObject =
242     GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
243   if (!GetOperations()->IsDone() || aNewObject.IsNull())
244     return aGEOMObject._retn();
245
246   return  GetObject( aNewObject );
247 }
248
249 //=============================================================================
250 /*!
251  *  CloseContour
252  */
253 //=============================================================================
254 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
255                                                                const GEOM::short_array& theWires,
256                                                                CORBA::Boolean isCommonVertex)
257 {
258   GEOM::GEOM_Object_var aGEOMObject;
259
260   // Set a not done flag
261   GetOperations()->SetNotDone();
262
263   // Get the object itself
264   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
265   if (anObject.IsNull())
266     return aGEOMObject._retn();
267
268   // Perform
269   Handle(GEOM_Object) aNewObject =
270     GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
271   if (!GetOperations()->IsDone() || aNewObject.IsNull())
272     return aGEOMObject._retn();
273
274   return GetObject(aNewObject);
275 }
276
277 //=============================================================================
278 /*!
279  *  RemoveIntWires
280  */
281 //=============================================================================
282 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
283                                                                  const GEOM::short_array& theWires)
284 {
285   GEOM::GEOM_Object_var aGEOMObject;
286
287   // Set a not done flag
288   GetOperations()->SetNotDone();
289
290   // Get the object itself
291   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
292   if (anObject.IsNull())
293     return aGEOMObject._retn();
294
295   // if theWires is empty - it's OK, it means that ALL wires should be removed
296
297   // Perform
298   Handle(GEOM_Object) aNewObject =
299     GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
300   if (!GetOperations()->IsDone() || aNewObject.IsNull())
301     return aGEOMObject._retn();
302
303   return GetObject(aNewObject);
304 }
305
306 //=============================================================================
307 /*!
308  *  FillHoles
309  */
310 //=============================================================================
311 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
312                                                             const GEOM::short_array& theWires)
313 {
314   GEOM::GEOM_Object_var aGEOMObject;
315
316   // Set a not done flag
317   GetOperations()->SetNotDone();
318
319   // Get the object itself
320   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
321   if (anObject.IsNull())
322     return aGEOMObject._retn();
323
324   // if theWires is empty - it's OK, it means that ALL wires should be removed
325
326   // Perform
327   Handle(GEOM_Object) aNewObject =
328     GetOperations()->FillHoles( anObject, Convert( theWires ) );
329   if (!GetOperations()->IsDone() || aNewObject.IsNull())
330     return aGEOMObject._retn();
331
332   return GetObject(aNewObject);
333 }
334
335 //=============================================================================
336 /*!
337  *  Sew
338  */
339 //=============================================================================
340 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
341                                                       CORBA::Double theTolerance)
342 {
343   GEOM::GEOM_Object_var aGEOMObject;
344
345   // Set a not done flag
346   GetOperations()->SetNotDone();
347
348   // Check parameters
349   if (theTolerance < 0)
350     return aGEOMObject._retn();
351
352   // Get the object itself
353   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
354   if (anObject.IsNull())
355     return aGEOMObject._retn();
356
357   // Perform
358   Handle(GEOM_Object) aNewObject =
359     GetOperations()->Sew( anObject, theTolerance, false );
360   if (!GetOperations()->IsDone() || aNewObject.IsNull())
361     return aGEOMObject._retn();
362
363   return GetObject(aNewObject);
364 }
365
366 //=============================================================================
367 /*!
368  *  SewAllowNonManifold
369  */
370 //=============================================================================
371 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SewAllowNonManifold (GEOM::GEOM_Object_ptr theObject,
372                                                                       CORBA::Double theTolerance)
373 {
374   GEOM::GEOM_Object_var aGEOMObject;
375
376   // Set a not done flag
377   GetOperations()->SetNotDone();
378
379   // Check parameters
380   if (theTolerance < 0)
381     return aGEOMObject._retn();
382
383   // Get the object itself
384   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
385   if (anObject.IsNull())
386     return aGEOMObject._retn();
387
388   // Perform
389   Handle(GEOM_Object) aNewObject =
390     GetOperations()->Sew( anObject, theTolerance, true );
391   if (!GetOperations()->IsDone() || aNewObject.IsNull())
392     return aGEOMObject._retn();
393
394   return GetObject(aNewObject);
395 }
396
397 //=============================================================================
398 /*!
399  *  RemoveInternalFaces
400  */
401 //=============================================================================
402 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveInternalFaces (GEOM::GEOM_Object_ptr theCompound)
403 {
404   GEOM::GEOM_Object_var aGEOMObject;
405
406   // Set a not done flag
407   GetOperations()->SetNotDone();
408
409   // Get the object
410   Handle(GEOM_Object) anObject = GetObjectImpl(theCompound);
411   if (anObject.IsNull())
412     return aGEOMObject._retn();
413
414   // Perform
415   Handle(GEOM_Object) aNewObject = GetOperations()->RemoveInternalFaces(anObject);
416   if (!GetOperations()->IsDone() || aNewObject.IsNull())
417     return aGEOMObject._retn();
418
419   return GetObject(aNewObject);
420 }
421
422 //=============================================================================
423 /*!
424  *  DivideEdge
425  */
426 //=============================================================================
427 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
428                                                              CORBA::Short theIndex,
429                                                              CORBA::Double theValue,
430                                                              CORBA::Boolean isByParameter)
431 {
432   GEOM::GEOM_Object_var aGEOMObject;
433
434   // Set a not done flag
435   GetOperations()->SetNotDone();
436
437   // Check parameters
438   if (theValue < 0 || theValue > 1)
439     return aGEOMObject._retn();
440
441   // Get the object itself
442   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
443   if (anObject.IsNull())
444     return aGEOMObject._retn();
445
446   // Perform
447   Handle(GEOM_Object) aNewObject =
448     GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
449   if (!GetOperations()->IsDone() || aNewObject.IsNull())
450     return aGEOMObject._retn();
451
452   return GetObject(aNewObject);
453 }
454
455 //=============================================================================
456 /*!
457  *  FuseCollinearEdgesWithinWire
458  */
459 //=============================================================================
460 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
461                                           (GEOM::GEOM_Object_ptr theWire,
462                                            const GEOM::ListOfGO& theVertices)
463 {
464   GEOM::GEOM_Object_var aGEOMObject;
465
466   //Set a not done flag
467   GetOperations()->SetNotDone();
468
469   //Get the reference objects
470   Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
471   if (aWire.IsNull()) return aGEOMObject._retn();
472
473   int ind, aLen;
474   std::list<Handle(GEOM_Object)> aVerts;
475   //Get the shapes
476   aLen = theVertices.length();
477   for (ind = 0; ind < aLen; ind++) {
478     Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
479     if (aSh.IsNull()) return aGEOMObject._retn();
480     aVerts.push_back(aSh);
481   }
482
483   //Perform operation
484   Handle(GEOM_Object) anObject =
485     GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
486   if (!GetOperations()->IsDone() || anObject.IsNull())
487     return aGEOMObject._retn();
488
489   return GetObject(anObject);
490 }
491
492 //=============================================================================
493 /*!
494  *  GetFreeBoundary
495  */
496 //=============================================================================
497 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
498                                                             GEOM::ListOfGO_out theClosedWires,
499                                                             GEOM::ListOfGO_out theOpenWires )
500 {
501   theClosedWires = new GEOM::ListOfGO;
502   theOpenWires = new GEOM::ListOfGO;
503
504   // Set a not done flag
505   GetOperations()->SetNotDone();
506
507   // Get the object itself
508   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
509   if (anObject.IsNull())
510     return false;
511
512   Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
513   Handle(TColStd_HSequenceOfTransient) anOpen  = new TColStd_HSequenceOfTransient();
514   bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
515
516   if ( !GetOperations()->IsDone() || !res )
517     return false;
518
519   int i, n = aClosed->Length();
520   theClosedWires->length( n );
521   for ( i = 1; i <= n; i++ )
522     (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
523
524   n = anOpen->Length();
525   theOpenWires->length( n );
526   for ( i = 1, n = anOpen->Length(); i <= n; i++ )
527     (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
528
529   return true;
530 }
531
532
533 //=============================================================================
534 /*!
535  *  ChangeOrientation
536  */
537 //=============================================================================
538 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
539 {
540   GEOM::GEOM_Object_var aGEOMObject;
541
542   // Set a not done flag
543   GetOperations()->SetNotDone();
544
545   // Check parameters
546   if ( CORBA::is_nil(theObject) )
547     return aGEOMObject._retn();
548
549   aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
550
551   // Get the object itself
552   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
553   if (anObject.IsNull())
554     return aGEOMObject._retn();
555
556   // Perform
557 //  Handle(GEOM_Object) aNewObject =
558     GetOperations()->ChangeOrientation( anObject );
559 //  if (!GetOperations()->IsDone() || aNewObject.IsNull())
560 //    return aGEOMObject._retn();
561
562   //return GetObject(aNewObject);
563   return aGEOMObject._retn();
564 }
565
566
567 //=============================================================================
568 /*!
569  *  ChangeOrientationCopy
570  */
571 //=============================================================================
572 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
573 {
574   GEOM::GEOM_Object_var aGEOMObject;
575
576   // Set a not done flag
577   GetOperations()->SetNotDone();
578
579   // Get the object itself
580   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
581   if (anObject.IsNull())
582     return aGEOMObject._retn();
583
584   // Perform
585   Handle(GEOM_Object) aNewObject =
586     GetOperations()->ChangeOrientationCopy( anObject );
587   if (!GetOperations()->IsDone() || aNewObject.IsNull())
588     return aGEOMObject._retn();
589
590   return GetObject(aNewObject);
591 }
592
593 //=============================================================================
594 /*!
595  *  LimitTolerance
596  */
597 //=============================================================================
598 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
599                                                                  CORBA::Double theTolerance)
600 {
601   GEOM::GEOM_Object_var aGEOMObject;
602
603   // Set a not done flag
604   GetOperations()->SetNotDone();
605
606   // Get the object itself
607   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
608   if (anObject.IsNull())
609     return aGEOMObject._retn();
610
611   // Perform
612   Handle(GEOM_Object) aNewObject =
613     GetOperations()->LimitTolerance(anObject, theTolerance);
614   if (!GetOperations()->IsDone() || aNewObject.IsNull())
615     return aGEOMObject._retn();
616
617   return GetObject(aNewObject);
618 }