46b425bee44a89be3eedc24f25f7cf7730672be5
[occt.git] / samples / qt / FuncDemo / src / SimpleDriver.cpp
1 // SimpleDriver.cpp: implementation of the SimpleDriver class.
2 //
3 //////////////////////////////////////////////////////////////////////
4
5 #include "SimpleDriver.h"
6
7 #include <TDF_Reference.hxx>
8 #include <TDF_ChildIterator.hxx>
9 #include <Standard_GUID.hxx>
10 #include <OSD_Timer.hxx>
11 #include <TDataStd_Real.hxx>
12 #include <BRepPrimAPI_MakeSphere.hxx>
13
14 IMPLEMENT_STANDARD_HANDLE(SimpleDriver,  TFunction_Driver)
15 IMPLEMENT_STANDARD_RTTIEXT(SimpleDriver, TFunction_Driver)
16
17 // ID of the function driver
18 const Standard_GUID& SimpleDriver::GetID()
19 {
20     static const Standard_GUID id("4534840D-6DCD-440f-9F0E-BDEF1C50D434");
21     return id;
22 }
23
24 // Constructor
25 SimpleDriver::SimpleDriver()
26 {
27
28 }
29
30 // Returns the arguments of the function
31 void SimpleDriver::Arguments(TDF_LabelList& args) const
32 {
33     // A double - relative time of execution
34     args.Append(Label());
35
36     // References to other functions through TDF_Reference
37     TDF_ChildIterator itr(Label().FindChild(1), false);
38     for (; itr.More(); itr.Next())
39     {
40         Handle(TDF_Reference) ref;
41         if (itr.Value().FindAttribute(TDF_Reference::GetID(), ref))
42             args.Append(ref->Get());
43     }
44 }
45
46
47 // Returns the results of the function
48 void SimpleDriver::Results(TDF_LabelList& res) const
49 {
50     // References to other functions through TDF_Reference
51     res.Append(Label());
52     TDF_ChildIterator itr(Label().FindChild(2), false);
53     for (; itr.More(); itr.Next())
54     {
55         Handle(TDF_Reference) ref;
56         if (itr.Value().FindAttribute(TDF_Reference::GetID(), ref))
57             res.Append(ref->Get());
58     }
59 }
60
61 // Execution.
62 Standard_Integer SimpleDriver::Execute(Handle(TFunction_Logbook)& ) const
63 {
64         // Check initialization
65         if (Label().IsNull())
66                 return 1;
67
68     // Take the double argument
69     Handle(TDataStd_Real) time_keeper;
70     if (!Label().FindAttribute(TDataStd_Real::GetID(), time_keeper))
71         return 2;
72     double times = time_keeper->Get();
73
74     // Make a sphere 10000 * "times" times (it takes about a second on a simple computer).
75     int i = 0;
76     while (++i < 10000 * times)
77     {
78         // Call any functions taking much time.
79         // It is necessary to "see" the execution of a function in real time.
80         BRepPrimAPI_MakeSphere mkSphere(100.0);
81         mkSphere.Build();
82     }
83
84     return 0;
85 }