0030679: Attached model hangs most of OCCT common functionality
[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>
234e52be 11#include "Standard_GUID.hxx"
12#include "TFunction_Logbook.hxx"
13#include "TDataStd_Real.hxx"
14#include "TNaming_Builder.hxx"
7fd59977 15
d7a28eda 16IMPLEMENT_STANDARD_RTTIEXT (TOcafFunction_CylDriver, TFunction_Driver)
7fd59977 17
18//=======================================================================
19//function : GetID
20//purpose :
21//=======================================================================
22
23const Standard_GUID& TOcafFunction_CylDriver::GetID() {
24 static Standard_GUID anID("22D22E53-D69A-11d4-8F1A-0060B0EE18E8");
25 return anID;
26}
27
28
29//=======================================================================
30//function : TPartStd_CylDriver
31//purpose : Creation of an instance of the driver. It's possible (and recommended)
32// : to have only one instance of a driver for the whole session.
33//=======================================================================
34
35TOcafFunction_CylDriver::TOcafFunction_CylDriver()
36{}
37
38//=======================================================================
39//function : Validate
40//purpose : Validation of the object label, its arguments and its results.
41//=======================================================================
42
f486f64d 43void TOcafFunction_CylDriver::Validate(Handle(TFunction_Logbook)& log) const
7fd59977 44{
45 // We validate the object label ( Label() ), all the arguments and the results of the object:
f486f64d 46 log->SetValid(Label(), Standard_True);
7fd59977 47}
48
49//=======================================================================
50//function : MustExecute
51//purpose : We call this method to check if the object was modified to
52// : be invoked. If the object label or an argument is modified,
53// : we must recompute the object - to call the method Execute().
54//=======================================================================
f486f64d 55Standard_Boolean TOcafFunction_CylDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
7fd59977 56{
57 // If the object's label is modified:
f486f64d 58 if (log->IsModified(Label())) return Standard_True;
7fd59977 59
60 // Cylinder (in our simple case) has 5 arguments:
61 //
62 // Let's check them:
f486f64d 63 if (log->IsModified(Label().FindChild(1))) return Standard_True; // radius.
64 if (log->IsModified(Label().FindChild(2))) return Standard_True; // height,
65 if (log->IsModified(Label().FindChild(3))) return Standard_True; // x.
66 if (log->IsModified(Label().FindChild(4))) return Standard_True; // y,
67 if (log->IsModified(Label().FindChild(5))) return Standard_True; // z.
7fd59977 68
69 // if there are no any modifications concerned the Cyl,
70 // it's not necessary to recompute (to call the method Execute()):
71 return Standard_False;
72}
73
74//=======================================================================
75//function : Execute
76//purpose :
77// : We compute the object and topologically name it.
78// : If during the execution we found something wrong,
79// : we return the number of the failure. For example:
80// : 1 - an attribute hasn't been found,
81// : 2 - algorithm failed,
82// : if there are no any mistakes occurred we return 0:
83// : 0 - no mistakes were found.
84//=======================================================================
f486f64d 85Standard_Integer TOcafFunction_CylDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
7fd59977 86{
87 // Get the values of dimension and position attributes
88 Handle(TDataStd_Real) TSR;
89 Standard_Real x,y,z,r,h;
90 if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
91 r=TSR->Get();
92
93 if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
94 h=TSR->Get();
95
96 if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
97 x=TSR->Get();
98
99 if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
100 y=TSR->Get();
101
102 if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
103 z=TSR->Get();
104
105 // Build a Cyl using the dimension and position attributes
106 BRepPrimAPI_MakeCylinder mkCyl( gp_Ax2(gp_Pnt(x, y ,z), gp_Dir(0,0,1)), r, h);
107 TopoDS_Shape ResultShape = mkCyl.Shape();
108
109
110 // Build a TNaming_NamedShape using built Cyl
111 TNaming_Builder B(Label());
112 B.Generated(ResultShape);
113// That's all:
114 // If there are no any mistakes we return 0:
115 return 0;
116}