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_Service.cxx
25 // Author : Francis KLOSS
29 #include "SUPERVGUI_Service.h"
30 #include "SUPERVGUI_Main.h"
31 #include "SUPERVGUI.h"
32 #include "QAD_Tools.h"
33 #include "QAD_FileDlg.h"
35 #include "SALOME_NamingService.hxx"
36 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
39 #include <qtextstream.h>
42 static const char * ComponentIcon[] = {
49 " .................. ",
58 " .................. ",
62 " .. .. .. .. .. .. ",
64 " .. .. .. .. .. .. ",
68 static const char * InterfaceIcon[] = {
96 SUPERVGUI_Service::SUPERVGUI_Service(SALOME_NamingService* ns):
97 QDialog(QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
98 naming(ns), myMFile(0)
100 setSizeGripEnabled( true );
101 setCaption(tr("TIT_SERVICES"));
103 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
105 myTabPane = new QTabWidget(this);
106 connect(myTabPane, SIGNAL(currentChanged(QWidget *)), this, SLOT(tabChanged(QWidget *)));
108 // Create Tab for Corba services
109 QWidget* aCorbaPane = new QWidget(myTabPane);
110 QVBoxLayout* aBaseLayoutV= new QVBoxLayout(aCorbaPane, 0, 4);
111 aBaseLayoutV->setMargin(5);
112 aBaseLayoutV->setSpacing(10);
114 QHBoxLayout* aBaseLayout = new QHBoxLayout(aCorbaPane); //!!
116 components = new QListView(aCorbaPane);
117 components->addColumn(tr("COL_COMPONENTS"));
118 components->addColumn(tr("COL_PORTTYPE"));
119 components->addColumn(tr("COL_PORTWAY"));
120 components->setColumnAlignment(1, AlignLeft);
121 components->setColumnAlignment(2, AlignLeft);
122 components->setColumnAlignment(3, AlignLeft);
123 components->setSelectionMode(QListView::Extended);
124 components->setRootIsDecorated(true);
125 // aBaseLayout->addWidget(components);
126 aBaseLayoutV->addWidget(components); //!!
128 //QHGroupBox* aAddBox = new QHGroupBox(tr("TIT_ADDNODE"), aCorbaPane); //!!
129 //aAddBox->setInsideSpacing(20); //!!
131 //NRI QPushButton* aComputeCBtn = new QPushButton(tr("TIT_ADDCNODE"), aCorbaPane); //!!
132 //NRI connect(aComputeCBtn, SIGNAL(clicked()), this, SLOT(addComputeNode())); //!!
133 //NRI aComputeCBtn->setDefault(false);
135 QPushButton* aComputeBtn = new QPushButton(tr("TIT_ADDFNODE"), aCorbaPane);
136 connect(aComputeBtn, SIGNAL(clicked()), this, SLOT(addFactoryNode()));
137 aComputeBtn->setDefault(true);
139 aBaseLayout->addWidget(aComputeBtn);
140 //NRI aBaseLayout->addWidget(aComputeCBtn); //!!
142 aBaseLayoutV->insertLayout(-1, aBaseLayout);
143 myTabPane->addTab(aCorbaPane, tr("MODULES_PANE"));
146 // Create Tab for Python services
147 QWidget* aPythonPane = new QWidget(myTabPane);
148 QVBoxLayout* aPythonLayout = new QVBoxLayout(aPythonPane, 0, 4);
149 aPythonLayout->setMargin(5);
150 aPythonLayout->setSpacing(10);
153 QHGroupBox* aAddBox2 = new QHGroupBox(tr("TIT_ADDNODE"), aPythonPane);
154 aAddBox2->setInsideSpacing(20);
156 /*QLabel* aTypeLbl = */new QLabel(tr("LBL_NODETYPE"), aAddBox2);
158 myTypeCombo = new QComboBox(aAddBox2);
159 myTypeCombo->insertItem( tr( "INLINE_COMP" ) );
160 myTypeCombo->insertItem( tr( "INLINE_SWTC" ) );
161 myTypeCombo->insertItem( tr( "INLINE_LOOP" ) );
162 myTypeCombo->insertItem( tr( "INLINE_GOTO") );
163 connect(myTypeCombo, SIGNAL(activated(int)), this, SLOT(typeNodeSelected(int)));
165 aPythonLayout->addWidget(aAddBox2);
168 myStackWidget = new QWidgetStack(aPythonPane);
171 myScriptPane = new SUPERVGUI_PythonEditPane(myStackWidget);
172 myOtherId = myStackWidget->addWidget(myScriptPane);
175 QTabWidget* aLoopTabPane = new QTabWidget(myStackWidget);
176 myInitPane = new SUPERVGUI_PythonEditPane(myStackWidget);
177 aLoopTabPane->addTab(myInitPane, "Init");
179 myMorePane = new SUPERVGUI_PythonEditPane(myStackWidget);
180 aLoopTabPane->addTab(myMorePane, "More");
182 myNextPane = new SUPERVGUI_PythonEditPane(myStackWidget);
183 aLoopTabPane->addTab(myNextPane, "Next");
184 myLoopId = myStackWidget->addWidget(aLoopTabPane);
186 myStackWidget->raiseWidget(myOtherId);
188 aPythonLayout->addWidget(myStackWidget, 1);
191 QPushButton* aCreateBtn = new QPushButton(tr("TIT_ADDNODE"), aPythonPane);
192 connect(aCreateBtn, SIGNAL(clicked()), this, SLOT(addInlineNode()));
193 aPythonLayout->addWidget(aCreateBtn);
195 myTabPane->addTab(aPythonPane, tr("INLINE_PANE"));
197 // Create Tab for Macro node only if environmental variable ENABLE_MACRO_NODE is set
198 if ( getenv( "ENABLE_MACRO_NODE" ) != NULL )
200 QWidget* aMacroPane = new QWidget(myTabPane);
201 QVBoxLayout* aMacroLayout = new QVBoxLayout(aMacroPane, 0, 4);
202 aMacroLayout->setMargin(5);
203 aMacroLayout->setSpacing(10);
205 QHBoxLayout* aLoadLayout = new QHBoxLayout(aMacroPane); //!!
206 aLoadLayout->addStretch();
208 QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), aMacroPane);
209 connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadGraph()));
211 aLoadLayout->addWidget(aLoadBtn);
213 aMacroLayout->addLayout(aLoadLayout);
215 myMacroPane = new QListView(aMacroPane);
216 myMacroPane->addColumn(tr("COL_COMPONENTS"));
217 myMacroPane->addColumn(tr("COL_PORTTYPE"));
218 myMacroPane->addColumn(tr("COL_PORTWAY"));
219 myMacroPane->setColumnAlignment(1, AlignLeft);
220 myMacroPane->setColumnAlignment(2, AlignLeft);
221 myMacroPane->setColumnAlignment(3, AlignLeft);
222 myMacroPane->setSelectionMode(QListView::Extended);
223 myMacroPane->setRootIsDecorated(true);
224 aMacroLayout->addWidget(myMacroPane); //!!
226 QPushButton* aAddBtn = new QPushButton(tr("TIT_ADDFNODE"), aMacroPane);
227 connect(aAddBtn, SIGNAL(clicked()), this, SLOT(addMacroNode()));
228 aAddBtn->setDefault(true);
230 aMacroLayout->addWidget(aAddBtn);
232 myTabPane->addTab(aMacroPane, tr("MACRO_PANE"));
235 aMainLayout->addWidget(myTabPane);
238 QHBox* aBtnBox = new QHBox(this);
239 QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout());
240 aBtnLayout->addStretch();
242 QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
243 connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
245 aMainLayout->addWidget(aBtnBox);
254 char* getDataStreamParameterName(int aType)
272 void SUPERVGUI_Service::initialise() {
273 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
274 SALOME_ModuleCatalog::ModuleCatalog_var *aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
275 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
276 if (CORBA::is_nil(*aModuleCatalog)) {
277 setCaption("Error in Connexion to omniNames with '/Kernel/ModulCatalog'");
281 QAD_ResourceMgr* aResMgr = QAD_Desktop::createResourceManager();
283 SALOME_ModuleCatalog::ListOfComponents_var lComponents = (*aModuleCatalog)->GetComponentList();
284 long nbComp = lComponents->length();
285 for (int i=0; i<nbComp; i++) {
286 SALOME_ModuleCatalog::Acomponent_ptr C = (*aModuleCatalog)->GetComponent((char *)lComponents[i]);
287 QListViewItem* myComponentItem = new QListViewItem(components, (char*)C->componentusername());
288 myComponentItem->setSelectable(false);
289 QString aIconName = C->component_icone();
290 if (!aIconName.isEmpty()) {
291 QString resDir = aResMgr->findFile(aIconName, C->componentname()) ;
293 resDir = QAD_Tools::addSlash(resDir);
294 QPixmap aIcone(resDir + aIconName);
295 QIconSet aIconSet(aIcone);
296 myComponentItem->setPixmap(0, aIconSet.pixmap(QIconSet::Small, QIconSet::Normal));
298 myComponentItem->setPixmap(0, ComponentIcon);
301 myComponentItem->setPixmap(0, ComponentIcon);
303 SALOME_ModuleCatalog::ListOfInterfaces* lInterfaces = C->GetInterfaceList();
304 long nbInterf = lInterfaces->length();
305 for (int j=0; j<nbInterf; j++) {
306 SALOME_ModuleCatalog::DefinitionInterface* Interface = C->GetInterface((char*)(*lInterfaces)[j]);
307 QListViewItem* myInterfaceItem = new QListViewItem(myComponentItem, (char*)Interface->interfacename);
308 myInterfaceItem->setSelectable(false);
309 myInterfaceItem->setPixmap(0, InterfaceIcon);
311 long nbServices = Interface->interfaceservicelist.length();
312 for (int k=0; k<nbServices; k++) {
313 SALOME_ModuleCatalog::Service* Service = &(Interface->interfaceservicelist[k]);
314 QListViewItem* myServiceItem = new QListViewItem(myInterfaceItem, (char*)Service->ServiceName);
315 myServiceItem->setSelectable(true);
316 components->ensureItemVisible(myServiceItem);
318 long nbPortsOut = Service->ServiceoutParameter.length();
319 for (int m=0; m<nbPortsOut; m++) {
320 SALOME_ModuleCatalog::ServicesParameter* PortOut = &(Service->ServiceoutParameter[m]);
321 QListViewItem* myPortOutItem =
322 new QListViewItem(myServiceItem, (char*)PortOut->Parametername, (char*)PortOut->Parametertype, "Out");
323 myPortOutItem->setSelectable(false);
326 long nbStreamPortsOut = Service->ServiceoutDataStreamParameter.length();
327 for (int m=0; m<nbStreamPortsOut; m++) {
328 SALOME_ModuleCatalog::ServicesDataStreamParameter* PortOut = &(Service->ServiceoutDataStreamParameter[m]);
329 QListViewItem* myPortOutItem =
330 new QListViewItem(myServiceItem, (char*)PortOut->Parametername,
331 getDataStreamParameterName(PortOut->Parametertype), "DataStream Out");
332 myPortOutItem->setSelectable(false);
335 long nbPortsIn = Service->ServiceinParameter.length();
336 for (int l=0; l<nbPortsIn; l++) {
337 SALOME_ModuleCatalog::ServicesParameter* PortIn = &(Service->ServiceinParameter[l]);
338 QListViewItem* myPortInItem =
339 new QListViewItem(myServiceItem, (char*)PortIn->Parametername, (char*)PortIn->Parametertype, "In");
340 myPortInItem->setSelectable(false);
343 long nbStreamPortsIn = Service->ServiceinDataStreamParameter.length();
344 for (int l=0; l<nbStreamPortsIn; l++) {
345 SALOME_ModuleCatalog::ServicesDataStreamParameter* PortIn = &(Service->ServiceinDataStreamParameter[l]);
346 QListViewItem* myPortInItem =
347 new QListViewItem(myServiceItem, (char*)PortIn->Parametername,
348 getDataStreamParameterName(PortIn->Parametertype), "DataStream In");
349 myPortInItem->setSelectable(false);
358 SUPERVGUI_Service::~SUPERVGUI_Service() {
359 Trace("SUPERVGUI_Service::~SUPERVGUI_Service")
360 if (myMFile) delete myMFile;
363 void SUPERVGUI_Service::addComputeNode() {
364 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
365 SUPERVGUI_Main* aMain = Supervision.getMain();
367 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
368 } else if (!aMain->isEditable()) {
369 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
371 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
372 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
373 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
374 if (CORBA::is_nil(*aModuleCatalog)) {
375 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
379 QListViewItemIterator i(components);
380 for (; i.current(); ++i) {
382 if (item->isSelected()) {
383 const char* service = item->text(0).latin1();
384 const char* interface = item->parent()->text(0).latin1();
385 const char* component = item->parent()->parent()->text(0).latin1();
386 SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(aDesktop->getComponentName(component));
387 if (myComponent==NULL) {
388 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
390 const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
393 SUPERV_CNode node = aMain->getDataflow()->CNode(*myService);
394 if (CORBA::is_nil(node)) {
395 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
398 //to appear a new node in the top-left corner of the current viewport
400 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
401 node->Coords(cx, cy);
404 aMain->addComputeNode(SUPERV::CNode::_narrow(node));
409 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
415 void SUPERVGUI_Service::addFactoryNode() {
416 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
417 SUPERVGUI_Main* aMain = Supervision.getMain();
419 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
420 } else if (!aMain->isEditable()) {
421 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
423 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
424 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
425 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
426 if (CORBA::is_nil(*aModuleCatalog)) {
427 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
431 QListViewItemIterator i(components);
432 for (; i.current(); ++i) {
434 if (item->isSelected()) {
435 const char* service = item->text(0).latin1();
436 const char* interface = item->parent()->text(0).latin1();
437 const char* component = aDesktop->getComponentName(item->parent()->parent()->text(0).latin1());
438 SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
439 if (myComponent==NULL) {
440 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
442 const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
445 MESSAGE ( " myService->TypeOfNode == " << myService->TypeOfNode )
448 if ( myService->TypeOfNode == 0 ) { // ComputeNode
449 SUPERV_CNode node = aMain->getDataflow()->CNode(*myService);
450 if (CORBA::is_nil(node)) {
451 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
454 //to appear a new node in the top-left corner of the current viewport
455 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
456 node->Coords(cx, cy);
459 aMain->addComputeNode(SUPERV::CNode::_narrow(node));
460 } else { // Factory Node
461 SUPERV_FNode node = aMain->getDataflow()->FNode(component, interface, *myService);
462 if (CORBA::is_nil(node)) {
463 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
466 //to appear a new node in the top-left corner of the current viewport
467 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
468 node->Coords(cx, cy);
471 aMain->addComputeNode(SUPERV::CNode::_narrow(node));
475 // SUPERV_FNode node = aMain->getDataflow()->FNode(component, interface, *myService);
476 // if (CORBA::is_nil(node)) {
477 // QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
480 // node->Coords(myX, myY);
483 // aMain->addComputeNode(SUPERV::CNode::_narrow(node));
488 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
495 void SUPERVGUI_Service::addInlineNode() {
496 SUPERVGUI_Main* aMain = Supervision.getMain();
498 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
499 } else if (!aMain->isEditable()) {
500 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
502 int aSel = myTypeCombo->currentItem();
505 case 0: // Computation
507 SUPERV_INode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(),
508 (myScriptPane->getFunction()).in());
509 if (CORBA::is_nil(aNode)) {
510 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
513 //to appear a new node in the top-left corner of the current viewport
514 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
515 aNode->Coords(cx, cy);
518 aMain->addComputeNode(SUPERV::CNode::_narrow(aNode));
524 SUPERV_INode aEndNode;
525 SUPERV_SNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(),
526 (myScriptPane->getFunction()).in(),
528 if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
529 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
532 //to appear a new node in the top-left corner of the current viewport
533 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
534 aStartNode->Coords(cx, cy);
535 aEndNode->Coords(cx + LABEL_WIDTH*2, cy);
538 aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
544 SUPERV_INode aEndNode;
545 SUPERV_LNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(),
546 myMorePane->getFuncName().latin1(), (myMorePane->getFunction()).in(),
547 myNextPane->getFuncName().latin1(), (myNextPane->getFunction()).in(),
549 if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
550 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
553 //to appear a new node in the top-left corner of the current viewport
554 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
555 aStartNode->Coords(cx, cy);
556 aEndNode->Coords(cx + LABEL_WIDTH*2, cy);
559 aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
565 SUPERV_GNode aGotoNode;
566 if (myScriptPane->isDefined())
567 aGotoNode = aMain->getDataflow()->GNode(myScriptPane->getFuncName().latin1(),
568 (myScriptPane->getFunction()).in(), "");
570 aGotoNode = aMain->getDataflow()->GNode("GoTo", (myScriptPane->getFunction()).in(), "");
571 if (CORBA::is_nil(aGotoNode)) {
572 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
575 //to appear a new node in the top-left corner of the current viewport
576 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
577 aGotoNode->Coords(cx, cy);
580 aMain->addGOTONode(SUPERV::GNode::_narrow(aGotoNode));
587 void SUPERVGUI_Service::addMacroNode() {
588 SUPERVGUI_Main* aMain = Supervision.getMain();
590 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
591 } else if (!aMain->isEditable()) {
592 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
596 if (aMain->getDataflow()->IsStreamGraph()) {
597 SUPERV_StreamGraph aSGraph = aMain->getDataflow()->ToStreamGraph();
598 if (!SUPERV_isNull(aSGraph))
599 aNode = aSGraph->StreamMNode(myMFile->name().latin1());
600 // TMP: while stream macro nodes doesn't impemented
601 if (CORBA::is_nil(aNode)) {
602 aNode = aSGraph->MNode(myMFile->name().latin1());
606 aNode = aMain->getDataflow()->MNode(myMFile->name().latin1());
607 if (CORBA::is_nil(aNode)) {
608 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
611 //to appear a new node in the top-left corner of the current viewport
613 aMain->getCanvasView()->viewportToContents(myX, myY, cx, cy);
614 aNode->Coords(cx, cy);
617 aMain->addMacroNode(SUPERV::CNode::_narrow(aNode));
620 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
625 void SUPERVGUI_Service::loadGraph() {
626 if ( getenv( "ENABLE_MACRO_NODE" ) == NULL )
627 // error! if ENABLE_MACRO_NODE is set - we should NOT get here by any means..
629 //MESSAGE("Error: ENABLE_MACRO_NODE is not set, but loadGraph() was called!");
633 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
636 tr("MSG_GRAPH_INSERT"),
638 if (aFileName.isEmpty()) return;
640 myMacroPane->clear();
642 myMFile = new QFile(aFileName);
643 if (!myMFile->open(IO_ReadOnly)) {
644 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
645 tr("MSG_CANT_LOADSCRIPT"));
646 delete myMFile; myMFile = 0;
650 QTextStream* aStream = new QTextStream(myMFile);
651 if (aStream->atEnd()) {
652 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
653 tr("MSG_EMTY_FILE"));
656 delete myMFile; myMFile = 0;
661 // temporary display only file name
662 QFileInfo anInfo(*myMFile);
663 QListViewItem* anItem = new QListViewItem(myMacroPane, anInfo.baseName());
664 anItem->setSelectable(true);
667 void SUPERVGUI_Service::typeNodeSelected(int theRow) {
669 myStackWidget->raiseWidget(myLoopId);
671 myStackWidget->raiseWidget(myOtherId);
676 void SUPERVGUI_Service::choose() {
677 Trace("SUPERVGUI_Service::choose")
683 void SUPERVGUI_Service::showEvent(QShowEvent* theEvent) {
684 SUPERVGUI_Main* aMain = Supervision.getMain();
685 if (aMain && (!aMain->isArrayShown())) {
686 aMain->getArrayView()->viewportToContents(0, 0, myX, myY);
687 //aMain->getGraph()->viewportToContents(0, 0, myX, myY);
689 QDialog::showEvent(theEvent);
693 void SUPERVGUI_Service::tabChanged(QWidget* theWidget) {
694 myIsInline = (myTabPane->currentPageIndex() == 1);
699 //*****************************************************
700 // Pane for Python script editing
701 //*****************************************************
702 SUPERVGUI_PythonEditPane::SUPERVGUI_PythonEditPane(QWidget* theParent)
705 QGridLayout* aEditLayout = new QGridLayout(this, 2, 4);
708 QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), this);
709 connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadFile()));
711 aEditLayout->addWidget(aLoadBtn, 0, 2);
713 myNextBtn = new QPushButton(tr("BUT_NEXT"), this);
714 myNextBtn->setEnabled(false);
715 connect(myNextBtn, SIGNAL(clicked()), this, SLOT(readFunction()));
717 aEditLayout->addWidget(myNextBtn, 0, 3);
720 myText = new QTextEdit(this);
721 myText->setWordWrap(QTextEdit::FixedColumnWidth);
722 myText->setWrapColumnOrWidth(80);
724 aEditLayout->addMultiCellWidget(myText, 1, 1, 0, 3);
728 * Searches for text beginning with "def" and ending with any meanful character at
729 * beginning of line. Starts searching with current position of given stream.
730 * Fills the myPyFunctions with strings corresponding to found fucntions.
732 void SUPERVGUI_PythonEditPane::initPyFunctions( QTextStream& theStream ) {
734 if ( theStream.atEnd() )
738 QString aLine = theStream.readLine();
740 while ( !theStream.atEnd() ) { // not EOF
742 // asv : 23.11.04 : fix for PAL6870 : skip empty lines in the beginning or between functions
743 // find("def)==0 -> analizing only global function definitions which start with 0 indentation
744 while ( !aLine.isNull() && aLine.find( "def" ) != 0 )
745 aLine = theStream.readLine();
747 if ( !aLine.isNull() && aLine.find("def") == 0 ) {
748 aPyFunction += aLine;
751 // read function body
752 aLine = theStream.readLine();
753 // asv : 23.11.04 : added "|| aLine.isEmpty()" - fix for PAL6870. readLine() returns an empty
754 // string for "\n" string, it trails \n caracter. but we accept such lines..
755 while ( !aLine.isNull() && ( aLine.isEmpty() || aLine[0].isSpace() ) ) {
756 aPyFunction += aLine;
758 aLine = theStream.readLine();
761 myPyFunctions << aPyFunction;
762 aPyFunction.setLength( 0 );
768 * Load existing Python script
770 void SUPERVGUI_PythonEditPane::loadFile() {
771 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
774 tr("TIT_LOADSCRIPT"),
776 if (aFileName.isEmpty()) return;
778 QFile aFile( aFileName );
779 if (!aFile.open(IO_ReadOnly)) {
780 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
781 tr("MSG_CANT_LOADSCRIPT"));
785 myPyFunctions.clear();
787 myNextBtn->setEnabled( false );
790 QTextStream aFileReader(&aFile);
791 if ( aFileReader.atEnd() ) {
792 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_EMTY_FILE"));
797 initPyFunctions( aFileReader );
799 if ( myPyFunctions.size() ) {
800 myNextBtn->setEnabled( true );
807 * Finds and Reads a function from current position in the opened file
808 * asv : Comment above is old! Present model: just take an already read string = PyFunction
809 * from the list which is filled in loadFile().
811 void SUPERVGUI_PythonEditPane::readFunction() {
813 if ( myPyIndex != -1 && myPyFunctions.size() && myPyFunctions.size() > myPyIndex )
814 myText->append( myPyFunctions[ myPyIndex++ ] );
815 if ( myPyFunctions.size() <= myPyIndex ) // last index was reached
816 myNextBtn->setEnabled( false );
820 * Returns the text after "def" and before "(" -- first defined function name
822 QString SUPERVGUI_PythonEditPane::getFuncName() {
824 for (int i=0; i < myText->paragraphs(); i++) {
825 QString aLine = myText->text(i);
826 int aDefPos = aLine.find("def");
828 int aStart = aLine.find(" ", aDefPos);
829 int aEnd = aLine.find("(", aStart);
830 QString aName = aLine.mid(aStart, (aEnd-aStart));
831 return aName.stripWhiteSpace();
838 * Returns the contents of the myText widget without trailing spacing
840 SUPERV_Strings SUPERVGUI_PythonEditPane::getFunction() {
841 SUPERV_Strings aStrings = new SUPERV::ListOfStrings();
842 aStrings->length(myText->paragraphs());
843 for (int i=0; i < myText->paragraphs(); i++) {
844 QString aLine = myText->text(i);
845 // asv : 30.11.04 - why do we have to remove trailing spaces??
846 // it's user's responsibility to enter correct Python code, we don't do anything with it.
847 // if (..) -- initial, while(..) -- my improvement, but also commented out -- needless.
848 //if (!aLine.right(1).compare(" ")) // replaced with the line below -- loop
849 //while (aLine.at(aLine.length()-1).isSpace()) // remove trailing spaces
850 // aLine = aLine.remove(aLine.length()-1,1);
851 aStrings[i] = CORBA::string_dup(aLine.latin1());
853 return aStrings._retn();
857 void SUPERVGUI_PythonEditPane::setFunction(SUPERV_Strings theStr) {
858 int aLen = theStr->length();
859 for (int i=0; i < aLen; i++)
860 myText->append(QString(theStr[i]));
862 // asv : 30.11.04 : 2.7 - Inline node function editor improvement
863 // 2.7.1 - set focus to editor widget on editor window opening
864 // 2.7.2 - scroll to the beginning of function on editor window opening
866 myText->ensureVisible( 0,0 );
874 SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg(bool isLoop)
875 :QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
877 setSizeGripEnabled( true );
878 setCaption(tr("TIT_FUNC_PYTHON"));
880 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
882 QTabWidget* aLoopTabPane = new QTabWidget(this);
883 myInitPane = new SUPERVGUI_PythonEditPane(this);
884 aLoopTabPane->addTab(myInitPane, "Init");
886 myMorePane = new SUPERVGUI_PythonEditPane(this);
887 aLoopTabPane->addTab(myMorePane, "More");
889 myNextPane = new SUPERVGUI_PythonEditPane(this);
890 aLoopTabPane->addTab(myNextPane, "Next");
892 aMainLayout->addWidget(aLoopTabPane);
894 myEditPane = new SUPERVGUI_PythonEditPane(this);
895 aMainLayout->addWidget(myEditPane);
897 QGroupBox* aBtnBox = new QGroupBox( this );
898 aBtnBox->setColumnLayout( 0, Qt::Vertical );
899 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
900 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
901 aBtnLayout->setAlignment( Qt::AlignTop );
902 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
904 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
905 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
906 aBtnLayout->addWidget( aOKBtn );
908 aBtnLayout->addStretch();
910 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
911 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
912 aBtnLayout->addWidget( aCancelBtn );
914 aMainLayout->addWidget(aBtnBox);