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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SUPERVGUI_CanvasPort.cxx
23 // Author : Natalia KOPNOVA
26 #include "SUPERVGUI_CanvasPort.h"
27 #include "SUPERVGUI_CanvasNode.h"
28 #include "SUPERVGUI_CanvasLink.h"
29 #include "SUPERVGUI_CanvasNodePrs.h"
30 #include "SUPERVGUI_Clipboard.h"
31 #include "SUPERVGUI_Main.h"
32 #include "SUPERVGUI.h"
33 #include "SUPERVGUI_BrowseNodeDlg.h"
35 #include "SalomeApp_Study.h"
37 SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
43 Trace("SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort");
44 myPort = SUPERV::Port::_duplicate(thePort);
46 // setName(myPort->Name());
47 setName(myMain->getCanvas()->getPortName(thePort));
50 connect(this, SIGNAL(objectDeleted()), myMain, SLOT(onObjectCreatedDeleted()));
53 SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort()
55 Trace("SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort");
56 if (myPrs) delete myPrs;
59 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
60 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
65 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::getPrs() const
67 if (myPrs == 0) ((SUPERVGUI_CanvasPort*)this)->myPrs = createPrs();
71 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
73 return new SUPERVGUI_CanvasPortPrs(myMain->getCanvas(), (SUPERVGUI_CanvasPort*)this);
76 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
78 QPopupMenu* popup = new QPopupMenu(theParent);
79 if ( myMain->isEditable() && !myMain->getDataflow()->IsExecuting() ) {
80 int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
81 if (myMain->getDataflow()->IsExecuting())
82 popup->setItemEnabled(anItem, false);
84 popup->setItemEnabled(anItem, !myPort->IsInput() || !myPort->IsLinked()
85 || myPort->Kind() == SUPERV::EndSwitchParameter);
86 popup->insertSeparator();
88 if (myMain->isEditable() && !myMain->getDataflow()->IsExecuting()
90 ((myPort->IsEndSwitch() && myPort->IsInput())
92 (myPort->IsInLine() && myPort->Node()->Kind() != SUPERV::EndLoopNode
94 !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
95 popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));
97 // Copy Port functionality
98 if (myMain->isEditable() && !myPort->Node()->IsFactory()
99 && !myPort->Node()->IsComputing()
100 && !myPort->Node()->IsMacro())
101 popup->insertItem(tr("ITM_COPY_PORT"), this, SLOT(copy()));
103 /*int anItem = */popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
104 // if (getEngine()->IsLinked())
105 // popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
107 // popup->setItemEnabled(anItem, getEngine()->HasInput());
112 QPoint SUPERVGUI_CanvasPort::getConnectionPoint() const
114 QPoint p = getPrs()->getConnectionPoint();
116 if (!getPrs()->isVisible()) {
117 if (parent() && parent()->inherits("SUPERVGUI_CanvasNode")) {
118 SUPERVGUI_CanvasNodePrs* aNode = ((SUPERVGUI_CanvasNode*) parent())->getPrs();
119 if (myPort->IsInput())
120 p = aNode->getInConnectionPoint();
122 p = aNode->getOutConnectionPoint();
128 void SUPERVGUI_CanvasPort::update()
130 // ignore update if node itself is destroyed (critical for Start/End control nodes)
131 if (!((SUPERVGUI_CanvasNode*) parent())->isDestroyed())
132 getPrs()->update(true);
135 void SUPERVGUI_CanvasPort::sync()
140 void SUPERVGUI_CanvasPort::sketchLink() {
141 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
143 myMain->getCanvasView()->startSketch(this);
146 void SUPERVGUI_CanvasPort::remove() {
147 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
149 //set myCopyPort from Main object to empty if engine of this port is deleted
150 //check if myCopyPort and this port engine is equal
151 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
152 if ( aCB->isCopyPort() )
153 if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) &&
154 QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) &&
155 myPort->IsInput() == aCB->getCopyPort()->IsInput() )
156 aCB->setCopyPort( 0 );
158 Trace("SUPERVGUI_CanvasPort::remove");
161 emit objectDeleted(); // mkr : PAL8237
166 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
168 getPrs()->moveBy(dx, dy);
170 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
171 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
172 (*it)->moveByPort(this, dx, dy);
176 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
178 myLinks.append(theLink);
182 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
185 myLinks.remove(theLink);
190 void SUPERVGUI_CanvasPort::updateLinks()
192 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
193 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
194 (*it)->moveByPort(this);
198 void SUPERVGUI_CanvasPort::browse()
200 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
201 aMes += getEngine()->ToString();
202 QMessageBox::information(SUIT_Session::session()->activeApplication()->desktop(), tr("MSG_INFO"), aMes);
205 void SUPERVGUI_CanvasPort::copy()
207 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
208 aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine()));
211 //***********************************************************
213 //***********************************************************
214 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
215 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
217 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
221 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
223 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
226 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
228 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
229 bool editable = getEngine()->IsInput() && !getEngine()->IsLinked() && !getMain()->getDataflow()->IsExecuting();
231 if (!getEngine()->IsGate() && editable)
232 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
237 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
239 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
240 if (aSupMod && getEngine()->Input(aSupMod->getEngine()->StringValue(theValue)))
243 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
246 void SUPERVGUI_CanvasPortIn::setInput()
248 // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
249 //getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
251 myDlg = new SUPERVGUI_GetValueDlg(this);
252 myDlg->installEventFilter(this);
254 if (!myDlg->isVisible())
258 myDlg->setActiveWindow();
263 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
265 if (o == myDlg && e->type() == QEvent::Close)
267 return SUPERVGUI_CanvasPort::eventFilter(o, e);
271 //***********************************************************
273 //***********************************************************
274 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut(QObject* theParent, SUPERVGUI_Main* theMain, SUPERV::Port_ptr thePort):
275 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
277 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
281 connect(this, SIGNAL(putInStudy( QString* )), getMain(), SLOT(onPutInStudy( QString* )));
284 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
286 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
289 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
291 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
293 if (!getEngine()->IsGate()) {
294 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
295 this, SLOT(toStudy()));
301 void SUPERVGUI_CanvasPortOut::sync()
303 /* asv : 26.01.05 : Bug PAL7164 : sometimes CanvasPortOut::sync() is called twice (or maybe even more)
304 by mistake. It happens because of incorrect Qt events, or other reason, but it is not a
305 stable feature (bug). Adding an object in the study in sync() is therefore called more than once
306 which is a BUG. I decided to move call to putDataStudy() method to Event handling function.
307 When a node successfully finishes execution - check the ports and put out-value to study,
308 if the corresponding flag is set.
309 bool ok = getEngine()->State() == SUPERV_Ready;
310 if (ok && myInStudy) {
311 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
314 SUPERVGUI_CanvasPort::update();
317 void SUPERVGUI_CanvasPortOut::toStudy()
319 Trace("SUPERVGUI_CanvasPortOut::toStudy");
321 // asv 08.02.05 : added && !myInStudy - fix for PAL8105
322 if ( (( SalomeApp_Study* )(getMain()->getStudy()))->studyDS()->GetProperties()->IsLocked() && !myInStudy ) {
323 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WRN_WARNING"),
324 tr("WRN_STUDY_LOCKED"));
328 myInStudy = !myInStudy;
330 getMain()->getCanvas()->update();
332 if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc.
333 if ( getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ) ) {
334 // mkr : PAL8110 : re-register dataflow in object browser with
335 // changing its key to IOR name (from xml-file name, for example)
336 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
338 MESSAGE("NULL Supervision module!");
341 aSupMod->unregisterGraph(getMain());
342 aSupMod->registerGraph(getMain()->getDataflow()->getIOR(), getMain());
346 QString aNodePortName = QString( getEngine()->Node()->Name() ) + QString( "_" ) + QString( getEngine()->Name() );
347 emit putInStudy( &aNodePortName );
353 //***********************************************************
355 //***********************************************************
356 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
357 SUPERV::StreamPort_ptr thePort):
358 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
360 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
363 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
365 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
366 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
370 void SUPERVGUI_CanvasStreamPortIn::setParams()
372 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
378 //***********************************************************
379 // Stream Output Port
380 //***********************************************************
381 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
382 SUPERV::StreamPort_ptr thePort):
383 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
385 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
389 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
391 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
392 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
396 void SUPERVGUI_CanvasStreamPortOut::setParams()
398 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);