7fd59977 |
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> |
234e52be |
11 | #include "Standard_GUID.hxx" |
12 | #include "TFunction_Logbook.hxx" |
13 | #include "TDataStd_Real.hxx" |
14 | #include "TNaming_Builder.hxx" |
7fd59977 |
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(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 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(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 | |
120 | |
121 | Standard_EXPORT Handle_Standard_Type& TOcafFunction_CylDriver_Type_() |
122 | { |
123 | |
124 | static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver); |
125 | if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver); |
126 | static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared); |
127 | if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared); |
128 | static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient); |
129 | if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient); |
130 | |
131 | |
132 | static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL}; |
133 | static Handle_Standard_Type _aType = new Standard_Type("TOcafFunction_CylDriver", |
134 | sizeof(TOcafFunction_CylDriver), |
135 | 1, |
136 | (Standard_Address)_Ancestors, |
137 | (Standard_Address)NULL); |
138 | |
139 | return _aType; |
140 | } |
141 | |
142 | |
143 | // DownCast method |
144 | // allow safe downcasting |
145 | // |
146 | const Handle(TOcafFunction_CylDriver) Handle(TOcafFunction_CylDriver)::DownCast(const Handle(Standard_Transient)& AnObject) |
147 | { |
148 | Handle(TOcafFunction_CylDriver) _anOtherObject; |
149 | |
150 | if (!AnObject.IsNull()) { |
151 | if (AnObject->IsKind(STANDARD_TYPE(TOcafFunction_CylDriver))) { |
152 | _anOtherObject = Handle(TOcafFunction_CylDriver)((Handle(TOcafFunction_CylDriver)&)AnObject); |
153 | } |
154 | } |
155 | |
156 | return _anOtherObject ; |
157 | } |
158 | const Handle(Standard_Type)& TOcafFunction_CylDriver::DynamicType() const |
159 | { |
160 | return STANDARD_TYPE(TOcafFunction_CylDriver) ; |
161 | } |
162 | Standard_Boolean TOcafFunction_CylDriver::IsKind(const Handle(Standard_Type)& AType) const |
163 | { |
164 | return (STANDARD_TYPE(TOcafFunction_CylDriver) == AType || TFunction_Driver::IsKind(AType)); |
165 | } |
166 | |
167 | Handle_TOcafFunction_CylDriver::~Handle_TOcafFunction_CylDriver() {} |
168 | |
169 | |