Salome HOME
Copyrights update
[modules/geom.git] / src / GEOMImpl / GEOMImpl_BoxDriver.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20
21 #include <Standard_Stream.hxx>
22
23 #include <GEOMImpl_BoxDriver.hxx>
24 #include <GEOMImpl_IBox.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
27
28 #include <BRepPrimAPI_MakeBox.hxx>
29 #include <BRep_Tool.hxx>
30 #include <gp_Pnt.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
34 #include <TopAbs.hxx>
35
36 #include <StdFail_NotDone.hxx>
37
38 //=======================================================================
39 //function : GetID
40 //purpose  :
41 //=======================================================================
42 const Standard_GUID& GEOMImpl_BoxDriver::GetID()
43 {
44   static Standard_GUID aBoxDriver("FF1BBB13-5D14-4df2-980B-3A668264EA16");
45   return aBoxDriver;
46 }
47
48
49 //=======================================================================
50 //function : GEOMImpl_BoxDriver
51 //purpose  :
52 //=======================================================================
53 GEOMImpl_BoxDriver::GEOMImpl_BoxDriver()
54 {
55 }
56
57 //=======================================================================
58 //function : Execute
59 //purpose  :
60 //=======================================================================
61 Standard_Integer GEOMImpl_BoxDriver::Execute(TFunction_Logbook& log) const
62 {
63   if (Label().IsNull()) return 0;
64   Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
65
66   GEOMImpl_IBox aBI (aFunction);
67   Standard_Integer aType = aFunction->GetType();
68
69   TopoDS_Shape aShape;
70
71   if (aType == BOX_DX_DY_DZ) {
72     BRepPrimAPI_MakeBox MB (aBI.GetDX(), aBI.GetDY(), aBI.GetDZ());
73     MB.Build();
74
75     if (!MB.IsDone()) {
76       StdFail_NotDone::Raise("Box with the given dimensions can not be computed");
77     }
78     aShape = MB.Shape();
79   }
80   else if (aType == BOX_TWO_PNT) {
81     Handle(GEOM_Function) aRefPoint1 = aBI.GetRef1();
82     Handle(GEOM_Function) aRefPoint2 = aBI.GetRef2();
83     TopoDS_Shape aShape1 = aRefPoint1->GetValue();
84     TopoDS_Shape aShape2 = aRefPoint2->GetValue();
85     if (aShape1.ShapeType() == TopAbs_VERTEX &&
86         aShape2.ShapeType() == TopAbs_VERTEX) {
87       gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(aShape1));
88       gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(aShape2));
89       BRepPrimAPI_MakeBox MB (P1,P2);
90       MB.Build();
91
92       if (!MB.IsDone()) {
93         StdFail_NotDone::Raise("Box can not be computed from the given point");
94       }
95       aShape = MB.Shape();
96     }
97   }
98   else {
99   }
100
101   if (aShape.IsNull()) return 0;
102
103   aFunction->SetValue(aShape);
104
105   log.SetTouched(Label());
106
107   return 1;
108 }
109
110
111 //=======================================================================
112 //function :  GEOMImpl_BoxDriver_Type_
113 //purpose  :
114 //=======================================================================
115 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BoxDriver_Type_()
116 {
117
118   static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
119   if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
120   static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
121   if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
122   static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
123   if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
124
125
126   static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
127   static Handle_Standard_Type _aType = new Standard_Type("GEOMImpl_BoxDriver",
128                                                          sizeof(GEOMImpl_BoxDriver),
129                                                          1,
130                                                          (Standard_Address)_Ancestors,
131                                                          (Standard_Address)NULL);
132
133   return _aType;
134 }
135
136 //=======================================================================
137 //function : DownCast
138 //purpose  :
139 //=======================================================================
140 const Handle(GEOMImpl_BoxDriver) Handle(GEOMImpl_BoxDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
141 {
142   Handle(GEOMImpl_BoxDriver) _anOtherObject;
143
144   if (!AnObject.IsNull()) {
145      if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BoxDriver))) {
146        _anOtherObject = Handle(GEOMImpl_BoxDriver)((Handle(GEOMImpl_BoxDriver)&)AnObject);
147      }
148   }
149
150   return _anOtherObject ;
151 }