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,
38 SUPERV::Port_ptr thePort):
44 Trace("SUPERVGUI_CanvasPort::SUPERVGUI_CanvasPort");
45 myPort = SUPERV::Port::_duplicate(thePort);
47 // setName(myPort->Name());
48 setName(myMain->getCanvas()->getPortName(thePort));
51 connect(this, SIGNAL(objectDeleted()), myMain, SLOT(onObjectCreatedDeleted()));
54 SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort()
56 Trace("SUPERVGUI_CanvasPort::~SUPERVGUI_CanvasPort");
57 if (myPrs) delete myPrs;
60 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
61 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
66 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::getPrs() const
68 if (myPrs == 0) ((SUPERVGUI_CanvasPort*)this)->myPrs = createPrs();
72 SUPERVGUI_CanvasPortPrs* SUPERVGUI_CanvasPort::createPrs() const
74 return new SUPERVGUI_CanvasPortPrs(myMain->getCanvas(), (SUPERVGUI_CanvasPort*)this);
77 QPopupMenu* SUPERVGUI_CanvasPort::getPopupMenu(QWidget* theParent)
79 QPopupMenu* popup = new QPopupMenu(theParent);
80 if ( myMain->isEditable() && !myMain->getDataflow()->IsExecuting() ) {
81 int anItem = popup->insertItem(tr("MSG_SKETCH_LINK"), this, SLOT(sketchLink()));
82 if (myMain->getDataflow()->IsExecuting())
83 popup->setItemEnabled(anItem, false);
85 popup->setItemEnabled(anItem, !myPort->IsInput() || !myPort->IsLinked()
86 || myPort->Kind() == SUPERV::EndSwitchParameter);
87 popup->insertSeparator();
89 if (myMain->isEditable() && !myMain->getDataflow()->IsExecuting()
91 ((myPort->IsEndSwitch() && myPort->IsInput())
93 (myPort->IsInLine() && myPort->Node()->Kind() != SUPERV::EndLoopNode
95 !(myPort->Node()->Kind() == SUPERV::LoopNode && !myPort->IsInput())))) {
96 popup->insertItem(tr("ITM_DEL_PORT"), this, SLOT(remove()));
98 // Copy Port functionality
99 if (myMain->isEditable() && !myPort->Node()->IsFactory()
100 && !myPort->Node()->IsComputing()
101 && !myPort->Node()->IsMacro())
102 popup->insertItem(tr("ITM_COPY_PORT"), this, SLOT(copy()));
104 /*int anItem = */popup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
105 // if (getEngine()->IsLinked())
106 // popup->setItemEnabled(anItem, getEngine()->State() == SUPERV_Ready);
108 // popup->setItemEnabled(anItem, getEngine()->HasInput());
113 QPoint SUPERVGUI_CanvasPort::getConnectionPoint() const
115 QPoint p = getPrs()->getConnectionPoint();
117 if (!getPrs()->isVisible()) {
118 if (parent() && parent()->inherits("SUPERVGUI_CanvasNode")) {
119 SUPERVGUI_CanvasNodePrs* aNode = ((SUPERVGUI_CanvasNode*) parent())->getPrs();
120 if (myPort->IsInput())
121 p = aNode->getInConnectionPoint();
123 p = aNode->getOutConnectionPoint();
129 void SUPERVGUI_CanvasPort::update()
131 // ignore update if node itself is destroyed (critical for Start/End control nodes)
132 if (!((SUPERVGUI_CanvasNode*) parent())->isDestroyed())
133 getPrs()->update(true);
136 void SUPERVGUI_CanvasPort::sync()
141 void SUPERVGUI_CanvasPort::sketchLink() {
142 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
144 myMain->getCanvasView()->startSketch(this);
147 void SUPERVGUI_CanvasPort::remove() {
148 myMain->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
150 //set myCopyPort from Main object to empty if engine of this port is deleted
151 //check if myCopyPort and this port engine is equal
152 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
153 if ( aCB->isCopyPort() )
154 if ( QString(myPort->Node()->Name()) == QString(aCB->getCopyPort()->Node()->Name()) &&
155 QString(myPort->Name()) == QString(aCB->getCopyPort()->Name()) &&
156 myPort->IsInput() == aCB->getCopyPort()->IsInput() )
157 aCB->setCopyPort( 0 );
159 Trace("SUPERVGUI_CanvasPort::remove");
162 emit objectDeleted(); // mkr : PAL8237
167 void SUPERVGUI_CanvasPort::moveBy(int dx, int dy)
169 getPrs()->moveBy(dx, dy);
171 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
172 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
173 (*it)->moveByPort(this, dx, dy);
177 void SUPERVGUI_CanvasPort::addLink(SUPERVGUI_CanvasLink* theLink)
179 myLinks.append(theLink);
183 void SUPERVGUI_CanvasPort::removeLink(SUPERVGUI_CanvasLink* theLink)
186 myLinks.remove(theLink);
191 void SUPERVGUI_CanvasPort::updateLinks()
193 QValueList<SUPERVGUI_CanvasLink*>::Iterator it;
194 for (it = myLinks.begin(); it != myLinks.end(); ++it) {
195 (*it)->moveByPort(this);
199 void SUPERVGUI_CanvasPort::browse()
201 QString aMes(getEngine()->IsInput()? tr("MSG_IPORT_VAL") : tr("MSG_OPORT_VAL"));
202 aMes += getEngine()->ToString();
203 QMessageBox::information(SUIT_Session::session()->activeApplication()->desktop(), tr("MSG_INFO"), aMes);
206 void SUPERVGUI_CanvasPort::copy()
208 SUPERVGUI_Clipboard* aCB = SUPERVGUI_Clipboard::getClipboard();
209 aCB->setCopyPort(SUPERV::Port::_duplicate(getEngine()));
212 //***********************************************************
214 //***********************************************************
215 SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn (QObject* theParent, SUPERVGUI_Main* theMain,
216 SUPERV::Port_ptr thePort):
217 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
219 Trace("SUPERVGUI_CanvasPortIn::SUPERVGUI_CanvasPortIn");
223 SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn()
225 Trace("SUPERVGUI_CanvasPortIn::~SUPERVGUI_CanvasPortIn");
228 QPopupMenu* SUPERVGUI_CanvasPortIn::getPopupMenu(QWidget* theParent)
230 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
231 bool editable = (getEngine()->IsInput() &&
232 !getEngine()->IsLinked() &&
233 !getMain()->getDataflow()->IsExecuting());
235 if (!getEngine()->IsGate() && editable)
236 popup->insertItem(tr("MSG_SETVALUE"), this, SLOT(setInput()));
241 void SUPERVGUI_CanvasPortIn::setValue(const char* theValue)
243 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
244 if (aSupMod && getEngine()->Input(aSupMod->getEngine()->StringValue(theValue)))
247 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("ERROR"), tr("MSG_CANT_SETVAL"));
250 void SUPERVGUI_CanvasPortIn::setInput()
252 // asv 28.01.05 : set "Editing" flag only on "OK" pressed in BrowseDlg
253 //getMain()->Editing(); // PAL6170: GUI->Engine: setting "Editing" flag
255 myDlg = new SUPERVGUI_GetValueDlg(this);
256 myDlg->installEventFilter(this);
258 if (!myDlg->isVisible())
262 myDlg->setActiveWindow();
267 bool SUPERVGUI_CanvasPortIn::eventFilter(QObject* o, QEvent* e)
269 if (o == myDlg && e->type() == QEvent::Close)
271 return SUPERVGUI_CanvasPort::eventFilter(o, e);
275 //***********************************************************
277 //***********************************************************
278 SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut (QObject* theParent, SUPERVGUI_Main* theMain,
279 SUPERV::Port_ptr thePort):
280 SUPERVGUI_CanvasPort(theParent, theMain, thePort)
282 Trace("SUPERVGUI_CanvasPortOut::SUPERVGUI_CanvasPortOut");
286 connect(this, SIGNAL(putInStudy( QString* )), getMain(), SLOT(onPutInStudy( QString* )));
289 SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut()
291 Trace("SUPERVGUI_CanvasPortOut::~SUPERVGUI_CanvasPortOut");
294 QPopupMenu* SUPERVGUI_CanvasPortOut::getPopupMenu(QWidget* theParent)
296 QPopupMenu* popup = SUPERVGUI_CanvasPort::getPopupMenu(theParent);
298 if (!getEngine()->IsGate()) {
299 popup->insertItem(myInStudy?tr("MSG_NOT_INSTUDY"):tr("MSG_PUT_INSTUDY"),
300 this, SLOT(toStudy()));
306 void SUPERVGUI_CanvasPortOut::sync()
308 /* asv : 26.01.05 : Bug PAL7164 : sometimes CanvasPortOut::sync() is called twice (or maybe even more)
309 by mistake. It happens because of incorrect Qt events, or other reason, but it is not a
310 stable feature (bug). Adding an object in the study in sync() is therefore called more than once
311 which is a BUG. I decided to move call to putDataStudy() method to Event handling function.
312 When a node successfully finishes execution - check the ports and put out-value to study,
313 if the corresponding flag is set.
314 bool ok = getEngine()->State() == SUPERV_Ready;
315 if (ok && myInStudy) {
316 myInStudy = getMain()->putDataStudy(getEngine(), STUDY_PORT_OUT);
319 SUPERVGUI_CanvasPort::update();
322 void SUPERVGUI_CanvasPortOut::toStudy()
324 Trace("SUPERVGUI_CanvasPortOut::toStudy");
326 // asv 08.02.05 : added && !myInStudy - fix for PAL8105
327 if ( (( SalomeApp_Study* )(getMain()->getStudy()))->studyDS()->GetProperties()->IsLocked() && !myInStudy ) {
328 QMessageBox::warning(SUIT_Session::session()->activeApplication()->desktop(), tr("WRN_WARNING"),
329 tr("WRN_STUDY_LOCKED"));
333 myInStudy = !myInStudy;
335 getMain()->getCanvas()->update();
337 if ( myInStudy ) // put values to study (supervision, supervision->dataflow, supervision->dataflow->runXXX, etc.
338 if ( getMain()->putDataStudy( getEngine(), STUDY_PORT_OUT ) ) {
339 // mkr : PAL8110 : re-register dataflow in object browser with
340 // changing its key to IOR name (from xml-file name, for example)
341 SUPERVGUI* aSupMod = SUPERVGUI::Supervision();
343 MESSAGE("NULL Supervision module!");
346 aSupMod->unregisterGraph(getMain());
347 aSupMod->registerGraph(getMain()->getDataflow()->getIOR(), getMain());
351 QString aNodePortName = QString( getEngine()->Node()->Name() ) + QString( "_" ) + QString( getEngine()->Name() );
352 emit putInStudy( &aNodePortName );
358 //***********************************************************
360 //***********************************************************
361 SUPERVGUI_CanvasStreamPortIn::SUPERVGUI_CanvasStreamPortIn(QObject* theParent, SUPERVGUI_Main* theMain,
362 SUPERV::StreamPort_ptr thePort):
363 SUPERVGUI_CanvasPortIn(theParent, theMain, thePort)
365 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
368 QPopupMenu* SUPERVGUI_CanvasStreamPortIn::getPopupMenu(QWidget* theParent)
370 QPopupMenu* popup = SUPERVGUI_CanvasPortIn::getPopupMenu(theParent);
371 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
375 void SUPERVGUI_CanvasStreamPortIn::setParams()
377 SUPERVGUI_StreamInDlg* aDlg = new SUPERVGUI_StreamInDlg(this);
383 //***********************************************************
384 // Stream Output Port
385 //***********************************************************
386 SUPERVGUI_CanvasStreamPortOut::SUPERVGUI_CanvasStreamPortOut(QObject* theParent, SUPERVGUI_Main* theMain,
387 SUPERV::StreamPort_ptr thePort):
388 SUPERVGUI_CanvasPortOut(theParent, theMain, thePort)
390 myStreamPort = SUPERV::StreamPort::_duplicate(thePort);
394 QPopupMenu* SUPERVGUI_CanvasStreamPortOut::getPopupMenu(QWidget* theParent)
396 QPopupMenu* popup = SUPERVGUI_CanvasPortOut::getPopupMenu(theParent);
397 popup->insertItem(tr("MSG_STREAM_PARAM"),this, SLOT(setParams()));
401 void SUPERVGUI_CanvasStreamPortOut::setParams()
403 SUPERVGUI_StreamOutDlg* aDlg = new SUPERVGUI_StreamOutDlg(this);