Back to index

salome-geom  6.5.0
ShHealOper_RemoveInternalWires.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // File:      ShHealOper_RemoveInternalWires.cxx
00024 // Created:   26.04.04 14:46:45
00025 // Author:    Galina KULIKOVA
00026 //
00027 #include <ShHealOper_RemoveInternalWires.hxx>
00028 #include <TopExp.hxx>
00029 #include <TopExp_Explorer.hxx>
00030 #include <TopAbs_ShapeEnum.hxx>
00031 #include <TopoDS.hxx>
00032 #include <TopTools_ListOfShape.hxx>
00033 #include <TopTools_ListIteratorOfListOfShape.hxx>
00034 #include <ShapeAnalysis.hxx>
00035 #include <ShapeFix_Shape.hxx>
00036 
00037 //=======================================================================
00038 //function : ShHealOper_RemoveInternalWires()
00039 //purpose  : Constructor
00040 //=======================================================================
00041 
00042 ShHealOper_RemoveInternalWires::ShHealOper_RemoveInternalWires ( const TopoDS_Shape& theShape )
00043 {
00044   Init(theShape);
00045 }
00046 //=======================================================================
00047 //function : Init
00048 //purpose  : 
00049 //=======================================================================
00050 
00051 void ShHealOper_RemoveInternalWires::Init(const TopoDS_Shape& theShape)
00052 {
00053   ShHealOper_Tool::Init(theShape);
00054   myMapWiresFace.Clear();
00055   TopExp::MapShapesAndAncestors(theShape,TopAbs_WIRE,TopAbs_FACE,myMapWiresFace);
00056 }
00057 //=======================================================================
00058 //function : Remove
00059 //purpose  : 
00060 //=======================================================================
00061 
00062 Standard_Boolean ShHealOper_RemoveInternalWires::Remove()
00063 {
00064   TopExp_Explorer aexpFaces(myInitShape,TopAbs_FACE);
00065   //removes internal wires from all faces in the shape
00066   Standard_Boolean isDone = Standard_False;
00067   for( ; aexpFaces.More(); aexpFaces.Next())
00068     isDone =  removeWire(TopoDS::Face(aexpFaces.Current()),TopoDS_Wire()) || isDone;
00069   if(isDone ) {
00070     TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
00071     //fix not-connected shell and solids obtained after removing wires
00072     fixShape(aNewShape);
00073   }
00074   myDone = isDone;
00075   return myDone;
00076 }
00077 //=======================================================================
00078 //function : Remove
00079 //purpose  : 
00080 //=======================================================================
00081 
00082 Standard_Boolean ShHealOper_RemoveInternalWires::Remove(const TopTools_SequenceOfShape& theRemovedShapes)
00083 {
00084   myDone = Standard_False;
00085   
00086   Standard_Integer i =1;
00087   for( ; i <= theRemovedShapes.Length(); i++) {
00088     //removes internal wires from specified faces.
00089     if(theRemovedShapes.Value(i).ShapeType() == TopAbs_FACE)
00090       myDone = (removeWire(TopoDS::Face(theRemovedShapes.Value(i)),TopoDS_Wire()) || myDone) ;
00091     else if(theRemovedShapes.Value(i).ShapeType() == TopAbs_WIRE)
00092     {
00093       //removes specified internal wires. 
00094       TopoDS_Wire awire = TopoDS::Wire(theRemovedShapes.Value(i));
00095       if(myMapWiresFace.Contains(awire)) {
00096         const TopTools_ListOfShape& aLfaces = myMapWiresFace.FindFromKey(awire);
00097         TopTools_ListIteratorOfListOfShape liter(aLfaces);
00098         for( ; liter.More(); liter.Next())
00099           myDone = (removeWire(TopoDS::Face(liter.Value()),awire) || myDone);
00100       }
00101     }
00102   }
00103   if(myDone ) {
00104     TopoDS_Shape aNewShape = myContext->Apply(myInitShape);
00105 
00106     //fix not-connected shell and solids obtained after removing wires
00107     fixShape(aNewShape);
00108     
00109   }
00110   return myDone;
00111 }
00112 //=======================================================================
00113 //function : removeWire
00114 //purpose  : 
00115 //=======================================================================
00116 
00117 Standard_Boolean ShHealOper_RemoveInternalWires::removeWire(const TopoDS_Face& theFace, 
00118                                                             const TopoDS_Wire& theWire)
00119 {
00120   TopoDS_Wire aBoundWire = ShapeAnalysis::OuterWire(theFace);
00121   if(!theWire.IsNull() && aBoundWire.IsSame(theWire)) {
00122     myErrorStatus = ShHealOper_InvalidParameters;
00123     return Standard_False;
00124   }
00125   
00126   Standard_Boolean isremove = Standard_False;
00127   if(!theWire.IsNull()) {
00128     myContext->Remove(theWire);
00129     isremove= Standard_True;
00130   }
00131   else {  
00132     TopExp_Explorer aExpW(theFace,TopAbs_WIRE);
00133     for( ; aExpW.More(); aExpW.Next()) {
00134       if(!aBoundWire.IsSame(aExpW.Current())) {
00135         myContext->Remove(aExpW.Current());
00136         isremove= Standard_True;
00137       }
00138     }
00139   }
00140   return isremove;
00141 }
00142 //=======================================================================
00143 //function : fixShape
00144 //purpose  : 
00145 //=======================================================================
00146 
00147 void ShHealOper_RemoveInternalWires::fixShape(const TopoDS_Shape& theShape )
00148 {
00149   Handle(ShapeFix_Shape) aFixTool = new ShapeFix_Shape(theShape);
00150   aFixTool->SetContext(myContext);
00151   aFixTool->FixShellTool()->FixFaceMode() = Standard_False;
00152   aFixTool->FixFreeFaceMode() = Standard_False;
00153   aFixTool->FixFreeWireMode() = Standard_False;
00154   aFixTool->FixSameParameterMode() = Standard_False;
00155   aFixTool->Perform();
00156   myResultShape = aFixTool->Shape();
00157 }