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 p):
45 SUPERVGUI_Label(parent, PORT_WIDTH, PORT_HEIGHT, "", QLabel::AlignLeft | QLabel::AlignVCenter),
49 Trace("SUPERVGUI_Port::SUPERVGUI_Port");
50 myName = port->Name();
51 QString aName(port->Name());
52 aName += (port->IsInput())? "Input":"Output";
55 if (myName.compare(OUTVOID) == 0)
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 if (port->IsInLine()) {
74 myDelItem = popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(deletePort()));
76 connect(this, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
77 connect(this, SIGNAL(MouseRelease(QMouseEvent*)), this, SLOT(endSketch()));
80 SUPERVGUI_Port::~SUPERVGUI_Port() {
81 Trace("SUPERVGUI_Port::~SUPERVGUI_Port")
84 SUPERV_Port SUPERVGUI_Port::getPort() {
85 Trace("SUPERVGUI_Port::getPort")
89 void SUPERVGUI_Port::showPopup(QMouseEvent* e) {
90 Trace("SUPERVGUI_Port::showPopup");
91 if (e->button() != RightButton) return;
92 if (main->getDataflow()->IsExecuting())
93 popup->setItemEnabled(mySketchItem, false);
95 if (!port->IsInput() //output port
97 port->IsInput() && (!port->IsLinked() //not linked input port
99 port->Kind() == SUPERV::EndSwitchParameter)) { //input port of EndSwitch node
100 popup->setItemEnabled(mySketchItem, true);
103 main->showPopup(popup, e);
107 QPoint SUPERVGUI_Port::getConnectPnt() {
112 void SUPERVGUI_Port::sync() {
113 if (port->IsParam() || port->IsInLine())
114 setText(myName + "=" + port->ToString());
121 void SUPERVGUI_Port::sketchLink() {
122 main->getGraph()->sketchBegin(this);
127 void SUPERVGUI_Port::endSketch() {
128 main->getGraph()->sketchEnd(this);
129 if (port->IsInput() && port->IsLinked())
134 void SUPERVGUI_Port::deletePort() {
135 SUPERVGUI_GraphNode* aNode = (SUPERVGUI_GraphNode* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_GraphNode");
137 aNode->deletePort(this);
144 //***********************************************************
148 SUPERVGUI_PortIn::SUPERVGUI_PortIn(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p)
149 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
151 Trace("SUPERVGUI_PortIn::SUPERVGUI_PortIn");
153 // link->move(0, height()/2-POINT_SIZE_HALF);
155 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
156 // bool linked = port->IsLinked();
157 // bool b = (!linked) && editing;
158 if ((!port->IsGate()) && editing ) {
159 psc = popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
161 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
164 SUPERVGUI_PortIn::~SUPERVGUI_PortIn() {
165 Trace("SUPERVGUI_PortIn::~SUPERVGUI_PortIn");
169 bool SUPERVGUI_PortIn::eventFilter( QObject* o, QEvent* e )
171 if ( o == myDlg && e->type() == QEvent::Close )
173 return SUPERVGUI_Port::eventFilter( o, e );
177 void SUPERVGUI_PortIn::deleteLinks() {
179 disconnect(myLinkPrs, 0, this, 0);
180 main->getGraph()->deleteLink(myLinkPrs);
186 void SUPERVGUI_PortIn::sync() {
187 SUPERVGUI_Port::sync();
188 if (port->IsLinked()) {
189 popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
191 if (port->HasInput()) {
192 popup->setItemEnabled(browser, true);
195 popup->setItemEnabled(browser, false);
201 void SUPERVGUI_PortIn::setValue(const char* d) {
202 Trace("SUPERVGUI_PortIn::setValue")
203 if (port->Input((*Supervision.getEngine())->StringValue(d))) {
206 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
210 void SUPERVGUI_PortIn::setInput() {
211 Trace("SUPERVGUI_PortIn::setInput");
213 myDlg = new SUPERVGUI_GetValueDlg(this);
214 myDlg->installEventFilter( this );
216 if ( !myDlg->isVisible() )
220 myDlg->setActiveWindow();
225 void SUPERVGUI_PortIn::browse() {
226 Trace("SUPERVGUI_PortIn::browse")
227 QString mess(tr("MSG_IPORT_VAL"));
228 mess += port->ToString();
229 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
235 * Returns coordinates of connection point in content coordinates
237 QPoint SUPERVGUI_PortIn::getConnectPnt() {
238 // Parent widget is internal node frame
239 // parent of parent is node it self
240 QWidget* aNode = parentWidget()->parentWidget();
241 QPoint aPnt(aNode->pos()); // position of the node
243 if (parentWidget()->isVisible()) {
244 aPnt += parentWidget()->pos();
245 return QPoint(aPnt.x() + pos().x(),
246 aPnt.y() + (pos().y() + height()/2));
248 return QPoint(aPnt.x(),
249 aPnt.y() + (aNode->height()/2));
252 void SUPERVGUI_PortIn::setLinkPrs(SUPERVGUI_Link* theLink) {
254 connect(myLinkPrs, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
255 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
256 popup->setItemEnabled(mySketchItem, false);
259 void SUPERVGUI_PortIn::onDeleteLink(SUPERVGUI_Link*) {
260 disconnect(myLinkPrs, 0, this, 0);
262 popup->setItemEnabled(psc, true);
263 if (port->HasInput())
265 if (main->isEditable()) {
266 popup->setItemEnabled(mySketchItem, true);
268 popup->setItemEnabled(mySketchItem, false);
274 //***********************************************************
278 SUPERVGUI_PortOut::SUPERVGUI_PortOut(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p):
279 SUPERVGUI_Port(parent, m, p),
282 Trace("SUPERVGUI_PortOut::SUPERVGUI_PortOut")
283 // link->move(width()-POINT_SIZE, height()/2-POINT_SIZE_HALF);
284 myLinksList.setAutoDelete(false);
286 if (!port->IsGate()) {
287 pls = popup->insertItem(tr("MSG_PUT_INSTUDY"), this, SLOT(toStudy()));
289 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
291 if (!main->getDataflow()->IsReadOnly()) {
292 popup->setItemEnabled(mySketchItem, true);
294 popup->setItemEnabled(mySketchItem, false);
298 SUPERVGUI_PortOut::~SUPERVGUI_PortOut() {
299 Trace("SUPERVGUI_PortOut::~SUPERVGUI_PortOut");
302 void SUPERVGUI_PortOut::sync() {
303 Trace("SUPERVGUI_PortOut::sync")
304 SUPERVGUI_Port::sync();
306 bool ok = (port->State() == SUPERV_Ready);
307 popup->setItemEnabled(browser, ok);
309 study = main->putDataStudy(port, STUDY_PORT_OUT);
314 popup->changeItem(pls, tr("MSG_NOT_INSTUDY"));
317 popup->changeItem(pls, tr("MSG_PUT_INSTUDY"));
322 void SUPERVGUI_PortOut::updateStudy() {
323 Trace("SUPERVGUI_PortOut::updateStudy")
324 SUPERVGUI_Node* aNode = (SUPERVGUI_Node* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_Node");
326 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
329 aNode = (SUPERVGUI_Node* )main->getArray()->child(port->Node()->Name(), "SUPERVGUI_Node");
331 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
335 void SUPERVGUI_PortOut::toStudy() {
336 Trace("SUPERVGUI_PortOut::toStudy")
337 if (!main->isFromStudy()) {
338 if (main->addStudy()) main->setAsFromStudy(true);
340 if (!main->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) study = !study;
344 void SUPERVGUI_PortOut::browse() {
345 Trace("SUPERVGUI_PortOut::browse")
346 QString mess(tr("MSG_OPORT_VAL"));
347 mess += port->ToString();
348 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
353 * Returns coordinates of connection point in scroll view content coordinates
355 QPoint SUPERVGUI_PortOut::getConnectPnt() {
356 // Parent widget is internal node frame
357 // parent of parent is node it self
358 QWidget* aNode = parentWidget()->parentWidget();
359 QPoint aPnt(aNode->pos()); // position of the node
360 if (parentWidget()->isVisible()) {
361 aPnt += parentWidget()->pos();
362 return QPoint(aPnt.x() + pos().x() + width(),
363 aPnt.y() + (pos().y() + height()/2));
365 return QPoint(aPnt.x() + aNode-> width(),
366 aPnt.y() + (aNode->height()/2));
370 void SUPERVGUI_PortOut::addLinkPrs(SUPERVGUI_Link* theLink) {
371 myLinksList.append(theLink);
372 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
373 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
377 void SUPERVGUI_PortOut::onDeleteLink(SUPERVGUI_Link* theLink) {
378 disconnect(theLink, 0, this, 0);
379 myLinksList.remove(theLink);
383 void SUPERVGUI_PortOut::deleteLinks() {
384 if (myLinksList.count() > 0) {
385 SUPERVGUI_Link* aLink;
386 while (aLink = myLinksList.last()) {
387 disconnect(aLink, 0, this, 0);
388 myLinksList.remove(aLink);
389 main->getGraph()->deleteLink(aLink);
396 //***********************************************************
397 // Input Port of EndSwitch Node
398 // ----------------------------
399 SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p)
400 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
402 Trace("SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode");
403 myLinksList.setAutoDelete(false);
405 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
406 if ((!port->IsGate()) && editing ) {
407 psc = popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
409 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
412 SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode() {
413 Trace("SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode");
416 bool SUPERVGUI_PortInESNode::eventFilter( QObject* o, QEvent* e ) {
417 if ( o == myDlg && e->type() == QEvent::Close )
419 return SUPERVGUI_Port::eventFilter( o, e );
422 void SUPERVGUI_PortInESNode::sync() {
423 SUPERVGUI_Port::sync();
424 if (port->IsLinked()) {
425 popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
427 if (port->HasInput()) {
428 popup->setItemEnabled(browser, true);
431 popup->setItemEnabled(browser, false);
437 void SUPERVGUI_PortInESNode::setValue(const char* d) {
438 Trace("SUPERVGUI_PortIn::setValue")
439 if (port->Input((*Supervision.getEngine())->StringValue(d))) {
442 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
447 * Returns coordinates of connection point in content coordinates
449 QPoint SUPERVGUI_PortInESNode::getConnectPnt() {
450 QWidget* aNode = parentWidget()->parentWidget();
451 QPoint aPnt(aNode->pos());
453 if (parentWidget()->isVisible()) {
454 aPnt += parentWidget()->pos();
455 return QPoint(aPnt.x() + pos().x(),
456 aPnt.y() + (pos().y() + height()/2));
458 return QPoint(aPnt.x(),
459 aPnt.y() + (aNode->height()/2));
462 void SUPERVGUI_PortInESNode::setLinkPrs(SUPERVGUI_Link* theLink) {
463 myLinksList.append(theLink);
464 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
465 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
468 void SUPERVGUI_PortInESNode::deleteLinks() {
469 if (myLinksList.count() > 0) {
470 SUPERVGUI_Link* aLink;
471 while (aLink = myLinksList.last()) {
472 disconnect(aLink, 0, this, 0);
473 myLinksList.remove(aLink);
474 main->getGraph()->deleteLink(aLink);
479 void SUPERVGUI_PortInESNode::setInput() {
480 Trace("SUPERVGUI_PortInESNode::setInput");
482 myDlg = new SUPERVGUI_GetValueDlg(this);
483 myDlg->installEventFilter( this );
485 if ( !myDlg->isVisible() )
489 myDlg->setActiveWindow();
494 void SUPERVGUI_PortInESNode::browse() {
495 Trace("SUPERVGUI_PortInESNode::browse")
496 QString mess(tr("MSG_IPORT_VAL"));
497 mess += port->ToString();
498 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
502 void SUPERVGUI_PortInESNode::onDeleteLink(SUPERVGUI_Link* theLink) {
503 disconnect(theLink, 0, this, 0);
504 myLinksList.remove(theLink);
506 if (myLinksList.count() == 0) {
507 popup->setItemEnabled(psc, true);
509 popup->setItemEnabled(psc, false);
512 if (port->HasInput())
515 if (main->isEditable()) {
516 popup->setItemEnabled(mySketchItem, true);
518 popup->setItemEnabled(mySketchItem, false);