1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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 <GEOMImpl_FaceDriver.hxx>
22 #include <GEOMImpl_IFace.hxx>
23 #include <GEOMImpl_Types.hxx>
25 #include <GEOM_Function.hxx>
27 #include <GEOMUtils.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(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 = GEOMUtils::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 #if OCC_VERSION_MAJOR < 7
122 log.SetTouched(Label());
124 log->SetTouched(Label());
130 //================================================================================
132 * \brief Returns a name of creation operation and names and values of creation parameters
134 //================================================================================
136 bool GEOMImpl_FaceDriver::
137 GetCreationInformation(std::string& theOperationName,
138 std::vector<GEOM_Param>& theParams)
140 if (Label().IsNull()) return 0;
141 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
143 GEOMImpl_IFace aCI( function );
144 Standard_Integer aType = function->GetType();
146 theOperationName = "RECTANGLE";
151 Handle(GEOM_Function) aRefFunct = aCI.GetRef1();
152 TopoDS_Shape aRefShape = aRefFunct->GetValue();
153 if (aRefShape.ShapeType() == TopAbs_EDGE)
154 AddParam( theParams, "Edge", aRefFunct );
156 AddParam( theParams, "Face", aRefFunct );
157 AddParam( theParams, "Height", aCI.GetH() );
158 AddParam( theParams, "Width", aCI.GetW() );
162 AddParam( theParams, "Height", aCI.GetH() );
163 AddParam( theParams, "Width", aCI.GetW() );
164 AddParam( theParams, "Orientation", aCI.GetOrientation() );
173 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_FaceDriver,GEOM_BaseDriver);