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()->parentWidget();
241 QPoint aPnt(aNode->pos()); // position of the node
243 if (parentWidget()->isVisible()) {
244 aPnt += parentWidget()->parentWidget()->pos();
245 aPnt += parentWidget()->pos();
246 return QPoint(aPnt.x() + pos().x(),
247 aPnt.y() + (pos().y() + height()/2));
249 return QPoint(aPnt.x(),
250 aPnt.y() + (aNode->height()/2));
253 void SUPERVGUI_PortIn::setLinkPrs(SUPERVGUI_Link* theLink) {
255 connect(myLinkPrs, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
256 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
257 popup->setItemEnabled(mySketchItem, false);
260 void SUPERVGUI_PortIn::onDeleteLink(SUPERVGUI_Link*) {
261 disconnect(myLinkPrs, 0, this, 0);
263 popup->setItemEnabled(psc, true);
264 if (port->HasInput())
266 if (main->isEditable()) {
267 popup->setItemEnabled(mySketchItem, true);
269 popup->setItemEnabled(mySketchItem, false);
275 //***********************************************************
279 SUPERVGUI_PortOut::SUPERVGUI_PortOut(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p):
280 SUPERVGUI_Port(parent, m, p),
283 Trace("SUPERVGUI_PortOut::SUPERVGUI_PortOut")
284 // link->move(width()-POINT_SIZE, height()/2-POINT_SIZE_HALF);
285 myLinksList.setAutoDelete(false);
287 if (!port->IsGate()) {
288 pls = popup->insertItem(tr("MSG_PUT_INSTUDY"), this, SLOT(toStudy()));
290 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
292 if (!main->getDataflow()->IsReadOnly()) {
293 popup->setItemEnabled(mySketchItem, true);
295 popup->setItemEnabled(mySketchItem, false);
299 SUPERVGUI_PortOut::~SUPERVGUI_PortOut() {
300 Trace("SUPERVGUI_PortOut::~SUPERVGUI_PortOut");
303 void SUPERVGUI_PortOut::sync() {
304 Trace("SUPERVGUI_PortOut::sync")
305 SUPERVGUI_Port::sync();
307 bool ok = (port->State() == SUPERV_Ready);
308 popup->setItemEnabled(browser, ok);
310 study = main->putDataStudy(port, STUDY_PORT_OUT);
315 popup->changeItem(pls, tr("MSG_NOT_INSTUDY"));
318 popup->changeItem(pls, tr("MSG_PUT_INSTUDY"));
323 void SUPERVGUI_PortOut::updateStudy() {
324 Trace("SUPERVGUI_PortOut::updateStudy")
325 SUPERVGUI_Node* aNode = (SUPERVGUI_Node* )main->getGraph()->child(port->Node()->Name(), "SUPERVGUI_Node");
327 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
330 aNode = (SUPERVGUI_Node* )main->getArray()->child(port->Node()->Name(), "SUPERVGUI_Node");
332 ((SUPERVGUI_PortOut*)aNode->child(port->Name(), "SUPERVGUI_PortOut"))->study = study;
336 void SUPERVGUI_PortOut::toStudy() {
337 Trace("SUPERVGUI_PortOut::toStudy")
338 if (!main->isFromStudy()) {
339 if (main->addStudy()) main->setAsFromStudy(true);
341 if (!main->getStudy()->getStudyDocument()->GetProperties()->IsLocked()) study = !study;
345 void SUPERVGUI_PortOut::browse() {
346 Trace("SUPERVGUI_PortOut::browse")
347 QString mess(tr("MSG_OPORT_VAL"));
348 mess += port->ToString();
349 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
354 * Returns coordinates of connection point in scroll view content coordinates
356 QPoint SUPERVGUI_PortOut::getConnectPnt() {
357 // Parent widget is internal node frame
358 // parent of parent is node it self
359 QWidget* aNode = parentWidget()->parentWidget()->parentWidget();
360 QPoint aPnt(aNode->pos()); // position of the node
361 if (parentWidget()->isVisible()) {
362 aPnt += parentWidget()->parentWidget()->pos();
363 aPnt += parentWidget()->pos();
364 return QPoint(aPnt.x() + pos().x() + width(),
365 aPnt.y() + (pos().y() + height()/2));
367 return QPoint(aPnt.x() + aNode-> width(),
368 aPnt.y() + (aNode->height()/2));
372 void SUPERVGUI_PortOut::addLinkPrs(SUPERVGUI_Link* theLink) {
373 myLinksList.append(theLink);
374 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
375 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
379 void SUPERVGUI_PortOut::onDeleteLink(SUPERVGUI_Link* theLink) {
380 disconnect(theLink, 0, this, 0);
381 myLinksList.remove(theLink);
385 void SUPERVGUI_PortOut::deleteLinks() {
386 if (myLinksList.count() > 0) {
387 SUPERVGUI_Link* aLink;
388 while (aLink = myLinksList.last()) {
389 disconnect(aLink, 0, this, 0);
390 myLinksList.remove(aLink);
391 main->getGraph()->deleteLink(aLink);
398 //***********************************************************
399 // Input Port of EndSwitch Node
400 // ----------------------------
401 SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode(QWidget* parent, SUPERVGUI_Main* m, SUPERV_Port p)
402 : SUPERVGUI_Port(parent, m, p), myDlg( 0 )
404 Trace("SUPERVGUI_PortInESNode::SUPERVGUI_PortInESNode");
405 myLinksList.setAutoDelete(false);
407 bool editing = port->IsInput() && ( !port->IsLinked() ); //main->isEditable();
408 if ((!port->IsGate()) && editing ) {
409 psc = popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
411 browser = popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
414 SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode() {
415 Trace("SUPERVGUI_PortInESNode::~SUPERVGUI_PortInESNode");
418 bool SUPERVGUI_PortInESNode::eventFilter( QObject* o, QEvent* e ) {
419 if ( o == myDlg && e->type() == QEvent::Close )
421 return SUPERVGUI_Port::eventFilter( o, e );
424 void SUPERVGUI_PortInESNode::sync() {
425 SUPERVGUI_Port::sync();
426 if (port->IsLinked()) {
427 popup->setItemEnabled(browser, port->State() == SUPERV_Ready);
429 if (port->HasInput()) {
430 popup->setItemEnabled(browser, true);
433 popup->setItemEnabled(browser, false);
439 void SUPERVGUI_PortInESNode::setValue(const char* d) {
440 Trace("SUPERVGUI_PortIn::setValue")
441 if (port->Input(Supervision.getEngine()->StringValue(d))) {
444 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
449 * Returns coordinates of connection point in content coordinates
451 QPoint SUPERVGUI_PortInESNode::getConnectPnt() {
452 QWidget* aNode = parentWidget()->parentWidget()->parentWidget();
453 QPoint aPnt(aNode->pos());
455 if (parentWidget()->isVisible()) {
456 aPnt += parentWidget()->parentWidget()->pos();
457 aPnt += parentWidget()->pos();
458 return QPoint(aPnt.x() + pos().x(),
459 aPnt.y() + (pos().y() + height()/2));
461 return QPoint(aPnt.x(),
462 aPnt.y() + (aNode->height()/2));
465 void SUPERVGUI_PortInESNode::setLinkPrs(SUPERVGUI_Link* theLink) {
466 myLinksList.append(theLink);
467 connect(theLink, SIGNAL(linkDeleted(SUPERVGUI_Link*)),
468 this, SLOT(onDeleteLink(SUPERVGUI_Link*)));
471 void SUPERVGUI_PortInESNode::deleteLinks() {
472 if (myLinksList.count() > 0) {
473 SUPERVGUI_Link* aLink;
474 while (aLink = myLinksList.last()) {
475 disconnect(aLink, 0, this, 0);
476 myLinksList.remove(aLink);
477 main->getGraph()->deleteLink(aLink);
482 void SUPERVGUI_PortInESNode::setInput() {
483 Trace("SUPERVGUI_PortInESNode::setInput");
485 myDlg = new SUPERVGUI_GetValueDlg(this);
486 myDlg->installEventFilter( this );
488 if ( !myDlg->isVisible() )
492 myDlg->setActiveWindow();
497 void SUPERVGUI_PortInESNode::browse() {
498 Trace("SUPERVGUI_PortInESNode::browse")
499 QString mess(tr("MSG_IPORT_VAL"));
500 mess += port->ToString();
501 QMessageBox::information(QAD_Application::getDesktop(), tr("MSG_INFO"), mess);
505 void SUPERVGUI_PortInESNode::onDeleteLink(SUPERVGUI_Link* theLink) {
506 disconnect(theLink, 0, this, 0);
507 myLinksList.remove(theLink);
509 if (myLinksList.count() == 0) {
510 popup->setItemEnabled(psc, true);
512 popup->setItemEnabled(psc, false);
515 if (port->HasInput())
518 if (main->isEditable()) {
519 popup->setItemEnabled(mySketchItem, true);
521 popup->setItemEnabled(mySketchItem, false);