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 );
145 if ( aHealer.GetOperators( anOperators ) )
147 for ( Standard_Integer i = 1; i <= anOperators.Length(); i++ )
149 string anOperation = anOperators.Value( i ).ToCString();
150 if ( GetOperatorParameters( anOperation, theParams, theValues ) )
151 theOperations.push_back( anOperation );
158 SetErrorCode("ERROR retrieving operators (GEOMImpl_IHealingOperations)");
161 if ( nbOperatorErrors ) {
162 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameters (GEOMImpl_IHealingOperations): nbOperatorErrors = ");
163 aMsg += TCollection_AsciiString( nbOperatorErrors );
164 MESSAGE(aMsg.ToCString());
168 //=============================================================================
170 * GetOperatorParameters
172 //=============================================================================
173 bool GEOMImpl_IHealingOperations::GetOperatorParameters( const string theOperation,
174 list<string>& theParams,
175 list<string>& theValues )
177 ShHealOper_ShapeProcess aHealer;
178 int nbParamValueErrors( 0 );
179 list<string> aParams;
180 if ( GetParameters( theOperation, aParams ) ) {
181 for ( list<string>::iterator it = aParams.begin(); it != aParams.end(); ++it ) {
182 TCollection_AsciiString aParam( (Standard_CString)(*it).c_str() );
183 TCollection_AsciiString aValue;
184 if ( aHealer.GetParameter( aParam, aValue ) ) {
185 theParams.push_back( aParam.ToCString() );
186 theValues.push_back( aValue.ToCString() );
189 nbParamValueErrors++;
195 if ( nbParamValueErrors ) {
196 TCollection_AsciiString aMsg ("ERRORS retrieving ShapeProcess parameter values (GEOMImpl_IHealingOperations): nbParamValueErrors = ");
197 aMsg += TCollection_AsciiString( nbParamValueErrors );
198 MESSAGE(aMsg.ToCString());
204 //=============================================================================
208 //=============================================================================
209 bool GEOMImpl_IHealingOperations::GetParameters (const string theOperation,
210 list<string>& theParams)
212 if ( theOperation == "SplitAngle" ) {
213 theParams.push_back( "SplitAngle.Angle" );
214 theParams.push_back( "SplitAngle.MaxTolerance" );
216 } else if ( theOperation == "SplitClosedFaces" ) {
217 theParams.push_back( "SplitClosedFaces.NbSplitPoints" );
219 } else if ( theOperation == "FixFaceSize" ) {
220 theParams.push_back( "FixFaceSize.Tolerance" );
222 } else if( theOperation == "DropSmallEdges" ) {
223 theParams.push_back( "DropSmallEdges.Tolerance3d" );
225 } else if( theOperation == "BSplineRestriction" ) {
226 theParams.push_back( "BSplineRestriction.SurfaceMode" );
227 theParams.push_back( "BSplineRestriction.Curve3dMode" );
228 theParams.push_back( "BSplineRestriction.Curve2dMode" );
229 theParams.push_back( "BSplineRestriction.Tolerance3d" );
230 theParams.push_back( "BSplineRestriction.Tolerance2d" );
231 theParams.push_back( "BSplineRestriction.RequiredDegree" );
232 theParams.push_back( "BSplineRestriction.RequiredNbSegments" );
233 theParams.push_back( "BSplineRestriction.Continuity3d" );
234 theParams.push_back( "BSplineRestriction.Continuity2d" );
236 } else if( theOperation == "SplitContinuity" ) {
237 theParams.push_back( "SplitContinuity.Tolerance3d" );
238 theParams.push_back( "SplitContinuity.SurfaceContinuity" );
239 theParams.push_back( "SplitContinuity.CurveContinuity" );
241 } else if( theOperation == "ToBezier" ) {
242 theParams.push_back( "ToBezier.SurfaceMode" );
243 theParams.push_back( "ToBezier.Curve3dMode" );
244 theParams.push_back( "ToBezier.Curve2dMode" );
245 theParams.push_back( "ToBezier.MaxTolerance" );
247 } else if( theOperation == "SameParameter" ) {
248 theParams.push_back( "SameParameter.Tolerance3d" );
250 } else if( theOperation == "FixShape" ) {
251 theParams.push_back( "FixShape.Tolerance3d" );
252 theParams.push_back( "FixShape.MaxTolerance3d" );
261 //=============================================================================
265 //=============================================================================
266 Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Object) theObject,
267 const Handle(TColStd_HArray1OfInteger)& theFaces)
269 // set error code, check parameters
272 if ( theObject.IsNull() ) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
275 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
276 if(aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
279 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
282 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
284 if(aFunction.IsNull()) return NULL;
286 //Check if the function is set correctly
287 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
289 // prepare "data container" class IHealing
290 GEOMImpl_IHealing HI(aFunction);
291 HI.SetFaces( theFaces );
292 HI.SetOriginal( aLastFunction );
294 //Compute the translation
297 if (!GetSolver()->ComputeFunction(aFunction))
299 SetErrorCode("Healing driver failed");
303 catch (Standard_Failure)
305 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
306 SetErrorCode(aFail->GetMessageString());
310 //Make a Python command
319 //=============================================================================
323 //=============================================================================
324 Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Object) theObject,
325 const Handle(TColStd_HArray1OfInteger)& theWires,
328 // set error code, check parameters
331 if (theObject.IsNull())
334 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
335 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
338 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
341 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), CLOSE_CONTOUR);
343 if (aFunction.IsNull()) return NULL;
345 //Check if the function is set correctly
346 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
348 // prepare "data container" class IHealing
349 GEOMImpl_IHealing HI(aFunction);
350 HI.SetWires( theWires );
351 HI.SetIsCommonVertex( isCommonVertex );
352 HI.SetOriginal( aLastFunction );
354 //Compute the translation
357 if (!GetSolver()->ComputeFunction(aFunction))
359 SetErrorCode("Healing driver failed");
363 catch (Standard_Failure)
365 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
366 SetErrorCode(aFail->GetMessageString());
370 //Make a Python command
378 //=============================================================================
382 //=============================================================================
383 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires (Handle(GEOM_Object) theObject,
384 const Handle(TColStd_HArray1OfInteger)& theWires)
386 // set error code, check parameters
389 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL wires must be removed
392 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
393 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
396 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
399 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INT_WIRES);
401 if (aFunction.IsNull()) return NULL;
403 //Check if the function is set correctly
404 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
406 // prepare "data container" class IHealing
407 GEOMImpl_IHealing HI(aFunction);
408 HI.SetWires( theWires );
409 HI.SetOriginal( aLastFunction );
411 //Compute the translation
414 if (!GetSolver()->ComputeFunction(aFunction))
416 SetErrorCode("Healing driver failed");
420 catch (Standard_Failure)
422 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
423 SetErrorCode(aFail->GetMessageString());
427 //Make a Python command
435 //=============================================================================
439 //=============================================================================
440 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) theObject,
441 const Handle(TColStd_HArray1OfInteger)& theWires)
443 // set error code, check parameters
446 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL holes must be removed
449 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
450 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
453 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
456 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), FILL_HOLES);
458 if (aFunction.IsNull()) return NULL;
460 //Check if the function is set correctly
461 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
463 // prepare "data container" class IHealing
464 GEOMImpl_IHealing HI(aFunction);
465 HI.SetWires( theWires );
466 HI.SetOriginal( aLastFunction );
468 //Compute the translation
471 if (!GetSolver()->ComputeFunction(aFunction))
473 SetErrorCode("Healing driver failed");
477 catch (Standard_Failure)
479 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
480 SetErrorCode(aFail->GetMessageString());
484 //Make a Python command
492 //=============================================================================
496 //=============================================================================
497 Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObject,
500 // set error code, check parameters
503 if (theObject.IsNull())
506 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
507 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
510 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
513 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SEWING);
515 if (aFunction.IsNull()) return NULL;
517 //Check if the function is set correctly
518 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
520 // prepare "data container" class IHealing
521 GEOMImpl_IHealing HI(aFunction);
522 HI.SetTolerance( theTolerance );
523 HI.SetOriginal( aLastFunction );
525 //Compute the translation
528 if (!GetSolver()->ComputeFunction(aFunction))
530 SetErrorCode("Healing driver failed");
534 catch (Standard_Failure)
536 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
537 SetErrorCode(aFail->GetMessageString());
541 //Make a Python command
549 //=============================================================================
553 //=============================================================================
554 Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) theObject,
559 // set error code, check parameters
562 if (theObject.IsNull())
565 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
566 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
569 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
572 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE);
574 if (aFunction.IsNull()) return NULL;
576 //Check if the function is set correctly
577 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
579 // prepare "data container" class IHealing
580 GEOMImpl_IHealing HI(aFunction);
581 HI.SetIndex( theIndex );
582 HI.SetDevideEdgeValue( theValue );
583 HI.SetIsByParameter( isByParameter );
584 HI.SetOriginal( aLastFunction );
586 //Compute the translation
589 if (!GetSolver()->ComputeFunction(aFunction))
591 SetErrorCode("Healing driver failed");
595 catch (Standard_Failure)
597 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
598 SetErrorCode(aFail->GetMessageString());
602 //Make a Python command
610 //=============================================================================
614 //=============================================================================
615 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject,
616 Handle(TColStd_HSequenceOfTransient)& theClosed,
617 Handle(TColStd_HSequenceOfTransient)& theOpen )
619 // set error code, check parameters
622 if ( theObject.IsNull() || theClosed.IsNull() || theOpen.IsNull() )
625 TopoDS_Shape aShape = theObject->GetValue();
626 if ( aShape.IsNull() )
629 // get free boundary shapes
630 ShapeAnalysis_FreeBounds anAnalizer( aShape );
631 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
632 TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
634 // iterate through shapes and append them to the return sequence
635 Handle(GEOM_Object) anObj;
636 Handle(GEOM_Function) aFunction;
637 TopExp_Explorer anExp;
638 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() )
640 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
641 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
642 TopoDS_Shape aValueShape = anExp.Current();
643 aFunction->SetValue( aValueShape );
644 theClosed->Append(anObj);
646 for ( anExp.Init( anOpen, TopAbs_WIRE ); anExp.More(); anExp.Next() )
648 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
649 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
650 TopoDS_Shape aValueShape = anExp.Current();
651 aFunction->SetValue( aValueShape );
652 theOpen->Append(anObj);