1 // Copyright (C) 2007-2016 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, or (at your option) any later version.
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
23 #include <Standard_Stream.hxx>
25 #include <GEOMImpl_RevolutionDriver.hxx>
27 #include <GEOMImpl_IRevolution.hxx>
28 #include <GEOMImpl_Types.hxx>
30 #include <GEOM_Function.hxx>
32 #include <GEOMUtils.hxx>
34 #include <BRepPrimAPI_MakeRevol.hxx>
35 #include <BRepBuilderAPI_Transform.hxx>
36 #include <BRep_Tool.hxx>
38 #include <TopoDS_Shape.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Vertex.hxx>
43 #include <gp_Trsf.hxx>
47 #include <Precision.hxx>
48 #include <StdFail_NotDone.hxx>
49 #include <Standard_TypeMismatch.hxx>
50 #include <Standard_ConstructionError.hxx>
52 //=======================================================================
55 //=======================================================================
56 const Standard_GUID& GEOMImpl_RevolutionDriver::GetID()
58 static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
59 return aRevolutionDriver;
63 //=======================================================================
64 //function : GEOMImpl_RevolutionDriver
66 //=======================================================================
67 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver()
71 //=======================================================================
74 //=======================================================================
75 Standard_Integer GEOMImpl_RevolutionDriver::Execute(LOGBOOK& log) const
77 if (Label().IsNull()) return 0;
78 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
80 GEOMImpl_IRevolution aCI (aFunction);
81 Standard_Integer aType = aFunction->GetType();
85 if (aType == REVOLUTION_BASE_AXIS_ANGLE || aType == REVOLUTION_BASE_AXIS_ANGLE_2WAYS) {
86 Handle(GEOM_Function) aRefBase = aCI.GetBase();
87 Handle(GEOM_Function) aRefAxis = aCI.GetAxis();
88 TopoDS_Shape aShapeBase = aRefBase->GetValue();
89 TopoDS_Shape aShapeAxis = aRefAxis->GetValue();
90 if (aShapeAxis.ShapeType() != TopAbs_EDGE) {
91 Standard_TypeMismatch::Raise("Revolution Axis must be an edge");
94 TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
96 TopExp::Vertices(anE, V1, V2, Standard_True);
97 if (V1.IsNull() || V2.IsNull()) {
98 Standard_ConstructionError::Raise("Bad edge for the Revolution Axis given");
101 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
102 if (aV.Magnitude() < Precision::Confusion()) {
103 Standard_ConstructionError::Raise
104 ("End vertices of edge, defining the Revolution Axis, are too close");
107 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
108 gp_Lin aL(BRep_Tool::Pnt(V1), gp_Dir(aV));
109 Standard_Real d = aL.Distance(BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)));
110 if (d < Precision::Confusion()) {
111 Standard_ConstructionError::Raise("Vertex to be rotated is too close to Revolution Axis");
114 double anAngle = aCI.GetAngle();
115 gp_Ax1 anAxis (BRep_Tool::Pnt(V1), aV);
116 if (aType == REVOLUTION_BASE_AXIS_ANGLE_2WAYS)
119 aTrsf.SetRotation(anAxis, ( -anAngle ));
120 BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
121 aShapeBase = aTransformation.Shape();
122 anAngle = anAngle * 2;
124 BRepPrimAPI_MakeRevol MR (aShapeBase, anAxis, anAngle, Standard_False);
125 if (!MR.IsDone()) MR.Build();
126 if (!MR.IsDone()) StdFail_NotDone::Raise("Revolution algorithm has failed");
131 if (aShape.IsNull()) return 0;
133 TopoDS_Shape aRes = GEOMUtils::CompsolidToCompound(aShape);
134 aFunction->SetValue(aRes);
136 #if OCC_VERSION_MAJOR < 7
137 log.SetTouched(Label());
139 log->SetTouched(Label());
145 //================================================================================
147 * \brief Returns a name of creation operation and names and values of creation parameters
149 //================================================================================
151 bool GEOMImpl_RevolutionDriver::
152 GetCreationInformation(std::string& theOperationName,
153 std::vector<GEOM_Param>& theParams)
155 if (Label().IsNull()) return 0;
156 Handle(GEOM_Function) function = GEOM_Function::GetFunction(Label());
158 GEOMImpl_IRevolution aCI( function );
159 Standard_Integer aType = function->GetType();
161 theOperationName = "REVOLUTION";
164 case REVOLUTION_BASE_AXIS_ANGLE:
165 case REVOLUTION_BASE_AXIS_ANGLE_2WAYS:
166 AddParam( theParams, "Object", aCI.GetBase() );
167 AddParam( theParams, "Axis", aCI.GetAxis() );
168 AddParam( theParams, "Angle", aCI.GetAngle() );
169 AddParam( theParams, "Both Directions", aType == REVOLUTION_BASE_AXIS_ANGLE_2WAYS );
178 OCCT_IMPLEMENT_STANDARD_RTTIEXT (GEOMImpl_RevolutionDriver,GEOM_BaseDriver);