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