fb2ef18813d11cb2ae6e8515c3d191132c9aa8b6
[occt.git] / samples / mfc / standard / 06_Ocaf / src / TOcafFunction_CylDriver.cxx
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>
5
6
7 #include <stdafx.h>
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"
15
16
17 //=======================================================================
18 //function : GetID
19 //purpose  :
20 //=======================================================================
21
22 const Standard_GUID& TOcafFunction_CylDriver::GetID() {
23   static Standard_GUID anID("22D22E53-D69A-11d4-8F1A-0060B0EE18E8");
24   return anID;
25 }
26
27
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 //=======================================================================
33
34 TOcafFunction_CylDriver::TOcafFunction_CylDriver()
35 {}
36
37 //=======================================================================
38 //function : Validate
39 //purpose  : Validation of the object label, its arguments and its results.
40 //=======================================================================
41
42 void TOcafFunction_CylDriver::Validate(Handle(TFunction_Logbook)& log) const
43 {
44   // We validate the object label ( Label() ), all the arguments and the results of the object:
45   log->SetValid(Label(), Standard_True);
46 }
47
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
55 {
56         // If the object's label is modified:
57   if (log->IsModified(Label())) return Standard_True; 
58
59   // Cylinder (in our simple case) has 5 arguments: 
60   // 
61   // Let's check them:
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.
67   
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;
71 }
72
73 //=======================================================================
74 //function : Execute
75 //purpose  : 
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
85 {
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;
90         r=TSR->Get();
91
92         if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
93         h=TSR->Get();
94
95         if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
96         x=TSR->Get();
97
98         if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
99         y=TSR->Get();
100
101         if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
102         z=TSR->Get();
103
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();
107
108
109         // Build a TNaming_NamedShape using built Cyl
110         TNaming_Builder B(Label());
111         B.Generated(ResultShape);
112 // That's all:
113   // If there are no any mistakes we return 0:
114   return 0;
115 }
116
117 TOcafFunction_CylDriver::~TOcafFunction_CylDriver() {}
118  
119 // DownCast method
120 //   allow safe downcasting
121 //
122 const Handle(TOcafFunction_CylDriver) TOcafFunction_CylDriver::DownCast(const Handle(Standard_Transient)& AnObject) 
123 {
124   Handle(TOcafFunction_CylDriver) _anOtherObject;
125
126   if (!AnObject.IsNull()) {
127      if (AnObject->IsKind(STANDARD_TYPE(TOcafFunction_CylDriver))) {
128        _anOtherObject = Handle(TOcafFunction_CylDriver)::DownCast (AnObject);
129      }
130   }
131
132   return _anOtherObject ;
133 }
134 const Handle(Standard_Type)& TOcafFunction_CylDriver::DynamicType() const 
135
136   return STANDARD_TYPE(TOcafFunction_CylDriver) ; 
137 }
138 Standard_Boolean TOcafFunction_CylDriver::IsKind(const Handle(Standard_Type)& AType) const 
139
140   return (STANDARD_TYPE(TOcafFunction_CylDriver) == AType || TFunction_Driver::IsKind(AType)); 
141 }
142
143
144