Integration of OCCT 6.5.0 from SVN
[occt.git] / samples / mfc / standard / 06_Ocaf / src / TOcafFunction_CylDriver.cxx
CommitLineData
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>
11
12
13//=======================================================================
14//function : GetID
15//purpose :
16//=======================================================================
17
18const Standard_GUID& TOcafFunction_CylDriver::GetID() {
19 static Standard_GUID anID("22D22E53-D69A-11d4-8F1A-0060B0EE18E8");
20 return anID;
21}
22
23
24//=======================================================================
25//function : TPartStd_CylDriver
26//purpose : Creation of an instance of the driver. It's possible (and recommended)
27// : to have only one instance of a driver for the whole session.
28//=======================================================================
29
30TOcafFunction_CylDriver::TOcafFunction_CylDriver()
31{}
32
33//=======================================================================
34//function : Validate
35//purpose : Validation of the object label, its arguments and its results.
36//=======================================================================
37
38void TOcafFunction_CylDriver::Validate(TFunction_Logbook& log) const
39{
40 // We validate the object label ( Label() ), all the arguments and the results of the object:
41 log.SetValid(Label(), Standard_True);
42}
43
44//=======================================================================
45//function : MustExecute
46//purpose : We call this method to check if the object was modified to
47// : be invoked. If the object label or an argument is modified,
48// : we must recompute the object - to call the method Execute().
49//=======================================================================
50Standard_Boolean TOcafFunction_CylDriver::MustExecute(const TFunction_Logbook& log) const
51{
52 // If the object's label is modified:
53 if (log.IsModified(Label())) return Standard_True;
54
55 // Cylinder (in our simple case) has 5 arguments:
56 //
57 // Let's check them:
58 if (log.IsModified(Label().FindChild(1))) return Standard_True; // radius.
59 if (log.IsModified(Label().FindChild(2))) return Standard_True; // height,
60 if (log.IsModified(Label().FindChild(3))) return Standard_True; // x.
61 if (log.IsModified(Label().FindChild(4))) return Standard_True; // y,
62 if (log.IsModified(Label().FindChild(5))) return Standard_True; // z.
63
64 // if there are no any modifications concerned the Cyl,
65 // it's not necessary to recompute (to call the method Execute()):
66 return Standard_False;
67}
68
69//=======================================================================
70//function : Execute
71//purpose :
72// : We compute the object and topologically name it.
73// : If during the execution we found something wrong,
74// : we return the number of the failure. For example:
75// : 1 - an attribute hasn't been found,
76// : 2 - algorithm failed,
77// : if there are no any mistakes occurred we return 0:
78// : 0 - no mistakes were found.
79//=======================================================================
80Standard_Integer TOcafFunction_CylDriver::Execute(TFunction_Logbook& log) const
81{
82 // Get the values of dimension and position attributes
83 Handle(TDataStd_Real) TSR;
84 Standard_Real x,y,z,r,h;
85 if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
86 r=TSR->Get();
87
88 if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
89 h=TSR->Get();
90
91 if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
92 x=TSR->Get();
93
94 if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
95 y=TSR->Get();
96
97 if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
98 z=TSR->Get();
99
100 // Build a Cyl using the dimension and position attributes
101 BRepPrimAPI_MakeCylinder mkCyl( gp_Ax2(gp_Pnt(x, y ,z), gp_Dir(0,0,1)), r, h);
102 TopoDS_Shape ResultShape = mkCyl.Shape();
103
104
105 // Build a TNaming_NamedShape using built Cyl
106 TNaming_Builder B(Label());
107 B.Generated(ResultShape);
108// That's all:
109 // If there are no any mistakes we return 0:
110 return 0;
111}
112
113TOcafFunction_CylDriver::~TOcafFunction_CylDriver() {}
114
115
116
117Standard_EXPORT Handle_Standard_Type& TOcafFunction_CylDriver_Type_()
118{
119
120 static Handle_Standard_Type aType1 = STANDARD_TYPE(TFunction_Driver);
121 if ( aType1.IsNull()) aType1 = STANDARD_TYPE(TFunction_Driver);
122 static Handle_Standard_Type aType2 = STANDARD_TYPE(MMgt_TShared);
123 if ( aType2.IsNull()) aType2 = STANDARD_TYPE(MMgt_TShared);
124 static Handle_Standard_Type aType3 = STANDARD_TYPE(Standard_Transient);
125 if ( aType3.IsNull()) aType3 = STANDARD_TYPE(Standard_Transient);
126
127
128 static Handle_Standard_Transient _Ancestors[]= {aType1,aType2,aType3,NULL};
129 static Handle_Standard_Type _aType = new Standard_Type("TOcafFunction_CylDriver",
130 sizeof(TOcafFunction_CylDriver),
131 1,
132 (Standard_Address)_Ancestors,
133 (Standard_Address)NULL);
134
135 return _aType;
136}
137
138
139// DownCast method
140// allow safe downcasting
141//
142const Handle(TOcafFunction_CylDriver) Handle(TOcafFunction_CylDriver)::DownCast(const Handle(Standard_Transient)& AnObject)
143{
144 Handle(TOcafFunction_CylDriver) _anOtherObject;
145
146 if (!AnObject.IsNull()) {
147 if (AnObject->IsKind(STANDARD_TYPE(TOcafFunction_CylDriver))) {
148 _anOtherObject = Handle(TOcafFunction_CylDriver)((Handle(TOcafFunction_CylDriver)&)AnObject);
149 }
150 }
151
152 return _anOtherObject ;
153}
154const Handle(Standard_Type)& TOcafFunction_CylDriver::DynamicType() const
155{
156 return STANDARD_TYPE(TOcafFunction_CylDriver) ;
157}
158Standard_Boolean TOcafFunction_CylDriver::IsKind(const Handle(Standard_Type)& AType) const
159{
160 return (STANDARD_TYPE(TOcafFunction_CylDriver) == AType || TFunction_Driver::IsKind(AType));
161}
162
163Handle_TOcafFunction_CylDriver::~Handle_TOcafFunction_CylDriver() {}
164
165