1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_CanvasPort.cxx
6 // Author : Natalia KOPNOVA
9 #include "SUPERVGUI_CanvasPort.h"
10 #include "SUPERVGUI_CanvasNode.h"
11 #include "SUPERVGUI_CanvasLink.h"
12 #include "SUPERVGUI_CanvasNodePrs.h"
13 #include "SUPERVGUI_Clipboard.h"
14 #include "SUPERVGUI_Main.h"
15 #include "SUPERVGUI.h"
16 #include "SUPERVGUI_BrowseNodeDlg.h"
18 #include "SalomeApp_Study.h"
20 SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
26 Trace("SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort");
27 myPort = SUPERV::Port::_duplicate(thePort);
29 // setName(myPort->Name());
30 setName(myMain->getCanvas()->getPortName(thePort));
33 connect(this, SIGNAL(objectDeleted()), myMain, SLOT(onObjectCreatedDeleted()));
36 SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort()
38 Trace("SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort");
39 if (myPrs) delete myPrs;
42 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
43 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
48 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::getPrs() const
50 if (myPrs == 0) ((SUPERVGUI_CanvasPort*)this)->myPrs = createPrs();
54 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
56 return new SUPERVGUI_CanvasPortPrs(myMain->getCanvas(), (SUPERVGUI_CanvasPort*)this);
59 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
61 QPopupMenu* popup = new QPopupMenu(theParent);
62 if ( myMain->isEditable() && !myMain->getDataflow()->IsExecuting() ) {
63 int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
64 if (myMain->getDataflow()->IsExecuting())
65 popup->setItemEnabled(anItem, false);
67 popup->setItemEnabled(anItem, !myPort->IsInput() || !myPort->IsLinked()
68 || myPort->Kind() == SUPERV::EndSwitchParameter);
69 popup->insertSeparator();
71 if (myMain->isEditable() && !myMain->getDataflow()->IsExecuting()
73 ((myPort->IsEndSwitch() && myPort->IsInput())
75 (myPort->IsInLine() && myPort->Node()->Kind() != SUPERV::EndLoopNode
77 !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
78 popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));
80 // Copy Port functionality
81 if (myMain->isEditable() && !myPort->Node()->IsFactory()
82 && !myPort->Node()->IsComputing()
83 && !myPort->Node()->IsMacro())
84 popup->insertItem(tr("ITM_COPY_PORT"), this, SLOT(copy()));
86 /*int anItem = */popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
87 // if (getEngine()->IsLinked())
88 // popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
90 // popup->setItemEnabled(anItem, getEngine()->HasInput());
95 QPoint SUPERVGUI_CanvasPort::getConnectionPoint() const
97 QPoint p = getPrs()->getConnectionPoint();
99 if (!getPrs()->isVisible()) {
100 if (parent() && parent()->inherits("SUPERVGUI_CanvasNode")) {
101 SUPERVGUI_CanvasNodePrs* aNode = ((SUPERVGUI_CanvasNode*) parent())->getPrs();
102 if (myPort->IsInput())
103 p = aNode->getInConnectionPoint();
105 p = aNode->getOutConnectionPoint();
111 void SUPERVGUI_CanvasPort::update()
113 // ignore update if node itself is destroyed (critical for Start/End control nodes)
114 if (!((SUPERVGUI_CanvasNode*) parent())->isDestroyed())
115 getPrs()->update(true);
118 void SUPERVGUI_CanvasPort::sync()
123 void SUPERVGUI_CanvasPort::sketchLink() {
124 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
126 myMain->getCanvasView()->startSketch(this);
129 void SUPERVGUI_CanvasPort::remove() {
130 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
132 //set myCopyPort from Main object to empty if engine of this port is deleted
133 //check if myCopyPort and this port engine is equal
134 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
135 if ( aCB->isCopyPort() )
136 if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) &&
137 QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) &&
138 myPort->IsInput() == aCB->getCopyPort()->IsInput() )
139 aCB->setCopyPort( 0 );
141 Trace("SUPERVGUI_CanvasPort::remove");
144 emit objectDeleted(); // mkr : PAL8237
149 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
151 getPrs()->moveBy(dx, dy);
153 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
154 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
155 (*it)->moveByPort(this, dx, dy);
159 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
161 myLinks.append(theLink);
165 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
168 myLinks.remove(theLink);
173 void SUPERVGUI_CanvasPort::updateLinks()
175 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
176 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
177 (*it)->moveByPort(this);
181 void SUPERVGUI_CanvasPort::browse()
183 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
184 aMes += getEngine()->ToString();
185 QMessageBox::information(SUIT_Session::session()->activeApplication()->desktop(), tr("MSG_INFO"), aMes);
188 void SUPERVGUI_CanvasPort::copy()
190 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
191 aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine()));
194 //***********************************************************
196 //***********************************************************
197 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
198 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
200 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
204 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
206 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
209 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
211 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
212 bool editable = getEngine()->IsInput() && !getEngine()->IsLinked() && !getMain()->getDataflow()->IsExecuting();
214 if (!getEngine()->IsGate() && editable)
215 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
220 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
222 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
223 if (aSupMod && getEngine()->Input(aSupMod->getEngine()->StringValue(theValue)))
226 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
229 void SUPERVGUI_CanvasPortIn::setInput()
231 // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
232 //getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
234 myDlg = new SUPERVGUI_GetValueDlg(this);
235 myDlg->installEventFilter(this);
237 if (!myDlg->isVisible())
241 myDlg->setActiveWindow();
246 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
248 if (o == myDlg && e->type() == QEvent::Close)
250 return SUPERVGUI_CanvasPort::eventFilter(o, e);
254 //***********************************************************
256 //***********************************************************
257 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
258 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
260 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
264 connect(this, SIGNAL(putInStudy( QString* )), getMain(), SLOT(onPutInStudy( QString* )));
267 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
269 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
272 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
274 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
276 if (!getEngine()->IsGate()) {
277 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
278 this, SLOT(toStudy()));
284 void SUPERVGUI_CanvasPortOut::sync()
286 /* asv : 26.01.05 : Bug PAL7164 : sometimes CanvasPortOut::sync() is called twice (or maybe even more)
287 by mistake. It happens because of incorrect Qt events, or other reason, but it is not a
288 stable feature (bug). Adding an object in the study in sync() is therefore called more than once
289 which is a BUG. I decided to move call to putDataStudy() method to Event handling function.
290 When a node successfully finishes execution - check the ports and put out-value to study,
291 if the corresponding flag is set.
292 bool ok = getEngine()->State() == SUPERV_Ready;
293 if (ok && myInStudy) {
294 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
297 SUPERVGUI_CanvasPort::update();
300 void SUPERVGUI_CanvasPortOut::toStudy()
302 Trace("SUPERVGUI_CanvasPortOut::toStudy");
304 // asv 08.02.05 : added && !myInStudy - fix for PAL8105
305 if ( (( SalomeApp_Study* )(getMain()->getStudy()))->studyDS()->GetProperties()->IsLocked() && !myInStudy ) {
306 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WRN_WARNING"),
307 tr("WRN_STUDY_LOCKED"));
311 myInStudy = !myInStudy;
313 getMain()->getCanvas()->update();
315 if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc.
316 if ( getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ) ) {
317 // mkr : PAL8110 : re-register dataflow in object browser with
318 // changing its key to IOR name (from xml-file name, for example)
319 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
321 MESSAGE("NULL Supervision module!");
324 aSupMod->unregisterGraph(getMain());
325 aSupMod->registerGraph(getMain()->getDataflow()->getIOR(), getMain());
329 QString aNodePortName = QString( getEngine()->Node()->Name() ) + QString( "_" ) + QString( getEngine()->Name() );
330 emit putInStudy( &aNodePortName );
336 //***********************************************************
338 //***********************************************************
339 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
340 SUPERV::StreamPort_ptr thePort):
341 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
343 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
346 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
348 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
349 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
353 void SUPERVGUI_CanvasStreamPortIn::setParams()
355 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
361 //***********************************************************
362 // Stream Output Port
363 //***********************************************************
364 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
365 SUPERV::StreamPort_ptr thePort):
366 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
368 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
372 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
374 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
375 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
379 void SUPERVGUI_CanvasStreamPortOut::setParams()
381 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);