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 <GEOMImpl_HealingDriver.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOMImpl_IHealing.hxx>
26 #include <GEOM_Function.hxx>
28 #include <GEOMImpl_GlueDriver.hxx>
29 #include <GEOMImpl_ShapeDriver.hxx>
31 #include <GEOMUtils.hxx>
32 #include <GEOMAlgo_RemoverWebs.hxx>
34 #include <ShHealOper_ShapeProcess.hxx>
35 #include <ShHealOper_RemoveFace.hxx>
36 #include <ShHealOper_CloseContour.hxx>
37 #include <ShHealOper_RemoveInternalWires.hxx>
38 #include <ShHealOper_FillHoles.hxx>
39 #include <ShHealOper_Sewing.hxx>
40 #include <ShHealOper_EdgeDivide.hxx>
41 #include <ShHealOper_ChangeOrientation.hxx>
43 #include <TNaming_CopyShape.hxx>
45 #include <BRep_Builder.hxx>
46 #include <BRepAdaptor_Curve.hxx>
47 #include <BRepTools_WireExplorer.hxx>
50 #include <TopExp_Explorer.hxx>
52 #include <TopoDS_Iterator.hxx>
53 #include <TopTools_IndexedMapOfShape.hxx>
54 #include <TopTools_ListOfShape.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
57 #include <TColStd_IndexedDataMapOfTransientTransient.hxx>
59 #include <Precision.hxx>
61 #include <StdFail_NotDone.hxx>
62 #include <Standard_NullObject.hxx>
64 //=======================================================================
65 //function : raiseNotDoneExeption
66 //purpose : global function: forms error message and raises exeption
67 //=======================================================================
68 void raiseNotDoneExeption( const int theErrorStatus )
70 switch ( theErrorStatus )
72 case ShHealOper_NotError: StdFail_NotDone::Raise( "ShHealOper_NotError_msg" );
73 case ShHealOper_InvalidParameters: StdFail_NotDone::Raise( "ShHealOper_InvalidParameters_msg" );
74 case ShHealOper_ErrorExecution:
75 default: StdFail_NotDone::Raise( "ShHealOper_ErrorExecution_msg" );
79 //=======================================================================
82 //=======================================================================
83 const Standard_GUID& GEOMImpl_HealingDriver::GetID()
85 static Standard_GUID aHealingDriver("FF1BBB61-5D14-4df2-980B-3A668264EA16");
86 return aHealingDriver;
89 //=======================================================================
90 //function : GEOMImpl_HealingDriver
92 //=======================================================================
93 GEOMImpl_HealingDriver::GEOMImpl_HealingDriver()
97 //=======================================================================
100 //=======================================================================
101 Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const
103 if (Label().IsNull()) return 0;
104 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
106 if (aFunction.IsNull()) return 0;
108 GEOMImpl_IHealing HI (aFunction);
109 Standard_Integer aType = aFunction->GetType();
110 Handle(GEOM_Function) anOriginalFunction = HI.GetOriginal();
111 if (anOriginalFunction.IsNull()) return 0;
112 TopoDS_Shape aShape, anOriginalShape = anOriginalFunction->GetValue();
113 if (anOriginalShape.IsNull()) return 0;
118 ShapeProcess(&HI, anOriginalShape, aShape);
121 SuppressFaces(&HI, anOriginalShape, aShape);
124 CloseContour(&HI, anOriginalShape, aShape);
126 case REMOVE_INT_WIRES:
127 RemoveIntWires(&HI, anOriginalShape, aShape);
130 RemoveHoles(&HI, anOriginalShape, aShape);
133 Sew(&HI, anOriginalShape, aShape, false);
135 case SEWING_NON_MANIFOLD:
136 Sew(&HI, anOriginalShape, aShape, true);
138 case REMOVE_INTERNAL_FACES:
139 RemoveInternalFaces(anOriginalShape, aShape);
142 AddPointOnEdge(&HI, anOriginalShape, aShape);
144 case CHANGE_ORIENTATION:
145 ChangeOrientation(&HI, anOriginalShape, aShape);
147 case LIMIT_TOLERANCE:
148 LimitTolerance(&HI, anOriginalShape, aShape);
150 case FUSE_COLLINEAR_EDGES:
152 Handle(TColStd_HSequenceOfTransient) aVerts = HI.GetShapes();
153 FuseCollinearEdges(anOriginalShape, aVerts, aShape);
161 raiseNotDoneExeption( ShHealOper_ErrorExecution );
163 aFunction->SetValue(aShape);
165 log.SetTouched(Label());
169 //=======================================================================
170 //function : ShapeProcess
172 //=======================================================================
173 Standard_Boolean GEOMImpl_HealingDriver::ShapeProcess (GEOMImpl_IHealing* theHI,
174 const TopoDS_Shape& theOriginalShape,
175 TopoDS_Shape& theOutShape) const
177 Handle(TColStd_HArray1OfExtendedString) anOperators = theHI->GetOperators();
178 Handle(TColStd_HArray1OfExtendedString) aParams = theHI->GetParameters();
179 Handle(TColStd_HArray1OfExtendedString) aValues = theHI->GetValues();
181 if (anOperators.IsNull() || anOperators->Length() <= 0)
182 return Standard_False;
184 Standard_Integer nbParams = 0, nbValues = 0;
185 if (!aParams.IsNull()) {
186 nbParams = aParams->Length();
188 if (!aValues.IsNull()) {
189 nbValues = aValues->Length();
191 if (nbParams != nbValues)
192 return Standard_False;
194 ShHealOper_ShapeProcess aHealer;
195 TColStd_SequenceOfAsciiString anOperatorsAS, aParamsAS, aValuesAS;
197 for (i = 1; i <= anOperators->Length(); i++)
198 anOperatorsAS.Append(TCollection_AsciiString(anOperators->Value(i)));
200 aHealer.SetOperators(anOperatorsAS);
202 for (i = 1; i <= nbParams; i++) {
203 aHealer.SetParameter(TCollection_AsciiString(aParams->Value(i)),
204 TCollection_AsciiString(aValues->Value(i)));
207 aHealer.Perform(theOriginalShape, theOutShape);
209 if (!aHealer.isDone())
210 raiseNotDoneExeption( ShHealOper_NotError );
212 return Standard_True;
215 //=======================================================================
216 //function : SupressFaces
218 //=======================================================================
219 void SuppressFacesRec (const TopTools_SequenceOfShape& theShapesFaces,
220 const TopoDS_Shape& theOriginalShape,
221 TopoDS_Shape& theOutShape)
223 if ((theOriginalShape.ShapeType() != TopAbs_COMPOUND &&
224 theOriginalShape.ShapeType() != TopAbs_COMPSOLID))
226 ShHealOper_RemoveFace aHealer (theOriginalShape);
227 Standard_Boolean aResult = aHealer.Perform(theShapesFaces);
230 theOutShape = aHealer.GetResultShape();
232 raiseNotDoneExeption(aHealer.GetErrorStatus());
240 TopTools_MapOfShape mapShape;
241 TopoDS_Iterator It (theOriginalShape, Standard_True, Standard_True);
243 for (; It.More(); It.Next()) {
244 TopoDS_Shape aShape_i = It.Value();
245 if (mapShape.Add(aShape_i)) {
246 // check, if current shape contains at least one of faces to be removed
247 bool isFound = false;
248 TopTools_IndexedMapOfShape aShapes_i;
249 TopExp::MapShapes(aShape_i, aShapes_i);
250 for (int i = 1; i <= theShapesFaces.Length() && !isFound; i++) {
251 const TopoDS_Shape& aFace_i = theShapesFaces.Value(i);
252 if (aShapes_i.Contains(aFace_i)) isFound = true;
255 TopoDS_Shape anOutSh_i;
256 SuppressFacesRec(theShapesFaces, aShape_i, anOutSh_i);
257 if ( !anOutSh_i.IsNull() )
258 BB.Add(CC, anOutSh_i);
262 BB.Add(CC, aShape_i);
270 Standard_Boolean GEOMImpl_HealingDriver::SuppressFaces (GEOMImpl_IHealing* theHI,
271 const TopoDS_Shape& theOriginalShape,
272 TopoDS_Shape& theOutShape) const
274 Handle(TColStd_HArray1OfInteger) aFaces = theHI->GetFaces();
276 Standard_Boolean aResult = Standard_False;
278 if (aFaces.IsNull()) {
279 ShHealOper_RemoveFace aHealer (theOriginalShape);
280 aResult = aHealer.Perform();
283 theOutShape = aHealer.GetResultShape();
285 raiseNotDoneExeption(aHealer.GetErrorStatus());
288 TopTools_SequenceOfShape aShapesFaces;
289 TopTools_IndexedMapOfShape aShapes;
290 TopExp::MapShapes(theOriginalShape, aShapes);
291 for (int i = 1; i <= aFaces->Length(); i++) {
292 int indexOfFace = aFaces->Value(i);
293 TopoDS_Shape aFace = aShapes.FindKey(indexOfFace);
294 aShapesFaces.Append(aFace);
296 SuppressFacesRec(aShapesFaces, theOriginalShape, theOutShape);
297 if ((theOriginalShape.ShapeType() == TopAbs_COMPOUND ||
298 theOriginalShape.ShapeType() == TopAbs_COMPSOLID)) {
299 TopoDS_Shape aSh = theOutShape;
300 theOutShape = GEOMImpl_GlueDriver::GlueFaces(aSh, Precision::Confusion(), Standard_True);
304 return Standard_True;
307 //=======================================================================
308 //function : CloseContour
310 //=======================================================================
311 Standard_Boolean GEOMImpl_HealingDriver::CloseContour (GEOMImpl_IHealing* theHI,
312 const TopoDS_Shape& theOriginalShape,
313 TopoDS_Shape& theOutShape) const
315 Standard_Boolean isByVertex = theHI->GetIsCommonVertex();
316 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
318 ShHealOper_CloseContour aHealer (theOriginalShape);
320 Standard_Boolean aResult = Standard_False;
321 if ( aWires.IsNull() ) {
322 if ( theOriginalShape.ShapeType() == TopAbs_WIRE )
323 aResult = aHealer.Perform(TopoDS::Wire(theOriginalShape), isByVertex, !isByVertex);
326 TopTools_SequenceOfShape aShapesWires;
327 TopTools_IndexedMapOfShape aShapes;
328 TopExp::MapShapes(theOriginalShape, aShapes);
329 for (int i = 1; i <= aWires->Length(); i++) {
330 int indexOfWire = aWires->Value(i);
331 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
332 aShapesWires.Append(aWire);
335 aResult = aHealer.Perform( aShapesWires, isByVertex, !isByVertex );
339 theOutShape = aHealer.GetResultShape();
341 raiseNotDoneExeption( aHealer.GetErrorStatus() );
346 //=======================================================================
347 //function : RemoveIntWires
349 //=======================================================================
350 Standard_Boolean GEOMImpl_HealingDriver::RemoveIntWires (GEOMImpl_IHealing* theHI,
351 const TopoDS_Shape& theOriginalShape,
352 TopoDS_Shape& theOutShape) const
354 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
356 ShHealOper_RemoveInternalWires aHealer(theOriginalShape);
358 Standard_Boolean aResult = Standard_False;
359 if (aWires.IsNull()) { // remove all faces
360 aResult = aHealer.Remove();
362 TopTools_SequenceOfShape aShapesWires;
363 TopTools_IndexedMapOfShape aShapes;
364 TopExp::MapShapes(theOriginalShape, aShapes);
365 for (int i = 1; i <= aWires->Length(); i++) {
366 int indexOfWire = aWires->Value(i);
367 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
368 aShapesWires.Append(aWire);
371 aResult = aHealer.Remove(aShapesWires);
375 theOutShape = aHealer.GetResultShape();
377 raiseNotDoneExeption( aHealer.GetErrorStatus() );
382 //=======================================================================
383 //function : RemoveHoles
385 //=======================================================================
386 Standard_Boolean GEOMImpl_HealingDriver::RemoveHoles (GEOMImpl_IHealing* theHI,
387 const TopoDS_Shape& theOriginalShape,
388 TopoDS_Shape& theOutShape) const
390 Handle(TColStd_HArray1OfInteger) aWires = theHI->GetWires();
392 ShHealOper_FillHoles aHealer (theOriginalShape);
394 Standard_Boolean aResult = Standard_False;
395 if (aWires.IsNull()) { // remove all faces
396 aResult = aHealer.Fill();
398 TopTools_SequenceOfShape aShapesWires;
399 TopTools_IndexedMapOfShape aShapes;
400 TopExp::MapShapes(theOriginalShape, aShapes);
401 for (int i = 1; i <= aWires->Length(); i++) {
402 int indexOfWire = aWires->Value(i);
403 TopoDS_Shape aWire = aShapes.FindKey(indexOfWire);
404 aShapesWires.Append(aWire);
407 aResult = aHealer.Fill(aShapesWires);
411 theOutShape = aHealer.GetResultShape();
413 raiseNotDoneExeption( aHealer.GetErrorStatus() );
418 //=======================================================================
421 //=======================================================================
422 Standard_Boolean GEOMImpl_HealingDriver::Sew (GEOMImpl_IHealing* theHI,
423 const TopoDS_Shape& theOriginalShape,
424 TopoDS_Shape& theOutShape,
425 Standard_Boolean isAllowNonManifold) const
427 Standard_Real aTol = theHI->GetTolerance();
429 ShHealOper_Sewing aHealer (theOriginalShape, aTol);
431 // Set non-manifold mode.
432 aHealer.SetNonManifoldMode(isAllowNonManifold);
434 Standard_Boolean aResult = aHealer.Perform();
437 theOutShape = aHealer.GetResultShape();
439 raiseNotDoneExeption( aHealer.GetErrorStatus() );
444 //=======================================================================
445 //function : RemoveInternalFaces
447 //=======================================================================
448 Standard_Boolean GEOMImpl_HealingDriver::RemoveInternalFaces (const TopoDS_Shape& theOriginalShape,
449 TopoDS_Shape& theOutShape) const
451 GEOMAlgo_RemoverWebs aTool;
452 aTool.SetShape(theOriginalShape);
455 if (aTool.ErrorStatus() == 0) { // OK
456 theOutShape = aTool.Result();
458 // as GEOMAlgo_RemoverWebs always produces compound, lets simplify it
459 // for the case, if it contains only one sub-shape
460 TopTools_ListOfShape listShapeRes;
461 GEOMUtils::AddSimpleShapes(theOutShape, listShapeRes);
462 if (listShapeRes.Extent() == 1) {
463 theOutShape = listShapeRes.First();
466 else if (aTool.ErrorStatus() == 11) // invalid argument (contains non-solids), do nothing
467 theOutShape = theOriginalShape;
469 StdFail_NotDone::Raise("GEOMAlgo_RemoverWebs failed!");
471 return Standard_True;
474 //=======================================================================
475 //function : AddPointOnEdge
477 //=======================================================================
478 Standard_Boolean GEOMImpl_HealingDriver::AddPointOnEdge (GEOMImpl_IHealing* theHI,
479 const TopoDS_Shape& theOriginalShape,
480 TopoDS_Shape& theOutShape) const
482 Standard_Boolean isByParameter = theHI->GetIsByParameter();
483 Standard_Integer anIndex = theHI->GetIndex();
484 Standard_Real aValue = theHI->GetDevideEdgeValue();
486 ShHealOper_EdgeDivide aHealer (theOriginalShape);
488 Standard_Boolean aResult = Standard_False;
489 if (anIndex == -1) { // apply algorythm for the whole shape which is EDGE
490 if (theOriginalShape.ShapeType() == TopAbs_EDGE)
491 aResult = aHealer.Perform(TopoDS::Edge(theOriginalShape), aValue, isByParameter);
493 TopTools_IndexedMapOfShape aShapes;
494 TopExp::MapShapes(theOriginalShape, aShapes);
495 TopoDS_Shape aEdgeShape = aShapes.FindKey(anIndex);
496 if (aEdgeShape.ShapeType() == TopAbs_EDGE)
497 aResult = aHealer.Perform(TopoDS::Edge(aEdgeShape), aValue, isByParameter);
501 theOutShape = aHealer.GetResultShape();
503 raiseNotDoneExeption( aHealer.GetErrorStatus() );
509 //=======================================================================
510 //function : ChangeOrientation
512 //=======================================================================
513 Standard_Boolean GEOMImpl_HealingDriver::ChangeOrientation (GEOMImpl_IHealing* theHI,
514 const TopoDS_Shape& theOriginalShape,
515 TopoDS_Shape& theOutShape) const
517 ShHealOper_ChangeOrientation aHealer (theOriginalShape);
519 Standard_Boolean aResult = aHealer.Perform();
522 theOutShape = aHealer.GetResultShape();
524 raiseNotDoneExeption( aHealer.GetErrorStatus() );
529 //=======================================================================
530 //function : LimitTolerance
532 //=======================================================================
533 void GEOMImpl_HealingDriver::LimitTolerance (GEOMImpl_IHealing* theHI,
534 const TopoDS_Shape& theOriginalShape,
535 TopoDS_Shape& theOutShape) const
537 Standard_Real aTol = theHI->GetTolerance();
538 TopAbs_ShapeEnum aType = theHI->GetType();
540 if (aTol < Precision::Confusion())
541 aTol = Precision::Confusion();
543 // 1. Make a copy to prevent the original shape changes.
544 TopoDS_Shape aShapeCopy;
545 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
546 TNaming_CopyShape::CopyTool(theOriginalShape, aMapTShapes, aShapeCopy);
548 // 2. Limit tolerance.
549 if (!GEOMUtils::FixShapeTolerance(aShapeCopy, aType, aTol))
550 StdFail_NotDone::Raise("Non valid shape result");
552 theOutShape = aShapeCopy;
555 //=======================================================================
556 //function : FuseCollinearEdges
558 //=======================================================================
559 void GEOMImpl_HealingDriver::FuseCollinearEdges (const TopoDS_Shape& theOriginalShape,
560 const Handle(TColStd_HSequenceOfTransient)& aVerts,
561 TopoDS_Shape& theOutShape)
563 if (theOriginalShape.ShapeType() != TopAbs_WIRE)
564 Standard_TypeMismatch::Raise("Not a wire is given");
567 Standard_Real AngTol = Precision::Angular();
568 Standard_Real LinTol = Precision::Confusion();
570 for (TopExp_Explorer ExV (theOriginalShape, TopAbs_VERTEX); ExV.More(); ExV.Next()) {
571 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV.Current());
572 tol = BRep_Tool::Tolerance(Vertex);
577 // 1. Make a copy to prevent the original shape changes.
579 TColStd_IndexedDataMapOfTransientTransient aMapTShapes;
580 TNaming_CopyShape::CopyTool(theOriginalShape, aMapTShapes, aWire);
581 TopoDS_Wire theWire = TopoDS::Wire(aWire);
583 // 2. Sub-shapes of the wire
584 TopTools_MapOfShape aMapToRemove;
586 TopTools_IndexedMapOfShape anOldIndices;
587 TopExp::MapShapes(theOriginalShape, anOldIndices);
589 TopTools_IndexedMapOfShape aNewIndices;
590 TopExp::MapShapes(theWire, aNewIndices);
592 // 3. Collect vertices of the wire, same or equal to the given vertices
593 bool removeAll = false;
594 if (aVerts.IsNull() || aVerts->Length() < 1)
598 for (unsigned int ind = 1; ind <= aVerts->Length(); ind++) {
599 Handle(GEOM_Function) aRefShape = Handle(GEOM_Function)::DownCast(aVerts->Value(ind));
600 TopoDS_Shape aShape_i = aRefShape->GetValue();
601 if (aShape_i.IsNull())
602 Standard_NullObject::Raise("Null vertex given");
603 if (aShape_i.ShapeType() != TopAbs_VERTEX)
604 Standard_TypeMismatch::Raise("Shape to suppress is not a vertex");
606 // find vertices shared with the initial wire
607 if (anOldIndices.Contains(aShape_i)) {
608 aMapToRemove.Add(aNewIndices.FindKey(anOldIndices.FindIndex(aShape_i)));
610 // try to find by coords in the new wire
611 TopoDS_Vertex aVert = TopoDS::Vertex(aShape_i);
612 gp_Pnt aP = BRep_Tool::Pnt(aVert);
614 bool isFound = false;
615 TopTools_MapOfShape mapShape;
616 TopExp_Explorer exp (theWire, TopAbs_VERTEX);
617 for (; exp.More() && !isFound; exp.Next()) {
618 if (mapShape.Add(exp.Current())) {
619 TopoDS_Vertex aVi = TopoDS::Vertex(exp.Current());
620 gp_Pnt aPi = BRep_Tool::Pnt(aVi);
621 if (aPi.Distance(aP) < LinTol) {
622 aMapToRemove.Add(aVi);
632 BRepLib::BuildCurves3d(theWire);
633 Handle(ShapeFix_Shape) Fixer = new ShapeFix_Shape(theWire);
634 Fixer->SetPrecision(LinTol);
635 Fixer->SetMaxTolerance(LinTol);
637 theWire = TopoDS::Wire(Fixer->Shape());
640 TopoDS_Edge prevEdge;
641 TopTools_ListOfShape finalList, currChain;
643 BRepTools_WireExplorer wexp (theWire);
645 prevEdge = wexp.Current();
646 currChain.Append(prevEdge);
650 Standard_NullObject::Raise("Empty wire given");
653 for (; wexp.More(); wexp.Next()) {
654 TopoDS_Edge anEdge = wexp.Current();
655 TopoDS_Vertex CurVertex = wexp.CurrentVertex();
657 bool continueChain = false;
658 if (aMapToRemove.Contains(CurVertex) || removeAll) {
659 // if C1 -> continue chain
660 if (AreEdgesC1(prevEdge, anEdge)) {
661 continueChain = true;
665 if (!continueChain) {
666 if (currChain.Extent() == 1) {
667 // add one edge to the final list
668 finalList.Append(currChain.First());
671 // make wire from the list of edges
673 TopoDS_Wire aCurrWire;
674 B.MakeWire(aCurrWire);
675 TopTools_ListIteratorOfListOfShape itEdges (currChain);
676 for (; itEdges.More(); itEdges.Next()) {
677 TopoDS_Shape aValue = itEdges.Value();
678 B.Add(aCurrWire, TopoDS::Edge(aValue));
681 // make edge from the wire
682 TopoDS_Edge anEdge = GEOMImpl_ShapeDriver::MakeEdgeFromWire(aCurrWire, LinTol, AngTol);
684 // add this new edge to the final list
685 finalList.Append(anEdge);
690 // add one edge to the chain
691 currChain.Append(anEdge);
695 if (currChain.Extent() == 1) {
696 // add one edge to the final list
697 finalList.Append(currChain.First());
700 // make wire from the list of edges
702 TopoDS_Wire aCurrWire;
703 B.MakeWire(aCurrWire);
704 TopTools_ListIteratorOfListOfShape itEdges (currChain);
705 for (; itEdges.More(); itEdges.Next()) {
706 TopoDS_Shape aValue = itEdges.Value();
707 B.Add(aCurrWire, TopoDS::Edge(aValue));
710 // make edge from the wire
711 TopoDS_Edge anEdge = GEOMImpl_ShapeDriver::MakeEdgeFromWire(aCurrWire, LinTol, AngTol);
713 // add this new edge to the final list
714 finalList.Append(anEdge);
718 TopoDS_Wire aFinalWire;
719 B.MakeWire(aFinalWire);
720 TopTools_ListIteratorOfListOfShape itEdges (finalList);
721 for (; itEdges.More(); itEdges.Next()) {
722 TopoDS_Shape aValue = itEdges.Value();
723 B.Add(aFinalWire, TopoDS::Edge(aValue));
725 theOutShape = aFinalWire;
727 if (!GEOMUtils::CheckShape(theOutShape, true))
728 StdFail_NotDone::Raise("Non valid shape result");
731 //=======================================================================
732 //function : AreEdgesC1
734 //=======================================================================
735 Standard_Boolean GEOMImpl_HealingDriver::AreEdgesC1 (const TopoDS_Edge& E1, const TopoDS_Edge& E2)
737 BRepAdaptor_Curve aCurve1 (E1);
738 BRepAdaptor_Curve aCurve2 (E2);
740 if (aCurve1.Continuity() == GeomAbs_C0 || aCurve2.Continuity() == GeomAbs_C0)
741 return Standard_False;
743 Standard_Real tol, tolMax = Precision::Confusion();
744 for (TopExp_Explorer ExV1 (E1, TopAbs_VERTEX); ExV1.More(); ExV1.Next()) {
745 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV1.Current());
746 tol = BRep_Tool::Tolerance(Vertex);
750 for (TopExp_Explorer ExV2 (E2, TopAbs_VERTEX); ExV2.More(); ExV2.Next()) {
751 TopoDS_Vertex Vertex = TopoDS::Vertex(ExV2.Current());
752 tol = BRep_Tool::Tolerance(Vertex);
757 Standard_Real f1, l1, f2, l2;
758 f1 = aCurve1.FirstParameter();
759 l1 = aCurve1.LastParameter();
760 f2 = aCurve2.FirstParameter();
761 l2 = aCurve2.LastParameter();
764 Standard_Real tmp = f1;
770 Standard_Real tmp = f2;
775 gp_Pnt pf1, pl1, pf2, pl2;
776 gp_Vec vf1, vl1, vf2, vl2;
777 aCurve1.D1(f1, pf1, vf1);
778 aCurve1.D1(l1, pl1, vl1);
779 aCurve2.D1(f2, pf2, vf2);
780 aCurve2.D1(l2, pl2, vl2);
782 // pf1--->---pl1.pf2--->---pl2
783 if (pl1.SquareDistance(pf2) < tolMax*tolMax) {
784 if (vl1.Angle(vf2) < Precision::Angular())
785 return Standard_True;
787 // pl1---<---pf1.pf2--->---pl2
788 else if (pf1.SquareDistance(pf2) < tolMax*tolMax) {
789 if (vf1.Angle(-vf2) < Precision::Angular())
790 return Standard_True;
792 // pf1--->---pl1.pl2---<---pf2
793 else if (pl1.SquareDistance(pl2) < tolMax*tolMax) {
794 if (vl1.Angle(-vl2) < Precision::Angular())
795 return Standard_True;
797 // pl1---<---pf1.pl2---<---pf2
799 if (vf1.Angle(vl2) < Precision::Angular())
800 return Standard_True;
803 return Standard_False;
806 //================================================================================
808 * \brief Returns a name of creation operation and names and values of creation parameters
810 //================================================================================
812 bool GEOMImpl_HealingDriver::
813 GetCreationInformation(std::string& theOperationName,
814 std::vector<GEOM_Param>& theParams)
816 if (Label().IsNull()) return 0;
817 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
819 GEOMImpl_IHealing aCI( function );
820 Standard_Integer aType = function->GetType();
825 theOperationName = "SHAPE_PROCESS";
826 AddParam( theParams, "Object", aCI.GetOriginal() );
827 Handle(TColStd_HArray1OfExtendedString) anOperators = aCI.GetOperators();
828 Handle(TColStd_HArray1OfExtendedString) aParams = aCI.GetParameters();
829 Handle(TColStd_HArray1OfExtendedString) aValues = aCI.GetValues();
830 for ( int i = anOperators->Lower(), nb = anOperators->Upper(); i <= nb; ++i )
832 const TCollection_ExtendedString& op = anOperators->Value(i);
833 AddParam( theParams, "Operation", op );
834 for ( int iP = aParams->Lower(), nbP = aParams->Upper(); iP <= nbP; ++iP )
836 const TCollection_ExtendedString& par = aParams->Value(i);
837 TCollection_AsciiString parAscii( par );
838 if ( par.Search( op ) == 1 && parAscii.Value( op.Length() + 1 ) == '.' )
840 GEOM_Param& p = AddParam( theParams, parAscii.ToCString() );
841 if ( iP <= aValues->Upper() )
842 p << aValues->Value( iP );
849 theOperationName = "SUPPRESS_FACES";
850 AddParam( theParams, "Selected Shape", aCI.GetOriginal() );
851 AddParam( theParams, "Faces to remove", aCI.GetFaces() );
854 theOperationName = "CLOSE_CONTOUR";
855 AddParam( theParams, "Selected Shape", aCI.GetOriginal() );
856 AddParam( theParams, "Contour to close", aCI.GetWires() );
857 AddParam( theParams, "Close by common vertex", aCI.GetIsCommonVertex() );
859 case REMOVE_INT_WIRES:
860 theOperationName = "SUPPRESS_INT_WIRES";
861 AddParam( theParams, "Selected face", aCI.GetOriginal() );
862 AddParam( theParams, "Wires to remove", aCI.GetWires(), "all" );
865 theOperationName = "SUPPERSS_HOLES";
866 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
867 AddParam( theParams, "Wires to remove", aCI.GetWires(), "all" );
870 case SEWING_NON_MANIFOLD:
871 theOperationName = "SEWING";
872 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
873 AddParam( theParams, "Allow Non Manifold", ( aType == SEWING_NON_MANIFOLD ));
874 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
877 theOperationName = "POINT_ON_EDGE";
878 if ( aCI.GetIndex() > 0 )
879 AddParam( theParams, "Edge", "#" ) << aCI.GetIndex() << " of " << aCI.GetOriginal();
881 AddParam( theParams, "Edge", aCI.GetOriginal() );
882 AddParam( theParams, "By parameter", aCI.GetIsByParameter() );
883 AddParam( theParams, "Value", aCI.GetDevideEdgeValue() );
885 case CHANGE_ORIENTATION:
886 theOperationName = "CHANGE_ORIENTATION";
887 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
889 case LIMIT_TOLERANCE:
890 theOperationName = "LIMIT_TOLERANCE";
891 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
892 AddParam( theParams, "Tolerance", aCI.GetTolerance() );
893 AddParam( theParams, "Type", aCI.GetType() );
895 case FUSE_COLLINEAR_EDGES:
896 theOperationName = "FUSE_EDGES";
897 AddParam( theParams, "Wire", aCI.GetOriginal() );
898 AddParam( theParams, "Vertexes", aCI.GetShapes() );
900 case REMOVE_INTERNAL_FACES:
901 theOperationName = "REMOVE_WEBS";
902 AddParam( theParams, "Selected shape", aCI.GetOriginal() );
910 IMPLEMENT_STANDARD_HANDLE (GEOMImpl_HealingDriver,GEOM_BaseDriver);
912 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_HealingDriver,GEOM_BaseDriver);