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"
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 SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort()
35 Trace("SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort");
36 if (myPrs) delete myPrs;
39 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
40 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
45 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::getPrs() const
47 if (myPrs == 0) ((SUPERVGUI_CanvasPort*)this)->myPrs = createPrs();
51 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
53 return new SUPERVGUI_CanvasPortPrs(myMain->getCanvas(), (SUPERVGUI_CanvasPort*)this);
56 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
58 QPopupMenu* popup = new QPopupMenu(theParent);
59 if ( myMain->isEditable() && !myMain->getDataflow()->IsExecuting() ) {
60 int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
61 if (myMain->getDataflow()->IsExecuting())
62 popup->setItemEnabled(anItem, false);
64 popup->setItemEnabled(anItem, !myPort->IsInput() || !myPort->IsLinked()
65 || myPort->Kind() == SUPERV::EndSwitchParameter);
66 popup->insertSeparator();
68 if (myMain->isEditable() && !myMain->getDataflow()->IsExecuting()
70 ((myPort->IsEndSwitch() && myPort->IsInput())
72 (myPort->IsInLine() && myPort->Node()->Kind() != SUPERV::EndLoopNode
74 !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
75 popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));
77 // Copy Port functionality
78 if (myMain->isEditable() && !myPort->Node()->IsFactory()
79 && !myPort->Node()->IsComputing()
80 && !myPort->Node()->IsMacro())
81 popup->insertItem(tr("ITM_COPY_PORT"), this, SLOT(copy()));
83 /*int anItem = */popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
84 // if (getEngine()->IsLinked())
85 // popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
87 // popup->setItemEnabled(anItem, getEngine()->HasInput());
92 QPoint SUPERVGUI_CanvasPort::getConnectionPoint() const
94 QPoint p = getPrs()->getConnectionPoint();
96 if (!getPrs()->isVisible()) {
97 if (parent() && parent()->inherits("SUPERVGUI_CanvasNode")) {
98 SUPERVGUI_CanvasNodePrs* aNode = ((SUPERVGUI_CanvasNode*) parent())->getPrs();
99 if (myPort->IsInput())
100 p = aNode->getInConnectionPoint();
102 p = aNode->getOutConnectionPoint();
108 void SUPERVGUI_CanvasPort::update()
110 // ignore update if node itself is destroyed (critical for Start/End control nodes)
111 if (!((SUPERVGUI_CanvasNode*) parent())->isDestroyed())
112 getPrs()->update(true);
115 void SUPERVGUI_CanvasPort::sync()
120 void SUPERVGUI_CanvasPort::sketchLink() {
121 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
123 myMain->getCanvasView()->startSketch(this);
126 void SUPERVGUI_CanvasPort::remove() {
127 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
129 //set myCopyPort from Main object to empty if engine of this port is deleted
130 //check if myCopyPort and this port engine is equal
131 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
132 if ( aCB->isCopyPort() )
133 if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) &&
134 QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) &&
135 myPort->IsInput() == aCB->getCopyPort()->IsInput() )
136 aCB->setCopyPort( 0 );
138 Trace("SUPERVGUI_CanvasPort::remove");
143 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
145 getPrs()->moveBy(dx, dy);
147 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
148 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
149 (*it)->moveByPort(this, dx, dy);
153 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
155 myLinks.append(theLink);
159 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
162 myLinks.remove(theLink);
167 void SUPERVGUI_CanvasPort::updateLinks()
169 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
170 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
171 (*it)->moveByPort(this);
175 void SUPERVGUI_CanvasPort::browse()
177 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
178 aMes += getEngine()->ToString();
179 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), aMes);
182 void SUPERVGUI_CanvasPort::copy()
184 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
185 aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine()));
188 //***********************************************************
190 //***********************************************************
191 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
192 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
194 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
198 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
200 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
203 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
205 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
206 bool editable = getEngine()->IsInput() && !getEngine()->IsLinked() && !getMain()->getDataflow()->IsExecuting();
208 if (!getEngine()->IsGate() && editable)
209 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
214 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
216 if (getEngine()->Input(Supervision.getEngine()->StringValue(theValue)))
219 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
222 void SUPERVGUI_CanvasPortIn::setInput()
224 // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
225 //getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
227 myDlg = new SUPERVGUI_GetValueDlg(this);
228 myDlg->installEventFilter(this);
230 if (!myDlg->isVisible())
234 myDlg->setActiveWindow();
239 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
241 if (o == myDlg && e->type() == QEvent::Close)
243 return SUPERVGUI_CanvasPort::eventFilter(o, e);
247 //***********************************************************
249 //***********************************************************
250 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
251 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
253 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
257 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
259 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
262 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
264 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
266 if (!getEngine()->IsGate()) {
267 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
268 this, SLOT(toStudy()));
274 void SUPERVGUI_CanvasPortOut::sync()
276 /* asv : 26.01.05 : Bug PAL7164 : sometimes CanvasPortOut::sync() is called twice (or maybe even more)
277 by mistake. It happens because of incorrect Qt events, or other reason, but it is not a
278 stable feature (bug). Adding an object in the study in sync() is therefore called more than once
279 which is a BUG. I decided to move call to putDataStudy() method to Event handling function.
280 When a node successfully finishes execution - check the ports and put out-value to study,
281 if the corresponding flag is set.
282 bool ok = getEngine()->State() == SUPERV_Ready;
283 if (ok && myInStudy) {
284 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
287 SUPERVGUI_CanvasPort::update();
290 void SUPERVGUI_CanvasPortOut::toStudy()
292 Trace("SUPERVGUI_CanvasPortOut::toStudy");
294 if (getMain()->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) {
295 QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"),
296 tr("WRN_STUDY_LOCKED"));
300 myInStudy = !myInStudy;
302 getMain()->getCanvas()->update();
304 if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc.
305 getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT );
310 //***********************************************************
312 //***********************************************************
313 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
314 SUPERV::StreamPort_ptr thePort):
315 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
317 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
320 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
322 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
323 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
327 void SUPERVGUI_CanvasStreamPortIn::setParams()
329 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
335 //***********************************************************
336 // Stream Output Port
337 //***********************************************************
338 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
339 SUPERV::StreamPort_ptr thePort):
340 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
342 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
346 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
348 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
349 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
353 void SUPERVGUI_CanvasStreamPortOut::setParams()
355 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);