0028225: MFC sample on OCAF uses old-style definition of a Handle-class
[occt.git] / samples / mfc / standard / 06_Ocaf / src / TOcafFunction_BoxDriver.cxx
CommitLineData
7fd59977 1// File: TOcafFunction_BoxDriver.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_BoxDriver.hxx>
234e52be 9#include "Standard_GUID.hxx"
10#include "TFunction_Logbook.hxx"
11#include "TDataStd_Real.hxx"
12#include "BRepPrimAPI_MakeBox.hxx"
13#include "TNaming_Builder.hxx"
7fd59977 14
d7a28eda 15IMPLEMENT_STANDARD_RTTIEXT (TOcafFunction_BoxDriver, TFunction_Driver)
16
7fd59977 17//=======================================================================
18//function : GetID
19//purpose :
20//=======================================================================
21
22const Standard_GUID& TOcafFunction_BoxDriver::GetID() {
23 static Standard_GUID anID("22D22E51-D69A-11d4-8F1A-0060B0EE18E8");
24 return anID;
25}
26
27
28//=======================================================================
29//function : TPartStd_BoxDriver
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
34TOcafFunction_BoxDriver::TOcafFunction_BoxDriver()
35{}
36
37//=======================================================================
38//function : Validate
39//purpose : Validation of the object label, its arguments and its results.
40//=======================================================================
41
f486f64d 42void TOcafFunction_BoxDriver::Validate(Handle(TFunction_Logbook)& log) const
7fd59977 43{
44 // We validate the object label ( Label() ), all the arguments and the results of the object:
f486f64d 45 log->SetValid(Label(), Standard_True);
7fd59977 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//=======================================================================
f486f64d 54Standard_Boolean TOcafFunction_BoxDriver::MustExecute(const Handle(TFunction_Logbook)& log) const
7fd59977 55{
56 // If the object's label is modified:
f486f64d 57 if (log->IsModified(Label())) return Standard_True;
7fd59977 58
59 // Cut (in our simple case) has two arguments: The original shape, and the tool shape.
60 // They are on the child labels of the box's label:
61 // So, OriginalNShape - is attached to the first child label
62 // ToolNShape - is attached to the second child label.
63 //
64 // Let's check them:
f486f64d 65 if (log->IsModified(Label().FindChild(1))) return Standard_True; // width.
66 if (log->IsModified(Label().FindChild(2))) return Standard_True; // length,
67 if (log->IsModified(Label().FindChild(3))) return Standard_True; // width.
68 if (log->IsModified(Label().FindChild(4))) return Standard_True; // length,
69 if (log->IsModified(Label().FindChild(5))) return Standard_True; // width.
70 if (log->IsModified(Label().FindChild(6))) return Standard_True; // length,
7fd59977 71
72 // if there are no any modifications concerned the box,
73 // it's not necessary to recompute (to call the method Execute()):
74 return Standard_False;
75}
76
77//=======================================================================
78//function : Execute
79//purpose :
80// : We compute the object and topologically name it.
81// : If during the execution we found something wrong,
82// : we return the number of the failure. For example:
83// : 1 - an attribute hasn't been found,
84// : 2 - algorithm failed,
85// : if there are no any mistakes occurred we return 0:
86// : 0 - no mistakes were found.
87//=======================================================================
f486f64d 88Standard_Integer TOcafFunction_BoxDriver::Execute(Handle(TFunction_Logbook)& /*log*/) const
7fd59977 89{
90 // Get the values of dimension and position attributes
91 Handle(TDataStd_Real) TSR;
92 Standard_Real x,y,z,l,h,w;
93 if (!Label().FindChild(1).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
94 l=TSR->Get();
95
96 if (!Label().FindChild(2).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
97 h=TSR->Get();
98
99 if (!Label().FindChild(3).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
100 w=TSR->Get();
101
102 if (!Label().FindChild(4).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
103 x=TSR->Get();
104
105 if (!Label().FindChild(5).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
106 y=TSR->Get();
107
108 if (!Label().FindChild(6).FindAttribute(TDataStd_Real::GetID(), TSR )) return 1;
109 z=TSR->Get();
110
111 // Build a box using the dimension and position attributes
112 BRepPrimAPI_MakeBox mkBox( gp_Pnt(x, y ,z), l, h ,w);
113 TopoDS_Shape ResultShape = mkBox.Shape();
114
115
116 // Build a TNaming_NamedShape using built box
117 TNaming_Builder B(Label());
118 B.Generated(ResultShape);
119// That's all:
120 // If there are no any mistakes we return 0:
121 return 0;
122}