1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include <Standard_Stream.hxx>
23 #include <GEOMImpl_BoxDriver.hxx>
24 #include <GEOMImpl_IBox.hxx>
25 #include <GEOMImpl_Types.hxx>
26 #include <GEOM_Function.hxx>
28 #include <BRepPrimAPI_MakeBox.hxx>
29 #include <BRep_Tool.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopoDS_Vertex.hxx>
36 #include <StdFail_NotDone.hxx>
38 //=======================================================================
41 //=======================================================================
42 const Standard_GUID& GEOMImpl_BoxDriver::GetID()
44 static Standard_GUID aBoxDriver("FF1BBB13-5D14-4df2-980B-3A668264EA16");
49 //=======================================================================
50 //function : GEOMImpl_BoxDriver
52 //=======================================================================
53 GEOMImpl_BoxDriver::GEOMImpl_BoxDriver()
57 //=======================================================================
60 //=======================================================================
61 Standard_Integer GEOMImpl_BoxDriver::Execute(TFunction_Logbook& log) const
63 if (Label().IsNull()) return 0;
64 Handle(GEOM_Function) aFunction = GEOM_Function::GetFunction(Label());
66 GEOMImpl_IBox aBI (aFunction);
67 Standard_Integer aType = aFunction->GetType();
71 if (aType == BOX_DX_DY_DZ) {
72 BRepPrimAPI_MakeBox MB (aBI.GetDX(), aBI.GetDY(), aBI.GetDZ());
76 StdFail_NotDone::Raise("Box with the given dimensions can not be computed");
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);
93 StdFail_NotDone::Raise("Box can not be computed from the given point");
101 if (aShape.IsNull()) return 0;
103 aFunction->SetValue(aShape);
105 log.SetTouched(Label());
111 //=======================================================================
112 //function : GEOMImpl_BoxDriver_Type_
114 //=======================================================================
115 Standard_EXPORT Handle_Standard_Type& GEOMImpl_BoxDriver_Type_()
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);
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),
130 (Standard_Address)_Ancestors,
131 (Standard_Address)NULL);
136 //=======================================================================
137 //function : DownCast
139 //=======================================================================
140 const Handle(GEOMImpl_BoxDriver) Handle(GEOMImpl_BoxDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
142 Handle(GEOMImpl_BoxDriver) _anOtherObject;
144 if (!AnObject.IsNull()) {
145 if (AnObject->IsKind(STANDARD_TYPE(GEOMImpl_BoxDriver))) {
146 _anOtherObject = Handle(GEOMImpl_BoxDriver)((Handle(GEOMImpl_BoxDriver)&)AnObject);
150 return _anOtherObject ;