1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
27 #include "GEOM_IHealingOperations_i.hh"
28 #include "GEOM_Engine.hxx"
29 #include "GEOM_Object.hxx"
31 #include "utilities.h"
33 #include "Utils_ExceptHandlers.hxx"
34 #include <Basics_Utils.hxx>
36 #include <TColStd_HSequenceOfTransient.hxx>
38 //=============================================================================
42 //=============================================================================
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)
49 MESSAGE("GEOM_IHealingOperations_i::GEOM_IHealingOperations_i");
52 //=============================================================================
56 //=============================================================================
58 GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i()
60 MESSAGE("GEOM_IHealingOperations_i::~GEOM_IHealingOperations_i");
63 //=============================================================================
67 //=============================================================================
68 Handle(TColStd_HArray1OfInteger) GEOM_IHealingOperations_i::Convert
69 (const GEOM::short_array& theInArray)
71 Handle(TColStd_HArray1OfInteger) anOutArray;
72 int n = theInArray.length();
75 anOutArray = new TColStd_HArray1OfInteger( 1, n );
76 for (int i = 0; i < n; i++)
77 anOutArray->SetValue( i+1, theInArray[i] );
81 //=============================================================================
85 //=============================================================================
86 Handle(TColStd_HArray1OfExtendedString) GEOM_IHealingOperations_i::Convert
87 (const GEOM::string_array& theInArray)
89 Handle(TColStd_HArray1OfExtendedString) anOutArray;
90 int n = theInArray.length();
93 anOutArray = new TColStd_HArray1OfExtendedString( 1, n );
94 for ( int i = 0; i < n; i++ )
95 anOutArray->SetValue( i+1, TCollection_ExtendedString( theInArray[i].in() ) );
100 //=============================================================================
104 //=============================================================================
105 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
106 const GEOM::string_array& theOperations,
107 const GEOM::string_array& theParams,
108 const GEOM::string_array& theValues)
110 Kernel_Utils::Localizer loc;
112 GEOM::GEOM_Object_var aGEOMObject;
114 // Set a not done flag
115 GetOperations()->SetNotDone();
117 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
118 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
119 // return aGEOMObject._retn();
121 // Get the object itself
122 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
123 if (anObject.IsNull())
124 return aGEOMObject._retn();
127 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
128 Convert( theOperations ), Convert( theParams ), Convert( theValues ) );
129 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
130 return aGEOMObject._retn();
132 return GetObject( aNewObject );
135 //=============================================================================
137 * GetShapeProcessParameters
139 //=============================================================================
140 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
141 GEOM::string_array_out theParams,
142 GEOM::string_array_out theValues)
144 GEOM::string_array_var anOpArray = new GEOM::string_array();
145 GEOM::string_array_var aParArray = new GEOM::string_array();
146 GEOM::string_array_var aValArray = new GEOM::string_array();
148 // retrieve the values as stl-lists
149 std::list<std::string> operationsList, paramsList, valuesList;
150 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
151 const int opSize = operationsList.size(),
152 parSize = paramsList.size(),
153 valSize = valuesList.size();
155 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
156 // allocate the CORBA arrays, sizes == returned lists' sizes
157 anOpArray->length(opSize);
158 aParArray->length(parSize);
159 aValArray->length(valSize);
161 // fill the local CORBA arrays with values from lists
162 std::list<std::string>::iterator opIt, parIt, valIt;
164 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
165 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
167 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
168 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
169 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
170 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
174 // initialize out-parameters with local arrays
175 theOperations = anOpArray._retn();
176 theParams = aParArray._retn();
177 theValues = aValArray._retn();
180 //=============================================================================
182 * GetOperatorParameters
184 //=============================================================================
185 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
186 GEOM::string_array_out theParams,
187 GEOM::string_array_out theValues)
189 GEOM::string_array_var aParArray = new GEOM::string_array();
190 GEOM::string_array_var aValArray = new GEOM::string_array();
192 // retrieve the values as stl-lists
193 std::list<std::string> paramsList, valuesList;
194 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
195 const int parSize = paramsList.size(), valSize = valuesList.size();
197 if ( parSize == valSize ) {
198 aParArray->length(parSize);
199 aValArray->length(valSize);
201 // fill the local CORBA arrays with values from lists
202 std::list<std::string>::iterator parIt, valIt;
204 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
205 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
206 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
207 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
212 // initialize out-parameters with local arrays
213 theParams = aParArray._retn();
214 theValues = aValArray._retn();
217 //=============================================================================
221 //=============================================================================
222 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
223 const GEOM::short_array& theFaces)
225 GEOM::GEOM_Object_var aGEOMObject;
227 // Set a not done flag
228 GetOperations()->SetNotDone();
230 // Get the object itself
231 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
232 if (anObject.IsNull())
233 return aGEOMObject._retn();
235 // if theFaces is empty - it's OK, it means that ALL faces must be removed
238 Handle(GEOM_Object) aNewObject =
239 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
240 if (!GetOperations()->IsDone() || aNewObject.IsNull())
241 return aGEOMObject._retn();
243 return GetObject( aNewObject );
246 //=============================================================================
250 //=============================================================================
251 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
252 const GEOM::short_array& theWires,
253 CORBA::Boolean isCommonVertex)
255 GEOM::GEOM_Object_var aGEOMObject;
257 // Set a not done flag
258 GetOperations()->SetNotDone();
260 // Get the object itself
261 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
262 if (anObject.IsNull())
263 return aGEOMObject._retn();
266 Handle(GEOM_Object) aNewObject =
267 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
268 if (!GetOperations()->IsDone() || aNewObject.IsNull())
269 return aGEOMObject._retn();
271 return GetObject(aNewObject);
274 //=============================================================================
278 //=============================================================================
279 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
280 const GEOM::short_array& theWires)
282 GEOM::GEOM_Object_var aGEOMObject;
284 // Set a not done flag
285 GetOperations()->SetNotDone();
287 // Get the object itself
288 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
289 if (anObject.IsNull())
290 return aGEOMObject._retn();
292 // if theWires is empty - it's OK, it means that ALL wires should be removed
295 Handle(GEOM_Object) aNewObject =
296 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
297 if (!GetOperations()->IsDone() || aNewObject.IsNull())
298 return aGEOMObject._retn();
300 return GetObject(aNewObject);
303 //=============================================================================
307 //=============================================================================
308 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
309 const GEOM::short_array& theWires)
311 GEOM::GEOM_Object_var aGEOMObject;
313 // Set a not done flag
314 GetOperations()->SetNotDone();
316 // Get the object itself
317 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
318 if (anObject.IsNull())
319 return aGEOMObject._retn();
321 // if theWires is empty - it's OK, it means that ALL wires should be removed
324 Handle(GEOM_Object) aNewObject =
325 GetOperations()->FillHoles( anObject, Convert( theWires ) );
326 if (!GetOperations()->IsDone() || aNewObject.IsNull())
327 return aGEOMObject._retn();
329 return GetObject(aNewObject);
332 //=============================================================================
336 //=============================================================================
337 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (GEOM::GEOM_Object_ptr theObject,
338 CORBA::Double theTolerance)
340 GEOM::GEOM_Object_var aGEOMObject;
342 // Set a not done flag
343 GetOperations()->SetNotDone();
346 if (theTolerance < 0)
347 return aGEOMObject._retn();
349 // Get the object itself
350 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
351 if (anObject.IsNull())
352 return aGEOMObject._retn();
355 Handle(GEOM_Object) aNewObject =
356 GetOperations()->Sew( anObject, theTolerance, false );
357 if (!GetOperations()->IsDone() || aNewObject.IsNull())
358 return aGEOMObject._retn();
360 return GetObject(aNewObject);
363 //=============================================================================
365 * SewAllowNonManifold
367 //=============================================================================
368 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SewAllowNonManifold (GEOM::GEOM_Object_ptr theObject,
369 CORBA::Double theTolerance)
371 GEOM::GEOM_Object_var aGEOMObject;
373 // Set a not done flag
374 GetOperations()->SetNotDone();
377 if (theTolerance < 0)
378 return aGEOMObject._retn();
380 // Get the object itself
381 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
382 if (anObject.IsNull())
383 return aGEOMObject._retn();
386 Handle(GEOM_Object) aNewObject =
387 GetOperations()->Sew( anObject, theTolerance, true );
388 if (!GetOperations()->IsDone() || aNewObject.IsNull())
389 return aGEOMObject._retn();
391 return GetObject(aNewObject);
394 //=============================================================================
396 * RemoveInternalFaces
398 //=============================================================================
399 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveInternalFaces (GEOM::GEOM_Object_ptr theCompound)
401 GEOM::GEOM_Object_var aGEOMObject;
403 // Set a not done flag
404 GetOperations()->SetNotDone();
407 Handle(GEOM_Object) anObject = GetObjectImpl(theCompound);
408 if (anObject.IsNull())
409 return aGEOMObject._retn();
412 Handle(GEOM_Object) aNewObject = GetOperations()->RemoveInternalFaces(anObject);
413 if (!GetOperations()->IsDone() || aNewObject.IsNull())
414 return aGEOMObject._retn();
416 return GetObject(aNewObject);
419 //=============================================================================
423 //=============================================================================
424 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
425 CORBA::Short theIndex,
426 CORBA::Double theValue,
427 CORBA::Boolean isByParameter)
429 GEOM::GEOM_Object_var aGEOMObject;
431 // Set a not done flag
432 GetOperations()->SetNotDone();
435 if (theValue < 0 || theValue > 1)
436 return aGEOMObject._retn();
438 // Get the object itself
439 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
440 if (anObject.IsNull())
441 return aGEOMObject._retn();
444 Handle(GEOM_Object) aNewObject =
445 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
446 if (!GetOperations()->IsDone() || aNewObject.IsNull())
447 return aGEOMObject._retn();
449 return GetObject(aNewObject);
452 //=============================================================================
454 * FuseCollinearEdgesWithinWire
456 //=============================================================================
457 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
458 (GEOM::GEOM_Object_ptr theWire,
459 const GEOM::ListOfGO& theVertices)
461 GEOM::GEOM_Object_var aGEOMObject;
463 //Set a not done flag
464 GetOperations()->SetNotDone();
466 //Get the reference objects
467 Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
468 if (aWire.IsNull()) return aGEOMObject._retn();
471 std::list<Handle(GEOM_Object)> aVerts;
473 aLen = theVertices.length();
474 for (ind = 0; ind < aLen; ind++) {
475 Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
476 if (aSh.IsNull()) return aGEOMObject._retn();
477 aVerts.push_back(aSh);
481 Handle(GEOM_Object) anObject =
482 GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
483 if (!GetOperations()->IsDone() || anObject.IsNull())
484 return aGEOMObject._retn();
486 return GetObject(anObject);
489 //=============================================================================
493 //=============================================================================
494 CORBA::Boolean GEOM_IHealingOperations_i::GetFreeBoundary ( GEOM::GEOM_Object_ptr theObject,
495 GEOM::ListOfGO_out theClosedWires,
496 GEOM::ListOfGO_out theOpenWires )
498 theClosedWires = new GEOM::ListOfGO;
499 theOpenWires = new GEOM::ListOfGO;
501 // Set a not done flag
502 GetOperations()->SetNotDone();
504 // Get the object itself
505 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
506 if (anObject.IsNull())
509 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
510 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
511 bool res = GetOperations()->GetFreeBoundary( anObject, aClosed, anOpen );
513 if ( !GetOperations()->IsDone() || !res )
516 int i, n = aClosed->Length();
517 theClosedWires->length( n );
518 for ( i = 1; i <= n; i++ )
519 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
521 n = anOpen->Length();
522 theOpenWires->length( n );
523 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
524 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
530 //=============================================================================
534 //=============================================================================
535 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
537 GEOM::GEOM_Object_var aGEOMObject;
539 // Set a not done flag
540 GetOperations()->SetNotDone();
543 if ( CORBA::is_nil(theObject) )
544 return aGEOMObject._retn();
546 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
548 // Get the object itself
549 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
550 if (anObject.IsNull())
551 return aGEOMObject._retn();
554 // Handle(GEOM_Object) aNewObject =
555 GetOperations()->ChangeOrientation( anObject );
556 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
557 // return aGEOMObject._retn();
559 //return GetObject(aNewObject);
560 return aGEOMObject._retn();
564 //=============================================================================
566 * ChangeOrientationCopy
568 //=============================================================================
569 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
571 GEOM::GEOM_Object_var aGEOMObject;
573 // Set a not done flag
574 GetOperations()->SetNotDone();
576 // Get the object itself
577 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
578 if (anObject.IsNull())
579 return aGEOMObject._retn();
582 Handle(GEOM_Object) aNewObject =
583 GetOperations()->ChangeOrientationCopy( anObject );
584 if (!GetOperations()->IsDone() || aNewObject.IsNull())
585 return aGEOMObject._retn();
587 return GetObject(aNewObject);
590 //=============================================================================
594 //=============================================================================
595 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
596 CORBA::Double theTolerance)
598 GEOM::GEOM_Object_var aGEOMObject;
600 // Set a not done flag
601 GetOperations()->SetNotDone();
603 // Get the object itself
604 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
605 if (anObject.IsNull())
606 return aGEOMObject._retn();
609 Handle(GEOM_Object) aNewObject =
610 GetOperations()->LimitTolerance(anObject, theTolerance);
611 if (!GetOperations()->IsDone() || aNewObject.IsNull())
612 return aGEOMObject._retn();
614 return GetObject(aNewObject);