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_PrismDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_PrismDriver.hxx"
4 #include "GEOMImpl_IPrism.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepPrimAPI_MakePrism.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 <Precision.hxx>
18 #include <gp_Pnt.hxx>
19 #include <Standard_ConstructionError.hxx>
20
21 //=======================================================================
22 //function : GetID
23 //purpose  :
24 //======================================================================= 
25 const Standard_GUID& GEOMImpl_PrismDriver::GetID()
26 {
27   static Standard_GUID aPrismDriver("FF1BBB17-5D14-4df2-980B-3A668264EA16");
28   return aPrismDriver; 
29 }
30
31
32 //=======================================================================
33 //function : GEOMImpl_PrismDriver
34 //purpose  : 
35 //=======================================================================
36 GEOMImpl_PrismDriver::GEOMImpl_PrismDriver() 
37 {
38 }
39
40 //=======================================================================
41 //function : Execute
42 //purpose  :
43 //======================================================================= 
44 Standard_Integer GEOMImpl_PrismDriver::Execute(TFunction_Logbook& log) const
45 {
46   if (Label().IsNull()) return 0;    
47   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
48
49   GEOMImpl_IPrism aCI (aFunction);
50   Standard_Integer aType = aFunction->GetType();
51
52   TopoDS_Shape aShape;
53
54   if (aType == PRISM_BASE_VEC_H) {
55     Handle(GEOM_Function) aRefBase = aCI.GetBase();
56     Handle(GEOM_Function) aRefVector = aCI.GetVector();
57     TopoDS_Shape aShapeBase = aRefBase->GetValue();
58     TopoDS_Shape aShapeVec = aRefVector->GetValue();
59     if (aShapeVec.ShapeType() == TopAbs_EDGE) {
60       TopoDS_Edge anE = TopoDS::Edge(aShapeVec);
61       TopoDS_Vertex V1, V2;
62       TopExp::Vertices(anE, V1, V2, Standard_True);
63       if (!V1.IsNull() && !V2.IsNull()) {
64         gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
65         if (Abs(aCI.GetH()) < Precision::Confusion()) {
66           Standard_ConstructionError::Raise("Absolute value of prism height is too small");
67         }
68         if (aV.Magnitude() > Precision::Confusion()) {
69           aV.Normalize();
70           aShape = BRepPrimAPI_MakePrism(aShapeBase, aV * aCI.GetH(), Standard_False).Shape();
71         }
72       }
73     }
74   } else if (aType == PRISM_BASE_TWO_PNT) {
75     Handle(GEOM_Function) aRefBase = aCI.GetBase();
76     Handle(GEOM_Function) aRefPnt1 = aCI.GetFirstPoint();
77     Handle(GEOM_Function) aRefPnt2 = aCI.GetLastPoint();
78     TopoDS_Shape aShapeBase = aRefBase->GetValue();
79     TopoDS_Shape aShapePnt1 = aRefPnt1->GetValue();
80     TopoDS_Shape aShapePnt2 = aRefPnt2->GetValue();
81     if (aShapePnt1.ShapeType() == TopAbs_VERTEX &&
82         aShapePnt2.ShapeType() == TopAbs_VERTEX) {
83       TopoDS_Vertex V1 = TopoDS::Vertex(aShapePnt1);
84       TopoDS_Vertex V2 = TopoDS::Vertex(aShapePnt2);
85       if (!V1.IsNull() && !V2.IsNull()) {
86         gp_Vec aV (BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
87         if (aV.Magnitude() > gp::Resolution()) {
88           aShape = BRepPrimAPI_MakePrism(aShapeBase, aV, Standard_False).Shape();
89         }
90       }
91     }
92   } else {
93   }
94
95   if (aShape.IsNull()) return 0;
96
97   aFunction->SetValue(aShape);
98
99   log.SetTouched(Label()); 
100
101   return 1;    
102 }
103
104
105 //=======================================================================
106 //function :  GEOMImpl_PrismDriver_Type_
107 //purpose  :
108 //======================================================================= 
109 Standard_EXPORT Handle_Standard_Type& GEOMImpl_PrismDriver_Type_()
110 {
111
112   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
113   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
114   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
115   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); 
116   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
117   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
118  
119
120   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
121   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_PrismDriver",
122                                                          sizeof(GEOMImpl_PrismDriver),
123                                                          1,
124                                                          (Standard_Address)_Ancestors,
125                                                          (Standard_Address)NULL);
126
127   return _aType;
128 }
129
130 //=======================================================================
131 //function : DownCast
132 //purpose  :
133 //======================================================================= 
134 const Handle(GEOMImpl_PrismDriver) Handle(GEOMImpl_PrismDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
135 {
136   Handle(GEOMImpl_PrismDriver) _anOtherObject;
137
138   if (!AnObject.IsNull()) {
139      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_PrismDriver))) {
140        _anOtherObject = Handle(GEOMImpl_PrismDriver)((Handle(GEOMImpl_PrismDriver)&)AnObject);
141      }
142   }
143
144   return _anOtherObject ;
145 }