1 // File: ShHealOper_RemoveInternalWires.cxx
2 // Created: 26.04.04 14:46:45
3 // Author: Galina KULIKOVA
4 // < MODULE = KERNEL> <PACKAGE = ShHealOper> : <Shape Healing Operations>
5 // Copyright (C) 2003 CEA
7 // This library is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU Lesser General Public
9 // License as published by the Free Software Foundation; either
10 // version 2.1 of the License.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <ShHealOper_RemoveInternalWires.hxx>
26 #include <TopExp_Explorer.hxx>
27 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopTools_ListOfShape.hxx>
30 #include <TopTools_ListIteratorOfListOfShape.hxx>
31 #include <ShapeAnalysis.hxx>
32 #include <ShapeFix_Shape.hxx>
34 //=======================================================================
35 //function : ShHealOper_RemoveInternalWires()
36 //purpose : Constructor
37 //=======================================================================
39 ShHealOper_RemoveInternalWires::ShHealOper_RemoveInternalWires ( const TopoDS_Shape& theShape )
43 //=======================================================================
46 //=======================================================================
48 void ShHealOper_RemoveInternalWires::Init(const TopoDS_Shape& theShape)
50 ShHealOper_Tool::Init(theShape);
51 myMapWiresFace.Clear();
52 TopExp::MapShapesAndAncestors(theShape,TopAbs_WIRE,TopAbs_FACE,myMapWiresFace);
54 //=======================================================================
57 //=======================================================================
59 Standard_Boolean ShHealOper_RemoveInternalWires::Remove()
61 TopExp_Explorer aexpFaces(myInitShape,TopAbs_FACE);
62 //removes internal wires from all faces in the shape
63 Standard_Boolean isDone = Standard_False;
64 for( ; aexpFaces.More(); aexpFaces.Next())
65 isDone = removeWire(TopoDS::Face(aexpFaces.Current()),TopoDS_Wire()) || isDone;
67 TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
68 //fix not-connected shell and solids obtained after removing wires
74 //=======================================================================
77 //=======================================================================
79 Standard_Boolean ShHealOper_RemoveInternalWires::Remove(const TopTools_SequenceOfShape& theRemovedShapes)
81 myDone = Standard_False;
83 Standard_Integer i =1;
84 for( ; i <= theRemovedShapes.Length(); i++) {
85 //removes internal wires from specified faces.
86 if(theRemovedShapes.Value(i).ShapeType() == TopAbs_FACE)
87 myDone = (removeWire(TopoDS::Face(theRemovedShapes.Value(i)),TopoDS_Wire()) || myDone) ;
88 else if(theRemovedShapes.Value(i).ShapeType() == TopAbs_WIRE)
90 //removes specified internal wires.
91 TopoDS_Wire awire = TopoDS::Wire(theRemovedShapes.Value(i));
92 if(myMapWiresFace.Contains(awire)) {
93 const TopTools_ListOfShape& aLfaces = myMapWiresFace.FindFromKey(awire);
94 TopTools_ListIteratorOfListOfShape liter(aLfaces);
95 for( ; liter.More(); liter.Next())
96 myDone = (removeWire(TopoDS::Face(liter.Value()),awire) || myDone);
101 TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
103 //fix not-connected shell and solids obtained after removing wires
109 //=======================================================================
110 //function : removeWire
112 //=======================================================================
114 Standard_Boolean ShHealOper_RemoveInternalWires::removeWire(const TopoDS_Face& theFace,
115 const TopoDS_Wire& theWire)
117 TopoDS_Wire aBoundWire = ShapeAnalysis::OuterWire(theFace);
118 if(!theWire.IsNull() && aBoundWire.IsSame(theWire)) {
119 myErrorStatus = ShHealOper_InvalidParameters;
120 return Standard_False;
123 Standard_Boolean isremove = Standard_False;
124 if(!theWire.IsNull()) {
125 myContext->Remove(theWire);
126 isremove= Standard_True;
129 TopExp_Explorer aExpW(theFace,TopAbs_WIRE);
130 for( ; aExpW.More(); aExpW.Next()) {
131 if(!aBoundWire.IsSame(aExpW.Current())) {
132 myContext->Remove(aExpW.Current());
133 isremove= Standard_True;
139 //=======================================================================
140 //function : fixShape
142 //=======================================================================
144 void ShHealOper_RemoveInternalWires::fixShape(const TopoDS_Shape& theShape )
146 Handle(ShapeFix_Shape) aFixTool = new ShapeFix_Shape(theShape);
147 aFixTool->SetContext(myContext);
148 aFixTool->FixShellTool()->FixFaceMode() = Standard_False;
149 aFixTool->FixFreeFaceMode() = Standard_False;
150 aFixTool->FixFreeWireMode() = Standard_False;
151 aFixTool->FixSameParameterMode() = Standard_False;
153 myResultShape = aFixTool->Shape();