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() && !myMain->getDataflow()->IsExecuting() ) {
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() && !myMain->getDataflow()->IsExecuting()
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() {
115 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
117 myMain->getCanvasView()->startSketch(this);
120 void SUPERVGUI_CanvasPort::remove() {
121 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
123 Trace("SUPERVGUI_CanvasPort::remove");
128 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
130 getPrs()->moveBy(dx, dy);
132 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
133 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
134 (*it)->moveByPort(this, dx, dy);
138 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
140 myLinks.append(theLink);
144 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
147 myLinks.remove(theLink);
152 void SUPERVGUI_CanvasPort::updateLinks()
154 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
155 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
156 (*it)->moveByPort(this);
160 void SUPERVGUI_CanvasPort::browse()
162 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
163 aMes += getEngine()->ToString();
164 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), aMes);
168 //***********************************************************
170 //***********************************************************
171 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
172 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
174 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
178 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
180 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
183 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
185 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
186 bool editable = getEngine()->IsInput() && !getEngine()->IsLinked() && !getMain()->getDataflow()->IsExecuting();
188 if (!getEngine()->IsGate() && editable)
189 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
194 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
196 if (getEngine()->Input(Supervision.getEngine()->StringValue(theValue)))
199 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
202 void SUPERVGUI_CanvasPortIn::setInput()
204 getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
206 myDlg = new SUPERVGUI_GetValueDlg(this);
207 myDlg->installEventFilter(this);
209 if (!myDlg->isVisible())
213 myDlg->setActiveWindow();
218 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
220 if (o == myDlg && e->type() == QEvent::Close)
222 return SUPERVGUI_CanvasPort::eventFilter(o, e);
226 //***********************************************************
228 //***********************************************************
229 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
230 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
232 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
236 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
238 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
241 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
243 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
245 if (!getEngine()->IsGate()) {
246 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
247 this, SLOT(toStudy()));
253 void SUPERVGUI_CanvasPortOut::sync()
255 bool ok = getEngine()->State() == SUPERV_Ready;
256 if (ok && myInStudy) {
257 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
259 SUPERVGUI_CanvasPort::update();
262 void SUPERVGUI_CanvasPortOut::toStudy()
264 Trace("SUPERVGUI_CanvasPortOut::toStudy");
266 if (getMain()->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) {
267 QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"),
268 tr("WRN_STUDY_LOCKED"));
272 if (!getMain()->isFromStudy()) {
273 if (getMain()->addStudy())
274 getMain()->setAsFromStudy(true);
276 myInStudy = !myInStudy;
278 getMain()->getCanvas()->update();
283 //***********************************************************
285 //***********************************************************
286 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
287 SUPERV::StreamPort_ptr thePort):
288 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
290 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
293 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
295 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
296 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
300 void SUPERVGUI_CanvasStreamPortIn::setParams()
302 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
308 //***********************************************************
309 // Stream Output Port
310 //***********************************************************
311 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
312 SUPERV::StreamPort_ptr thePort):
313 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
315 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
319 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
321 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
322 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
326 void SUPERVGUI_CanvasStreamPortOut::setParams()
328 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);