1 // File: TOcafFunction_BoxDriver.cxx
2 // Created: Mon Dec 27 10:37:13 1999
3 // Author: Vladislav ROMASHKO
4 // <vro@flox.nnov.matra-dtv.fr>
8 #include <TOcafFunction_BoxDriver.hxx>
9 #include "Standard_GUID.hxx"
10 #include "TFunction_Logbook.hxx"
11 #include "TDataStd_Real.hxx"
12 #include "BRepPrimAPI_MakeBox.hxx"
13 #include "TNaming_Builder.hxx"
15 //=======================================================================
18 //=======================================================================
20 const Standard_GUID& TOcafFunction_BoxDriver::GetID() {
21 static Standard_GUID anID("22D22E51-D69A-11d4-8F1A-0060B0EE18E8");
26 //=======================================================================
27 //function : TPartStd_BoxDriver
28 //purpose : Creation of an instance of the driver. It's possible (and recommended)
29 // : to have only one instance of a driver for the whole session.
30 //=======================================================================
32 TOcafFunction_BoxDriver::TOcafFunction_BoxDriver()
35 //=======================================================================
37 //purpose : Validation of the object label, its arguments and its results.
38 //=======================================================================
40 void TOcafFunction_BoxDriver::Validate(TFunction_Logbook& log) const
42 // We validate the object label ( Label() ), all the arguments and the results of the object:
43 log.SetValid(Label(), Standard_True);
46 //=======================================================================
47 //function : MustExecute
48 //purpose : We call this method to check if the object was modified to
49 // : be invoked. If the object label or an argument is modified,
50 // : we must recompute the object - to call the method Execute().
51 //=======================================================================
52 Standard_Boolean TOcafFunction_BoxDriver::MustExecute(const TFunction_Logbook& log) const
54 // If the object's label is modified:
55 if (log.IsModified(Label())) return Standard_True;
57 // Cut (in our simple case) has two arguments: The original shape, and the tool shape.
58 // They are on the child labels of the box's label:
59 // So, OriginalNShape - is attached to the first child label
60 // ToolNShape - is attached to the second child label.
63 if (log.IsModified(Label().FindChild(1))) return Standard_True; // width.
64 if (log.IsModified(Label().FindChild(2))) return Standard_True; // length,
65 if (log.IsModified(Label().FindChild(3))) return Standard_True; // width.
66 if (log.IsModified(Label().FindChild(4))) return Standard_True; // length,
67 if (log.IsModified(Label().FindChild(5))) return Standard_True; // width.
68 if (log.IsModified(Label().FindChild(6))) return Standard_True; // length,
70 // if there are no any modifications concerned the box,
71 // it's not necessary to recompute (to call the method Execute()):
72 return Standard_False;
75 //=======================================================================
78 // : We compute the object and topologically name it.
79 // : If during the execution we found something wrong,
80 // : we return the number of the failure. For example:
81 // : 1 - an attribute hasn't been found,
82 // : 2 - algorithm failed,
83 // : if there are no any mistakes occurred we return 0:
84 // : 0 - no mistakes were found.
85 //=======================================================================
86 Standard_Integer TOcafFunction_BoxDriver::Execute(TFunction_Logbook& /*log*/) const
88 // Get the values of dimension and position attributes
89 Handle(TDataStd_Real) TSR;
90 Standard_Real x,y,z,l,h,w;
91 if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
94 if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
97 if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
100 if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
103 if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
106 if (!Label().FindChild(6).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
109 // Build a box using the dimension and position attributes
110 BRepPrimAPI_MakeBox mkBox( gp_Pnt(x, y ,z), l, h ,w);
111 TopoDS_Shape ResultShape = mkBox.Shape();
114 // Build a TNaming_NamedShape using built box
115 TNaming_Builder B(Label());
116 B.Generated(ResultShape);
118 // If there are no any mistakes we return 0:
122 TOcafFunction_BoxDriver::~TOcafFunction_BoxDriver() {}
126 Standard_EXPORT Handle_Standard_Type& TOcafFunction_BoxDriver_Type_()
129 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
130 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
131 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
132 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
133 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
134 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
137 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
138 static Handle_Standard_Type _aType = new Standard_Type("TOcafFunction_BoxDriver",
139 sizeof(TOcafFunction_BoxDriver),
141 (Standard_Address)_Ancestors,
142 (Standard_Address)NULL);
149 // allow safe downcasting
151 const Handle(TOcafFunction_BoxDriver) Handle(TOcafFunction_BoxDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
153 Handle(TOcafFunction_BoxDriver) _anOtherObject;
155 if (!AnObject.IsNull()) {
156 if (AnObject->IsKind(STANDARD_TYPE(TOcafFunction_BoxDriver))) {
157 _anOtherObject = Handle(TOcafFunction_BoxDriver)((Handle(TOcafFunction_BoxDriver)&)AnObject);
161 return _anOtherObject ;
163 const Handle(Standard_Type)& TOcafFunction_BoxDriver::DynamicType() const
165 return STANDARD_TYPE(TOcafFunction_BoxDriver) ;
167 Standard_Boolean TOcafFunction_BoxDriver::IsKind(const Handle(Standard_Type)& AType) const
169 return (STANDARD_TYPE(TOcafFunction_BoxDriver) == AType || TFunction_Driver::IsKind(AType));
172 Handle_TOcafFunction_BoxDriver::~Handle_TOcafFunction_BoxDriver() {}