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_Main.h"
15 #include "SUPERVGUI.h"
16 #include "SUPERVGUI_BrowseNodeDlg.h"
19 SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
25 Trace("SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort");
26 myPort = SUPERV::Port::_duplicate(thePort);
28 // setName(myPort->Name());
29 setName(myMain->getCanvas()->getPortName(thePort));
32 SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort()
34 Trace("SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort");
35 if (myPrs) delete myPrs;
38 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
39 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
44 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::getPrs() const
46 if (myPrs == 0) ((SUPERVGUI_CanvasPort*)this)->myPrs = createPrs();
50 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
52 return new SUPERVGUI_CanvasPortPrs(myMain->getCanvas(), (SUPERVGUI_CanvasPort*)this);
55 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
57 QPopupMenu* popup = new QPopupMenu(theParent);
58 if (myMain->isEditable()) {
59 int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
60 if (myMain->getDataflow()->IsExecuting())
61 popup->setItemEnabled(anItem, false);
63 popup->setItemEnabled(anItem, !myPort->IsInput() || !myPort->IsLinked()
64 || myPort->Kind() == SUPERV::EndSwitchParameter);
65 popup->insertSeparator();
67 if (myMain->isEditable()
69 ((myPort->IsEndSwitch() && myPort->IsInput())
71 (myPort->IsInLine() && myPort->Node()->Kind() != SUPERV::EndLoopNode
73 !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
74 popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));
77 int anItem = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
78 // if (getEngine()->IsLinked())
79 // popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
81 // popup->setItemEnabled(anItem, getEngine()->HasInput());
86 QPoint SUPERVGUI_CanvasPort::getConnectionPoint() const
88 QPoint p = getPrs()->getConnectionPoint();
90 if (!getPrs()->isVisible()) {
91 if (parent() && parent()->inherits("SUPERVGUI_CanvasNode")) {
92 SUPERVGUI_CanvasNodePrs* aNode = ((SUPERVGUI_CanvasNode*) parent())->getPrs();
93 if (myPort->IsInput())
94 p = aNode->getInConnectionPoint();
96 p = aNode->getOutConnectionPoint();
102 void SUPERVGUI_CanvasPort::update()
104 // ignore update if node itself is destroyed (critical for Start/End control nodes)
105 if (!((SUPERVGUI_CanvasNode*) parent())->isDestroyed())
106 getPrs()->update(true);
109 void SUPERVGUI_CanvasPort::sync()
114 void SUPERVGUI_CanvasPort::sketchLink()
116 myMain->getCanvasView()->startSketch(this);
119 void SUPERVGUI_CanvasPort::remove() {
120 Trace("SUPERVGUI_CanvasPort::remove");
125 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
127 getPrs()->moveBy(dx, dy);
129 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
130 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
131 (*it)->moveByPort(this, dx, dy);
135 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
137 myLinks.append(theLink);
141 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
144 myLinks.remove(theLink);
149 void SUPERVGUI_CanvasPort::updateLinks()
151 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
152 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
153 (*it)->moveByPort(this);
157 void SUPERVGUI_CanvasPort::browse()
159 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
160 aMes += getEngine()->ToString();
161 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), aMes);
165 //***********************************************************
167 //***********************************************************
168 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
169 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
171 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
175 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
177 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
180 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
182 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
183 bool editable = getEngine()->IsInput() && (!getEngine()->IsLinked());
185 if (!getEngine()->IsGate() && editable)
186 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
191 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
193 if (getEngine()->Input(Supervision.getEngine()->StringValue(theValue)))
196 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
199 void SUPERVGUI_CanvasPortIn::setInput()
202 myDlg = new SUPERVGUI_GetValueDlg(this);
203 myDlg->installEventFilter(this);
205 if (!myDlg->isVisible())
209 myDlg->setActiveWindow();
215 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
217 if (o == myDlg && e->type() == QEvent::Close)
219 return SUPERVGUI_CanvasPort::eventFilter(o, e);
223 //***********************************************************
225 //***********************************************************
226 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
227 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
229 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
233 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
235 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
238 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
240 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
242 if (!getEngine()->IsGate()) {
243 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
244 this, SLOT(toStudy()));
250 void SUPERVGUI_CanvasPortOut::sync()
252 bool ok = getEngine()->State() == SUPERV_Ready;
253 if (ok && myInStudy) {
254 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
256 SUPERVGUI_CanvasPort::update();
259 void SUPERVGUI_CanvasPortOut::toStudy()
261 Trace("SUPERVGUI_CanvasPortOut::toStudy");
263 if (getMain()->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) {
264 QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"),
265 tr("WRN_STUDY_LOCKED"));
269 if (!getMain()->isFromStudy()) {
270 if (getMain()->addStudy())
271 getMain()->setAsFromStudy(true);
273 myInStudy = !myInStudy;
275 getMain()->getCanvas()->update();
280 //***********************************************************
282 //***********************************************************
283 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
284 SUPERV::StreamPort_ptr thePort):
285 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
287 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
290 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
292 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
293 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
297 void SUPERVGUI_CanvasStreamPortIn::setParams()
299 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
305 //***********************************************************
306 // Stream Output Port
307 //***********************************************************
308 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
309 SUPERV::StreamPort_ptr thePort):
310 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
312 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
316 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
318 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
319 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
323 void SUPERVGUI_CanvasStreamPortOut::setParams()
325 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);