1 // Copyright (C) 2007-2010 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
20 #include <Standard_Stream.hxx>
22 #include <GEOMImpl_FaceDriver.hxx>
23 #include <GEOMImpl_IFace.hxx>
24 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
27 #include <GEOMImpl_IMeasureOperations.hxx>
29 #include <BRepBuilderAPI_MakeFace.hxx>
30 #include <BRep_Tool.hxx>
34 #include <TopoDS_Shape.hxx>
35 #include <TopoDS_Edge.hxx>
36 #include <TopoDS_Face.hxx>
37 #include <TopoDS_Vertex.hxx>
41 #include <StdFail_NotDone.hxx>
43 //=======================================================================
46 //=======================================================================
47 const Standard_GUID& GEOMImpl_FaceDriver::GetID()
49 static Standard_GUID aFaceDriver("F7953CC1-FF8B-4628-BF5E-9D3510DE4629");
54 //=======================================================================
55 //function : GEOMImpl_FaceDriver
57 //=======================================================================
58 GEOMImpl_FaceDriver::GEOMImpl_FaceDriver()
62 //=======================================================================
65 //=======================================================================
66 Standard_Integer GEOMImpl_FaceDriver::Execute(TFunction_Logbook& log) const
68 if (Label().IsNull()) return 0;
69 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
71 GEOMImpl_IFace aFI (aFunction);
72 Standard_Integer aType = aFunction->GetType();
76 if (aType == FACE_OBJ_H_W) {
77 Handle(GEOM_Function) aRefFunct = aFI.GetRef1();
78 TopoDS_Shape aRefShape = aRefFunct->GetValue();
79 if (aRefShape.ShapeType() == TopAbs_EDGE) {
80 TopoDS_Edge anEdge = TopoDS::Edge(aRefShape);
81 double aH = aFI.GetH() / 2.0;
82 double aW = aFI.GetW() / 2.0;
84 TopExp::Vertices(anEdge, V1, V2, Standard_True);
85 gp_Pnt aP (BRep_Tool::Pnt(V1));
86 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
87 gp_Pln aPlane (aP, aV);
88 aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
89 } else if (aRefShape.ShapeType() == TopAbs_FACE) {
90 double aH = aFI.GetH() / 2.0;
91 double aW = aFI.GetW() / 2.0;
92 gp_Ax3 anAx = GEOMImpl_IMeasureOperations::GetPosition(aRefShape);
94 aShape = BRepBuilderAPI_MakeFace(aPln, -aH, +aH, -aW, +aW).Shape();
97 else if (aType == FACE_H_W) {
98 double aH = aFI.GetH() / 2.0;
99 double aW = aFI.GetW() / 2.0;
100 TopoDS_Vertex V1, V2;
101 int anOrient = aFI.GetOrientation();
102 gp_Pnt aP = gp::Origin();
106 else if (anOrient == 2)
108 else if (anOrient == 3)
111 gp_Pln aPlane (aP, aV);
112 aShape = BRepBuilderAPI_MakeFace(aPlane, -aH, +aH, -aW, +aW).Shape();
117 if (aShape.IsNull()) return 0;
119 aFunction->SetValue(aShape);
121 log.SetTouched(Label());
127 //=======================================================================
128 //function : GEOMImpl_FaceDriver_Type_
130 //=======================================================================
131 Standard_EXPORT Handle_Standard_Type& GEOMImpl_FaceDriver_Type_()
134 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
135 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
136 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
137 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
138 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
139 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
142 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
143 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_FaceDriver",
144 sizeof(GEOMImpl_FaceDriver),
146 (Standard_Address)_Ancestors,
147 (Standard_Address)NULL);
152 //=======================================================================
153 //function : DownCast
155 //=======================================================================
156 const Handle(GEOMImpl_FaceDriver) Handle(GEOMImpl_FaceDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
158 Handle(GEOMImpl_FaceDriver) _anOtherObject;
160 if (!AnObject.IsNull()) {
161 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_FaceDriver))) {
162 _anOtherObject = Handle(GEOMImpl_FaceDriver)((Handle(GEOMImpl_FaceDriver)&)AnObject);
166 return _anOtherObject ;