1 // Copyright (C) 2007-2014 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, or (at your option) any later version.
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 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ProcessShape (GEOM::GEOM_Object_ptr theObject,
87 const GEOM::string_array& theOperations,
88 const GEOM::string_array& theParams,
89 const GEOM::string_array& theValues)
91 Kernel_Utils::Localizer loc;
93 GEOM::GEOM_Object_var aGEOMObject;
95 // Set a not done flag
96 GetOperations()->SetNotDone();
98 // Check if theOperations has more than 0 elements and theParams and theValues have the same length
99 //if (theOperations.length() <= 0 || theParams.length() != theValues.length())
100 // return aGEOMObject._retn();
102 // Get the object itself
103 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
104 if (anObject.IsNull())
105 return aGEOMObject._retn();
108 Handle(GEOM_Object) aNewObject = GetOperations()->ShapeProcess( anObject,
109 ConvertStringArray( theOperations ), ConvertStringArray( theParams ),
110 ConvertStringArray( theValues ) );
111 if ( !GetOperations()->IsDone() || aNewObject.IsNull() )
112 return aGEOMObject._retn();
114 return GetObject( aNewObject );
117 //=============================================================================
119 * GetShapeProcessParameters
121 //=============================================================================
122 void GEOM_IHealingOperations_i::GetShapeProcessParameters(GEOM::string_array_out theOperations,
123 GEOM::string_array_out theParams,
124 GEOM::string_array_out theValues)
126 GEOM::string_array_var anOpArray = new GEOM::string_array();
127 GEOM::string_array_var aParArray = new GEOM::string_array();
128 GEOM::string_array_var aValArray = new GEOM::string_array();
130 // retrieve the values as stl-lists
131 std::list<std::string> operationsList, paramsList, valuesList;
132 GetOperations()->GetShapeProcessParameters( operationsList, paramsList, valuesList );
133 const int opSize = operationsList.size(),
134 parSize = paramsList.size(),
135 valSize = valuesList.size();
137 if ( opSize >= 0 && parSize >= 0 && parSize == valSize ) {
138 // allocate the CORBA arrays, sizes == returned lists' sizes
139 anOpArray->length(opSize);
140 aParArray->length(parSize);
141 aValArray->length(valSize);
143 // fill the local CORBA arrays with values from lists
144 std::list<std::string>::iterator opIt, parIt, valIt;
146 for ( opIt = operationsList.begin(); opIt != operationsList.end(); i++,++opIt )
147 anOpArray[i] = CORBA::string_dup( (*opIt).c_str() );
149 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
150 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
151 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
152 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
156 // initialize out-parameters with local arrays
157 theOperations = anOpArray._retn();
158 theParams = aParArray._retn();
159 theValues = aValArray._retn();
162 //=============================================================================
164 * GetOperatorParameters
166 //=============================================================================
167 void GEOM_IHealingOperations_i::GetOperatorParameters (const char* theOperator,
168 GEOM::string_array_out theParams,
169 GEOM::string_array_out theValues)
171 GEOM::string_array_var aParArray = new GEOM::string_array();
172 GEOM::string_array_var aValArray = new GEOM::string_array();
174 // retrieve the values as stl-lists
175 std::list<std::string> paramsList, valuesList;
176 if ( GetOperations()->GetOperatorParameters( theOperator, paramsList, valuesList ) ) {
177 const int parSize = paramsList.size(), valSize = valuesList.size();
179 if ( parSize == valSize ) {
180 aParArray->length(parSize);
181 aValArray->length(valSize);
183 // fill the local CORBA arrays with values from lists
184 std::list<std::string>::iterator parIt, valIt;
186 for ( i = 0, parIt = paramsList.begin(), valIt = valuesList.begin();
187 parIt != paramsList.end(); i++, ++parIt,++valIt ) {
188 aParArray[i] = CORBA::string_dup( (*parIt).c_str() );
189 aValArray[i] = CORBA::string_dup( (*valIt).c_str() );
194 // initialize out-parameters with local arrays
195 theParams = aParArray._retn();
196 theValues = aValArray._retn();
199 //=============================================================================
203 //=============================================================================
204 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::SuppressFaces (GEOM::GEOM_Object_ptr theObject,
205 const GEOM::short_array& theFaces)
207 GEOM::GEOM_Object_var aGEOMObject;
209 // Set a not done flag
210 GetOperations()->SetNotDone();
212 // Get the object itself
213 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
214 if (anObject.IsNull())
215 return aGEOMObject._retn();
217 // if theFaces is empty - it's OK, it means that ALL faces must be removed
220 Handle(GEOM_Object) aNewObject =
221 GetOperations()->SuppressFaces( anObject, Convert( theFaces ) );
222 if (!GetOperations()->IsDone() || aNewObject.IsNull())
223 return aGEOMObject._retn();
225 return GetObject( aNewObject );
228 //=============================================================================
232 //=============================================================================
233 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::CloseContour (GEOM::GEOM_Object_ptr theObject,
234 const GEOM::short_array& theWires,
235 CORBA::Boolean isCommonVertex)
237 GEOM::GEOM_Object_var aGEOMObject;
239 // Set a not done flag
240 GetOperations()->SetNotDone();
242 // Get the object itself
243 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
244 if (anObject.IsNull())
245 return aGEOMObject._retn();
248 Handle(GEOM_Object) aNewObject =
249 GetOperations()->CloseContour( anObject, Convert( theWires ), isCommonVertex );
250 if (!GetOperations()->IsDone() || aNewObject.IsNull())
251 return aGEOMObject._retn();
253 return GetObject(aNewObject);
256 //=============================================================================
260 //=============================================================================
261 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::RemoveIntWires (GEOM::GEOM_Object_ptr theObject,
262 const GEOM::short_array& theWires)
264 GEOM::GEOM_Object_var aGEOMObject;
266 // Set a not done flag
267 GetOperations()->SetNotDone();
269 // Get the object itself
270 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
271 if (anObject.IsNull())
272 return aGEOMObject._retn();
274 // if theWires is empty - it's OK, it means that ALL wires should be removed
277 Handle(GEOM_Object) aNewObject =
278 GetOperations()->RemoveIntWires( anObject, Convert( theWires ) );
279 if (!GetOperations()->IsDone() || aNewObject.IsNull())
280 return aGEOMObject._retn();
282 return GetObject(aNewObject);
285 //=============================================================================
289 //=============================================================================
290 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FillHoles (GEOM::GEOM_Object_ptr theObject,
291 const GEOM::short_array& theWires)
293 GEOM::GEOM_Object_var aGEOMObject;
295 // Set a not done flag
296 GetOperations()->SetNotDone();
298 // Get the object itself
299 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
300 if (anObject.IsNull())
301 return aGEOMObject._retn();
303 // if theWires is empty - it's OK, it means that ALL wires should be removed
306 Handle(GEOM_Object) aNewObject =
307 GetOperations()->FillHoles( anObject, Convert( theWires ) );
308 if (!GetOperations()->IsDone() || aNewObject.IsNull())
309 return aGEOMObject._retn();
311 return GetObject(aNewObject);
314 //=============================================================================
318 //=============================================================================
319 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::Sew (const GEOM::ListOfGO& theObjects,
320 CORBA::Double theTolerance)
322 GEOM::GEOM_Object_var aGEOMObject;
324 // Set a not done flag
325 GetOperations()->SetNotDone();
328 if (theTolerance < 0)
329 return aGEOMObject._retn();
332 std::list< Handle(GEOM_Object) > aShapes;
333 if (! GetListOfObjectsImpl( theObjects, aShapes ))
334 return aGEOMObject._retn();
337 Handle(GEOM_Object) aNewObject = GetOperations()->Sew( aShapes, theTolerance, false );
338 if (!GetOperations()->IsDone() || aNewObject.IsNull())
339 return aGEOMObject._retn();
341 return GetObject(aNewObject);
344 //=============================================================================
346 * SewAllowNonManifold
348 //=============================================================================
349 GEOM::GEOM_Object_ptr
350 GEOM_IHealingOperations_i::SewAllowNonManifold (const GEOM::ListOfGO& theObjects,
351 CORBA::Double theTolerance)
353 GEOM::GEOM_Object_var aGEOMObject;
355 // Set a not done flag
356 GetOperations()->SetNotDone();
359 if (theTolerance < 0)
360 return aGEOMObject._retn();
363 std::list< Handle(GEOM_Object) > aShapes;
364 if (! GetListOfObjectsImpl( theObjects, aShapes ))
365 return aGEOMObject._retn();
368 Handle(GEOM_Object) aNewObject = GetOperations()->Sew( aShapes, theTolerance, true );
369 if (!GetOperations()->IsDone() || aNewObject.IsNull())
370 return aGEOMObject._retn();
372 return GetObject(aNewObject);
375 //=============================================================================
377 * RemoveInternalFaces
379 //=============================================================================
380 GEOM::GEOM_Object_ptr
381 GEOM_IHealingOperations_i::RemoveInternalFaces (const GEOM::ListOfGO& theSolids)
383 GEOM::GEOM_Object_var aGEOMObject;
385 // Set a not done flag
386 GetOperations()->SetNotDone();
389 std::list< Handle(GEOM_Object) > aShapes;
390 if (! GetListOfObjectsImpl( theSolids, aShapes ))
391 return aGEOMObject._retn();
394 Handle(GEOM_Object) aNewObject = GetOperations()->RemoveInternalFaces(aShapes);
395 if (!GetOperations()->IsDone() || aNewObject.IsNull())
396 return aGEOMObject._retn();
398 return GetObject(aNewObject);
401 //=============================================================================
405 //=============================================================================
406 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::DivideEdge (GEOM::GEOM_Object_ptr theObject,
407 CORBA::Short theIndex,
408 CORBA::Double theValue,
409 CORBA::Boolean isByParameter)
411 GEOM::GEOM_Object_var aGEOMObject;
413 // Set a not done flag
414 GetOperations()->SetNotDone();
417 if (theValue < 0 || theValue > 1)
418 return aGEOMObject._retn();
420 // Get the object itself
421 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
422 if (anObject.IsNull())
423 return aGEOMObject._retn();
426 Handle(GEOM_Object) aNewObject =
427 GetOperations()->DivideEdge( anObject, theIndex, theValue, isByParameter );
428 if (!GetOperations()->IsDone() || aNewObject.IsNull())
429 return aGEOMObject._retn();
431 return GetObject(aNewObject);
434 //=============================================================================
438 //=============================================================================
439 GEOM::GEOM_Object_ptr
440 GEOM_IHealingOperations_i::DivideEdgeByPoint (GEOM::GEOM_Object_ptr theObject,
441 CORBA::Short theIndex,
442 GEOM::GEOM_Object_ptr thePoint)
444 GEOM::GEOM_Object_var aGEOMObject;
446 // Set a not done flag
447 GetOperations()->SetNotDone();
449 // Get the object itself
450 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
451 if (anObject.IsNull())
452 return aGEOMObject._retn();
455 Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint);
457 return aGEOMObject._retn();
460 Handle(GEOM_Object) aNewObject =
461 GetOperations()->DivideEdgeByPoint( anObject, theIndex, aPoint );
462 if (!GetOperations()->IsDone() || aNewObject.IsNull())
463 return aGEOMObject._retn();
465 return GetObject(aNewObject);
468 //=============================================================================
470 * FuseCollinearEdgesWithinWire
472 //=============================================================================
473 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::FuseCollinearEdgesWithinWire
474 (GEOM::GEOM_Object_ptr theWire,
475 const GEOM::ListOfGO& theVertices)
477 GEOM::GEOM_Object_var aGEOMObject;
479 //Set a not done flag
480 GetOperations()->SetNotDone();
482 //Get the reference objects
483 Handle(GEOM_Object) aWire = GetObjectImpl(theWire);
484 if (aWire.IsNull()) return aGEOMObject._retn();
487 std::list<Handle(GEOM_Object)> aVerts;
489 aLen = theVertices.length();
490 for (ind = 0; ind < aLen; ind++) {
491 Handle(GEOM_Object) aSh = GetObjectImpl(theVertices[ind]);
492 if (aSh.IsNull()) return aGEOMObject._retn();
493 aVerts.push_back(aSh);
497 Handle(GEOM_Object) anObject =
498 GetOperations()->FuseCollinearEdgesWithinWire(aWire, aVerts);
499 if (!GetOperations()->IsDone() || anObject.IsNull())
500 return aGEOMObject._retn();
502 return GetObject(anObject);
505 //=============================================================================
509 //=============================================================================
511 GEOM_IHealingOperations_i::GetFreeBoundary ( const GEOM::ListOfGO & theObjects,
512 GEOM::ListOfGO_out theClosedWires,
513 GEOM::ListOfGO_out theOpenWires )
515 theClosedWires = new GEOM::ListOfGO;
516 theOpenWires = new GEOM::ListOfGO;
518 // Set a not done flag
519 GetOperations()->SetNotDone();
522 Handle(TColStd_HSequenceOfTransient) anObjects = new TColStd_HSequenceOfTransient();
523 for ( size_t i = 0; i < theObjects.length(); ++i )
525 Handle(GEOM_Object) anObject = GetObjectImpl(theObjects[i]);
526 if (anObject.IsNull())
528 anObjects->Append( anObject );
531 Handle(TColStd_HSequenceOfTransient) aClosed = new TColStd_HSequenceOfTransient();
532 Handle(TColStd_HSequenceOfTransient) anOpen = new TColStd_HSequenceOfTransient();
533 bool res = GetOperations()->GetFreeBoundary( anObjects, aClosed, anOpen );
535 if ( !GetOperations()->IsDone() || !res )
538 int i, n = aClosed->Length();
539 theClosedWires->length( n );
540 for ( i = 1; i <= n; i++ )
541 (*theClosedWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(aClosed->Value(i)));
543 n = anOpen->Length();
544 theOpenWires->length( n );
545 for ( i = 1, n = anOpen->Length(); i <= n; i++ )
546 (*theOpenWires)[i-1] = GetObject(Handle(GEOM_Object)::DownCast(anOpen->Value(i)));
552 //=============================================================================
556 //=============================================================================
557 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientation (GEOM::GEOM_Object_ptr theObject)
559 GEOM::GEOM_Object_var aGEOMObject;
561 // Set a not done flag
562 GetOperations()->SetNotDone();
565 if ( CORBA::is_nil(theObject) )
566 return aGEOMObject._retn();
568 aGEOMObject = GEOM::GEOM_Object::_duplicate(theObject);
570 // Get the object itself
571 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
572 if (anObject.IsNull())
573 return aGEOMObject._retn();
576 // Handle(GEOM_Object) aNewObject =
577 GetOperations()->ChangeOrientation( anObject );
578 // if (!GetOperations()->IsDone() || aNewObject.IsNull())
579 // return aGEOMObject._retn();
581 //return GetObject(aNewObject);
582 return aGEOMObject._retn();
586 //=============================================================================
588 * ChangeOrientationCopy
590 //=============================================================================
591 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject)
593 GEOM::GEOM_Object_var aGEOMObject;
595 // Set a not done flag
596 GetOperations()->SetNotDone();
598 // Get the object itself
599 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
600 if (anObject.IsNull())
601 return aGEOMObject._retn();
604 Handle(GEOM_Object) aNewObject =
605 GetOperations()->ChangeOrientationCopy( anObject );
606 if (!GetOperations()->IsDone() || aNewObject.IsNull())
607 return aGEOMObject._retn();
609 return GetObject(aNewObject);
612 //=============================================================================
616 //=============================================================================
617 GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject,
618 CORBA::Double theTolerance)
620 GEOM::GEOM_Object_var aGEOMObject;
622 // Set a not done flag
623 GetOperations()->SetNotDone();
625 // Get the object itself
626 Handle(GEOM_Object) anObject = GetObjectImpl(theObject);
627 if (anObject.IsNull())
628 return aGEOMObject._retn();
631 Handle(GEOM_Object) aNewObject =
632 GetOperations()->LimitTolerance(anObject, theTolerance);
633 if (!GetOperations()->IsDone() || aNewObject.IsNull())
634 return aGEOMObject._retn();
636 return GetObject(aNewObject);