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