2 #include <Standard_Stream.hxx>
4 #include <GEOMImpl_HealingDriver.hxx>
5 #include <GEOMImpl_Types.hxx>
6 #include <GEOMImpl_IHealing.hxx>
7 #include <GEOM_Function.hxx>
9 #include <ShHealOper_ShapeProcess.hxx>
10 #include <ShHealOper_RemoveFace.hxx>
11 #include <ShHealOper_CloseContour.hxx>
12 #include <ShHealOper_RemoveInternalWires.hxx>
13 #include <ShHealOper_FillHoles.hxx>
14 #include <ShHealOper_Sewing.hxx>
15 #include <ShHealOper_EdgeDivide.hxx>
19 #include <TopTools_IndexedMapOfShape.hxx>
21 #include <StdFail_NotDone.hxx>
23 //=======================================================================
24 //function : raiseNotDoneExeption
25 //purpose : global function: forms error message and raises exeption
26 //=======================================================================
27 void raiseNotDoneExeption( const int theErrorStatus )
29 switch ( theErrorStatus )
31 case ShHealOper_NotError: StdFail_NotDone::Raise( "ShHealOper_NotError_msg" );
32 case ShHealOper_InvalidParameters: StdFail_NotDone::Raise( "ShHealOper_InvalidParameters_msg" );
33 case ShHealOper_ErrorExecution:
34 default: StdFail_NotDone::Raise( "ShHealOper_ErrorExecution_msg" );
38 //=======================================================================
41 //=======================================================================
42 const Standard_GUID& GEOMImpl_HealingDriver::GetID()
44 static Standard_GUID aHealingDriver("FF1BBB61-5D14-4df2-980B-3A668264EA16");
45 return aHealingDriver;
49 //=======================================================================
50 //function : GEOMImpl_HealingDriver
52 //=======================================================================
54 GEOMImpl_HealingDriver::GEOMImpl_HealingDriver()
58 //=======================================================================
61 //=======================================================================
62 Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const
64 if (Label().IsNull()) return 0;
65 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
67 if (aFunction.IsNull()) return 0;
69 GEOMImpl_IHealing HI (aFunction);
70 Standard_Integer aType = aFunction->GetType();
71 Handle(GEOM_Function) anOriginalFunction = HI.GetOriginal();
72 if (anOriginalFunction.IsNull()) return 0;
73 TopoDS_Shape aShape, anOriginalShape = anOriginalFunction->GetValue();
74 if (anOriginalShape.IsNull()) return 0;
79 ShapeProcess(&HI, anOriginalShape, aShape);
82 SuppressFaces(&HI, anOriginalShape, aShape);
85 CloseContour(&HI, anOriginalShape, aShape);
87 case REMOVE_INT_WIRES:
88 RemoveIntWires(&HI, anOriginalShape, aShape);
91 RemoveHoles(&HI, anOriginalShape, aShape);
94 Sew(&HI, anOriginalShape, aShape);
97 AddPointOnEdge(&HI, anOriginalShape, aShape);
104 raiseNotDoneExeption( ShHealOper_ErrorExecution );
106 aFunction->SetValue(aShape);
108 log.SetTouched(Label());
112 //=======================================================================
113 //function : ShapeProcess
115 //=======================================================================
116 Standard_Boolean GEOMImpl_HealingDriver::ShapeProcess (GEOMImpl_IHealing* theHI,
117 const TopoDS_Shape& theOriginalShape,
118 TopoDS_Shape& theOutShape) const
120 Handle(TColStd_HArray1OfExtendedString) anOperators = theHI->GetOperators();
121 Handle(TColStd_HArray1OfExtendedString) aParams = theHI->GetParameters();
122 Handle(TColStd_HArray1OfExtendedString) aValues = theHI->GetValues();
124 if (anOperators.IsNull() || anOperators->Length() <= 0)
125 return Standard_False;
127 Standard_Integer nbParams = 0, nbValues = 0;
128 if (!aParams.IsNull()) {
129 nbParams = aParams->Length();
131 if (!aValues.IsNull()) {
132 nbValues = aValues->Length();
134 if (nbParams != nbValues)
135 return Standard_False;
137 ShHealOper_ShapeProcess aHealer;
138 TColStd_SequenceOfAsciiString anOperatorsAS, aParamsAS, aValuesAS;
140 for (i = 1; i <= anOperators->Length(); i++)
141 anOperatorsAS.Append(TCollection_AsciiString(anOperators->Value(i)));
143 aHealer.SetOperators(anOperatorsAS);
145 for (i = 1; i <= nbParams; i++) {
146 aHealer.SetParameter(TCollection_AsciiString(aParams->Value(i)),
147 TCollection_AsciiString(aValues->Value(i)));
150 aHealer.Perform(theOriginalShape, theOutShape);
152 if (!aHealer.isDone())
153 raiseNotDoneExeption( ShHealOper_NotError );
155 return Standard_True;
158 //=======================================================================
159 //function : SupressFaces
161 //=======================================================================
162 Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
163 const TopoDS_Shape& theOriginalShape,
164 TopoDS_Shape& theOutShape) const
166 Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
168 ShHealOper_RemoveFace aHealer (theOriginalShape);
170 Standard_Boolean aResult = Standard_False;
171 if (aFaces.IsNull()) // remove all faces
173 aResult = aHealer.Perform();
175 TopTools_SequenceOfShape aShapesFaces;
176 TopTools_IndexedMapOfShape aShapes;
177 TopExp::MapShapes(theOriginalShape, aShapes);
178 for (int i = 1; i <= aFaces->Length(); i++) {
179 int indexOfFace = aFaces->Value(i);
180 TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
181 aShapesFaces.Append(aFace);
184 aResult = aHealer.Perform(aShapesFaces);
188 theOutShape = aHealer.GetResultShape();
190 raiseNotDoneExeption( aHealer.GetErrorStatus() );
195 //=======================================================================
196 //function : CloseContour
198 //=======================================================================
199 Standard_Boolean GEOMImpl_HealingDriver::CloseContour (GEOMImpl_IHealing* theHI,
200 const TopoDS_Shape& theOriginalShape,
201 TopoDS_Shape& theOutShape) const
203 Standard_Boolean isByVertex = theHI->GetIsCommonVertex();
204 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
206 ShHealOper_CloseContour aHealer (theOriginalShape);
208 Standard_Boolean aResult = Standard_False;
209 if ( aWires.IsNull() ) {
210 if ( theOriginalShape.ShapeType() == TopAbs_WIRE )
211 aResult = aHealer.Perform(TopoDS::Wire(theOriginalShape), isByVertex, !isByVertex);
214 TopTools_SequenceOfShape aShapesWires;
215 TopTools_IndexedMapOfShape aShapes;
216 TopExp::MapShapes(theOriginalShape, aShapes);
217 for (int i = 1; i <= aWires->Length(); i++) {
218 int indexOfWire = aWires->Value(i);
219 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
220 aShapesWires.Append(aWire);
223 aResult = aHealer.Perform( aShapesWires, isByVertex, !isByVertex );
227 theOutShape = aHealer.GetResultShape();
229 raiseNotDoneExeption( aHealer.GetErrorStatus() );
234 //=======================================================================
235 //function : RemoveIntWires
237 //=======================================================================
238 Standard_Boolean GEOMImpl_HealingDriver::RemoveIntWires (GEOMImpl_IHealing* theHI,
239 const TopoDS_Shape& theOriginalShape,
240 TopoDS_Shape& theOutShape) const
242 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
244 ShHealOper_RemoveInternalWires aHealer(theOriginalShape);
246 Standard_Boolean aResult = Standard_False;
247 if (aWires.IsNull()) { // remove all faces
248 aResult = aHealer.Remove();
250 TopTools_SequenceOfShape aShapesWires;
251 TopTools_IndexedMapOfShape aShapes;
252 TopExp::MapShapes(theOriginalShape, aShapes);
253 for (int i = 1; i <= aWires->Length(); i++) {
254 int indexOfWire = aWires->Value(i);
255 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
256 aShapesWires.Append(aWire);
259 aResult = aHealer.Remove(aShapesWires);
263 theOutShape = aHealer.GetResultShape();
265 raiseNotDoneExeption( aHealer.GetErrorStatus() );
270 //=======================================================================
271 //function : RemoveHoles
273 //=======================================================================
274 Standard_Boolean GEOMImpl_HealingDriver::RemoveHoles (GEOMImpl_IHealing* theHI,
275 const TopoDS_Shape& theOriginalShape,
276 TopoDS_Shape& theOutShape) const
278 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
280 ShHealOper_FillHoles aHealer (theOriginalShape);
282 Standard_Boolean aResult = Standard_False;
283 if (aWires.IsNull()) { // remove all faces
284 aResult = aHealer.Fill();
286 TopTools_SequenceOfShape aShapesWires;
287 TopTools_IndexedMapOfShape aShapes;
288 TopExp::MapShapes(theOriginalShape, aShapes);
289 for (int i = 1; i <= aWires->Length(); i++) {
290 int indexOfWire = aWires->Value(i);
291 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
292 aShapesWires.Append(aWire);
295 aResult = aHealer.Fill(aShapesWires);
299 theOutShape = aHealer.GetResultShape();
301 raiseNotDoneExeption( aHealer.GetErrorStatus() );
306 //=======================================================================
309 //=======================================================================
310 Standard_Boolean GEOMImpl_HealingDriver::Sew (GEOMImpl_IHealing* theHI,
311 const TopoDS_Shape& theOriginalShape,
312 TopoDS_Shape& theOutShape) const
314 Standard_Real aTol = theHI->GetTolerance();
316 ShHealOper_Sewing aHealer (theOriginalShape, aTol);
318 Standard_Boolean aResult = aHealer.Perform();
321 theOutShape = aHealer.GetResultShape();
323 raiseNotDoneExeption( aHealer.GetErrorStatus() );
328 //=======================================================================
329 //function : AddPointOnEdge
331 //=======================================================================
332 Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theHI,
333 const TopoDS_Shape& theOriginalShape,
334 TopoDS_Shape& theOutShape) const
336 Standard_Boolean isByParameter = theHI->GetIsByParameter();
337 Standard_Integer anIndex = theHI->GetIndex();
338 Standard_Real aValue = theHI->GetDevideEdgeValue();
340 ShHealOper_EdgeDivide aHealer (theOriginalShape);
342 Standard_Boolean aResult = Standard_False;
343 if (anIndex == -1) { // apply algorythm for the whole shape which is EDGE
344 if (theOriginalShape.ShapeType() == TopAbs_EDGE)
345 aResult = aHealer.Perform(TopoDS::Edge(theOriginalShape), aValue, isByParameter);
347 TopTools_IndexedMapOfShape aShapes;
348 TopExp::MapShapes(theOriginalShape, aShapes);
349 TopoDS_Shape aEdgeShape = aShapes.FindKey(anIndex);
350 if (aEdgeShape.ShapeType() == TopAbs_EDGE)
351 aResult = aHealer.Perform(TopoDS::Edge(aEdgeShape), aValue, isByParameter);
355 theOutShape = aHealer.GetResultShape();
357 raiseNotDoneExeption( aHealer.GetErrorStatus() );
363 //=======================================================================
364 //function : GEOMImpl_HealingDriver_Type_
366 //=======================================================================
367 Standard_EXPORT Handle_Standard_Type& GEOMImpl_HealingDriver_Type_()
370 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
371 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
372 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
373 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
374 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
375 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
378 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
379 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_HealingDriver",
380 sizeof(GEOMImpl_HealingDriver),
382 (Standard_Address)_Ancestors,
383 (Standard_Address)NULL);
388 //=======================================================================
389 //function : DownCast
391 //=======================================================================
393 const Handle(GEOMImpl_HealingDriver) Handle(GEOMImpl_HealingDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
395 Handle(GEOMImpl_HealingDriver) _anOtherObject;
397 if (!AnObject.IsNull()) {
398 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_HealingDriver))) {
399 _anOtherObject = Handle(GEOMImpl_HealingDriver)((Handle(GEOMImpl_HealingDriver)&)AnObject);
403 return _anOtherObject ;