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())->getGraph(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())->Graph(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())->Graph(f);
117 dataflow = (*Supervision.getEngine())->GraphE(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();
159 //myIsRunned = false;
160 myCurrentView = GRAPH;
161 myIsFromStudy = false;
162 study = theDesktop->getActiveStudy();
163 timer = new QTimer(this);
164 connect(timer, SIGNAL(timeout()), this, SLOT(execute()));
166 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
167 SALOMEDS::StudyBuilder_var builder = studyDoc->NewBuilder();
168 SALOMEDS::SComponent_var father = studyDoc->FindComponent(STUDY_SUPERVISION);
169 SALOMEDS::GenericAttribute_var anAttr;
170 SALOMEDS::AttributeName_var aName;
171 SALOMEDS::AttributePixMap_var aPixmap;
172 if (father->_is_nil()) {
173 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
175 father = builder->NewComponent(STUDY_SUPERVISION);
176 anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
177 aName = SALOMEDS::AttributeName::_narrow(anAttr);
178 aName->SetValue("Supervision");
180 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
181 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
182 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
184 builder->DefineComponentInstance(father, *Supervision.getEngine());
188 objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
191 graph = new SUPERVGUI_Graph(this);
192 array = new SUPERVGUI_Array(this);
194 message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
195 notification = new NOTIFICATION_Consumer();
197 QBoxLayout * layout = new QVBoxLayout(this);
198 layout->setMargin(0);
199 layout->setSpacing(0);
200 layout->addWidget(graph);
201 layout->addWidget(array);
205 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
206 myLogFile = fopen( myLogFileName.latin1(), "a" );
207 if ( myLogFile == NULL )
212 SUPERVGUI_Main::~SUPERVGUI_Main() {
213 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
214 if ( myLogFile != NULL) {
217 graph->removeLinks();
218 delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
219 if (!SUPERV_isNull(dataflow)) {
220 if (dataflow->IsExecuting()) {
221 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
222 tr("MSG_DF_RUNNING"),
223 tr("MSG_DF_EXECUTION"),
224 tr("MSG_DF_KILL")) == 1) {
231 void SUPERVGUI_Main::StartTimer(const char* m) {
232 Trace("SUPERVGUI_Main::StartTimer")
233 if (!timer->isActive()) {
235 message->setMessage(m);
239 void SUPERVGUI_Main::StopTimer(const char* m) {
240 Trace("SUPERVGUI_Main::StopTimer")
241 if (timer->isActive()) {
244 message->setMessage(m);
249 void SUPERVGUI_Main::filterNotification() {
250 Trace("SUPERVGUI_Main::filterNotification");
251 SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
252 dlg->setFiltered( myFiltered );
253 dlg->setLogged( myLogged, myLogFileName );
254 dlg->setWarning( myWarning );
255 dlg->setStep( myStep );
256 dlg->setTrace( myTrace );
257 dlg->setVerbose( myVerbose );
258 if ( dlg->exec() == QDialog::Accepted ) {
259 myLogged = dlg->getLogged();
260 myLogFileName = dlg->getLogFile();
261 myFiltered = dlg->getFiltered();
262 myWarning = dlg->getWarning();
263 myStep = dlg->getStep();
264 myTrace = dlg->getTrace();
265 myVerbose = dlg->getVerbose();
267 if ( myLogFile != NULL) {
271 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
272 myLogFile = fopen( myLogFileName.latin1(), "a" );
273 if ( myLogFile == NULL ) {
275 QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
281 void SUPERVGUI_Main::syncAsync() {
282 Trace("SUPERVGUI_Main::syncAsync")
283 QTimer::singleShot(1, this, SLOT(sync()));
288 * Called by timer when dataflow is executing
290 void SUPERVGUI_Main::execute() {
292 SUPERV::GraphEvent aEvent;
293 SUPERV::GraphState aState;
294 dataflow->EventNoW(aNode, aEvent, aState);
295 if ((aEvent == SUPERV::NoEvent) && (aState == SUPERV::NoState)) return;
297 if (!SUPERV_isNull(aNode)) {
298 SUPERVGUI_Node* aNodePrs;
299 if (myCurrentView == TABLE) {
300 aNodePrs = (SUPERVGUI_Node*) array->child(aNode->Name(), "SUPERVGUI_Node");
302 aNodePrs = (SUPERVGUI_Node*) graph->child(aNode->Name(), "SUPERVGUI_Node");
307 switch (dataflow->State()) {
308 case SUPERV_Editing :
309 StopTimer(dataflow->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
312 case SUPERV_Suspend :
313 StopTimer(tr("MSG_GRAPH_SUSPENDED"));
317 StopTimer(tr("MSG_GRAPH_FINISHED"));
321 StopTimer(tr("MSG_GRAPH_ABORTED"));
325 StopTimer(tr("MSG_GRAPH_KILLED"));
333 void SUPERVGUI_Main::sync() {
334 Trace("SUPERVGUI_Main::sync")
335 if ((SUPERV_isNull(dataflow))) return;
336 QString t = tr("GRAPH_TITLE");
338 t += dataflow->Name();
341 study->updateObjBrowser();
342 if (myCurrentView == TABLE) {
350 void SUPERVGUI_Main::showTable() {
351 if (myCurrentView == TABLE) return;
353 if (array->create()) {
354 myCurrentView = TABLE;
361 void SUPERVGUI_Main::showFullGraph() {
362 if (myCurrentView == TABLE) {
366 myCurrentView = GRAPH;
368 graph->setFullView();
372 void SUPERVGUI_Main::showContolFlow() {
373 if (myCurrentView == TABLE) {
377 myCurrentView = CONTROLFLOW;
379 graph->setControlView();
383 bool SUPERVGUI_Main::exportDataflow(QString theFile) {
384 Trace("SUPERVGUI_Main::exportDataflow");
385 if ((SUPERV_isNull(dataflow))) return false;
387 if (!theFile.isEmpty()) {
388 if (!dataflow->Export(theFile.latin1())) {
389 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
396 void SUPERVGUI_Main::insertFile() {
397 Trace("SUPERVGUI_Main::insertFile")
398 if ((SUPERV_isNull(dataflow))) return;
400 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
403 tr("MSG_GRAPH_INSERT"),
406 if (dataflow->Import(f.latin1())) {
407 if (myCurrentView == TABLE) {
413 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
418 void SUPERVGUI_Main::copy() {
419 Trace("SUPERVGUI_Main::copy");
420 if (dataflow->ThreadsMax() == 0) {
421 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
424 QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
425 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
426 (aStudyFrame->getRightFrame()->getViewFrame());
428 SUPERV_Graph aNewGraph = dataflow->Copy();
429 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
430 aNewName += dataflow->Name();
431 aNewGraph->SetName(aNewName);
432 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
433 Supervision.getDesktop(),
435 study->showFrame(aStudyFrame);
439 void SUPERVGUI_Main::run() {
440 Trace("SUPERVGUI_Main::run")
441 if ((SUPERV_isNull(dataflow))) return;
443 if (dataflow->IsEditing()) {
444 if (!dataflow->IsValid()) {
445 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
446 } else if (!dataflow->IsExecutable()) {
447 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
448 } else if (graph->isAnyLinkCreating()) {
449 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
451 myRunTime = QDateTime::currentDateTime();
454 if (!dataflow->ReRun()) {
455 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
457 StartTimer(tr("MSG_GRAPH_STARTED"));
462 if (!dataflow->Run()) {
463 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
465 StartTimer(tr("MSG_GRAPH_STARTED"));
473 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
479 void SUPERVGUI_Main::startExecute() {
480 Trace("SUPERVGUI_Main::startExecute")
481 if ((SUPERV_isNull(dataflow))) return;
483 if (dataflow->IsEditing()) {
484 if (!dataflow->IsValid()) {
485 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
486 } else if (!dataflow->IsExecutable()) {
487 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
488 } else if (graph->isAnyLinkCreating()) {
489 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
491 myRunTime = QDateTime::currentDateTime();
494 if (!dataflow->ReStart()) {
495 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
497 StartTimer(tr("MSG_GRAPH_STARTED"));
502 if (!dataflow->Start()) {
503 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
505 StartTimer(tr("MSG_GRAPH_STARTED"));
511 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
516 void SUPERVGUI_Main::kill() {
517 Trace("SUPERVGUI_Main::kill")
518 if ((SUPERV_isNull(dataflow))) return;
520 if (dataflow->IsEditing()) {
521 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
522 } else if (dataflow->Kill()) {
526 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
530 void SUPERVGUI_Main::suspendResume() {
531 Trace("SUPERVGUI_Main::suspendResume")
532 if ((SUPERV_isNull(dataflow))) return;
534 if (dataflow->IsEditing()) {
535 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
536 } else if (dataflow->State() == SUPERV_Suspend) {
537 if (dataflow->Resume()) {
538 message->setMessage(tr("MSG_DF_RESUMED"));
541 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
544 if (dataflow->Suspend()) {
547 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
552 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
553 Trace("SUPERVGUI_Main::stopRestart")
554 if ((SUPERV_isNull(dataflow))) return;
556 if (dataflow->IsEditing()) {
557 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
558 } else if (dataflow->State() == SUPERV_Stop) {
559 if (dataflow->ReStart()) {
560 message->setMessage(tr("MSG_DF_RESTARTED"));
563 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
566 if (dataflow->Stop()) {
569 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
574 void SUPERVGUI_Main::addNode() {
575 Trace("SUPERVGUI_Main::addNode");
576 if (SUPERV_isNull(dataflow)) return;
578 if (dataflow->IsExecuting()) {
579 if (QMessageBox::warning(QAD_Application::getDesktop(),
580 tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
581 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
587 Supervision.getBrowser()->choose();
593 * Add Computation node
595 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
596 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
597 switch (myCurrentView) {
600 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
601 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
602 graph->addChild(aNode, theNode->X(), theNode->Y());
608 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
610 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
611 graph->addChild(aNode, theNode->X(), theNode->Y());
625 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
626 switch (myCurrentView) {
629 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
630 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
631 graph->addChild(aNode, theNode->X(), theNode->Y());
637 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
639 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
640 graph->addChild(aNode, theNode->X(), theNode->Y());
654 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
655 switch (myCurrentView) {
658 SUPERVGUI_StartControlNode* aStartPrs =
659 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
660 SUPERVGUI_EndControlNode* aEndPrs =
661 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
663 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
664 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
665 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
666 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
668 aStartPrs->updateLinksPrs();
669 aEndPrs->updateLinksPrs();
673 graph->repaintContents();
678 SUPERVGUI_StartControlNode* aStartPrs =
679 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
680 SUPERVGUI_EndControlNode* aEndPrs =
681 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
683 aStartPrs->hideAll();
686 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
687 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
688 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
689 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
691 aStartPrs->updateLinksPrs();
692 aEndPrs->updateLinksPrs();
696 graph->repaintContents();
708 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
709 Trace("SUPERVGUI_Main::getGraph")
713 SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
714 Trace("SUPERVGUI_Main::getArray")
718 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
719 Trace("SUPERVGUI_Main::getDataflow")
723 QAD_Message* SUPERVGUI_Main::getMessage() {
724 Trace("SUPERVGUI_Main::getMessage")
728 QAD_Study* SUPERVGUI_Main::getStudy() {
729 Trace("SUPERVGUI_Main::getStudy")
733 bool SUPERVGUI_Main::isArrayShown() {
734 Trace("SUPERVGUI_Main::isArrayShown")
735 return(myCurrentView == TABLE);
738 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
739 Trace("SUPERVGUI_Main::showPopup");
740 // To check is Supervision active?
741 if (myIsLocked) return;
743 // if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
744 if (QAD_Application::getDesktop()->getActiveComponent().compare( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
747 if (e->button() == RightButton) {
748 p->exec(e->globalPos());
754 void SUPERVGUI_Main::changeInformation() {
755 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
759 /* Trace("SUPERVGUI_Main::changeInformation")
760 if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
765 // returns false, if can't add dataflow into the study
766 bool SUPERVGUI_Main::addStudy() {
767 Trace("SUPERVGUI_Main::addStudy");
768 if (myIsFromStudy) return false;
769 if ((SUPERV_isNull(dataflow))) return false;
771 SALOMEDS::Study_var aStudy = study->getStudyDocument();
772 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
773 SALOMEDS::GenericAttribute_var anAttr;
774 SALOMEDS::AttributeName_var aName;
775 SALOMEDS::AttributeIOR_var anIORAttr;
776 SALOMEDS::AttributePixMap_var aPixmap;
777 bool aLocked = aStudy->GetProperties()->IsLocked();
778 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
780 // searching dataflow
781 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
782 if (aSO->_is_nil()) { // create new dataflow SObject
783 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
784 if (aComponent->_is_nil()) { // is supervision component not found, then create it
785 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
786 anOperation->start();
787 if (aLocked) aStudy->GetProperties()->SetLocked(false);
788 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
789 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
790 aName = SALOMEDS::AttributeName::_narrow(anAttr);
791 //aName->SetValue("Supervision");
792 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
794 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
795 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
796 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
797 aBuilder->DefineComponentInstance(aComponent, *Supervision.getEngine());
798 if (aLocked) aStudy->GetProperties()->SetLocked(true);
799 anOperation->finish();
802 aSO = aBuilder->NewObject(aComponent);
803 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
804 aName = SALOMEDS::AttributeName::_narrow(anAttr);
805 aName->SetValue(dataflow->Name());
806 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
807 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
808 anIORAttr->SetValue(dataflow->getIOR());
810 if (aLocked) return false;
814 Supervision.unregisterGraph(this);
815 Supervision.registerGraph(dataflow->getIOR(), this);
816 myIsFromStudy = true;
821 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
822 Trace("SUPERVGUI_Main::chooseData")
824 QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
826 SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
827 SALOMEDS::GenericAttribute_var anAttr;
828 SALOMEDS::AttributeIOR_var anIOR;
829 Standard_CString ior = "";
830 if (object->FindAttribute(anAttr, "AttributeIOR")) {
831 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
832 ior = anIOR->Value();
833 portIn->setValue(ior);
837 setCursor(Supervision.getCursor());
838 objectBrowser->setCursor(Supervision.getCursor());
839 Supervision.putInfo("");
845 void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
846 Trace("SUPERVGUI_Main::setData")
849 setCursor(forbiddenCursor);
850 objectBrowser->setCursor(pointingHandCursor);
851 Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
854 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
855 const SALOMEDS::SObject_var theSO,
857 QAD_Operation* theOperation,
859 SALOMEDS::SObject_var aResult;
860 SALOMEDS::AttributeName_var aName;
861 SALOMEDS::GenericAttribute_var anAttr;
862 if (!*theStarted) { // optimisation
863 SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
864 for (; anIterator->More(); anIterator->Next()) {
865 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
866 aName = SALOMEDS::AttributeName::_narrow(anAttr);
867 if (strcmp(aName->Value(), theName) == 0) {
868 aResult = anIterator->Value();
874 if (!aResult->_is_nil()) return aResult;
878 theOperation->start();
880 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
881 aResult = aBuilder->NewObject(theSO);
882 anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
883 aName = SALOMEDS::AttributeName::_narrow(anAttr);
884 aName->SetValue(theName);
888 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
889 Trace("SUPERVGUI_Main::putDataStudy");
891 static bool isIn = false;
892 if (isIn) return true; else isIn = true;
894 SALOMEDS::Study_var aStudy = study->getStudyDocument();
895 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
896 SALOMEDS::GenericAttribute_var anAttr;
897 SALOMEDS::AttributeName_var aName;
898 SALOMEDS::AttributeIOR_var anIORAttr;
899 SALOMEDS::AttributePixMap_var aPixmap;
900 bool aTransaction = false;
901 bool aLocked = aStudy->GetProperties()->IsLocked();
902 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
904 // searching dataflow
905 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
906 if (aSO->_is_nil()) { // create new dataflow SObject
907 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
908 if (aComponent->_is_nil()) { // is supervision component not found, then create it
909 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
910 anOperation->start();
911 if (aLocked) aStudy->GetProperties()->SetLocked(false);
912 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
913 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
914 aName = SALOMEDS::AttributeName::_narrow(anAttr);
915 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
917 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
918 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
919 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
920 aBuilder->DefineComponentInstance(aComponent, *Supervision.getEngine());
921 if (aLocked) aStudy->GetProperties()->SetLocked(true);
922 anOperation->finish();
926 aSO = aBuilder->NewObject(aComponent);
927 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
928 aName = SALOMEDS::AttributeName::_narrow(anAttr);
929 aName->SetValue(dataflow->Name());
930 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
931 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
932 anIORAttr->SetValue(dataflow->getIOR());
934 aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO
935 QString("Run ") + myRunTime.toString() , op, &aTransaction);
936 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name(), op, &aTransaction); // get node SO
937 aSO = SearchOrCreateSOWithName(aStudy, aSO, inout, op, &aTransaction); // get in/out SO
938 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name(), op, &aTransaction); // get port SO
941 if (aTransaction) op->finish();
946 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
947 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
948 if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
952 // set object value to the study: if object is external, then put it with
953 // help of the specific component - owner
955 // get according component driver for result object
956 SALOME_LifeCycleCORBA aLCC(myNService);
957 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
958 if (!aFNode->_is_nil()) {
959 Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
960 aFNode->GetComponentName());
961 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
962 if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
963 CORBA::Object_ptr anObject = new CORBA::Object();
964 CORBA::Any* anAny = p->ToAny();
965 (*anAny) >>= anObject;
967 if (aDriver->CanPublishInStudy(anObject)) {
968 SALOMEDS::SObject_var aTmpSO;
974 aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
975 aBuilder->Addreference(aSO, aTmpSO);
976 } else { // can't publish object: abort transaction
977 if (aTransaction) op->abort();
981 } else { // component has no drivel, but could store IORs (like Calculator)
982 SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString());
983 if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO);
991 anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
994 if (aTransaction) op->finish();
995 study->updateObjBrowser();
1001 void SUPERVGUI_Main::ActivatePanning()
1003 if (graph->isVisible()) {
1004 graph->ActivatePanning();
1005 } else if (array->isVisible()) {
1006 array->ActivatePanning();
1011 void SUPERVGUI_Main::ResetView()
1013 if (graph->isVisible()) {
1015 } else if (array->isVisible()) {
1021 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
1022 myIsFromStudy = theToStudy;
1023 graph->setAsFromStudy(theToStudy);
1024 array->setAsFromStudy(theToStudy);
1027 void SUPERVGUI_Main::checkIsInStudy() {
1028 if (!myIsFromStudy) return;
1030 SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
1031 SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
1032 SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
1033 SALOMEDS::SObject_var aDataflowLbl;
1034 SALOMEDS::GenericAttribute_var anAttr;
1036 for (; aChildIterator->More(); aChildIterator->Next()) {
1037 aDataflowLbl = aChildIterator->Value();
1038 if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
1041 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1042 if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
1044 // This Graph considered as in study but in study it is not exists
1045 Supervision.unregisterGraph(this);
1046 setAsFromStudy(false);
1049 void SUPERVGUI_Main::syncNotification() {
1059 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1060 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
1062 mess += "NOTIF: "; mess += graph;
1063 mess += " / " ; mess += node;
1064 mess += " / " ; mess += type;
1065 mess += " / " ; mess += message;
1066 getMessage()->setMessage(mess.latin1());
1071 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1072 char* sender, long counter, char* date, long stamp) {
1073 Trace("SUPERVGUI_Main::isFiltered");
1075 if (strcmp(getDataflow()->Name(), graph) == 0) {
1077 QObjectList* nodes = queryList("SUPERVGUI_Node");
1078 QObjectListIt i(*nodes);
1079 while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
1081 if (strcmp(n->name(), node) == 0) {
1082 if (strcmp(type, NOTIF_WARNING) == 0) {
1084 } else if (strcmp(type, NOTIF_STEP) == 0) {
1086 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1088 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1095 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1096 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 );
1097 fflush( myLogFile );
1105 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1106 array->setPaletteBackgroundColor(color);
1107 graph->setPaletteBackgroundColor(color);
1109 SUPERVGraph_View::setPaletteBackgroundColor(color);