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_Node.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI_Node.h"
30 #include "SUPERVGUI_Main.h"
31 #include "SUPERVGUI_Python.h"
32 #include "SUPERVGUI.h"
33 #include "SUPERVGUI_BrowseNodeDlg.h"
34 #include "SALOMEGUI_NameDlg.h"
35 #include "SUPERVGUI_Information.h"
36 #include "SUPERVGUI_ComputeNode.h"
37 #include "SUPERVGUI_ControlNode.h"
41 #include <qlineedit.h>
42 #include <qpushbutton.h>
44 #include <qgroupbox.h>
49 SUPERVGUI_Node::SUPERVGUI_Node(QWidget* theParent, SUPERVGUI_Main* theMain, SUPERV_CNode theNode):
50 QFrame(theParent, "", WDestructiveClose),
59 Trace("SUPERVGUI_Node::SUPERVGUI_Node");
60 QPalette BackColor = QPalette(MAIN_BACK);
61 setPalette(BackColor);
63 setName(myNode->Name());
64 //myTitle = new SUPERVGUI_Label(0, LABEL_WIDTH, LABEL_HEIGHT, name(), QLabel::AlignLeft);
65 //connect(myTitle, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
68 myStatus = new SUPERVGUI_Label(0, LABEL_WIDTH/2, LABEL_HEIGHT, "", QLabel::AlignHCenter);
69 myTime = new SUPERVGUI_Label(0, LABEL_WIDTH/2, LABEL_HEIGHT, "00:00:00", QLabel::AlignHCenter);
73 connect(myStatus, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
74 connect(myTime, SIGNAL(MousePress(QMouseEvent*)), this, SLOT(showPopup(QMouseEvent*)));
77 myPopup = new QPopupMenu(this);
78 if (myMain->isEditable() && getNodeType() != SUPERV::EndLoopNode
79 && getNodeType() != SUPERV::EndSwitchNode) {
80 myRenameItem = myPopup->insertItem(tr("MSG_RENAME"), this, SLOT(rename()));
81 myDeleteItem = myPopup->insertItem(tr("MSG_DELETE"), this, SLOT(remove()));
82 mySeparatorId = myPopup->insertSeparator();
84 myPopup->insertItem(tr("MSG_BROWSE"), this, SLOT(browse()));
85 if ((getNodeType() != SUPERV::EndLoopNode) && (getNodeType() != SUPERV::EndSwitchNode))
86 myPopup->insertItem(tr("MSG_CHANGE_INFO"), this, SLOT(changeInformation()));
87 //myPopup->insertItem(tr("MSG_CONFIGURE"), this, SLOT(configure()));
89 if (myMain->isEditable() && (getNodeType() != SUPERV::FactoryNode)
90 && (getNodeType() != SUPERV::ComputingNode)) {
91 if ((getNodeType() != SUPERV::EndLoopNode)) {
92 QPopupMenu* aAddPortMnu = new QPopupMenu(this);
93 aAddPortMnu->insertItem("Input", this, SLOT(addInputPort()));
94 if (getNodeType() != SUPERV::LoopNode)
95 aAddPortMnu->insertItem("Output", this, SLOT(addOutputPort()));
97 myPopup->insertSeparator();
98 if ((getNodeType() != SUPERV::EndSwitchNode))
99 myPopup->insertItem("Edit Function", this, SLOT(editFunction()));
100 myPopup->insertItem("Add Port", aAddPortMnu);
104 // create execution popup
105 myRunPopup = new QPopupMenu(this);
106 mySuspendItem = myRunPopup->insertItem(tr("MSG_SUSPEND"), this, SLOT(suspendResume()));
107 myKillItem = myRunPopup->insertItem(tr("MSG_KILL"), this, SLOT(kill()));
108 //myStopItem = myRunPopup->insertItem(tr("MSG_STOP"), this, SLOT(stopRestart()));
110 setState(myNode->State());
113 SUPERVGUI_Node::~SUPERVGUI_Node()
115 Trace("SUPERVGUI_Node::~SUPERVGUI_Node")
119 void SUPERVGUI_Node::sync() {
120 setState(myNode->State());
124 void SUPERVGUI_Node::setState(SUPERV::GraphState theState)
126 MESSAGE("NodeState="<<theState);
127 myRunPopup->changeItem(mySuspendItem, tr("MSG_SUSPEND"));
128 myRunPopup->setItemEnabled(mySuspendItem, true);
129 myRunPopup->setItemEnabled(myStopItem, false);
133 myStatus->setText("Waiting");
134 myStatus->setPaletteBackgroundColor(QColor(35, 192, 255));
137 myStatus->setText("Running");
138 myStatus->setPaletteBackgroundColor(QColor(32,210,32));
139 myRunPopup->changeItem(myStopItem, tr("MSG_STOP"));
140 myRunPopup->setItemEnabled(myStopItem, true);
143 case SUPERV::SuspendReadyState:
144 myStatus->setText("Suspended");
145 myStatus->setPaletteBackgroundColor(QColor(255,180, 0));
146 myRunPopup->changeItem(mySuspendItem, tr("MSG_RESUME"));
149 myStatus->setText("Finished");
150 myStatus->setPaletteBackgroundColor(QColor(255, 158, 255));
151 myRunPopup->setItemEnabled(mySuspendItem, false);
152 myRunPopup->changeItem(myStopItem, tr("MSG_RESTART"));
153 myRunPopup->setItemEnabled(myStopItem, true);
156 myStatus->setText("Aborted");
157 myStatus->setPaletteBackgroundColor(red);
158 myRunPopup->setItemEnabled(mySuspendItem, false);
159 myRunPopup->changeItem(myStopItem, tr("MSG_RESTART"));
160 myRunPopup->setItemEnabled(myStopItem, true);
163 myStatus->setText("Killed");
164 myStatus->setPaletteBackgroundColor(red);
165 myRunPopup->setItemEnabled(mySuspendItem, false);
166 myRunPopup->changeItem(myStopItem, tr("MSG_RESTART"));
167 myRunPopup->setItemEnabled(myStopItem, true);
170 //cout<<"### Node state = "<<theState<<endl;
171 myStatus->setText("No Status");
172 myStatus->setPaletteBackgroundColor(QColor(NODE_RED, NODE_GREEN, NODE_BLUE));
173 myRunPopup->setItemEnabled(mySuspendItem, false);
176 myTime->setPaletteBackgroundColor(myStatus->paletteBackgroundColor());
177 long sec = 0; //myNode->CpuUsed();
181 hms[0]=(char)(((s/10)%10)+48);
182 hms[1]=(char)((s%10)+48);
186 hms[3]=(char)((s/10)+48);
187 hms[4]=(char)((s%10)+48);
190 hms[6]=(char)((sec/10)+48);
191 hms[7]=(char)((sec%10)+48);
193 myTime->setText(hms);
196 void SUPERVGUI_Node::rename()
198 QString nm = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), myNode->Name() );
199 if ( !nm.isEmpty() ) {
205 void SUPERVGUI_Node::remove() {
206 Trace("SUPERVGUI_Node::remove");
209 myMain->getGraph()->deleteNode(this);
212 void SUPERVGUI_Node::suspendResume() {
213 Trace("SUPERVGUI_Node::suspendResume");
214 int n = queryList("SUPERVGUI_Node")->count();
215 if (myNode->IsSuspended()) {
216 if (!((n==1)? myMain->getDataflow()->Resume() : myNode->Resume())) {
217 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESUMENODE"));
220 if (!((n==1)? myMain->getDataflow()->Suspend() : myNode->Suspend())) {
221 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_SUSPENDNODE"));
223 myStatus->setPaletteBackgroundColor(QColor(255,180, 0));
224 myTime->setPaletteBackgroundColor(QColor(255,180, 0));
229 void SUPERVGUI_Node::kill() {
230 Trace("SUPERVGUI_Node::kill");
231 int n = queryList("SUPERVGUI_Node")->count();
232 if (!((n==1)? myMain->getDataflow()->Kill() : myNode->Kill())) {
233 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_KILLNODE"));
235 myStatus->setPaletteBackgroundColor(Qt::red);
236 myTime->setPaletteBackgroundColor(Qt::red);
240 void SUPERVGUI_Node::stopRestart() {
241 Trace("SUPERVGUI_Node::stopRestart");
243 int n = queryList("SUPERVGUI_Node")->count();
244 if ((myNode->State() == SUPERV_Stop) || (myNode->State() == SUPERV_Kill)) {
245 if (!((n==1)? myMain->getDataflow()->Run() : myNode->ReStart())) {
246 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_RESTARTNODE"));
249 if (!((n==1)? myMain->getDataflow()->Stop() : myNode->Stop())) {
250 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_STOPNODE"));
255 void SUPERVGUI_Node::changeInformation() {
256 SUPERVGUI_Information* aDlg = new SUPERVGUI_Information(myNode, !myMain->isEditable());
260 if (myNode->IsGOTO()) {
261 QString nmGT = myNode->Name();
262 if ( !nmGT.isEmpty() ) {
266 if (myMain->isEditable()) {
267 if (myMain->isArrayShown()) { //Table View
268 if (myNode->IsLoop() || myNode->IsSwitch()) { //for synchronic names changing
269 QString nmA = myNode->Name();
270 if ( !nmA.isEmpty() ) {
272 QString aStrA(tr("ENDNODE_PREFIX"));
274 (dynamic_cast<SUPERVGUI_Cell*>(this))->getPairCell()->getTitle()->setText(aStrA);
275 (dynamic_cast<SUPERVGUI_Cell*>(this))->getPairCell()->setNodeName(aStrA);
276 // QToolTip::remove((dynamic_cast<SUPERVGUI_Cell*>(this))->getPairCell()->getTitle());
277 QToolTip::add((dynamic_cast<SUPERVGUI_Cell*>(this))->getPairCell()->getTitle(),
278 (dynamic_cast<SUPERVGUI_Cell*>(this))->getPairCell()->getTitle()->text());
282 // QToolTip::remove((dynamic_cast<SUPERVGUI_Cell*>(this))->getTitle());
283 QToolTip::add((dynamic_cast<SUPERVGUI_Cell*>(this))->getTitle(),
284 (dynamic_cast<SUPERVGUI_Cell*>(this))->getTitle()->text());
285 QToolTip::add((dynamic_cast<SUPERVGUI_Cell*>(this))->getComponent(),
286 (dynamic_cast<SUPERVGUI_Cell*>(this))->getComponent()->text());
289 if (myNode->IsLoop() || myNode->IsSwitch()) { //for synchronic names changing
290 QString nm = myNode->Name();
291 if ( !nm.isEmpty() ) {
293 QString aStr(tr("ENDNODE_PREFIX"));
295 (dynamic_cast<SUPERVGUI_StartControlNode*>(this))->getEndNode()->setNodeName(aStr);
299 if (!(myNode->IsGOTO())) {
300 // QToolTip::remove((dynamic_cast<SUPERVGUI_ComputeNode*>(this))->getCommLabel());
301 QToolTip::add((dynamic_cast<SUPERVGUI_ComputeNode*>(this))->getCommLabel(),
302 (dynamic_cast<SUPERVGUI_ComputeNode*>(this))->getCommLabel()->text());
303 QToolTip::add((dynamic_cast<SUPERVGUI_ComputeNode*>(this))->getTitleLabel(),
304 (dynamic_cast<SUPERVGUI_ComputeNode*>(this))->getTitleLabel()->text());
309 /* Trace("SUPERVGUI_Node::changeInformation")
310 if (Supervision.information(myNode, !myMain->isEditable())) {
315 void SUPERVGUI_Node::configure() {
316 Trace("SUPERVGUI_Node::configure")
317 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_NOT_IMPLEMENTED")); // kloss : a faire : lancer l'ihm DATA
320 void SUPERVGUI_Node::showPython() {
321 Trace("SUPERVGUI_Node::showPython")
322 SUPERVGUI_Python cp(myMain->getStudy()->get_PyInterp(), !myMain->isEditable());
326 void SUPERVGUI_Node::showPopup(QMouseEvent* e) {
327 Trace("SUPERVGUI_Node::showPopup");
328 if (myMain->getDataflow()->IsExecuting())
329 myMain->showPopup(myRunPopup, e);
331 myMain->showPopup(myPopup, e);
335 void SUPERVGUI_Node::mousePressEvent(QMouseEvent* e) {
336 myMain->showPopup(myPopup, e);
340 bool SUPERVGUI_Node::isWarning() {
341 Trace("SUPERVGUI_Node::isWarning")
345 bool SUPERVGUI_Node::isStep() {
346 Trace("SUPERVGUI_Node::isStep")
350 bool SUPERVGUI_Node::isTrace() {
351 Trace("SUPERVGUI_Node::isTrace")
355 bool SUPERVGUI_Node::isVerbose() {
356 Trace("SUPERVGUI_Node::isVerbose")
360 void SUPERVGUI_Node::setWarning(bool b) {
361 Trace("SUPERVGUI_Node::setWarning")
365 void SUPERVGUI_Node::setStep(bool b) {
366 Trace("SUPERVGUI_Node::setStep")
370 void SUPERVGUI_Node::setTrace(bool b) {
371 Trace("SUPERVGUI_Node::setTrace")
375 void SUPERVGUI_Node::setVerbose(bool b) {
376 Trace("SUPERVGUI_Node::setVerbose")
381 void SUPERVGUI_Node::browse() {
383 aBrowseDlg = new SUPERVGUI_BrowseNodeDlg(this);
384 aBrowseDlg->installEventFilter( this );
386 if ( !aBrowseDlg->isVisible() )
390 aBrowseDlg->setActiveWindow();
391 aBrowseDlg->setFocus();
395 bool SUPERVGUI_Node::eventFilter( QObject* o, QEvent* e )
397 if ( o == aBrowseDlg && e->type() == QEvent::Close )
399 return QFrame::eventFilter( o, e );
403 void SUPERVGUI_Node::setNodeName(QString aName) {
404 if ( myNode->SetName(aName.latin1())) {
405 setName(myNode->Name());
406 //myTitle->setText(aName);
408 QMessageBox::warning( QAD_Application::getDesktop(), tr( "ERROR" ), tr( "MSG_CANT_RENAMENODE" ) );
412 SUPERV_Port SUPERVGUI_Node::createInPort() {
413 SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg();
415 SUPERV_INode aNode = getInlineNode();
416 if (SUPERV_isNull(aNode)) {
417 MESSAGE("SUPERVGUI_Node::createInPort: Node is wrong type");
420 SUPERV_Ports aPorts = aNode->Ports();
421 for (int i=0; i<aPorts->length(); i++) {
422 if (aDlg->getName() == QString(aPorts[i]->Name())){
423 QMessageBox::warning(0, tr("ERROR"), tr("MSG_PORT_EXIST"));
427 SUPERV_Port aPort = aNode->InPort(aDlg->getName().latin1(),
428 aDlg->getType().latin1());
437 SUPERV_Port SUPERVGUI_Node::createOutPort() {
438 SUPERVGUI_PortParamsDlg* aDlg = new SUPERVGUI_PortParamsDlg();
440 SUPERV_INode aNode = getInlineNode();
441 if (SUPERV_isNull(aNode)) {
442 MESSAGE("SUPERVGUI_Node::createInPort: Node is wrong type");
445 SUPERV_Ports aPorts = aNode->Ports();
446 for (int i=0; i<aPorts->length(); i++) {
447 if (aDlg->getName() == QString(aPorts[i]->Name())){
448 QMessageBox::warning(0, tr("ERROR"), tr("MSG_PORT_EXIST"));
452 SUPERV_Port aPort = aNode->OutPort(aDlg->getName().latin1(),
453 aDlg->getType().latin1());
463 void SUPERVGUI_Node::addInputPort() {
468 void SUPERVGUI_Node::addOutputPort() {
473 void SUPERVGUI_Node::editFunction() {
474 if (getNodeType() == SUPERV::LoopNode) {
475 SUPERVGUI_EditPythonDlg* aDlg = new SUPERVGUI_EditPythonDlg(true);
476 SUPERV_LNode aLNode = getLoopNode();
477 aDlg->setInitFunction(aLNode->PyInit());
478 aDlg->setMoreFunction(aLNode->PyMore());
479 aDlg->setNextFunction(aLNode->PyNext());
481 aLNode->SetPyInit(aDlg->getInitFuncName().latin1(), (aDlg->getInitFunction()).in());
482 aLNode->SetPyMore(aDlg->getMoreFuncName().latin1(), (aDlg->getMoreFunction()).in());
483 aLNode->SetPyNext(aDlg->getNextFuncName().latin1(), (aDlg->getNextFunction()).in());
487 SUPERVGUI_EditPythonDlg* aDlg = new SUPERVGUI_EditPythonDlg();
488 SUPERV_INode aINode = getInlineNode();
489 aDlg->setFunction(aINode->PyFunction());
491 aINode->SetPyFunction(aDlg->getFuncName().latin1(), (aDlg->getFunction()).in());
503 * Port parameters dialog definition
506 SUPERVGUI_PortParamsDlg::SUPERVGUI_PortParamsDlg()
507 : QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
509 setSizeGripEnabled( true );
510 setCaption("Port parameters");
512 QGridLayout* aBaseLayout = new QGridLayout( this );
513 aBaseLayout->setMargin( 11 ); aBaseLayout->setSpacing( 6 );
515 QLabel* aNameLbl = new QLabel("Port Name", this );
516 aBaseLayout->addWidget(aNameLbl, 0, 0);
518 myNameTxt = new QLineEdit( this );
519 aNameLbl->setBuddy( myNameTxt );
520 aBaseLayout->addWidget(myNameTxt, 0, 1);
522 QLabel* aTypeLbl = new QLabel("Value Type", this );
523 aBaseLayout->addWidget(aTypeLbl, 1, 0);
525 myTypeTxt = new QLineEdit( this );
526 aTypeLbl->setBuddy( myTypeTxt );
527 aBaseLayout->addWidget(myTypeTxt, 1, 1);
529 QGroupBox* aBtnBox = new QGroupBox( this );
530 aBtnBox->setColumnLayout( 0, Qt::Vertical );
531 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
532 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
533 aBtnLayout->setAlignment( Qt::AlignTop );
534 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
536 aBaseLayout->addMultiCellWidget( aBtnBox, 2, 2, 0, 1 );
538 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
539 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
540 aBtnLayout->addWidget( aOKBtn );
542 aBtnLayout->addStretch();
544 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
545 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
546 aBtnLayout->addWidget( aCancelBtn );