Salome HOME
6b3848b97e927da66c1fa1afe5a184595c7cfffb
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FaceDriver.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_FaceDriver.hxx>
21
22 #include <GEOMImpl_IFace.hxx>
23 #include <GEOMImpl_Types.hxx>
24
25 #include <GEOM_Function.hxx>
26
27 #include <GEOMUtils.hxx>
28
29 #include <BRepBuilderAPI_MakeFace.hxx>
30 #include <BRep_Tool.hxx>
31 #include <gp_Pnt.hxx>
32 #include <gp_Pln.hxx>
33 #include <TopoDS.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Vertex.hxx>
38 #include <TopAbs.hxx>
39 #include <TopExp.hxx>
40
41 #include <StdFail_NotDone.hxx>
42
43 //=======================================================================
44 //function : GetID
45 //purpose  :
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
48 {
49   static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
50   return aFaceDriver;
51 }
52
53
54 //=======================================================================
55 //function : GEOMImpl_FaceDriver
56 //purpose  :
57 //=======================================================================
58 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
59 {
60 }
61
62 //=======================================================================
63 //function : Execute
64 //purpose  :
65 //=======================================================================
66 Standard_Integer GEOMImpl_FaceDriver::Execute(Handle(TFunction_Logbook)& log) const
67 {
68   if (Label().IsNull()) return 0;
69   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70
71   GEOMImpl_IFace aFI (aFunction);
72   Standard_Integer aType = aFunction->GetType();
73
74   TopoDS_Shape aShape;
75
76   if (aType == FACE_OBJ_H_W) {
77     Handle(GEOM_Function) aRefFunct = aFI.GetRef1();
78     TopoDS_Shape aRefShape = aRefFunct->GetValue();
79     if (aRefShape.ShapeType() == TopAbs_EDGE) {
80       TopoDS_Edge anEdge = TopoDS::Edge(aRefShape);
81       double aH = aFI.GetH() / 2.0;
82       double aW = aFI.GetW() / 2.0;
83       TopoDS_Vertex V1, V2;
84       TopExp::Vertices(anEdge, V1, V2, Standard_True);
85       gp_Pnt aP (BRep_Tool::Pnt(V1));
86       gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
87       gp_Pln aPlane (aP, aV);
88       aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
89     } else if (aRefShape.ShapeType() == TopAbs_FACE) {
90       double aH = aFI.GetH() / 2.0;
91       double aW = aFI.GetW() / 2.0;
92       gp_Ax3 anAx = GEOMUtils::GetPosition(aRefShape);
93       gp_Pln aPln (anAx);
94       aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
95     }
96   }
97   else if (aType == FACE_H_W) {
98     double aH = aFI.GetH() / 2.0;
99     double aW = aFI.GetW() / 2.0;
100     TopoDS_Vertex V1, V2;
101     int anOrient = aFI.GetOrientation();
102     gp_Pnt aP = gp::Origin();
103     gp_Vec aV;
104     if (anOrient == 1)
105       aV = gp::DZ();
106     else if (anOrient == 2)
107       aV = gp::DX();
108     else if (anOrient == 3)
109       aV = gp::DY();
110
111     gp_Pln aPlane (aP, aV);
112     aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
113   }
114   else {
115   }
116
117   if (aShape.IsNull()) return 0;
118
119   aFunction->SetValue(aShape);
120
121   log->SetTouched(Label());
122
123   return 1;
124 }
125
126 //================================================================================
127 /*!
128  * \brief Returns a name of creation operation and names and values of creation parameters
129  */
130 //================================================================================
131
132 bool GEOMImpl_FaceDriver::
133 GetCreationInformation(std::string&             theOperationName,
134                        std::vector<GEOM_Param>& theParams)
135 {
136   if (Label().IsNull()) return 0;
137   Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
138
139   GEOMImpl_IFace aCI( function );
140   Standard_Integer aType = function->GetType();
141
142   theOperationName = "RECTANGLE";
143
144   switch ( aType ) {
145   case FACE_OBJ_H_W:
146   {
147     Handle(GEOM_Function) aRefFunct = aCI.GetRef1();
148     TopoDS_Shape aRefShape = aRefFunct->GetValue();
149     if (aRefShape.ShapeType() == TopAbs_EDGE)
150       AddParam( theParams, "Edge", aRefFunct );
151     else
152       AddParam( theParams, "Face", aRefFunct );
153     AddParam( theParams, "Height", aCI.GetH() );
154     AddParam( theParams, "Width", aCI.GetW() );
155     break;
156   }
157   case FACE_H_W:
158     AddParam( theParams, "Height", aCI.GetH() );
159     AddParam( theParams, "Width", aCI.GetW() );
160     AddParam( theParams, "Orientation", aCI.GetOrientation() );
161     break;
162   default:
163     return false;
164   }
165   
166   return true;
167 }
168
169 IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_FaceDriver,GEOM_BaseDriver)