Salome HOME
4aafb71144ee1a9ba18c99c9a38360cccc0a2d27
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FaceDriver.cxx
1 // Copyright (C) 2007-2012  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.
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 <Standard_Stream.hxx>
21
22 #include <GEOMImpl_FaceDriver.hxx>
23 #include <GEOMImpl_IFace.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
26
27 #include <GEOMImpl_IMeasureOperations.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(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 = GEOMImpl_IMeasureOperations::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 //function :  GEOMImpl_FaceDriver_Type_
129 //purpose  :
130 //=======================================================================
131 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
132 {
133
134   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
135   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
136   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
137   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
138   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
139   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
140
141
142   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
143   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FaceDriver",
144                                                          sizeof(GEOMImpl_FaceDriver),
145                                                          1,
146                                                          (Standard_Address)_Ancestors,
147                                                          (Standard_Address)NULL);
148
149   return _aType;
150 }
151
152 //=======================================================================
153 //function : DownCast
154 //purpose  :
155 //=======================================================================
156 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
157 {
158   Handle(GEOMImpl_FaceDriver) _anOtherObject;
159
160   if (!AnObject.IsNull()) {
161      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
162        _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
163      }
164   }
165
166   return _anOtherObject ;
167 }