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());
202 //=============================================================================
206 //=============================================================================
207 bool GEOMImpl_IHealingOperations::GetParameters (const string theOperation,
208 list<string>& theParams)
210 if ( theOperation == "SplitAngle" ) {
211 theParams.push_back( "SplitAngle.Angle" );
212 theParams.push_back( "SplitAngle.MaxTolerance" );
214 } else if ( theOperation == "SplitClosedFaces" ) {
215 theParams.push_back( "SplitClosedFaces.NbSplitPoints" );
217 } else if ( theOperation == "FixFaceSize" ) {
218 theParams.push_back( "FixFaceSize.Tolerance" );
220 } else if( theOperation == "DropSmallEdges" ) {
221 theParams.push_back( "DropSmallEdges.Tolerance3d" );
223 } else if( theOperation == "BSplineRestriction" ) {
224 theParams.push_back( "BSplineRestriction.SurfaceMode" );
225 theParams.push_back( "BSplineRestriction.Curve3dMode" );
226 theParams.push_back( "BSplineRestriction.Curve2dMode" );
227 theParams.push_back( "BSplineRestriction.Tolerance3d" );
228 theParams.push_back( "BSplineRestriction.Tolerance2d" );
229 theParams.push_back( "BSplineRestriction.RequiredDegree" );
230 theParams.push_back( "BSplineRestriction.RequiredNbSegments" );
231 theParams.push_back( "BSplineRestriction.Continuity3d" );
232 theParams.push_back( "BSplineRestriction.Continuity2d" );
234 } else if( theOperation == "SplitContinuity" ) {
235 theParams.push_back( "SplitContinuity.Tolerance3d" );
236 theParams.push_back( "SplitContinuity.SurfaceContinuity" );
237 theParams.push_back( "SplitContinuity.CurveContinuity" );
239 } else if( theOperation == "ToBezier" ) {
240 theParams.push_back( "ToBezier.SurfaceMode" );
241 theParams.push_back( "ToBezier.Curve3dMode" );
242 theParams.push_back( "ToBezier.Curve2dMode" );
243 theParams.push_back( "ToBezier.MaxTolerance" );
245 } else if( theOperation == "SameParameter" ) {
246 theParams.push_back( "SameParameter.Tolerance3d" );
248 } else if( theOperation == "FixShape" ) {
249 theParams.push_back( "FixShape.Tolerance3d" );
250 theParams.push_back( "FixShape.MaxTolerance3d" );
259 //=============================================================================
263 //=============================================================================
264 Handle(GEOM_Object) GEOMImpl_IHealingOperations::SuppressFaces (Handle(GEOM_Object) theObject,
265 const Handle(TColStd_HArray1OfInteger)& theFaces)
267 // set error code, check parameters
270 if ( theObject.IsNull() ) // if theFaces.IsNull() - it's OK, it means that ALL faces must be removed..
273 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
274 if(aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
277 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
280 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SUPPRESS_FACES);
282 if(aFunction.IsNull()) return NULL;
284 //Check if the function is set correctly
285 if(aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
287 // prepare "data container" class IHealing
288 GEOMImpl_IHealing HI(aFunction);
289 HI.SetFaces( theFaces );
290 HI.SetOriginal( aLastFunction );
292 //Compute the translation
295 if (!GetSolver()->ComputeFunction(aFunction))
297 SetErrorCode("Healing driver failed");
301 catch (Standard_Failure)
303 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
304 SetErrorCode(aFail->GetMessageString());
308 //Make a Python command
317 //=============================================================================
321 //=============================================================================
322 Handle(GEOM_Object) GEOMImpl_IHealingOperations::CloseContour (Handle(GEOM_Object) theObject,
323 const Handle(TColStd_HArray1OfInteger)& theWires,
326 // set error code, check parameters
329 if (theObject.IsNull())
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(), CLOSE_CONTOUR);
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.SetWires( theWires );
349 HI.SetIsCommonVertex( isCommonVertex );
350 HI.SetOriginal( aLastFunction );
352 //Compute the translation
355 if (!GetSolver()->ComputeFunction(aFunction))
357 SetErrorCode("Healing driver failed");
361 catch (Standard_Failure)
363 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
364 SetErrorCode(aFail->GetMessageString());
368 //Make a Python command
376 //=============================================================================
380 //=============================================================================
381 Handle(GEOM_Object) GEOMImpl_IHealingOperations::RemoveIntWires (Handle(GEOM_Object) theObject,
382 const Handle(TColStd_HArray1OfInteger)& theWires)
384 // set error code, check parameters
387 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL wires must be removed
390 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
391 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
394 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
397 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), REMOVE_INT_WIRES);
399 if (aFunction.IsNull()) return NULL;
401 //Check if the function is set correctly
402 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
404 // prepare "data container" class IHealing
405 GEOMImpl_IHealing HI(aFunction);
406 HI.SetWires( theWires );
407 HI.SetOriginal( aLastFunction );
409 //Compute the translation
412 if (!GetSolver()->ComputeFunction(aFunction))
414 SetErrorCode("Healing driver failed");
418 catch (Standard_Failure)
420 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
421 SetErrorCode(aFail->GetMessageString());
425 //Make a Python command
433 //=============================================================================
437 //=============================================================================
438 Handle(GEOM_Object) GEOMImpl_IHealingOperations::FillHoles (Handle(GEOM_Object) theObject,
439 const Handle(TColStd_HArray1OfInteger)& theWires)
441 // set error code, check parameters
444 if (theObject.IsNull()) // if theWires is NULL it's OK, it means that ALL holes must be removed
447 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
448 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
451 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
454 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), FILL_HOLES);
456 if (aFunction.IsNull()) return NULL;
458 //Check if the function is set correctly
459 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
461 // prepare "data container" class IHealing
462 GEOMImpl_IHealing HI(aFunction);
463 HI.SetWires( theWires );
464 HI.SetOriginal( aLastFunction );
466 //Compute the translation
469 if (!GetSolver()->ComputeFunction(aFunction))
471 SetErrorCode("Healing driver failed");
475 catch (Standard_Failure)
477 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
478 SetErrorCode(aFail->GetMessageString());
482 //Make a Python command
490 //=============================================================================
494 //=============================================================================
495 Handle(GEOM_Object) GEOMImpl_IHealingOperations::Sew (Handle(GEOM_Object) theObject,
498 // set error code, check parameters
501 if (theObject.IsNull())
504 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
505 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
508 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
511 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), SEWING);
513 if (aFunction.IsNull()) return NULL;
515 //Check if the function is set correctly
516 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
518 // prepare "data container" class IHealing
519 GEOMImpl_IHealing HI(aFunction);
520 HI.SetTolerance( theTolerance );
521 HI.SetOriginal( aLastFunction );
523 //Compute the translation
526 if (!GetSolver()->ComputeFunction(aFunction))
528 SetErrorCode("Healing driver failed");
532 catch (Standard_Failure)
534 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
535 SetErrorCode(aFail->GetMessageString());
539 //Make a Python command
547 //=============================================================================
551 //=============================================================================
552 Handle(GEOM_Object) GEOMImpl_IHealingOperations::DivideEdge (Handle(GEOM_Object) theObject,
557 // set error code, check parameters
560 if (theObject.IsNull())
563 Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction();
564 if (aLastFunction.IsNull()) return NULL; //There is no function which creates an object to be processed
567 Handle(GEOM_Object) aNewObject = GetEngine()->AddObject( GetDocID(), GEOM_COPY );
570 aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), DIVIDE_EDGE);
572 if (aFunction.IsNull()) return NULL;
574 //Check if the function is set correctly
575 if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL;
577 // prepare "data container" class IHealing
578 GEOMImpl_IHealing HI(aFunction);
579 HI.SetIndex( theIndex );
580 HI.SetDevideEdgeValue( theValue );
581 HI.SetIsByParameter( isByParameter );
582 HI.SetOriginal( aLastFunction );
584 //Compute the translation
587 if (!GetSolver()->ComputeFunction(aFunction))
589 SetErrorCode("Healing driver failed");
593 catch (Standard_Failure)
595 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
596 SetErrorCode(aFail->GetMessageString());
600 //Make a Python command
608 //=============================================================================
612 //=============================================================================
613 bool GEOMImpl_IHealingOperations::GetFreeBoundary (Handle(GEOM_Object) theObject,
614 Handle(TColStd_HSequenceOfTransient)& theClosed,
615 Handle(TColStd_HSequenceOfTransient)& theOpen )
617 // set error code, check parameters
620 if ( theObject.IsNull() || theClosed.IsNull() || theOpen.IsNull() )
623 TopoDS_Shape aShape = theObject->GetValue();
624 if ( aShape.IsNull() )
627 // get free boundary shapes
628 ShapeAnalysis_FreeBounds anAnalizer( aShape );
629 TopoDS_Compound aClosed = anAnalizer.GetClosedWires();
630 TopoDS_Compound anOpen = anAnalizer.GetOpenWires();
632 // iterate through shapes and append them to the return sequence
633 Handle(GEOM_Object) anObj;
634 Handle(GEOM_Function) aFunction;
635 TopExp_Explorer anExp;
636 for ( anExp.Init( aClosed, TopAbs_WIRE ); anExp.More(); anExp.Next() )
638 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
639 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
640 TopoDS_Shape aValueShape = anExp.Current();
641 aFunction->SetValue( aValueShape );
642 theClosed->Append(anObj);
644 for ( anExp.Init( anOpen, TopAbs_WIRE ); anExp.More(); anExp.Next() )
646 anObj = GetEngine()->AddObject( GetDocID(), GEOM_FREE_BOUNDS );
647 aFunction = anObj->AddFunction( GEOMImpl_CopyDriver::GetID(), COPY_WITHOUT_REF );
648 TopoDS_Shape aValueShape = anExp.Current();
649 aFunction->SetValue( aValueShape );
650 theOpen->Append(anObj);