Back to index

salome-geom  6.5.0
GEOMImpl_ArcDriver.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_ArcDriver.hxx>
00026 #include <GEOMImpl_IArc.hxx>
00027 #include <GEOMImpl_Types.hxx>
00028 #include <GEOM_Function.hxx>
00029 
00030 #include <BRepBuilderAPI_MakeEdge.hxx>
00031 #include <BRep_Tool.hxx>
00032 #include <TopoDS.hxx>
00033 #include <TopoDS_Shape.hxx>
00034 #include <TopoDS_Edge.hxx>
00035 #include <TopoDS_Vertex.hxx>
00036 #include <TopAbs.hxx>
00037 #include <TopExp.hxx>
00038 
00039 #include <GC_MakeArcOfCircle.hxx>
00040 #include <GC_MakeCircle.hxx>
00041 #include <GC_MakeArcOfEllipse.hxx>
00042 #include <GC_MakeEllipse.hxx>
00043 #include <Standard_ConstructionError.hxx>
00044 #include <Precision.hxx>
00045 #include <gp_Pnt.hxx>
00046 #include <gp_Vec.hxx>
00047 #include <gp_Circ.hxx>
00048 #include <gp_Elips.hxx>
00049 #include <Geom_Circle.hxx>
00050 #include <Geom_Ellipse.hxx>
00051 
00052 #include "utilities.h"
00053 
00054 //=======================================================================
00055 //function : GetID
00056 //purpose  :
00057 //======================================================================= 
00058 const Standard_GUID& GEOMImpl_ArcDriver::GetID()
00059 {
00060   static Standard_GUID aArcDriver("FF1BBB35-5D14-4df2-980B-3A668264EA16");
00061   return aArcDriver; 
00062 }
00063 
00064 
00065 //=======================================================================
00066 //function : GEOMImpl_ArcDriver
00067 //purpose  : 
00068 //=======================================================================
00069 GEOMImpl_ArcDriver::GEOMImpl_ArcDriver() 
00070 {
00071 }
00072 
00073 //=======================================================================
00074 //function : Execute
00075 //purpose  :
00076 //======================================================================= 
00077 Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
00078 {
00079   if (Label().IsNull()) return 0;    
00080   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
00081 
00082   GEOMImpl_IArc aCI (aFunction);
00083   Standard_Integer aType = aFunction->GetType();
00084 
00085   TopoDS_Shape aShape;
00086   if ((aType == CIRC_ARC_THREE_PNT) || (aType == CIRC_ARC_CENTER) || (aType == ELLIPSE_ARC_CENTER_TWO_PNT))
00087   {
00088     Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
00089     Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
00090     Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
00091 
00092     TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
00093     TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
00094     TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
00095 
00096     if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
00097         aShapePnt2.ShapeType() == TopAbs_VERTEX &&
00098         aShapePnt3.ShapeType() == TopAbs_VERTEX)
00099     {
00100       gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
00101       gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
00102       gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
00103 
00104       if (aP1.Distance(aP2) < gp::Resolution() ||
00105           aP1.Distance(aP3) < gp::Resolution() ||
00106           aP2.Distance(aP3) < gp::Resolution())
00107         Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
00108 
00109       if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
00110         Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
00111 
00112       if (aType == CIRC_ARC_THREE_PNT)
00113       {
00114         GC_MakeArcOfCircle arc (aP1, aP2, aP3);
00115         aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
00116       } else if ( aType == CIRC_ARC_CENTER ) { // CIRC_ARC_CENTER
00117         Standard_Boolean sense = aCI.GetSense();
00118 
00119         Standard_Real aRad = aP1.Distance(aP2);
00120         gp_Vec aV1 (aP1, aP2);
00121         gp_Vec aV2 (aP1, aP3);
00122         gp_Vec aN = aV1 ^ aV2;
00123 
00124         if (sense)
00125           aN = -aN;
00126 
00127         GC_MakeCircle circ (aP1, aN, aRad);
00128         Handle(Geom_Circle) aGeomCirc = circ.Value();
00129 
00130         GC_MakeArcOfCircle arc (aGeomCirc->Circ(), aP2, aP3, Standard_True);
00131         aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
00132       } else if ( aType == ELLIPSE_ARC_CENTER_TWO_PNT ) { // ELLIPSE_ARC_CENTER_TWO_PNT
00133         if ( aP1.Distance(aP2) <= aP1.Distance(aP3) ) {
00134           // Standard_ConstructionError::Raise("Arc creation aborted: the distance from Center Point to Point 1 needs to be bigger than the distance from Center Point to Point 2");      
00135           cout << "aP1.Distance(aP2) <= aP1.Distance(aP3)" << endl;
00136           gp_Pnt aTmpP = aP2;
00137           aP2 = aP3;
00138           aP3 = aTmpP;
00139         }
00140 
00141         GC_MakeEllipse ellipse (aP2, aP3, aP1);
00142         Handle(Geom_Ellipse) aGeomEllipse = ellipse.Value();
00143 
00144 //         gp_Vec aV1 (aP1, aP2);
00145 //         gp_Vec aV2 (aP1, aP3);
00146 // 
00147 //         double alpha = fabs(aV1.Angle(aV2));
00148         
00149         GC_MakeArcOfEllipse arc (aGeomEllipse->Elips(), aP2, aP3, Standard_True);
00150         aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
00151       }
00152     }
00153   }
00154   else {
00155   }
00156 
00157   if (aShape.IsNull()) return 0;
00158 
00159   aFunction->SetValue(aShape);
00160 
00161   log.SetTouched(Label());
00162   return 1;
00163 }
00164 
00165 
00166 //=======================================================================
00167 //function :  GEOMImpl_ArcDriver_Type_
00168 //purpose  :
00169 //======================================================================= 
00170 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArcDriver_Type_()
00171 {
00172 
00173   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
00174   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
00175   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
00176   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
00177   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
00178   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
00179  
00180 
00181   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
00182   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArcDriver",
00183                                                          sizeof(GEOMImpl_ArcDriver),
00184                                                          1,
00185                                                          (Standard_Address)_Ancestors,
00186                                                          (Standard_Address)NULL);
00187 
00188   return _aType;
00189 }
00190 
00191 //=======================================================================
00192 //function : DownCast
00193 //purpose  :
00194 //======================================================================= 
00195 const Handle(GEOMImpl_ArcDriver) Handle(GEOMImpl_ArcDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
00196 {
00197   Handle(GEOMImpl_ArcDriver) _anOtherObject;
00198 
00199   if (!AnObject.IsNull()) {
00200      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArcDriver))) {
00201        _anOtherObject = Handle(GEOMImpl_ArcDriver)((Handle(GEOMImpl_ArcDriver)&)AnObject);
00202      }
00203   }
00204 
00205   return _anOtherObject ;
00206 }