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 "SUPERVGraph_ViewFrame.h"
42 #include "SUPERVGUI_Main.h"
43 #include "SUPERVGUI.h"
44 #include "SUPERVGUI_ComputeNode.h"
45 #include "SUPERVGUI_ControlNode.h"
46 #include "NOTIFICATION.hxx"
47 #include "SUPERVGUI_Notification.h"
48 #include "SALOMEGUI_ImportOperation.h"
49 #include "SUPERVGUI_Information.h"
52 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool fromIOR)
53 : SUPERVGraph_View(theParent),
56 myLogFileName( QString::null ),
63 Trace("SUPERVGUI_Main::SUPERVGUI_Main (new)");
64 theParent->setViewWidget(this);
66 //SUPERVGUI_Main* am = Supervision.getMain();
67 QAD_ObjectBrowser* ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
69 // ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
71 //ob = am->objectBrowser;
73 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(ob->getListView()->currentItem());
74 SALOMEDS::SObject_var obj = theDesktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
75 SALOMEDS::GenericAttribute_var anAttr;
76 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
77 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
78 Standard_CString ior = anIOR->Value();
79 dataflow = Supervision.getEngine()->getStreamGraph(ior);
80 if (SUPERV_isNull(dataflow)) {
81 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
87 QMessageBox::warning(0, tr("ERROR"), tr("MSG_NOACCESS_BY_IOR"));
91 dataflow = Supervision.getEngine()->StreamGraph(MAIN_NEW);
92 if (SUPERV_isNull(dataflow)) {
93 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
101 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool isModify, const char* f)
102 : SUPERVGraph_View(theParent),
105 myLogFileName( QString::null ),
112 Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
113 theParent->setViewWidget(this);
115 dataflow = Supervision.getEngine()->StreamGraph(f);
117 dataflow = Supervision.getEngine()->StreamGraphE(f);
119 if (SUPERV_isNull(dataflow)) {
120 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
127 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph cp)
128 : SUPERVGraph_View(theParent),
131 myLogFileName( QString::null ),
138 Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
139 theParent->setViewWidget(this);
140 // dataflow = cp->Copy();
142 if (SUPERV_isNull(dataflow)) {
143 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
150 void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
151 Trace("SUPERVGUI_Main::init");
152 if (theDesktop) myNService = theDesktop->getNameService();
158 myThread = new SUPERVGUI_Thread();
159 myThread->setMain(this);
162 //myIsRunned = false;
163 myCurrentView = GRAPH;
164 myIsFromStudy = false;
165 study = theDesktop->getActiveStudy();
167 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
168 bool aLocked = studyDoc->GetProperties()->IsLocked();
169 SALOMEDS::StudyBuilder_var builder = studyDoc->NewBuilder();
170 SALOMEDS::SComponent_var father = studyDoc->FindComponent(STUDY_SUPERVISION);
171 SALOMEDS::GenericAttribute_var anAttr;
172 SALOMEDS::AttributeName_var aName;
173 SALOMEDS::AttributePixMap_var aPixmap;
174 if (father->_is_nil()) {
175 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
177 if (aLocked) studyDoc->GetProperties()->SetLocked(false);
178 father = builder->NewComponent(STUDY_SUPERVISION);
179 anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
180 aName = SALOMEDS::AttributeName::_narrow(anAttr);
181 //aName->SetValue("Supervision");
182 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
184 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
185 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
186 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
188 builder->DefineComponentInstance(father, Supervision.getEngine());
189 if (aLocked) studyDoc->GetProperties()->SetLocked(true);
193 objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
196 graph = new SUPERVGUI_Graph(this);
197 array = new SUPERVGUI_Array(this);
199 message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
200 notification = new NOTIFICATION_Consumer();
202 QBoxLayout * layout = new QVBoxLayout(this);
203 layout->setMargin(0);
204 layout->setSpacing(0);
205 layout->addWidget(graph);
206 layout->addWidget(array);
210 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
211 myLogFile = fopen( myLogFileName.latin1(), "a" );
212 if ( myLogFile == NULL )
215 myTimer = new QTimer( this );
216 connect( myTimer, SIGNAL(timeout()), this, SLOT(checkExecution()) );
219 SUPERVGUI_Main::~SUPERVGUI_Main() {
220 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
221 if ( myLogFile != NULL) {
224 graph->removeLinks();
225 delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
226 if (!SUPERV_isNull(dataflow)) {
227 if (dataflow->IsExecuting()) {
228 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
229 tr("MSG_DF_RUNNING"),
230 tr("MSG_DF_EXECUTION"),
231 tr("MSG_DF_KILL")) == 1) {
238 void SUPERVGUI_Main::filterNotification() {
239 Trace("SUPERVGUI_Main::filterNotification");
240 SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
241 dlg->setFiltered( myFiltered );
242 dlg->setLogged( myLogged, myLogFileName );
243 dlg->setWarning( myWarning );
244 dlg->setStep( myStep );
245 dlg->setTrace( myTrace );
246 dlg->setVerbose( myVerbose );
247 if ( dlg->exec() == QDialog::Accepted ) {
248 myLogged = dlg->getLogged();
249 myLogFileName = dlg->getLogFile();
250 myFiltered = dlg->getFiltered();
251 myWarning = dlg->getWarning();
252 myStep = dlg->getStep();
253 myTrace = dlg->getTrace();
254 myVerbose = dlg->getVerbose();
256 if ( myLogFile != NULL) {
260 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
261 myLogFile = fopen( myLogFileName.latin1(), "a" );
262 if ( myLogFile == NULL ) {
264 QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
270 void SUPERVGUI_Main::syncAsync() {
271 Trace("SUPERVGUI_Main::syncAsync")
272 QTimer::singleShot(1, this, SLOT(sync()));
277 * Called by thread when dataflow is executing
279 void SUPERVGUI_Main::execute(char * theNodeName, SUPERV::GraphState theNodeState) {
281 SUPERVGUI_Node* aNodePrs;
282 SUPERVGUI_GraphNode* aGraphNodePrs;
283 if (myCurrentView == TABLE) {
284 aNodePrs = (SUPERVGUI_Node*) array->child(theNodeName, "SUPERVGUI_Node");
285 aGraphNodePrs = (SUPERVGUI_GraphNode*) array->child(theNodeName, "SUPERVGUI_GraphNode");
287 aNodePrs = (SUPERVGUI_Node*) graph->child(theNodeName, "SUPERVGUI_Node");
288 aGraphNodePrs = (SUPERVGUI_GraphNode*) graph->child(theNodeName, "SUPERVGUI_GraphNode");
291 aGraphNodePrs->sync();
295 aNodePrs->syncOnEvent(theNodeState);
301 void SUPERVGUI_Main::sync() {
302 Trace("SUPERVGUI_Main::sync")
303 if ((SUPERV_isNull(dataflow))) return;
304 QString t = tr("GRAPH_TITLE");
306 t += dataflow->Name();
309 study->updateObjBrowser();
310 if (myCurrentView == TABLE) {
318 void SUPERVGUI_Main::showTable() {
319 if (myCurrentView == TABLE) return;
321 if (array->create()) {
322 myCurrentView = TABLE;
329 void SUPERVGUI_Main::showFullGraph() {
330 if (myCurrentView == TABLE) {
334 myCurrentView = GRAPH;
336 graph->setFullView();
340 void SUPERVGUI_Main::showContolFlow() {
341 if (myCurrentView == TABLE) {
345 myCurrentView = CONTROLFLOW;
347 graph->setControlView();
351 bool SUPERVGUI_Main::exportDataflow(QString theFile) {
352 Trace("SUPERVGUI_Main::exportDataflow");
353 if ((SUPERV_isNull(dataflow))) return false;
355 if (!theFile.isEmpty()) {
356 if (!dataflow->Export(theFile.latin1())) {
357 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
364 void SUPERVGUI_Main::insertFile() {
365 Trace("SUPERVGUI_Main::insertFile")
366 if ((SUPERV_isNull(dataflow))) return;
368 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
371 tr("MSG_GRAPH_INSERT"),
374 if (dataflow->Import(f.latin1())) {
375 if (myCurrentView == TABLE) {
381 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
386 void SUPERVGUI_Main::copy() {
387 Trace("SUPERVGUI_Main::copy");
388 if (dataflow->ThreadsMax() == 0) {
389 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
392 QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
393 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
394 (aStudyFrame->getRightFrame()->getViewFrame());
396 SUPERV_Graph aNewGraph = dataflow->StreamCopy();
397 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
398 aNewName += dataflow->Name();
399 aNewGraph->SetName(aNewName);
400 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
401 Supervision.getDesktop(),
403 study->showFrame(aStudyFrame);
407 void SUPERVGUI_Main::run() {
408 Trace("SUPERVGUI_Main::run")
409 if ((SUPERV_isNull(dataflow))) return;
411 if (dataflow->IsEditing()) {
412 if (!dataflow->IsValid()) {
413 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
414 } else if (!dataflow->IsExecutable()) {
415 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
416 } else if (graph->isAnyLinkCreating()) {
417 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
419 myRunTime = QDateTime::currentDateTime();
422 if (!dataflow->ReRun()) {
423 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
425 myThread->startThread(tr("MSG_GRAPH_STARTED"));
426 //syncNotification();
430 if (!dataflow->Run()) {
431 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
433 myThread->startThread(tr("MSG_GRAPH_STARTED"));
434 //syncNotification();
441 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
447 void SUPERVGUI_Main::startExecute() {
448 Trace("SUPERVGUI_Main::startExecute")
449 if ((SUPERV_isNull(dataflow))) return;
451 if (dataflow->IsEditing()) {
452 if (!dataflow->IsValid()) {
453 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
454 } else if (!dataflow->IsExecutable()) {
455 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
456 } else if (graph->isAnyLinkCreating()) {
457 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
459 myRunTime = QDateTime::currentDateTime();
462 if (!dataflow->ReStart()) {
463 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
465 myThread->startThread(tr("MSG_GRAPH_STARTED"));
466 //syncNotification();
470 if (!dataflow->Start()) {
471 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
473 myThread->startThread(tr("MSG_GRAPH_STARTED"));
474 //syncNotification();
479 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
484 void SUPERVGUI_Main::kill() {
485 Trace("SUPERVGUI_Main::kill")
486 if ((SUPERV_isNull(dataflow))) return;
488 if (dataflow->IsEditing()) {
489 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
490 } else if (dataflow->Kill()) {
492 myThread->stopThread(tr("MSG_GRAPH_KILLED"));
495 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
499 void SUPERVGUI_Main::suspendResume() {
500 Trace("SUPERVGUI_Main::suspendResume")
501 if ((SUPERV_isNull(dataflow))) return;
503 if (dataflow->IsEditing()) {
504 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
505 } else if (dataflow->State() == SUPERV_Suspend) {
506 if (dataflow->Resume()) {
507 myThread->startThread(tr("MSG_DF_RESUMED"));
509 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
512 if (dataflow->Suspend()) {
514 myThread->stopThread(tr("MSG_GRAPH_SUSPENDED"));
516 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
521 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
522 Trace("SUPERVGUI_Main::stopRestart")
523 if ((SUPERV_isNull(dataflow))) return;
525 if (dataflow->IsEditing()) {
526 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
527 } else if (dataflow->State() == SUPERV_Stop) {
528 if (dataflow->ReStart()) {
529 message->setMessage(tr("MSG_DF_RESTARTED"));
532 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
535 if (dataflow->Stop()) {
538 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
543 void SUPERVGUI_Main::addNode() {
544 Trace("SUPERVGUI_Main::addNode");
545 if (SUPERV_isNull(dataflow)) return;
547 if (dataflow->IsExecuting()) {
548 if (QMessageBox::warning(QAD_Application::getDesktop(),
549 tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
550 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
556 Supervision.getBrowser()->choose();
562 * Add Computation node
564 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
565 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
566 switch (myCurrentView) {
569 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
570 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
571 graph->addChild(aNode, theNode->X(), theNode->Y());
577 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
579 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
580 graph->addChild(aNode, theNode->X(), theNode->Y());
594 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
595 switch (myCurrentView) {
598 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
599 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
600 graph->addChild(aNode, theNode->X(), theNode->Y());
606 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
608 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
609 graph->addChild(aNode, theNode->X(), theNode->Y());
623 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
624 switch (myCurrentView) {
627 SUPERVGUI_StartControlNode* aStartPrs =
628 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
629 SUPERVGUI_EndControlNode* aEndPrs =
630 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
632 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
633 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
634 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
635 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
637 aStartPrs->updateLinksPrs();
638 aEndPrs->updateLinksPrs();
642 graph->repaintContents();
647 SUPERVGUI_StartControlNode* aStartPrs =
648 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
649 SUPERVGUI_EndControlNode* aEndPrs =
650 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
652 aStartPrs->hideAll();
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();
677 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
678 Trace("SUPERVGUI_Main::getGraph")
682 SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
683 Trace("SUPERVGUI_Main::getArray")
687 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
688 Trace("SUPERVGUI_Main::getDataflow")
692 QAD_Message* SUPERVGUI_Main::getMessage() {
693 Trace("SUPERVGUI_Main::getMessage")
697 QAD_Study* SUPERVGUI_Main::getStudy() {
698 Trace("SUPERVGUI_Main::getStudy")
702 bool SUPERVGUI_Main::isArrayShown() {
703 Trace("SUPERVGUI_Main::isArrayShown")
704 return(myCurrentView == TABLE);
707 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
708 Trace("SUPERVGUI_Main::showPopup");
709 // To check is Supervision active?
710 if (myIsLocked) return;
712 //if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
713 if (QAD_Application::getDesktop()->getActiveComponent().compare(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
716 if (e->button() == RightButton) {
717 p->exec(e->globalPos());
723 void SUPERVGUI_Main::changeInformation() {
724 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
728 /* Trace("SUPERVGUI_Main::changeInformation")
729 if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
734 // returns false, if can't add dataflow into the study
735 bool SUPERVGUI_Main::addStudy() {
736 Trace("SUPERVGUI_Main::addStudy");
737 if (myIsFromStudy) return false;
738 if ((SUPERV_isNull(dataflow))) return false;
740 SALOMEDS::Study_var aStudy = study->getStudyDocument();
741 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
742 SALOMEDS::GenericAttribute_var anAttr;
743 SALOMEDS::AttributeName_var aName;
744 SALOMEDS::AttributeIOR_var anIORAttr;
745 SALOMEDS::AttributePixMap_var aPixmap;
746 bool aLocked = aStudy->GetProperties()->IsLocked();
747 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
749 // searching dataflow
750 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
751 if (aSO->_is_nil()) { // create new dataflow SObject
752 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
753 if (aComponent->_is_nil()) { // is supervision component not found, then create it
754 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
755 anOperation->start();
756 if (aLocked) aStudy->GetProperties()->SetLocked(false);
757 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
758 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
759 aName = SALOMEDS::AttributeName::_narrow(anAttr);
760 //aName->SetValue(STUDY_SUPERVISION);
761 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
762 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
763 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
764 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
765 aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
766 if (aLocked) aStudy->GetProperties()->SetLocked(true);
767 anOperation->finish();
770 aSO = aBuilder->NewObject(aComponent);
771 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
772 aName = SALOMEDS::AttributeName::_narrow(anAttr);
773 aName->SetValue(dataflow->Name());
774 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
775 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
776 anIORAttr->SetValue(dataflow->getIOR());
778 if (aLocked) return false;
782 Supervision.unregisterGraph(this);
783 Supervision.registerGraph(dataflow->getIOR(), this);
784 myIsFromStudy = true;
789 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
790 Trace("SUPERVGUI_Main::chooseData")
792 QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
794 SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
795 SALOMEDS::GenericAttribute_var anAttr;
796 SALOMEDS::AttributeIOR_var anIOR;
797 Standard_CString ior = "";
798 if (object->FindAttribute(anAttr, "AttributeIOR")) {
799 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
800 ior = anIOR->Value();
801 portIn->setValue(ior);
805 setCursor(Supervision.getCursor());
806 objectBrowser->setCursor(Supervision.getCursor());
807 Supervision.putInfo("");
813 void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
814 Trace("SUPERVGUI_Main::setData")
817 setCursor(forbiddenCursor);
818 objectBrowser->setCursor(pointingHandCursor);
819 Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
822 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
823 const SALOMEDS::SObject_var theSO,
825 //QAD_Operation* theOperation,
827 SALOMEDS::SObject_var aResult;
828 SALOMEDS::AttributeName_var aName;
829 SALOMEDS::GenericAttribute_var anAttr;
830 if (!*theStarted) { // optimisation
831 SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
832 for (; anIterator->More(); anIterator->Next()) {
833 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
834 aName = SALOMEDS::AttributeName::_narrow(anAttr);
835 if (strcmp(aName->Value(), theName) == 0) {
836 aResult = anIterator->Value();
842 if (!aResult->_is_nil()) return aResult;
844 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
847 //theOperation->start();
848 aBuilder->NewCommand();
850 aResult = aBuilder->NewObject(theSO);
851 anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
852 aName = SALOMEDS::AttributeName::_narrow(anAttr);
853 aName->SetValue(theName);
857 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
858 Trace("SUPERVGUI_Main::putDataStudy");
860 static bool isIn = false;
861 if (isIn) return true; else isIn = true;
863 SALOMEDS::Study_var aStudy = study->getStudyDocument();
864 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
865 SALOMEDS::GenericAttribute_var anAttr;
866 SALOMEDS::AttributeName_var aName;
867 SALOMEDS::AttributeIOR_var anIORAttr;
868 SALOMEDS::AttributePixMap_var aPixmap;
869 bool aTransaction = false;
870 bool aLocked = aStudy->GetProperties()->IsLocked();
871 // QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
873 // searching dataflow
874 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
875 if (aSO->_is_nil()) { // create new dataflow SObject
876 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
877 if (aComponent->_is_nil()) { // is supervision component not found, then create it
878 //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
879 //anOperation->start();
880 aBuilder->NewCommand();
881 if (aLocked) aStudy->GetProperties()->SetLocked(false);
882 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
883 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
884 aName = SALOMEDS::AttributeName::_narrow(anAttr);
885 //aName->SetValue(STUDY_SUPERVISION);
886 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
888 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
889 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
890 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
891 aBuilder->DefineComponentInstance(aComponent, Supervision.getEngine());
892 if (aLocked) aStudy->GetProperties()->SetLocked(true);
893 // anOperation->finish();
894 aBuilder->CommitCommand();
898 aBuilder->NewCommand();
899 aSO = aBuilder->NewObject(aComponent);
900 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
901 aName = SALOMEDS::AttributeName::_narrow(anAttr);
902 aName->SetValue(dataflow->Name());
903 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
904 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
905 anIORAttr->SetValue(dataflow->getIOR());
907 //QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
908 aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO
909 QString("Run ") + myRunTime.toString() /*, anOperation*/, &aTransaction);
910 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name()/*, anOperation*/, &aTransaction); // get node SO
911 aSO = SearchOrCreateSOWithName(aStudy, aSO, inout/*, anOperation*/, &aTransaction); // get in/out SO
912 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name()/*, anOperation*/, &aTransaction); // get port SO
915 if (aTransaction) aBuilder->CommitCommand();
921 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
922 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
923 if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
927 // set object value to the study: if object is external, then put it with
928 // help of the specific component - owner
930 // get according component driver for result object
931 SALOME_LifeCycleCORBA aLCC(myNService);
932 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
933 if (!aFNode->_is_nil()) {
934 Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
935 aFNode->GetComponentName());
936 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
937 if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
938 CORBA::Object_ptr anObject = new CORBA::Object();
939 CORBA::Any* anAny = p->ToAny();
940 (*anAny) >>= anObject;
942 if (aDriver->CanPublishInStudy(anObject)) {
943 SALOMEDS::SObject_var aTmpSO;
948 aBuilder->NewCommand();
950 aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
951 aBuilder->Addreference(aSO, aTmpSO);
952 } else { // can't publish object: abort transaction
953 if (aTransaction) aBuilder->AbortCommand();
958 } else { // component has no drivel, but could store IORs (like Calculator)
959 SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString());
960 if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO);
967 aBuilder->NewCommand();
969 anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
974 aBuilder->CommitCommand();
975 if (!myThread->running())
976 study->updateObjBrowser();
982 void SUPERVGUI_Main::ActivatePanning()
984 if (graph->isVisible()) {
985 graph->ActivatePanning();
986 } else if (array->isVisible()) {
987 array->ActivatePanning();
992 void SUPERVGUI_Main::ResetView()
994 if (graph->isVisible()) {
996 } else if (array->isVisible()) {
1002 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
1003 myIsFromStudy = theToStudy;
1004 graph->setAsFromStudy(theToStudy);
1005 array->setAsFromStudy(theToStudy);
1008 void SUPERVGUI_Main::checkIsInStudy() {
1009 if (!myIsFromStudy) return;
1011 SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
1012 SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
1013 SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
1014 SALOMEDS::SObject_var aDataflowLbl;
1015 SALOMEDS::GenericAttribute_var anAttr;
1017 for (; aChildIterator->More(); aChildIterator->Next()) {
1018 aDataflowLbl = aChildIterator->Value();
1019 if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
1022 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1023 if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
1025 // This Graph considered as in study but in study it is not exists
1026 Supervision.unregisterGraph(this);
1027 setAsFromStudy(false);
1030 void SUPERVGUI_Main::syncNotification() {
1040 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1041 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
1043 mess += "NOTIF: "; mess += graph;
1044 mess += " / " ; mess += node;
1045 mess += " / " ; mess += type;
1046 mess += " / " ; mess += message;
1047 getMessage()->setMessage(mess.latin1());
1052 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1053 char* sender, long counter, char* date, long stamp) {
1054 Trace("SUPERVGUI_Main::isFiltered");
1056 if (strcmp(getDataflow()->Name(), graph) == 0) {
1058 QObjectList* nodes = queryList("SUPERVGUI_Node");
1059 QObjectListIt i(*nodes);
1060 while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
1062 if (strcmp(n->name(), node) == 0) {
1063 if (strcmp(type, NOTIF_WARNING) == 0) {
1065 } else if (strcmp(type, NOTIF_STEP) == 0) {
1067 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1069 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1076 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1077 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 );
1078 fflush( myLogFile );
1086 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1087 array->setPaletteBackgroundColor(color);
1088 graph->setPaletteBackgroundColor(color);
1090 SUPERVGraph_View::setPaletteBackgroundColor(color);
1093 QPtrList< char * > SUPERVGUI_Main::getEventNodes() {
1094 return myEventNodes;
1097 void SUPERVGUI_Main::setEventNodes(QPtrList< char * > theEventNodes) {
1098 myEventNodes = theEventNodes;
1101 QPtrList< SUPERV::GraphState > SUPERVGUI_Main::getStates() {
1105 void SUPERVGUI_Main::setStates(QPtrList< SUPERV::GraphState > theStates) {
1106 myStates = theStates;
1109 int SUPERVGUI_Main::getNodesNumber() {
1110 //create a list of nodes of the graph
1111 SUPERV_Nodes nodes = getDataflow()->Nodes();
1112 int RetVal = nodes->CNodes.length() + nodes->FNodes.length() +
1113 nodes->INodes.length() + nodes->GNodes.length() +
1114 nodes->LNodes.length() + nodes->SNodes.length();
1118 SUPERVGUI_Thread* SUPERVGUI_Main::getMyThread() {
1122 void SUPERVGUI_Main::startTimer() {
1123 myTimer->start(500);
1126 void SUPERVGUI_Main::executionFinished() {
1127 getStudy()->updateObjBrowser();
1130 void SUPERVGUI_Main::checkExecution() {
1131 if (myThread->finished()) {
1133 executionFinished();
1139 /******************************* SUPERVGUI_Thread class ****************************************/
1140 SUPERVGUI_Thread::SUPERVGUI_Thread()
1146 SUPERVGUI_Thread::~SUPERVGUI_Thread()
1148 //it is a virtual destructor and needs to be determine here
1151 void SUPERVGUI_Thread::startThread(const char* m)
1156 myMain->getMessage()->setMessage(m);
1161 void SUPERVGUI_Thread::stopThread(const char* m)
1163 //myIsActive = false;
1165 myMain->getMessage()->setMessage(m);
1168 void SUPERVGUI_Thread::setMain(SUPERVGUI_Main* theMain)
1173 void SUPERVGUI_Thread::run()
1175 SUPERV_CNode aNode = NULL;
1176 SUPERV::GraphEvent aEvent = SUPERV::UndefinedEvent ;
1177 SUPERV::GraphState aState = SUPERV::UndefinedState ;
1179 SUPERV_CNode aPrevNode = NULL;
1180 SUPERV::GraphEvent aPrevEvent = SUPERV::UndefinedEvent ;
1181 SUPERV::GraphState aPrevState = SUPERV::UndefinedState ;
1186 QPtrList< char * > anEventNodes;
1187 QPtrList< SUPERV::GraphState > aStates;
1189 myMain->startTimer();
1191 myMain->getDataflow()->Event(aNode, aEvent, aState);
1193 if (aEvent == SUPERV::UndefinedEvent && aState == SUPERV::UndefinedState
1195 aEvent == SUPERV::NoEvent && aState == SUPERV::NoState) {
1196 if (myMain->getEventNodes().count()) {
1197 myMain->removeEventNodes();
1199 if (myMain->getStates().count()) {
1200 myMain->removeStates();
1205 if ( aNode != NULL) {
1206 aName = aNode->Name();
1209 if ( aPrevNode == NULL ) { //first initialize aPrev... variables
1210 anEventNodes = myMain->getEventNodes();
1211 anEventNodes.append( &aName ) ;
1212 myMain->setEventNodes(anEventNodes);
1214 aStates = myMain->getStates();
1215 aStates.append( &aState ) ;
1216 myMain->setStates(aStates);
1219 if ( aEvent == aPrevEvent && aState == aPrevState) {
1220 QString aNameStr = aName;
1221 QString aPrevNameStr = aPrevName;
1222 if ( aNameStr != aPrevNameStr ) {
1223 anEventNodes = myMain->getEventNodes();
1224 anEventNodes.append( &aName ) ;
1225 myMain->setEventNodes(anEventNodes);
1227 aStates = myMain->getStates();
1228 aStates.append( &aState ) ;
1229 myMain->setStates(aStates);
1233 anEventNodes = myMain->getEventNodes();
1234 anEventNodes.append( &aName ) ;
1235 myMain->setEventNodes(anEventNodes);
1237 aStates = myMain->getStates();
1238 aStates.append( &aState ) ;
1239 myMain->setStates(aStates);
1244 switch (myMain->getDataflow()->State()) {
1245 case SUPERV_Editing :
1246 stopThread(myMain->getDataflow()->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
1249 case SUPERV_Suspend :
1250 stopThread(tr("MSG_GRAPH_SUSPENDED"));
1254 stopThread(tr("MSG_GRAPH_FINISHED"));
1258 stopThread(tr("MSG_GRAPH_ABORTED"));
1265 if (myMain->getEventNodes().count()) {
1266 //if list not empty call execute() -> sync()
1267 char * aNodeName = *(myMain->getEventNodes().getFirst());
1268 SUPERV::GraphState aNodeState = *(myMain->getStates().getFirst());
1270 myMain->execute(aNodeName,aNodeState); //this is from main
1272 myMain->removeFirstEN();
1273 myMain->removeFirstS();
1277 aPrevEvent = aEvent;
1278 aPrevState = aState;
1279 aPrevName = aPrevNode->Name();
1284 // VSR: 04/12/03 ---> update object browser ufter finishing
1286 // myMain->getStudy()->updateObjBrowser();
1288 // VSR: 04/12/03 <---