3 #include "GEOMImpl_HealingDriver.hxx"
4 #include "GEOMImpl_Types.hxx"
5 #include "GEOMImpl_IHealing.hxx"
6 #include "GEOM_Function.hxx"
8 #include "ShHealOper_ShapeProcess.hxx"
9 #include "ShHealOper_RemoveFace.hxx"
10 #include "ShHealOper_CloseContour.hxx"
11 #include "ShHealOper_RemoveInternalWires.hxx"
12 #include "ShHealOper_FillHoles.hxx"
13 #include "ShHealOper_Sewing.hxx"
14 #include "ShHealOper_EdgeDivide.hxx"
18 #include <TopTools_IndexedMapOfShape.hxx>
20 #include <StdFail_NotDone.hxx>
22 //=======================================================================
23 //function : raiseNotDoneExeption
24 //purpose : global function: forms error message and raises exeption
25 //=======================================================================
26 void raiseNotDoneExeption( const int theErrorStatus )
28 switch ( theErrorStatus )
30 case ShHealOper_NotError: StdFail_NotDone::Raise( "ShHealOper_NotError_msg" );
31 case ShHealOper_InvalidParameters: StdFail_NotDone::Raise( "ShHealOper_InvalidParameters_msg" );
32 case ShHealOper_ErrorExecution:
33 default: StdFail_NotDone::Raise( "ShHealOper_ErrorExecution_msg" );
37 //=======================================================================
40 //=======================================================================
41 const Standard_GUID& GEOMImpl_HealingDriver::GetID()
43 static Standard_GUID aHealingDriver("FF1BBB61-5D14-4df2-980B-3A668264EA16");
44 return aHealingDriver;
48 //=======================================================================
49 //function : GEOMImpl_HealingDriver
51 //=======================================================================
53 GEOMImpl_HealingDriver::GEOMImpl_HealingDriver()
57 //=======================================================================
60 //=======================================================================
61 Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const
63 if (Label().IsNull()) return 0;
64 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
66 if (aFunction.IsNull()) return 0;
68 GEOMImpl_IHealing HI (aFunction);
69 Standard_Integer aType = aFunction->GetType();
70 Handle(GEOM_Function) anOriginalFunction = HI.GetOriginal();
71 if (anOriginalFunction.IsNull()) return 0;
72 TopoDS_Shape aShape, anOriginalShape = anOriginalFunction->GetValue();
73 if (anOriginalShape.IsNull()) return 0;
78 ShapeProcess(&HI, anOriginalShape, aShape);
81 SuppressFaces(&HI, anOriginalShape, aShape);
84 CloseContour(&HI, anOriginalShape, aShape);
86 case REMOVE_INT_WIRES:
87 RemoveIntWires(&HI, anOriginalShape, aShape);
90 RemoveHoles(&HI, anOriginalShape, aShape);
93 Sew(&HI, anOriginalShape, aShape);
96 AddPointOnEdge(&HI, anOriginalShape, aShape);
103 raiseNotDoneExeption( ShHealOper_ErrorExecution );
105 aFunction->SetValue(aShape);
107 log.SetTouched(Label());
111 //=======================================================================
112 //function : ShapeProcess
114 //=======================================================================
115 Standard_Boolean GEOMImpl_HealingDriver::ShapeProcess (GEOMImpl_IHealing* theHI,
116 const TopoDS_Shape& theOriginalShape,
117 TopoDS_Shape& theOutShape) const
119 Handle(TColStd_HArray1OfExtendedString) anOperators = theHI->GetOperators();
120 Handle(TColStd_HArray1OfExtendedString) aParams = theHI->GetParameters();
121 Handle(TColStd_HArray1OfExtendedString) aValues = theHI->GetValues();
123 if (anOperators.IsNull() || anOperators->Length() <= 0)
124 return Standard_False;
126 Standard_Integer nbParams = 0, nbValues = 0;
127 if (!aParams.IsNull()) {
128 nbParams = aParams->Length();
130 if (!aValues.IsNull()) {
131 nbValues = aValues->Length();
133 if (nbParams != nbValues)
134 return Standard_False;
136 ShHealOper_ShapeProcess aHealer;
137 TColStd_SequenceOfAsciiString anOperatorsAS, aParamsAS, aValuesAS;
139 for (i = 1; i <= anOperators->Length(); i++)
140 anOperatorsAS.Append(TCollection_AsciiString(anOperators->Value(i)));
142 aHealer.SetOperators(anOperatorsAS);
144 for (i = 1; i <= nbParams; i++) {
145 aHealer.SetParameter(TCollection_AsciiString(aParams->Value(i)),
146 TCollection_AsciiString(aValues->Value(i)));
149 aHealer.Perform(theOriginalShape, theOutShape);
151 if (!aHealer.isDone())
152 raiseNotDoneExeption( ShHealOper_NotError );
154 return Standard_True;
157 //=======================================================================
158 //function : SupressFaces
160 //=======================================================================
161 Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
162 const TopoDS_Shape& theOriginalShape,
163 TopoDS_Shape& theOutShape) const
165 Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
167 ShHealOper_RemoveFace aHealer (theOriginalShape);
169 Standard_Boolean aResult = Standard_False;
170 if (aFaces.IsNull()) // remove all faces
172 aResult = aHealer.Perform();
174 TopTools_SequenceOfShape aShapesFaces;
175 TopTools_IndexedMapOfShape aShapes;
176 TopExp::MapShapes(theOriginalShape, aShapes);
177 for (int i = 1; i <= aFaces->Length(); i++) {
178 int indexOfFace = aFaces->Value(i);
179 TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
180 aShapesFaces.Append(aFace);
183 aResult = aHealer.Perform(aShapesFaces);
187 theOutShape = aHealer.GetResultShape();
189 raiseNotDoneExeption( aHealer.GetErrorStatus() );
194 //=======================================================================
195 //function : CloseContour
197 //=======================================================================
198 Standard_Boolean GEOMImpl_HealingDriver::CloseContour (GEOMImpl_IHealing* theHI,
199 const TopoDS_Shape& theOriginalShape,
200 TopoDS_Shape& theOutShape) const
202 Standard_Boolean isByVertex = theHI->GetIsCommonVertex();
203 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
205 ShHealOper_CloseContour aHealer (theOriginalShape);
207 Standard_Boolean aResult = Standard_False;
208 if ( aWires.IsNull() ) {
209 if ( theOriginalShape.ShapeType() == TopAbs_WIRE )
210 aResult = aHealer.Perform(TopoDS::Wire(theOriginalShape), isByVertex, !isByVertex);
213 TopTools_SequenceOfShape aShapesWires;
214 TopTools_IndexedMapOfShape aShapes;
215 TopExp::MapShapes(theOriginalShape, aShapes);
216 for (int i = 1; i <= aWires->Length(); i++) {
217 int indexOfWire = aWires->Value(i);
218 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
219 aShapesWires.Append(aWire);
222 aResult = aHealer.Perform( aShapesWires, isByVertex, !isByVertex );
226 theOutShape = aHealer.GetResultShape();
228 raiseNotDoneExeption( aHealer.GetErrorStatus() );
233 //=======================================================================
234 //function : RemoveIntWires
236 //=======================================================================
237 Standard_Boolean GEOMImpl_HealingDriver::RemoveIntWires (GEOMImpl_IHealing* theHI,
238 const TopoDS_Shape& theOriginalShape,
239 TopoDS_Shape& theOutShape) const
241 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
243 ShHealOper_RemoveInternalWires aHealer(theOriginalShape);
245 Standard_Boolean aResult = Standard_False;
246 if (aWires.IsNull()) { // remove all faces
247 aResult = aHealer.Remove();
249 TopTools_SequenceOfShape aShapesWires;
250 TopTools_IndexedMapOfShape aShapes;
251 TopExp::MapShapes(theOriginalShape, aShapes);
252 for (int i = 1; i <= aWires->Length(); i++) {
253 int indexOfWire = aWires->Value(i);
254 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
255 aShapesWires.Append(aWire);
258 aResult = aHealer.Remove(aShapesWires);
262 theOutShape = aHealer.GetResultShape();
264 raiseNotDoneExeption( aHealer.GetErrorStatus() );
269 //=======================================================================
270 //function : RemoveHoles
272 //=======================================================================
273 Standard_Boolean GEOMImpl_HealingDriver::RemoveHoles (GEOMImpl_IHealing* theHI,
274 const TopoDS_Shape& theOriginalShape,
275 TopoDS_Shape& theOutShape) const
277 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
279 ShHealOper_FillHoles aHealer (theOriginalShape);
281 Standard_Boolean aResult = Standard_False;
282 if (aWires.IsNull()) { // remove all faces
283 aResult = aHealer.Fill();
285 TopTools_SequenceOfShape aShapesWires;
286 TopTools_IndexedMapOfShape aShapes;
287 TopExp::MapShapes(theOriginalShape, aShapes);
288 for (int i = 1; i <= aWires->Length(); i++) {
289 int indexOfWire = aWires->Value(i);
290 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
291 aShapesWires.Append(aWire);
294 aResult = aHealer.Fill(aShapesWires);
298 theOutShape = aHealer.GetResultShape();
300 raiseNotDoneExeption( aHealer.GetErrorStatus() );
305 //=======================================================================
308 //=======================================================================
309 Standard_Boolean GEOMImpl_HealingDriver::Sew (GEOMImpl_IHealing* theHI,
310 const TopoDS_Shape& theOriginalShape,
311 TopoDS_Shape& theOutShape) const
313 Standard_Real aTol = theHI->GetTolerance();
315 ShHealOper_Sewing aHealer (theOriginalShape, aTol);
317 Standard_Boolean aResult = aHealer.Perform();
320 theOutShape = aHealer.GetResultShape();
322 raiseNotDoneExeption( aHealer.GetErrorStatus() );
327 //=======================================================================
328 //function : AddPointOnEdge
330 //=======================================================================
331 Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theHI,
332 const TopoDS_Shape& theOriginalShape,
333 TopoDS_Shape& theOutShape) const
335 Standard_Boolean isByParameter = theHI->GetIsByParameter();
336 Standard_Integer anIndex = theHI->GetIndex();
337 Standard_Real aValue = theHI->GetDevideEdgeValue();
339 ShHealOper_EdgeDivide aHealer (theOriginalShape);
341 Standard_Boolean aResult = Standard_False;
342 if (anIndex == -1) { // apply algorythm for the whole shape which is EDGE
343 if (theOriginalShape.ShapeType() == TopAbs_EDGE)
344 aResult = aHealer.Perform(TopoDS::Edge(theOriginalShape), aValue, isByParameter);
346 TopTools_IndexedMapOfShape aShapes;
347 TopExp::MapShapes(theOriginalShape, aShapes);
348 TopoDS_Shape aEdgeShape = aShapes.FindKey(anIndex);
349 if (aEdgeShape.ShapeType() == TopAbs_EDGE)
350 aResult = aHealer.Perform(TopoDS::Edge(aEdgeShape), aValue, isByParameter);
354 theOutShape = aHealer.GetResultShape();
356 raiseNotDoneExeption( aHealer.GetErrorStatus() );
362 //=======================================================================
363 //function : GEOMImpl_HealingDriver_Type_
365 //=======================================================================
366 Standard_EXPORT Handle_Standard_Type& GEOMImpl_HealingDriver_Type_()
369 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
370 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
371 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
372 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
373 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
374 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
377 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
378 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_HealingDriver",
379 sizeof(GEOMImpl_HealingDriver),
381 (Standard_Address)_Ancestors,
382 (Standard_Address)NULL);
387 //=======================================================================
388 //function : DownCast
390 //=======================================================================
392 const Handle(GEOMImpl_HealingDriver) Handle(GEOMImpl_HealingDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
394 Handle(GEOMImpl_HealingDriver) _anOtherObject;
396 if (!AnObject.IsNull()) {
397 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_HealingDriver))) {
398 _anOtherObject = Handle(GEOMImpl_HealingDriver)((Handle(GEOMImpl_HealingDriver)&)AnObject);
402 return _anOtherObject ;