Salome HOME
4aa496c63a0c463fd8405624c6e60ee8cf008825
[modules/geom.git] / src / GEOMImpl / GEOMImpl_PatchFaceDriver.cxx
1 // Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include <GEOMImpl_PatchFaceDriver.hxx>
21 #include <GEOMImpl_IPatchFace.hxx>
22 #include <GEOMImpl_Types.hxx>
23 #include <GEOM_Function.hxx>
24 #include <GEOMUtils.hxx>
25
26 #include <BRep_Builder.hxx>
27 #include <BRepBuilderAPI_MakeFace.hxx>
28 #include <BRepTools.hxx>
29
30 #include <TopExp.hxx>
31 #include <TopExp_Explorer.hxx>
32
33 #include <TopoDS.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Iterator.hxx>
36 #include <TopAbs.hxx>
37 #include <TopTools_ListIteratorOfListOfShape.hxx>
38 #include <TopTools_MapOfShape.hxx>
39
40 #include <StdFail_NotDone.hxx>
41
42 //=======================================================================
43 //function : GetID
44 //purpose  :
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_PatchFaceDriver::GetID()
47 {
48   static Standard_GUID aPatchFaceDriver("6E0A4C17-9E56-4739-8C67-B37C01C47ED6");
49   return aPatchFaceDriver;
50 }
51
52
53 //=======================================================================
54 //function : GEOMImpl_PatchFaceDriver
55 //purpose  :
56 //=======================================================================
57 GEOMImpl_PatchFaceDriver::GEOMImpl_PatchFaceDriver()
58 {
59 }
60
61 //=======================================================================
62 //function : Execute
63 //purpose  :
64 //=======================================================================
65 Standard_Integer GEOMImpl_PatchFaceDriver::Execute(Handle(TFunction_Logbook)& log) const
66 {
67   if (Label().IsNull()) return 0;
68   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
69   GEOMImpl_IPatchFace aCI(aFunction);
70
71   Handle(GEOM_Function) aRefShape = aCI.GetShape();
72   if (aRefShape.IsNull()) return 0;
73
74   TopoDS_Shape aFaceShape = aRefShape->GetValue();
75
76   TopoDS_Compound aCompound;
77   if (aFaceShape.ShapeType() == TopAbs_FACE)
78   {
79     if (aFaceShape.Orientation() == TopAbs_Orientation::TopAbs_REVERSED)
80       aFaceShape.Reverse();
81
82     // Colect all Wires from face
83     TopTools_ListOfShape aWires;
84     TopoDS_Wire anOuterWire = BRepTools::OuterWire(TopoDS::Face(aFaceShape));
85     aWires.Append(anOuterWire);
86     for (TopExp_Explorer anExpW(aFaceShape, TopAbs_WIRE); anExpW.More(); anExpW.Next())
87     {
88       TopoDS_Wire aWire = TopoDS::Wire(anExpW.Current());
89       if (anOuterWire.IsSame(aWire))
90         continue;
91
92       aWire.Reverse();
93       aWires.Append(aWire);
94     }
95
96     BRep_Builder aBrepBuilder;
97     TopLoc_Location aLocation;
98     Handle(Geom_Surface) aSurface = BRep_Tool::Surface(TopoDS::Face(aFaceShape), aLocation);
99
100     // Create result compound from all faces
101     aBrepBuilder.MakeCompound(aCompound);
102     TopTools_ListIteratorOfListOfShape anIterWires(aWires);
103     for (; anIterWires.More(); anIterWires.Next())
104     {
105       // Create face on surface from wire 
106       TopoDS_Face aFace;
107       aBrepBuilder.MakeFace(aFace, aSurface, aLocation, 1.e-7);
108       aBrepBuilder.Add(aFace, anIterWires.Value());
109
110       // Add created face to compound
111       aBrepBuilder.Add(aCompound, aFace);
112     }
113   }
114   else
115   {
116     Standard_ConstructionError::Raise("Wrong arguments: a face must be given");
117   }
118
119   if (aCompound.IsNull()) return 0;
120
121   aFunction->SetValue(aCompound);
122   log->SetTouched(Label());
123   
124   return 1;
125 }
126
127 //================================================================================
128 /*!
129  * \brief Returns a name of creation operation and names and values of creation parameters
130  */
131  //================================================================================
132
133 bool GEOMImpl_PatchFaceDriver::
134 GetCreationInformation(std::string&             /*theOperationName*/,
135                        std::vector<GEOM_Param>& /*theParams*/)
136 {
137   return false;
138 }
139
140 IMPLEMENT_STANDARD_RTTIEXT(GEOMImpl_PatchFaceDriver, GEOM_BaseDriver)