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