1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE
5 // File : SUPERVGUI_CanvasPort.cxx
6 // Author : Natalia KOPNOVA
10 #include "SUPERVGUI_CanvasPort.h"
11 #include "SUPERVGUI_CanvasNode.h"
12 #include "SUPERVGUI_CanvasLink.h"
13 #include "SUPERVGUI_CanvasNodePrs.h"
14 #include "SUPERVGUI_Clipboard.h"
15 #include "SUPERVGUI_Main.h"
16 #include "SUPERVGUI.h"
17 #include "SUPERVGUI_BrowseNodeDlg.h"
19 #include "SalomeApp_Study.h"
21 SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
27 Trace("SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort");
28 myPort = SUPERV::Port::_duplicate(thePort);
30 // setName(myPort->Name());
31 setName(myMain->getCanvas()->getPortName(thePort));
34 SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort()
36 Trace("SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort");
37 if (myPrs) delete myPrs;
40 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
41 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
46 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::getPrs() const
48 if (myPrs == 0) ((SUPERVGUI_CanvasPort*)this)->myPrs = createPrs();
52 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
54 return new SUPERVGUI_CanvasPortPrs(myMain->getCanvas(), (SUPERVGUI_CanvasPort*)this);
57 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
59 QPopupMenu* popup = new QPopupMenu(theParent);
60 if ( myMain->isEditable() && !myMain->getDataflow()->IsExecuting() ) {
61 int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
62 if (myMain->getDataflow()->IsExecuting())
63 popup->setItemEnabled(anItem, false);
65 popup->setItemEnabled(anItem, !myPort->IsInput() || !myPort->IsLinked()
66 || myPort->Kind() == SUPERV::EndSwitchParameter);
67 popup->insertSeparator();
69 if (myMain->isEditable() && !myMain->getDataflow()->IsExecuting()
71 ((myPort->IsEndSwitch() && myPort->IsInput())
73 (myPort->IsInLine() && myPort->Node()->Kind() != SUPERV::EndLoopNode
75 !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
76 popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));
78 // Copy Port functionality
79 if (myMain->isEditable() && !myPort->Node()->IsFactory()
80 && !myPort->Node()->IsComputing()
81 && !myPort->Node()->IsMacro())
82 popup->insertItem(tr("ITM_COPY_PORT"), this, SLOT(copy()));
84 /*int anItem = */popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
85 // if (getEngine()->IsLinked())
86 // popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
88 // popup->setItemEnabled(anItem, getEngine()->HasInput());
93 QPoint SUPERVGUI_CanvasPort::getConnectionPoint() const
95 QPoint p = getPrs()->getConnectionPoint();
97 if (!getPrs()->isVisible()) {
98 if (parent() && parent()->inherits("SUPERVGUI_CanvasNode")) {
99 SUPERVGUI_CanvasNodePrs* aNode = ((SUPERVGUI_CanvasNode*) parent())->getPrs();
100 if (myPort->IsInput())
101 p = aNode->getInConnectionPoint();
103 p = aNode->getOutConnectionPoint();
109 void SUPERVGUI_CanvasPort::update()
111 // ignore update if node itself is destroyed (critical for Start/End control nodes)
112 if (!((SUPERVGUI_CanvasNode*) parent())->isDestroyed())
113 getPrs()->update(true);
116 void SUPERVGUI_CanvasPort::sync()
121 void SUPERVGUI_CanvasPort::sketchLink() {
122 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
124 myMain->getCanvasView()->startSketch(this);
127 void SUPERVGUI_CanvasPort::remove() {
128 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
130 //set myCopyPort from Main object to empty if engine of this port is deleted
131 //check if myCopyPort and this port engine is equal
132 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
133 if ( aCB->isCopyPort() )
134 if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) &&
135 QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) &&
136 myPort->IsInput() == aCB->getCopyPort()->IsInput() )
137 aCB->setCopyPort( 0 );
139 Trace("SUPERVGUI_CanvasPort::remove");
144 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
146 getPrs()->moveBy(dx, dy);
148 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
149 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
150 (*it)->moveByPort(this, dx, dy);
154 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
156 myLinks.append(theLink);
160 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
163 myLinks.remove(theLink);
168 void SUPERVGUI_CanvasPort::updateLinks()
170 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
171 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
172 (*it)->moveByPort(this);
176 void SUPERVGUI_CanvasPort::browse()
178 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
179 aMes += getEngine()->ToString();
180 QMessageBox::information(SUIT_Session::session()->activeApplication()->desktop(), tr("MSG_INFO"), aMes);
183 void SUPERVGUI_CanvasPort::copy()
185 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
186 aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine()));
189 //***********************************************************
191 //***********************************************************
192 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
193 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
195 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
199 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
201 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
204 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
206 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
207 bool editable = getEngine()->IsInput() && !getEngine()->IsLinked() && !getMain()->getDataflow()->IsExecuting();
209 if (!getEngine()->IsGate() && editable)
210 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
215 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
217 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
218 if (aSupMod && getEngine()->Input(aSupMod->getEngine()->StringValue(theValue)))
221 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
224 void SUPERVGUI_CanvasPortIn::setInput()
226 // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
227 //getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
229 myDlg = new SUPERVGUI_GetValueDlg(this);
230 myDlg->installEventFilter(this);
232 if (!myDlg->isVisible())
236 myDlg->setActiveWindow();
241 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
243 if (o == myDlg && e->type() == QEvent::Close)
245 return SUPERVGUI_CanvasPort::eventFilter(o, e);
249 //***********************************************************
251 //***********************************************************
252 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
253 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
255 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
259 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
261 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
264 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
266 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
268 if (!getEngine()->IsGate()) {
269 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
270 this, SLOT(toStudy()));
276 void SUPERVGUI_CanvasPortOut::sync()
278 /* asv : 26.01.05 : Bug PAL7164 : sometimes CanvasPortOut::sync() is called twice (or maybe even more)
279 by mistake. It happens because of incorrect Qt events, or other reason, but it is not a
280 stable feature (bug). Adding an object in the study in sync() is therefore called more than once
281 which is a BUG. I decided to move call to putDataStudy() method to Event handling function.
282 When a node successfully finishes execution - check the ports and put out-value to study,
283 if the corresponding flag is set.
284 bool ok = getEngine()->State() == SUPERV_Ready;
285 if (ok && myInStudy) {
286 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
289 SUPERVGUI_CanvasPort::update();
292 void SUPERVGUI_CanvasPortOut::toStudy()
294 Trace("SUPERVGUI_CanvasPortOut::toStudy");
296 // asv 08.02.05 : added && !myInStudy - fix for PAL8105
297 if ( (( SalomeApp_Study* )(getMain()->getStudy()))->studyDS()->GetProperties()->IsLocked() && !myInStudy ) {
298 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WRN_WARNING"),
299 tr("WRN_STUDY_LOCKED"));
303 myInStudy = !myInStudy;
305 getMain()->getCanvas()->update();
307 if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc.
308 if ( getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ) ) {
309 // mkr : PAL8110 : re-register dataflow in object browser with
310 // changing its key to IOR name (from xml-file name, for example)
311 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
313 MESSAGE("NULL Supervision module!");
316 aSupMod->unregisterGraph(getMain());
317 aSupMod->registerGraph(getMain()->getDataflow()->getIOR(), getMain());
323 //***********************************************************
325 //***********************************************************
326 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
327 SUPERV::StreamPort_ptr thePort):
328 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
330 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
333 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
335 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
336 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
340 void SUPERVGUI_CanvasStreamPortIn::setParams()
342 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
348 //***********************************************************
349 // Stream Output Port
350 //***********************************************************
351 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
352 SUPERV::StreamPort_ptr thePort):
353 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
355 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
359 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
361 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
362 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
366 void SUPERVGUI_CanvasStreamPortOut::setParams()
368 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);