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