]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOM_I/GEOM_IHealingOperations_i.cc
Salome HOME
195b4a3a0384d92c6feedc55166ecb841ed16938
[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  *  DivideEdge
400  */
401 //=============================================================================
402 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
403                                                              CORBA::Short theIndex,
404                                                              CORBA::Double theValue,
405                                                              CORBA::Boolean isByParameter)
406 {
407   GEOM::GEOM_Object_var aGEOMObject;
408
409   // Set a not done flag
410   GetOperations()->SetNotDone();
411
412   // Check parameters
413   if (theValue < 0 || theValue > 1)
414     return aGEOMObject._retn();
415
416   // Get the object itself
417   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
418   if (anObject.IsNull())
419     return aGEOMObject._retn();
420
421   // Perform
422   Handle(GEOM_Object) aNewObject =
423     GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
424   if (!GetOperations()->IsDone() || aNewObject.IsNull())
425     return aGEOMObject._retn();
426
427   return GetObject(aNewObject);
428 }
429
430 //=============================================================================
431 /*!
432  *  FuseCollinearEdgesWithinWire
433  */
434 //=============================================================================
435 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
436                                           (GEOM::GEOM_Object_ptr theWire,
437                                            const GEOM::ListOfGO& theVertices)
438 {
439   GEOM::GEOM_Object_var aGEOMObject;
440
441   //Set a not done flag
442   GetOperations()->SetNotDone();
443
444   //Get the reference objects
445   Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
446   if (aWire.IsNull()) return aGEOMObject._retn();
447
448   int ind, aLen;
449   std::list<Handle(GEOM_Object)> aVerts;
450   //Get the shapes
451   aLen = theVertices.length();
452   for (ind = 0; ind < aLen; ind++) {
453     Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
454     if (aSh.IsNull()) return aGEOMObject._retn();
455     aVerts.push_back(aSh);
456   }
457
458   //Perform operation
459   Handle(GEOM_Object) anObject =
460     GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
461   if (!GetOperations()->IsDone() || anObject.IsNull())
462     return aGEOMObject._retn();
463
464   return GetObject(anObject);
465 }
466
467 //=============================================================================
468 /*!
469  *  GetFreeBoundary
470  */
471 //=============================================================================
472 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
473                                                             GEOM::ListOfGO_out theClosedWires,
474                                                             GEOM::ListOfGO_out theOpenWires )
475 {
476   theClosedWires = new GEOM::ListOfGO;
477   theOpenWires = new GEOM::ListOfGO;
478
479   // Set a not done flag
480   GetOperations()->SetNotDone();
481
482   // Get the object itself
483   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
484   if (anObject.IsNull())
485     return false;
486
487   Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
488   Handle(TColStd_HSequenceOfTransient) anOpen  = new TColStd_HSequenceOfTransient();
489   bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
490
491   if ( !GetOperations()->IsDone() || !res )
492     return false;
493
494   int i, n = aClosed->Length();
495   theClosedWires->length( n );
496   for ( i = 1; i <= n; i++ )
497     (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
498
499   n = anOpen->Length();
500   theOpenWires->length( n );
501   for ( i = 1, n = anOpen->Length(); i <= n; i++ )
502     (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
503
504   return true;
505 }
506
507
508 //=============================================================================
509 /*!
510  *  ChangeOrientation
511  */
512 //=============================================================================
513 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
514 {
515   GEOM::GEOM_Object_var aGEOMObject;
516
517   // Set a not done flag
518   GetOperations()->SetNotDone();
519
520   // Check parameters
521   if ( CORBA::is_nil(theObject) )
522     return aGEOMObject._retn();
523
524   aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
525
526   // Get the object itself
527   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
528   if (anObject.IsNull())
529     return aGEOMObject._retn();
530
531   // Perform
532 //  Handle(GEOM_Object) aNewObject =
533     GetOperations()->ChangeOrientation( anObject );
534 //  if (!GetOperations()->IsDone() || aNewObject.IsNull())
535 //    return aGEOMObject._retn();
536
537   //return GetObject(aNewObject);
538   return aGEOMObject._retn();
539 }
540
541
542 //=============================================================================
543 /*!
544  *  ChangeOrientationCopy
545  */
546 //=============================================================================
547 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
548 {
549   GEOM::GEOM_Object_var aGEOMObject;
550
551   // Set a not done flag
552   GetOperations()->SetNotDone();
553
554   // Get the object itself
555   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
556   if (anObject.IsNull())
557     return aGEOMObject._retn();
558
559   // Perform
560   Handle(GEOM_Object) aNewObject =
561     GetOperations()->ChangeOrientationCopy( anObject );
562   if (!GetOperations()->IsDone() || aNewObject.IsNull())
563     return aGEOMObject._retn();
564
565   return GetObject(aNewObject);
566 }
567
568 //=============================================================================
569 /*!
570  *  LimitTolerance
571  */
572 //=============================================================================
573 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
574                                                                  CORBA::Double theTolerance)
575 {
576   GEOM::GEOM_Object_var aGEOMObject;
577
578   // Set a not done flag
579   GetOperations()->SetNotDone();
580
581   // Get the object itself
582   Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
583   if (anObject.IsNull())
584     return aGEOMObject._retn();
585
586   // Perform
587   Handle(GEOM_Object) aNewObject =
588     GetOperations()->LimitTolerance(anObject, theTolerance);
589   if (!GetOperations()->IsDone() || aNewObject.IsNull())
590     return aGEOMObject._retn();
591
592   return GetObject(aNewObject);
593 }