2 // File : SUPERVGUI_Port.cxx
3 // Created : 25 / 10 / 2001
4 // Author : Francis KLOSS
9 #include "SUPERVGUI_Port.h"
10 #include "SUPERVGUI_Def.h"
11 #include "SUPERVGUI_Main.h"
12 #include "SUPERVGUI_Link.h"
13 #include "SUPERVGUI.h"
14 #include "SUPERVGUI_BrowseNodeDlg.h"
15 #include "QAD_LeftFrame.h"
16 #include "QAD_ObjectBrowser.h"
18 #include "SUPERVGUI_GraphNode.h"
24 SUPERVGUI_Port::SUPERVGUI_Port(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p):
25 SUPERVGUI_Label(parent, PORT_WIDTH, PORT_HEIGHT, "", QLabel::AlignLeft | QLabel::AlignVCenter),
29 Trace("SUPERVGUI_Port::SUPERVGUI_Port");
30 myName = port->Name();
31 QString aName(port->Name());
32 aName += (port->IsInput())? "Input":"Output";
35 if (myName.compare(OUTVOID) == 0)
36 setAlignment(QLabel::AlignRight | QLabel::AlignVCenter);
38 if (port->IsParam() || port->IsInLine())
39 setText(myName + "=" + port->ToString());
45 setFrameShape(QLabel::Box);
46 setFrameShadow(QLabel::Plain);
48 popup = new QPopupMenu(this);
49 if (main->isEditable()) {
50 mySketchItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
51 popup->insertSeparator();
53 if (port->IsInLine()) {
54 myDelItem = popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(deletePort()));
56 connect(this, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
57 connect(this, SIGNAL(MouseRelease(QMouseEvent*)), this, SLOT(endSketch()));
60 SUPERVGUI_Port::~SUPERVGUI_Port() {
61 Trace("SUPERVGUI_Port::~SUPERVGUI_Port")
64 SUPERV_Port SUPERVGUI_Port::getPort() {
65 Trace("SUPERVGUI_Port::getPort")
69 void SUPERVGUI_Port::showPopup(QMouseEvent* e) {
70 Trace("SUPERVGUI_Port::showPopup");
71 if (e->button() != RightButton) return;
72 if (main->getDataflow()->IsExecuting())
73 popup->setItemEnabled(mySketchItem, false);
75 if (!port->IsInput() //output port
77 port->IsInput() && (!port->IsLinked() //not linked input port
79 port->Kind() == SUPERV::EndSwitchParameter)) { //input port of EndSwitch node
80 popup->setItemEnabled(mySketchItem, true);
83 main->showPopup(popup, e);
87 QPoint SUPERVGUI_Port::getConnectPnt() {
92 void SUPERVGUI_Port::sync() {
93 if (port->IsParam() || port->IsInLine())
94 setText(myName + "=" + port->ToString());
101 void SUPERVGUI_Port::sketchLink() {
102 main->getGraph()->sketchBegin(this);
107 void SUPERVGUI_Port::endSketch() {
108 main->getGraph()->sketchEnd(this);
109 if (port->IsInput() && port->IsLinked())
114 void SUPERVGUI_Port::deletePort() {
115 SUPERVGUI_GraphNode* aNode = (SUPERVGUI_GraphNode* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_GraphNode");
117 aNode->deletePort(this);
124 //***********************************************************
128 SUPERVGUI_PortIn::SUPERVGUI_PortIn(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p)
129 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
131 Trace("SUPERVGUI_PortIn::SUPERVGUI_PortIn");
133 // link->move(0, height()/2-POINT_SIZE_HALF);
135 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
136 // bool linked = port->IsLinked();
137 // bool b = (!linked) && editing;
138 if ((!port->IsGate()) && editing ) {
139 psc = popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
141 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
144 SUPERVGUI_PortIn::~SUPERVGUI_PortIn() {
145 Trace("SUPERVGUI_PortIn::~SUPERVGUI_PortIn");
149 bool SUPERVGUI_PortIn::eventFilter( QObject* o, QEvent* e )
151 if ( o == myDlg && e->type() == QEvent::Close )
153 return SUPERVGUI_Port::eventFilter( o, e );
157 void SUPERVGUI_PortIn::deleteLinks() {
159 disconnect(myLinkPrs, 0, this, 0);
160 main->getGraph()->deleteLink(myLinkPrs);
166 void SUPERVGUI_PortIn::sync() {
167 SUPERVGUI_Port::sync();
168 if (port->IsLinked()) {
169 popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
171 if (port->HasInput()) {
172 popup->setItemEnabled(browser, true);
175 popup->setItemEnabled(browser, false);
181 void SUPERVGUI_PortIn::setValue(const char* d) {
182 Trace("SUPERVGUI_PortIn::setValue")
183 if (port->Input((*Supervision.getEngine())->StringValue(d))) {
186 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
190 void SUPERVGUI_PortIn::setInput() {
191 Trace("SUPERVGUI_PortIn::setInput");
193 myDlg = new SUPERVGUI_GetValueDlg(this);
194 myDlg->installEventFilter( this );
196 if ( !myDlg->isVisible() )
200 myDlg->setActiveWindow();
205 void SUPERVGUI_PortIn::browse() {
206 Trace("SUPERVGUI_PortIn::browse")
207 QString mess(tr("MSG_IPORT_VAL"));
208 mess += port->ToString();
209 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
215 * Returns coordinates of connection point in content coordinates
217 QPoint SUPERVGUI_PortIn::getConnectPnt() {
218 // Parent widget is internal node frame
219 // parent of parent is node it self
220 QWidget* aNode = parentWidget()->parentWidget();
221 QPoint aPnt(aNode->pos()); // position of the node
223 if (parentWidget()->isVisible()) {
224 aPnt += parentWidget()->pos();
225 return QPoint(aPnt.x() + pos().x(),
226 aPnt.y() + (pos().y() + height()/2));
228 return QPoint(aPnt.x(),
229 aPnt.y() + (aNode->height()/2));
232 void SUPERVGUI_PortIn::setLinkPrs(SUPERVGUI_Link* theLink) {
234 connect(myLinkPrs, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
235 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
236 popup->setItemEnabled(mySketchItem, false);
239 void SUPERVGUI_PortIn::onDeleteLink(SUPERVGUI_Link*) {
240 disconnect(myLinkPrs, 0, this, 0);
242 popup->setItemEnabled(psc, true);
243 if (port->HasInput())
245 if (main->isEditable()) {
246 popup->setItemEnabled(mySketchItem, true);
248 popup->setItemEnabled(mySketchItem, false);
252 void SUPERVGUI_PortIn::deletePort() {
254 SUPERVGUI_Port::deletePort();
259 //***********************************************************
263 SUPERVGUI_PortOut::SUPERVGUI_PortOut(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p):
264 SUPERVGUI_Port(parent, m, p),
267 Trace("SUPERVGUI_PortOut::SUPERVGUI_PortOut")
268 // link->move(width()-POINT_SIZE, height()/2-POINT_SIZE_HALF);
269 myLinksList.setAutoDelete(false);
271 if (!port->IsGate()) {
272 pls = popup->insertItem(tr("MSG_PUT_INSTUDY"), this, SLOT(toStudy()));
274 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
276 if (!main->getDataflow()->IsReadOnly()) {
277 popup->setItemEnabled(mySketchItem, true);
279 popup->setItemEnabled(mySketchItem, false);
283 SUPERVGUI_PortOut::~SUPERVGUI_PortOut() {
284 Trace("SUPERVGUI_PortOut::~SUPERVGUI_PortOut");
287 void SUPERVGUI_PortOut::sync() {
288 Trace("SUPERVGUI_PortOut::sync")
289 SUPERVGUI_Port::sync();
291 bool ok = (port->State() == SUPERV_Ready);
292 popup->setItemEnabled(browser, ok);
294 study = main->putDataStudy(port, STUDY_PORT_OUT);
299 popup->changeItem(pls, tr("MSG_NOT_INSTUDY"));
302 popup->changeItem(pls, tr("MSG_PUT_INSTUDY"));
307 void SUPERVGUI_PortOut::updateStudy() {
308 Trace("SUPERVGUI_PortOut::updateStudy")
309 SUPERVGUI_Node* aNode = (SUPERVGUI_Node* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_Node");
311 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
314 aNode = (SUPERVGUI_Node* )main->getArray()->child(port->Node()->Name(), "SUPERVGUI_Node");
316 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
320 void SUPERVGUI_PortOut::toStudy() {
321 Trace("SUPERVGUI_PortOut::toStudy")
322 if (!main->isFromStudy()) {
323 if (main->addStudy()) main->setAsFromStudy(true);
325 if (!main->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) study = !study;
329 void SUPERVGUI_PortOut::browse() {
330 Trace("SUPERVGUI_PortOut::browse")
331 QString mess(tr("MSG_OPORT_VAL"));
332 mess += port->ToString();
333 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
338 * Returns coordinates of connection point in scroll view content coordinates
340 QPoint SUPERVGUI_PortOut::getConnectPnt() {
341 // Parent widget is internal node frame
342 // parent of parent is node it self
343 QWidget* aNode = parentWidget()->parentWidget();
344 QPoint aPnt(aNode->pos()); // position of the node
345 if (parentWidget()->isVisible()) {
346 aPnt += parentWidget()->pos();
347 return QPoint(aPnt.x() + pos().x() + width(),
348 aPnt.y() + (pos().y() + height()/2));
350 return QPoint(aPnt.x() + aNode-> width(),
351 aPnt.y() + (aNode->height()/2));
355 void SUPERVGUI_PortOut::addLinkPrs(SUPERVGUI_Link* theLink) {
356 myLinksList.append(theLink);
357 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
358 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
362 void SUPERVGUI_PortOut::onDeleteLink(SUPERVGUI_Link* theLink) {
363 disconnect(theLink, 0, this, 0);
364 myLinksList.remove(theLink);
368 void SUPERVGUI_PortOut::deleteLinks() {
369 if (myLinksList.count() > 0) {
370 SUPERVGUI_Link* aLink;
371 while (aLink = myLinksList.last()) {
372 disconnect(aLink, 0, this, 0);
373 myLinksList.remove(aLink);
374 main->getGraph()->deleteLink(aLink);
380 void SUPERVGUI_PortOut::deletePort() {
382 SUPERVGUI_Port::deletePort();
386 //***********************************************************
387 // Input Port of EndSwitch Node
388 // ----------------------------
389 SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p)
390 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
392 Trace("SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode");
393 myLinksList.setAutoDelete(false);
395 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
396 if ((!port->IsGate()) && editing ) {
397 psc = popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
399 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
402 SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode() {
403 Trace("SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode");
406 bool SUPERVGUI_PortInESNode::eventFilter( QObject* o, QEvent* e ) {
407 if ( o == myDlg && e->type() == QEvent::Close )
409 return SUPERVGUI_Port::eventFilter( o, e );
412 void SUPERVGUI_PortInESNode::sync() {
413 SUPERVGUI_Port::sync();
414 if (port->IsLinked()) {
415 popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
417 if (port->HasInput()) {
418 popup->setItemEnabled(browser, true);
421 popup->setItemEnabled(browser, false);
427 void SUPERVGUI_PortInESNode::setValue(const char* d) {
428 Trace("SUPERVGUI_PortIn::setValue")
429 if (port->Input((*Supervision.getEngine())->StringValue(d))) {
432 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
437 * Returns coordinates of connection point in content coordinates
439 QPoint SUPERVGUI_PortInESNode::getConnectPnt() {
440 QWidget* aNode = parentWidget()->parentWidget();
441 QPoint aPnt(aNode->pos());
443 if (parentWidget()->isVisible()) {
444 aPnt += parentWidget()->pos();
445 return QPoint(aPnt.x() + pos().x(),
446 aPnt.y() + (pos().y() + height()/2));
448 return QPoint(aPnt.x(),
449 aPnt.y() + (aNode->height()/2));
452 void SUPERVGUI_PortInESNode::setLinkPrs(SUPERVGUI_Link* theLink) {
453 myLinksList.append(theLink);
454 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
455 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
458 void SUPERVGUI_PortInESNode::deleteLinks() {
459 if (myLinksList.count() > 0) {
460 SUPERVGUI_Link* aLink;
461 while (aLink = myLinksList.last()) {
462 disconnect(aLink, 0, this, 0);
463 myLinksList.remove(aLink);
464 main->getGraph()->deleteLink(aLink);
469 void SUPERVGUI_PortInESNode::setInput() {
470 Trace("SUPERVGUI_PortInESNode::setInput");
472 myDlg = new SUPERVGUI_GetValueDlg(this);
473 myDlg->installEventFilter( this );
475 if ( !myDlg->isVisible() )
479 myDlg->setActiveWindow();
484 void SUPERVGUI_PortInESNode::browse() {
485 Trace("SUPERVGUI_PortInESNode::browse")
486 QString mess(tr("MSG_IPORT_VAL"));
487 mess += port->ToString();
488 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
492 void SUPERVGUI_PortInESNode::onDeleteLink(SUPERVGUI_Link* theLink) {
493 disconnect(theLink, 0, this, 0);
494 myLinksList.remove(theLink);
496 if (myLinksList.count() == 0) {
497 popup->setItemEnabled(psc, true);
499 popup->setItemEnabled(psc, false);
502 if (port->HasInput())
505 if (main->isEditable()) {
506 popup->setItemEnabled(mySketchItem, true);
508 popup->setItemEnabled(mySketchItem, false);
512 void SUPERVGUI_PortInESNode::deletePort() {
514 SUPERVGUI_Port::deletePort();