1 // SUPERV SUPERVGUI : GUI for Supervisor component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SUPERVGUI_ControlNode.cxx
8 // Author : Vitaly SMETANNIKOV
12 #include "SUPERVGUI_ControlNode.h"
13 #include <qapplication.h>
14 #include "SUPERVGUI_Main.h"
15 #include <qgroupbox.h>
17 #define TITLECOLOR Qt::red.light()
18 #define BACKCOLOR Qt::cyan.light()
20 //-----------------------------------------------------------
21 //******************* Start Node ****************************
22 //-----------------------------------------------------------
23 SUPERVGUI_StartControlNode::SUPERVGUI_StartControlNode(QWidget* theParent, SUPERVGUI_Main* theMain,
24 SUPERV_CNode theNode):
25 SUPERVGUI_GraphNode(theParent, theMain, theNode)
27 setPaletteBackgroundColor(BACKCOLOR);
28 QGridLayout* aGridLayout = new QGridLayout(this, 0, 3, 0, 0);
29 aGridLayout->setColStretch(0, 1);
30 aGridLayout->setColStretch(1, 1);
31 aGridLayout->addColSpacing(2, LABEL_HEIGHT/2);
33 myTitle->setAlignment(Qt::AlignHCenter);
34 myTitle->reparent(this, pos());
35 myTitle->setPaletteBackgroundColor(TITLECOLOR);
37 aGridLayout->addMultiCellWidget(myTitle, 0, 0, 0, 2);
39 myPortsBox->reparent(this, pos());
40 aGridLayout->addMultiCellWidget(myPortsBox, 1, 1, 0, 1);
41 // myGatesBox->setPaletteBackgroundColor(backgroundColor().dark(105));
43 myStatus->reparent(this, pos());
44 myTime->reparent(this, pos());
45 aGridLayout->addWidget(myStatus, 2, 0);
46 aGridLayout->addMultiCellWidget(myTime, 2, 2, 1, 2);
48 myPopup->insertSeparator();
49 myPortsItem = myPopup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
57 void SUPERVGUI_StartControlNode::switchPorts() {
58 bool aIsVisible = myPortsBox->isVisible();
59 if (aIsVisible) myPortsBox->hide();
60 else myPortsBox->show();
62 myPopup->setItemChecked(myPortsItem, aIsVisible);
66 void SUPERVGUI_StartControlNode::hideAll() {
69 myPopup->setItemChecked(myPortsItem, true);
73 void SUPERVGUI_StartControlNode::showAll() {
76 myPopup->setItemChecked(myPortsItem, false);
80 void SUPERVGUI_StartControlNode::rename() {
81 SUPERVGUI_Node::rename();
82 QString aStr(tr("ENDNODE_PREFIX"));
84 myEndNode->setNodeName(aStr);
88 void SUPERVGUI_StartControlNode::remove() {
89 myEndNode->deleteLinks();
92 myMain->getGraph()->deleteNode(myEndNode);
93 myMain->getGraph()->deleteNode(this);
97 void SUPERVGUI_StartControlNode::setEndNode(SUPERVGUI_EndControlNode* theEndNode) {
98 myEndNode = theEndNode;
101 SUPERVGUI_EndControlNode* SUPERVGUI_StartControlNode::getEndNode() {
106 void SUPERVGUI_StartControlNode::setShape() {
109 int aOffset = LABEL_HEIGHT/2;
110 QPointArray aArray(8);
111 aArray.setPoint(0, aOffset, aH);
112 aArray.setPoint(1, 0, aH-LABEL_HEIGHT);
113 aArray.setPoint(2, 0, LABEL_HEIGHT);
114 aArray.setPoint(3, aOffset, 0);
115 aArray.setPoint(4, aW, 0);
116 aArray.setPoint(5, aW-aOffset, LABEL_HEIGHT);
117 aArray.setPoint(6, aW-aOffset, aH-LABEL_HEIGHT);
118 aArray.setPoint(7, aW, aH);
119 QRegion aRegion(aArray);
125 void SUPERVGUI_StartControlNode::updateShape() {
126 qApp->processEvents();
132 void SUPERVGUI_StartControlNode::addOutputPort() {
133 SUPERVGUI_GraphNode::addOutputPort();
134 myEndNode->updatePorts();
135 myEndNode->updateShape();
136 updateLinksPrs(true);
137 myEndNode->updateLinksPrs(true);
140 void SUPERVGUI_StartControlNode::addInputPort() {
141 SUPERVGUI_GraphNode::addInputPort();
142 myEndNode->updatePorts();
143 myEndNode->updateShape();
144 updateLinksPrs(true);
145 myEndNode->updateLinksPrs(true);
148 void SUPERVGUI_StartControlNode::deletePort(SUPERVGUI_Port* thePort) {
149 if (getNodeType() == SUPERV::LoopNode) {
151 SUPERV_Port aPortEngine = thePort->getPort();
152 QString aName(aPortEngine->Name());
153 QString aNameIn = aName + "Input";
154 QString aNameOut = aName + "Output";
156 SUPERVGUI_Port* aPort = (SUPERVGUI_Port*) child(aNameOut, "SUPERVGUI_Port");
157 aPort->deleteLinks();
160 aPort = (SUPERVGUI_Port*) child(aNameIn, "SUPERVGUI_Port");
161 aPort->deleteLinks();
164 aPort = (SUPERVGUI_Port*) myEndNode->child(aNameIn, "SUPERVGUI_Port");
165 aPort->deleteLinks();
168 aPort = (SUPERVGUI_Port*) myEndNode->child(aNameOut, "SUPERVGUI_Port");
169 aPort->deleteLinks();
175 myEndNode->getPIcount()--;
176 myEndNode->getPOcount()--;
178 aPortEngine->destroy();
182 myEndNode->updatePorts();
183 myEndNode->updateShape();
185 SUPERVGUI_GraphNode::deletePort(thePort);
190 QPoint SUPERVGUI_StartControlNode::getOutConnectPnt() {
191 return QPoint(pos().x() + width() - LABEL_HEIGHT/2,
192 pos().y() + (height()/2));
196 //-----------------------------------------------------------
197 //******************* End Node ******************************
198 //-----------------------------------------------------------
200 SUPERVGUI_EndControlNode::SUPERVGUI_EndControlNode(QWidget* theParent, SUPERVGUI_Main* theMain,
201 SUPERV_CNode theNode, SUPERVGUI_StartControlNode* theStart):
202 SUPERVGUI_GraphNode(theParent, theMain, theNode)
204 myStartNode = theStart;
206 setPaletteBackgroundColor(BACKCOLOR);
208 QGridLayout* aGridLayout = new QGridLayout(this, 0, 3, 0, 0);
209 aGridLayout->setColStretch(1, 1);
210 aGridLayout->setColStretch(2, 1);
211 aGridLayout->addColSpacing(0, LABEL_HEIGHT/2);
213 myTitle->setAlignment(Qt::AlignHCenter);
214 myTitle->reparent(this, pos());
215 myTitle->setPaletteBackgroundColor(TITLECOLOR);
216 aGridLayout->addMultiCellWidget(myTitle, 0, 0, 0, 2);
218 myPortsBox->reparent(this, pos());
220 aGridLayout->addMultiCellWidget(myPortsBox, 1, 1, 1, 2);
222 myStatus->reparent(this, pos());
223 myTime->reparent(this, pos());
224 aGridLayout->addMultiCellWidget(myStatus, 2, 2, 0, 1);
225 aGridLayout->addWidget(myTime, 2, 2);
230 myPopup->removeItem(myRenameItem);
231 myPopup->removeItem(myDeleteItem);
232 myPopup->removeItem(mySeparatorId);
234 myPopup->insertSeparator();
235 myPortsItem = myPopup->insertItem(tr("POP_HIDEPORTS"), this, SLOT(switchPorts()));
236 myStartNode->setEndNode(this);
241 void SUPERVGUI_EndControlNode::switchPorts() {
242 bool aIsVisible = myPortsBox->isVisible();
243 if (aIsVisible) myPortsBox->hide();
244 else myPortsBox->show();
246 myPopup->setItemChecked(myPortsItem, aIsVisible);
249 void SUPERVGUI_EndControlNode::hideAll() {
252 myPopup->setItemChecked(myPortsItem, true);
256 void SUPERVGUI_EndControlNode::showAll() {
259 myPopup->setItemChecked(myPortsItem, false);
263 void SUPERVGUI_EndControlNode::setShape() {
266 int aOffset = LABEL_HEIGHT/2;
267 QPointArray aArray(8);
268 aArray.setPoint(0, 0, aH);
269 aArray.setPoint(1, aOffset, aH-LABEL_HEIGHT);
270 aArray.setPoint(2, aOffset, LABEL_HEIGHT);
271 aArray.setPoint(3, 0, 0);
272 aArray.setPoint(4, aW-aOffset, 0);
273 aArray.setPoint(5, aW, LABEL_HEIGHT);
274 aArray.setPoint(6, aW, aH-LABEL_HEIGHT);
275 aArray.setPoint(7, aW-aOffset, aH);
276 QRegion aRegion(aArray);
282 void SUPERVGUI_EndControlNode::updateShape() {
283 qApp->processEvents();
289 QPoint SUPERVGUI_EndControlNode::getInConnectPnt() {
290 return QPoint(pos().x() + LABEL_HEIGHT/2,
291 pos().y() + (height()/2));
295 //-----------------------------------------------------------
296 //******************* GoTo Node *****************************
297 //-----------------------------------------------------------
298 SUPERVGUI_GotoNode::SUPERVGUI_GotoNode(QWidget* theParent, SUPERVGUI_Main* theMain,
299 SUPERV_CNode theNode):
300 SUPERVGUI_GraphNode(theParent, theMain, theNode)
302 setPaletteBackgroundColor(BACKCOLOR);
304 QGridLayout* aGridLayout = new QGridLayout(this, 3, 2, 0, 0);
306 myTitle->setAlignment(Qt::AlignHCenter);
307 myTitle->reparent(this, pos());
308 myTitle->setPaletteBackgroundColor(Qt::green.light());
309 aGridLayout->addMultiCellWidget(myTitle, 0, 0, 0, 1);
311 myPortsBox->reparent(this, pos());
312 aGridLayout->addMultiCellWidget(myPortsBox, 1, 1, 0, 1);
314 myStatus->reparent(this, pos());
315 myTime->reparent(this, pos());
316 aGridLayout->addWidget(myStatus, 2, 0);
317 aGridLayout->addWidget(myTime, 2, 1);
319 myPopup->insertSeparator();
320 myPopup->insertItem("Link to Node...", this, SLOT(linkToNode()));
326 //SUPERV_Ports aPorts = getEngine()->Ports(); //existing
327 //int n = aPorts->length();
331 void SUPERVGUI_GotoNode::setShape() {
334 QPointArray aArray(8);
335 aArray.setPoint(0, LABEL_HEIGHT, aH);
336 aArray.setPoint(1, 0, aH-LABEL_HEIGHT);
337 aArray.setPoint(2, 0, LABEL_HEIGHT);
338 aArray.setPoint(3, LABEL_HEIGHT, 0);
339 aArray.setPoint(4, aW-LABEL_HEIGHT, 0);
340 aArray.setPoint(5, aW, LABEL_HEIGHT);
341 aArray.setPoint(6, aW, aH-LABEL_HEIGHT);
342 aArray.setPoint(7, aW-LABEL_HEIGHT, aH);
343 QRegion aRegion(aArray);
349 void SUPERVGUI_GotoNode::hideAll() {
352 //myPopup->setItemChecked(myPortsItem, true);
356 void SUPERVGUI_GotoNode::showAll() {
359 //myPopup->setItemChecked(myPortsItem, false);
362 void SUPERVGUI_GotoNode::updateShape() {
363 qApp->processEvents();
369 void SUPERVGUI_GotoNode::linkToNode() {
370 SUPERVGUI_SelectInlineDlg* aDlg = new SUPERVGUI_SelectInlineDlg(getMain());
372 setLinkedNode((char*)aDlg->getName().latin1());
373 myMain->getGraph()->sync();
379 void SUPERVGUI_GotoNode::setLinkedNode(char* theNodeName) {
380 getGotoNode()->SetCoupled(theNodeName);
385 //-----------------------------------------------------------
386 //*************** Select Inline node dialog******************
387 //-----------------------------------------------------------
389 SUPERVGUI_SelectInlineDlg::SUPERVGUI_SelectInlineDlg(SUPERVGUI_Main* theMain)
390 :QDialog(theMain, 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
392 setSizeGripEnabled( true );
393 setCaption(tr("TIT_FUNC_PYTHON"));
394 QGridLayout* aMainLayout = new QGridLayout(this, 2, 2, 7, 4);
396 QLabel* aLabel = new QLabel("Connect to", this );
397 aMainLayout->addWidget(aLabel, 0, 0);
399 myCombo = new QComboBox(this);
400 myCombo->clear(); //for the additional check from GUI side for bug PAL7007
401 SUPERV_Nodes aNodesList = theMain->getDataflow()->Nodes();
403 for (i = 0; i < aNodesList->INodes.length(); i++) {
404 myCombo->insertItem(QString(aNodesList->INodes[i]->Name()));
406 for (i = 0; i < aNodesList->LNodes.length(); i++) {
407 myCombo->insertItem(QString(aNodesList->LNodes[i]->Name()));
409 for (i = 0; i < aNodesList->SNodes.length(); i++) {
410 myCombo->insertItem(QString(aNodesList->SNodes[i]->Name()));
412 aMainLayout->addWidget(myCombo, 0, 1);
414 QGroupBox* aBtnBox = new QGroupBox( this );
415 aBtnBox->setColumnLayout( 0, Qt::Vertical );
416 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
417 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
418 aBtnLayout->setAlignment( Qt::AlignTop );
419 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
421 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
422 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
423 aBtnLayout->addWidget( aOKBtn );
425 aBtnLayout->addStretch();
427 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
428 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
429 aBtnLayout->addWidget( aCancelBtn );
431 aMainLayout->addMultiCellWidget(aBtnBox, 1, 1, 0, 1);