1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include <Standard_Stream.hxx>
24 #include <GEOMImpl_FaceDriver.hxx>
25 #include <GEOMImpl_IFace.hxx>
26 #include <GEOMImpl_Types.hxx>
27 #include <GEOM_Function.hxx>
29 #include <GEOMImpl_IMeasureOperations.hxx>
31 #include <BRepBuilderAPI_MakeFace.hxx>
32 #include <BRep_Tool.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Face.hxx>
39 #include <TopoDS_Vertex.hxx>
43 #include <StdFail_NotDone.hxx>
45 //=======================================================================
48 //=======================================================================
49 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
51 static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
56 //=======================================================================
57 //function : GEOMImpl_FaceDriver
59 //=======================================================================
60 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
64 //=======================================================================
67 //=======================================================================
68 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
70 if (Label().IsNull()) return 0;
71 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
73 GEOMImpl_IFace aFI (aFunction);
74 Standard_Integer aType = aFunction->GetType();
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;
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);
96 aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
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();
108 else if (anOrient == 2)
110 else if (anOrient == 3)
113 gp_Pln aPlane (aP, aV);
114 aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
119 if (aShape.IsNull()) return 0;
121 aFunction->SetValue(aShape);
123 log.SetTouched(Label());
129 //=======================================================================
130 //function : GEOMImpl_FaceDriver_Type_
132 //=======================================================================
133 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
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);
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),
148 (Standard_Address)_Ancestors,
149 (Standard_Address)NULL);
154 //=======================================================================
155 //function : DownCast
157 //=======================================================================
158 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
160 Handle(GEOMImpl_FaceDriver) _anOtherObject;
162 if (!AnObject.IsNull()) {
163 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
164 _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
168 return _anOtherObject ;