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