2 // File : SUPERVGUI_Main.cxx
3 // Created : 24 / 10 / 2001
4 // Author : Francis KLOSS
9 #include "QAD_Splitter.h"
10 #include "QAD_LeftFrame.h"
11 #include "QAD_ObjectBrowser.h"
12 #include "QAD_ObjectBrowserItem.h"
13 #include "QAD_PyEditor.h"
14 #include "QAD_Message.h"
15 #include "QAD_FileDlg.h"
16 #include "QAD_Application.h"
17 #include "SUPERVGUI_Def.h"
18 #include "QAD_RightFrame.h"
19 #include "SUPERVGraph_ViewFrame.h"
22 #include "SUPERVGUI_Main.h"
23 #include "SUPERVGUI.h"
24 #include "SUPERVGUI_ComputeNode.h"
25 #include "SUPERVGUI_ControlNode.h"
26 #include "NOTIFICATION.hxx"
27 #include "SUPERVGUI_Notification.h"
28 #include "SALOMEGUI_ImportOperation.h"
29 #include "SUPERVGUI_Information.h"
32 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool fromIOR)
33 : SUPERVGraph_View(theParent),
36 myLogFileName( QString::null ),
43 Trace("SUPERVGUI_Main::SUPERVGUI_Main (new)");
44 theParent->setViewWidget(this);
46 //SUPERVGUI_Main* am = Supervision.getMain();
47 QAD_ObjectBrowser* ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
49 // ob = ((QAD_StudyFrame*)(theDesktop->getMainFrame()->activeWindow()))->getLeftFrame()->getObjectBrowser();
51 //ob = am->objectBrowser;
53 QAD_ObjectBrowserItem* item = (QAD_ObjectBrowserItem*)(ob->getListView()->currentItem());
54 SALOMEDS::SObject_var obj = theDesktop->getActiveStudy()->getStudyDocument()->FindObjectID(item->getEntry().latin1());
55 SALOMEDS::GenericAttribute_var anAttr;
56 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
57 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
58 Standard_CString ior = anIOR->Value();
59 dataflow = (*Supervision.getEngine())->getGraph(ior);
60 if (SUPERV_isNull(dataflow)) {
61 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_ACCESS_BAD_IOR"));
67 QMessageBox::warning(0, tr("ERROR"), tr("MSG_NOACCESS_BY_IOR"));
71 dataflow = (*Supervision.getEngine())->Graph(MAIN_NEW);
72 if (SUPERV_isNull(dataflow)) {
73 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_DF"));
81 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, bool isModify, const char* f)
82 : SUPERVGraph_View(theParent),
85 myLogFileName( QString::null ),
92 Trace("SUPERVGUI_Main::SUPERVGUI_Main (file)")
93 theParent->setViewWidget(this);
95 dataflow = (*Supervision.getEngine())->Graph(f);
97 dataflow = (*Supervision.getEngine())->GraphE(f);
99 if (SUPERV_isNull(dataflow)) {
100 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
107 SUPERVGUI_Main::SUPERVGUI_Main(SUPERVGraph_ViewFrame* theParent, QAD_Desktop* theDesktop, SUPERV_Graph cp)
108 : SUPERVGraph_View(theParent),
111 myLogFileName( QString::null ),
118 Trace("SUPERVGUI_Main::SUPERVGUI_Main (copy)");
119 theParent->setViewWidget(this);
120 // dataflow = cp->Copy();
122 if (SUPERV_isNull(dataflow)) {
123 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_COPY"));
130 void SUPERVGUI_Main::init(QAD_Desktop* theDesktop) {
131 Trace("SUPERVGUI_Main::init");
132 if (theDesktop) myNService = theDesktop->getNameService();
139 //myIsRunned = false;
140 myCurrentView = GRAPH;
141 myIsFromStudy = false;
142 study = theDesktop->getActiveStudy();
143 timer = new QTimer(this);
144 connect(timer, SIGNAL(timeout()), this, SLOT(execute()));
146 SALOMEDS::Study_var studyDoc = study->getStudyDocument();
147 SALOMEDS::StudyBuilder_var builder = studyDoc->NewBuilder();
148 SALOMEDS::SComponent_var father = studyDoc->FindComponent(STUDY_SUPERVISION);
149 SALOMEDS::GenericAttribute_var anAttr;
150 SALOMEDS::AttributeName_var aName;
151 SALOMEDS::AttributePixMap_var aPixmap;
152 if (father->_is_nil()) {
153 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
155 father = builder->NewComponent(STUDY_SUPERVISION);
156 anAttr = builder->FindOrCreateAttribute(father, "AttributeName");
157 aName = SALOMEDS::AttributeName::_narrow(anAttr);
158 //aName->SetValue("Supervision");
159 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
161 anAttr = builder->FindOrCreateAttribute(father, "AttributePixMap");
162 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
163 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
165 builder->DefineComponentInstance(father, *Supervision.getEngine());
169 objectBrowser = study->getActiveStudyFrame()->getLeftFrame()->getObjectBrowser();
172 graph = new SUPERVGUI_Graph(this);
173 array = new SUPERVGUI_Array(this);
175 message = study->getActiveStudyFrame()->getRightFrame()->getMessage();
176 notification = new NOTIFICATION_Consumer();
178 QBoxLayout * layout = new QVBoxLayout(this);
179 layout->setMargin(0);
180 layout->setSpacing(0);
181 layout->addWidget(graph);
182 layout->addWidget(array);
186 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
187 myLogFile = fopen( myLogFileName.latin1(), "a" );
188 if ( myLogFile == NULL )
193 SUPERVGUI_Main::~SUPERVGUI_Main() {
194 Trace("SUPERVGUI_Main::~SUPERVGUI_Main");
195 if ( myLogFile != NULL) {
198 graph->removeLinks();
199 delete notification; // kloss : nota bene : quand un datalow est detruit : verifier que les canaux de notification sont aussi detruit
200 if (!SUPERV_isNull(dataflow)) {
201 if (dataflow->IsExecuting()) {
202 if (QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
203 tr("MSG_DF_RUNNING"),
204 tr("MSG_DF_EXECUTION"),
205 tr("MSG_DF_KILL")) == 1) {
212 void SUPERVGUI_Main::StartTimer(const char* m) {
213 Trace("SUPERVGUI_Main::StartTimer")
214 if (!timer->isActive()) {
216 message->setMessage(m);
220 void SUPERVGUI_Main::StopTimer(const char* m) {
221 Trace("SUPERVGUI_Main::StopTimer")
222 if (timer->isActive()) {
225 message->setMessage(m);
230 void SUPERVGUI_Main::filterNotification() {
231 Trace("SUPERVGUI_Main::filterNotification");
232 SUPERVGUI_Notification* dlg = new SUPERVGUI_Notification(this);
233 dlg->setFiltered( myFiltered );
234 dlg->setLogged( myLogged, myLogFileName );
235 dlg->setWarning( myWarning );
236 dlg->setStep( myStep );
237 dlg->setTrace( myTrace );
238 dlg->setVerbose( myVerbose );
239 if ( dlg->exec() == QDialog::Accepted ) {
240 myLogged = dlg->getLogged();
241 myLogFileName = dlg->getLogFile();
242 myFiltered = dlg->getFiltered();
243 myWarning = dlg->getWarning();
244 myStep = dlg->getStep();
245 myTrace = dlg->getTrace();
246 myVerbose = dlg->getVerbose();
248 if ( myLogFile != NULL) {
252 if ( myLogged && !myLogFileName.isEmpty() && QFile::exists( myLogFileName ) ) {
253 myLogFile = fopen( myLogFileName.latin1(), "a" );
254 if ( myLogFile == NULL ) {
256 QMessageBox::warning( QAD_Application::getDesktop(), tr("ERROR"), tr( "ERR_CANT_OPEN_LOG_FILE" ) );
262 void SUPERVGUI_Main::syncAsync() {
263 Trace("SUPERVGUI_Main::syncAsync")
264 QTimer::singleShot(1, this, SLOT(sync()));
269 * Called by timer when dataflow is executing
271 void SUPERVGUI_Main::execute() {
273 SUPERV::GraphEvent aEvent;
274 SUPERV::GraphState aState;
275 dataflow->EventNoW(aNode, aEvent, aState);
276 if ((aEvent == SUPERV::NoEvent) && (aState == SUPERV::NoState)) return;
278 if (!SUPERV_isNull(aNode)) {
279 SUPERVGUI_Node* aNodePrs;
280 if (myCurrentView == TABLE) {
281 aNodePrs = (SUPERVGUI_Node*) array->child(aNode->Name(), "SUPERVGUI_Node");
283 aNodePrs = (SUPERVGUI_Node*) graph->child(aNode->Name(), "SUPERVGUI_Node");
288 switch (dataflow->State()) {
289 case SUPERV_Editing :
290 StopTimer(dataflow->IsReadOnly()? tr("MSG_GRAPH_READONLY"): tr("MSG_GRAPH_EDITING"));
293 case SUPERV_Suspend :
294 StopTimer(tr("MSG_GRAPH_SUSPENDED"));
298 StopTimer(tr("MSG_GRAPH_FINISHED"));
302 StopTimer(tr("MSG_GRAPH_ABORTED"));
306 StopTimer(tr("MSG_GRAPH_KILLED"));
314 void SUPERVGUI_Main::sync() {
315 Trace("SUPERVGUI_Main::sync")
316 if ((SUPERV_isNull(dataflow))) return;
317 QString t = tr("GRAPH_TITLE");
319 t += dataflow->Name();
322 study->updateObjBrowser();
323 if (myCurrentView == TABLE) {
331 void SUPERVGUI_Main::showTable() {
332 if (myCurrentView == TABLE) return;
334 if (array->create()) {
335 myCurrentView = TABLE;
342 void SUPERVGUI_Main::showFullGraph() {
343 if (myCurrentView == TABLE) {
347 myCurrentView = GRAPH;
349 graph->setFullView();
353 void SUPERVGUI_Main::showContolFlow() {
354 if (myCurrentView == TABLE) {
358 myCurrentView = CONTROLFLOW;
360 graph->setControlView();
364 bool SUPERVGUI_Main::exportDataflow(QString theFile) {
365 Trace("SUPERVGUI_Main::exportDataflow");
366 if ((SUPERV_isNull(dataflow))) return false;
368 if (!theFile.isEmpty()) {
369 if (!dataflow->Export(theFile.latin1())) {
370 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_WRITING"));
377 void SUPERVGUI_Main::insertFile() {
378 Trace("SUPERVGUI_Main::insertFile")
379 if ((SUPERV_isNull(dataflow))) return;
381 QString f = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
384 tr("MSG_GRAPH_INSERT"),
387 if (dataflow->Import(f.latin1())) {
388 if (myCurrentView == TABLE) {
394 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_BAD_FILE").arg(f));
399 void SUPERVGUI_Main::copy() {
400 Trace("SUPERVGUI_Main::copy");
401 if (dataflow->ThreadsMax() == 0) {
402 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NOTHING_COPY"));
405 QAD_StudyFrame* aStudyFrame = Supervision.createGraph();
406 SUPERVGraph_ViewFrame* aViewFrame = dynamic_cast<SUPERVGraph_ViewFrame*>
407 (aStudyFrame->getRightFrame()->getViewFrame());
409 SUPERV_Graph aNewGraph = dataflow->Copy();
410 QString aNewName(tr("MSG_COPY_PREFIX").arg(++myCopyNum));
411 aNewName += dataflow->Name();
412 aNewGraph->SetName(aNewName);
413 SUPERVGUI_Main* m = new SUPERVGUI_Main(aViewFrame,
414 Supervision.getDesktop(),
416 study->showFrame(aStudyFrame);
420 void SUPERVGUI_Main::run() {
421 Trace("SUPERVGUI_Main::run")
422 if ((SUPERV_isNull(dataflow))) return;
424 if (dataflow->IsEditing()) {
425 if (!dataflow->IsValid()) {
426 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
427 } else if (!dataflow->IsExecutable()) {
428 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
430 myRunTime = QDateTime::currentDateTime();
433 if (!dataflow->ReRun()) {
434 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
436 StartTimer(tr("MSG_GRAPH_STARTED"));
441 if (!dataflow->Run()) {
442 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
444 StartTimer(tr("MSG_GRAPH_STARTED"));
452 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
458 void SUPERVGUI_Main::startExecute() {
459 Trace("SUPERVGUI_Main::startExecute")
460 if ((SUPERV_isNull(dataflow))) return;
462 if (dataflow->IsEditing()) {
463 if (!dataflow->IsValid()) {
464 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTVALID"));
465 } else if (!dataflow->IsExecutable()) {
466 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTEXECUTABLE"));
468 myRunTime = QDateTime::currentDateTime();
471 if (!dataflow->ReStart()) {
472 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
474 StartTimer(tr("MSG_GRAPH_STARTED"));
479 if (!dataflow->Start()) {
480 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_BADEXECUTE"));
482 StartTimer(tr("MSG_GRAPH_STARTED"));
488 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_RUNNING"));
493 void SUPERVGUI_Main::kill() {
494 Trace("SUPERVGUI_Main::kill")
495 if ((SUPERV_isNull(dataflow))) return;
497 if (dataflow->IsEditing()) {
498 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
499 } else if (dataflow->Kill()) {
503 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANTKILL_DF"));
507 void SUPERVGUI_Main::suspendResume() {
508 Trace("SUPERVGUI_Main::suspendResume")
509 if ((SUPERV_isNull(dataflow))) return;
511 if (dataflow->IsEditing()) {
512 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
513 } else if (dataflow->State() == SUPERV_Suspend) {
514 if (dataflow->Resume()) {
515 message->setMessage(tr("MSG_DF_RESUMED"));
518 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUME"));
521 if (dataflow->Suspend()) {
524 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPEND"));
529 void SUPERVGUI_Main::stopRestart() { // kloss : a reviser et a connecter dans le popup du dataflow (pas de creation de bouton)
530 Trace("SUPERVGUI_Main::stopRestart")
531 if ((SUPERV_isNull(dataflow))) return;
533 if (dataflow->IsEditing()) {
534 QMessageBox::warning(0, tr("ERROR"), tr("MSG_DF_NOTRUNNING"));
535 } else if (dataflow->State() == SUPERV_Stop) {
536 if (dataflow->ReStart()) {
537 message->setMessage(tr("MSG_DF_RESTARTED"));
540 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTART"));
543 if (dataflow->Stop()) {
546 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOP"));
551 void SUPERVGUI_Main::addNode() {
552 Trace("SUPERVGUI_Main::addNode");
553 if (SUPERV_isNull(dataflow)) return;
555 if (dataflow->IsExecuting()) {
556 if (QMessageBox::warning(QAD_Application::getDesktop(),
557 tr("WARNING"), tr("MSG_GRAPH_ISRUN"),
558 QMessageBox::Yes, QMessageBox::No) == QMessageBox::No) {
564 Supervision.getBrowser()->choose();
570 * Add Computation node
572 void SUPERVGUI_Main::addComputeNode(SUPERV_CNode theNode) {
573 //cout<<"### X="<<theNode->X()<<" Y="<<theNode->Y()<<endl;
574 switch (myCurrentView) {
577 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
578 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
579 graph->addChild(aNode, theNode->X(), theNode->Y());
585 SUPERVGUI_Node* aNode = new SUPERVGUI_ComputeNode(graph->viewport(), this, theNode);
587 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
588 graph->addChild(aNode, theNode->X(), theNode->Y());
602 void SUPERVGUI_Main::addGOTONode(SUPERV_CNode theNode) {
603 switch (myCurrentView) {
606 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
607 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
608 graph->addChild(aNode, theNode->X(), theNode->Y());
614 SUPERVGUI_Node* aNode = new SUPERVGUI_GotoNode(graph->viewport(), this, theNode);
616 graph->ResizeGraph(aNode, theNode->X(), theNode->Y());
617 graph->addChild(aNode, theNode->X(), theNode->Y());
631 void SUPERVGUI_Main::addControlNode(SUPERV_CNode theStartNode, SUPERV_CNode theEndNode) {
632 switch (myCurrentView) {
635 SUPERVGUI_StartControlNode* aStartPrs =
636 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
637 SUPERVGUI_EndControlNode* aEndPrs =
638 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
640 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
641 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
642 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
643 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
644 aStartPrs->updateLinksPrs();
645 aEndPrs->updateLinksPrs();
648 graph->repaintContents();
653 SUPERVGUI_StartControlNode* aStartPrs =
654 new SUPERVGUI_StartControlNode(graph->viewport(), this, theStartNode);
655 SUPERVGUI_EndControlNode* aEndPrs =
656 new SUPERVGUI_EndControlNode(graph->viewport(), this, theEndNode, aStartPrs);
658 aStartPrs->hideAll();
661 graph->ResizeGraph(aStartPrs, theStartNode->X(), theStartNode->Y());
662 graph->addChild(aStartPrs, theStartNode->X(), theStartNode->Y());
663 graph->ResizeGraph(aEndPrs, theEndNode->X(), theEndNode->Y());
664 graph->addChild(aEndPrs, theEndNode->X(), theEndNode->Y());
665 aStartPrs->updateLinksPrs();
666 aEndPrs->updateLinksPrs();
669 graph->repaintContents();
681 SUPERVGUI_Graph* SUPERVGUI_Main::getGraph() {
682 Trace("SUPERVGUI_Main::getGraph")
686 SUPERVGUI_Array* SUPERVGUI_Main::getArray() {
687 Trace("SUPERVGUI_Main::getArray")
691 SUPERV_Graph SUPERVGUI_Main::getDataflow() {
692 Trace("SUPERVGUI_Main::getDataflow")
696 QAD_Message* SUPERVGUI_Main::getMessage() {
697 Trace("SUPERVGUI_Main::getMessage")
701 QAD_Study* SUPERVGUI_Main::getStudy() {
702 Trace("SUPERVGUI_Main::getStudy")
706 bool SUPERVGUI_Main::isArrayShown() {
707 Trace("SUPERVGUI_Main::isArrayShown")
708 return(myCurrentView == TABLE);
711 void SUPERVGUI_Main::showPopup(QPopupMenu* p, QMouseEvent* e) {
712 Trace("SUPERVGUI_Main::showPopup");
713 // To check is Supervision active?
714 if (myIsLocked) return;
716 // if (QAD_Application::getDesktop()->getActiveComponent().compare(STUDY_SUPERVISION) !=0) return;
717 if (QAD_Application::getDesktop()->getActiveComponent().compare( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) ) !=0) return;
720 if (e->button() == RightButton) {
721 p->exec(e->globalPos());
727 void SUPERVGUI_Main::changeInformation() {
728 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly());
732 /* Trace("SUPERVGUI_Main::changeInformation")
733 if (Supervision.information(SUPERV::CNode::_narrow(dataflow), dataflow->IsReadOnly())) {
738 // returns false, if can't add dataflow into the study
739 bool SUPERVGUI_Main::addStudy() {
740 Trace("SUPERVGUI_Main::addStudy");
741 if (myIsFromStudy) return false;
742 if ((SUPERV_isNull(dataflow))) return false;
744 SALOMEDS::Study_var aStudy = study->getStudyDocument();
745 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
746 SALOMEDS::GenericAttribute_var anAttr;
747 SALOMEDS::AttributeName_var aName;
748 SALOMEDS::AttributeIOR_var anIORAttr;
749 SALOMEDS::AttributePixMap_var aPixmap;
750 bool aLocked = aStudy->GetProperties()->IsLocked();
751 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
753 // searching dataflow
754 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
755 if (aSO->_is_nil()) { // create new dataflow SObject
756 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
757 if (aComponent->_is_nil()) { // is supervision component not found, then create it
758 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
759 anOperation->start();
760 if (aLocked) aStudy->GetProperties()->SetLocked(false);
761 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
762 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
763 aName = SALOMEDS::AttributeName::_narrow(anAttr);
764 //aName->SetValue("Supervision");
765 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
767 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
768 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
769 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
770 aBuilder->DefineComponentInstance(aComponent, *Supervision.getEngine());
771 if (aLocked) aStudy->GetProperties()->SetLocked(true);
772 anOperation->finish();
775 aSO = aBuilder->NewObject(aComponent);
776 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeName");
777 aName = SALOMEDS::AttributeName::_narrow(anAttr);
778 aName->SetValue(dataflow->Name());
779 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
780 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
781 anIORAttr->SetValue(dataflow->getIOR());
783 if (aLocked) return false;
787 Supervision.unregisterGraph(this);
788 Supervision.registerGraph(dataflow->getIOR(), this);
789 myIsFromStudy = true;
794 void SUPERVGUI_Main::chooseData(QListViewItem* item) {
795 Trace("SUPERVGUI_Main::chooseData")
797 QString id = ((QAD_ObjectBrowserItem*)item)->getEntry();
799 SALOMEDS::SObject_var object = study->getStudyDocument()->FindObjectID(id.latin1());
800 SALOMEDS::GenericAttribute_var anAttr;
801 SALOMEDS::AttributeIOR_var anIOR;
802 Standard_CString ior = "";
803 if (object->FindAttribute(anAttr, "AttributeIOR")) {
804 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
805 ior = anIOR->Value();
806 portIn->setValue(ior);
810 setCursor(Supervision.getCursor());
811 objectBrowser->setCursor(Supervision.getCursor());
812 Supervision.putInfo("");
818 void SUPERVGUI_Main::setData(SUPERVGUI_PortIn* p) {
819 Trace("SUPERVGUI_Main::setData")
822 setCursor(forbiddenCursor);
823 objectBrowser->setCursor(pointingHandCursor);
824 Supervision.putInfo(tr("MSG_CHOOSE_DATA"));
827 SALOMEDS::SObject_var SearchOrCreateSOWithName(const SALOMEDS::Study_var theStudy,
828 const SALOMEDS::SObject_var theSO,
830 QAD_Operation* theOperation,
832 SALOMEDS::SObject_var aResult;
833 SALOMEDS::AttributeName_var aName;
834 SALOMEDS::GenericAttribute_var anAttr;
835 if (!*theStarted) { // optimisation
836 SALOMEDS::ChildIterator_var anIterator = theStudy->NewChildIterator(theSO);
837 for (; anIterator->More(); anIterator->Next()) {
838 if (anIterator->Value()->FindAttribute(anAttr, "AttributeName")) {
839 aName = SALOMEDS::AttributeName::_narrow(anAttr);
840 if (strcmp(aName->Value(), theName) == 0) {
841 aResult = anIterator->Value();
847 if (!aResult->_is_nil()) return aResult;
851 theOperation->start();
853 SALOMEDS::StudyBuilder_var aBuilder = theStudy->NewBuilder();
854 aResult = aBuilder->NewObject(theSO);
855 anAttr = aBuilder->FindOrCreateAttribute(aResult, "AttributeName");
856 aName = SALOMEDS::AttributeName::_narrow(anAttr);
857 aName->SetValue(theName);
861 bool SUPERVGUI_Main::putDataStudy(SUPERV_Port p, const char* inout) {
862 Trace("SUPERVGUI_Main::putDataStudy");
864 static bool isIn = false;
865 if (isIn) return true; else isIn = true;
867 SALOMEDS::Study_var aStudy = study->getStudyDocument();
868 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
869 SALOMEDS::GenericAttribute_var anAttr;
870 SALOMEDS::AttributeName_var aName;
871 SALOMEDS::AttributeIOR_var anIORAttr;
872 SALOMEDS::AttributePixMap_var aPixmap;
873 bool aTransaction = false;
874 bool aLocked = aStudy->GetProperties()->IsLocked();
875 QAD_Operation* op = new SALOMEGUI_ImportOperation( study );
877 // searching dataflow
878 SALOMEDS::SObject_var aSO = aStudy->FindObjectIOR(dataflow->getIOR());
879 if (aSO->_is_nil()) { // create new dataflow SObject
880 SALOMEDS::SComponent_ptr aComponent = aStudy->FindComponent(STUDY_SUPERVISION);
881 if (aComponent->_is_nil()) { // is supervision component not found, then create it
882 QAD_Operation* anOperation = new SALOMEGUI_ImportOperation( study );
883 anOperation->start();
884 if (aLocked) aStudy->GetProperties()->SetLocked(false);
885 aComponent = aBuilder->NewComponent(STUDY_SUPERVISION);
886 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributeName");
887 aName = SALOMEDS::AttributeName::_narrow(anAttr);
888 aName->SetValue( QAD_Application::getDesktop()->getComponentUserName( "SUPERV" ) );
890 anAttr = aBuilder->FindOrCreateAttribute(aComponent, "AttributePixMap");
891 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
892 aPixmap->SetPixMap( "ICON_OBJBROWSER_Supervision" );
893 aBuilder->DefineComponentInstance(aComponent, *Supervision.getEngine());
894 if (aLocked) aStudy->GetProperties()->SetLocked(true);
895 anOperation->finish();
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 aSO = SearchOrCreateSOWithName(aStudy, aSO, // get run time SO
908 QString("Run ") + myRunTime.toString() , op, &aTransaction);
909 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Node()->Name(), op, &aTransaction); // get node SO
910 aSO = SearchOrCreateSOWithName(aStudy, aSO, inout, op, &aTransaction); // get in/out SO
911 aSO = SearchOrCreateSOWithName(aStudy, aSO, p->Name(), op, &aTransaction); // get port SO
914 if (aTransaction) op->finish();
919 anAttr = aBuilder->FindOrCreateAttribute(aSO, "AttributeIOR");
920 anIORAttr = SALOMEDS::AttributeIOR::_narrow(anAttr);
921 if (!aTransaction && strcmp(anIORAttr->Value(), p->ToString()) == 0) {
925 // set object value to the study: if object is external, then put it with
926 // help of the specific component - owner
928 // get according component driver for result object
929 SALOME_LifeCycleCORBA aLCC(myNService);
930 SUPERV_FNode aFNode = SUPERV::FNode::_narrow(p->Node());
931 if (!aFNode->_is_nil()) {
932 Engines::Component_var aComponent = aLCC.FindOrLoad_Component(aFNode->GetContainer(),
933 aFNode->GetComponentName());
934 SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(aComponent);
935 if (!CORBA::is_nil(aDriver)) { // if driver was found, publish object
936 CORBA::Object_ptr anObject = new CORBA::Object();
937 CORBA::Any* anAny = p->ToAny();
938 (*anAny) >>= anObject;
940 if (aDriver->CanPublishInStudy(anObject)) {
941 SALOMEDS::SObject_var aTmpSO;
947 aTmpSO = aDriver->PublishInStudy(aStudy, aTmpSO, anObject, "");
948 aBuilder->Addreference(aSO, aTmpSO);
949 } else { // can't publish object: abort transaction
950 if (aTransaction) op->abort();
961 anIORAttr->SetValue(p->ToString()); // ior attribute already set for the prevoius condition
964 if (aTransaction) op->finish();
965 study->updateObjBrowser();
971 void SUPERVGUI_Main::ActivatePanning()
973 if (graph->isVisible()) {
974 graph->ActivatePanning();
975 } else if (array->isVisible()) {
976 array->ActivatePanning();
981 void SUPERVGUI_Main::ResetView()
983 if (graph->isVisible()) {
985 } else if (array->isVisible()) {
991 void SUPERVGUI_Main::setAsFromStudy(bool theToStudy) {
992 myIsFromStudy = theToStudy;
993 graph->setAsFromStudy(theToStudy);
994 array->setAsFromStudy(theToStudy);
997 void SUPERVGUI_Main::checkIsInStudy() {
998 if (!myIsFromStudy) return;
1000 SALOMEDS::Study_var aStudyDoc = study->getStudyDocument();
1001 SALOMEDS::SComponent_var aFatherLbl = aStudyDoc->FindComponent(STUDY_SUPERVISION);
1002 SALOMEDS::ChildIterator_var aChildIterator = aStudyDoc->NewChildIterator(aFatherLbl);
1003 SALOMEDS::SObject_var aDataflowLbl;
1004 SALOMEDS::GenericAttribute_var anAttr;
1006 for (; aChildIterator->More(); aChildIterator->Next()) {
1007 aDataflowLbl = aChildIterator->Value();
1008 if (!aDataflowLbl->FindAttribute(anAttr, "AttributeIOR"))
1011 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1012 if (strcmp(anIOR->Value(), dataflow->getIOR()) == 0) return;
1014 // This Graph considered as in study but in study it is not exists
1015 Supervision.unregisterGraph(this);
1016 setAsFromStudy(false);
1019 void SUPERVGUI_Main::syncNotification() {
1029 while (notification->Receive(&graph, &node, &type, &message, &sender, &counter, &date, &stamp)) {
1030 if (isFiltered(graph, node, type, message, sender, counter, date, stamp)) {
1032 mess += "NOTIF: "; mess += graph;
1033 mess += " / " ; mess += node;
1034 mess += " / " ; mess += type;
1035 mess += " / " ; mess += message;
1036 getMessage()->setMessage(mess.latin1());
1041 bool SUPERVGUI_Main::isFiltered(char* graph, char* node, char* type, char* message,
1042 char* sender, long counter, char* date, long stamp) {
1043 Trace("SUPERVGUI_Main::isFiltered");
1045 if (strcmp(getDataflow()->Name(), graph) == 0) {
1047 QObjectList* nodes = queryList("SUPERVGUI_Node");
1048 QObjectListIt i(*nodes);
1049 while ((n=(SUPERVGUI_Node*)i.current()) != 0) {
1051 if (strcmp(n->name(), node) == 0) {
1052 if (strcmp(type, NOTIF_WARNING) == 0) {
1054 } else if (strcmp(type, NOTIF_STEP) == 0) {
1056 } else if (strcmp(type, NOTIF_TRACE) == 0) {
1058 } else if (strcmp(type, NOTIF_VERBOSE) == 0) {
1065 if ( myLogged && myLogFile && ( ( !myFiltered ) || b ) ) {
1066 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 );
1067 fflush( myLogFile );
1075 void SUPERVGUI_Main::setPaletteBackgroundColor(const QColor& color) {
1076 array->setPaletteBackgroundColor(color);
1077 graph->setPaletteBackgroundColor(color);
1079 SUPERVGraph_View::setPaletteBackgroundColor(color);