1 // File: TOcafFunction_CylDriver.cxx
2 // Created: Mon Dec 27 10:37:13 1999
3 // Author: Vladislav ROMASHKO
4 // <vro@flox.nnov.matra-dtv.fr>
8 #include <TOcafFunction_CylDriver.hxx>
9 #include <TCollection_AsciiString.hxx>
10 #include <TDF_Tool.hxx>
11 #include "Standard_GUID.hxx"
12 #include "TFunction_Logbook.hxx"
13 #include "TDataStd_Real.hxx"
14 #include "TNaming_Builder.hxx"
17 //=======================================================================
20 //=======================================================================
22 const Standard_GUID& TOcafFunction_CylDriver::GetID() {
23 static Standard_GUID anID("22D22E53-D69A-11d4-8F1A-0060B0EE18E8");
28 //=======================================================================
29 //function : TPartStd_CylDriver
30 //purpose : Creation of an instance of the driver. It's possible (and recommended)
31 // : to have only one instance of a driver for the whole session.
32 //=======================================================================
34 TOcafFunction_CylDriver::TOcafFunction_CylDriver()
37 //=======================================================================
39 //purpose : Validation of the object label, its arguments and its results.
40 //=======================================================================
42 void TOcafFunction_CylDriver::Validate(Handle(TFunction_Logbook)& log) const
44 // We validate the object label ( Label() ), all the arguments and the results of the object:
45 log->SetValid(Label(), Standard_True);
48 //=======================================================================
49 //function : MustExecute
50 //purpose : We call this method to check if the object was modified to
51 // : be invoked. If the object label or an argument is modified,
52 // : we must recompute the object - to call the method Execute().
53 //=======================================================================
54 Standard_Boolean TOcafFunction_CylDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
56 // If the object's label is modified:
57 if (log->IsModified(Label())) return Standard_True;
59 // Cylinder (in our simple case) has 5 arguments:
62 if (log->IsModified(Label().FindChild(1))) return Standard_True; // radius.
63 if (log->IsModified(Label().FindChild(2))) return Standard_True; // height,
64 if (log->IsModified(Label().FindChild(3))) return Standard_True; // x.
65 if (log->IsModified(Label().FindChild(4))) return Standard_True; // y,
66 if (log->IsModified(Label().FindChild(5))) return Standard_True; // z.
68 // if there are no any modifications concerned the Cyl,
69 // it's not necessary to recompute (to call the method Execute()):
70 return Standard_False;
73 //=======================================================================
76 // : We compute the object and topologically name it.
77 // : If during the execution we found something wrong,
78 // : we return the number of the failure. For example:
79 // : 1 - an attribute hasn't been found,
80 // : 2 - algorithm failed,
81 // : if there are no any mistakes occurred we return 0:
82 // : 0 - no mistakes were found.
83 //=======================================================================
84 Standard_Integer TOcafFunction_CylDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
86 // Get the values of dimension and position attributes
87 Handle(TDataStd_Real) TSR;
88 Standard_Real x,y,z,r,h;
89 if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
92 if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
95 if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
98 if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
101 if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
104 // Build a Cyl using the dimension and position attributes
105 BRepPrimAPI_MakeCylinder mkCyl( gp_Ax2(gp_Pnt(x, y ,z), gp_Dir(0,0,1)), r, h);
106 TopoDS_Shape ResultShape = mkCyl.Shape();
109 // Build a TNaming_NamedShape using built Cyl
110 TNaming_Builder B(Label());
111 B.Generated(ResultShape);
113 // If there are no any mistakes we return 0:
117 TOcafFunction_CylDriver::~TOcafFunction_CylDriver() {}
120 // allow safe downcasting
122 const Handle(TOcafFunction_CylDriver) TOcafFunction_CylDriver::DownCast(const Handle(Standard_Transient)& AnObject)
124 Handle(TOcafFunction_CylDriver) _anOtherObject;
126 if (!AnObject.IsNull()) {
127 if (AnObject->IsKind(STANDARD_TYPE(TOcafFunction_CylDriver))) {
128 _anOtherObject = Handle(TOcafFunction_CylDriver)::DownCast (AnObject);
132 return _anOtherObject ;
134 const Handle(Standard_Type)& TOcafFunction_CylDriver::DynamicType() const
136 return STANDARD_TYPE(TOcafFunction_CylDriver) ;
138 Standard_Boolean TOcafFunction_CylDriver::IsKind(const Handle(Standard_Type)& AType) const
140 return (STANDARD_TYPE(TOcafFunction_CylDriver) == AType || TFunction_Driver::IsKind(AType));