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