1 // Copyright (C) 2007-2011 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.
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 // File: ShHealOper_RemoveInternalWires.cxx
24 // Created: 26.04.04 14:46:45
25 // Author: Galina KULIKOVA
27 #include <ShHealOper_RemoveInternalWires.hxx>
29 #include <TopExp_Explorer.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
32 #include <TopTools_ListOfShape.hxx>
33 #include <TopTools_ListIteratorOfListOfShape.hxx>
34 #include <ShapeAnalysis.hxx>
35 #include <ShapeFix_Shape.hxx>
37 //=======================================================================
38 //function : ShHealOper_RemoveInternalWires()
39 //purpose : Constructor
40 //=======================================================================
42 ShHealOper_RemoveInternalWires::ShHealOper_RemoveInternalWires ( const TopoDS_Shape& theShape )
46 //=======================================================================
49 //=======================================================================
51 void ShHealOper_RemoveInternalWires::Init(const TopoDS_Shape& theShape)
53 ShHealOper_Tool::Init(theShape);
54 myMapWiresFace.Clear();
55 TopExp::MapShapesAndAncestors(theShape,TopAbs_WIRE,TopAbs_FACE,myMapWiresFace);
57 //=======================================================================
60 //=======================================================================
62 Standard_Boolean ShHealOper_RemoveInternalWires::Remove()
64 TopExp_Explorer aexpFaces(myInitShape,TopAbs_FACE);
65 //removes internal wires from all faces in the shape
66 Standard_Boolean isDone = Standard_False;
67 for( ; aexpFaces.More(); aexpFaces.Next())
68 isDone = removeWire(TopoDS::Face(aexpFaces.Current()),TopoDS_Wire()) || isDone;
70 TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
71 //fix not-connected shell and solids obtained after removing wires
77 //=======================================================================
80 //=======================================================================
82 Standard_Boolean ShHealOper_RemoveInternalWires::Remove(const TopTools_SequenceOfShape& theRemovedShapes)
84 myDone = Standard_False;
86 Standard_Integer i =1;
87 for( ; i <= theRemovedShapes.Length(); i++) {
88 //removes internal wires from specified faces.
89 if(theRemovedShapes.Value(i).ShapeType() == TopAbs_FACE)
90 myDone = (removeWire(TopoDS::Face(theRemovedShapes.Value(i)),TopoDS_Wire()) || myDone) ;
91 else if(theRemovedShapes.Value(i).ShapeType() == TopAbs_WIRE)
93 //removes specified internal wires.
94 TopoDS_Wire awire = TopoDS::Wire(theRemovedShapes.Value(i));
95 if(myMapWiresFace.Contains(awire)) {
96 const TopTools_ListOfShape& aLfaces = myMapWiresFace.FindFromKey(awire);
97 TopTools_ListIteratorOfListOfShape liter(aLfaces);
98 for( ; liter.More(); liter.Next())
99 myDone = (removeWire(TopoDS::Face(liter.Value()),awire) || myDone);
104 TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
106 //fix not-connected shell and solids obtained after removing wires
112 //=======================================================================
113 //function : removeWire
115 //=======================================================================
117 Standard_Boolean ShHealOper_RemoveInternalWires::removeWire(const TopoDS_Face& theFace,
118 const TopoDS_Wire& theWire)
120 TopoDS_Wire aBoundWire = ShapeAnalysis::OuterWire(theFace);
121 if(!theWire.IsNull() && aBoundWire.IsSame(theWire)) {
122 myErrorStatus = ShHealOper_InvalidParameters;
123 return Standard_False;
126 Standard_Boolean isremove = Standard_False;
127 if(!theWire.IsNull()) {
128 myContext->Remove(theWire);
129 isremove= Standard_True;
132 TopExp_Explorer aExpW(theFace,TopAbs_WIRE);
133 for( ; aExpW.More(); aExpW.Next()) {
134 if(!aBoundWire.IsSame(aExpW.Current())) {
135 myContext->Remove(aExpW.Current());
136 isremove= Standard_True;
142 //=======================================================================
143 //function : fixShape
145 //=======================================================================
147 void ShHealOper_RemoveInternalWires::fixShape(const TopoDS_Shape& theShape )
149 Handle(ShapeFix_Shape) aFixTool = new ShapeFix_Shape(theShape);
150 aFixTool->SetContext(myContext);
151 aFixTool->FixShellTool()->FixFaceMode() = Standard_False;
152 aFixTool->FixFreeFaceMode() = Standard_False;
153 aFixTool->FixFreeWireMode() = Standard_False;
154 aFixTool->FixSameParameterMode() = Standard_False;
156 myResultShape = aFixTool->Shape();