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"
53 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool fromIOR)
54 : SUPERVGraph_View(theParent),
57 myLogFileName( QString::null ),
64 Trace("SUPERVGUI_Main::SUPERVGUI_Main (new)");
65 theParent->setViewWidget(this);
67 //SUPERVGUI_Main* am = Supervision.getMain();
68 QAD_ObjectBrowser* ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
70 // ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
72 //ob = am->objectBrowser;
74 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(ob->getListView()->currentItem());
75 SALOMEDS::SObject_var obj = theDesktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
76 SALOMEDS::GenericAttribute_var anAttr;
77 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
78 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
79 Standard_CString ior = anIOR->Value();
80 dataflow = Supervision.getEngine()->getStreamGraph(ior);
81 if (SUPERV_isNull(dataflow)) {
82 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
88 QMessageBox::warning(0, tr("ERROR"), tr("MSG_NOACCESS_BY_IOR"));
92 dataflow = Supervision.getEngine()->StreamGraph(MAIN_NEW);
93 if (SUPERV_isNull(dataflow)) {
94 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
102 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool isModify, const char* f)
103 : SUPERVGraph_View(theParent),
106 myLogFileName( QString::null ),
113 Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
114 theParent->setViewWidget(this);
116 dataflow = Supervision.getEngine()->StreamGraph(f);
118 dataflow = Supervision.getEngine()->StreamGraphE(f);
120 if (SUPERV_isNull(dataflow)) {
121 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
128 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph cp)
129 : SUPERVGraph_View(theParent),
132 myLogFileName( QString::null ),
139 Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
140 theParent->setViewWidget(this);
141 // dataflow = cp->Copy();
143 if (SUPERV_isNull(dataflow)) {
144 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
151 void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
152 Trace("SUPERVGUI_Main::init");
153 if (theDesktop) myNService = theDesktop->getNameService();
159 myThread = new SUPERVGUI_Thread();
160 myThread->setMain(this);
161 connect(this, SIGNAL(KillMyThread(bool)), myThread, SLOT(KillThread(bool)));
164 //myIsRunned = false;
165 myCurrentView = GRAPH;
166 myIsFromStudy = false;
167 study = theDesktop->getActiveStudy();
169 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
170 bool aLocked = studyDoc->GetProperties()->IsLocked();
171 SALOMEDS::StudyBuilder_var builder = studyDoc->NewBuilder();
172 SALOMEDS::SComponent_var father = studyDoc->FindComponent(STUDY_SUPERVISION);
173 SALOMEDS::GenericAttribute_var anAttr;
174 SALOMEDS::AttributeName_var aName;
175 SALOMEDS::AttributePixMap_var aPixmap;
176 if (father->_is_nil()) {
177 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
179 if (aLocked) studyDoc->GetProperties()->SetLocked(false);
180 father = builder->NewComponent(STUDY_SUPERVISION);
181 anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
182 aName = SALOMEDS::AttributeName::_narrow(anAttr);
183 //aName->SetValue("Supervision");
184 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
186 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
187 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
188 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
190 builder->DefineComponentInstance(father, Supervision.getEngine());
191 if (aLocked) studyDoc->GetProperties()->SetLocked(true);
195 objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
198 graph = new SUPERVGUI_Graph(this);
199 array = new SUPERVGUI_Array(this);
201 message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
202 notification = new NOTIFICATION_Consumer();
204 QBoxLayout * layout = new QVBoxLayout(this);
205 layout->setMargin(0);
206 layout->setSpacing(0);
207 layout->addWidget(graph);
208 layout->addWidget(array);
212 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
213 myLogFile = fopen( myLogFileName.latin1(), "a" );
214 if ( myLogFile == NULL )
217 myTimer = new QTimer( this );
218 connect( myTimer, SIGNAL(timeout()), this, SLOT(checkExecution()) );
221 SUPERVGUI_Main::~SUPERVGUI_Main() {
222 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
223 if ( myLogFile != NULL) {
226 graph->removeLinks();
227 delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
228 if (!SUPERV_isNull(dataflow)) {
229 if (dataflow->IsExecuting()) {
230 if (QMessageBox::warning(QAD_Application::getDesktop(),
232 tr("MSG_DF_RUNNING"),
233 tr("MSG_DF_EXECUTION"),
234 tr("MSG_DF_KILL")) == 1) {
235 if (dataflow->Kill()) {
236 if (myThread->running())
241 emit KillMyThread(true);
242 if (myThread->running())
247 emit KillMyThread(true);
248 if (myThread->running())
254 void SUPERVGUI_Main::filterNotification() {
255 Trace("SUPERVGUI_Main::filterNotification");
256 SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
257 dlg->setFiltered( myFiltered );
258 dlg->setLogged( myLogged, myLogFileName );
259 dlg->setWarning( myWarning );
260 dlg->setStep( myStep );
261 dlg->setTrace( myTrace );
262 dlg->setVerbose( myVerbose );
263 if ( dlg->exec() == QDialog::Accepted ) {
264 myLogged = dlg->getLogged();
265 myLogFileName = dlg->getLogFile();
266 myFiltered = dlg->getFiltered();
267 myWarning = dlg->getWarning();
268 myStep = dlg->getStep();
269 myTrace = dlg->getTrace();
270 myVerbose = dlg->getVerbose();
272 if ( myLogFile != NULL) {
276 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
277 myLogFile = fopen( myLogFileName.latin1(), "a" );
278 if ( myLogFile == NULL ) {
280 QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
286 void SUPERVGUI_Main::changeDSGraphParameters() {
287 SUPERVGUI_DSGraphParameters* aDlg = new SUPERVGUI_DSGraphParameters(dataflow, dataflow->IsReadOnly());
293 void SUPERVGUI_Main::syncAsync() {
294 Trace("SUPERVGUI_Main::syncAsync")
295 QTimer::singleShot(1, this, SLOT(sync()));
300 * Called by thread when dataflow is executing
302 void SUPERVGUI_Main::execute(char * theNodeName, SUPERV::GraphState theNodeState) {
304 SUPERVGUI_Node* aNodePrs;
305 SUPERVGUI_GraphNode* aGraphNodePrs;
306 if (myCurrentView == TABLE) {
307 aNodePrs = (SUPERVGUI_Node*) array->child(theNodeName, "SUPERVGUI_Node");
308 aGraphNodePrs = (SUPERVGUI_GraphNode*) array->child(theNodeName, "SUPERVGUI_GraphNode");
310 aNodePrs = (SUPERVGUI_Node*) graph->child(theNodeName, "SUPERVGUI_Node");
311 aGraphNodePrs = (SUPERVGUI_GraphNode*) graph->child(theNodeName, "SUPERVGUI_GraphNode");
314 aGraphNodePrs->sync();
318 aNodePrs->syncOnEvent(theNodeState);
324 void SUPERVGUI_Main::sync() {
325 Trace("SUPERVGUI_Main::sync")
326 if ((SUPERV_isNull(dataflow))) return;
327 QString t = tr("GRAPH_TITLE");
329 t += dataflow->Name();
332 study->updateObjBrowser();
333 if (myCurrentView == TABLE) {
341 void SUPERVGUI_Main::showTable() {
342 if (myCurrentView == TABLE) return;
344 if (array->create()) {
345 myCurrentView = TABLE;
352 void SUPERVGUI_Main::showFullGraph() {
353 if (myCurrentView == TABLE) {
357 myCurrentView = GRAPH;
359 graph->setFullView();
363 void SUPERVGUI_Main::showContolFlow() {
364 if (myCurrentView == TABLE) {
368 myCurrentView = CONTROLFLOW;
370 graph->setControlView();
374 bool SUPERVGUI_Main::exportDataflow(QString theFile) {
375 Trace("SUPERVGUI_Main::exportDataflow");
376 if ((SUPERV_isNull(dataflow))) return false;
378 if (!theFile.isEmpty()) {
379 if (!dataflow->Export(theFile.latin1())) {
380 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
387 void SUPERVGUI_Main::insertFile() {
388 Trace("SUPERVGUI_Main::insertFile")
389 if ((SUPERV_isNull(dataflow))) return;
391 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
394 tr("MSG_GRAPH_INSERT"),
397 if (dataflow->Import(f.latin1())) {
398 if (myCurrentView == TABLE) {
404 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
409 void SUPERVGUI_Main::copy() {
410 Trace("SUPERVGUI_Main::copy");
411 if (dataflow->ThreadsMax() == 0) {
412 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
415 QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
416 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
417 (aStudyFrame->getRightFrame()->getViewFrame());
419 SUPERV_Graph aNewGraph = dataflow->StreamCopy();
420 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
421 aNewName += dataflow->Name();
422 aNewGraph->SetName(aNewName);
423 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
424 Supervision.getDesktop(),
426 study->showFrame(aStudyFrame);
430 void SUPERVGUI_Main::run() {
431 Trace("SUPERVGUI_Main::run")
432 if ((SUPERV_isNull(dataflow))) return;
434 if (dataflow->IsEditing()) {
435 if (!dataflow->IsValid()) {
436 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
437 } else if (!dataflow->IsExecutable()) {
438 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
439 } else if (graph->isAnyLinkCreating()) {
440 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
442 myRunTime = QDateTime::currentDateTime();
445 if (!dataflow->ReRun()) {
446 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
448 myThread->startThread(tr("MSG_GRAPH_STARTED"));
449 //syncNotification();
453 if (!dataflow->Run()) {
454 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
456 myThread->startThread(tr("MSG_GRAPH_STARTED"));
457 //syncNotification();
464 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
470 void SUPERVGUI_Main::startExecute() {
471 Trace("SUPERVGUI_Main::startExecute")
472 if ((SUPERV_isNull(dataflow))) return;
474 if (dataflow->IsEditing()) {
475 if (!dataflow->IsValid()) {
476 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
477 } else if (!dataflow->IsExecutable()) {
478 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
479 } else if (graph->isAnyLinkCreating()) {
480 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
482 myRunTime = QDateTime::currentDateTime();
485 if (!dataflow->ReStart()) {
486 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
488 myThread->startThread(tr("MSG_GRAPH_STARTED"));
489 //syncNotification();
493 if (!dataflow->Start()) {
494 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
496 myThread->startThread(tr("MSG_GRAPH_STARTED"));
497 //syncNotification();
502 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
507 void SUPERVGUI_Main::kill() {
508 Trace("SUPERVGUI_Main::kill")
509 if ((SUPERV_isNull(dataflow))) return;
511 if (dataflow->IsEditing()) {
512 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
513 } else if (dataflow->Kill()) {
515 myThread->stopThread(tr("MSG_GRAPH_KILLED"));
518 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
522 void SUPERVGUI_Main::suspendResume() {
523 Trace("SUPERVGUI_Main::suspendResume")
524 if ((SUPERV_isNull(dataflow))) return;
526 if (dataflow->IsEditing()) {
527 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
528 } else if (dataflow->State() == SUPERV_Suspend) {
529 if (dataflow->Resume()) {
530 myThread->startThread(tr("MSG_DF_RESUMED"));
532 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
535 if (dataflow->Suspend()) {
537 myThread->stopThread(tr("MSG_GRAPH_SUSPENDED"));
539 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
544 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
545 Trace("SUPERVGUI_Main::stopRestart")
546 if ((SUPERV_isNull(dataflow))) return;
548 if (dataflow->IsEditing()) {
549 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
550 } else if (dataflow->State() == SUPERV_Stop) {
551 if (dataflow->ReStart()) {
552 message->setMessage(tr("MSG_DF_RESTARTED"));
555 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
558 if (dataflow->Stop()) {
561 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
566 void SUPERVGUI_Main::addNode() {
567 Trace("SUPERVGUI_Main::addNode");
568 if (SUPERV_isNull(dataflow)) return;
570 if (dataflow->IsExecuting()) {
571 if (QMessageBox::warning(QAD_Application::getDesktop(),
572 tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
573 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
579 Supervision.getBrowser()->choose();
585 * Add Computation node
587 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
588 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
589 switch (myCurrentView) {
592 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
593 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
594 graph->addChild(aNode, theNode->X(), theNode->Y());
600 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
602 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
603 graph->addChild(aNode, theNode->X(), theNode->Y());
617 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
618 switch (myCurrentView) {
621 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
622 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
623 graph->addChild(aNode, theNode->X(), theNode->Y());
629 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
631 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
632 graph->addChild(aNode, theNode->X(), theNode->Y());
646 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
647 switch (myCurrentView) {
650 SUPERVGUI_StartControlNode* aStartPrs =
651 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
652 SUPERVGUI_EndControlNode* aEndPrs =
653 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
655 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
656 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
657 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
658 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
660 aStartPrs->updateLinksPrs();
661 aEndPrs->updateLinksPrs();
665 graph->repaintContents();
670 SUPERVGUI_StartControlNode* aStartPrs =
671 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
672 SUPERVGUI_EndControlNode* aEndPrs =
673 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
675 aStartPrs->hideAll();
678 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
679 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
680 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
681 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
683 aStartPrs->updateLinksPrs();
684 aEndPrs->updateLinksPrs();
688 graph->repaintContents();
700 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
701 Trace("SUPERVGUI_Main::getGraph")
705 SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
706 Trace("SUPERVGUI_Main::getArray")
710 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
711 Trace("SUPERVGUI_Main::getDataflow")
715 QAD_Message* SUPERVGUI_Main::getMessage() {
716 Trace("SUPERVGUI_Main::getMessage")
720 QAD_Study* SUPERVGUI_Main::getStudy() {
721 Trace("SUPERVGUI_Main::getStudy")
725 bool SUPERVGUI_Main::isArrayShown() {
726 Trace("SUPERVGUI_Main::isArrayShown")
727 return(myCurrentView == TABLE);
730 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
731 Trace("SUPERVGUI_Main::showPopup");
732 // To check is Supervision active?
733 if (myIsLocked) return;
734 if (dataflow->IsExecuting()) return;
736 //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
737 if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
740 if (e->button() == RightButton) {
741 p->exec(e->globalPos());
747 void SUPERVGUI_Main::changeInformation() {
748 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
752 /* Trace("SUPERVGUI_Main::changeInformation")
753 if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
758 // returns false, if can't add dataflow into the study
759 bool SUPERVGUI_Main::addStudy() {
760 Trace("SUPERVGUI_Main::addStudy");
761 if (myIsFromStudy) return false;
762 if ((SUPERV_isNull(dataflow))) return false;
764 SALOMEDS::Study_var aStudy = study->getStudyDocument();
765 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
766 SALOMEDS::GenericAttribute_var anAttr;
767 SALOMEDS::AttributeName_var aName;
768 SALOMEDS::AttributeIOR_var anIORAttr;
769 SALOMEDS::AttributePixMap_var aPixmap;
770 bool aLocked = aStudy->GetProperties()->IsLocked();
771 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
773 // searching dataflow
774 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
775 if (aSO->_is_nil()) { // create new dataflow SObject
776 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
777 if (aComponent->_is_nil()) { // is supervision component not found, then create it
778 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
779 anOperation->start();
780 if (aLocked) aStudy->GetProperties()->SetLocked(false);
781 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
782 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
783 aName = SALOMEDS::AttributeName::_narrow(anAttr);
784 //aName->SetValue(STUDY_SUPERVISION);
785 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
786 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
787 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
788 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
789 aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
790 if (aLocked) aStudy->GetProperties()->SetLocked(true);
791 anOperation->finish();
794 aSO = aBuilder->NewObject(aComponent);
795 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
796 aName = SALOMEDS::AttributeName::_narrow(anAttr);
797 aName->SetValue(dataflow->Name());
798 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
799 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
800 anIORAttr->SetValue(dataflow->getIOR());
802 if (aLocked) return false;
806 Supervision.unregisterGraph(this);
807 Supervision.registerGraph(dataflow->getIOR(), this);
808 myIsFromStudy = true;
813 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
814 Trace("SUPERVGUI_Main::chooseData")
816 QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
818 SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
819 SALOMEDS::GenericAttribute_var anAttr;
820 SALOMEDS::AttributeIOR_var anIOR;
821 Standard_CString ior = "";
822 if (object->FindAttribute(anAttr, "AttributeIOR")) {
823 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
824 ior = anIOR->Value();
825 portIn->setValue(ior);
829 setCursor(Supervision.getCursor());
830 objectBrowser->setCursor(Supervision.getCursor());
831 Supervision.putInfo("");
837 void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
838 Trace("SUPERVGUI_Main::setData")
841 setCursor(forbiddenCursor);
842 objectBrowser->setCursor(pointingHandCursor);
843 Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
846 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
847 const SALOMEDS::SObject_var theSO,
849 //QAD_Operation* theOperation,
851 SALOMEDS::SObject_var aResult;
852 SALOMEDS::AttributeName_var aName;
853 SALOMEDS::GenericAttribute_var anAttr;
854 if (!*theStarted) { // optimisation
855 SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
856 for (; anIterator->More(); anIterator->Next()) {
857 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
858 aName = SALOMEDS::AttributeName::_narrow(anAttr);
859 if (strcmp(aName->Value(), theName) == 0) {
860 aResult = anIterator->Value();
866 if (!aResult->_is_nil()) return aResult;
868 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
871 //theOperation->start();
872 aBuilder->NewCommand();
874 aResult = aBuilder->NewObject(theSO);
875 anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
876 aName = SALOMEDS::AttributeName::_narrow(anAttr);
877 aName->SetValue(theName);
881 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
882 Trace("SUPERVGUI_Main::putDataStudy");
884 static bool isIn = false;
885 if (isIn) return true; else isIn = true;
887 SALOMEDS::Study_var aStudy = study->getStudyDocument();
888 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
889 SALOMEDS::GenericAttribute_var anAttr;
890 SALOMEDS::AttributeName_var aName;
891 SALOMEDS::AttributeIOR_var anIORAttr;
892 SALOMEDS::AttributePixMap_var aPixmap;
893 bool aTransaction = false;
894 bool aLocked = aStudy->GetProperties()->IsLocked();
895 // QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
897 // searching dataflow
898 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
899 if (aSO->_is_nil()) { // create new dataflow SObject
900 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
901 if (aComponent->_is_nil()) { // is supervision component not found, then create it
902 //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
903 //anOperation->start();
904 aBuilder->NewCommand();
905 if (aLocked) aStudy->GetProperties()->SetLocked(false);
906 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
907 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
908 aName = SALOMEDS::AttributeName::_narrow(anAttr);
909 //aName->SetValue(STUDY_SUPERVISION);
910 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
912 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
913 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
914 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
915 aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
916 if (aLocked) aStudy->GetProperties()->SetLocked(true);
917 // anOperation->finish();
918 aBuilder->CommitCommand();
922 aBuilder->NewCommand();
923 aSO = aBuilder->NewObject(aComponent);
924 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
925 aName = SALOMEDS::AttributeName::_narrow(anAttr);
926 aName->SetValue(dataflow->Name());
927 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
928 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
929 anIORAttr->SetValue(dataflow->getIOR());
931 //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
932 aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO
933 QString("Run ") + myRunTime.toString() /*, anOperation*/, &aTransaction);
934 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name()/*, anOperation*/, &aTransaction); // get node SO
935 aSO = SearchOrCreateSOWithName(aStudy, aSO, inout/*, anOperation*/, &aTransaction); // get in/out SO
936 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name()/*, anOperation*/, &aTransaction); // get port SO
939 if (aTransaction) aBuilder->CommitCommand();
945 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
946 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
947 if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
951 // set object value to the study: if object is external, then put it with
952 // help of the specific component - owner
954 // get according component driver for result object
955 SALOME_LifeCycleCORBA aLCC(myNService);
956 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
957 if (!aFNode->_is_nil()) {
958 Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
959 aFNode->GetComponentName());
960 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
961 if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
962 CORBA::Object_ptr anObject = new CORBA::Object();
963 CORBA::Any* anAny = p->ToAny();
964 (*anAny) >>= anObject;
966 if (aDriver->CanPublishInStudy(anObject)) {
967 SALOMEDS::SObject_var aTmpSO;
972 aBuilder->NewCommand();
974 aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
975 aBuilder->Addreference(aSO, aTmpSO);
976 } else { // can't publish object: abort transaction
977 if (aTransaction) aBuilder->AbortCommand();
982 } else { // component has no drivel, but could store IORs (like Calculator)
983 SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString());
984 if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO);
991 aBuilder->NewCommand();
993 anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
998 aBuilder->CommitCommand();
999 if (!myThread->running())
1000 study->updateObjBrowser();
1006 void SUPERVGUI_Main::ActivatePanning()
1008 if (graph->isVisible()) {
1009 graph->ActivatePanning();
1010 } else if (array->isVisible()) {
1011 array->ActivatePanning();
1016 void SUPERVGUI_Main::ResetView()
1018 if (graph->isVisible()) {
1020 } else if (array->isVisible()) {
1026 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
1027 myIsFromStudy = theToStudy;
1028 graph->setAsFromStudy(theToStudy);
1029 array->setAsFromStudy(theToStudy);
1032 void SUPERVGUI_Main::checkIsInStudy() {
1033 if (!myIsFromStudy) return;
1035 SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
1036 SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
1037 SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
1038 SALOMEDS::SObject_var aDataflowLbl;
1039 SALOMEDS::GenericAttribute_var anAttr;
1041 for (; aChildIterator->More(); aChildIterator->Next()) {
1042 aDataflowLbl = aChildIterator->Value();
1043 if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
1046 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1047 if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
1049 // This Graph considered as in study but in study it is not exists
1050 Supervision.unregisterGraph(this);
1051 setAsFromStudy(false);
1054 void SUPERVGUI_Main::syncNotification() {
1064 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1065 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
1067 mess += "NOTIF: "; mess += graph;
1068 mess += " / " ; mess += node;
1069 mess += " / " ; mess += type;
1070 mess += " / " ; mess += message;
1071 getMessage()->setMessage(mess.latin1());
1076 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1077 char* sender, long counter, char* date, long stamp) {
1078 Trace("SUPERVGUI_Main::isFiltered");
1080 if (strcmp(getDataflow()->Name(), graph) == 0) {
1082 QObjectList* nodes = queryList("SUPERVGUI_Node");
1083 QObjectListIt i(*nodes);
1084 while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
1086 if (strcmp(n->name(), node) == 0) {
1087 if (strcmp(type, NOTIF_WARNING) == 0) {
1089 } else if (strcmp(type, NOTIF_STEP) == 0) {
1091 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1093 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1100 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1101 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 );
1102 fflush( myLogFile );
1110 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1111 array->setPaletteBackgroundColor(color);
1112 graph->setPaletteBackgroundColor(color);
1114 SUPERVGraph_View::setPaletteBackgroundColor(color);
1117 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1118 return myEventNodes;
1121 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1122 myEventNodes = theEventNodes;
1125 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1129 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1130 myStates = theStates;
1133 int SUPERVGUI_Main::getNodesNumber() {
1134 //create a list of nodes of the graph
1135 SUPERV_Nodes nodes = getDataflow()->Nodes();
1136 int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1137 nodes->INodes.length() + nodes->GNodes.length() +
1138 nodes->LNodes.length() + nodes->SNodes.length();
1142 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1146 void SUPERVGUI_Main::startTimer() {
1147 myTimer->start(500);
1150 void SUPERVGUI_Main::executionFinished() {
1151 getStudy()->updateObjBrowser();
1154 void SUPERVGUI_Main::checkExecution() {
1155 if (myThread->finished()) {
1157 executionFinished();
1161 /******************************* SUPERVGUI_Thread class ****************************************/
1162 SUPERVGUI_Thread::SUPERVGUI_Thread()
1168 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1170 //it is a virtual destructor and needs to be determine here
1173 void SUPERVGUI_Thread::startThread(const char* m)
1178 myMain->getMessage()->setMessage(m);
1183 void SUPERVGUI_Thread::stopThread(const char* m)
1185 myMain->getMessage()->setMessage(m);
1188 void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
1193 void SUPERVGUI_Thread::KillThread(bool theValue)
1196 myIsActive = !(theValue);
1200 typedef TVoidMemFun2ArgEvent<SUPERVGUI_Main, char*, SUPERV::GraphState> TNodeSyncEvent;
1202 void SUPERVGUI_Thread::run()
1204 SUPERV_CNode aNode = NULL;
1205 SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1206 SUPERV::GraphState aState = SUPERV::UndefinedState ;
1208 SUPERV_CNode aPrevNode = NULL;
1209 SUPERV::GraphEvent aPrevEvent = SUPERV::UndefinedEvent ;
1210 SUPERV::GraphState aPrevState = SUPERV::UndefinedState ;
1215 QPtrList< char * > anEventNodes;
1216 QPtrList< SUPERV::GraphState > aStates;
1218 myMain->startTimer();
1220 myMain->getDataflow()->Event(aNode, aEvent, aState);
1222 if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
1224 aEvent == SUPERV::NoEvent && aState == SUPERV::NoState
1226 aEvent == SUPERV::KillEvent && aState == SUPERV::KillState) {
1227 if (myMain->getEventNodes().count()) {
1228 myMain->removeEventNodes();
1230 if (myMain->getStates().count()) {
1231 myMain->removeStates();
1236 if ( aNode != NULL) {
1237 aName = aNode->Name();
1240 if ( aPrevNode == NULL ) { //first initialize aPrev... variables
1241 anEventNodes = myMain->getEventNodes();
1242 anEventNodes.append( &aName ) ;
1243 myMain->setEventNodes(anEventNodes);
1245 aStates = myMain->getStates();
1246 aStates.append( &aState ) ;
1247 myMain->setStates(aStates);
1250 if ( aEvent == aPrevEvent && aState == aPrevState) {
1251 QString aNameStr = aName;
1252 QString aPrevNameStr = aPrevName;
1253 if ( aNameStr != aPrevNameStr ) {
1254 anEventNodes = myMain->getEventNodes();
1255 anEventNodes.append( &aName ) ;
1256 myMain->setEventNodes(anEventNodes);
1258 aStates = myMain->getStates();
1259 aStates.append( &aState ) ;
1260 myMain->setStates(aStates);
1264 anEventNodes = myMain->getEventNodes();
1265 anEventNodes.append( &aName ) ;
1266 myMain->setEventNodes(anEventNodes);
1268 aStates = myMain->getStates();
1269 aStates.append( &aState ) ;
1270 myMain->setStates(aStates);
1275 switch (myMain->getDataflow()->State()) {
1276 case SUPERV_Editing :
1277 stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
1280 case SUPERV_Suspend :
1281 stopThread(tr("MSG_GRAPH_SUSPENDED"));
1285 stopThread(tr("MSG_GRAPH_FINISHED"));
1289 stopThread(tr("MSG_GRAPH_ABORTED"));
1293 stopThread(tr("MSG_GRAPH_KILLED"));
1300 if (myMain->getEventNodes().count()) {
1301 //if list not empty call execute() -> sync()
1302 char * aNodeName = *(myMain->getEventNodes().getFirst());
1303 SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
1305 // It is PROHIBITED to deal with widgets in a secondary thread, so event posting is used here
1306 ProcessVoidEvent( new TNodeSyncEvent( myMain, &SUPERVGUI_Main::execute, aNodeName, aNodeState ) );
1308 myMain->removeFirstEN();
1309 myMain->removeFirstS();
1313 aPrevEvent = aEvent;
1314 aPrevState = aState;
1315 aPrevName = aPrevNode->Name();
1320 // VSR: 04/12/03 ---> update object browser ufter finishing
1322 // myMain->getStudy()->updateObjBrowser();
1324 // VSR: 04/12/03 <---