Salome HOME
PAL8395: Fix pb. with bug2extraEdges.py
[modules/geom.git] / src / GEOMImpl / GEOMImpl_BoxDriver.cxx
1
2 using namespace std;
3 #include "GEOMImpl_BoxDriver.hxx"
4 #include "GEOMImpl_IBox.hxx"
5 #include "GEOMImpl_Types.hxx"
6 #include "GEOM_Function.hxx"
7
8 #include <BRepPrimAPI_MakeBox.hxx>
9 #include <BRep_Tool.hxx>
10 #include <gp_Pnt.hxx>
11 #include <TopoDS.hxx>
12 #include <TopoDS_Shape.hxx>
13 #include <TopoDS_Vertex.hxx>
14 #include <TopAbs.hxx>
15
16 #include <StdFail_NotDone.hxx>
17
18 //=======================================================================
19 //function : GetID
20 //purpose  :
21 //=======================================================================
22 const Standard_GUID& GEOMImpl_BoxDriver::GetID()
23 {
24   static Standard_GUID aBoxDriver("FF1BBB13-5D14-4df2-980B-3A668264EA16");
25   return aBoxDriver;
26 }
27
28
29 //=======================================================================
30 //function : GEOMImpl_BoxDriver
31 //purpose  :
32 //=======================================================================
33 GEOMImpl_BoxDriver::GEOMImpl_BoxDriver()
34 {
35 }
36
37 //=======================================================================
38 //function : Execute
39 //purpose  :
40 //=======================================================================
41 Standard_Integer GEOMImpl_BoxDriver::Execute(TFunction_Logbook& log) const
42 {
43   if (Label().IsNull()) return 0;
44   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
45
46   GEOMImpl_IBox aBI (aFunction);
47   Standard_Integer aType = aFunction->GetType();
48
49   TopoDS_Shape aShape;
50
51   if (aType == BOX_DX_DY_DZ) {
52     BRepPrimAPI_MakeBox MB (aBI.GetDX(), aBI.GetDY(), aBI.GetDZ());
53     MB.Build();
54
55     if (!MB.IsDone()) {
56       StdFail_NotDone::Raise("Box with the given dimensions can not be computed");
57     }
58     aShape = MB.Shape();
59   }
60   else if (aType == BOX_TWO_PNT) {
61     Handle(GEOM_Function) aRefPoint1 = aBI.GetRef1();
62     Handle(GEOM_Function) aRefPoint2 = aBI.GetRef2();
63     TopoDS_Shape aShape1 = aRefPoint1->GetValue();
64     TopoDS_Shape aShape2 = aRefPoint2->GetValue();
65     if (aShape1.ShapeType() == TopAbs_VERTEX &&
66         aShape2.ShapeType() == TopAbs_VERTEX) {
67       gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
68       gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
69       BRepPrimAPI_MakeBox MB (P1,P2);
70       MB.Build();
71
72       if (!MB.IsDone()) {
73         StdFail_NotDone::Raise("Box can not be computed from the given point");
74       }
75       aShape = MB.Shape();
76     }
77   }
78   else {
79   }
80
81   if (aShape.IsNull()) return 0;
82
83   aFunction->SetValue(aShape);
84
85   log.SetTouched(Label());
86
87   return 1;
88 }
89
90
91 //=======================================================================
92 //function :  GEOMImpl_BoxDriver_Type_
93 //purpose  :
94 //=======================================================================
95 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BoxDriver_Type_()
96 {
97
98   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
99   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
100   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
101   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
102   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
103   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
104
105
106   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
107   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BoxDriver",
108                                                          sizeof(GEOMImpl_BoxDriver),
109                                                          1,
110                                                          (Standard_Address)_Ancestors,
111                                                          (Standard_Address)NULL);
112
113   return _aType;
114 }
115
116 //=======================================================================
117 //function : DownCast
118 //purpose  :
119 //=======================================================================
120 const Handle(GEOMImpl_BoxDriver) Handle(GEOMImpl_BoxDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
121 {
122   Handle(GEOMImpl_BoxDriver) _anOtherObject;
123
124   if (!AnObject.IsNull()) {
125      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BoxDriver))) {
126        _anOtherObject = Handle(GEOMImpl_BoxDriver)((Handle(GEOMImpl_BoxDriver)&)AnObject);
127      }
128   }
129
130   return _anOtherObject ;
131 }