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_RevolutionDriver.hxx>
25 #include <GEOMImpl_IShapesOperations.hxx>
26 #include <GEOMImpl_IRevolution.hxx>
27 #include <GEOMImpl_Types.hxx>
28 #include <GEOM_Function.hxx>
30 #include <BRepPrimAPI_MakeRevol.hxx>
31 #include <BRep_Tool.hxx>
33 #include <TopoDS_Shape.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Vertex.hxx>
42 #include <Precision.hxx>
43 #include <StdFail_NotDone.hxx>
44 #include <Standard_TypeMismatch.hxx>
45 #include <Standard_ConstructionError.hxx>
47 //=======================================================================
50 //=======================================================================
51 const Standard_GUID& GEOMImpl_RevolutionDriver::GetID()
53 static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
54 return aRevolutionDriver;
58 //=======================================================================
59 //function : GEOMImpl_RevolutionDriver
61 //=======================================================================
62 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver()
66 //=======================================================================
69 //=======================================================================
70 Standard_Integer GEOMImpl_RevolutionDriver::Execute(TFunction_Logbook& log) const
72 if (Label().IsNull()) return 0;
73 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
75 GEOMImpl_IRevolution aCI (aFunction);
76 Standard_Integer aType = aFunction->GetType();
80 if (aType == REVOLUTION_BASE_AXIS_ANGLE) {
81 Handle(GEOM_Function) aRefBase = aCI.GetBase();
82 Handle(GEOM_Function) aRefAxis = aCI.GetAxis();
83 TopoDS_Shape aShapeBase = aRefBase->GetValue();
84 TopoDS_Shape aShapeAxis = aRefAxis->GetValue();
85 if (aShapeAxis.ShapeType() != TopAbs_EDGE) {
86 Standard_TypeMismatch::Raise("Revolution Axis must be an edge");
89 TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
91 TopExp::Vertices(anE, V1, V2, Standard_True);
92 if (V1.IsNull() || V2.IsNull()) {
93 Standard_ConstructionError::Raise("Bad edge for the Revolution Axis given");
96 gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
97 if (aV.Magnitude() < Precision::Confusion()) {
98 Standard_ConstructionError::Raise
99 ("End vertices of edge, defining the Revolution Axis, are too close");
102 if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
103 gp_Lin aL(BRep_Tool::Pnt(V1), gp_Dir(aV));
104 Standard_Real d = aL.Distance(BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)));
105 if (d < Precision::Confusion()) {
106 Standard_ConstructionError::Raise("Vertex to be rotated is too close to Revolution Axis");
110 gp_Ax1 anAxis (BRep_Tool::Pnt(V1), aV);
111 BRepPrimAPI_MakeRevol MR (aShapeBase, anAxis, aCI.GetAngle(), Standard_False);
112 if (!MR.IsDone()) MR.Build();
113 if (!MR.IsDone()) StdFail_NotDone::Raise("Revolution algorithm has failed");
118 if (aShape.IsNull()) return 0;
120 TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
121 aFunction->SetValue(aRes);
123 log.SetTouched(Label());
129 //=======================================================================
130 //function : GEOMImpl_RevolutionDriver_Type_
132 //=======================================================================
133 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RevolutionDriver_Type_()
136 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
137 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
138 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
139 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
140 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
141 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
144 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
145 static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RevolutionDriver",
146 sizeof(GEOMImpl_RevolutionDriver),
148 (Standard_Address)_Ancestors,
149 (Standard_Address)NULL);
154 //=======================================================================
155 //function : DownCast
157 //=======================================================================
158 const Handle(GEOMImpl_RevolutionDriver) Handle(GEOMImpl_RevolutionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
160 Handle(GEOMImpl_RevolutionDriver) _anOtherObject;
162 if (!AnObject.IsNull()) {
163 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RevolutionDriver))) {
164 _anOtherObject = Handle(GEOMImpl_RevolutionDriver)((Handle(GEOMImpl_RevolutionDriver)&)AnObject);
168 return _anOtherObject ;