Back to index

salome-geom  6.5.0
GEOMImpl_RevolutionDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include <Standard_Stream.hxx>
00024 
00025 #include <GEOMImpl_RevolutionDriver.hxx>
00026 
00027 #include <GEOMImpl_IShapesOperations.hxx>
00028 #include <GEOMImpl_IRevolution.hxx>
00029 #include <GEOMImpl_Types.hxx>
00030 #include <GEOM_Function.hxx>
00031 
00032 #include <BRepPrimAPI_MakeRevol.hxx>
00033 #include <BRepBuilderAPI_Transform.hxx>
00034 #include <BRep_Tool.hxx>
00035 #include <TopoDS.hxx>
00036 #include <TopoDS_Shape.hxx>
00037 #include <TopoDS_Edge.hxx>
00038 #include <TopoDS_Vertex.hxx>
00039 #include <TopAbs.hxx>
00040 #include <TopExp.hxx>
00041 #include <gp_Trsf.hxx>
00042 #include <gp_Pnt.hxx>
00043 #include <gp_Lin.hxx>
00044 #include <gp_Dir.hxx>
00045 #include <Precision.hxx>
00046 #include <StdFail_NotDone.hxx>
00047 #include <Standard_TypeMismatch.hxx>
00048 #include <Standard_ConstructionError.hxx>
00049 
00050 //=======================================================================
00051 //function : GetID
00052 //purpose  :
00053 //======================================================================= 
00054 const Standard_GUID& GEOMImpl_RevolutionDriver::GetID()
00055 {
00056   static Standard_GUID aRevolutionDriver("FF1BBB18-5D14-4df2-980B-3A668264EA16");
00057   return aRevolutionDriver; 
00058 }
00059 
00060 
00061 //=======================================================================
00062 //function : GEOMImpl_RevolutionDriver
00063 //purpose  : 
00064 //=======================================================================
00065 GEOMImpl_RevolutionDriver::GEOMImpl_RevolutionDriver() 
00066 {
00067 }
00068 
00069 //=======================================================================
00070 //function : Execute
00071 //purpose  :
00072 //======================================================================= 
00073 Standard_Integer GEOMImpl_RevolutionDriver::Execute(TFunction_Logbook& log) const
00074 {
00075   if (Label().IsNull()) return 0;    
00076   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00077 
00078   GEOMImpl_IRevolution aCI (aFunction);
00079   Standard_Integer aType = aFunction->GetType();
00080 
00081   TopoDS_Shape aShape;
00082 
00083   if (aType == REVOLUTION_BASE_AXIS_ANGLE || aType == REVOLUTION_BASE_AXIS_ANGLE_2WAYS) {
00084     Handle(GEOM_Function) aRefBase = aCI.GetBase();
00085     Handle(GEOM_Function) aRefAxis = aCI.GetAxis();
00086     TopoDS_Shape aShapeBase = aRefBase->GetValue();
00087     TopoDS_Shape aShapeAxis = aRefAxis->GetValue();
00088     if (aShapeAxis.ShapeType() != TopAbs_EDGE) {
00089       Standard_TypeMismatch::Raise("Revolution Axis must be an edge");
00090     }
00091 
00092     TopoDS_Edge anE = TopoDS::Edge(aShapeAxis);
00093     TopoDS_Vertex V1, V2;
00094     TopExp::Vertices(anE, V1, V2, Standard_True);
00095     if (V1.IsNull() || V2.IsNull()) {
00096       Standard_ConstructionError::Raise("Bad edge for the Revolution Axis given");
00097     }
00098 
00099     gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
00100     if (aV.Magnitude() < Precision::Confusion()) {
00101       Standard_ConstructionError::Raise
00102         ("End vertices of edge, defining the Revolution Axis, are too close");
00103     }
00104 
00105     if (aShapeBase.ShapeType() == TopAbs_VERTEX) {
00106       gp_Lin aL(BRep_Tool::Pnt(V1), gp_Dir(aV));
00107       Standard_Real d = aL.Distance(BRep_Tool::Pnt(TopoDS::Vertex(aShapeBase)));
00108       if (d < Precision::Confusion()) {
00109         Standard_ConstructionError::Raise("Vertex to be rotated is too close to Revolution Axis");
00110       }
00111     }
00112     double anAngle = aCI.GetAngle();
00113     gp_Ax1 anAxis (BRep_Tool::Pnt(V1), aV);
00114     if (aType == REVOLUTION_BASE_AXIS_ANGLE_2WAYS)
00115       {
00116         gp_Trsf aTrsf;
00117         aTrsf.SetRotation(anAxis, ( -anAngle ));
00118         BRepBuilderAPI_Transform aTransformation(aShapeBase, aTrsf, Standard_False);
00119         aShapeBase = aTransformation.Shape();
00120         anAngle = anAngle * 2;
00121       }
00122     BRepPrimAPI_MakeRevol MR (aShapeBase, anAxis, anAngle, Standard_False);
00123     if (!MR.IsDone()) MR.Build();
00124     if (!MR.IsDone()) StdFail_NotDone::Raise("Revolution algorithm has failed");
00125     aShape = MR.Shape();
00126   } else {
00127   }
00128 
00129   if (aShape.IsNull()) return 0;
00130 
00131   TopoDS_Shape aRes = GEOMImpl_IShapesOperations::CompsolidToCompound(aShape);
00132   aFunction->SetValue(aRes);
00133 
00134   log.SetTouched(Label());
00135 
00136   return 1;
00137 }
00138 
00139 
00140 //=======================================================================
00141 //function :  GEOMImpl_RevolutionDriver_Type_
00142 //purpose  :
00143 //======================================================================= 
00144 Standard_EXPORT Handle_Standard_Type& GEOMImpl_RevolutionDriver_Type_()
00145 {
00146 
00147   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00148   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00149   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00150   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00151   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00152   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00153  
00154 
00155   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00156   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_RevolutionDriver",
00157                                                          sizeof(GEOMImpl_RevolutionDriver),
00158                                                          1,
00159                                                          (Standard_Address)_Ancestors,
00160                                                          (Standard_Address)NULL);
00161 
00162   return _aType;
00163 }
00164 
00165 //=======================================================================
00166 //function : DownCast
00167 //purpose  :
00168 //======================================================================= 
00169 const Handle(GEOMImpl_RevolutionDriver) Handle(GEOMImpl_RevolutionDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00170 {
00171   Handle(GEOMImpl_RevolutionDriver) _anOtherObject;
00172 
00173   if (!AnObject.IsNull()) {
00174      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_RevolutionDriver))) {
00175        _anOtherObject = Handle(GEOMImpl_RevolutionDriver)((Handle(GEOMImpl_RevolutionDriver)&)AnObject);
00176      }
00177   }
00178 
00179   return _anOtherObject ;
00180 }