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
24 #pragma warning( disable:4786 )
27 #include <Standard_Version.hxx>
28 #include <Standard_Stream.hxx>
30 #include <GEOMImpl_IHealingOperations.hxx>
32 #include <GEOM_PythonDump.hxx>
34 #include <GEOMImpl_HealingDriver.hxx>
35 #include <GEOMImpl_Types.hxx>
36 #include <GEOMImpl_IHealing.hxx>
37 #include <GEOMImpl_IVector.hxx>
38 #include <GEOMImpl_VectorDriver.hxx>
39 #include <GEOMImpl_CopyDriver.hxx>
41 #include <Basics_OCCTVersion.hxx>
43 #include "utilities.h"
45 #include <Utils_ExceptHandlers.hxx>
47 #include <ShHealOper_ShapeProcess.hxx>
49 #include <ShapeAnalysis_FreeBounds.hxx>
51 #include <TopoDS_Compound.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <TColStd_HArray1OfExtendedString.hxx>
55 #include <TColStd_HSequenceOfTransient.hxx>
56 #include <TCollection_AsciiString.hxx>
58 #include <TDF_Tool.hxx>
60 #include <Standard_Failure.hxx>
61 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
63 //=============================================================================
67 //=============================================================================
68 GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations (GEOM_Engine* theEngine, int theDocID)
69 : GEOM_IOperations(theEngine, theDocID)
71 MESSAGE("GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations");
74 //=============================================================================
78 //=============================================================================
79 GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations()
81 MESSAGE("GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations");
85 //=============================================================================
89 //=============================================================================
90 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Object) theObject,
91 const Handle(TColStd_HArray1OfExtendedString)& theOperators,
92 const Handle(TColStd_HArray1OfExtendedString)& theParams,
93 const Handle(TColStd_HArray1OfExtendedString)& theValues)
95 // set error code, check parameters
98 if (theObject.IsNull())
101 if (theOperators.IsNull() || theOperators->Length() <= 0) {
102 SetErrorCode("No operators requested");
106 Standard_Integer nbParams = 0, nbValues = 0;
107 if (!theParams.IsNull()) {
108 nbParams = theParams->Length();
110 if (!theValues.IsNull()) {
111 nbValues = theValues->Length();
114 if (nbParams != nbValues) {
115 SetErrorCode("Number of parameter values must be equal to the number of parameters");
119 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
120 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
123 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
126 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SHAPE_PROCESS);
128 if (aFunction.IsNull()) return NULL;
130 //Check if the function is set correctly
131 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
133 // prepare "data container" class IHealing
134 GEOMImpl_IHealing HI(aFunction);
135 HI.SetOriginal(aLastFunction);
136 HI.SetOperators( theOperators );
138 HI.SetParameters( theParams );
139 HI.SetValues( theValues );
142 //Compute the translation
144 #if OCC_VERSION_LARGE > 0x06010000
147 if (!GetSolver()->ComputeFunction(aFunction))
149 SetErrorCode("Shape Healing algorithm failed");
153 catch (Standard_Failure)
155 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
156 SetErrorCode(aFail->GetMessageString());
160 //Make a Python command
161 GEOM::TPythonDump pd (aFunction);
162 pd << aNewObject << " = geompy.ProcessShape(" << theObject << ", [";
165 int i = theOperators->Lower(), nb = theOperators->Upper();
166 for ( ; i <= nb; i++) {
167 pd << "\"" << TCollection_AsciiString(theOperators->Value( i )).ToCString()
168 << (( i < nb ) ? "\", " : "\"");
171 // list of parameters
172 i = theParams->Lower(); nb = theParams->Upper();
173 for ( ; i <= nb; i++) {
174 pd << "\"" << TCollection_AsciiString(theParams->Value( i )).ToCString()
175 << (( i < nb ) ? "\", " : "\"");
179 i = theValues->Lower(); nb = theValues->Upper();
180 for ( ; i <= nb; i++) {
181 pd << "\"" << TCollection_AsciiString(theValues->Value( i )).ToCString()
182 << (( i < nb ) ? "\", " : "\"");
190 //=============================================================================
194 //=============================================================================
195 void GEOMImpl_IHealingOperations::GetShapeProcessParameters (std::list<std::string>& theOperations,
196 std::list<std::string>& theParams,
197 std::list<std::string>& theValues)
199 ShHealOper_ShapeProcess aHealer;
200 TColStd_SequenceOfAsciiString anOperators;
201 int nbOperatorErrors( 0 );
202 if ( aHealer.GetOperators( anOperators ) )
204 for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
206 std::string anOperation = anOperators.Value( i ).ToCString();
207 if ( GetOperatorParameters( anOperation, theParams, theValues ) )
208 theOperations.push_back( anOperation );
215 SetErrorCode("ERROR retrieving operators (GEOMImpl_IHealingOperations)");
218 if ( nbOperatorErrors ) {
219 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameters (GEOMImpl_IHealingOperations): nbOperatorErrors = ");
220 aMsg += TCollection_AsciiString( nbOperatorErrors );
221 MESSAGE(aMsg.ToCString());
225 //=============================================================================
227 * GetOperatorParameters
229 //=============================================================================
230 bool GEOMImpl_IHealingOperations::GetOperatorParameters( const std::string & theOperation,
231 std::list<std::string>& theParams,
232 std::list<std::string>& theValues )
234 ShHealOper_ShapeProcess aHealer;
235 int nbParamValueErrors( 0 );
236 std::list<std::string> aParams;
237 if ( GetParameters( theOperation, aParams ) ) {
238 for ( std::list<std::string>::iterator it = aParams.begin(); it != aParams.end(); ++it ) {
239 TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() );
240 TCollection_AsciiString aValue;
241 if ( aHealer.GetParameter( aParam, aValue ) ) {
242 theParams.push_back( aParam.ToCString() );
243 theValues.push_back( aValue.ToCString() );
246 nbParamValueErrors++;
252 if ( nbParamValueErrors ) {
253 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameter values (GEOMImpl_IHealingOperations): nbParamValueErrors = ");
254 aMsg += TCollection_AsciiString( nbParamValueErrors );
255 MESSAGE(aMsg.ToCString());
261 //=============================================================================
265 //=============================================================================
266 bool GEOMImpl_IHealingOperations::GetParameters (const std::string theOperation,
267 std::list<std::string>& theParams)
269 if ( theOperation == "SplitAngle" ) {
270 theParams.push_back( "SplitAngle.Angle" );
271 theParams.push_back( "SplitAngle.MaxTolerance" );
273 } else if ( theOperation == "SplitClosedFaces" ) {
274 theParams.push_back( "SplitClosedFaces.NbSplitPoints" );
276 } else if ( theOperation == "FixFaceSize" ) {
277 theParams.push_back( "FixFaceSize.Tolerance" );
279 } else if( theOperation == "DropSmallEdges" ) {
280 theParams.push_back( "DropSmallEdges.Tolerance3d" );
282 } else if( theOperation == "BSplineRestriction" ) {
283 theParams.push_back( "BSplineRestriction.SurfaceMode" );
284 theParams.push_back( "BSplineRestriction.Curve3dMode" );
285 theParams.push_back( "BSplineRestriction.Curve2dMode" );
286 theParams.push_back( "BSplineRestriction.Tolerance3d" );
287 theParams.push_back( "BSplineRestriction.Tolerance2d" );
288 theParams.push_back( "BSplineRestriction.RequiredDegree" );
289 theParams.push_back( "BSplineRestriction.RequiredNbSegments" );
290 theParams.push_back( "BSplineRestriction.Continuity3d" );
291 theParams.push_back( "BSplineRestriction.Continuity2d" );
293 } else if( theOperation == "SplitContinuity" ) {
294 theParams.push_back( "SplitContinuity.Tolerance3d" );
295 theParams.push_back( "SplitContinuity.SurfaceContinuity" );
296 theParams.push_back( "SplitContinuity.CurveContinuity" );
298 } else if( theOperation == "ToBezier" ) {
299 theParams.push_back( "ToBezier.SurfaceMode" );
300 theParams.push_back( "ToBezier.Curve3dMode" );
301 theParams.push_back( "ToBezier.Curve2dMode" );
302 theParams.push_back( "ToBezier.MaxTolerance" );
304 } else if( theOperation == "SameParameter" ) {
305 theParams.push_back( "SameParameter.Tolerance3d" );
307 } else if( theOperation == "FixShape" ) {
308 theParams.push_back( "FixShape.Tolerance3d" );
309 theParams.push_back( "FixShape.MaxTolerance3d" );
318 //=============================================================================
322 //=============================================================================
323 Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
324 (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theFaces)
326 // set error code, check parameters
329 if (theObject.IsNull()) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
332 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
333 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
336 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
339 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
341 if (aFunction.IsNull()) return NULL;
343 //Check if the function is set correctly
344 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
346 // prepare "data container" class IHealing
347 GEOMImpl_IHealing HI (aFunction);
348 HI.SetFaces(theFaces);
349 HI.SetOriginal(aLastFunction);
351 //Compute the translation
353 #if OCC_VERSION_LARGE > 0x06010000
356 if (!GetSolver()->ComputeFunction(aFunction))
358 SetErrorCode("Healing driver failed");
362 catch (Standard_Failure)
364 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
365 SetErrorCode(aFail->GetMessageString());
369 //Make a Python command
370 GEOM::TPythonDump pd (aFunction);
371 pd << aNewObject << " = geompy.SuppressFaces(" << theObject << ", [";
374 int i = theFaces->Lower(), nb = theFaces->Upper();
375 for ( ; i <= nb; i++)
376 pd << theFaces->Value( i ) << (( i < nb ) ? ", " : "])");
382 //=============================================================================
386 //=============================================================================
387 Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
388 (Handle(GEOM_Object) theObject,
389 const Handle(TColStd_HArray1OfInteger)& theWires,
392 // set error code, check parameters
395 if (theObject.IsNull())
397 SetErrorCode("NULL object given");
401 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
402 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
405 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
408 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CLOSE_CONTOUR);
410 if (aFunction.IsNull()) return NULL;
412 //Check if the function is set correctly
413 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
415 // prepare "data container" class IHealing
416 GEOMImpl_IHealing HI(aFunction);
417 HI.SetWires( theWires );
418 HI.SetIsCommonVertex( isCommonVertex );
419 HI.SetOriginal( aLastFunction );
421 //Compute the translation
423 #if OCC_VERSION_LARGE > 0x06010000
426 if (!GetSolver()->ComputeFunction(aFunction))
428 SetErrorCode("Healing driver failed");
432 catch (Standard_Failure)
434 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
435 SetErrorCode(aFail->GetMessageString());
439 //Make a Python command
440 GEOM::TPythonDump pd (aFunction);
441 pd << aNewObject << " = geompy.CloseContour(" << theObject << ", [";
444 if (!theWires.IsNull())
446 int i = theWires->Lower(), nb = theWires->Upper();
447 pd << theWires->Value(i++);
449 pd << ", " << theWires->Value(i++);
451 pd << "], " << (int)isCommonVertex << ")";
457 //=============================================================================
461 //=============================================================================
462 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires
463 (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theWires)
465 // set error code, check parameters
468 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL wires must be removed
471 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
472 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
475 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
478 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INT_WIRES);
480 if (aFunction.IsNull()) return NULL;
482 //Check if the function is set correctly
483 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
485 // prepare "data container" class IHealing
486 GEOMImpl_IHealing HI(aFunction);
487 HI.SetWires( theWires );
488 HI.SetOriginal( aLastFunction );
490 //Compute the translation
492 #if OCC_VERSION_LARGE > 0x06010000
495 if (!GetSolver()->ComputeFunction(aFunction))
497 SetErrorCode("Healing driver failed");
501 catch (Standard_Failure)
503 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
504 SetErrorCode(aFail->GetMessageString());
508 //Make a Python command
509 GEOM::TPythonDump pd (aFunction);
510 pd << aNewObject << " = geompy.SuppressInternalWires(" << theObject << ", [";
513 if (!theWires.IsNull()) {
514 int i = theWires->Lower(), nb = theWires->Upper();
515 for ( ; i <= nb; i++)
516 pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
525 //=============================================================================
529 //=============================================================================
530 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) theObject,
531 const Handle(TColStd_HArray1OfInteger)& theWires)
533 // set error code, check parameters
536 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL holes must be removed
539 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
540 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
543 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
546 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), FILL_HOLES);
548 if (aFunction.IsNull()) return NULL;
550 //Check if the function is set correctly
551 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
553 // prepare "data container" class IHealing
554 GEOMImpl_IHealing HI(aFunction);
555 HI.SetWires( theWires );
556 HI.SetOriginal( aLastFunction );
558 //Compute the translation
560 #if OCC_VERSION_LARGE > 0x06010000
563 if (!GetSolver()->ComputeFunction(aFunction))
565 SetErrorCode("Healing driver failed");
569 catch (Standard_Failure)
571 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
572 SetErrorCode(aFail->GetMessageString());
576 //Make a Python command
577 GEOM::TPythonDump pd (aFunction);
578 pd << aNewObject << " = geompy.SuppressHoles(" << theObject << ", [";
581 if ( theWires.IsNull() )
584 int i = theWires->Lower(), nb = theWires->Upper();
585 for ( ; i <= nb; i++)
586 pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
593 //=============================================================================
597 //=============================================================================
598 Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObject,
600 bool isAllowNonManifold)
602 // set error code, check parameters
605 if (theObject.IsNull())
608 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
609 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
612 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
615 int aFunctionType = (isAllowNonManifold ? SEWING_NON_MANIFOLD : SEWING);
617 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), aFunctionType);
619 if (aFunction.IsNull()) return NULL;
621 //Check if the function is set correctly
622 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
624 // prepare "data container" class IHealing
625 GEOMImpl_IHealing HI(aFunction);
626 HI.SetTolerance( theTolerance );
627 HI.SetOriginal( aLastFunction );
631 #if OCC_VERSION_LARGE > 0x06010000
634 if (!GetSolver()->ComputeFunction(aFunction))
636 SetErrorCode("Healing driver failed");
640 catch (Standard_Failure) {
641 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
642 SetErrorCode(aFail->GetMessageString());
646 //Make a Python command
647 GEOM::TPythonDump pd(aFunction);
649 pd << aNewObject << " = geompy.Sew(" << theObject << ", " << theTolerance;
651 if (isAllowNonManifold) {
661 //=============================================================================
663 * RemoveInternalFaces
665 //=============================================================================
666 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveInternalFaces (Handle(GEOM_Object) theObject)
668 // set error code, check parameters
671 if (theObject.IsNull())
674 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
675 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
678 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
681 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INTERNAL_FACES);
682 if (aFunction.IsNull()) return NULL;
684 //Check if the function is set correctly
685 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
687 // prepare "data container" class IHealing
688 GEOMImpl_IHealing HI (aFunction);
689 HI.SetOriginal(aLastFunction);
693 #if OCC_VERSION_LARGE > 0x06010000
696 if (!GetSolver()->ComputeFunction(aFunction))
698 SetErrorCode("Healing driver failed");
702 catch (Standard_Failure) {
703 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
704 SetErrorCode(aFail->GetMessageString());
708 //Make a Python command
709 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.RemoveInternalFaces(" << theObject << ")";
715 //=============================================================================
719 //=============================================================================
720 Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) theObject,
725 // set error code, check parameters
728 if (theObject.IsNull())
731 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
732 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
735 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
738 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE);
740 if (aFunction.IsNull()) return NULL;
742 //Check if the function is set correctly
743 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
745 // prepare "data container" class IHealing
746 GEOMImpl_IHealing HI(aFunction);
747 HI.SetIndex( theIndex );
748 HI.SetDevideEdgeValue( theValue );
749 HI.SetIsByParameter( isByParameter );
750 HI.SetOriginal( aLastFunction );
752 //Compute the translation
754 #if OCC_VERSION_LARGE > 0x06010000
757 if (!GetSolver()->ComputeFunction(aFunction)) {
758 SetErrorCode("Healing driver failed");
762 catch (Standard_Failure) {
763 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
764 SetErrorCode(aFail->GetMessageString());
768 //Make a Python command
769 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.DivideEdge(" << theObject
770 << ", " << theIndex << ", " << theValue << ", " << (int)isByParameter << ")";
776 //=============================================================================
778 * FuseCollinearEdgesWithinWire
780 //=============================================================================
781 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FuseCollinearEdgesWithinWire
782 (Handle(GEOM_Object) theWire,
783 std::list<Handle(GEOM_Object)> theVertices)
787 if (theWire.IsNull()) return NULL;
790 Handle(GEOM_Object) aRes = GetEngine()->AddObject(GetDocID(), theWire->GetType());
792 // Add a new function
793 Handle(GEOM_Function) aFunction;
794 aFunction = aRes->AddFunction(GEOMImpl_HealingDriver::GetID(), FUSE_COLLINEAR_EDGES);
795 if (aFunction.IsNull()) return NULL;
797 // Check if the function is set correctly
798 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
800 GEOMImpl_IHealing aCI (aFunction);
802 Handle(GEOM_Function) aRefShape = theWire->GetLastFunction();
803 if (aRefShape.IsNull()) return NULL;
804 aCI.SetOriginal(aRefShape);
806 Handle(TColStd_HSequenceOfTransient) aVertices = new TColStd_HSequenceOfTransient;
807 std::list<Handle(GEOM_Object)>::iterator it = theVertices.begin();
808 for (; it != theVertices.end(); it++) {
809 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
810 if (aRefSh.IsNull()) {
811 SetErrorCode("NULL argument shape for the shape construction");
814 aVertices->Append(aRefSh);
816 aCI.SetShapes(aVertices);
818 // Compute the new wire
820 #if OCC_VERSION_LARGE > 0x06010000
823 if (!GetSolver()->ComputeFunction(aFunction)) {
824 SetErrorCode("Healing driver failed");
828 catch (Standard_Failure) {
829 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
830 SetErrorCode(aFail->GetMessageString());
834 // Make a Python command
835 GEOM::TPythonDump pd (aFunction);
836 pd << aRes << " = geompy.FuseCollinearEdgesWithinWire(" << theWire << ", [";
838 it = theVertices.begin();
839 if (it != theVertices.end()) {
841 while (it != theVertices.end()) {
842 pd << ", " << (*it++);
851 //=============================================================================
855 //=============================================================================
856 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject,
857 Handle(TColStd_HSequenceOfTransient)& theClosed,
858 Handle(TColStd_HSequenceOfTransient)& theOpen )
860 // set error code, check parameters
863 if ( theObject.IsNull() || theClosed.IsNull() || theOpen.IsNull() )
866 TopoDS_Shape aShape = theObject->GetValue();
867 if ( aShape.IsNull() )
870 // get free boundary shapes
872 #if OCC_VERSION_LARGE > 0x06030008
873 ShapeAnalysis_FreeBounds anAnalizer(aShape, Standard_False,
874 Standard_True, Standard_True);
876 ShapeAnalysis_FreeBounds anAnalizer(aShape);
878 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
879 TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
881 // iterate through shapes and append them to the return sequence
882 Handle(GEOM_Object) anObj;
883 Handle(GEOM_Function) aFunction;
884 TopExp_Explorer anExp;
885 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() )
887 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
888 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
889 TopoDS_Shape aValueShape = anExp.Current();
890 aFunction->SetValue( aValueShape );
891 theClosed->Append(anObj);
893 for ( anExp.Init( anOpen, TopAbs_WIRE ); anExp.More(); anExp.Next() )
895 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
896 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
897 TopoDS_Shape aValueShape = anExp.Current();
898 aFunction->SetValue( aValueShape );
899 theOpen->Append(anObj);
902 if(!aFunction.IsNull()) {
904 //Make a Python command
905 GEOM::TPythonDump pd (aFunction);
907 Standard_Integer i, aLen = theClosed->Length();
910 for (i = 1; i <= aLen; i++) {
911 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i));
912 pd << anObj_i << ((i < aLen) ? ", " : "");
916 pd << "(isDone, empty_list, ";
919 aLen = theOpen->Length();
922 for (i = 1; i <= aLen; i++) {
923 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i));
924 pd << anObj_i << ((i < aLen) ? ", " : "");
931 pd << ") = geompy.GetFreeBoundary(" << theObject << ")";
939 //=============================================================================
943 //=============================================================================
944 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_Object) theObject)
946 // set error code, check parameters
949 if (theObject.IsNull())
952 if (!theObject->IsMainShape()) {
953 SetErrorCode("Sub-shape cannot be transformed - need to create a copy");
957 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
958 if (aLastFunction.IsNull())
959 return NULL; //There is no function which creates an object to be processed
961 if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066
963 aFunction = theObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE);
965 //Check if the function is set correctly
966 if (aFunction.IsNull()) return NULL;
967 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
969 // prepare "data container" class IVector
970 GEOMImpl_IVector aVI (aFunction);
971 aVI.SetCurve(aLastFunction);
975 aFunction = theObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
977 //Check if the function is set correctly
978 if (aFunction.IsNull()) return NULL;
979 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
981 // prepare "data container" class IHealing
982 GEOMImpl_IHealing HI (aFunction);
983 HI.SetOriginal(aLastFunction);
986 //Compute the translation
988 #if OCC_VERSION_LARGE > 0x06010000
991 if (!GetSolver()->ComputeFunction(aFunction)) {
992 SetErrorCode("Healing driver failed");
996 catch (Standard_Failure) {
997 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
998 SetErrorCode(aFail->GetMessageString());
1002 //Make a Python command
1003 GEOM::TPythonDump(aFunction) << "geompy.ChangeOrientationShell("
1004 << theObject << ")";
1010 //=============================================================================
1012 * ChangeOrientationCopy
1014 //=============================================================================
1015 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(GEOM_Object) theObject)
1017 // set error code, check parameters
1020 if (theObject.IsNull())
1023 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1024 if (aLastFunction.IsNull())
1025 return NULL; //There is no function which creates an object to be processed
1028 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1030 if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066
1032 aFunction = aNewObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE);
1034 //Check if the function is set correctly
1035 if (aFunction.IsNull()) return NULL;
1036 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
1038 // prepare "data container" class IVector
1039 GEOMImpl_IVector aVI (aFunction);
1040 aVI.SetCurve(aLastFunction);
1044 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
1046 //Check if the function is set correctly
1047 if (aFunction.IsNull()) return NULL;
1048 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
1050 // prepare "data container" class IHealing
1051 GEOMImpl_IHealing aHI (aFunction);
1052 aHI.SetOriginal(aLastFunction);
1055 // Compute the result
1057 #if OCC_VERSION_LARGE > 0x06010000
1060 if (!GetSolver()->ComputeFunction(aFunction)) {
1061 SetErrorCode("Healing driver failed");
1065 catch (Standard_Failure) {
1066 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1067 SetErrorCode(aFail->GetMessageString());
1071 //Make a Python command
1072 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.ChangeOrientationShellCopy("
1073 << theObject << ")";
1079 //=============================================================================
1083 //=============================================================================
1084 Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject,
1085 double theTolerance)
1087 // Set error code, check parameters
1090 if (theObject.IsNull())
1093 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1094 if (aLastFunction.IsNull())
1095 return NULL; // There is no function which creates an object to be processed
1098 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1101 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), LIMIT_TOLERANCE);
1103 if (aFunction.IsNull())
1106 // Check if the function is set correctly
1107 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
1109 // Prepare "data container" class IHealing
1110 GEOMImpl_IHealing HI (aFunction);
1111 HI.SetOriginal(aLastFunction);
1112 HI.SetTolerance(theTolerance);
1116 #if OCC_VERSION_LARGE > 0x06010000
1119 if (!GetSolver()->ComputeFunction(aFunction)) {
1120 SetErrorCode("Healing driver failed");
1124 catch (Standard_Failure) {
1125 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1126 SetErrorCode(aFail->GetMessageString());
1130 // Make a Python command
1131 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance("
1132 << theObject << ", " << theTolerance << ")";