Salome HOME
197b52ee0ac0f172a4d083fab9735e0927eb1616
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FaceDriver.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #include <Standard_Stream.hxx>
23
24 #include <GEOMImpl_FaceDriver.hxx>
25 #include <GEOMImpl_IFace.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
28
29 #include <GEOMImpl_IMeasureOperations.hxx>
30
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRep_Tool.hxx>
33 #include <gp_Pnt.hxx>
34 #include <gp_Pln.hxx>
35 #include <TopoDS.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Vertex.hxx>
40 #include <TopAbs.hxx>
41 #include <TopExp.hxx>
42
43 #include <StdFail_NotDone.hxx>
44
45 //=======================================================================
46 //function : GetID
47 //purpose  :
48 //=======================================================================
49 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
50 {
51   static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
52   return aFaceDriver;
53 }
54
55
56 //=======================================================================
57 //function : GEOMImpl_FaceDriver
58 //purpose  :
59 //=======================================================================
60 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
61 {
62 }
63
64 //=======================================================================
65 //function : Execute
66 //purpose  :
67 //=======================================================================
68 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
69 {
70   if (Label().IsNull()) return 0;
71   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
72
73   GEOMImpl_IFace aFI (aFunction);
74   Standard_Integer aType = aFunction->GetType();
75
76   TopoDS_Shape aShape;
77
78   if (aType == FACE_OBJ_H_W) {
79     Handle(GEOM_Function) aRefFunct = aFI.GetRef1();
80     TopoDS_Shape aRefShape = aRefFunct->GetValue();
81     if (aRefShape.ShapeType() == TopAbs_EDGE) {
82       TopoDS_Edge anEdge = TopoDS::Edge(aRefShape);
83       double aH = aFI.GetH() / 2.0;
84       double aW = aFI.GetW() / 2.0;
85       TopoDS_Vertex V1, V2;
86       TopExp::Vertices(anEdge, V1, V2, Standard_True);
87       gp_Pnt aP (BRep_Tool::Pnt(V1));
88       gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
89       gp_Pln aPlane (aP, aV);
90       aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
91     } else if (aRefShape.ShapeType() == TopAbs_FACE) {
92       double aH = aFI.GetH() / 2.0;
93       double aW = aFI.GetW() / 2.0;
94       gp_Ax3 anAx = GEOMImpl_IMeasureOperations::GetPosition(aRefShape);
95       gp_Pln aPln (anAx);
96       aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
97     }
98   }
99   else if (aType == FACE_H_W) {
100     double aH = aFI.GetH() / 2.0;
101     double aW = aFI.GetW() / 2.0;
102     TopoDS_Vertex V1, V2;
103     int anOrient = aFI.GetOrientation();
104     gp_Pnt aP = gp::Origin();
105     gp_Vec aV;
106     if (anOrient == 1)
107       aV = gp::DZ();
108     else if (anOrient == 2)
109       aV = gp::DX();
110     else if (anOrient == 3)
111       aV = gp::DY();
112
113     gp_Pln aPlane (aP, aV);
114     aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
115   }
116   else {
117   }
118
119   if (aShape.IsNull()) return 0;
120
121   aFunction->SetValue(aShape);
122
123   log.SetTouched(Label());
124
125   return 1;
126 }
127
128
129 //=======================================================================
130 //function :  GEOMImpl_FaceDriver_Type_
131 //purpose  :
132 //=======================================================================
133 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
134 {
135
136   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
137   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
138   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
139   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
140   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
141   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
142
143
144   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
145   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FaceDriver",
146                                                          sizeof(GEOMImpl_FaceDriver),
147                                                          1,
148                                                          (Standard_Address)_Ancestors,
149                                                          (Standard_Address)NULL);
150
151   return _aType;
152 }
153
154 //=======================================================================
155 //function : DownCast
156 //purpose  :
157 //=======================================================================
158 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
159 {
160   Handle(GEOMImpl_FaceDriver) _anOtherObject;
161
162   if (!AnObject.IsNull()) {
163      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
164        _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
165      }
166   }
167
168   return _anOtherObject ;
169 }