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 // File: ShHealOper_RemoveInternalWires.cxx
22 // Created: 26.04.04 14:46:45
23 // Author: Galina KULIKOVA
26 #include <ShHealOper_RemoveInternalWires.hxx>
28 #include <TopExp_Explorer.hxx>
29 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopTools_ListOfShape.hxx>
32 #include <TopTools_ListIteratorOfListOfShape.hxx>
33 #include <ShapeAnalysis.hxx>
34 #include <ShapeFix_Shape.hxx>
36 //=======================================================================
37 //function : ShHealOper_RemoveInternalWires()
38 //purpose : Constructor
39 //=======================================================================
41 ShHealOper_RemoveInternalWires::ShHealOper_RemoveInternalWires ( const TopoDS_Shape& theShape )
45 //=======================================================================
48 //=======================================================================
50 void ShHealOper_RemoveInternalWires::Init(const TopoDS_Shape& theShape)
52 ShHealOper_Tool::Init(theShape);
53 myMapWiresFace.Clear();
54 TopExp::MapShapesAndAncestors(theShape,TopAbs_WIRE,TopAbs_FACE,myMapWiresFace);
56 //=======================================================================
59 //=======================================================================
61 Standard_Boolean ShHealOper_RemoveInternalWires::Remove()
63 TopExp_Explorer aexpFaces(myInitShape,TopAbs_FACE);
64 //removes internal wires from all faces in the shape
65 Standard_Boolean isDone = Standard_False;
66 for( ; aexpFaces.More(); aexpFaces.Next())
67 isDone = removeWire(TopoDS::Face(aexpFaces.Current()),TopoDS_Wire()) || isDone;
69 TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
70 //fix not-connected shell and solids obtained after removing wires
76 //=======================================================================
79 //=======================================================================
81 Standard_Boolean ShHealOper_RemoveInternalWires::Remove(const TopTools_SequenceOfShape& theRemovedShapes)
83 myDone = Standard_False;
85 Standard_Integer i =1;
86 for( ; i <= theRemovedShapes.Length(); i++) {
87 //removes internal wires from specified faces.
88 if(theRemovedShapes.Value(i).ShapeType() == TopAbs_FACE)
89 myDone = (removeWire(TopoDS::Face(theRemovedShapes.Value(i)),TopoDS_Wire()) || myDone) ;
90 else if(theRemovedShapes.Value(i).ShapeType() == TopAbs_WIRE)
92 //removes specified internal wires.
93 TopoDS_Wire awire = TopoDS::Wire(theRemovedShapes.Value(i));
94 if(myMapWiresFace.Contains(awire)) {
95 const TopTools_ListOfShape& aLfaces = myMapWiresFace.FindFromKey(awire);
96 TopTools_ListIteratorOfListOfShape liter(aLfaces);
97 for( ; liter.More(); liter.Next())
98 myDone = (removeWire(TopoDS::Face(liter.Value()),awire) || myDone);
103 TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
105 //fix not-connected shell and solids obtained after removing wires
111 //=======================================================================
112 //function : removeWire
114 //=======================================================================
116 Standard_Boolean ShHealOper_RemoveInternalWires::removeWire(const TopoDS_Face& theFace,
117 const TopoDS_Wire& theWire)
119 TopoDS_Wire aBoundWire = ShapeAnalysis::OuterWire(theFace);
120 if(!theWire.IsNull() && aBoundWire.IsSame(theWire)) {
121 myErrorStatus = ShHealOper_InvalidParameters;
122 return Standard_False;
125 Standard_Boolean isremove = Standard_False;
126 if(!theWire.IsNull()) {
127 myContext->Remove(theWire);
128 isremove= Standard_True;
131 TopExp_Explorer aExpW(theFace,TopAbs_WIRE);
132 for( ; aExpW.More(); aExpW.Next()) {
133 if(!aBoundWire.IsSame(aExpW.Current())) {
134 myContext->Remove(aExpW.Current());
135 isremove= Standard_True;
141 //=======================================================================
142 //function : fixShape
144 //=======================================================================
146 void ShHealOper_RemoveInternalWires::fixShape(const TopoDS_Shape& theShape )
148 Handle(ShapeFix_Shape) aFixTool = new ShapeFix_Shape(theShape);
149 aFixTool->SetContext(myContext);
150 aFixTool->FixShellTool()->FixFaceMode() = Standard_False;
151 aFixTool->FixFreeFaceMode() = Standard_False;
152 aFixTool->FixFreeWireMode() = Standard_False;
153 aFixTool->FixSameParameterMode() = Standard_False;
155 myResultShape = aFixTool->Shape();