3 #include "GEOMImpl_IHealingOperations.hxx"
5 #include "GEOMImpl_HealingDriver.hxx"
6 #include "GEOMImpl_Types.hxx"
7 #include "GEOMImpl_IHealing.hxx"
8 #include "GEOMImpl_CopyDriver.hxx"
10 #include "ShHealOper_ShapeProcess.hxx"
12 #include "utilities.h"
14 #include "Utils_ExceptHandlers.hxx"
16 #include <ShapeAnalysis_FreeBounds.hxx>
18 #include <TopoDS_Compound.hxx>
19 #include <TopExp_Explorer.hxx>
21 #include <TColStd_HArray1OfExtendedString.hxx>
22 #include <TColStd_HSequenceOfTransient.hxx>
23 #include <TCollection_AsciiString.hxx>
25 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
28 //=============================================================================
32 //=============================================================================
34 GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations (GEOM_Engine* theEngine, int theDocID)
35 : GEOM_IOperations(theEngine, theDocID)
37 MESSAGE("GEOMImpl_IHealingOperations::GEOMImpl_IHealingOperations");
40 //=============================================================================
44 //=============================================================================
46 GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations()
48 MESSAGE("GEOMImpl_IHealingOperations::~GEOMImpl_IHealingOperations");
52 //=============================================================================
56 //=============================================================================
57 Handle(GEOM_Object) GEOMImpl_IHealingOperations::ShapeProcess (Handle(GEOM_Object) theObject,
58 const Handle(TColStd_HArray1OfExtendedString)& theOperators,
59 const Handle(TColStd_HArray1OfExtendedString)& theParams,
60 const Handle(TColStd_HArray1OfExtendedString)& theValues)
62 // set error code, check parameters
65 if (theObject.IsNull())
68 if (theOperators.IsNull() || theOperators->Length() <= 0) {
69 SetErrorCode("No operators requested");
73 Standard_Integer nbParams = 0, nbValues = 0;
74 if (!theParams.IsNull()) {
75 nbParams = theParams->Length();
77 if (!theValues.IsNull()) {
78 nbValues = theValues->Length();
81 if (nbParams != nbValues) {
82 SetErrorCode("Number of parameter values must be equal to the number of parameters");
86 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
87 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
90 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
93 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SHAPE_PROCESS);
95 if (aFunction.IsNull()) return NULL;
97 //Check if the function is set correctly
98 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
100 // prepare "data container" class IHealing
101 GEOMImpl_IHealing HI(aFunction);
102 HI.SetOriginal(aLastFunction);
103 HI.SetOperators( theOperators );
105 HI.SetParameters( theParams );
106 HI.SetValues( theValues );
109 //Compute the translation
112 if (!GetSolver()->ComputeFunction(aFunction))
114 SetErrorCode("Shape Healing algorithm failed");
118 catch (Standard_Failure)
120 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
121 SetErrorCode(aFail->GetMessageString());
125 //Make a Python command
133 //=============================================================================
137 //=============================================================================
138 void GEOMImpl_IHealingOperations::GetShapeProcessParameters (list<string>& theOperations,
139 list<string>& theParams,
140 list<string>& theValues)
142 ShHealOper_ShapeProcess aHealer;
143 TColStd_SequenceOfAsciiString anOperators;
144 int nbOperatorErrors( 0 ), nbParamValueErrors( 0 );
145 if ( aHealer.GetOperators( anOperators ) )
147 for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
149 string anOperation = anOperators.Value( i ).ToCString();
150 theOperations.push_back( anOperation );
151 list<string> aParams, aValues;
152 if ( GetParameters( anOperation, aParams ) )
154 for ( list<string>::iterator it = aParams.begin(); it != aParams.end(); ++it )
156 TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() );
157 TCollection_AsciiString aValue;
158 if ( aHealer.GetParameter( aParam, aValue ) )
160 theParams.push_back( aParam.ToCString() );
161 theValues.push_back( aValue.ToCString() );
164 nbParamValueErrors++;
173 SetErrorCode("ERROR retrieving operators (GEOMImpl_IHealingOperations)");
176 if (nbOperatorErrors || nbParamValueErrors) {
177 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameters (GEOMImpl_IHealingOperations): nbOperatorErrors = ");
178 aMsg += TCollection_AsciiString(nbOperatorErrors);
179 aMsg += " ,nbParamValueErrors = ";
180 aMsg += TCollection_AsciiString(nbParamValueErrors);
181 MESSAGE(aMsg.ToCString());
185 //=============================================================================
189 //=============================================================================
190 bool GEOMImpl_IHealingOperations::GetParameters (const string theOperation,
191 list<string>& theParams)
193 if ( theOperation == "SplitAngle" ) {
194 theParams.push_back( "SplitAngle.Angle" );
195 theParams.push_back( "SplitAngle.MaxTolerance" );
197 } else if ( theOperation == "SplitClosedFaces" ) {
198 theParams.push_back( "SplitClosedFaces.NbSplitPoints" );
200 } else if ( theOperation == "FixFaceSize" ) {
201 theParams.push_back( "FixFaceSize.Tolerance" );
203 } else if( theOperation == "DropSmallEdges" ) {
204 theParams.push_back( "DropSmallEdges.Tolerance3d" );
206 } else if( theOperation == "BSplineRestriction" ) {
207 theParams.push_back( "BSplineRestriction.SurfaceMode" );
208 theParams.push_back( "BSplineRestriction.Curve3dMode" );
209 theParams.push_back( "BSplineRestriction.Curve2dMode" );
210 theParams.push_back( "BSplineRestriction.Tolerance3d" );
211 theParams.push_back( "BSplineRestriction.Tolerance2d" );
212 theParams.push_back( "BSplineRestriction.RequiredDegree" );
213 theParams.push_back( "BSplineRestriction.RequiredNbSegments" );
214 theParams.push_back( "BSplineRestriction.Continuity3d" );
215 theParams.push_back( "BSplineRestriction.Continuity2d" );
217 } else if( theOperation == "SplitContinuity" ) {
218 theParams.push_back( "SplitContinuity.Tolerance3d" );
219 theParams.push_back( "SplitContinuity.SurfaceContinuity" );
220 theParams.push_back( "SplitContinuity.CurveContinuity" );
222 } else if( theOperation == "ToBezier" ) {
223 theParams.push_back( "ToBezier.SurfaceMode" );
224 theParams.push_back( "ToBezier.Curve3dMode" );
225 theParams.push_back( "ToBezier.Curve2dMode" );
226 theParams.push_back( "ToBezier.MaxTolerance" );
228 } else if( theOperation == "SameParameter" ) {
229 theParams.push_back( "SameParameter.Tolerance3d" );
231 } else if( theOperation == "FixShape" ) {
232 theParams.push_back( "FixShape.Tolerance3d" );
233 theParams.push_back( "FixShape.MaxTolerance3d" );
242 //=============================================================================
246 //=============================================================================
247 Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Object) theObject,
248 const Handle(TColStd_HArray1OfInteger)& theFaces)
250 // set error code, check parameters
253 if ( theObject.IsNull() ) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
256 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
257 if(aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
260 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
263 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
265 if(aFunction.IsNull()) return NULL;
267 //Check if the function is set correctly
268 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
270 // prepare "data container" class IHealing
271 GEOMImpl_IHealing HI(aFunction);
272 HI.SetFaces( theFaces );
273 HI.SetOriginal( aLastFunction );
275 //Compute the translation
278 if (!GetSolver()->ComputeFunction(aFunction))
280 SetErrorCode("Healing driver failed");
284 catch (Standard_Failure)
286 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
287 SetErrorCode(aFail->GetMessageString());
291 //Make a Python command
300 //=============================================================================
304 //=============================================================================
305 Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Object) theObject,
306 const Handle(TColStd_HArray1OfInteger)& theWires,
309 // set error code, check parameters
312 if (theObject.IsNull())
315 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
316 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
319 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
322 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CLOSE_CONTOUR);
324 if (aFunction.IsNull()) return NULL;
326 //Check if the function is set correctly
327 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
329 // prepare "data container" class IHealing
330 GEOMImpl_IHealing HI(aFunction);
331 HI.SetWires( theWires );
332 HI.SetIsCommonVertex( isCommonVertex );
333 HI.SetOriginal( aLastFunction );
335 //Compute the translation
338 if (!GetSolver()->ComputeFunction(aFunction))
340 SetErrorCode("Healing driver failed");
344 catch (Standard_Failure)
346 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
347 SetErrorCode(aFail->GetMessageString());
351 //Make a Python command
359 //=============================================================================
363 //=============================================================================
364 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires (Handle(GEOM_Object) theObject,
365 const Handle(TColStd_HArray1OfInteger)& theWires)
367 // set error code, check parameters
370 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL wires must be removed
373 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
374 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
377 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
380 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INT_WIRES);
382 if (aFunction.IsNull()) return NULL;
384 //Check if the function is set correctly
385 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
387 // prepare "data container" class IHealing
388 GEOMImpl_IHealing HI(aFunction);
389 HI.SetWires( theWires );
390 HI.SetOriginal( aLastFunction );
392 //Compute the translation
395 if (!GetSolver()->ComputeFunction(aFunction))
397 SetErrorCode("Healing driver failed");
401 catch (Standard_Failure)
403 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
404 SetErrorCode(aFail->GetMessageString());
408 //Make a Python command
416 //=============================================================================
420 //=============================================================================
421 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) theObject,
422 const Handle(TColStd_HArray1OfInteger)& theWires)
424 // set error code, check parameters
427 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL holes must be removed
430 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
431 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
434 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
437 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), FILL_HOLES);
439 if (aFunction.IsNull()) return NULL;
441 //Check if the function is set correctly
442 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
444 // prepare "data container" class IHealing
445 GEOMImpl_IHealing HI(aFunction);
446 HI.SetWires( theWires );
447 HI.SetOriginal( aLastFunction );
449 //Compute the translation
452 if (!GetSolver()->ComputeFunction(aFunction))
454 SetErrorCode("Healing driver failed");
458 catch (Standard_Failure)
460 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
461 SetErrorCode(aFail->GetMessageString());
465 //Make a Python command
473 //=============================================================================
477 //=============================================================================
478 Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObject,
481 // set error code, check parameters
484 if (theObject.IsNull())
487 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
488 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
491 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
494 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SEWING);
496 if (aFunction.IsNull()) return NULL;
498 //Check if the function is set correctly
499 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
501 // prepare "data container" class IHealing
502 GEOMImpl_IHealing HI(aFunction);
503 HI.SetTolerance( theTolerance );
504 HI.SetOriginal( aLastFunction );
506 //Compute the translation
509 if (!GetSolver()->ComputeFunction(aFunction))
511 SetErrorCode("Healing driver failed");
515 catch (Standard_Failure)
517 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
518 SetErrorCode(aFail->GetMessageString());
522 //Make a Python command
530 //=============================================================================
534 //=============================================================================
535 Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) theObject,
540 // set error code, check parameters
543 if (theObject.IsNull())
546 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
547 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
550 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
553 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE);
555 if (aFunction.IsNull()) return NULL;
557 //Check if the function is set correctly
558 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
560 // prepare "data container" class IHealing
561 GEOMImpl_IHealing HI(aFunction);
562 HI.SetIndex( theIndex );
563 HI.SetDevideEdgeValue( theValue );
564 HI.SetIsByParameter( isByParameter );
565 HI.SetOriginal( aLastFunction );
567 //Compute the translation
570 if (!GetSolver()->ComputeFunction(aFunction))
572 SetErrorCode("Healing driver failed");
576 catch (Standard_Failure)
578 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
579 SetErrorCode(aFail->GetMessageString());
583 //Make a Python command
591 //=============================================================================
595 //=============================================================================
596 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject,
597 Handle(TColStd_HSequenceOfTransient)& theClosed,
598 Handle(TColStd_HSequenceOfTransient)& theOpen )
600 // set error code, check parameters
603 if ( theObject.IsNull() || theClosed.IsNull() || theOpen.IsNull() )
606 TopoDS_Shape aShape = theObject->GetValue();
607 if ( aShape.IsNull() )
610 // get free boundary shapes
611 ShapeAnalysis_FreeBounds anAnalizer( aShape );
612 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
613 TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
615 // iterate through shapes and append them to the return sequence
616 Handle(GEOM_Object) anObj;
617 Handle(GEOM_Function) aFunction;
618 TopExp_Explorer anExp;
619 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() )
621 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
622 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
623 TopoDS_Shape aValueShape = anExp.Current();
624 aFunction->SetValue( aValueShape );
625 theClosed->Append(anObj);
627 for ( anExp.Init( anOpen, TopAbs_WIRE ); anExp.More(); anExp.Next() )
629 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
630 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
631 TopoDS_Shape aValueShape = anExp.Current();
632 aFunction->SetValue( aValueShape );
633 theOpen->Append(anObj);