]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_FaceDriver.cxx
Salome HOME
Heal invalid shape after scaling, because different scaling along axes can produce...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_FaceDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_FaceDriver.hxx>
24 #include <GEOMImpl_IFace.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <GEOMImpl_IMeasureOperations.hxx>
29
30 #include <BRepBuilderAPI_MakeFace.hxx>
31 #include <BRep_Tool.hxx>
32 #include <gp_Pnt.hxx>
33 #include <gp_Pln.hxx>
34 #include <TopoDS.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Vertex.hxx>
39 #include <TopAbs.hxx>
40 #include <TopExp.hxx>
41
42 #include <StdFail_NotDone.hxx>
43
44 //=======================================================================
45 //function : GetID
46 //purpose  :
47 //=======================================================================
48 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
49 {
50   static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
51   return aFaceDriver;
52 }
53
54
55 //=======================================================================
56 //function : GEOMImpl_FaceDriver
57 //purpose  :
58 //=======================================================================
59 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
60 {
61 }
62
63 //=======================================================================
64 //function : Execute
65 //purpose  :
66 //=======================================================================
67 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
68 {
69   if (Label().IsNull()) return 0;
70   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71
72   GEOMImpl_IFace aFI (aFunction);
73   Standard_Integer aType = aFunction->GetType();
74
75   TopoDS_Shape aShape;
76
77   if (aType == FACE_OBJ_H_W) {
78     Handle(GEOM_Function) aRefFunct = aFI.GetRef1();
79     TopoDS_Shape aRefShape = aRefFunct->GetValue();
80     if (aRefShape.ShapeType() == TopAbs_EDGE) {
81       TopoDS_Edge anEdge = TopoDS::Edge(aRefShape);
82       double aH = aFI.GetH() / 2.0;
83       double aW = aFI.GetW() / 2.0;
84       TopoDS_Vertex V1, V2;
85       TopExp::Vertices(anEdge, V1, V2, Standard_True);
86       gp_Pnt aP (BRep_Tool::Pnt(V1));
87       gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
88       gp_Pln aPlane (aP, aV);
89       aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
90     } else if (aRefShape.ShapeType() == TopAbs_FACE) {
91       double aH = aFI.GetH() / 2.0;
92       double aW = aFI.GetW() / 2.0;
93       gp_Ax3 anAx = GEOMImpl_IMeasureOperations::GetPosition(aRefShape);
94       gp_Pln aPln (anAx);
95       aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
96     }
97   }
98   else if (aType == FACE_H_W) {
99     double aH = aFI.GetH() / 2.0;
100     double aW = aFI.GetW() / 2.0;
101     TopoDS_Vertex V1, V2;
102     int anOrient = aFI.GetOrientation();
103     gp_Pnt aP = gp::Origin();
104     gp_Vec aV;
105     if (anOrient == 1)
106       aV = gp::DZ();
107     else if (anOrient == 2)
108       aV = gp::DX();
109     else if (anOrient == 3)
110       aV = gp::DY();
111
112     gp_Pln aPlane (aP, aV);
113     aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
114   }
115   else {
116   }
117
118   if (aShape.IsNull()) return 0;
119
120   aFunction->SetValue(aShape);
121
122   log.SetTouched(Label());
123
124   return 1;
125 }
126
127
128 //=======================================================================
129 //function :  GEOMImpl_FaceDriver_Type_
130 //purpose  :
131 //=======================================================================
132 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
133 {
134
135   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
136   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
137   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
138   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
139   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
140   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
141
142
143   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
144   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FaceDriver",
145                                                          sizeof(GEOMImpl_FaceDriver),
146                                                          1,
147                                                          (Standard_Address)_Ancestors,
148                                                          (Standard_Address)NULL);
149
150   return _aType;
151 }
152
153 //=======================================================================
154 //function : DownCast
155 //purpose  :
156 //=======================================================================
157 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
158 {
159   Handle(GEOMImpl_FaceDriver) _anOtherObject;
160
161   if (!AnObject.IsNull()) {
162      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
163        _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
164      }
165   }
166
167   return _anOtherObject ;
168 }