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