1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include <GEOMImpl_FaceDriver.hxx>
21 #include <GEOMImpl_IFace.hxx>
22 #include <GEOMImpl_Types.hxx>
24 #include <GEOM_Function.hxx>
26 #include <GEOMUtils.hxx>
28 #include <BRepBuilderAPI_MakeFace.hxx>
29 #include <BRep_Tool.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Face.hxx>
36 #include <TopoDS_Vertex.hxx>
40 #include <StdFail_NotDone.hxx>
42 //=======================================================================
45 //=======================================================================
46 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
48 static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
53 //=======================================================================
54 //function : GEOMImpl_FaceDriver
56 //=======================================================================
57 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
61 //=======================================================================
64 //=======================================================================
65 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
67 if (Label().IsNull()) return 0;
68 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
70 GEOMImpl_IFace aFI (aFunction);
71 Standard_Integer aType = aFunction->GetType();
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;
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);
93 aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
96 else if (aType == FACE_H_W) {
97 double aH = aFI.GetH() / 2.0;
98 double aW = aFI.GetW() / 2.0;
100 int anOrient = aFI.GetOrientation();
101 gp_Pnt aP = gp::Origin();
105 else if (anOrient == 2)
107 else if (anOrient == 3)
110 gp_Pln aPlane (aP, aV);
111 aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
116 if (aShape.IsNull()) return 0;
118 aFunction->SetValue(aShape);
120 log.SetTouched(Label());
126 //=======================================================================
127 //function : GEOMImpl_FaceDriver_Type_
129 //=======================================================================
130 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
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);
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),
145 (Standard_Address)_Ancestors,
146 (Standard_Address)NULL);
151 //=======================================================================
152 //function : DownCast
154 //=======================================================================
155 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
157 Handle(GEOMImpl_FaceDriver) _anOtherObject;
159 if (!AnObject.IsNull()) {
160 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
161 _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
165 return _anOtherObject ;