1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SUPERVGUI_Port.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI_Port.h"
30 #include "SUPERVGUI_Def.h"
31 #include "SUPERVGUI_Main.h"
32 #include "SUPERVGUI_Link.h"
33 #include "SUPERVGUI.h"
34 #include "SUPERVGUI_BrowseNodeDlg.h"
35 #include "QAD_LeftFrame.h"
36 #include "QAD_ObjectBrowser.h"
38 #include "SUPERVGUI_GraphNode.h"
44 SUPERVGUI_Port::SUPERVGUI_Port(QWidget* parent, SUPERVGUI_Main* m, SUPERV::Port_ptr p):
45 SUPERVGUI_Label(parent, PORT_WIDTH, PORT_HEIGHT, "", QLabel::AlignLeft | QLabel::AlignVCenter),
48 Trace("SUPERVGUI_Port::SUPERVGUI_Port");
49 port = SUPERV::Port::_duplicate(p);
50 myName = port->Name();
51 QString aName(port->Name());
52 aName += (port->IsInput())? "Input":"Output";
55 if (!port->IsInput() && port->IsGate())
56 setAlignment(QLabel::AlignRight | QLabel::AlignVCenter);
58 if (port->IsParam() || port->IsInLine())
59 setText(myName + "=" + port->ToString());
65 setFrameShape(QLabel::Box);
66 setFrameShadow(QLabel::Plain);
68 popup = new QPopupMenu(this);
69 if (main->isEditable()) {
70 mySketchItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
71 popup->insertSeparator();
73 //for Loop Node: enable "Delete" popup item only for the input port
74 if ( ( port->IsInLine()
76 ( port->Node()->Kind()!=SUPERV::EndLoopNode )
78 !( port->Node()->Kind()==SUPERV::LoopNode && !port->IsInput() )
81 ( port->IsEndSwitch() && port->IsInput())) {
82 myDelItem = popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(deletePort()));
84 browser = popup->insertItem(tr("MSG_BROWSE"),this, SLOT(browse()));
86 connect(this, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
87 connect(this, SIGNAL(MouseRelease(QMouseEvent*)), this, SLOT(endSketch()));
90 SUPERVGUI_Port::~SUPERVGUI_Port() {
91 Trace("SUPERVGUI_Port::~SUPERVGUI_Port")
94 SUPERV_Port SUPERVGUI_Port::getPort() {
95 Trace("SUPERVGUI_Port::getPort")
99 void SUPERVGUI_Port::showPopup(QMouseEvent* e) {
100 Trace("SUPERVGUI_Port::showPopup");
101 if (e->button() != RightButton) return;
102 if (main->getDataflow()->IsExecuting())
103 popup->setItemEnabled(mySketchItem, false);
105 if (!port->IsInput() //output port
107 port->IsInput() && (!port->IsLinked() //not linked input port
109 port->Kind() == SUPERV::EndSwitchParameter)) { //input port of EndSwitch node
110 popup->setItemEnabled(mySketchItem, true);
113 main->showPopup(popup, e);
117 void SUPERVGUI_Port::browse() {
118 Trace("SUPERVGUI_Port::browse")
119 QString mess = (port->IsInput())? (tr("MSG_IPORT_VAL")) : (tr("MSG_OPORT_VAL"));
120 mess += port->ToString();
121 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
125 QPoint SUPERVGUI_Port::getConnectPnt() {
130 void SUPERVGUI_Port::sync() {
131 if (port->IsParam() || port->IsInLine())
132 setText(myName + "=" + port->ToString());
139 void SUPERVGUI_Port::sketchLink() {
140 main->getGraph()->sketchBegin(this);
145 void SUPERVGUI_Port::endSketch() {
146 main->getGraph()->sketchEnd(this);
147 if (port->IsInput() && port->IsLinked())
152 void SUPERVGUI_Port::deletePort() {
153 SUPERVGUI_GraphNode* aNode = (SUPERVGUI_GraphNode* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_GraphNode");
155 aNode->deletePort(this);
162 //***********************************************************
166 SUPERVGUI_PortIn::SUPERVGUI_PortIn(QWidget* parent, SUPERVGUI_Main* m, SUPERV::Port_ptr p)
167 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
169 Trace("SUPERVGUI_PortIn::SUPERVGUI_PortIn");
171 // link->move(0, height()/2-POINT_SIZE_HALF);
173 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
174 // bool linked = port->IsLinked();
175 // bool b = (!linked) && editing;
176 if ((!port->IsGate()) && editing ) {
177 psc = popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
179 // browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
182 SUPERVGUI_PortIn::~SUPERVGUI_PortIn() {
183 Trace("SUPERVGUI_PortIn::~SUPERVGUI_PortIn");
187 bool SUPERVGUI_PortIn::eventFilter( QObject* o, QEvent* e )
189 if ( o == myDlg && e->type() == QEvent::Close )
191 return SUPERVGUI_Port::eventFilter( o, e );
194 void SUPERVGUI_PortIn::showPopup(QMouseEvent* e){
195 if (e->button() != RightButton) return;
196 if (main->getDataflow()->IsExecuting())
197 popup->setItemEnabled(mySketchItem, false);
199 popup->setItemEnabled(mySketchItem, !port->IsLinked());
200 popup->setItemEnabled(psc, !port->IsLinked());
202 main->showPopup(popup, e);
205 void SUPERVGUI_PortIn::deleteLinks() {
207 disconnect(myLinkPrs, 0, this, 0);
208 main->getGraph()->deleteLink(myLinkPrs);
214 void SUPERVGUI_PortIn::sync() {
215 SUPERVGUI_Port::sync();
216 // if (port->IsLinked()) {
217 // popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
219 if (!port->IsLinked()) {
220 if (port->HasInput()) {
221 // popup->setItemEnabled(browser, true);
224 //popup->setItemEnabled(browser, false);
230 void SUPERVGUI_PortIn::setValue(const char* d) {
231 Trace("SUPERVGUI_PortIn::setValue")
232 if (port->Input(Supervision.getEngine()->StringValue(d))) {
235 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
239 void SUPERVGUI_PortIn::setInput() {
240 Trace("SUPERVGUI_PortIn::setInput");
242 myDlg = new SUPERVGUI_GetValueDlg(this);
243 myDlg->installEventFilter( this );
245 if ( !myDlg->isVisible() )
249 myDlg->setActiveWindow();
254 /*void SUPERVGUI_PortIn::browse() {
255 Trace("SUPERVGUI_PortIn::browse")
256 QString mess(tr("MSG_IPORT_VAL"));
257 mess += port->ToString();
258 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
264 * Returns coordinates of connection point in content coordinates
266 QPoint SUPERVGUI_PortIn::getConnectPnt() {
267 // Parent widget is internal node frame
268 // parent of parent is node it self
269 QWidget* aNode = parentWidget()->parentWidget()->parentWidget();
270 QPoint aPnt(aNode->pos()); // position of the node
272 if (parentWidget()->isVisible()) {
273 aPnt += parentWidget()->parentWidget()->pos();
274 aPnt += parentWidget()->pos();
275 return QPoint(aPnt.x() + pos().x(),
276 aPnt.y() + (pos().y() + height()/2));
278 return QPoint(aPnt.x(),
279 aPnt.y() + (aNode->height()/2));
282 void SUPERVGUI_PortIn::setLinkPrs(SUPERVGUI_Link* theLink) {
284 connect(myLinkPrs, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
285 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
286 popup->setItemEnabled(mySketchItem, false);
289 void SUPERVGUI_PortIn::onDeleteLink(SUPERVGUI_Link*) {
290 disconnect(myLinkPrs, 0, this, 0);
292 popup->setItemEnabled(psc, true);
293 if (port->HasInput())
295 if (main->isEditable()) {
296 popup->setItemEnabled(mySketchItem, true);
298 popup->setItemEnabled(mySketchItem, false);
304 //***********************************************************
308 SUPERVGUI_PortOut::SUPERVGUI_PortOut(QWidget* parent, SUPERVGUI_Main* m, SUPERV::Port_ptr p):
309 SUPERVGUI_Port(parent, m, p),
312 Trace("SUPERVGUI_PortOut::SUPERVGUI_PortOut")
313 // link->move(width()-POINT_SIZE, height()/2-POINT_SIZE_HALF);
314 myLinksList.setAutoDelete(false);
316 if (!port->IsGate()) {
317 pls = popup->insertItem(tr("MSG_PUT_INSTUDY"), this, SLOT(toStudy()));
319 //browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
321 if (!main->getDataflow()->IsReadOnly()) {
322 popup->setItemEnabled(mySketchItem, true);
324 popup->setItemEnabled(mySketchItem, false);
328 SUPERVGUI_PortOut::~SUPERVGUI_PortOut() {
329 Trace("SUPERVGUI_PortOut::~SUPERVGUI_PortOut");
332 void SUPERVGUI_PortOut::sync() {
333 Trace("SUPERVGUI_PortOut::sync")
334 SUPERVGUI_Port::sync();
336 bool ok = (port->State() == SUPERV_Ready);
337 // popup->setItemEnabled(browser, ok);
339 study = main->putDataStudy(port, STUDY_PORT_OUT);
344 popup->changeItem(pls, tr("MSG_NOT_INSTUDY"));
347 popup->changeItem(pls, tr("MSG_PUT_INSTUDY"));
352 void SUPERVGUI_PortOut::updateStudy() {
353 Trace("SUPERVGUI_PortOut::updateStudy")
354 SUPERVGUI_Node* aNode = (SUPERVGUI_Node* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_Node");
356 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
359 aNode = (SUPERVGUI_Node* )main->getArray()->child(port->Node()->Name(), "SUPERVGUI_Node");
361 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
365 void SUPERVGUI_PortOut::toStudy() {
366 Trace("SUPERVGUI_PortOut::toStudy")
368 if (main->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) {
369 QMessageBox::warning(QAD_Application::getDesktop(), tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"));
373 if (!main->isFromStudy()) {
374 if (main->addStudy()) main->setAsFromStudy(true);
380 /*void SUPERVGUI_PortOut::browse() {
381 Trace("SUPERVGUI_PortOut::browse")
382 QString mess(tr("MSG_OPORT_VAL"));
383 mess += port->ToString();
384 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
389 * Returns coordinates of connection point in scroll view content coordinates
391 QPoint SUPERVGUI_PortOut::getConnectPnt() {
392 // Parent widget is internal node frame
393 // parent of parent is node it self
394 QWidget* aNode = parentWidget()->parentWidget()->parentWidget();
395 QPoint aPnt(aNode->pos()); // position of the node
396 if (parentWidget()->isVisible()) {
397 aPnt += parentWidget()->parentWidget()->pos();
398 aPnt += parentWidget()->pos();
399 return QPoint(aPnt.x() + pos().x() + width(),
400 aPnt.y() + (pos().y() + height()/2));
402 return QPoint(aPnt.x() + aNode-> width(),
403 aPnt.y() + (aNode->height()/2));
407 void SUPERVGUI_PortOut::addLinkPrs(SUPERVGUI_Link* theLink) {
408 myLinksList.append(theLink);
409 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
410 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
414 void SUPERVGUI_PortOut::onDeleteLink(SUPERVGUI_Link* theLink) {
415 disconnect(theLink, 0, this, 0);
416 myLinksList.remove(theLink);
420 void SUPERVGUI_PortOut::deleteLinks() {
421 if (myLinksList.count() > 0) {
422 while (SUPERVGUI_Link* aLink = myLinksList.last()) {
423 disconnect(aLink, 0, this, 0);
424 myLinksList.remove(aLink);
425 main->getGraph()->deleteLink(aLink);
432 // ----------------------------
433 // Input Port of EndSwitch Node
434 // ----------------------------
435 SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode(QWidget* parent, SUPERVGUI_Main* m, SUPERV::Port_ptr p)
436 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
438 Trace("SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode");
439 myLinksList.setAutoDelete(false);
441 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
442 if ((!port->IsGate()) && editing ) {
443 psc = popup->insertItem(tr("MSG_SETVALUE"),this, SLOT(setInput()));
445 // browser = popup->insertItem(tr("MSG_BROWSE"),this, SLOT(browse()));
448 SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode() {
449 Trace("SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode");
452 bool SUPERVGUI_PortInESNode::eventFilter( QObject* o, QEvent* e ) {
453 if ( o == myDlg && e->type() == QEvent::Close )
455 return SUPERVGUI_Port::eventFilter( o, e );
458 void SUPERVGUI_PortInESNode::sync() {
459 SUPERVGUI_Port::sync();
460 /* if (port->IsLinked()) {
461 popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
463 if (!port->IsLinked()) {
464 if (port->HasInput()) {
465 // popup->setItemEnabled(browser, true);
468 // popup->setItemEnabled(browser, false);
474 void SUPERVGUI_PortInESNode::setValue(const char* d) {
475 Trace("SUPERVGUI_PortIn::setValue")
476 if (port->Input(Supervision.getEngine()->StringValue(d))) {
479 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
484 * Returns coordinates of connection point in content coordinates
486 QPoint SUPERVGUI_PortInESNode::getConnectPnt() {
487 QWidget* aNode = parentWidget()->parentWidget()->parentWidget();
488 QPoint aPnt(aNode->pos());
490 if (parentWidget()->isVisible()) {
491 aPnt += parentWidget()->parentWidget()->pos();
492 aPnt += parentWidget()->pos();
493 return QPoint(aPnt.x() + pos().x(),
494 aPnt.y() + (pos().y() + height()/2));
496 return QPoint(aPnt.x(),
497 aPnt.y() + (aNode->height()/2));
500 void SUPERVGUI_PortInESNode::setLinkPrs(SUPERVGUI_Link* theLink) {
501 myLinksList.append(theLink);
502 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
503 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
506 void SUPERVGUI_PortInESNode::deleteLinks() {
507 if (myLinksList.count() > 0) {
508 while (SUPERVGUI_Link* aLink = myLinksList.last()) {
509 disconnect(aLink, 0, this, 0);
510 myLinksList.remove(aLink);
511 main->getGraph()->deleteLink(aLink);
516 void SUPERVGUI_PortInESNode::setInput() {
517 Trace("SUPERVGUI_PortInESNode::setInput");
519 myDlg = new SUPERVGUI_GetValueDlg(this);
520 myDlg->installEventFilter( this );
522 if ( !myDlg->isVisible() )
526 myDlg->setActiveWindow();
531 /*void SUPERVGUI_PortInESNode::browse() {
532 Trace("SUPERVGUI_PortInESNode::browse")
533 QString mess(tr("MSG_IPORT_VAL"));
534 mess += port->ToString();
535 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
539 void SUPERVGUI_PortInESNode::onDeleteLink(SUPERVGUI_Link* theLink) {
540 disconnect(theLink, 0, this, 0);
541 myLinksList.remove(theLink);
543 if (myLinksList.count() == 0) {
544 popup->setItemEnabled(psc, true);
546 popup->setItemEnabled(psc, false);
549 if (port->HasInput())
552 if (main->isEditable()) {
553 popup->setItemEnabled(mySketchItem, true);
555 popup->setItemEnabled(mySketchItem, false);
561 // ----------------------------
563 // ----------------------------
565 SUPERVGUI_StreamPortIn::SUPERVGUI_StreamPortIn(QWidget* parent, SUPERVGUI_Main* m, SUPERV::StreamPort_ptr p):
566 SUPERVGUI_PortIn(parent, m, p)
568 myPort = SUPERV::StreamPort::_duplicate(p);
569 myParamItem = popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
572 SUPERVGUI_StreamPortIn::~SUPERVGUI_StreamPortIn()
577 void SUPERVGUI_StreamPortIn::setParams()
579 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
585 void SUPERVGUI_StreamPortIn::sync()
587 SUPERVGUI_PortIn::sync();
588 setText(myName + "=" + myPort->ToString());
592 //------------------------------------------------------------------------------------------------
594 SUPERVGUI_StreamPortOut::SUPERVGUI_StreamPortOut(QWidget* parent, SUPERVGUI_Main* m, SUPERV::StreamPort_ptr p):
595 SUPERVGUI_PortOut(parent, m, p)
597 myPort = SUPERV::StreamPort::_duplicate(p);
598 myParamItem = popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
601 SUPERVGUI_StreamPortOut::~SUPERVGUI_StreamPortOut()
605 void SUPERVGUI_StreamPortOut::setParams()
607 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);
613 void SUPERVGUI_StreamPortOut::sync()
615 SUPERVGUI_PortOut::sync();
616 setText(myName + "=" + myPort->ToString());
620 //------------------------------------------------------------------------------------------------