]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMImpl/GEOMImpl_CylinderDriver.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_CylinderDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_CylinderDriver.hxx"
4 #include "GEOMImpl_ICylinder.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepPrimAPI_MakeCylinder.hxx>
9 #include <BRep_Tool.hxx>
10
11 #include <TopAbs.hxx>
12 #include <TopoDS.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Vertex.hxx>
15 #include <TopExp.hxx>
16
17 #include <Standard_TypeMismatch.hxx>
18 #include <Standard_NullObject.hxx>
19 #include <StdFail_NotDone.hxx>
20 #include <gp_Pnt.hxx>
21 #include <gp.hxx>
22
23 //=======================================================================
24 //function : GetID
25 //purpose  :
26 //=======================================================================
27 const Standard_GUID& GEOMImpl_CylinderDriver::GetID()
28 {
29   static Standard_GUID aCylinderDriver("FF1BBB14-5D14-4df2-980B-3A668264EA16");
30   return aCylinderDriver;
31 }
32
33
34 //=======================================================================
35 //function : GEOMImpl_CylinderDriver
36 //purpose  :
37 //=======================================================================
38 GEOMImpl_CylinderDriver::GEOMImpl_CylinderDriver()
39 {
40 }
41
42 //=======================================================================
43 //function : Execute
44 //purpose  :
45 //=======================================================================
46 Standard_Integer GEOMImpl_CylinderDriver::Execute(TFunction_Logbook& log) const
47 {
48   if (Label().IsNull()) return 0;
49   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
50
51   GEOMImpl_ICylinder aCI (aFunction);
52   Standard_Integer aType = aFunction->GetType();
53
54   gp_Pnt aP;
55   gp_Vec aV;
56
57   if (aType == CYLINDER_R_H) {
58     aP = gp::Origin();
59     aV = gp::DZ();
60   }
61   else if (aType == CYLINDER_PNT_VEC_R_H) {
62     Handle(GEOM_Function) aRefPoint  = aCI.GetPoint();
63     Handle(GEOM_Function) aRefVector = aCI.GetVector();
64     TopoDS_Shape aShapePnt = aRefPoint->GetValue();
65     TopoDS_Shape aShapeVec = aRefVector->GetValue();
66     if (aShapePnt.IsNull() || aShapeVec.IsNull()) {
67       Standard_NullObject::Raise("Cylinder creation aborted: point or vector is not defined");
68     }
69     if (aShapePnt.ShapeType() != TopAbs_VERTEX ||
70         aShapeVec.ShapeType() != TopAbs_EDGE) {
71       Standard_TypeMismatch::Raise("Cylinder creation aborted: point or vector shapes has wrong type");
72     }
73
74     aP = BRep_Tool::Pnt(TopoDS::Vertex(aShapePnt));
75
76     TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
77     TopoDS_Vertex V1, V2;
78     TopExp::Vertices(anE, V1, V2, Standard_True);
79     if (V1.IsNull() || V2.IsNull()) {
80       Standard_NullObject::Raise("Cylinder creation aborted: vector is not defined");
81     }
82     aV = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
83   }
84   else {
85     return 0;
86   }
87
88   if (aCI.GetH() < 0.0) aV.Reverse();
89   gp_Ax2 anAxes (aP, aV);
90
91   BRepPrimAPI_MakeCylinder MC (anAxes, aCI.GetR(), Abs(aCI.GetH()));
92   MC.Build();
93   if (!MC.IsDone()) {
94     StdFail_NotDone::Raise("Cylinder can't be computed from the given parameters");
95   }
96
97   TopoDS_Shape aShape = MC.Shape();
98   if (aShape.IsNull()) return 0;
99
100   aFunction->SetValue(aShape);
101
102   log.SetTouched(Label());
103
104   return 1;
105 }
106
107
108 //=======================================================================
109 //function :  GEOMImpl_CylinderDriver_Type_
110 //purpose  :
111 //=======================================================================
112 Standard_EXPORT Handle_Standard_Type& GEOMImpl_CylinderDriver_Type_()
113 {
114
115   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
116   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
117   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
118   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
119   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
120   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
121
122
123   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
124   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_CylinderDriver",
125                                                          sizeof(GEOMImpl_CylinderDriver),
126                                                          1,
127                                                          (Standard_Address)_Ancestors,
128                                                          (Standard_Address)NULL);
129
130   return _aType;
131 }
132
133 //=======================================================================
134 //function : DownCast
135 //purpose  :
136 //=======================================================================
137 const Handle(GEOMImpl_CylinderDriver) Handle(GEOMImpl_CylinderDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
138 {
139   Handle(GEOMImpl_CylinderDriver) _anOtherObject;
140
141   if (!AnObject.IsNull()) {
142      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_CylinderDriver))) {
143        _anOtherObject = Handle(GEOMImpl_CylinderDriver)((Handle(GEOMImpl_CylinderDriver)&)AnObject);
144      }
145   }
146
147   return _anOtherObject ;
148 }