1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_HealingDriver.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOMImpl_IHealing.hxx>
26 #include <GEOM_Function.hxx>
28 #include <ShHealOper_ShapeProcess.hxx>
29 #include <ShHealOper_RemoveFace.hxx>
30 #include <ShHealOper_CloseContour.hxx>
31 #include <ShHealOper_RemoveInternalWires.hxx>
32 #include <ShHealOper_FillHoles.hxx>
33 #include <ShHealOper_Sewing.hxx>
34 #include <ShHealOper_EdgeDivide.hxx>
38 #include <TopTools_IndexedMapOfShape.hxx>
40 #include <StdFail_NotDone.hxx>
42 //=======================================================================
43 //function : raiseNotDoneExeption
44 //purpose : global function: forms error message and raises exeption
45 //=======================================================================
46 void raiseNotDoneExeption( const int theErrorStatus )
48 switch ( theErrorStatus )
50 case ShHealOper_NotError: StdFail_NotDone::Raise( "ShHealOper_NotError_msg" );
51 case ShHealOper_InvalidParameters: StdFail_NotDone::Raise( "ShHealOper_InvalidParameters_msg" );
52 case ShHealOper_ErrorExecution:
53 default: StdFail_NotDone::Raise( "ShHealOper_ErrorExecution_msg" );
57 //=======================================================================
60 //=======================================================================
61 const Standard_GUID& GEOMImpl_HealingDriver::GetID()
63 static Standard_GUID aHealingDriver("FF1BBB61-5D14-4df2-980B-3A668264EA16");
64 return aHealingDriver;
68 //=======================================================================
69 //function : GEOMImpl_HealingDriver
71 //=======================================================================
73 GEOMImpl_HealingDriver::GEOMImpl_HealingDriver()
77 //=======================================================================
80 //=======================================================================
81 Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const
83 if (Label().IsNull()) return 0;
84 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
86 if (aFunction.IsNull()) return 0;
88 GEOMImpl_IHealing HI (aFunction);
89 Standard_Integer aType = aFunction->GetType();
90 Handle(GEOM_Function) anOriginalFunction = HI.GetOriginal();
91 if (anOriginalFunction.IsNull()) return 0;
92 TopoDS_Shape aShape, anOriginalShape = anOriginalFunction->GetValue();
93 if (anOriginalShape.IsNull()) return 0;
98 ShapeProcess(&HI, anOriginalShape, aShape);
101 SuppressFaces(&HI, anOriginalShape, aShape);
104 CloseContour(&HI, anOriginalShape, aShape);
106 case REMOVE_INT_WIRES:
107 RemoveIntWires(&HI, anOriginalShape, aShape);
110 RemoveHoles(&HI, anOriginalShape, aShape);
113 Sew(&HI, anOriginalShape, aShape);
116 AddPointOnEdge(&HI, anOriginalShape, aShape);
123 raiseNotDoneExeption( ShHealOper_ErrorExecution );
125 aFunction->SetValue(aShape);
127 log.SetTouched(Label());
131 //=======================================================================
132 //function : ShapeProcess
134 //=======================================================================
135 Standard_Boolean GEOMImpl_HealingDriver::ShapeProcess (GEOMImpl_IHealing* theHI,
136 const TopoDS_Shape& theOriginalShape,
137 TopoDS_Shape& theOutShape) const
139 Handle(TColStd_HArray1OfExtendedString) anOperators = theHI->GetOperators();
140 Handle(TColStd_HArray1OfExtendedString) aParams = theHI->GetParameters();
141 Handle(TColStd_HArray1OfExtendedString) aValues = theHI->GetValues();
143 if (anOperators.IsNull() || anOperators->Length() <= 0)
144 return Standard_False;
146 Standard_Integer nbParams = 0, nbValues = 0;
147 if (!aParams.IsNull()) {
148 nbParams = aParams->Length();
150 if (!aValues.IsNull()) {
151 nbValues = aValues->Length();
153 if (nbParams != nbValues)
154 return Standard_False;
156 ShHealOper_ShapeProcess aHealer;
157 TColStd_SequenceOfAsciiString anOperatorsAS, aParamsAS, aValuesAS;
159 for (i = 1; i <= anOperators->Length(); i++)
160 anOperatorsAS.Append(TCollection_AsciiString(anOperators->Value(i)));
162 aHealer.SetOperators(anOperatorsAS);
164 for (i = 1; i <= nbParams; i++) {
165 aHealer.SetParameter(TCollection_AsciiString(aParams->Value(i)),
166 TCollection_AsciiString(aValues->Value(i)));
169 aHealer.Perform(theOriginalShape, theOutShape);
171 if (!aHealer.isDone())
172 raiseNotDoneExeption( ShHealOper_NotError );
174 return Standard_True;
177 //=======================================================================
178 //function : SupressFaces
180 //=======================================================================
181 Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
182 const TopoDS_Shape& theOriginalShape,
183 TopoDS_Shape& theOutShape) const
185 Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
187 ShHealOper_RemoveFace aHealer (theOriginalShape);
189 Standard_Boolean aResult = Standard_False;
190 if (aFaces.IsNull()) // remove all faces
192 aResult = aHealer.Perform();
194 TopTools_SequenceOfShape aShapesFaces;
195 TopTools_IndexedMapOfShape aShapes;
196 TopExp::MapShapes(theOriginalShape, aShapes);
197 for (int i = 1; i <= aFaces->Length(); i++) {
198 int indexOfFace = aFaces->Value(i);
199 TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
200 aShapesFaces.Append(aFace);
203 aResult = aHealer.Perform(aShapesFaces);
207 theOutShape = aHealer.GetResultShape();
209 raiseNotDoneExeption( aHealer.GetErrorStatus() );
214 //=======================================================================
215 //function : CloseContour
217 //=======================================================================
218 Standard_Boolean GEOMImpl_HealingDriver::CloseContour (GEOMImpl_IHealing* theHI,
219 const TopoDS_Shape& theOriginalShape,
220 TopoDS_Shape& theOutShape) const
222 Standard_Boolean isByVertex = theHI->GetIsCommonVertex();
223 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
225 ShHealOper_CloseContour aHealer (theOriginalShape);
227 Standard_Boolean aResult = Standard_False;
228 if ( aWires.IsNull() ) {
229 if ( theOriginalShape.ShapeType() == TopAbs_WIRE )
230 aResult = aHealer.Perform(TopoDS::Wire(theOriginalShape), isByVertex, !isByVertex);
233 TopTools_SequenceOfShape aShapesWires;
234 TopTools_IndexedMapOfShape aShapes;
235 TopExp::MapShapes(theOriginalShape, aShapes);
236 for (int i = 1; i <= aWires->Length(); i++) {
237 int indexOfWire = aWires->Value(i);
238 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
239 aShapesWires.Append(aWire);
242 aResult = aHealer.Perform( aShapesWires, isByVertex, !isByVertex );
246 theOutShape = aHealer.GetResultShape();
248 raiseNotDoneExeption( aHealer.GetErrorStatus() );
253 //=======================================================================
254 //function : RemoveIntWires
256 //=======================================================================
257 Standard_Boolean GEOMImpl_HealingDriver::RemoveIntWires (GEOMImpl_IHealing* theHI,
258 const TopoDS_Shape& theOriginalShape,
259 TopoDS_Shape& theOutShape) const
261 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
263 ShHealOper_RemoveInternalWires aHealer(theOriginalShape);
265 Standard_Boolean aResult = Standard_False;
266 if (aWires.IsNull()) { // remove all faces
267 aResult = aHealer.Remove();
269 TopTools_SequenceOfShape aShapesWires;
270 TopTools_IndexedMapOfShape aShapes;
271 TopExp::MapShapes(theOriginalShape, aShapes);
272 for (int i = 1; i <= aWires->Length(); i++) {
273 int indexOfWire = aWires->Value(i);
274 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
275 aShapesWires.Append(aWire);
278 aResult = aHealer.Remove(aShapesWires);
282 theOutShape = aHealer.GetResultShape();
284 raiseNotDoneExeption( aHealer.GetErrorStatus() );
289 //=======================================================================
290 //function : RemoveHoles
292 //=======================================================================
293 Standard_Boolean GEOMImpl_HealingDriver::RemoveHoles (GEOMImpl_IHealing* theHI,
294 const TopoDS_Shape& theOriginalShape,
295 TopoDS_Shape& theOutShape) const
297 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
299 ShHealOper_FillHoles aHealer (theOriginalShape);
301 Standard_Boolean aResult = Standard_False;
302 if (aWires.IsNull()) { // remove all faces
303 aResult = aHealer.Fill();
305 TopTools_SequenceOfShape aShapesWires;
306 TopTools_IndexedMapOfShape aShapes;
307 TopExp::MapShapes(theOriginalShape, aShapes);
308 for (int i = 1; i <= aWires->Length(); i++) {
309 int indexOfWire = aWires->Value(i);
310 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
311 aShapesWires.Append(aWire);
314 aResult = aHealer.Fill(aShapesWires);
318 theOutShape = aHealer.GetResultShape();
320 raiseNotDoneExeption( aHealer.GetErrorStatus() );
325 //=======================================================================
328 //=======================================================================
329 Standard_Boolean GEOMImpl_HealingDriver::Sew (GEOMImpl_IHealing* theHI,
330 const TopoDS_Shape& theOriginalShape,
331 TopoDS_Shape& theOutShape) const
333 Standard_Real aTol = theHI->GetTolerance();
335 ShHealOper_Sewing aHealer (theOriginalShape, aTol);
337 Standard_Boolean aResult = aHealer.Perform();
340 theOutShape = aHealer.GetResultShape();
342 raiseNotDoneExeption( aHealer.GetErrorStatus() );
347 //=======================================================================
348 //function : AddPointOnEdge
350 //=======================================================================
351 Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theHI,
352 const TopoDS_Shape& theOriginalShape,
353 TopoDS_Shape& theOutShape) const
355 Standard_Boolean isByParameter = theHI->GetIsByParameter();
356 Standard_Integer anIndex = theHI->GetIndex();
357 Standard_Real aValue = theHI->GetDevideEdgeValue();
359 ShHealOper_EdgeDivide aHealer (theOriginalShape);
361 Standard_Boolean aResult = Standard_False;
362 if (anIndex == -1) { // apply algorythm for the whole shape which is EDGE
363 if (theOriginalShape.ShapeType() == TopAbs_EDGE)
364 aResult = aHealer.Perform(TopoDS::Edge(theOriginalShape), aValue, isByParameter);
366 TopTools_IndexedMapOfShape aShapes;
367 TopExp::MapShapes(theOriginalShape, aShapes);
368 TopoDS_Shape aEdgeShape = aShapes.FindKey(anIndex);
369 if (aEdgeShape.ShapeType() == TopAbs_EDGE)
370 aResult = aHealer.Perform(TopoDS::Edge(aEdgeShape), aValue, isByParameter);
374 theOutShape = aHealer.GetResultShape();
376 raiseNotDoneExeption( aHealer.GetErrorStatus() );
382 //=======================================================================
383 //function : GEOMImpl_HealingDriver_Type_
385 //=======================================================================
386 Standard_EXPORT Handle_Standard_Type& GEOMImpl_HealingDriver_Type_()
389 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
390 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
391 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
392 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
393 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
394 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
397 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
398 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_HealingDriver",
399 sizeof(GEOMImpl_HealingDriver),
401 (Standard_Address)_Ancestors,
402 (Standard_Address)NULL);
407 //=======================================================================
408 //function : DownCast
410 //=======================================================================
412 const Handle(GEOMImpl_HealingDriver) Handle(GEOMImpl_HealingDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
414 Handle(GEOMImpl_HealingDriver) _anOtherObject;
416 if (!AnObject.IsNull()) {
417 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_HealingDriver))) {
418 _anOtherObject = Handle(GEOMImpl_HealingDriver)((Handle(GEOMImpl_HealingDriver)&)AnObject);
422 return _anOtherObject ;