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
24 #pragma warning( disable:4786 )
27 #include <Standard_Version.hxx>
29 #include <GEOMImpl_IHealingOperations.hxx>
30 #include <GEOM_PythonDump.hxx>
31 #include <GEOMImpl_HealingDriver.hxx>
32 #include <GEOMImpl_Types.hxx>
33 #include <GEOMImpl_IHealing.hxx>
34 #include <GEOMImpl_IVector.hxx>
35 #include <GEOMImpl_VectorDriver.hxx>
36 #include <GEOMImpl_CopyDriver.hxx>
37 #include <ShHealOper_ModifStats.hxx>
38 #include <ShHealOper_ShapeProcess.hxx>
40 #include <Basics_OCCTVersion.hxx>
42 #include <utilities.h>
44 #include <Utils_ExceptHandlers.hxx>
46 #include <BRep_Builder.hxx>
47 #include <ShapeAnalysis_FreeBounds.hxx>
48 #include <TColStd_HArray1OfExtendedString.hxx>
49 #include <TColStd_HSequenceOfTransient.hxx>
50 #include <TCollection_AsciiString.hxx>
51 #include <TopExp_Explorer.hxx>
52 #include <TopTools_SequenceOfShape.hxx>
53 #include <TopoDS_Compound.hxx>
55 #include <Standard_Failure.hxx>
56 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
58 //=============================================================================
62 //=============================================================================
63 GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations (GEOM_Engine* theEngine, int theDocID)
64 : GEOM_IOperations(theEngine, theDocID)
66 myModifStats = new ShHealOper_ModifStats;
67 MESSAGE("GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations");
70 //=============================================================================
74 //=============================================================================
75 GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations()
78 MESSAGE("GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations");
82 //=============================================================================
86 //=============================================================================
87 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Object) theObject,
88 const Handle(TColStd_HArray1OfExtendedString)& theOperators,
89 const Handle(TColStd_HArray1OfExtendedString)& theParams,
90 const Handle(TColStd_HArray1OfExtendedString)& theValues)
92 // set error code, check parameters
95 if (theObject.IsNull())
98 if (theOperators.IsNull() || theOperators->Length() <= 0) {
99 SetErrorCode("No operators requested");
103 Standard_Integer nbParams = 0, nbValues = 0;
104 if (!theParams.IsNull()) {
105 nbParams = theParams->Length();
107 if (!theValues.IsNull()) {
108 nbValues = theValues->Length();
111 if (nbParams != nbValues) {
112 SetErrorCode("Number of parameter values must be equal to the number of parameters");
116 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
117 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
120 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
123 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SHAPE_PROCESS);
125 if (aFunction.IsNull()) return NULL;
127 //Check if the function is set correctly
128 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
130 // prepare "data container" class IHealing
131 GEOMImpl_IHealing HI(aFunction);
132 HI.SetOriginal(aLastFunction);
133 HI.SetOperators( theOperators );
135 HI.SetParameters( theParams );
136 HI.SetValues( theValues );
138 HI.SetStatistics( myModifStats );
140 //Compute the translation
143 if (!GetSolver()->ComputeFunction(aFunction))
145 SetErrorCode("Shape Healing algorithm failed");
149 catch (Standard_Failure)
151 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
152 SetErrorCode(aFail->GetMessageString());
156 //Make a Python command
157 GEOM::TPythonDump pd (aFunction);
158 pd << aNewObject << " = geompy.ProcessShape(" << theObject << ", [";
161 int i = theOperators->Lower(), nb = theOperators->Upper();
162 for ( ; i <= nb; i++) {
163 pd << "\"" << TCollection_AsciiString(theOperators->Value( i )).ToCString()
164 << (( i < nb ) ? "\", " : "\"");
167 // list of parameters
168 i = theParams->Lower(); nb = theParams->Upper();
169 for ( ; i <= nb; i++) {
170 pd << "\"" << TCollection_AsciiString(theParams->Value( i )).ToCString()
171 << (( i < nb ) ? "\", " : "\"");
175 i = theValues->Lower(); nb = theValues->Upper();
176 for ( ; i <= nb; i++) {
177 pd << "\"" << TCollection_AsciiString(theValues->Value( i )).ToCString()
178 << (( i < nb ) ? "\", " : "\"");
186 //=============================================================================
190 //=============================================================================
191 void GEOMImpl_IHealingOperations::GetShapeProcessParameters (std::list<std::string>& theOperations,
192 std::list<std::string>& theParams,
193 std::list<std::string>& theValues)
195 ShHealOper_ShapeProcess aHealer;
196 TColStd_SequenceOfAsciiString anOperators;
197 int nbOperatorErrors( 0 );
198 if ( aHealer.GetOperators( anOperators ) )
200 for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
202 std::string anOperation = anOperators.Value( i ).ToCString();
203 if ( GetOperatorParameters( anOperation, theParams, theValues ) )
204 theOperations.push_back( anOperation );
211 SetErrorCode("ERROR retrieving operators (GEOMImpl_IHealingOperations)");
214 if ( nbOperatorErrors ) {
215 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameters (GEOMImpl_IHealingOperations): nbOperatorErrors = ");
216 aMsg += TCollection_AsciiString( nbOperatorErrors );
217 MESSAGE(aMsg.ToCString());
221 //=============================================================================
223 * GetOperatorParameters
225 //=============================================================================
226 bool GEOMImpl_IHealingOperations::GetOperatorParameters( const std::string & theOperation,
227 std::list<std::string>& theParams,
228 std::list<std::string>& theValues )
230 ShHealOper_ShapeProcess aHealer;
231 int nbParamValueErrors( 0 );
232 std::list<std::string> aParams;
233 if ( GetParameters( theOperation, aParams ) ) {
234 for ( std::list<std::string>::iterator it = aParams.begin(); it != aParams.end(); ++it ) {
235 TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() );
236 TCollection_AsciiString aValue;
237 if ( aHealer.GetParameter( aParam, aValue ) ) {
238 theParams.push_back( aParam.ToCString() );
239 theValues.push_back( aValue.ToCString() );
242 nbParamValueErrors++;
248 if ( nbParamValueErrors ) {
249 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameter values (GEOMImpl_IHealingOperations): nbParamValueErrors = ");
250 aMsg += TCollection_AsciiString( nbParamValueErrors );
251 MESSAGE(aMsg.ToCString());
257 //=============================================================================
261 //=============================================================================
262 bool GEOMImpl_IHealingOperations::GetParameters (const std::string theOperation,
263 std::list<std::string>& theParams)
265 if ( theOperation == "SplitAngle" ) {
266 theParams.push_back( "SplitAngle.Angle" );
267 theParams.push_back( "SplitAngle.MaxTolerance" );
269 } else if ( theOperation == "SplitClosedFaces" ) {
270 theParams.push_back( "SplitClosedFaces.NbSplitPoints" );
272 } else if ( theOperation == "FixFaceSize" ) {
273 theParams.push_back( "FixFaceSize.Tolerance" );
275 } else if( theOperation == "DropSmallEdges" ) {
276 theParams.push_back( "DropSmallEdges.Tolerance3d" );
278 } else if( theOperation == "BSplineRestriction" ) {
279 theParams.push_back( "BSplineRestriction.SurfaceMode" );
280 theParams.push_back( "BSplineRestriction.Curve3dMode" );
281 theParams.push_back( "BSplineRestriction.Curve2dMode" );
282 theParams.push_back( "BSplineRestriction.Tolerance3d" );
283 theParams.push_back( "BSplineRestriction.Tolerance2d" );
284 theParams.push_back( "BSplineRestriction.RequiredDegree" );
285 theParams.push_back( "BSplineRestriction.RequiredNbSegments" );
286 theParams.push_back( "BSplineRestriction.Continuity3d" );
287 theParams.push_back( "BSplineRestriction.Continuity2d" );
289 } else if( theOperation == "SplitContinuity" ) {
290 theParams.push_back( "SplitContinuity.Tolerance3d" );
291 theParams.push_back( "SplitContinuity.SurfaceContinuity" );
292 theParams.push_back( "SplitContinuity.CurveContinuity" );
294 } else if( theOperation == "ToBezier" ) {
295 theParams.push_back( "ToBezier.SurfaceMode" );
296 theParams.push_back( "ToBezier.Curve3dMode" );
297 theParams.push_back( "ToBezier.Curve2dMode" );
298 theParams.push_back( "ToBezier.MaxTolerance" );
300 } else if( theOperation == "SameParameter" ) {
301 theParams.push_back( "SameParameter.Tolerance3d" );
303 } else if( theOperation == "FixShape" ) {
304 theParams.push_back( "FixShape.Tolerance3d" );
305 theParams.push_back( "FixShape.MaxTolerance3d" );
314 //=============================================================================
318 //=============================================================================
319 Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces
320 (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theFaces)
322 // set error code, check parameters
325 if (theObject.IsNull()) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
328 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
329 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
332 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
335 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
337 if (aFunction.IsNull()) return NULL;
339 //Check if the function is set correctly
340 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
342 // prepare "data container" class IHealing
343 GEOMImpl_IHealing HI (aFunction);
344 HI.SetFaces(theFaces);
345 HI.SetOriginal(aLastFunction);
346 HI.SetStatistics( myModifStats );
348 //Compute the translation
351 if (!GetSolver()->ComputeFunction(aFunction))
353 SetErrorCode("Healing driver failed");
357 catch (Standard_Failure)
359 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
360 SetErrorCode(aFail->GetMessageString());
364 //Make a Python command
365 GEOM::TPythonDump pd (aFunction);
366 pd << aNewObject << " = geompy.SuppressFaces(" << theObject << ", [";
369 int i = theFaces->Lower(), nb = theFaces->Upper();
370 for ( ; i <= nb; i++)
371 pd << theFaces->Value( i ) << (( i < nb ) ? ", " : "])");
377 //=============================================================================
381 //=============================================================================
382 Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour
383 (Handle(GEOM_Object) theObject,
384 const Handle(TColStd_HArray1OfInteger)& theWires,
387 // set error code, check parameters
390 if (theObject.IsNull())
392 SetErrorCode("NULL object given");
396 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
397 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
400 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
403 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CLOSE_CONTOUR);
405 if (aFunction.IsNull()) return NULL;
407 //Check if the function is set correctly
408 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
410 // prepare "data container" class IHealing
411 GEOMImpl_IHealing HI(aFunction);
412 HI.SetWires( theWires );
413 HI.SetIsCommonVertex( isCommonVertex );
414 HI.SetOriginal( aLastFunction );
415 HI.SetStatistics( myModifStats );
417 //Compute the translation
420 if (!GetSolver()->ComputeFunction(aFunction))
422 SetErrorCode("Healing driver failed");
426 catch (Standard_Failure)
428 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
429 SetErrorCode(aFail->GetMessageString());
433 //Make a Python command
434 GEOM::TPythonDump pd (aFunction);
435 pd << aNewObject << " = geompy.CloseContour(" << theObject << ", [";
438 if (!theWires.IsNull())
440 int i = theWires->Lower(), nb = theWires->Upper();
441 pd << theWires->Value(i++);
443 pd << ", " << theWires->Value(i++);
445 pd << "], " << (int)isCommonVertex << ")";
451 //=============================================================================
455 //=============================================================================
456 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires
457 (Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theWires)
459 // set error code, check parameters
462 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL wires must be removed
465 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
466 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
469 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
472 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INT_WIRES);
474 if (aFunction.IsNull()) return NULL;
476 //Check if the function is set correctly
477 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
479 // prepare "data container" class IHealing
480 GEOMImpl_IHealing HI(aFunction);
481 HI.SetWires( theWires );
482 HI.SetOriginal( aLastFunction );
483 HI.SetStatistics( myModifStats );
485 //Compute the translation
488 if (!GetSolver()->ComputeFunction(aFunction))
490 SetErrorCode("Healing driver failed");
494 catch (Standard_Failure)
496 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
497 SetErrorCode(aFail->GetMessageString());
501 //Make a Python command
502 GEOM::TPythonDump pd (aFunction);
503 pd << aNewObject << " = geompy.SuppressInternalWires(" << theObject << ", [";
506 if (!theWires.IsNull()) {
507 int i = theWires->Lower(), nb = theWires->Upper();
508 for ( ; i <= nb; i++)
509 pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
518 //=============================================================================
522 //=============================================================================
523 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) theObject,
524 const Handle(TColStd_HArray1OfInteger)& theWires)
526 // set error code, check parameters
529 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL holes must be removed
532 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
533 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
536 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
539 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), FILL_HOLES);
541 if (aFunction.IsNull()) return NULL;
543 //Check if the function is set correctly
544 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
546 // prepare "data container" class IHealing
547 GEOMImpl_IHealing HI(aFunction);
548 HI.SetWires( theWires );
549 HI.SetOriginal( aLastFunction );
550 HI.SetStatistics( myModifStats );
552 //Compute the translation
555 if (!GetSolver()->ComputeFunction(aFunction))
557 SetErrorCode("Healing driver failed");
561 catch (Standard_Failure)
563 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
564 SetErrorCode(aFail->GetMessageString());
568 //Make a Python command
569 GEOM::TPythonDump pd (aFunction);
570 pd << aNewObject << " = geompy.SuppressHoles(" << theObject << ", [";
573 if ( theWires.IsNull() )
576 int i = theWires->Lower(), nb = theWires->Upper();
577 for ( ; i <= nb; i++)
578 pd << theWires->Value( i ) << (( i < nb ) ? ", " : "])");
585 //=============================================================================
589 //=============================================================================
591 GEOMImpl_IHealingOperations::Sew (std::list<Handle(GEOM_Object)>& theObjects,
593 bool isAllowNonManifold)
595 // set error code, check parameters
598 if (theObjects.empty())
601 Handle(TColStd_HSequenceOfTransient) objects =
602 GEOM_Object::GetLastFunctions( theObjects );
603 if ( objects.IsNull() || objects->IsEmpty() ) {
604 SetErrorCode("NULL argument shape");
609 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
612 int aFunctionType = (isAllowNonManifold ? SEWING_NON_MANIFOLD : SEWING);
613 Handle(GEOM_Function) aFunction =
614 aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), aFunctionType);
615 if (aFunction.IsNull()) return NULL;
617 //Check if the function is set correctly
618 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
620 // prepare "data container" class IHealing
621 GEOMImpl_IHealing HI(aFunction);
622 HI.SetTolerance( theTolerance );
623 HI.SetOriginal( theObjects.front()->GetLastFunction() ); objects->Remove(1);
624 HI.SetShapes( objects );
625 HI.SetStatistics( myModifStats );
630 if (!GetSolver()->ComputeFunction(aFunction))
632 SetErrorCode("Healing driver failed");
636 catch (Standard_Failure) {
637 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
638 SetErrorCode(aFail->GetMessageString());
642 //Make a Python command
643 GEOM::TPythonDump pd(aFunction);
645 pd << aNewObject << " = geompy.Sew(" << theObjects << ", " << theTolerance;
647 if (isAllowNonManifold) {
657 //=============================================================================
659 * RemoveInternalFaces
661 //=============================================================================
663 GEOMImpl_IHealingOperations::RemoveInternalFaces (std::list< Handle(GEOM_Object)> & theSolids)
665 // set error code, check parameters
668 if (theSolids.empty())
671 Handle(TColStd_HSequenceOfTransient) objects = GEOM_Object::GetLastFunctions( theSolids );
672 if ( objects.IsNull() || objects->IsEmpty() ) {
673 SetErrorCode("NULL argument shape");
678 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), GEOM_COPY);
681 Handle(GEOM_Function)
682 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INTERNAL_FACES);
683 if (aFunction.IsNull()) return NULL;
685 //Check if the function is set correctly
686 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
688 // prepare "data container" class IHealing
689 GEOMImpl_IHealing HI (aFunction);
690 HI.SetOriginal( theSolids.front()->GetLastFunction() ); objects->Remove(1);
691 HI.SetShapes( objects );
692 HI.SetStatistics( myModifStats );
697 if (!GetSolver()->ComputeFunction(aFunction))
699 SetErrorCode("Healing driver failed");
703 catch (Standard_Failure) {
704 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
705 SetErrorCode(aFail->GetMessageString());
709 //Make a Python command
710 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.RemoveInternalFaces(" << theSolids << ")";
716 //=============================================================================
720 //=============================================================================
721 Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) theObject,
726 // set error code, check parameters
729 if (theObject.IsNull())
732 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
733 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
736 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
739 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE);
741 if (aFunction.IsNull()) return NULL;
743 //Check if the function is set correctly
744 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
746 // prepare "data container" class IHealing
747 GEOMImpl_IHealing HI(aFunction);
748 HI.SetIndex( theIndex );
749 HI.SetDevideEdgeValue( theValue );
750 HI.SetIsByParameter( isByParameter );
751 HI.SetOriginal( aLastFunction );
752 HI.SetStatistics( myModifStats );
754 //Compute the translation
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 //=============================================================================
780 //=============================================================================
782 GEOMImpl_IHealingOperations::DivideEdgeByPoint (Handle(GEOM_Object) theObject,
784 std::list< Handle(GEOM_Object)> & thePoints)
786 // set error code, check parameters
789 if (theObject.IsNull() || thePoints.empty() )
792 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
793 if (aLastFunction.IsNull() )
794 return NULL; //There is no function which creates an object to be processed
796 Handle(TColStd_HSequenceOfTransient) aPointFunc = GEOM_Object::GetLastFunctions( thePoints );
797 if ( aPointFunc.IsNull() || aPointFunc->IsEmpty() ) {
798 SetErrorCode("NULL argument points");
803 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
806 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE_BY_POINT);
808 if (aFunction.IsNull()) return NULL;
810 //Check if the function is set correctly
811 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
813 // prepare "data container" class IHealing
814 GEOMImpl_IHealing HI(aFunction);
815 HI.SetIndex ( theIndex );
816 HI.SetOriginal ( aLastFunction );
817 HI.SetShapes ( aPointFunc );
819 HI.SetStatistics( myModifStats );
821 //Compute the translation
824 if (!GetSolver()->ComputeFunction(aFunction)) {
825 SetErrorCode("Healing driver failed");
829 catch (Standard_Failure) {
830 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
831 SetErrorCode(aFail->GetMessageString());
835 //Make a Python command
836 GEOM::TPythonDump(aFunction)
837 << aNewObject << " = geompy.DivideEdgeByPoint(" << theObject
838 << ", " << theIndex << ", " << thePoints << ")";
844 //=============================================================================
846 * FuseCollinearEdgesWithinWire
848 //=============================================================================
849 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FuseCollinearEdgesWithinWire
850 (Handle(GEOM_Object) theWire,
851 std::list<Handle(GEOM_Object)> theVertices)
855 if (theWire.IsNull()) return NULL;
858 Handle(GEOM_Object) aRes = GetEngine()->AddObject(GetDocID(), theWire->GetType());
860 // Add a new function
861 Handle(GEOM_Function) aFunction;
862 aFunction = aRes->AddFunction(GEOMImpl_HealingDriver::GetID(), FUSE_COLLINEAR_EDGES);
863 if (aFunction.IsNull()) return NULL;
865 // Check if the function is set correctly
866 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
868 GEOMImpl_IHealing aCI (aFunction);
869 aCI.SetStatistics( myModifStats );
871 Handle(GEOM_Function) aRefShape = theWire->GetLastFunction();
872 if (aRefShape.IsNull()) return NULL;
873 aCI.SetOriginal(aRefShape);
875 Handle(TColStd_HSequenceOfTransient) aVertices = new TColStd_HSequenceOfTransient;
876 std::list<Handle(GEOM_Object)>::iterator it = theVertices.begin();
877 for (; it != theVertices.end(); it++) {
878 Handle(GEOM_Function) aRefSh = (*it)->GetLastFunction();
879 if (aRefSh.IsNull()) {
880 SetErrorCode("NULL argument shape for the shape construction");
883 aVertices->Append(aRefSh);
885 aCI.SetShapes(aVertices);
887 // Compute the new wire
890 if (!GetSolver()->ComputeFunction(aFunction)) {
891 SetErrorCode("Healing driver failed");
895 catch (Standard_Failure) {
896 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
897 SetErrorCode(aFail->GetMessageString());
901 // Make a Python command
902 GEOM::TPythonDump pd (aFunction);
903 pd << aRes << " = geompy.FuseCollinearEdgesWithinWire(" << theWire << ", [";
905 it = theVertices.begin();
906 if (it != theVertices.end()) {
908 while (it != theVertices.end()) {
909 pd << ", " << (*it++);
918 //=============================================================================
922 //=============================================================================
923 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(TColStd_HSequenceOfTransient)& theObjects,
924 Handle(TColStd_HSequenceOfTransient)& theClosed,
925 Handle(TColStd_HSequenceOfTransient)& theOpen )
927 // set error code, check parameters
930 if ( theObjects.IsNull() || theObjects->Length() == 0 ||
931 theClosed.IsNull() || theOpen.IsNull() )
935 TopTools_SequenceOfShape shapes;
936 for ( int ind = 1; ind <= theObjects->Length(); ind++)
938 Handle(GEOM_Object) aRefShape = Handle(GEOM_Object)::DownCast( theObjects->Value(ind));
939 if ( aRefShape.IsNull() )
941 aShape = aRefShape->GetValue();
942 if ( aShape.IsNull() )
944 shapes.Append( aShape );
947 if ( shapes.Length() > 1 )
949 TopoDS_Compound compound;
950 BRep_Builder builder;
951 builder.MakeCompound( compound );
952 for ( int i = 1; i <= shapes.Length(); ++i )
953 builder.Add( compound, shapes( i ) );
958 // get free boundary shapes
960 ShapeAnalysis_FreeBounds anAnalizer(aShape, Standard_False,
961 Standard_True, Standard_True);
962 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
963 TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
965 // iterate through shapes and append them to the return sequence
966 Handle(GEOM_Object) anObj;
967 Handle(GEOM_Function) aFunction;
968 TopExp_Explorer anExp;
969 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() )
971 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
972 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
973 TopoDS_Shape aValueShape = anExp.Current();
974 aFunction->SetValue( aValueShape );
975 theClosed->Append(anObj);
977 for ( anExp.Init( anOpen, TopAbs_WIRE ); anExp.More(); anExp.Next() )
979 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
980 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
981 TopoDS_Shape aValueShape = anExp.Current();
982 aFunction->SetValue( aValueShape );
983 theOpen->Append(anObj);
986 if(!aFunction.IsNull()) {
988 //Make a Python command
989 GEOM::TPythonDump pd (aFunction);
991 Standard_Integer i, aLen = theClosed->Length();
994 for (i = 1; i <= aLen; i++) {
995 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theClosed->Value(i));
996 pd << anObj_i << ((i < aLen) ? ", " : "");
1000 pd << "(isDone, empty_list, ";
1003 aLen = theOpen->Length();
1006 for (i = 1; i <= aLen; i++) {
1007 Handle(GEOM_Object) anObj_i = Handle(GEOM_Object)::DownCast(theOpen->Value(i));
1008 pd << anObj_i << ((i < aLen) ? ", " : "");
1015 pd << ") = geompy.GetFreeBoundary(" << theObjects << ")";
1023 //=============================================================================
1027 //=============================================================================
1028 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_Object) theObject)
1030 // set error code, check parameters
1033 if (theObject.IsNull())
1036 if (!theObject->IsMainShape()) {
1037 SetErrorCode("Sub-shape cannot be transformed - need to create a copy");
1041 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1042 if (aLastFunction.IsNull())
1043 return NULL; //There is no function which creates an object to be processed
1045 if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066
1047 aFunction = theObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE);
1049 //Check if the function is set correctly
1050 if (aFunction.IsNull()) return NULL;
1051 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
1053 // prepare "data container" class IVector
1054 GEOMImpl_IVector aVI (aFunction);
1055 aVI.SetCurve(aLastFunction);
1057 myModifStats->Clear();
1058 myModifStats->AddModif( "Vector reversed" );
1062 aFunction = theObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
1064 //Check if the function is set correctly
1065 if (aFunction.IsNull()) return NULL;
1066 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
1068 // prepare "data container" class IHealing
1069 GEOMImpl_IHealing HI (aFunction);
1070 HI.SetOriginal(aLastFunction);
1071 HI.SetStatistics( myModifStats );
1074 //Compute the translation
1077 if (!GetSolver()->ComputeFunction(aFunction)) {
1078 SetErrorCode("Healing driver failed");
1082 catch (Standard_Failure) {
1083 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1084 SetErrorCode(aFail->GetMessageString());
1088 //Make a Python command
1089 GEOM::TPythonDump(aFunction) << "geompy.ChangeOrientationShell("
1090 << theObject << ")";
1096 //=============================================================================
1098 * ChangeOrientationCopy
1100 //=============================================================================
1101 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(GEOM_Object) theObject)
1103 // set error code, check parameters
1106 if (theObject.IsNull())
1109 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1110 if (aLastFunction.IsNull())
1111 return NULL; //There is no function which creates an object to be processed
1114 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1116 if (theObject->GetType() == GEOM_VECTOR) { // Mantis issue 21066
1118 aFunction = aNewObject->AddFunction(GEOMImpl_VectorDriver::GetID(), VECTOR_REVERSE);
1120 //Check if the function is set correctly
1121 if (aFunction.IsNull()) return NULL;
1122 if (aFunction->GetDriverGUID() != GEOMImpl_VectorDriver::GetID()) return NULL;
1124 // prepare "data container" class IVector
1125 GEOMImpl_IVector aVI (aFunction);
1126 aVI.SetCurve(aLastFunction);
1128 myModifStats->Clear();
1129 myModifStats->AddModif( "Vector reversed" );
1133 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CHANGE_ORIENTATION);
1135 //Check if the function is set correctly
1136 if (aFunction.IsNull()) return NULL;
1137 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
1139 // prepare "data container" class IHealing
1140 GEOMImpl_IHealing aHI (aFunction);
1141 aHI.SetOriginal(aLastFunction);
1142 aHI.SetStatistics( myModifStats );
1145 // Compute the result
1148 if (!GetSolver()->ComputeFunction(aFunction)) {
1149 SetErrorCode("Healing driver failed");
1153 catch (Standard_Failure) {
1154 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1155 SetErrorCode(aFail->GetMessageString());
1159 //Make a Python command
1160 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.ChangeOrientationShellCopy("
1161 << theObject << ")";
1167 //=============================================================================
1171 //=============================================================================
1172 Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject,
1173 double theTolerance)
1175 // Set error code, check parameters
1178 if (theObject.IsNull())
1181 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
1182 if (aLastFunction.IsNull())
1183 return NULL; // There is no function which creates an object to be processed
1186 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType());
1189 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), LIMIT_TOLERANCE);
1191 if (aFunction.IsNull())
1194 // Check if the function is set correctly
1195 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
1197 // Prepare "data container" class IHealing
1198 GEOMImpl_IHealing HI (aFunction);
1199 HI.SetOriginal(aLastFunction);
1200 HI.SetTolerance(theTolerance);
1201 HI.SetStatistics( myModifStats );
1206 if (!GetSolver()->ComputeFunction(aFunction)) {
1207 SetErrorCode("Healing driver failed");
1211 catch (Standard_Failure) {
1212 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1213 SetErrorCode(aFail->GetMessageString());
1217 // Make a Python command
1218 GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance("
1219 << theObject << ", " << theTolerance << ")";