]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_CircleDriver.cxx
Salome HOME
if a shape to be rotated is a vertex, and it is located ON the Revolution Axis, then...
[modules/geom.git] / src / GEOMImpl / GEOMImpl_CircleDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_CircleDriver.hxx"
4 #include "GEOMImpl_ICircle.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_MakeCircle.hxx>
18 #include <Geom_Circle.hxx>
19
20 #include <Standard_ConstructionError.hxx>
21 #include <Precision.hxx>
22 #include <gp_Pnt.hxx>
23 #include <gp_Vec.hxx>
24 #include <gp_Circ.hxx>
25
26 //=======================================================================
27 //function : GetID
28 //purpose  :
29 //======================================================================= 
30 const Standard_GUID& GEOMImpl_CircleDriver::GetID()
31 {
32   static Standard_GUID aCircleDriver("FF1BBB32-5D14-4df2-980B-3A668264EA16");
33   return aCircleDriver; 
34 }
35
36
37 //=======================================================================
38 //function : GEOMImpl_CircleDriver
39 //purpose  : 
40 //=======================================================================
41 GEOMImpl_CircleDriver::GEOMImpl_CircleDriver() 
42 {
43 }
44
45 //=======================================================================
46 //function : Execute
47 //purpose  :
48 //======================================================================= 
49 Standard_Integer GEOMImpl_CircleDriver::Execute(TFunction_Logbook& log) const
50 {
51   if (Label().IsNull()) return 0;    
52   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
53
54   GEOMImpl_ICircle aCI (aFunction);
55   Standard_Integer aType = aFunction->GetType();
56
57   TopoDS_Shape aShape;
58
59   if (aType == CIRCLE_PNT_VEC_R) {
60     Handle(GEOM_Function) aRefPoint  = aCI.GetCenter();
61     Handle(GEOM_Function) aRefVector = aCI.GetVector();
62     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
63     TopoDS_Shape aShapeVec = aRefVector->GetValue();
64     if (aShapePnt.ShapeType() == TopAbs_VERTEX &&
65         aShapeVec.ShapeType() == TopAbs_EDGE) {
66       gp_Pnt aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
67       TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
68       TopoDS_Vertex V1, V2;
69       TopExp::Vertices(anE, V1, V2, Standard_True);
70       if (!V1.IsNull() && !V2.IsNull()) {
71         gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
72         gp_Ax2 anAxes (aP, aV);
73         gp_Circ aCirc (anAxes, aCI.GetRadius());
74         aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
75       }
76     }
77   }
78   else if (aType == CIRCLE_THREE_PNT) {
79     Handle(GEOM_Function) aRefPoint1 = aCI.GetPoint1();
80     Handle(GEOM_Function) aRefPoint2 = aCI.GetPoint2();
81     Handle(GEOM_Function) aRefPoint3 = aCI.GetPoint3();
82     TopoDS_Shape aShapePnt1 = aRefPoint1->GetValue();
83     TopoDS_Shape aShapePnt2 = aRefPoint2->GetValue();
84     TopoDS_Shape aShapePnt3 = aRefPoint3->GetValue();
85     if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
86         aShapePnt2.ShapeType() == TopAbs_VERTEX &&
87         aShapePnt3.ShapeType() == TopAbs_VERTEX) {
88       gp_Pnt aP1 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt1));
89       gp_Pnt aP2 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt2));
90       gp_Pnt aP3 = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt3));
91       if (aP1.Distance(aP2) < gp::Resolution() ||
92           aP1.Distance(aP3) < gp::Resolution() ||
93           aP2.Distance(aP3) < gp::Resolution())
94         Standard_ConstructionError::Raise("Circle creation aborted: coincident points given");
95       if (gp_Vec(aP1, aP2).IsParallel(gp_Vec(aP1, aP3), Precision::Angular()))
96         Standard_ConstructionError::Raise("Circle creation aborted: points lay on one line");
97       Handle(Geom_Circle) aCirc = GC_MakeCircle(aP1, aP2, aP3).Value();
98       aShape = BRepBuilderAPI_MakeEdge(aCirc).Edge();
99     }
100   }
101   else {
102   }
103
104   if (aShape.IsNull()) return 0;
105
106   aFunction->SetValue(aShape);
107
108   log.SetTouched(Label()); 
109
110   return 1;    
111 }
112
113
114 //=======================================================================
115 //function :  GEOMImpl_CircleDriver_Type_
116 //purpose  :
117 //======================================================================= 
118 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CircleDriver_Type_()
119 {
120
121   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
122   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
123   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
124   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
125   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
126   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
127  
128
129   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
130   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CircleDriver",
131                                                          sizeof(GEOMImpl_CircleDriver),
132                                                          1,
133                                                          (Standard_Address)_Ancestors,
134                                                          (Standard_Address)NULL);
135
136   return _aType;
137 }
138
139 //=======================================================================
140 //function : DownCast
141 //purpose  :
142 //======================================================================= 
143 const Handle(GEOMImpl_CircleDriver) Handle(GEOMImpl_CircleDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
144 {
145   Handle(GEOMImpl_CircleDriver) _anOtherObject;
146
147   if (!AnObject.IsNull()) {
148      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CircleDriver))) {
149        _anOtherObject = Handle(GEOMImpl_CircleDriver)((Handle(GEOMImpl_CircleDriver)&)AnObject);
150      }
151   }
152
153   return _anOtherObject ;
154 }