]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_ArcDriver.cxx
Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / GEOMImpl / GEOMImpl_ArcDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_ArcDriver.hxx"
4 #include "GEOMImpl_IArc.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepBuilderAPI_MakeEdge.hxx>
9 #include <BRep_Tool.hxx>
10 #include <TopoDS.hxx>
11 #include <TopoDS_Shape.hxx>
12 #include <TopoDS_Edge.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopAbs.hxx>
15 #include <TopExp.hxx>
16
17 #include <GC_MakeArcOfCircle.hxx>
18
19 #include <Standard_ConstructionError.hxx>
20 #include <Precision.hxx>
21 #include <gp_Pnt.hxx>
22 #include <gp_Vec.hxx>
23
24 //=======================================================================
25 //function : GetID
26 //purpose  :
27 //======================================================================= 
28 const Standard_GUID& GEOMImpl_ArcDriver::GetID()
29 {
30   static Standard_GUID aArcDriver("FF1BBB35-5D14-4df2-980B-3A668264EA16");
31   return aArcDriver; 
32 }
33
34
35 //=======================================================================
36 //function : GEOMImpl_ArcDriver
37 //purpose  : 
38 //=======================================================================
39 GEOMImpl_ArcDriver::GEOMImpl_ArcDriver() 
40 {
41 }
42
43 //=======================================================================
44 //function : Execute
45 //purpose  :
46 //======================================================================= 
47 Standard_Integer GEOMImpl_ArcDriver::Execute(TFunction_Logbook& log) const
48 {
49   if (Label().IsNull()) return 0;    
50   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
51
52   GEOMImpl_IArc aCI (aFunction);
53   Standard_Integer aType = aFunction->GetType();
54
55   TopoDS_Shape aShape;
56
57   if (aType == CIRC_ARC_THREE_PNT) {
58     Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
59     Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
60     Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
61     TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
62     TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
63     TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
64     if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
65         aShapePnt2.ShapeType() == TopAbs_VERTEX &&
66         aShapePnt3.ShapeType() == TopAbs_VERTEX) {
67       gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
68       gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
69       gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
70       if (aP1.Distance(aP2) < gp::Resolution() ||
71           aP1.Distance(aP3) < gp::Resolution() ||
72           aP2.Distance(aP3) < gp::Resolution())
73         Standard_ConstructionError::Raise("Arc creation aborted: coincident points given");
74       if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
75         Standard_ConstructionError::Raise("Arc creation aborted: points lay on one line");
76       GC_MakeArcOfCircle arc (aP1, aP2, aP3);
77       aShape = BRepBuilderAPI_MakeEdge(arc).Edge();
78     }
79   } else {
80   }
81
82   if (aShape.IsNull()) return 0;
83
84   aFunction->SetValue(aShape);
85
86   log.SetTouched(Label());
87   
88   return 1;    
89 }
90
91
92 //=======================================================================
93 //function :  GEOMImpl_ArcDriver_Type_
94 //purpose  :
95 //======================================================================= 
96 Standard_EXPORT Handle_Standard_Type& GEOMImpl_ArcDriver_Type_()
97 {
98
99   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
100   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
101   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
102   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
103   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
104   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
105  
106
107   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
108   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_ArcDriver",
109                                                          sizeof(GEOMImpl_ArcDriver),
110                                                          1,
111                                                          (Standard_Address)_Ancestors,
112                                                          (Standard_Address)NULL);
113
114   return _aType;
115 }
116
117 //=======================================================================
118 //function : DownCast
119 //purpose  :
120 //======================================================================= 
121 const Handle(GEOMImpl_ArcDriver) Handle(GEOMImpl_ArcDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
122 {
123   Handle(GEOMImpl_ArcDriver) _anOtherObject;
124
125   if (!AnObject.IsNull()) {
126      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_ArcDriver))) {
127        _anOtherObject = Handle(GEOMImpl_ArcDriver)((Handle(GEOMImpl_ArcDriver)&)AnObject);
128      }
129   }
130
131   return _anOtherObject ;
132 }