1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI_Main.cxx
25 // Author : Francis KLOSS
29 #include "QAD_Splitter.h"
30 #include "QAD_LeftFrame.h"
31 #include "QAD_ObjectBrowser.h"
32 #include "QAD_ObjectBrowserItem.h"
33 #include "QAD_PyEditor.h"
34 #include "QAD_Message.h"
35 #include "QAD_FileDlg.h"
36 #include "QAD_Application.h"
37 #include "SUPERVGUI_Def.h"
38 #include "QAD_RightFrame.h"
39 #include "SALOME_Event.hxx"
40 #include "SUPERVGraph_ViewFrame.h"
43 #include "SUPERVGUI_Main.h"
44 #include "SUPERVGUI.h"
45 #include "SUPERVGUI_ComputeNode.h"
46 #include "SUPERVGUI_ControlNode.h"
47 #include "NOTIFICATION.hxx"
48 #include "SUPERVGUI_Notification.h"
49 #include "SALOMEGUI_ImportOperation.h"
50 #include "SUPERVGUI_Information.h"
51 #include "SUPERVGUI_CanvasControlNode.h"
52 #include <qvalidator.h>
54 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool fromIOR)
55 : SUPERVGraph_View(theParent),
58 myLogFileName( QString::null ),
65 Trace("SUPERVGUI_Main::SUPERVGUI_Main (new)");
66 theParent->setViewWidget(this);
68 //SUPERVGUI_Main* am = Supervision.getMain();
69 QAD_ObjectBrowser* ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
71 // ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
73 //ob = am->objectBrowser;
75 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(ob->getListView()->currentItem());
76 SALOMEDS::SObject_var obj = theDesktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
77 SALOMEDS::GenericAttribute_var anAttr;
78 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
79 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
80 Standard_CString ior = anIOR->Value();
81 dataflow = Supervision.getEngine()->getStreamGraph(ior);
82 if (SUPERV_isNull(dataflow)) {
83 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
89 QMessageBox::warning(0, tr("ERROR"), tr("MSG_NOACCESS_BY_IOR"));
93 dataflow = Supervision.getEngine()->StreamGraph(MAIN_NEW);
94 if (SUPERV_isNull(dataflow)) {
95 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
103 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool isModify, const char* f)
104 : SUPERVGraph_View(theParent),
107 myLogFileName( QString::null ),
114 Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
115 theParent->setViewWidget(this);
117 dataflow = Supervision.getEngine()->StreamGraph(f);
119 dataflow = Supervision.getEngine()->StreamGraphE(f);
121 if (SUPERV_isNull(dataflow)) {
122 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
129 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph cp)
130 : SUPERVGraph_View(theParent),
133 myLogFileName( QString::null ),
140 Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
141 theParent->setViewWidget(this);
142 // dataflow = cp->Copy();
144 if (SUPERV_isNull(dataflow)) {
145 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
152 void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
153 Trace("SUPERVGUI_Main::init");
154 if (theDesktop) myNService = theDesktop->getNameService();
160 myThread = new SUPERVGUI_Thread();
161 myThread->setMain(this);
162 connect(this, SIGNAL(KillMyThread(bool)), myThread, SLOT(KillThread(bool)));
165 //myIsRunned = false;
166 myCurrentView = CANVAS;
167 // myCurrentView = GRAPH;
168 myIsFromStudy = false;
170 study = theDesktop->getActiveStudy();
172 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
173 bool aLocked = studyDoc->GetProperties()->IsLocked();
174 SALOMEDS::StudyBuilder_var builder = studyDoc->NewBuilder();
175 SALOMEDS::SComponent_var father = studyDoc->FindComponent(STUDY_SUPERVISION);
176 SALOMEDS::GenericAttribute_var anAttr;
177 SALOMEDS::AttributeName_var aName;
178 SALOMEDS::AttributePixMap_var aPixmap;
179 if (father->_is_nil()) {
180 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
182 if (aLocked) studyDoc->GetProperties()->SetLocked(false);
183 father = builder->NewComponent(STUDY_SUPERVISION);
184 anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
185 aName = SALOMEDS::AttributeName::_narrow(anAttr);
186 //aName->SetValue("Supervision");
187 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
189 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
190 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
191 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
193 builder->DefineComponentInstance(father, Supervision.getEngine());
194 if (aLocked) studyDoc->GetProperties()->SetLocked(true);
198 objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
201 graph = new SUPERVGUI_Graph(this);
203 array = new SUPERVGUI_Array(this);
205 myCanvas = new SUPERVGUI_Canvas(this);
206 myCanvasView = new SUPERVGUI_CanvasView(myCanvas, this);
208 message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
209 notification = new NOTIFICATION_Consumer();
211 QBoxLayout * layout = new QVBoxLayout(this);
212 layout->setMargin(0);
213 layout->setSpacing(0);
214 layout->addWidget(graph);
215 layout->addWidget(array);
216 layout->addWidget(myCanvasView);
218 if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
223 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
224 myLogFile = fopen( myLogFileName.latin1(), "a" );
225 if ( myLogFile == NULL )
228 myTimer = new QTimer( this );
229 connect( myTimer, SIGNAL(timeout()), this, SLOT(checkExecution()) );
232 SUPERVGUI_Main::~SUPERVGUI_Main() {
233 //cout << "===> SUPERVGUI_Main::~SUPERVGUI_Main() " << endl;
234 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
236 // close all opened SubGraphs
237 QMap<QString, QAD_StudyFrame*>::iterator it;
238 for (it = mySubGraphs.begin(); it != mySubGraphs.end(); ++it) {
239 it.data()->removeEventFilter(this);
243 mySubGraphMap.clear();
245 QAD_StudyFrame* aSubGraph;
246 for (aSubGraph = mySubGraphs.first(); aSubGraph; aSubGraph = mySubGraphs.next()) {
247 aSubGraph->removeEventFilter(this);
252 if ( myLogFile != NULL) {
255 graph->removeLinks();
257 // delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
258 notification->_remove_ref(); // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
259 if (!SUPERV_isNull(dataflow)) {
260 if (dataflow->IsExecuting()) {
261 if (QMessageBox::warning(QAD_Application::getDesktop(),
263 tr("MSG_DF_RUNNING"),
264 tr("MSG_DF_EXECUTION"),
265 tr("MSG_DF_KILL")) == 1) {
266 if (dataflow->Kill()) {
267 if (myThread->running())
272 emit KillMyThread(true);
273 if (myThread->running())
278 emit KillMyThread(true);
279 if (myThread->running())
285 void SUPERVGUI_Main::filterNotification() {
286 Trace("SUPERVGUI_Main::filterNotification");
287 SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
288 dlg->setFiltered( myFiltered );
289 dlg->setLogged( myLogged, myLogFileName );
290 dlg->setWarning( myWarning );
291 dlg->setStep( myStep );
292 dlg->setTrace( myTrace );
293 dlg->setVerbose( myVerbose );
294 if ( dlg->exec() == QDialog::Accepted ) {
295 myLogged = dlg->getLogged();
296 myLogFileName = dlg->getLogFile();
297 myFiltered = dlg->getFiltered();
298 myWarning = dlg->getWarning();
299 myStep = dlg->getStep();
300 myTrace = dlg->getTrace();
301 myVerbose = dlg->getVerbose();
303 if ( myLogFile != NULL) {
307 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
308 myLogFile = fopen( myLogFileName.latin1(), "a" );
309 if ( myLogFile == NULL ) {
311 QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
317 void SUPERVGUI_Main::changeDSGraphParameters() {
318 SUPERVGUI_DSGraphParameters* aDlg = new SUPERVGUI_DSGraphParameters(dataflow, dataflow->IsReadOnly());
324 void SUPERVGUI_Main::syncAsync() {
325 Trace("SUPERVGUI_Main::syncAsync")
326 QTimer::singleShot(1, this, SLOT(sync()));
331 * Called by thread when dataflow is executing
333 void SUPERVGUI_Main::execute(char * theNodeName, SUPERV::GraphState theNodeState) {
334 if (myCurrentView == CANVAS || myCurrentView == CONTROLFLOW) {
335 SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*) myCanvas->child(theNodeName, "SUPERVGUI_CanvasNode");
336 if (aNode) aNode->sync();
339 SUPERVGUI_Node* aNodePrs;
340 SUPERVGUI_GraphNode* aGraphNodePrs;
341 if (myCurrentView == TABLE) {
342 aNodePrs = (SUPERVGUI_Node*) array->child(theNodeName, "SUPERVGUI_Node");
343 aGraphNodePrs = (SUPERVGUI_GraphNode*) array->child(theNodeName, "SUPERVGUI_GraphNode");
345 aNodePrs = (SUPERVGUI_Node*) graph->child(theNodeName, "SUPERVGUI_Node");
346 aGraphNodePrs = (SUPERVGUI_GraphNode*) graph->child(theNodeName, "SUPERVGUI_GraphNode");
349 aGraphNodePrs->sync();
353 aNodePrs->syncOnEvent(theNodeState);
359 void SUPERVGUI_Main::sync() {
360 Trace("SUPERVGUI_Main::sync")
361 if ((SUPERV_isNull(dataflow))) return;
362 QString t = tr("GRAPH_TITLE");
364 t += dataflow->Name();
367 study->updateObjBrowser();
368 if (myCurrentView == TABLE) {
370 } else if (myCurrentView == GRAPH) {
379 void SUPERVGUI_Main::showTable() {
380 if (myCurrentView == TABLE) return;
382 if (array->create()) {
383 if (myCurrentView == GRAPH)
386 myCanvasView->hide();
387 myCurrentView = TABLE;
393 void SUPERVGUI_Main::showFullGraph() {
394 if (myCurrentView == TABLE) {
398 else if (myCurrentView != GRAPH) { // (myCurrentView == CANVAS) {
399 myCanvasView->hide();
402 myCurrentView = GRAPH;
404 graph->setFullView();
408 void SUPERVGUI_Main::showContolFlow() {
410 if (myCurrentView == TABLE) {
414 else if (myCurrentView == GRAPH) {
418 myCurrentView = CONTROLFLOW;
419 myCanvas->setControlView();
422 myCanvasView->show();
426 void SUPERVGUI_Main::showCanvas() {
427 if (myCurrentView == CANVAS) return;
430 if (myCurrentView == TABLE) {
434 else if (myCurrentView == GRAPH) {
438 myCurrentView = CANVAS;
439 myCanvas->setFullView();
442 myCanvasView->show();
447 bool SUPERVGUI_Main::exportDataflow(QString theFile) {
448 Trace("SUPERVGUI_Main::exportDataflow");
449 if ((SUPERV_isNull(dataflow))) return false;
451 if (!theFile.isEmpty()) {
452 if (!dataflow->Export(theFile.latin1())) {
453 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
460 void SUPERVGUI_Main::insertFile() {
461 Trace("SUPERVGUI_Main::insertFile")
462 if ((SUPERV_isNull(dataflow))) return;
464 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
467 tr("MSG_GRAPH_INSERT"),
470 if (dataflow->Import(f.latin1())) {
471 if (myCurrentView == TABLE) {
475 else if (myCurrentView != GRAPH) { // (myCurrentView == CANVAS) {
480 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
485 void SUPERVGUI_Main::copy() {
486 Trace("SUPERVGUI_Main::copy");
487 if (dataflow->ThreadsMax() == 0) {
488 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
491 QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
492 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
493 (aStudyFrame->getRightFrame()->getViewFrame());
495 SUPERV_Graph aNewGraph; // = dataflow->StreamCopy();
496 if (dataflow->IsStreamGraph()) {
497 SUPERV_StreamGraph aSGraph = dataflow->ToStreamGraph();
498 if (SUPERV_isNull(aSGraph)) {
499 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_CANT_COPY"));
502 aNewGraph = aSGraph->StreamCopy();
505 aNewGraph = dataflow->Copy();
507 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
508 aNewName += dataflow->Name();
509 aNewGraph->SetName(aNewName);
510 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
511 Supervision.getDesktop(),
513 study->showFrame(aStudyFrame);
517 void SUPERVGUI_Main::openSubGraph(SUPERV_CNode theNode, bool correct)
519 //cout << "===> SUPERVGUI_Main::openSubGraph(" << theNode->Name() << ")" << endl;
520 //cout << " macro node : " << theNode->IsMacro() << ", " << theNode->IsFlowMacro() << ", " << theNode->IsStreamMacro() << endl;
521 if (theNode->IsMacro()) {
522 // get SubGraph from MacroNode
523 SUPERV_Graph aMacro = SUPERV::Graph::_narrow(theNode);
525 if (aMacro->IsStreamMacro())
526 aGraph = aMacro->StreamObjRef();
528 aGraph = aMacro->FlowObjRef();
531 if (SUPERV_isNull(aGraph)) {
532 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOACCESS"));
536 QString aGraphName = aGraph->Name();
537 QAD_StudyFrame* aStudyFrame;
538 if (mySubGraphs.contains(aGraphName)) {
539 //cout << " activate already opened dataflow " << aGraphName << endl;
540 aStudyFrame = mySubGraphs[aGraphName];
541 aStudyFrame->setActiveWindow();
542 aStudyFrame->setFocus();
545 aStudyFrame = Supervision.createGraph();
547 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
548 (aStudyFrame->getRightFrame()->getViewFrame());
550 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
551 Supervision.getDesktop(),
553 // connect(aStudyFrame, SIGNAL(sfStudyFrameClosing(QAD_StudyFrame*)),
554 // this, SLOT(onSubGraphClosed(QAD_StudyFrame*)));
555 connect(aStudyFrame, SIGNAL(sfStudyFrameActivated(QAD_StudyFrame*)),
556 this, SLOT(onSubGraphActivated(QAD_StudyFrame*)));
557 aStudyFrame->installEventFilter(this);
559 mySubGraphs.insert(aGraphName, aStudyFrame);
560 mySubGraphMap.insert(aGraphName, theNode->Name());
565 study->showFrame(aStudyFrame);
566 if (!correct) myLastGraph = aStudyFrame;
571 bool SUPERVGUI_Main::eventFilter( QObject* o, QEvent* e)
573 // workaround to get close event
574 if (o->inherits("QAD_StudyFrame") && e->type() == QEvent::Close) {
575 QAD_StudyFrame* aFrame = (QAD_StudyFrame*) o;
576 onSubGraphClosed(aFrame);
578 return SUPERVGraph_View::eventFilter(o, e);
581 // workaround to fix PAL6255 -> opened SubGraph is not on top
582 void SUPERVGUI_Main::onSubGraphActivated(QAD_StudyFrame* theStudyFrame)
585 QAD_StudyFrame* aFrame = myLastGraph;
587 aFrame->setActiveWindow();
592 void SUPERVGUI_Main::onSubGraphClosed(QAD_StudyFrame* theStudyFrame)
594 QAD_ViewFrame* viewFrame = theStudyFrame->getRightFrame()->getViewFrame();
595 if(SUPERVGraph_ViewFrame* supervFrame = dynamic_cast<SUPERVGraph_ViewFrame*>(viewFrame)){
596 theStudyFrame->removeEventFilter(this);
597 disconnect(theStudyFrame, 0, this, 0);
599 SUPERVGraph_View* view = supervFrame->getViewWidget();
600 SUPERVGUI_Main* aGraph = dynamic_cast<SUPERVGUI_Main*>(view);
602 QString aGraphName = aGraph->getDataflow()->Name();
603 QMap<QString, QString>::iterator it = mySubGraphMap.find(aGraphName);
604 if (it != mySubGraphMap.end()) {
605 QString aNodeName = it.data();
606 SUPERVGUI_CanvasNode* aNode = (SUPERVGUI_CanvasNode*)
607 myCanvas->child(aNodeName, "SUPERVGUI_CanvasNode");
612 mySubGraphMap.remove(it);
614 mySubGraphs.remove(aGraphName);
619 void SUPERVGUI_Main::run() {
620 Trace("SUPERVGUI_Main::run")
621 if ((SUPERV_isNull(dataflow))) return;
623 if (dataflow->IsEditing()) {
624 if (!dataflow->IsValid()) {
625 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
626 } else if (!dataflow->IsExecutable()) {
627 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
628 } else if (graph->isAnyLinkCreating() || myCanvasView->isAnyLinkCreating()) {
629 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
631 myRunTime = QDateTime::currentDateTime();
634 if (!dataflow->ReRun()) {
635 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
636 if (dataflow->State() == SUPERV::ErrorState) {
640 myThread->startThread(tr("MSG_GRAPH_STARTED"));
644 if (!dataflow->Run()) {
645 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
646 if (dataflow->State() == SUPERV::ErrorState) {
650 myThread->startThread(tr("MSG_GRAPH_STARTED"));
656 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
662 void SUPERVGUI_Main::startExecute() {
663 Trace("SUPERVGUI_Main::startExecute")
664 if ((SUPERV_isNull(dataflow))) return;
666 if (dataflow->IsEditing()) {
667 if (!dataflow->IsValid()) {
668 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
669 } else if (!dataflow->IsExecutable()) {
670 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
671 } else if (graph->isAnyLinkCreating() || myCanvasView->isAnyLinkCreating()) {
672 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
674 myRunTime = QDateTime::currentDateTime();
677 if (!dataflow->ReStart()) {
678 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
680 myThread->startThread(tr("MSG_GRAPH_STARTED"));
684 if (!dataflow->Start()) {
685 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
687 myThread->startThread(tr("MSG_GRAPH_STARTED"));
692 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
697 void SUPERVGUI_Main::kill() {
698 Trace("SUPERVGUI_Main::kill")
699 if ((SUPERV_isNull(dataflow))) return;
701 if (dataflow->IsEditing()) {
702 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
703 } else if (dataflow->Kill()) {
705 myThread->stopThread(tr("MSG_GRAPH_KILLED"));
708 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
712 void SUPERVGUI_Main::suspendResume() {
713 Trace("SUPERVGUI_Main::suspendResume")
714 if ((SUPERV_isNull(dataflow))) return;
716 if (dataflow->IsEditing()) {
717 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
718 } else if (dataflow->State() == SUPERV_Suspend) {
719 if (dataflow->Resume()) {
720 myThread->startThread(tr("MSG_DF_RESUMED"));
722 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
725 if (dataflow->Suspend()) {
727 myThread->stopThread(tr("MSG_GRAPH_SUSPENDED"));
729 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
734 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
735 Trace("SUPERVGUI_Main::stopRestart")
736 if ((SUPERV_isNull(dataflow))) return;
738 if (dataflow->IsEditing()) {
739 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
740 } else if (dataflow->State() == SUPERV_Stop) {
741 if (dataflow->ReStart()) {
742 message->setMessage(tr("MSG_DF_RESTARTED"));
745 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
748 if (dataflow->Stop()) {
751 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
756 void SUPERVGUI_Main::addNode() {
757 Trace("SUPERVGUI_Main::addNode");
758 if (SUPERV_isNull(dataflow)) return;
760 if (dataflow->IsExecuting()) {
761 if (QMessageBox::warning(QAD_Application::getDesktop(),
762 tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
763 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
769 Supervision.getBrowser()->choose();
773 * Add Computation node
775 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
776 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
777 switch (myCurrentView) {
780 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
781 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
782 graph->addChild(aNode, theNode->X(), theNode->Y());
793 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasComputeNode(myCanvas, this, theNode);
794 aNode->move(theNode->X(), theNode->Y());
795 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
806 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
807 switch (myCurrentView) {
810 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
811 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
812 graph->addChild(aNode, theNode->X(), theNode->Y());
823 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasGotoNode(myCanvas, this, theNode);
824 aNode->move(theNode->X(), theNode->Y());
825 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
836 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
837 switch (myCurrentView) {
840 SUPERVGUI_StartControlNode* aStartPrs =
841 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
842 SUPERVGUI_EndControlNode* aEndPrs =
843 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
845 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
846 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
847 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
848 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
850 aStartPrs->updateLinksPrs();
851 aEndPrs->updateLinksPrs();
855 graph->repaintContents();
865 SUPERVGUI_CanvasStartNode* aStartNode = new SUPERVGUI_CanvasStartNode(myCanvas, this, theStartNode);
866 aStartNode->move(theStartNode->X(), theStartNode->Y());
867 if (myCurrentView == CONTROLFLOW) aStartNode->hideAll();
869 SUPERVGUI_CanvasEndNode* aEndNode = new SUPERVGUI_CanvasEndNode(myCanvas, this, theEndNode, aStartNode);
870 aEndNode->move(theEndNode->X(), theEndNode->Y());
871 if (myCurrentView == CONTROLFLOW) aEndNode->hideAll();
885 void SUPERVGUI_Main::addMacroNode(SUPERV_CNode theNode) {
886 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
887 switch (myCurrentView) {
890 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
891 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
892 graph->addChild(aNode, theNode->X(), theNode->Y());
903 SUPERVGUI_CanvasNode* aNode = new SUPERVGUI_CanvasMacroNode(myCanvas, this, theNode);
904 aNode->move(theNode->X(), theNode->Y());
905 if (myCurrentView == CONTROLFLOW) aNode->hideAll();
914 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
915 Trace("SUPERVGUI_Main::getGraph")
919 SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
920 Trace("SUPERVGUI_Main::getArray")
924 SUPERVGUI_Canvas* SUPERVGUI_Main::getCanvas() {
925 Trace("SUPERVGUI_Main::getCanvas")
929 SUPERVGUI_CanvasView* SUPERVGUI_Main::getCanvasView() {
930 Trace("SUPERVGUI_Main::getCanvasView")
931 return(myCanvasView);
934 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
935 Trace("SUPERVGUI_Main::getDataflow")
939 QAD_Message* SUPERVGUI_Main::getMessage() {
940 Trace("SUPERVGUI_Main::getMessage")
944 QAD_Study* SUPERVGUI_Main::getStudy() {
945 Trace("SUPERVGUI_Main::getStudy")
949 bool SUPERVGUI_Main::isArrayShown() {
950 Trace("SUPERVGUI_Main::isArrayShown")
951 return(myCurrentView == TABLE);
954 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
955 Trace("SUPERVGUI_Main::showPopup");
956 // To check is Supervision active?
957 if (myIsLocked) return;
958 //if (dataflow->IsExecuting()) return;
960 //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
961 if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
964 if (e->button() == RightButton) {
965 p->exec(e->globalPos());
971 void SUPERVGUI_Main::changeInformation() {
972 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
976 /* Trace("SUPERVGUI_Main::changeInformation")
977 if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
982 // returns false, if can't add dataflow into the study
983 bool SUPERVGUI_Main::addStudy() {
984 Trace("SUPERVGUI_Main::addStudy");
985 if (myIsFromStudy) return false;
986 if ((SUPERV_isNull(dataflow))) return false;
988 SALOMEDS::Study_var aStudy = study->getStudyDocument();
989 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
990 SALOMEDS::GenericAttribute_var anAttr;
991 SALOMEDS::AttributeName_var aName;
992 SALOMEDS::AttributeIOR_var anIORAttr;
993 SALOMEDS::AttributePixMap_var aPixmap;
994 bool aLocked = aStudy->GetProperties()->IsLocked();
995 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
997 // searching dataflow
998 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
999 if (aSO->_is_nil()) { // create new dataflow SObject
1000 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1001 if (aComponent->_is_nil()) { // is supervision component not found, then create it
1002 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
1003 anOperation->start();
1004 if (aLocked) aStudy->GetProperties()->SetLocked(false);
1005 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1006 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1007 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1008 //aName->SetValue(STUDY_SUPERVISION);
1009 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
1010 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1011 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1012 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1013 aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
1014 if (aLocked) aStudy->GetProperties()->SetLocked(true);
1015 anOperation->finish();
1018 aSO = aBuilder->NewObject(aComponent);
1019 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1020 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1021 aName->SetValue(dataflow->Name());
1022 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1023 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
1024 anIORAttr->SetValue(dataflow->getIOR());
1026 if (aLocked) return false;
1030 Supervision.unregisterGraph(this);
1031 Supervision.registerGraph(dataflow->getIOR(), this);
1032 myIsFromStudy = true;
1037 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
1038 Trace("SUPERVGUI_Main::chooseData")
1040 QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
1041 if (!id.isEmpty()) {
1042 SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
1043 SALOMEDS::GenericAttribute_var anAttr;
1044 SALOMEDS::AttributeIOR_var anIOR;
1045 Standard_CString ior = "";
1046 if (object->FindAttribute(anAttr, "AttributeIOR")) {
1047 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1048 ior = anIOR->Value();
1049 portIn->setValue(ior);
1053 setCursor(Supervision.getCursor());
1054 objectBrowser->setCursor(Supervision.getCursor());
1055 Supervision.putInfo("");
1061 void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
1062 Trace("SUPERVGUI_Main::setData")
1065 setCursor(forbiddenCursor);
1066 objectBrowser->setCursor(pointingHandCursor);
1067 Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
1070 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
1071 const SALOMEDS::SObject_var theSO,
1072 const char* theName,
1073 //QAD_Operation* theOperation,
1075 SALOMEDS::SObject_var aResult;
1076 SALOMEDS::AttributeName_var aName;
1077 SALOMEDS::GenericAttribute_var anAttr;
1078 if (!*theStarted) { // optimisation
1079 SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
1080 for (; anIterator->More(); anIterator->Next()) {
1081 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
1082 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1083 if (strcmp(aName->Value(), theName) == 0) {
1084 aResult = anIterator->Value();
1090 if (!aResult->_is_nil()) return aResult;
1092 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
1095 //theOperation->start();
1096 aBuilder->NewCommand();
1098 aResult = aBuilder->NewObject(theSO);
1099 anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
1100 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1101 aName->SetValue(theName);
1105 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
1106 Trace("SUPERVGUI_Main::putDataStudy");
1108 static bool isIn = false;
1109 if (isIn) return true; else isIn = true;
1111 SALOMEDS::Study_var aStudy = study->getStudyDocument();
1112 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
1113 SALOMEDS::GenericAttribute_var anAttr;
1114 SALOMEDS::AttributeName_var aName;
1115 SALOMEDS::AttributeIOR_var anIORAttr;
1116 SALOMEDS::AttributePixMap_var aPixmap;
1117 bool aTransaction = false;
1118 bool aLocked = aStudy->GetProperties()->IsLocked();
1119 // QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
1121 // searching dataflow
1122 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
1123 if (aSO->_is_nil()) { // create new dataflow SObject
1124 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
1125 if (aComponent->_is_nil()) { // is supervision component not found, then create it
1126 //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
1127 //anOperation->start();
1128 aBuilder->NewCommand();
1129 if (aLocked) aStudy->GetProperties()->SetLocked(false);
1130 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
1131 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
1132 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1133 //aName->SetValue(STUDY_SUPERVISION);
1134 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
1136 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
1137 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
1138 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
1139 aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
1140 if (aLocked) aStudy->GetProperties()->SetLocked(true);
1141 // anOperation->finish();
1142 aBuilder->CommitCommand();
1144 aTransaction = true;
1146 aBuilder->NewCommand();
1147 aSO = aBuilder->NewObject(aComponent);
1148 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
1149 aName = SALOMEDS::AttributeName::_narrow(anAttr);
1150 aName->SetValue(dataflow->Name());
1151 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1152 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
1153 anIORAttr->SetValue(dataflow->getIOR());
1155 //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
1156 aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO
1157 QString("Run ") + myRunTime.toString() /*, anOperation*/, &aTransaction);
1158 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name()/*, anOperation*/, &aTransaction); // get node SO
1159 aSO = SearchOrCreateSOWithName(aStudy, aSO, inout/*, anOperation*/, &aTransaction); // get in/out SO
1160 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name()/*, anOperation*/, &aTransaction); // get port SO
1163 if (aTransaction) aBuilder->CommitCommand();
1169 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
1170 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
1171 if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
1175 // set object value to the study: if object is external, then put it with
1176 // help of the specific component - owner
1178 // get according component driver for result object
1179 SALOME_LifeCycleCORBA aLCC(myNService);
1180 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
1181 if (!aFNode->_is_nil()) {
1182 Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
1183 aFNode->GetComponentName());
1184 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
1185 if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
1186 CORBA::Object_ptr anObject = new CORBA::Object();
1187 CORBA::Any* anAny = p->ToAny();
1188 (*anAny) >>= anObject;
1190 if (aDriver->CanPublishInStudy(anObject)) {
1191 SALOMEDS::SObject_var aTmpSO;
1192 if (!aTransaction) {
1194 aTransaction = true;
1196 aBuilder->NewCommand();
1198 aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
1199 aBuilder->Addreference(aSO, aTmpSO);
1200 } else { // can't publish object: abort transaction
1201 if (aTransaction) aBuilder->AbortCommand();
1206 } else { // component has no drivel, but could store IORs (like Calculator)
1207 SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString());
1208 if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO);
1212 if (!aTransaction) {
1213 aTransaction = true;
1215 aBuilder->NewCommand();
1217 anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
1222 aBuilder->CommitCommand();
1223 if (!myThread->running())
1224 study->updateObjBrowser();
1230 void SUPERVGUI_Main::ActivatePanning()
1232 if (graph->isVisible()) {
1233 graph->ActivatePanning();
1234 } else if (array->isVisible()) {
1235 array->ActivatePanning();
1236 } else if (myCanvasView->isVisible()) {
1237 myCanvasView->ActivatePanning();
1242 void SUPERVGUI_Main::ResetView()
1244 if (graph->isVisible()) {
1246 } else if (array->isVisible()) {
1248 } else if (myCanvasView->isVisible()) {
1249 myCanvasView->ResetView();
1254 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
1255 myIsFromStudy = theToStudy;
1256 graph->setAsFromStudy(theToStudy);
1257 array->setAsFromStudy(theToStudy);
1258 myCanvas->setAsFromStudy(theToStudy);
1261 void SUPERVGUI_Main::checkIsInStudy() {
1262 if (!myIsFromStudy) return;
1264 SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
1265 SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
1266 SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
1267 SALOMEDS::SObject_var aDataflowLbl;
1268 SALOMEDS::GenericAttribute_var anAttr;
1270 for (; aChildIterator->More(); aChildIterator->Next()) {
1271 aDataflowLbl = aChildIterator->Value();
1272 if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
1275 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1276 if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
1278 // This Graph considered as in study but in study it is not exists
1279 Supervision.unregisterGraph(this);
1280 setAsFromStudy(false);
1283 void SUPERVGUI_Main::syncNotification() {
1293 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1294 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
1296 mess += "NOTIF: "; mess += graph;
1297 mess += " / " ; mess += node;
1298 mess += " / " ; mess += type;
1299 mess += " / " ; mess += message;
1300 getMessage()->setMessage(mess.latin1());
1305 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1306 char* sender, long counter, char* date, long stamp) {
1307 Trace("SUPERVGUI_Main::isFiltered");
1309 if (strcmp(getDataflow()->Name(), graph) == 0) {
1311 QObjectList* nodes = queryList("SUPERVGUI_Node");
1312 QObjectListIt i(*nodes);
1313 while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
1315 if (strcmp(n->name(), node) == 0) {
1316 if (strcmp(type, NOTIF_WARNING) == 0) {
1318 } else if (strcmp(type, NOTIF_STEP) == 0) {
1320 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1322 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1329 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1330 fprintf( myLogFile, "NOTIF %ld\t%s\t%s\t%ld\t%s\t%s\t%s\t%s\n", stamp, date, sender, counter, graph, node, type, message );
1331 fflush( myLogFile );
1339 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1340 array->setPaletteBackgroundColor(color);
1341 graph->setPaletteBackgroundColor(color);
1342 myCanvas->setBackgroundColor(color);
1343 myCanvasView->setPaletteBackgroundColor(color.light());
1345 SUPERVGraph_View::setPaletteBackgroundColor(color);
1348 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1349 return myEventNodes;
1352 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1353 myEventNodes = theEventNodes;
1356 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1360 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1361 myStates = theStates;
1364 int SUPERVGUI_Main::getNodesNumber() {
1365 //create a list of nodes of the graph
1366 SUPERV_Nodes nodes = getDataflow()->Nodes();
1367 int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1368 nodes->INodes.length() + nodes->GNodes.length() +
1369 nodes->LNodes.length() + nodes->SNodes.length();
1373 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1377 void SUPERVGUI_Main::startTimer() {
1378 myTimer->start(500);
1381 void SUPERVGUI_Main::executionFinished() {
1382 getStudy()->updateObjBrowser();
1385 void SUPERVGUI_Main::checkExecution() {
1386 if (myThread->finished()) {
1388 executionFinished();
1392 /******************************* SUPERVGUI_Thread class ****************************************/
1393 SUPERVGUI_Thread::SUPERVGUI_Thread()
1399 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1401 //it is a virtual destructor and needs to be determine here
1404 void SUPERVGUI_Thread::startThread(const char* m)
1409 myMain->getMessage()->setMessage(m);
1414 void SUPERVGUI_Thread::stopThread(const char* m)
1416 myMain->getMessage()->setMessage(m);
1419 void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
1424 void SUPERVGUI_Thread::KillThread(bool theValue)
1427 myIsActive = !(theValue);
1431 typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyncEvent;
1433 void SUPERVGUI_Thread::run()
1435 SUPERV_CNode aNode = NULL;
1436 SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1437 SUPERV::GraphState aState = SUPERV::UndefinedState ;
1439 SUPERV_CNode aPrevNode = NULL;
1440 SUPERV::GraphEvent aPrevEvent = SUPERV::UndefinedEvent ;
1441 SUPERV::GraphState aPrevState = SUPERV::UndefinedState ;
1446 QPtrList< char * > anEventNodes;
1447 QPtrList< SUPERV::GraphState > aStates;
1449 myMain->startTimer();
1451 myMain->getDataflow()->Event(aNode, aEvent, aState);
1453 if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
1455 aEvent == SUPERV::NoEvent && aState == SUPERV::NoState
1457 aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) {
1458 if (myMain->getEventNodes().count()) {
1459 myMain->removeEventNodes();
1461 if (myMain->getStates().count()) {
1462 myMain->removeStates();
1467 if ( aNode != NULL) {
1468 aName = aNode->Name();
1471 if ( aPrevNode == NULL ) { //first initialize aPrev... variables
1472 anEventNodes = myMain->getEventNodes();
1473 anEventNodes.append( &aName ) ;
1474 myMain->setEventNodes(anEventNodes);
1476 aStates = myMain->getStates();
1477 aStates.append( &aState ) ;
1478 myMain->setStates(aStates);
1481 if ( aEvent == aPrevEvent && aState == aPrevState) {
1482 QString aNameStr = aName;
1483 QString aPrevNameStr = aPrevName;
1484 if ( aNameStr != aPrevNameStr ) {
1485 anEventNodes = myMain->getEventNodes();
1486 anEventNodes.append( &aName ) ;
1487 myMain->setEventNodes(anEventNodes);
1489 aStates = myMain->getStates();
1490 aStates.append( &aState ) ;
1491 myMain->setStates(aStates);
1495 anEventNodes = myMain->getEventNodes();
1496 anEventNodes.append( &aName ) ;
1497 myMain->setEventNodes(anEventNodes);
1499 aStates = myMain->getStates();
1500 aStates.append( &aState ) ;
1501 myMain->setStates(aStates);
1506 switch (myMain->getDataflow()->State()) {
1507 case SUPERV_Editing :
1508 stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
1511 case SUPERV_Suspend :
1512 stopThread(tr("MSG_GRAPH_SUSPENDED"));
1516 stopThread(tr("MSG_GRAPH_FINISHED"));
1520 stopThread(tr("MSG_GRAPH_ABORTED"));
1524 stopThread(tr("MSG_GRAPH_KILLED"));
1531 if (myMain->getEventNodes().count()) {
1532 //if list not empty call execute() -> sync()
1533 char * aNodeName = *(myMain->getEventNodes().getFirst());
1534 SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
1536 // It is PROHIBITED to deal with widgets in a secondary thread, so event posting is used here
1537 ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aNodeName, aNodeState ) );
1539 myMain->removeFirstEN();
1540 myMain->removeFirstS();
1545 aPrevEvent = aEvent;
1546 aPrevState = aState;
1547 aPrevName = aPrevNode->Name();
1552 // VSR: 04/12/03 ---> update object browser ufter finishing
1554 // myMain->getStudy()->updateObjBrowser();
1556 // VSR: 04/12/03 <---
1560 /******************************* SUPERVGUI_DSGraphParameters class ****************************************/
1564 SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters(SUPERV_Graph theGraph, bool isReadOnly)
1565 : QDialog( QAD_Application::getDesktop(), "", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1567 Trace("SUPERVGUI_DSGraphParameters::SUPERVGUI_DSGraphParameters");
1568 setCaption( tr( "TLT_DSGRAPHPARAMS" ) );
1569 setSizeGripEnabled( true );
1572 QGridLayout* TopLayout = new QGridLayout( this );
1573 TopLayout->setSpacing( 6 );
1574 TopLayout->setMargin( 11 );
1576 QGroupBox* TopGroup = new QGroupBox( this, "TopGroup" );
1577 TopGroup->setColumnLayout(0, Qt::Vertical );
1578 TopGroup->layout()->setSpacing( 0 );
1579 TopGroup->layout()->setMargin( 0 );
1580 QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
1581 TopGroupLayout->setAlignment( Qt::AlignTop );
1582 TopGroupLayout->setSpacing( 6 );
1583 TopGroupLayout->setMargin( 11 );
1586 QLabel* DeltaTimeL = new QLabel( tr( "DELTATIME_LBL" ), TopGroup );
1587 TopGroupLayout->addWidget( DeltaTimeL, 0, 0 );
1589 myDeltaTime = new QAD_SpinBoxDbl( TopGroup, 0.0, 1.0, 0.1);
1590 myDeltaTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1591 TopGroupLayout->addWidget( myDeltaTime, 0, 1 );
1594 QLabel* TimeOutL = new QLabel( tr( "TIMEOUT_LBL" ), TopGroup);
1595 TopGroupLayout->addWidget( TimeOutL, 1, 0 );
1597 myTimeOut = new QLineEdit( TopGroup );
1598 myTimeOut->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1599 myTimeOut->setValidator( new QIntValidator(this) );
1600 myTimeOut->setMinimumSize( 100, 0 );
1601 myTimeOut->setReadOnly( isReadOnly );
1602 TopGroupLayout->addWidget( myTimeOut, 1, 1 );
1605 QLabel* DataStreamTraceL = new QLabel( tr( "DATASTREAMTRACE_LBL" ), TopGroup);
1606 TopGroupLayout->addWidget( DataStreamTraceL, 2, 0 );
1608 myDataStreamTrace = new QComboBox( TopGroup );
1609 myDataStreamTrace->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1610 myDataStreamTrace->insertItem("WithoutTrace");
1611 myDataStreamTrace->insertItem("SummaryTrace");
1612 myDataStreamTrace->insertItem("DetailedTrace");
1613 TopGroupLayout->addWidget( myDataStreamTrace, 2, 1 );
1615 QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
1616 GroupButtons->setColumnLayout(0, Qt::Vertical );
1617 GroupButtons->layout()->setSpacing( 0 );
1618 GroupButtons->layout()->setMargin( 0 );
1619 QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
1620 GroupButtonsLayout->setAlignment( Qt::AlignTop );
1621 GroupButtonsLayout->setSpacing( 6 );
1622 GroupButtonsLayout->setMargin( 11 );
1624 QPushButton* okB = new QPushButton( tr( "BUT_OK" ), GroupButtons );
1625 QPushButton* cancelB = new QPushButton( tr( "BUT_CANCEL" ), GroupButtons );
1627 GroupButtonsLayout->addWidget( okB, 0, 0 );
1628 GroupButtonsLayout->addItem ( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
1629 GroupButtonsLayout->addWidget( cancelB, 0, 2 );
1631 TopLayout->addWidget( TopGroup, 0, 0 );
1632 TopLayout->addWidget( GroupButtons, 1, 0 );
1634 connect( okB, SIGNAL( clicked() ), this, SLOT( accept() ) );
1635 connect( cancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
1643 SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters() {
1644 Trace("SUPERVGUI_DSGraphParameters::~SUPERVGUI_DSGraphParameters");
1650 void SUPERVGUI_DSGraphParameters::setData() {
1653 SUPERV::KindOfDataStreamTrace aDataStreamTrace;
1655 // myGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1656 if (myGraph->IsStreamGraph()) {
1657 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1658 if (!SUPERV_isNull(aSGraph))
1659 aSGraph->StreamParams(aTimeOut, aDataStreamTrace, aDeltaTime);
1662 myDeltaTime->setValue(aDeltaTime);
1663 myTimeOut->setText(QString("%1").arg(aTimeOut));
1664 myDataStreamTrace->setCurrentItem((int)aDataStreamTrace);
1670 void SUPERVGUI_DSGraphParameters::accept() {
1671 // myGraph->SetStreamParams( myTimeOut->text().toLong(),
1672 // (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1673 // myDeltaTime->value());
1674 if (myGraph->IsStreamGraph()) {
1675 SUPERV_StreamGraph aSGraph = myGraph->ToStreamGraph();
1676 if (!SUPERV_isNull(aSGraph))
1677 aSGraph->SetStreamParams( myTimeOut->text().toLong(),
1678 (SUPERV::KindOfDataStreamTrace) myDataStreamTrace->currentItem(),
1679 myDeltaTime->value());