25749069fcaff3a1ac20727ab3331e7e63337ff5
[occt.git] / samples / qt / FuncDemo / src / mainwindow.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2004-2007 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the example classes of the Qt Toolkit.
6 **
7 ** Licensees holding a valid Qt License Agreement may use this file in
8 ** accordance with the rights, responsibilities and obligations
9 ** contained therein.  Please consult your licensing agreement or
10 ** contact sales@trolltech.com if any conditions of this licensing
11 ** agreement are not clear to you.
12 **
13 ** Further information about Qt licensing is available at:
14 ** http://www.trolltech.com/products/qt/licensing.html or by
15 ** contacting info@trolltech.com.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ****************************************************************************/
21
22 #include <QtGui>
23 #include <QtGlobal>
24 #if QT_VERSION > QT_VERSION_CHECK(5, 0, 0)
25 #include <QtWidgets>
26 #endif
27
28 #include "mainwindow.h"
29 #include "graphwidget.h"
30 #include "node.h"
31 #include "edge.h"
32
33 #include "SimpleDriver.h"
34 #include "PointDriver.h"
35 #include "CircleDriver.h"
36 #include "PrismDriver.h"
37 #include "ConeDriver.h"
38 #include "CylinderDriver.h"
39 #include "ShapeSaverDriver.h"
40
41 #include <TDocStd_Document.hxx>
42 #include <TFunction_DriverTable.hxx>
43 #include <TFunction_IFunction.hxx>
44 #include <TFunction_GraphNode.hxx>
45 #include <TFunction_DoubleMapOfIntegerLabel.hxx>
46 #include <TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel.hxx>
47 #include <TFunction_Scope.hxx>
48
49 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
50 #include <OSD_Timer.hxx>
51
52 #include <TDF_Tool.hxx>
53 #include <TDF_Reference.hxx>
54 #include <TDF_MapIteratorOfLabelMap.hxx>
55 #include <TDF_ListIteratorOfLabelList.hxx>
56 #include <TDF_ChildIterator.hxx>
57
58 #include <TDataStd_Name.hxx>
59 #include <TDataStd_Real.hxx>
60 #include <TDataStd_RealArray.hxx>
61 #ifdef __GNUC__
62 #include <unistd.h>
63 #endif
64
65 MainWindow::MainWindow()
66 {
67     graph = new GraphWidget(this);
68     setCentralWidget(graph);
69
70     createActions();
71     createMenus();
72     createToolBars();
73     createStatusBar();
74
75     // Create a new document
76     createDefaultModel1();
77 }
78
79 Handle(AppStd_Application) MainWindow::getApplication()
80 {
81     if (gApplication.IsNull())
82         gApplication = new AppStd_Application();
83     return gApplication;
84 }
85
86 void MainWindow::closeEvent(QCloseEvent *event)
87 {
88     event->accept();
89 }
90
91 void MainWindow::model1()
92 {
93     // Clean the view
94     if (!graph->getDocument().IsNull())
95     {
96         QList<QGraphicsItem*> items = graph->scene()->items();
97         for (int i = 0; i < items.size(); i++)
98         {
99             QGraphicsItem* item = items.at(i);
100             graph->scene()->removeItem(item);
101         }
102     
103         // Close the document
104         getApplication()->Close(graph->getDocument());
105     }
106
107     // Create a new document
108     createDefaultModel1();
109 }
110
111 void MainWindow::model2()
112 {
113     // Clean the view
114     if (!graph->getDocument().IsNull())
115     {
116         QList<QGraphicsItem*> items = graph->scene()->items();
117         for (int i = 0; i < items.size(); i++)
118         {
119             QGraphicsItem* item = items.at(i);
120             graph->scene()->removeItem(item);
121         }
122     
123         // Close the document
124         getApplication()->Close(graph->getDocument());
125     }
126
127     // Create a new document
128     createDefaultModel2();
129 }
130
131 static void prepareFunctions(GraphWidget* graph)
132 {
133     if (!graph->getDocument().IsNull())
134     {
135         TDF_Label L = graph->getDocument()->Main().Root();
136         TDF_ChildIterator itr(L, true);
137         for (; itr.More(); itr.Next())
138         {
139             Handle(TFunction_GraphNode) G;
140             if (itr.Value().FindAttribute(TFunction_GraphNode::GetID(), G))
141             {
142                 G->SetStatus(TFunction_ES_NotExecuted);
143             }
144         }
145     }
146 }
147
148 // Redraw the nodes (change their colour).            
149 void MainWindow::redrawGraph()
150 {
151     QList<QGraphicsItem*> items = graph->scene()->items();
152     for (int i = 0; i < items.size(); i++)
153     {
154         QGraphicsItem* item = items.at(i);
155         item->update();
156     }
157 }
158
159 void MainWindow::compute()
160 {
161     OSD_Timer aTimer;
162     double seconds, CPUTime;
163     int hours, minutes;
164     aTimer.Start();
165
166     int i = 0, nb = 1; // number of repetitions (for test-purpose).
167
168     // Run computation
169     while (i++ < nb)
170     {
171         prepareFunctions(graph);
172         graph->compute();
173
174         while (!graph->isFinished())
175         {
176             // Redraw the nodes (change their colour).            
177             redrawGraph();
178
179             // Process user-events.
180             qApp->processEvents();
181             #ifdef __GNUC__
182                sleep(0.001);
183             #else
184                ::Sleep(100);
185             #endif
186         }
187     }
188
189     aTimer.Show(seconds, minutes, hours, CPUTime);
190     cout << "Execution of "<<graph->getNbThreads()<< " threads took          " << hours << " hours, " << minutes << " minutes, " << seconds << " seconds" << endl;
191
192     // Redraw the nodes (change their colour).            
193     redrawGraph();
194 }
195
196 void MainWindow::nbThreads()
197 {
198     bool ok;
199     int nb = QInputDialog::getInt(this, tr("Number of threads"), tr("(1 - 4): "),
200                                       graph->getNbThreads(), 1, 4, 1, &ok);
201     if (ok)
202         graph->setNbThreads(nb);
203 }
204
205 void MainWindow::about()
206 {
207    QMessageBox::about(this, tr("Test-application of the advanced Function Mechanism"),
208                       tr("The <b>Application</b> runs different models "
209                       "in single and multi-threaded modes. "
210                       "It shows graphically the result of computation."));
211 }
212
213 void MainWindow::createActions()
214 {
215     model1Act = new QAction(QIcon("images/open.png"), tr("Model 1"), this);
216     model1Act->setStatusTip(tr("Model 1"));
217     connect(model1Act, SIGNAL(triggered()), this, SLOT(model1()));
218
219     model2Act = new QAction(QIcon("images/open.png"), tr("Model 2"), this);
220     model2Act->setStatusTip(tr("Model 2"));
221     connect(model2Act, SIGNAL(triggered()), this, SLOT(model2()));
222
223     computeAct = new QAction(QIcon("images/new.png"), tr("Compute"), this);
224     computeAct->setStatusTip(tr("Compute"));
225     connect(computeAct, SIGNAL(triggered()), this, SLOT(compute()));
226
227     nbThreadsAct = new QAction(tr("Number of threads"), this);
228     nbThreadsAct->setStatusTip(tr("Number of threads"));
229     connect(nbThreadsAct, SIGNAL(triggered()), this, SLOT(nbThreads()));
230
231     exitAct = new QAction(tr("E&xit"), this);
232     exitAct->setShortcut(tr("Ctrl+Q"));
233     exitAct->setStatusTip(tr("Exit the application"));
234     connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
235
236     aboutAct = new QAction(tr("&About"), this);
237     aboutAct->setStatusTip(tr("Show the application's About box"));
238     connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
239 }
240
241 void MainWindow::createMenus()
242 {
243     computeMenu = menuBar()->addMenu(tr("&Model"));
244     computeMenu->addAction(model1Act);
245     computeMenu->addAction(model2Act);
246     computeMenu->addSeparator();
247     computeMenu->addAction(computeAct);
248     computeMenu->addAction(nbThreadsAct);
249     computeMenu->addSeparator();
250     computeMenu->addAction(exitAct);
251
252     menuBar()->addSeparator();
253
254     helpMenu = menuBar()->addMenu(tr("&Help"));
255     helpMenu->addAction(aboutAct);
256 }
257
258 void MainWindow::createToolBars()
259 {
260     computeToolBar = addToolBar(tr("Model"));
261     computeToolBar->addAction(model1Act);
262     computeToolBar->addAction(model2Act);
263     computeToolBar->addAction(computeAct);
264 }
265
266 void MainWindow::createStatusBar()
267 {
268     statusBar()->showMessage(tr("Ready"));
269 }
270
271 void MainWindow::createDefaultModel1()
272 {
273     Handle(AppStd_Application) app = MainWindow::getApplication();
274     Handle(TDocStd_Document) doc;
275     app->NewDocument("XmlOcaf", doc);
276     TDF_Label mainLabel = doc->Main();
277
278     // Initialize function drivers
279     TFunction_DriverTable::Get()->AddDriver(SimpleDriver::GetID(), new SimpleDriver());
280
281     // Set a logbook.
282     Handle(TFunction_Logbook) logbook = TFunction_Logbook::Set(mainLabel);
283
284     // Create a tree of functions
285     TDF_Label L1 = mainLabel.FindChild(1);
286     TDF_Label L2 = mainLabel.FindChild(2);
287     TDF_Label L3 = mainLabel.FindChild(3);
288     TDF_Label L4 = mainLabel.FindChild(4);
289     TDF_Label L5 = mainLabel.FindChild(5);
290     TDF_Label L6 = mainLabel.FindChild(6);
291     TDF_Label L7 = mainLabel.FindChild(7);
292     double time = 2;
293     // 1:
294     TFunction_IFunction::NewFunction(L1, SimpleDriver::GetID());
295     TDataStd_Name::Set(L1, "1");
296     TDataStd_Real::Set(L1, time); // Argument
297     TDF_Reference::Set(L1.FindChild(2).FindChild(1), L1); // Result
298     TFunction_IFunction iFunc1(L1);
299     iFunc1.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
300     // 2:
301     TFunction_IFunction::NewFunction(L2, SimpleDriver::GetID());
302     TDataStd_Name::Set(L2, "2");
303     TDataStd_Real::Set(L2, time); // Argument
304     TDF_Reference::Set(L2.FindChild(2).FindChild(1), L2); // Result
305     TFunction_IFunction iFunc2(L2);
306     iFunc2.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
307     // 3:
308     TFunction_IFunction::NewFunction(L3, SimpleDriver::GetID());
309     TDataStd_Name::Set(L3, "3");
310     TDataStd_Real::Set(L3, time); // Argument
311     TDF_Reference::Set(L3.FindChild(1).FindChild(1), L1); // Argument: F3 -> F1
312     TDF_Reference::Set(L3.FindChild(2).FindChild(1), L3); // Result
313     TFunction_IFunction iFunc3(L3);
314     iFunc3.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
315     // 4:
316     TFunction_IFunction::NewFunction(L4, SimpleDriver::GetID());
317     TDataStd_Name::Set(L4, "4");
318     TDataStd_Real::Set(L4, time); // Argument
319     TDF_Reference::Set(L4.FindChild(1).FindChild(1), L2); // Argument F4 -> F2
320     TDF_Reference::Set(L4.FindChild(1).FindChild(2), L3); // Argument F4 -> F3
321     TDF_Reference::Set(L4.FindChild(2).FindChild(1), L4); // Result
322     TFunction_IFunction iFunc4(L4);
323     iFunc4.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
324     // 5:
325     TFunction_IFunction::NewFunction(L5, SimpleDriver::GetID());
326     TDataStd_Name::Set(L5, "5");
327     TDataStd_Real::Set(L5, time); // Argument
328     TDF_Reference::Set(L5.FindChild(1).FindChild(1), L4); // Argument F5 -> F4
329     TDF_Reference::Set(L5.FindChild(2).FindChild(1), L5); // Result
330     TFunction_IFunction iFunc5(L5);
331     iFunc5.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
332     // 6:
333     TFunction_IFunction::NewFunction(L6, SimpleDriver::GetID());
334     TDataStd_Name::Set(L6, "6");
335     TDataStd_Real::Set(L6, time); // Argument
336     TDF_Reference::Set(L6.FindChild(1).FindChild(1), L4); // Argument F6 ->F4
337     TDF_Reference::Set(L6.FindChild(2).FindChild(1), L6); // Result
338     TFunction_IFunction iFunc6(L6);
339     iFunc6.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
340     // 7:
341     TFunction_IFunction::NewFunction(L7, SimpleDriver::GetID());
342     TDataStd_Name::Set(L7, "7");
343     TDataStd_Real::Set(L7, time); // Argument
344     TDF_Reference::Set(L7.FindChild(1).FindChild(1), L4); // Argument F7 -> F4
345     TDF_Reference::Set(L7.FindChild(2).FindChild(1), L7); // Result
346     TFunction_IFunction iFunc7(L7);
347     iFunc7.GetGraphNode()->SetStatus(TFunction_ES_NotExecuted);
348
349     // Construct the dependencies between functions.
350     TFunction_IFunction::UpdateDependencies(mainLabel);
351
352     // Set the functions 1 and 2 modified
353     iFunc1.GetLogbook()->SetTouched(L1);
354     iFunc2.GetLogbook()->SetTouched(L2);
355
356     // Draw the model
357     graph->createModel(doc);
358 }
359
360 void MainWindow::createDefaultModel2()
361 {
362     Handle(AppStd_Application) app = MainWindow::getApplication();
363     Handle(TDocStd_Document) doc;
364     app->NewDocument("BinOcaf", doc);
365     //app->Open("W:\\TestFM\\model2.cbf", doc);
366     TDF_Label mainLabel = doc->Main();
367
368     // Initialize function drivers
369     TFunction_DriverTable::Get()->AddDriver(PointDriver::GetID(), new PointDriver());
370     TFunction_DriverTable::Get()->AddDriver(CircleDriver::GetID(), new CircleDriver());
371     TFunction_DriverTable::Get()->AddDriver(PrismDriver::GetID(), new PrismDriver());
372     TFunction_DriverTable::Get()->AddDriver(ConeDriver::GetID(), new ConeDriver());
373     TFunction_DriverTable::Get()->AddDriver(CylinderDriver::GetID(), new CylinderDriver());
374     TFunction_DriverTable::Get()->AddDriver(ShapeSaverDriver::GetID(), new ShapeSaverDriver());
375
376     // Create a tree of functions
377     TDF_Label Lpoint1  = mainLabel.FindChild(1);
378     TDF_Label Lpoint2  = mainLabel.FindChild(2);
379     TDF_Label Lpoint3  = mainLabel.FindChild(3);
380     TDF_Label Lpoint4  = mainLabel.FindChild(4);
381     TDF_Label Lcircle1 = mainLabel.FindChild(5);
382     TDF_Label Lcircle2 = mainLabel.FindChild(6);
383     TDF_Label Lcircle3 = mainLabel.FindChild(7);
384     TDF_Label Lcircle4 = mainLabel.FindChild(8);
385     TDF_Label Lprism1  = mainLabel.FindChild(9);
386     TDF_Label Lprism2  = mainLabel.FindChild(10);
387     TDF_Label Lprism3  = mainLabel.FindChild(11);
388     TDF_Label Lprism4  = mainLabel.FindChild(12);
389     TDF_Label Lcone1   = mainLabel.FindChild(13);
390     TDF_Label Lcyl1    = mainLabel.FindChild(14);
391     TDF_Label Lcyl2    = mainLabel.FindChild(15);
392     TDF_Label Lcyl3    = mainLabel.FindChild(16);
393     TDF_Label Lcyl4    = mainLabel.FindChild(17);
394     TDF_Label Lcyl5    = mainLabel.FindChild(18);
395     TDF_Label Lcyl6    = mainLabel.FindChild(19);
396     TDF_Label Lcyl7    = mainLabel.FindChild(20);
397     TDF_Label Lcyl8    = mainLabel.FindChild(21);
398     TDF_Label Lcone2   = mainLabel.FindChild(22);
399     TDF_Label Lshape1  = mainLabel.FindChild(23);
400
401     // Set a logbook.
402     Handle(TFunction_Logbook) logbook = TFunction_Logbook::Set(mainLabel);
403
404     // Points:
405     // Point 1:
406     TFunction_IFunction::NewFunction(Lpoint1, PointDriver::GetID());
407     TDataStd_Name::Set(Lpoint1, "P1");
408     Handle(TDataStd_RealArray) arr1 = TDataStd_RealArray::Set(Lpoint1, 1, 3);
409     arr1->SetValue(1, -50);
410     arr1->SetValue(2, -50);
411     arr1->SetValue(3, 0);
412     TDF_Reference::Set(Lpoint1.FindChild(1).FindChild(1), Lpoint1); // Argument
413     TDF_Reference::Set(Lpoint1.FindChild(2).FindChild(1), Lpoint1); // Result
414     TFunction_IFunction iFuncPoint1(Lpoint1);
415     iFuncPoint1.SetStatus(TFunction_ES_NotExecuted);
416     // Point 2:
417     TFunction_IFunction::NewFunction(Lpoint2, PointDriver::GetID());
418     TDataStd_Name::Set(Lpoint2, "P2");
419     Handle(TDataStd_RealArray) arr2 = TDataStd_RealArray::Set(Lpoint2, 1, 3);
420     arr2->SetValue(1, 50);
421     arr2->SetValue(2, -50);
422     arr2->SetValue(3, 0);
423     TDF_Reference::Set(Lpoint2.FindChild(1).FindChild(1), Lpoint2); // Argument
424     TDF_Reference::Set(Lpoint2.FindChild(2).FindChild(1), Lpoint2); // Result
425     TFunction_IFunction iFuncPoint2(Lpoint2);
426     iFuncPoint2.SetStatus(TFunction_ES_NotExecuted);
427     // Point 3:
428     TFunction_IFunction::NewFunction(Lpoint3, PointDriver::GetID());
429     TDataStd_Name::Set(Lpoint3, "P3");
430     Handle(TDataStd_RealArray) arr3 = TDataStd_RealArray::Set(Lpoint3, 1, 3);
431     arr3->SetValue(1, 50);
432     arr3->SetValue(2, 50);
433     arr3->SetValue(3, 0);
434     TDF_Reference::Set(Lpoint3.FindChild(1).FindChild(1), Lpoint3); // Argument
435     TDF_Reference::Set(Lpoint3.FindChild(2).FindChild(1), Lpoint3); // Result
436     TFunction_IFunction iFuncPoint3(Lpoint3);
437     iFuncPoint3.SetStatus(TFunction_ES_NotExecuted);
438     // Point 4:
439     TFunction_IFunction::NewFunction(Lpoint4, PointDriver::GetID());
440     TDataStd_Name::Set(Lpoint4, "P4");
441     Handle(TDataStd_RealArray) arr4 = TDataStd_RealArray::Set(Lpoint4, 1, 3);
442     arr4->SetValue(1, -50);
443     arr4->SetValue(2, 50);
444     arr4->SetValue(3, 0);
445     TDF_Reference::Set(Lpoint4.FindChild(1).FindChild(1), Lpoint4); // Argument
446     TDF_Reference::Set(Lpoint4.FindChild(2).FindChild(1), Lpoint4); // Result
447     TFunction_IFunction iFuncPoint4(Lpoint4);
448     iFuncPoint4.SetStatus(TFunction_ES_NotExecuted);
449     // Circles:
450     // Circle 1:
451     TFunction_IFunction::NewFunction(Lcircle1, CircleDriver::GetID());
452     TDataStd_Name::Set(Lcircle1, "C1");
453     TDataStd_Real::Set(Lcircle1, 10);
454     TDF_Reference::Set(Lcircle1.FindChild(1).FindChild(1), Lpoint1); // Argument: point
455     TDF_Reference::Set(Lcircle1.FindChild(2).FindChild(1), Lcircle1); // Result
456     TFunction_IFunction iFuncCircle1(Lcircle1);
457     iFuncCircle1.SetStatus(TFunction_ES_NotExecuted);
458     // Circle 2:
459     TFunction_IFunction::NewFunction(Lcircle2, CircleDriver::GetID());
460     TDataStd_Name::Set(Lcircle2, "C2");
461     TDataStd_Real::Set(Lcircle2, 20);
462     TDF_Reference::Set(Lcircle2.FindChild(1).FindChild(1), Lpoint2); // Argument: point
463     TDF_Reference::Set(Lcircle2.FindChild(2).FindChild(1), Lcircle2); // Result
464     TFunction_IFunction iFuncCircle2(Lcircle2);
465     iFuncCircle2.SetStatus(TFunction_ES_NotExecuted);
466     // Circle 3:
467     TFunction_IFunction::NewFunction(Lcircle3, CircleDriver::GetID());
468     TDataStd_Name::Set(Lcircle3, "C3");
469     TDataStd_Real::Set(Lcircle3, 30);
470     TDF_Reference::Set(Lcircle3.FindChild(1).FindChild(1), Lpoint3); // Argument: point
471     TDF_Reference::Set(Lcircle3.FindChild(2).FindChild(1), Lcircle3); // Result
472     TFunction_IFunction iFuncCircle3(Lcircle3);
473     iFuncCircle3.SetStatus(TFunction_ES_NotExecuted);
474     // Circle 4:
475     TFunction_IFunction::NewFunction(Lcircle4, CircleDriver::GetID());
476     TDataStd_Name::Set(Lcircle4, "C4");
477     TDataStd_Real::Set(Lcircle4, 40);
478     TDF_Reference::Set(Lcircle4.FindChild(1).FindChild(1), Lpoint4); // Argument: point
479     TDF_Reference::Set(Lcircle4.FindChild(2).FindChild(1), Lcircle4); // Result
480     TFunction_IFunction iFuncCircle4(Lcircle4);
481     iFuncCircle4.SetStatus(TFunction_ES_NotExecuted);
482     // Prisms:
483     // Prism 1:
484     TFunction_IFunction::NewFunction(Lprism1, PrismDriver::GetID());
485     TDataStd_Name::Set(Lprism1, "Pr1");
486     TDataStd_Real::Set(Lprism1, 30);
487     TDF_Reference::Set(Lprism1.FindChild(1).FindChild(1), Lcircle1); // Argument: point
488     TDF_Reference::Set(Lprism1.FindChild(2).FindChild(1), Lprism1); // Result
489     TDF_Reference::Set(Lprism1.FindChild(2).FindChild(2), Lprism1.FindChild(3)); // Result (top)
490     TFunction_IFunction iFuncPrism1(Lprism1);
491     iFuncPrism1.SetStatus(TFunction_ES_NotExecuted);
492     // Prism 2:
493     TFunction_IFunction::NewFunction(Lprism2, PrismDriver::GetID());
494     TDataStd_Name::Set(Lprism2, "Pr2");
495     TDataStd_Real::Set(Lprism2, 30);
496     TDF_Reference::Set(Lprism2.FindChild(1).FindChild(1), Lcircle2); // Argument: point
497     TDF_Reference::Set(Lprism2.FindChild(2).FindChild(1), Lprism2); // Result
498     TDF_Reference::Set(Lprism2.FindChild(2).FindChild(2), Lprism2.FindChild(3)); // Result (top)
499     TFunction_IFunction iFuncPrism2(Lprism2);
500     iFuncPrism2.SetStatus(TFunction_ES_NotExecuted);
501     // Prism 3:
502     TFunction_IFunction::NewFunction(Lprism3, PrismDriver::GetID());
503     TDataStd_Name::Set(Lprism3, "Pr3");
504     TDataStd_Real::Set(Lprism3, 30);
505     TDF_Reference::Set(Lprism3.FindChild(1).FindChild(1), Lcircle3); // Argument: point
506     TDF_Reference::Set(Lprism3.FindChild(2).FindChild(1), Lprism3); // Result
507     TDF_Reference::Set(Lprism3.FindChild(2).FindChild(2), Lprism3.FindChild(3)); // Result (top)
508     TFunction_IFunction iFuncPrism3(Lprism3);
509     iFuncPrism3.SetStatus(TFunction_ES_NotExecuted);
510     // Prism 4:
511     TFunction_IFunction::NewFunction(Lprism4, PrismDriver::GetID());
512     TDataStd_Name::Set(Lprism4, "Pr4");
513     TDataStd_Real::Set(Lprism4, 30);
514     TDF_Reference::Set(Lprism4.FindChild(1).FindChild(1), Lcircle4); // Argument: point
515     TDF_Reference::Set(Lprism4.FindChild(2).FindChild(1), Lprism4); // Result
516     TDF_Reference::Set(Lprism4.FindChild(2).FindChild(2), Lprism4.FindChild(3)); // Result (top)
517     TFunction_IFunction iFuncPrism4(Lprism4);
518     iFuncPrism4.SetStatus(TFunction_ES_NotExecuted);
519     // Cone 1:
520     TFunction_IFunction::NewFunction(Lcone1, ConeDriver::GetID());
521     TDataStd_Name::Set(Lcone1, "Co1");
522     TDataStd_Real::Set(Lcone1, 20);
523     TDF_Reference::Set(Lcone1.FindChild(1).FindChild(1), Lprism1.FindChild(3)); // Argument: top
524     TDF_Reference::Set(Lcone1.FindChild(1).FindChild(2), Lprism2.FindChild(3)); // Argument: top
525     TDF_Reference::Set(Lcone1.FindChild(1).FindChild(3), Lprism3.FindChild(3)); // Argument: top
526     TDF_Reference::Set(Lcone1.FindChild(1).FindChild(4), Lprism4.FindChild(3)); // Argument: top
527     TDF_Reference::Set(Lcone1.FindChild(2).FindChild(1), Lcone1); // Result
528     TDF_Reference::Set(Lcone1.FindChild(2).FindChild(2), Lcone1.FindChild(3)); // Result
529     TFunction_IFunction iFuncCone1(Lcone1);
530     iFuncCone1.SetStatus(TFunction_ES_NotExecuted);
531     // Cylinders:
532     // Cylinder 1:
533     TFunction_IFunction::NewFunction(Lcyl1, CylinderDriver::GetID());
534     TDataStd_Name::Set(Lcyl1, "Cyl1");
535     Handle(TDataStd_RealArray) carr1 = TDataStd_RealArray::Set(Lcyl1, 1, 3);
536     carr1->SetValue(1, 10.0);
537     carr1->SetValue(2, 45.0);
538     carr1->SetValue(3, 20.0);
539     TDF_Reference::Set(Lcyl1.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
540     TDF_Reference::Set(Lcyl1.FindChild(2).FindChild(1), Lcyl1); // Result
541     TDF_Reference::Set(Lcyl1.FindChild(2).FindChild(2), Lcyl1.FindChild(3)); // Result
542     TFunction_IFunction iFuncCyl1(Lcyl1);
543     iFuncCyl1.SetStatus(TFunction_ES_NotExecuted);
544     // Cylinder 2:
545     TFunction_IFunction::NewFunction(Lcyl2, CylinderDriver::GetID());
546     TDataStd_Name::Set(Lcyl2, "Cyl2");
547     Handle(TDataStd_RealArray) carr2 = TDataStd_RealArray::Set(Lcyl2, 1, 3);
548     carr2->SetValue(1, 10.0);
549     carr2->SetValue(2, 90.0);
550     carr2->SetValue(3, 20.0);
551     TDF_Reference::Set(Lcyl2.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
552     TDF_Reference::Set(Lcyl2.FindChild(2).FindChild(1), Lcyl2); // Result
553     TDF_Reference::Set(Lcyl2.FindChild(2).FindChild(2), Lcyl2.FindChild(3)); // Result
554     TFunction_IFunction iFuncCyl2(Lcyl2);
555     iFuncCyl2.SetStatus(TFunction_ES_NotExecuted);
556     // Cylinder 3:
557     TFunction_IFunction::NewFunction(Lcyl3, CylinderDriver::GetID());
558     TDataStd_Name::Set(Lcyl3, "Cyl3");
559     Handle(TDataStd_RealArray) carr3 = TDataStd_RealArray::Set(Lcyl3, 1, 3);
560     carr3->SetValue(1, 10.0);
561     carr3->SetValue(2, 135.0);
562     carr3->SetValue(3, 20.0);
563     TDF_Reference::Set(Lcyl3.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
564     TDF_Reference::Set(Lcyl3.FindChild(2).FindChild(1), Lcyl3); // Result
565     TDF_Reference::Set(Lcyl3.FindChild(2).FindChild(2), Lcyl3.FindChild(3)); // Result
566     TFunction_IFunction iFuncCyl3(Lcyl3);
567     iFuncCyl3.SetStatus(TFunction_ES_NotExecuted);
568     // Cylinder 4:
569     TFunction_IFunction::NewFunction(Lcyl4, CylinderDriver::GetID());
570     TDataStd_Name::Set(Lcyl4, "Cyl4");
571     Handle(TDataStd_RealArray) carr4 = TDataStd_RealArray::Set(Lcyl4, 1, 3);
572     carr4->SetValue(1, 10.0);
573     carr4->SetValue(2, 180.0);
574     carr4->SetValue(3, 20.0);
575     TDF_Reference::Set(Lcyl4.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
576     TDF_Reference::Set(Lcyl4.FindChild(2).FindChild(1), Lcyl4); // Result
577     TDF_Reference::Set(Lcyl4.FindChild(2).FindChild(2), Lcyl4.FindChild(3)); // Result
578     TFunction_IFunction iFuncCyl4(Lcyl4);
579     iFuncCyl4.SetStatus(TFunction_ES_NotExecuted);
580     // Cylinder 5:
581     TFunction_IFunction::NewFunction(Lcyl5, CylinderDriver::GetID());
582     TDataStd_Name::Set(Lcyl5, "Cyl5");
583     Handle(TDataStd_RealArray) carr5 = TDataStd_RealArray::Set(Lcyl5, 1, 3);
584     carr5->SetValue(1, 10.0);
585     carr5->SetValue(2, 225.0);
586     carr5->SetValue(3, 20.0);
587     TDF_Reference::Set(Lcyl5.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
588     TDF_Reference::Set(Lcyl5.FindChild(2).FindChild(1), Lcyl5); // Result
589     TDF_Reference::Set(Lcyl5.FindChild(2).FindChild(2), Lcyl5.FindChild(3)); // Result
590     TFunction_IFunction iFuncCyl5(Lcyl5);
591     iFuncCyl5.SetStatus(TFunction_ES_NotExecuted);
592     // Cylinder 6:
593     TFunction_IFunction::NewFunction(Lcyl6, CylinderDriver::GetID());
594     TDataStd_Name::Set(Lcyl6, "Cyl6");
595     Handle(TDataStd_RealArray) carr6 = TDataStd_RealArray::Set(Lcyl6, 1, 3);
596     carr6->SetValue(1, 10.0);
597     carr6->SetValue(2, 270.0);
598     carr6->SetValue(3, 20.0);
599     TDF_Reference::Set(Lcyl6.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
600     TDF_Reference::Set(Lcyl6.FindChild(2).FindChild(1), Lcyl6); // Result
601     TDF_Reference::Set(Lcyl6.FindChild(2).FindChild(2), Lcyl6.FindChild(3)); // Result
602     TFunction_IFunction iFuncCyl6(Lcyl6);
603     iFuncCyl6.SetStatus(TFunction_ES_NotExecuted);
604     // Cylinder 7:
605     TFunction_IFunction::NewFunction(Lcyl7, CylinderDriver::GetID());
606     TDataStd_Name::Set(Lcyl7, "Cyl7");
607     Handle(TDataStd_RealArray) carr7 = TDataStd_RealArray::Set(Lcyl7, 1, 3);
608     carr7->SetValue(1, 10.0);
609     carr7->SetValue(2, 315.0);
610     carr7->SetValue(3, 20.0);
611     TDF_Reference::Set(Lcyl7.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
612     TDF_Reference::Set(Lcyl7.FindChild(2).FindChild(1), Lcyl7); // Result
613     TDF_Reference::Set(Lcyl7.FindChild(2).FindChild(2), Lcyl7.FindChild(3)); // Result
614     TFunction_IFunction iFuncCyl7(Lcyl7);
615     iFuncCyl7.SetStatus(TFunction_ES_NotExecuted);
616     // Cylinder 8:
617     TFunction_IFunction::NewFunction(Lcyl8, CylinderDriver::GetID());
618     TDataStd_Name::Set(Lcyl8, "Cyl8");
619     Handle(TDataStd_RealArray) carr8 = TDataStd_RealArray::Set(Lcyl8, 1, 3);
620     carr8->SetValue(1, 10.0);
621     carr8->SetValue(2, 0.0);
622     carr8->SetValue(3, 20.0);
623     TDF_Reference::Set(Lcyl8.FindChild(1).FindChild(1), Lcone1.FindChild(3)); // Argument: top
624     TDF_Reference::Set(Lcyl8.FindChild(2).FindChild(1), Lcyl8); // Result
625     TDF_Reference::Set(Lcyl8.FindChild(2).FindChild(2), Lcyl8.FindChild(3)); // Result
626     TFunction_IFunction iFuncCyl8(Lcyl8);
627     iFuncCyl8.SetStatus(TFunction_ES_NotExecuted);
628     // Cone 2:
629     TFunction_IFunction::NewFunction(Lcone2, ConeDriver::GetID());
630     TDataStd_Name::Set(Lcone2, "Co2");
631     TDataStd_Real::Set(Lcone2, 30);
632     TDF_Reference::Set(Lcone2.FindChild(1).FindChild(1), Lcyl1.FindChild(3)); // Argument: top
633     TDF_Reference::Set(Lcone2.FindChild(1).FindChild(2), Lcyl3.FindChild(3)); // Argument: top
634     TDF_Reference::Set(Lcone2.FindChild(1).FindChild(3), Lcyl5.FindChild(3)); // Argument: top
635     TDF_Reference::Set(Lcone2.FindChild(1).FindChild(4), Lcyl7.FindChild(3)); // Argument: top
636     TDF_Reference::Set(Lcone2.FindChild(2).FindChild(1), Lcone2); // Result
637     TDF_Reference::Set(Lcone2.FindChild(2).FindChild(2), Lcone2.FindChild(3)); // Result
638     TFunction_IFunction iFuncCone2(Lcone2);
639     iFuncCone2.SetStatus(TFunction_ES_NotExecuted);
640     // Shape saver 1:
641     TFunction_IFunction::NewFunction(Lshape1, ShapeSaverDriver::GetID());
642     TDataStd_Name::Set(Lshape1, "Sh");
643     TFunction_IFunction iFuncShape1(Lshape1);
644     iFuncShape1.SetStatus(TFunction_ES_NotExecuted);
645     // Arguments of this functions - results of all functions
646     int iTag = 1;
647     const TFunction_DoubleMapOfIntegerLabel& all = iFuncShape1.GetAllFunctions();
648     TFunction_DoubleMapIteratorOfDoubleMapOfIntegerLabel itrm(all);
649     for (; itrm.More(); itrm.Next())
650     {
651         TFunction_IFunction iFunc(itrm.Key2());
652         TDF_LabelList res;
653         iFunc.Results(res);
654         TDF_ListIteratorOfLabelList itrl(res);
655         for (; itrl.More(); itrl.Next(), iTag++)
656         {
657             TDF_Reference::Set(Lshape1.FindChild(1).FindChild(iTag), itrl.Value());
658         }
659     }
660
661     // Construct the dependencies between functions.
662     TFunction_IFunction::UpdateDependencies(mainLabel);
663
664     // Set the functions 1 .. 4 modified
665     TFunction_IFunction(mainLabel).GetLogbook()->SetTouched(Lpoint1);
666     TFunction_IFunction(mainLabel).GetLogbook()->SetTouched(Lpoint2);
667     TFunction_IFunction(mainLabel).GetLogbook()->SetTouched(Lpoint3);
668     TFunction_IFunction(mainLabel).GetLogbook()->SetTouched(Lpoint4);
669
670     // Draw the model
671     graph->createModel(doc);
672
673     //app->SaveAs(doc, "W:\\TestFM\\model2.cbf");
674 }