Back to index

salome-geom  6.5.0
GEOMImpl_DiskDriver.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #include <Standard_Stream.hxx>
00021 
00022 #include <GEOMImpl_DiskDriver.hxx>
00023 #include <GEOMImpl_IDisk.hxx>
00024 #include <GEOMImpl_Types.hxx>
00025 #include <GEOM_Function.hxx>
00026 
00027 #include <BRepBuilderAPI_MakeEdge.hxx>
00028 #include <BRepBuilderAPI_MakeWire.hxx>
00029 #include <BRepBuilderAPI_MakeFace.hxx>
00030 #include <BRep_Tool.hxx>
00031 #include <TopoDS.hxx>
00032 #include <TopoDS_Shape.hxx>
00033 #include <TopoDS_Edge.hxx>
00034 #include <TopoDS_Vertex.hxx>
00035 #include <TopoDS_Wire.hxx>
00036 #include <TopAbs.hxx>
00037 #include <TopExp.hxx>
00038 
00039 #include <GC_MakeCircle.hxx>
00040 #include <Geom_Circle.hxx>
00041 
00042 #include <Standard_ConstructionError.hxx>
00043 #include <Precision.hxx>
00044 #include <gp_Pnt.hxx>
00045 #include <gp_Vec.hxx>
00046 #include <gp_Circ.hxx>
00047 
00048 //=======================================================================
00049 //function : GetID
00050 //purpose  :
00051 //======================================================================= 
00052 const Standard_GUID& GEOMImpl_DiskDriver::GetID()
00053 {
00054   static Standard_GUID aDiskDriver("C1FEEF9D-1C6D-41ce-9507-F10D75430CE1");
00055   return aDiskDriver; 
00056 }
00057 
00058 
00059 //=======================================================================
00060 //function : GEOMImpl_DiskDriver
00061 //purpose  : 
00062 //=======================================================================
00063 GEOMImpl_DiskDriver::GEOMImpl_DiskDriver() 
00064 {
00065 }
00066 
00067 //=======================================================================
00068 //function : Execute
00069 //purpose  :
00070 //======================================================================= 
00071 Standard_Integer GEOMImpl_DiskDriver::Execute(TFunction_Logbook& log) const
00072 {
00073   if (Label().IsNull()) return 0;    
00074   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00075 
00076   GEOMImpl_IDisk aCI (aFunction);
00077   Standard_Integer aType = aFunction->GetType();
00078 
00079   TopoDS_Shape aShape;
00080 
00081   if (aType == DISK_PNT_VEC_R) {
00082     Handle(GEOM_Function) aRefPoint  = aCI.GetCenter();
00083     Handle(GEOM_Function) aRefVector = aCI.GetVector();
00084     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
00085     TopoDS_Shape aShapeVec = aRefVector->GetValue();
00086     if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
00087         aShapeVec.ShapeType() == TopAbs_EDGE) {
00088       gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
00089       TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
00090       TopoDS_Vertex V1, V2;
00091       TopExp::Vertices(anE, V1, V2, Standard_True);
00092       if (!V1.IsNull() && !V2.IsNull()) {
00093         gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
00094         gp_Ax2 anAxes (aP, -aV);
00095         gp_Circ aCirc (anAxes, aCI.GetRadius());
00096         TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
00097         BRepBuilderAPI_MakeWire MW;
00098         MW.Add(TopoDS::Edge(aCircle));
00099         BRepBuilderAPI_MakeFace MF (MW, Standard_False);
00100         aShape = MF.Shape();
00101       }
00102     }
00103   }
00104   else if (aType == DISK_THREE_PNT) {
00105     Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
00106     Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
00107     Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
00108     TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
00109     TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
00110     TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
00111     if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
00112         aShapePnt2.ShapeType() == TopAbs_VERTEX &&
00113         aShapePnt3.ShapeType() == TopAbs_VERTEX) {
00114       gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
00115       gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
00116       gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
00117       if (aP1.Distance(aP2) < gp::Resolution() ||
00118           aP1.Distance(aP3) < gp::Resolution() ||
00119           aP2.Distance(aP3) < gp::Resolution())
00120         Standard_ConstructionError::Raise("Disk creation aborted: coincident points given");
00121       if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
00122         Standard_ConstructionError::Raise("Disk creation aborted: points lay on one line");
00123       Handle(Geom_Circle) aCirc = GC_MakeCircle(aP3, aP2, aP1).Value();
00124       TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
00125       BRepBuilderAPI_MakeWire MW;
00126       MW.Add(TopoDS::Edge(aCircle));
00127       BRepBuilderAPI_MakeFace MF (MW, Standard_False);
00128       aShape = MF.Shape();
00129     }  
00130   }
00131   else if (aType == DISK_R) {
00132     int anOrient = aCI.GetOrientation();
00133     gp_Pnt aP = gp::Origin();
00134     gp_Vec aV;
00135     if (anOrient == 1)
00136       aV = gp::DZ();
00137     else if (anOrient == 2)
00138       aV = gp::DX();
00139     else if (anOrient == 3)
00140       aV = gp::DY();
00141 
00142     gp_Ax2 anAxes (aP, -aV);
00143     gp_Circ aCirc (anAxes, aCI.GetRadius());
00144     TopoDS_Shape aCircle = BRepBuilderAPI_MakeEdge(aCirc).Edge();
00145     BRepBuilderAPI_MakeWire MW;
00146     MW.Add(TopoDS::Edge(aCircle));
00147     BRepBuilderAPI_MakeFace MF (MW, Standard_False);
00148     aShape = MF.Shape();
00149   }
00150    else {
00151   }
00152 
00153   if (aShape.IsNull()) return 0;
00154 
00155   aFunction->SetValue(aShape);
00156 
00157   log.SetTouched(Label()); 
00158 
00159   return 1;    
00160 }
00161 
00162 
00163 //=======================================================================
00164 //function :  GEOMImpl_DiskDriver_Type_
00165 //purpose  :
00166 //======================================================================= 
00167 Standard_EXPORT Handle_Standard_Type& GEOMImpl_DiskDriver_Type_()
00168 {
00169 
00170   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00171   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00172   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00173   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00174   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00175   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00176  
00177 
00178   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00179   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_DiskDriver",
00180                                                          sizeof(GEOMImpl_DiskDriver),
00181                                                          1,
00182                                                          (Standard_Address)_Ancestors,
00183                                                          (Standard_Address)NULL);
00184 
00185   return _aType;
00186 }
00187 
00188 //=======================================================================
00189 //function : DownCast
00190 //purpose  :
00191 //======================================================================= 
00192 const Handle(GEOMImpl_DiskDriver) Handle(GEOMImpl_DiskDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00193 {
00194   Handle(GEOMImpl_DiskDriver) _anOtherObject;
00195 
00196   if (!AnObject.IsNull()) {
00197      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_DiskDriver))) {
00198        _anOtherObject = Handle(GEOMImpl_DiskDriver)((Handle(GEOMImpl_DiskDriver)&)AnObject);
00199      }
00200   }
00201 
00202   return _anOtherObject ;
00203 }