1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_FaceDriver.hxx>
24 #include <GEOMImpl_IFace.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <GEOMImpl_IMeasureOperations.hxx>
30 #include <BRepBuilderAPI_MakeFace.hxx>
31 #include <BRep_Tool.hxx>
35 #include <TopoDS_Shape.hxx>
36 #include <TopoDS_Edge.hxx>
37 #include <TopoDS_Face.hxx>
38 #include <TopoDS_Vertex.hxx>
42 #include <StdFail_NotDone.hxx>
44 //=======================================================================
47 //=======================================================================
48 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
50 static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
55 //=======================================================================
56 //function : GEOMImpl_FaceDriver
58 //=======================================================================
59 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
63 //=======================================================================
66 //=======================================================================
67 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
69 if (Label().IsNull()) return 0;
70 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
72 GEOMImpl_IFace aFI (aFunction);
73 Standard_Integer aType = aFunction->GetType();
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;
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);
95 aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
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();
107 else if (anOrient == 2)
109 else if (anOrient == 3)
112 gp_Pln aPlane (aP, aV);
113 aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
118 if (aShape.IsNull()) return 0;
120 aFunction->SetValue(aShape);
122 log.SetTouched(Label());
128 //=======================================================================
129 //function : GEOMImpl_FaceDriver_Type_
131 //=======================================================================
132 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
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);
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),
147 (Standard_Address)_Ancestors,
148 (Standard_Address)NULL);
153 //=======================================================================
154 //function : DownCast
156 //=======================================================================
157 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
159 Handle(GEOMImpl_FaceDriver) _anOtherObject;
161 if (!AnObject.IsNull()) {
162 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
163 _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
167 return _anOtherObject ;