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");
179 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
183 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
184 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
185 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
187 builder->DefineComponentInstance(father, *Supervision.getEngine());
191 objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
194 graph = new SUPERVGUI_Graph(this);
195 array = new SUPERVGUI_Array(this);
197 message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
198 notification = new NOTIFICATION_Consumer();
200 QBoxLayout * layout = new QVBoxLayout(this);
201 layout->setMargin(0);
202 layout->setSpacing(0);
203 layout->addWidget(graph);
204 layout->addWidget(array);
208 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
209 myLogFile = fopen( myLogFileName.latin1(), "a" );
210 if ( myLogFile == NULL )
215 SUPERVGUI_Main::~SUPERVGUI_Main() {
216 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
217 if ( myLogFile != NULL) {
220 graph->removeLinks();
221 delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
222 if (!SUPERV_isNull(dataflow)) {
223 if (dataflow->IsExecuting()) {
224 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
225 tr("MSG_DF_RUNNING"),
226 tr("MSG_DF_EXECUTION"),
227 tr("MSG_DF_KILL")) == 1) {
234 void SUPERVGUI_Main::StartTimer(const char* m) {
235 Trace("SUPERVGUI_Main::StartTimer")
236 if (!timer->isActive()) {
238 message->setMessage(m);
242 void SUPERVGUI_Main::StopTimer(const char* m) {
243 Trace("SUPERVGUI_Main::StopTimer")
244 if (timer->isActive()) {
247 message->setMessage(m);
252 void SUPERVGUI_Main::filterNotification() {
253 Trace("SUPERVGUI_Main::filterNotification");
254 SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
255 dlg->setFiltered( myFiltered );
256 dlg->setLogged( myLogged, myLogFileName );
257 dlg->setWarning( myWarning );
258 dlg->setStep( myStep );
259 dlg->setTrace( myTrace );
260 dlg->setVerbose( myVerbose );
261 if ( dlg->exec() == QDialog::Accepted ) {
262 myLogged = dlg->getLogged();
263 myLogFileName = dlg->getLogFile();
264 myFiltered = dlg->getFiltered();
265 myWarning = dlg->getWarning();
266 myStep = dlg->getStep();
267 myTrace = dlg->getTrace();
268 myVerbose = dlg->getVerbose();
270 if ( myLogFile != NULL) {
274 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
275 myLogFile = fopen( myLogFileName.latin1(), "a" );
276 if ( myLogFile == NULL ) {
278 QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
284 void SUPERVGUI_Main::syncAsync() {
285 Trace("SUPERVGUI_Main::syncAsync")
286 QTimer::singleShot(1, this, SLOT(sync()));
291 * Called by timer when dataflow is executing
293 void SUPERVGUI_Main::execute() {
295 SUPERV::GraphEvent aEvent;
296 SUPERV::GraphState aState;
297 dataflow->EventNoW(aNode, aEvent, aState);
298 if ((aEvent == SUPERV::NoEvent) && (aState == SUPERV::NoState)) return;
300 if (!SUPERV_isNull(aNode)) {
301 SUPERVGUI_Node* aNodePrs;
302 if (myCurrentView == TABLE) {
303 aNodePrs = (SUPERVGUI_Node*) array->child(aNode->Name(), "SUPERVGUI_Node");
305 aNodePrs = (SUPERVGUI_Node*) graph->child(aNode->Name(), "SUPERVGUI_Node");
310 switch (dataflow->State()) {
311 case SUPERV_Editing :
312 StopTimer(dataflow->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
315 case SUPERV_Suspend :
316 StopTimer(tr("MSG_GRAPH_SUSPENDED"));
320 StopTimer(tr("MSG_GRAPH_FINISHED"));
324 StopTimer(tr("MSG_GRAPH_ABORTED"));
328 StopTimer(tr("MSG_GRAPH_KILLED"));
336 void SUPERVGUI_Main::sync() {
337 Trace("SUPERVGUI_Main::sync")
338 if ((SUPERV_isNull(dataflow))) return;
339 QString t = tr("GRAPH_TITLE");
341 t += dataflow->Name();
344 study->updateObjBrowser();
345 if (myCurrentView == TABLE) {
353 void SUPERVGUI_Main::showTable() {
354 if (myCurrentView == TABLE) return;
356 if (array->create()) {
357 myCurrentView = TABLE;
364 void SUPERVGUI_Main::showFullGraph() {
365 if (myCurrentView == TABLE) {
369 myCurrentView = GRAPH;
371 graph->setFullView();
375 void SUPERVGUI_Main::showContolFlow() {
376 if (myCurrentView == TABLE) {
380 myCurrentView = CONTROLFLOW;
382 graph->setControlView();
386 bool SUPERVGUI_Main::exportDataflow(QString theFile) {
387 Trace("SUPERVGUI_Main::exportDataflow");
388 if ((SUPERV_isNull(dataflow))) return false;
390 if (!theFile.isEmpty()) {
391 if (!dataflow->Export(theFile.latin1())) {
392 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
399 void SUPERVGUI_Main::insertFile() {
400 Trace("SUPERVGUI_Main::insertFile")
401 if ((SUPERV_isNull(dataflow))) return;
403 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
406 tr("MSG_GRAPH_INSERT"),
409 if (dataflow->Import(f.latin1())) {
410 if (myCurrentView == TABLE) {
416 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
421 void SUPERVGUI_Main::copy() {
422 Trace("SUPERVGUI_Main::copy");
423 if (dataflow->ThreadsMax() == 0) {
424 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
427 QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
428 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
429 (aStudyFrame->getRightFrame()->getViewFrame());
431 SUPERV_Graph aNewGraph = dataflow->Copy();
432 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
433 aNewName += dataflow->Name();
434 aNewGraph->SetName(aNewName);
435 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
436 Supervision.getDesktop(),
438 study->showFrame(aStudyFrame);
442 void SUPERVGUI_Main::run() {
443 Trace("SUPERVGUI_Main::run")
444 if ((SUPERV_isNull(dataflow))) return;
446 if (dataflow->IsEditing()) {
447 if (!dataflow->IsValid()) {
448 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
449 } else if (!dataflow->IsExecutable()) {
450 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
451 } else if (graph->isAnyLinkCreating()) {
452 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
454 myRunTime = QDateTime::currentDateTime();
457 if (!dataflow->ReRun()) {
458 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
460 StartTimer(tr("MSG_GRAPH_STARTED"));
465 if (!dataflow->Run()) {
466 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
468 StartTimer(tr("MSG_GRAPH_STARTED"));
476 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
482 void SUPERVGUI_Main::startExecute() {
483 Trace("SUPERVGUI_Main::startExecute")
484 if ((SUPERV_isNull(dataflow))) return;
486 if (dataflow->IsEditing()) {
487 if (!dataflow->IsValid()) {
488 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
489 } else if (!dataflow->IsExecutable()) {
490 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
491 } else if (graph->isAnyLinkCreating()) {
492 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CRL_NOTCOMPLETE"));
494 myRunTime = QDateTime::currentDateTime();
497 if (!dataflow->ReStart()) {
498 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
500 StartTimer(tr("MSG_GRAPH_STARTED"));
505 if (!dataflow->Start()) {
506 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
508 StartTimer(tr("MSG_GRAPH_STARTED"));
514 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
519 void SUPERVGUI_Main::kill() {
520 Trace("SUPERVGUI_Main::kill")
521 if ((SUPERV_isNull(dataflow))) return;
523 if (dataflow->IsEditing()) {
524 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
525 } else if (dataflow->Kill()) {
529 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
533 void SUPERVGUI_Main::suspendResume() {
534 Trace("SUPERVGUI_Main::suspendResume")
535 if ((SUPERV_isNull(dataflow))) return;
537 if (dataflow->IsEditing()) {
538 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
539 } else if (dataflow->State() == SUPERV_Suspend) {
540 if (dataflow->Resume()) {
541 message->setMessage(tr("MSG_DF_RESUMED"));
544 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
547 if (dataflow->Suspend()) {
550 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
555 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
556 Trace("SUPERVGUI_Main::stopRestart")
557 if ((SUPERV_isNull(dataflow))) return;
559 if (dataflow->IsEditing()) {
560 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
561 } else if (dataflow->State() == SUPERV_Stop) {
562 if (dataflow->ReStart()) {
563 message->setMessage(tr("MSG_DF_RESTARTED"));
566 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
569 if (dataflow->Stop()) {
572 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
577 void SUPERVGUI_Main::addNode() {
578 Trace("SUPERVGUI_Main::addNode");
579 if (SUPERV_isNull(dataflow)) return;
581 if (dataflow->IsExecuting()) {
582 if (QMessageBox::warning(QAD_Application::getDesktop(),
583 tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
584 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
590 Supervision.getBrowser()->choose();
596 * Add Computation node
598 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
599 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
600 switch (myCurrentView) {
603 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
604 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
605 graph->addChild(aNode, theNode->X(), theNode->Y());
611 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
613 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
614 graph->addChild(aNode, theNode->X(), theNode->Y());
628 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
629 switch (myCurrentView) {
632 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
633 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
634 graph->addChild(aNode, theNode->X(), theNode->Y());
640 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
642 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
643 graph->addChild(aNode, theNode->X(), theNode->Y());
657 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode, bool Update) {
658 switch (myCurrentView) {
661 SUPERVGUI_StartControlNode* aStartPrs =
662 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
663 SUPERVGUI_EndControlNode* aEndPrs =
664 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
666 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
667 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
668 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
669 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
671 aStartPrs->updateLinksPrs();
672 aEndPrs->updateLinksPrs();
676 graph->repaintContents();
681 SUPERVGUI_StartControlNode* aStartPrs =
682 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
683 SUPERVGUI_EndControlNode* aEndPrs =
684 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
686 aStartPrs->hideAll();
689 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
690 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
691 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
692 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
694 aStartPrs->updateLinksPrs();
695 aEndPrs->updateLinksPrs();
699 graph->repaintContents();
711 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
712 Trace("SUPERVGUI_Main::getGraph")
716 SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
717 Trace("SUPERVGUI_Main::getArray")
721 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
722 Trace("SUPERVGUI_Main::getDataflow")
726 QAD_Message* SUPERVGUI_Main::getMessage() {
727 Trace("SUPERVGUI_Main::getMessage")
731 QAD_Study* SUPERVGUI_Main::getStudy() {
732 Trace("SUPERVGUI_Main::getStudy")
736 bool SUPERVGUI_Main::isArrayShown() {
737 Trace("SUPERVGUI_Main::isArrayShown")
738 return(myCurrentView == TABLE);
741 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
742 Trace("SUPERVGUI_Main::showPopup");
743 // To check is Supervision active?
744 if (myIsLocked) return;
746 // if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
747 if (QAD_Application::getDesktop()->getActiveComponent().compare( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
750 if (e->button() == RightButton) {
751 p->exec(e->globalPos());
757 void SUPERVGUI_Main::changeInformation() {
758 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
762 /* Trace("SUPERVGUI_Main::changeInformation")
763 if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
768 // returns false, if can't add dataflow into the study
769 bool SUPERVGUI_Main::addStudy() {
770 Trace("SUPERVGUI_Main::addStudy");
771 if (myIsFromStudy) return false;
772 if ((SUPERV_isNull(dataflow))) return false;
774 SALOMEDS::Study_var aStudy = study->getStudyDocument();
775 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
776 SALOMEDS::GenericAttribute_var anAttr;
777 SALOMEDS::AttributeName_var aName;
778 SALOMEDS::AttributeIOR_var anIORAttr;
779 SALOMEDS::AttributePixMap_var aPixmap;
780 bool aLocked = aStudy->GetProperties()->IsLocked();
781 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
783 // searching dataflow
784 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
785 if (aSO->_is_nil()) { // create new dataflow SObject
786 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
787 if (aComponent->_is_nil()) { // is supervision component not found, then create it
788 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
789 anOperation->start();
790 if (aLocked) aStudy->GetProperties()->SetLocked(false);
791 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
792 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
793 aName = SALOMEDS::AttributeName::_narrow(anAttr);
794 //aName->SetValue("Supervision");
795 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
797 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
798 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
799 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
800 aBuilder->DefineComponentInstance(aComponent, *Supervision.getEngine());
801 if (aLocked) aStudy->GetProperties()->SetLocked(true);
802 anOperation->finish();
805 aSO = aBuilder->NewObject(aComponent);
806 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
807 aName = SALOMEDS::AttributeName::_narrow(anAttr);
808 aName->SetValue(dataflow->Name());
809 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
810 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
811 anIORAttr->SetValue(dataflow->getIOR());
813 if (aLocked) return false;
817 Supervision.unregisterGraph(this);
818 Supervision.registerGraph(dataflow->getIOR(), this);
819 myIsFromStudy = true;
824 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
825 Trace("SUPERVGUI_Main::chooseData")
827 QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
829 SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
830 SALOMEDS::GenericAttribute_var anAttr;
831 SALOMEDS::AttributeIOR_var anIOR;
832 Standard_CString ior = "";
833 if (object->FindAttribute(anAttr, "AttributeIOR")) {
834 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
835 ior = anIOR->Value();
836 portIn->setValue(ior);
840 setCursor(Supervision.getCursor());
841 objectBrowser->setCursor(Supervision.getCursor());
842 Supervision.putInfo("");
848 void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
849 Trace("SUPERVGUI_Main::setData")
852 setCursor(forbiddenCursor);
853 objectBrowser->setCursor(pointingHandCursor);
854 Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
857 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
858 const SALOMEDS::SObject_var theSO,
860 QAD_Operation* theOperation,
862 SALOMEDS::SObject_var aResult;
863 SALOMEDS::AttributeName_var aName;
864 SALOMEDS::GenericAttribute_var anAttr;
865 if (!*theStarted) { // optimisation
866 SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
867 for (; anIterator->More(); anIterator->Next()) {
868 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
869 aName = SALOMEDS::AttributeName::_narrow(anAttr);
870 if (strcmp(aName->Value(), theName) == 0) {
871 aResult = anIterator->Value();
877 if (!aResult->_is_nil()) return aResult;
881 theOperation->start();
883 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
884 aResult = aBuilder->NewObject(theSO);
885 anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
886 aName = SALOMEDS::AttributeName::_narrow(anAttr);
887 aName->SetValue(theName);
891 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
892 Trace("SUPERVGUI_Main::putDataStudy");
894 static bool isIn = false;
895 if (isIn) return true; else isIn = true;
897 SALOMEDS::Study_var aStudy = study->getStudyDocument();
898 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
899 SALOMEDS::GenericAttribute_var anAttr;
900 SALOMEDS::AttributeName_var aName;
901 SALOMEDS::AttributeIOR_var anIORAttr;
902 SALOMEDS::AttributePixMap_var aPixmap;
903 bool aTransaction = false;
904 bool aLocked = aStudy->GetProperties()->IsLocked();
905 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
907 // searching dataflow
908 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
909 if (aSO->_is_nil()) { // create new dataflow SObject
910 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
911 if (aComponent->_is_nil()) { // is supervision component not found, then create it
912 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
913 anOperation->start();
914 if (aLocked) aStudy->GetProperties()->SetLocked(false);
915 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
916 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
917 aName = SALOMEDS::AttributeName::_narrow(anAttr);
918 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
920 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
921 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
922 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
923 aBuilder->DefineComponentInstance(aComponent, *Supervision.getEngine());
924 if (aLocked) aStudy->GetProperties()->SetLocked(true);
925 anOperation->finish();
929 aSO = aBuilder->NewObject(aComponent);
930 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
931 aName = SALOMEDS::AttributeName::_narrow(anAttr);
932 aName->SetValue(dataflow->Name());
933 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
934 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
935 anIORAttr->SetValue(dataflow->getIOR());
937 aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO
938 QString("Run ") + myRunTime.toString() , op, &aTransaction);
939 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name(), op, &aTransaction); // get node SO
940 aSO = SearchOrCreateSOWithName(aStudy, aSO, inout, op, &aTransaction); // get in/out SO
941 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name(), op, &aTransaction); // get port SO
944 if (aTransaction) op->finish();
949 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
950 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
951 if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
955 // set object value to the study: if object is external, then put it with
956 // help of the specific component - owner
958 // get according component driver for result object
959 SALOME_LifeCycleCORBA aLCC(myNService);
960 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
961 if (!aFNode->_is_nil()) {
962 Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
963 aFNode->GetComponentName());
964 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
965 if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
966 CORBA::Object_ptr anObject = new CORBA::Object();
967 CORBA::Any* anAny = p->ToAny();
968 (*anAny) >>= anObject;
970 if (aDriver->CanPublishInStudy(anObject)) {
971 SALOMEDS::SObject_var aTmpSO;
977 aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
978 aBuilder->Addreference(aSO, aTmpSO);
979 } else { // can't publish object: abort transaction
980 if (aTransaction) op->abort();
984 } else { // component has no drivel, but could store IORs (like Calculator)
985 SALOMEDS::SObject_var anIORSO = aStudy->FindObjectIOR(p->ToString());
986 if (!CORBA::is_nil(anIORSO)) aBuilder->Addreference(aSO, anIORSO);
994 anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
997 if (aTransaction) op->finish();
998 study->updateObjBrowser();
1004 void SUPERVGUI_Main::ActivatePanning()
1006 if (graph->isVisible()) {
1007 graph->ActivatePanning();
1008 } else if (array->isVisible()) {
1009 array->ActivatePanning();
1014 void SUPERVGUI_Main::ResetView()
1016 if (graph->isVisible()) {
1018 } else if (array->isVisible()) {
1024 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
1025 myIsFromStudy = theToStudy;
1026 graph->setAsFromStudy(theToStudy);
1027 array->setAsFromStudy(theToStudy);
1030 void SUPERVGUI_Main::checkIsInStudy() {
1031 if (!myIsFromStudy) return;
1033 SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
1034 SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
1035 SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
1036 SALOMEDS::SObject_var aDataflowLbl;
1037 SALOMEDS::GenericAttribute_var anAttr;
1039 for (; aChildIterator->More(); aChildIterator->Next()) {
1040 aDataflowLbl = aChildIterator->Value();
1041 if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
1044 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1045 if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
1047 // This Graph considered as in study but in study it is not exists
1048 Supervision.unregisterGraph(this);
1049 setAsFromStudy(false);
1052 void SUPERVGUI_Main::syncNotification() {
1062 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1063 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
1065 mess += "NOTIF: "; mess += graph;
1066 mess += " / " ; mess += node;
1067 mess += " / " ; mess += type;
1068 mess += " / " ; mess += message;
1069 getMessage()->setMessage(mess.latin1());
1074 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1075 char* sender, long counter, char* date, long stamp) {
1076 Trace("SUPERVGUI_Main::isFiltered");
1078 if (strcmp(getDataflow()->Name(), graph) == 0) {
1080 QObjectList* nodes = queryList("SUPERVGUI_Node");
1081 QObjectListIt i(*nodes);
1082 while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
1084 if (strcmp(n->name(), node) == 0) {
1085 if (strcmp(type, NOTIF_WARNING) == 0) {
1087 } else if (strcmp(type, NOTIF_STEP) == 0) {
1089 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1091 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1098 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1099 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 );
1100 fflush( myLogFile );
1108 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1109 array->setPaletteBackgroundColor(color);
1110 graph->setPaletteBackgroundColor(color);
1112 SUPERVGraph_View::setPaletteBackgroundColor(color);