1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_HealingDriver.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOMImpl_IHealing.hxx>
28 #include <GEOM_Function.hxx>
30 #include <GEOMImpl_GlueDriver.hxx>
31 #include <GEOMImpl_ShapeDriver.hxx>
33 #include <GEOMUtils.hxx>
34 #include <GEOMAlgo_RemoverWebs.hxx>
36 #include <ShHealOper_ShapeProcess.hxx>
37 #include <ShHealOper_RemoveFace.hxx>
38 #include <ShHealOper_CloseContour.hxx>
39 #include <ShHealOper_RemoveInternalWires.hxx>
40 #include <ShHealOper_FillHoles.hxx>
41 #include <ShHealOper_Sewing.hxx>
42 #include <ShHealOper_EdgeDivide.hxx>
43 #include <ShHealOper_ChangeOrientation.hxx>
45 #include <TNaming_CopyShape.hxx>
47 #include <ShapeFix_ShapeTolerance.hxx>
48 #include <ShapeFix_Shape.hxx>
50 #include <BRep_Builder.hxx>
51 #include <BRepAdaptor_Curve.hxx>
52 #include <BRepCheck_Analyzer.hxx>
53 #include <BRepTools_WireExplorer.hxx>
56 #include <TopExp_Explorer.hxx>
58 #include <TopoDS_Iterator.hxx>
59 #include <TopTools_IndexedMapOfShape.hxx>
60 #include <TopTools_ListOfShape.hxx>
61 #include <TopTools_ListIteratorOfListOfShape.hxx>
63 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
65 #include <Precision.hxx>
67 #include <StdFail_NotDone.hxx>
68 #include <Standard_NullObject.hxx>
70 //=======================================================================
71 //function : raiseNotDoneExeption
72 //purpose : global function: forms error message and raises exeption
73 //=======================================================================
74 void raiseNotDoneExeption( const int theErrorStatus )
76 switch ( theErrorStatus )
78 case ShHealOper_NotError: StdFail_NotDone::Raise( "ShHealOper_NotError_msg" );
79 case ShHealOper_InvalidParameters: StdFail_NotDone::Raise( "ShHealOper_InvalidParameters_msg" );
80 case ShHealOper_ErrorExecution:
81 default: StdFail_NotDone::Raise( "ShHealOper_ErrorExecution_msg" );
85 //=======================================================================
88 //=======================================================================
89 const Standard_GUID& GEOMImpl_HealingDriver::GetID()
91 static Standard_GUID aHealingDriver("FF1BBB61-5D14-4df2-980B-3A668264EA16");
92 return aHealingDriver;
95 //=======================================================================
96 //function : GEOMImpl_HealingDriver
98 //=======================================================================
99 GEOMImpl_HealingDriver::GEOMImpl_HealingDriver()
103 //=======================================================================
106 //=======================================================================
107 Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const
109 if (Label().IsNull()) return 0;
110 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
112 if (aFunction.IsNull()) return 0;
114 GEOMImpl_IHealing HI (aFunction);
115 Standard_Integer aType = aFunction->GetType();
116 Handle(GEOM_Function) anOriginalFunction = HI.GetOriginal();
117 if (anOriginalFunction.IsNull()) return 0;
118 TopoDS_Shape aShape, anOriginalShape = anOriginalFunction->GetValue();
119 if (anOriginalShape.IsNull()) return 0;
124 ShapeProcess(&HI, anOriginalShape, aShape);
127 SuppressFaces(&HI, anOriginalShape, aShape);
130 CloseContour(&HI, anOriginalShape, aShape);
132 case REMOVE_INT_WIRES:
133 RemoveIntWires(&HI, anOriginalShape, aShape);
136 RemoveHoles(&HI, anOriginalShape, aShape);
139 Sew(&HI, anOriginalShape, aShape, false);
141 case SEWING_NON_MANIFOLD:
142 Sew(&HI, anOriginalShape, aShape, true);
144 case REMOVE_INTERNAL_FACES:
145 RemoveInternalFaces(&HI, anOriginalShape, aShape);
148 AddPointOnEdge(&HI, anOriginalShape, aShape);
150 case CHANGE_ORIENTATION:
151 ChangeOrientation(&HI, anOriginalShape, aShape);
153 case LIMIT_TOLERANCE:
154 LimitTolerance(&HI, anOriginalShape, aShape);
156 case FUSE_COLLINEAR_EDGES:
158 Handle(TColStd_HSequenceOfTransient) aVerts = HI.GetShapes();
159 FuseCollinearEdges(anOriginalShape, aVerts, aShape);
167 raiseNotDoneExeption( ShHealOper_ErrorExecution );
169 aFunction->SetValue(aShape);
171 log.SetTouched(Label());
175 //=======================================================================
176 //function : ShapeProcess
178 //=======================================================================
179 Standard_Boolean GEOMImpl_HealingDriver::ShapeProcess (GEOMImpl_IHealing* theHI,
180 const TopoDS_Shape& theOriginalShape,
181 TopoDS_Shape& theOutShape) const
183 Handle(TColStd_HArray1OfExtendedString) anOperators = theHI->GetOperators();
184 Handle(TColStd_HArray1OfExtendedString) aParams = theHI->GetParameters();
185 Handle(TColStd_HArray1OfExtendedString) aValues = theHI->GetValues();
187 if (anOperators.IsNull() || anOperators->Length() <= 0)
188 return Standard_False;
190 Standard_Integer nbParams = 0, nbValues = 0;
191 if (!aParams.IsNull()) {
192 nbParams = aParams->Length();
194 if (!aValues.IsNull()) {
195 nbValues = aValues->Length();
197 if (nbParams != nbValues)
198 return Standard_False;
200 ShHealOper_ShapeProcess aHealer;
201 TColStd_SequenceOfAsciiString anOperatorsAS, aParamsAS, aValuesAS;
203 for (i = 1; i <= anOperators->Length(); i++)
204 anOperatorsAS.Append(TCollection_AsciiString(anOperators->Value(i)));
206 aHealer.SetOperators(anOperatorsAS);
208 for (i = 1; i <= nbParams; i++) {
209 aHealer.SetParameter(TCollection_AsciiString(aParams->Value(i)),
210 TCollection_AsciiString(aValues->Value(i)));
213 aHealer.Perform(theOriginalShape, theOutShape);
215 if (!aHealer.isDone())
216 raiseNotDoneExeption( ShHealOper_NotError );
218 return Standard_True;
221 //=======================================================================
222 //function : SupressFaces
224 //=======================================================================
225 void SuppressFacesRec (const TopTools_SequenceOfShape& theShapesFaces,
226 const TopoDS_Shape& theOriginalShape,
227 TopoDS_Shape& theOutShape)
229 if ((theOriginalShape.ShapeType() != TopAbs_COMPOUND &&
230 theOriginalShape.ShapeType() != TopAbs_COMPSOLID))
232 ShHealOper_RemoveFace aHealer (theOriginalShape);
233 Standard_Boolean aResult = aHealer.Perform(theShapesFaces);
236 theOutShape = aHealer.GetResultShape();
238 raiseNotDoneExeption(aHealer.GetErrorStatus());
246 TopTools_MapOfShape mapShape;
247 TopoDS_Iterator It (theOriginalShape, Standard_True, Standard_True);
249 for (; It.More(); It.Next()) {
250 TopoDS_Shape aShape_i = It.Value();
251 if (mapShape.Add(aShape_i)) {
252 // check, if current shape contains at least one of faces to be removed
253 bool isFound = false;
254 TopTools_IndexedMapOfShape aShapes_i;
255 TopExp::MapShapes(aShape_i, aShapes_i);
256 for (int i = 1; i <= theShapesFaces.Length() && !isFound; i++) {
257 const TopoDS_Shape& aFace_i = theShapesFaces.Value(i);
258 if (aShapes_i.Contains(aFace_i)) isFound = true;
261 TopoDS_Shape anOutSh_i;
262 SuppressFacesRec(theShapesFaces, aShape_i, anOutSh_i);
263 if ( !anOutSh_i.IsNull() )
264 BB.Add(CC, anOutSh_i);
268 BB.Add(CC, aShape_i);
276 Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
277 const TopoDS_Shape& theOriginalShape,
278 TopoDS_Shape& theOutShape) const
280 Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
282 Standard_Boolean aResult = Standard_False;
284 if (aFaces.IsNull()) {
285 ShHealOper_RemoveFace aHealer (theOriginalShape);
286 aResult = aHealer.Perform();
289 theOutShape = aHealer.GetResultShape();
291 raiseNotDoneExeption(aHealer.GetErrorStatus());
294 TopTools_SequenceOfShape aShapesFaces;
295 TopTools_IndexedMapOfShape aShapes;
296 TopExp::MapShapes(theOriginalShape, aShapes);
297 for (int i = 1; i <= aFaces->Length(); i++) {
298 int indexOfFace = aFaces->Value(i);
299 TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
300 aShapesFaces.Append(aFace);
302 SuppressFacesRec(aShapesFaces, theOriginalShape, theOutShape);
303 if ((theOriginalShape.ShapeType() == TopAbs_COMPOUND ||
304 theOriginalShape.ShapeType() == TopAbs_COMPSOLID)) {
305 TopoDS_Shape aSh = theOutShape;
306 theOutShape = GEOMImpl_GlueDriver::GlueFaces(aSh, Precision::Confusion(), Standard_True);
310 return Standard_True;
313 //=======================================================================
314 //function : CloseContour
316 //=======================================================================
317 Standard_Boolean GEOMImpl_HealingDriver::CloseContour (GEOMImpl_IHealing* theHI,
318 const TopoDS_Shape& theOriginalShape,
319 TopoDS_Shape& theOutShape) const
321 Standard_Boolean isByVertex = theHI->GetIsCommonVertex();
322 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
324 ShHealOper_CloseContour aHealer (theOriginalShape);
326 Standard_Boolean aResult = Standard_False;
327 if ( aWires.IsNull() ) {
328 if ( theOriginalShape.ShapeType() == TopAbs_WIRE )
329 aResult = aHealer.Perform(TopoDS::Wire(theOriginalShape), isByVertex, !isByVertex);
332 TopTools_SequenceOfShape aShapesWires;
333 TopTools_IndexedMapOfShape aShapes;
334 TopExp::MapShapes(theOriginalShape, aShapes);
335 for (int i = 1; i <= aWires->Length(); i++) {
336 int indexOfWire = aWires->Value(i);
337 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
338 aShapesWires.Append(aWire);
341 aResult = aHealer.Perform( aShapesWires, isByVertex, !isByVertex );
345 theOutShape = aHealer.GetResultShape();
347 raiseNotDoneExeption( aHealer.GetErrorStatus() );
352 //=======================================================================
353 //function : RemoveIntWires
355 //=======================================================================
356 Standard_Boolean GEOMImpl_HealingDriver::RemoveIntWires (GEOMImpl_IHealing* theHI,
357 const TopoDS_Shape& theOriginalShape,
358 TopoDS_Shape& theOutShape) const
360 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
362 ShHealOper_RemoveInternalWires aHealer(theOriginalShape);
364 Standard_Boolean aResult = Standard_False;
365 if (aWires.IsNull()) { // remove all faces
366 aResult = aHealer.Remove();
368 TopTools_SequenceOfShape aShapesWires;
369 TopTools_IndexedMapOfShape aShapes;
370 TopExp::MapShapes(theOriginalShape, aShapes);
371 for (int i = 1; i <= aWires->Length(); i++) {
372 int indexOfWire = aWires->Value(i);
373 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
374 aShapesWires.Append(aWire);
377 aResult = aHealer.Remove(aShapesWires);
381 theOutShape = aHealer.GetResultShape();
383 raiseNotDoneExeption( aHealer.GetErrorStatus() );
388 //=======================================================================
389 //function : RemoveHoles
391 //=======================================================================
392 Standard_Boolean GEOMImpl_HealingDriver::RemoveHoles (GEOMImpl_IHealing* theHI,
393 const TopoDS_Shape& theOriginalShape,
394 TopoDS_Shape& theOutShape) const
396 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
398 ShHealOper_FillHoles aHealer (theOriginalShape);
400 Standard_Boolean aResult = Standard_False;
401 if (aWires.IsNull()) { // remove all faces
402 aResult = aHealer.Fill();
404 TopTools_SequenceOfShape aShapesWires;
405 TopTools_IndexedMapOfShape aShapes;
406 TopExp::MapShapes(theOriginalShape, aShapes);
407 for (int i = 1; i <= aWires->Length(); i++) {
408 int indexOfWire = aWires->Value(i);
409 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
410 aShapesWires.Append(aWire);
413 aResult = aHealer.Fill(aShapesWires);
417 theOutShape = aHealer.GetResultShape();
419 raiseNotDoneExeption( aHealer.GetErrorStatus() );
424 //=======================================================================
427 //=======================================================================
428 Standard_Boolean GEOMImpl_HealingDriver::Sew (GEOMImpl_IHealing* theHI,
429 const TopoDS_Shape& theOriginalShape,
430 TopoDS_Shape& theOutShape,
431 Standard_Boolean isAllowNonManifold) const
433 Standard_Real aTol = theHI->GetTolerance();
435 TopoDS_Compound faceCompound;
436 BRep_Builder builder;
437 builder.MakeCompound( faceCompound );
439 TopExp_Explorer faceExp( theOriginalShape, TopAbs_FACE );
440 for ( ; faceExp.More(); faceExp.Next() )
441 builder.Add( faceCompound, faceExp.Current() );
443 Handle(TColStd_HSequenceOfTransient) otherObjs = theHI->GetShapes();
444 for ( int ind = 1; ind <= otherObjs->Length(); ind++)
446 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(otherObjs->Value(ind));
447 TopoDS_Shape aShape = aRefShape->GetValue();
449 Standard_NullObject::Raise("Null object given");
450 for ( faceExp.Init( aShape, TopAbs_FACE ); faceExp.More(); faceExp.Next() )
451 builder.Add( faceCompound, faceExp.Current() );
454 ShHealOper_Sewing aHealer (faceCompound, aTol);
456 // Set non-manifold mode.
457 aHealer.SetNonManifoldMode(isAllowNonManifold);
459 Standard_Boolean aResult = aHealer.Perform();
462 theOutShape = aHealer.GetResultShape();
464 raiseNotDoneExeption( aHealer.GetErrorStatus() );
469 //=======================================================================
470 //function : RemoveInternalFaces
472 //=======================================================================
474 GEOMImpl_HealingDriver::RemoveInternalFaces (GEOMImpl_IHealing* theHI,
475 const TopoDS_Shape& theOriginalShape,
476 TopoDS_Shape& theOutShape) const
478 // get all input shapes
479 TopTools_SequenceOfShape shapeSeq;
480 shapeSeq.Append( theOriginalShape );
481 Handle(TColStd_HSequenceOfTransient) otherObjs = theHI->GetShapes();
482 if ( !otherObjs.IsNull() )
483 for ( int ind = 1; ind <= otherObjs->Length(); ind++)
485 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(otherObjs->Value(ind));
486 TopoDS_Shape aShape = aRefShape->GetValue();
488 Standard_NullObject::Raise("Null object given");
489 shapeSeq.Append( aShape );
492 // pass input shapes to the algorithm
493 GEOMAlgo_RemoverWebs aTool;
494 if ( shapeSeq.Length() == 1 )
496 aTool.SetShape( shapeSeq.First() );
500 TopoDS_Compound solidCompound;
501 BRep_Builder builder;
502 builder.MakeCompound( solidCompound );
503 for ( int ind = 1; ind <= shapeSeq.Length(); ++ind )
504 for ( TopExp_Explorer so( shapeSeq( ind ), TopAbs_SOLID ); so.More(); so.Next() )
505 builder.Add( solidCompound, so.Current() );
507 aTool.SetShape( solidCompound );
513 if (aTool.ErrorStatus() == 0) { // OK
514 theOutShape = aTool.Result();
516 // as GEOMAlgo_RemoverWebs always produces compound, lets simplify it
517 // for the case, if it contains only one sub-shape
518 TopTools_ListOfShape listShapeRes;
519 GEOMUtils::AddSimpleShapes(theOutShape, listShapeRes);
520 if (listShapeRes.Extent() == 1) {
521 theOutShape = listShapeRes.First();
524 else if (aTool.ErrorStatus() == 11) // invalid argument (contains non-solids), do nothing
525 theOutShape = theOriginalShape;
527 StdFail_NotDone::Raise("GEOMAlgo_RemoverWebs failed!");
529 return Standard_True;
532 //=======================================================================
533 //function : AddPointOnEdge
535 //=======================================================================
536 Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theHI,
537 const TopoDS_Shape& theOriginalShape,
538 TopoDS_Shape& theOutShape) const
540 Standard_Boolean isByParameter = theHI->GetIsByParameter();
541 Standard_Integer anIndex = theHI->GetIndex();
542 Standard_Real aValue = theHI->GetDevideEdgeValue();
544 ShHealOper_EdgeDivide aHealer (theOriginalShape);
546 Standard_Boolean aResult = Standard_False;
547 if (anIndex == -1) { // apply algorythm for the whole shape which is EDGE
548 if (theOriginalShape.ShapeType() == TopAbs_EDGE)
549 aResult = aHealer.Perform(TopoDS::Edge(theOriginalShape), aValue, isByParameter);
551 TopTools_IndexedMapOfShape aShapes;
552 TopExp::MapShapes(theOriginalShape, aShapes);
553 TopoDS_Shape aEdgeShape = aShapes.FindKey(anIndex);
554 if (aEdgeShape.ShapeType() == TopAbs_EDGE)
555 aResult = aHealer.Perform(TopoDS::Edge(aEdgeShape), aValue, isByParameter);
559 theOutShape = aHealer.GetResultShape();
561 raiseNotDoneExeption( aHealer.GetErrorStatus() );
567 //=======================================================================
568 //function : ChangeOrientation
570 //=======================================================================
571 Standard_Boolean GEOMImpl_HealingDriver::ChangeOrientation (GEOMImpl_IHealing* theHI,
572 const TopoDS_Shape& theOriginalShape,
573 TopoDS_Shape& theOutShape) const
575 ShHealOper_ChangeOrientation aHealer (theOriginalShape);
577 Standard_Boolean aResult = aHealer.Perform();
580 theOutShape = aHealer.GetResultShape();
582 raiseNotDoneExeption( aHealer.GetErrorStatus() );
587 //=======================================================================
588 //function : LimitTolerance
590 //=======================================================================
591 void GEOMImpl_HealingDriver::LimitTolerance (GEOMImpl_IHealing* theHI,
592 const TopoDS_Shape& theOriginalShape,
593 TopoDS_Shape& theOutShape) const
595 Standard_Real aTol = theHI->GetTolerance();
596 if (aTol < Precision::Confusion())
597 aTol = Precision::Confusion();
599 // 1. Make a copy to prevent the original shape changes.
600 TopoDS_Shape aShapeCopy;
601 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
602 TNaming_CopyShape::CopyTool(theOriginalShape, aMapTShapes, aShapeCopy);
604 // 2. Limit tolerance.
605 ShapeFix_ShapeTolerance aSFT;
606 aSFT.LimitTolerance(aShapeCopy, aTol, aTol, TopAbs_SHAPE);
608 // 3. Fix obtained shape.
609 Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShapeCopy);
611 theOutShape = aSfs->Shape();
613 BRepCheck_Analyzer ana (theOutShape, Standard_True);
615 StdFail_NotDone::Raise("Non valid shape result");
618 //=======================================================================
619 //function : FuseCollinearEdges
621 //=======================================================================
622 void GEOMImpl_HealingDriver::FuseCollinearEdges (const TopoDS_Shape& theOriginalShape,
623 const Handle(TColStd_HSequenceOfTransient)& aVerts,
624 TopoDS_Shape& theOutShape)
626 if (theOriginalShape.ShapeType() != TopAbs_WIRE)
627 Standard_TypeMismatch::Raise("Not a wire is given");
630 Standard_Real AngTol = Precision::Angular();
631 Standard_Real LinTol = Precision::Confusion();
633 for (TopExp_Explorer ExV (theOriginalShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
634 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
635 tol = BRep_Tool::Tolerance(Vertex);
640 // 1. Make a copy to prevent the original shape changes.
642 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
643 TNaming_CopyShape::CopyTool(theOriginalShape, aMapTShapes, aWire);
644 TopoDS_Wire theWire = TopoDS::Wire(aWire);
646 // 2. Sub-shapes of the wire
647 TopTools_MapOfShape aMapToRemove;
649 TopTools_IndexedMapOfShape anOldIndices;
650 TopExp::MapShapes(theOriginalShape, anOldIndices);
652 TopTools_IndexedMapOfShape aNewIndices;
653 TopExp::MapShapes(theWire, aNewIndices);
655 // 3. Collect vertices of the wire, same or equal to the given vertices
656 bool removeAll = false;
657 if (aVerts.IsNull() || aVerts->Length() < 1)
661 for ( int ind = 1; ind <= aVerts->Length(); ind++) {
662 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aVerts->Value(ind));
663 TopoDS_Shape aShape_i = aRefShape->GetValue();
664 if (aShape_i.IsNull())
665 Standard_NullObject::Raise("Null vertex given");
666 if (aShape_i.ShapeType() != TopAbs_VERTEX)
667 Standard_TypeMismatch::Raise("Shape to suppress is not a vertex");
669 // find vertices shared with the initial wire
670 if (anOldIndices.Contains(aShape_i)) {
671 aMapToRemove.Add(aNewIndices.FindKey(anOldIndices.FindIndex(aShape_i)));
673 // try to find by coords in the new wire
674 TopoDS_Vertex aVert = TopoDS::Vertex(aShape_i);
675 gp_Pnt aP = BRep_Tool::Pnt(aVert);
677 bool isFound = false;
678 TopTools_MapOfShape mapShape;
679 TopExp_Explorer exp (theWire, TopAbs_VERTEX);
680 for (; exp.More() && !isFound; exp.Next()) {
681 if (mapShape.Add(exp.Current())) {
682 TopoDS_Vertex aVi = TopoDS::Vertex(exp.Current());
683 gp_Pnt aPi = BRep_Tool::Pnt(aVi);
684 if (aPi.Distance(aP) < LinTol) {
685 aMapToRemove.Add(aVi);
695 BRepLib::BuildCurves3d(theWire);
696 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(theWire);
697 Fixer->SetPrecision(LinTol);
698 Fixer->SetMaxTolerance(LinTol);
700 theWire = TopoDS::Wire(Fixer->Shape());
703 TopoDS_Edge prevEdge;
704 TopTools_ListOfShape finalList, currChain;
706 BRepTools_WireExplorer wexp (theWire);
708 prevEdge = wexp.Current();
709 currChain.Append(prevEdge);
713 Standard_NullObject::Raise("Empty wire given");
716 for (; wexp.More(); wexp.Next()) {
717 TopoDS_Edge anEdge = wexp.Current();
718 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
720 bool continueChain = false;
721 if (aMapToRemove.Contains(CurVertex) || removeAll) {
722 // if C1 -> continue chain
723 if (AreEdgesC1(prevEdge, anEdge)) {
724 continueChain = true;
728 if (!continueChain) {
729 if (currChain.Extent() == 1) {
730 // add one edge to the final list
731 finalList.Append(currChain.First());
734 // make wire from the list of edges
736 TopoDS_Wire aCurrWire;
737 B.MakeWire(aCurrWire);
738 TopTools_ListIteratorOfListOfShape itEdges (currChain);
739 for (; itEdges.More(); itEdges.Next()) {
740 TopoDS_Shape aValue = itEdges.Value();
741 B.Add(aCurrWire, TopoDS::Edge(aValue));
744 // make edge from the wire
745 TopoDS_Edge anEdge = GEOMImpl_ShapeDriver::MakeEdgeFromWire(aCurrWire, LinTol, AngTol);
747 // add this new edge to the final list
748 finalList.Append(anEdge);
753 // add one edge to the chain
754 currChain.Append(anEdge);
758 if (currChain.Extent() == 1) {
759 // add one edge to the final list
760 finalList.Append(currChain.First());
763 // make wire from the list of edges
765 TopoDS_Wire aCurrWire;
766 B.MakeWire(aCurrWire);
767 TopTools_ListIteratorOfListOfShape itEdges (currChain);
768 for (; itEdges.More(); itEdges.Next()) {
769 TopoDS_Shape aValue = itEdges.Value();
770 B.Add(aCurrWire, TopoDS::Edge(aValue));
773 // make edge from the wire
774 TopoDS_Edge anEdge = GEOMImpl_ShapeDriver::MakeEdgeFromWire(aCurrWire, LinTol, AngTol);
776 // add this new edge to the final list
777 finalList.Append(anEdge);
781 TopoDS_Wire aFinalWire;
782 B.MakeWire(aFinalWire);
783 TopTools_ListIteratorOfListOfShape itEdges (finalList);
784 for (; itEdges.More(); itEdges.Next()) {
785 TopoDS_Shape aValue = itEdges.Value();
786 B.Add(aFinalWire, TopoDS::Edge(aValue));
788 theOutShape = aFinalWire;
790 BRepCheck_Analyzer ana (theOutShape, Standard_True);
792 StdFail_NotDone::Raise("Non valid shape result");
795 //=======================================================================
796 //function : AreEdgesC1
798 //=======================================================================
799 Standard_Boolean GEOMImpl_HealingDriver::AreEdgesC1 (const TopoDS_Edge& E1, const TopoDS_Edge& E2)
801 BRepAdaptor_Curve aCurve1 (E1);
802 BRepAdaptor_Curve aCurve2 (E2);
804 if (aCurve1.Continuity() == GeomAbs_C0 || aCurve2.Continuity() == GeomAbs_C0)
805 return Standard_False;
807 Standard_Real tol, tolMax = Precision::Confusion();
808 for (TopExp_Explorer ExV1 (E1, TopAbs_VERTEX); ExV1.More(); ExV1.Next()) {
809 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV1.Current());
810 tol = BRep_Tool::Tolerance(Vertex);
814 for (TopExp_Explorer ExV2 (E2, TopAbs_VERTEX); ExV2.More(); ExV2.Next()) {
815 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV2.Current());
816 tol = BRep_Tool::Tolerance(Vertex);
821 Standard_Real f1, l1, f2, l2;
822 f1 = aCurve1.FirstParameter();
823 l1 = aCurve1.LastParameter();
824 f2 = aCurve2.FirstParameter();
825 l2 = aCurve2.LastParameter();
828 Standard_Real tmp = f1;
834 Standard_Real tmp = f2;
839 gp_Pnt pf1, pl1, pf2, pl2;
840 gp_Vec vf1, vl1, vf2, vl2;
841 aCurve1.D1(f1, pf1, vf1);
842 aCurve1.D1(l1, pl1, vl1);
843 aCurve2.D1(f2, pf2, vf2);
844 aCurve2.D1(l2, pl2, vl2);
846 // pf1--->---pl1.pf2--->---pl2
847 if (pl1.SquareDistance(pf2) < tolMax*tolMax) {
848 if (vl1.Angle(vf2) < Precision::Angular())
849 return Standard_True;
851 // pl1---<---pf1.pf2--->---pl2
852 else if (pf1.SquareDistance(pf2) < tolMax*tolMax) {
853 if (vf1.Angle(-vf2) < Precision::Angular())
854 return Standard_True;
856 // pf1--->---pl1.pl2---<---pf2
857 else if (pl1.SquareDistance(pl2) < tolMax*tolMax) {
858 if (vl1.Angle(-vl2) < Precision::Angular())
859 return Standard_True;
861 // pl1---<---pf1.pl2---<---pf2
863 if (vf1.Angle(vl2) < Precision::Angular())
864 return Standard_True;
867 return Standard_False;
870 //================================================================================
872 * \brief Returns a name of creation operation and names and values of creation parameters
874 //================================================================================
876 bool GEOMImpl_HealingDriver::
877 GetCreationInformation(std::string& theOperationName,
878 std::vector<GEOM_Param>& theParams)
880 if (Label().IsNull()) return 0;
881 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
883 GEOMImpl_IHealing aCI( function );
884 Standard_Integer aType = function->GetType();
889 theOperationName = "SHAPE_PROCESS";
890 AddParam( theParams, "Object", aCI.GetOriginal() );
891 Handle(TColStd_HArray1OfExtendedString) anOperators = aCI.GetOperators();
892 Handle(TColStd_HArray1OfExtendedString) aParams = aCI.GetParameters();
893 Handle(TColStd_HArray1OfExtendedString) aValues = aCI.GetValues();
894 for ( int i = anOperators->Lower(), nb = anOperators->Upper(); i <= nb; ++i )
896 const TCollection_ExtendedString& op = anOperators->Value(i);
897 AddParam( theParams, "Operation", op );
898 for ( int iP = aParams->Lower(), nbP = aParams->Upper(); iP <= nbP; ++iP )
900 const TCollection_ExtendedString& par = aParams->Value(i);
901 TCollection_AsciiString parAscii( par );
902 if ( par.Search( op ) == 1 && parAscii.Value( op.Length() + 1 ) == '.' )
904 GEOM_Param& p = AddParam( theParams, parAscii.ToCString() );
905 if ( iP <= aValues->Upper() )
906 p << aValues->Value( iP );
913 theOperationName = "SUPPRESS_FACES";
914 AddParam( theParams, "Selected Shape", aCI.GetOriginal() );
915 AddParam( theParams, "Faces to remove", aCI.GetFaces() );
918 theOperationName = "CLOSE_CONTOUR";
919 AddParam( theParams, "Selected Shape", aCI.GetOriginal() );
920 AddParam( theParams, "Contour to close", aCI.GetWires() );
921 AddParam( theParams, "Close by common vertex", aCI.GetIsCommonVertex() );
923 case REMOVE_INT_WIRES:
924 theOperationName = "SUPPRESS_INT_WIRES";
925 AddParam( theParams, "Selected face", aCI.GetOriginal() );
926 AddParam( theParams, "Wires to remove", aCI.GetWires(), "all" );
929 theOperationName = "SUPPERSS_HOLES";
930 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
931 AddParam( theParams, "Wires to remove", aCI.GetWires(), "all" );
934 case SEWING_NON_MANIFOLD:
935 theOperationName = "SEWING";
936 AddParam( theParams, "Selected shapes", aCI.GetOriginalAndShapes() );
937 AddParam( theParams, "Allow Non Manifold", ( aType == SEWING_NON_MANIFOLD ));
938 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
941 theOperationName = "POINT_ON_EDGE";
942 if ( aCI.GetIndex() > 0 )
943 AddParam( theParams, "Edge", "#" ) << aCI.GetIndex() << " of " << aCI.GetOriginal();
945 AddParam( theParams, "Edge", aCI.GetOriginal() );
946 AddParam( theParams, "By parameter", aCI.GetIsByParameter() );
947 AddParam( theParams, "Value", aCI.GetDevideEdgeValue() );
949 case CHANGE_ORIENTATION:
950 theOperationName = "CHANGE_ORIENTATION";
951 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
953 case LIMIT_TOLERANCE:
954 theOperationName = "LIMIT_TOLERANCE";
955 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
956 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
958 case FUSE_COLLINEAR_EDGES:
959 theOperationName = "FUSE_EDGES";
960 AddParam( theParams, "Wire", aCI.GetOriginal() );
961 AddParam( theParams, "Vertexes", aCI.GetShapes() );
963 case REMOVE_INTERNAL_FACES:
964 theOperationName = "REMOVE_WEBS";
965 AddParam( theParams, "Selected shapes", aCI.GetOriginalAndShapes() );
973 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_HealingDriver,GEOM_BaseDriver);
975 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_HealingDriver,GEOM_BaseDriver);