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)
38 #include <qtextstream.h>
41 static const char * ComponentIcon[] = {
48 " .................. ",
57 " .................. ",
61 " .. .. .. .. .. .. ",
63 " .. .. .. .. .. .. ",
67 static const char * InterfaceIcon[] = {
95 SUPERVGUI_Service::SUPERVGUI_Service(SALOME_NamingService* ns):
96 QDialog(QAD_Application::getDesktop(), 0, false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
97 naming(ns), myMFile(0)
99 setSizeGripEnabled( true );
100 setCaption(tr("TIT_SERVICES"));
102 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
104 myTabPane = new QTabWidget(this);
105 connect(myTabPane, SIGNAL(currentChanged(QWidget *)), this, SLOT(tabChanged(QWidget *)));
107 // Create Tab for Corba services
108 QWidget* aCorbaPane = new QWidget(myTabPane);
109 QVBoxLayout* aBaseLayoutV= new QVBoxLayout(aCorbaPane, 0, 4);
110 aBaseLayoutV->setMargin(5);
111 aBaseLayoutV->setSpacing(10);
113 QHBoxLayout* aBaseLayout = new QHBoxLayout(aCorbaPane); //!!
115 components = new QListView(aCorbaPane);
116 components->addColumn(tr("COL_COMPONENTS"));
117 components->addColumn(tr("COL_PORTTYPE"));
118 components->addColumn(tr("COL_PORTWAY"));
119 components->setColumnAlignment(1, AlignLeft);
120 components->setColumnAlignment(2, AlignLeft);
121 components->setColumnAlignment(3, AlignLeft);
122 components->setSelectionMode(QListView::Extended);
123 components->setRootIsDecorated(true);
124 // aBaseLayout->addWidget(components);
125 aBaseLayoutV->addWidget(components); //!!
127 //QHGroupBox* aAddBox = new QHGroupBox(tr("TIT_ADDNODE"), aCorbaPane); //!!
128 //aAddBox->setInsideSpacing(20); //!!
130 //NRI QPushButton* aComputeCBtn = new QPushButton(tr("TIT_ADDCNODE"), aCorbaPane); //!!
131 //NRI connect(aComputeCBtn, SIGNAL(clicked()), this, SLOT(addComputeNode())); //!!
132 //NRI aComputeCBtn->setDefault(false);
134 QPushButton* aComputeBtn = new QPushButton(tr("TIT_ADDFNODE"), aCorbaPane);
135 connect(aComputeBtn, SIGNAL(clicked()), this, SLOT(addFactoryNode()));
136 aComputeBtn->setDefault(true);
138 aBaseLayout->addWidget(aComputeBtn);
139 //NRI aBaseLayout->addWidget(aComputeCBtn); //!!
141 aBaseLayoutV->insertLayout(-1, aBaseLayout);
142 myTabPane->addTab(aCorbaPane, tr("MODULES_PANE"));
145 // Create Tab for Python services
146 QWidget* aPythonPane = new QWidget(myTabPane);
147 QVBoxLayout* aPythonLayout = new QVBoxLayout(aPythonPane, 0, 4);
148 aPythonLayout->setMargin(5);
149 aPythonLayout->setSpacing(10);
152 QHGroupBox* aAddBox2 = new QHGroupBox(tr("TIT_ADDNODE"), aPythonPane);
153 aAddBox2->setInsideSpacing(20);
155 QLabel* aTypeLbl = new QLabel(tr("LBL_NODETYPE"), aAddBox2);
157 myTypeCombo = new QComboBox(aAddBox2);
158 myTypeCombo->insertItem("Computation");
159 myTypeCombo->insertItem("Switch");
160 myTypeCombo->insertItem("Loop");
161 myTypeCombo->insertItem("GoTo");
162 //myTypeCombo->insertItem("Label");
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 node->Coords(myX, myY);
401 aMain->addComputeNode(SUPERV::CNode::_narrow(node));
406 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
412 void SUPERVGUI_Service::addFactoryNode() {
413 QAD_Desktop* aDesktop = QAD_Application::getDesktop();
414 SUPERVGUI_Main* aMain = Supervision.getMain();
416 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
417 } else if (!aMain->isEditable()) {
418 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
420 CORBA::Object_ptr obj = naming->Resolve("/Kernel/ModulCatalog");
421 SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
422 *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
423 if (CORBA::is_nil(*aModuleCatalog)) {
424 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
428 QListViewItemIterator i(components);
429 for (; i.current(); ++i) {
431 if (item->isSelected()) {
432 const char* service = item->text(0).latin1();
433 const char* interface = item->parent()->text(0).latin1();
434 const char* component = aDesktop->getComponentName(item->parent()->parent()->text(0).latin1());
435 SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
436 if (myComponent==NULL) {
437 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
439 const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
442 MESSAGE ( " myService->TypeOfNode == " << myService->TypeOfNode )
444 if ( myService->TypeOfNode == 0 ) { // ComputeNode
445 SUPERV_CNode node = aMain->getDataflow()->CNode(*myService);
446 if (CORBA::is_nil(node)) {
447 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
450 node->Coords(myX, myY);
453 aMain->addComputeNode(SUPERV::CNode::_narrow(node));
454 } else { // Factory Node
455 SUPERV_FNode node = aMain->getDataflow()->FNode(component, interface, *myService);
456 if (CORBA::is_nil(node)) {
457 QMessageBox::warning(aDesktop, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
460 node->Coords(myX, myY);
463 aMain->addComputeNode(SUPERV::CNode::_narrow(node));
467 // SUPERV_FNode node = aMain->getDataflow()->FNode(component, interface, *myService);
468 // if (CORBA::is_nil(node)) {
469 // QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
472 // node->Coords(myX, myY);
475 // aMain->addComputeNode(SUPERV::CNode::_narrow(node));
480 QMessageBox::warning(aDesktop, tr("WARNING"), tr("MSG_NONODE_TOADD"));
487 void SUPERVGUI_Service::addInlineNode() {
488 SUPERVGUI_Main* aMain = Supervision.getMain();
490 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
491 } else if (!aMain->isEditable()) {
492 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
494 int aSel = myTypeCombo->currentItem();
496 case 0: // Computation
497 if (myScriptPane->isDefined()) {
498 SUPERV_INode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(),
499 (myScriptPane->getFunction()).in());
500 if (CORBA::is_nil(aNode)) {
501 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
504 aNode->Coords(myX, myY);
507 aMain->addComputeNode(SUPERV::CNode::_narrow(aNode));
512 if (myScriptPane->isDefined()) {
513 SUPERV_INode aEndNode;
514 SUPERV_SNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(),
515 (myScriptPane->getFunction()).in(),
517 if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
518 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
521 aStartNode->Coords(myX, myY);
522 aEndNode->Coords(myX + LABEL_WIDTH*2, myY);
525 aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
531 SUPERV_INode aEndNode;
532 SUPERV_LNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(),
533 myMorePane->getFuncName().latin1(), (myMorePane->getFunction()).in(),
534 myNextPane->getFuncName().latin1(), (myNextPane->getFunction()).in(),
536 if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
537 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
540 aStartNode->Coords(myX, myY);
541 aEndNode->Coords(myX + LABEL_WIDTH*2, myY);
544 aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
550 SUPERV_GNode aGotoNode;
551 if (myScriptPane->isDefined())
552 aGotoNode = aMain->getDataflow()->GNode(myScriptPane->getFuncName().latin1(),
553 (myScriptPane->getFunction()).in(), "");
555 aGotoNode = aMain->getDataflow()->GNode("GoTo", (myScriptPane->getFunction()).in(), "");
556 if (CORBA::is_nil(aGotoNode)) {
557 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
560 aGotoNode->Coords(myX, myY);
563 aMain->addGOTONode(SUPERV::GNode::_narrow(aGotoNode));
570 void SUPERVGUI_Service::addMacroNode() {
571 SUPERVGUI_Main* aMain = Supervision.getMain();
573 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
574 } else if (!aMain->isEditable()) {
575 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
579 if (aMain->getDataflow()->IsStreamGraph()) {
580 SUPERV_StreamGraph aSGraph = aMain->getDataflow()->ToStreamGraph();
581 if (!SUPERV_isNull(aSGraph))
582 aNode = aSGraph->StreamMNode(myMFile->name().latin1());
583 // TMP: while stream macro nodes doesn't impemented
584 if (CORBA::is_nil(aNode)) {
585 aNode = aSGraph->MNode(myMFile->name().latin1());
589 aNode = aMain->getDataflow()->MNode(myMFile->name().latin1());
590 if (CORBA::is_nil(aNode)) {
591 QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));
594 aNode->Coords(myX, myY);
597 aMain->addMacroNode(SUPERV::CNode::_narrow(aNode));
600 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
605 void SUPERVGUI_Service::loadGraph() {
606 if ( getenv( "ENABLE_MACRO_NODE" ) == NULL )
607 // error! if ENABLE_MACRO_NODE is set - we should NOT get here by any means..
609 //cout << "Error: ENABLE_MACRO_NODE is not set, but loadGraph() was called!" << endl;
613 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
616 tr("MSG_GRAPH_INSERT"),
618 if (aFileName.isEmpty()) return;
620 myMacroPane->clear();
622 myMFile = new QFile(aFileName);
623 if (!myMFile->open(IO_ReadOnly)) {
624 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
625 tr("MSG_CANT_LOADSCRIPT"));
626 delete myMFile; myMFile = 0;
630 QTextStream* aStream = new QTextStream(myMFile);
631 if (aStream->atEnd()) {
632 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
633 tr("MSG_EMTY_FILE"));
636 delete myMFile; myMFile = 0;
641 // temporary display only file name
642 QFileInfo anInfo(*myMFile);
643 QListViewItem* anItem = new QListViewItem(myMacroPane, anInfo.baseName());
644 anItem->setSelectable(true);
647 void SUPERVGUI_Service::typeNodeSelected(int theRow) {
649 myStackWidget->raiseWidget(myLoopId);
651 myStackWidget->raiseWidget(myOtherId);
656 void SUPERVGUI_Service::choose() {
657 Trace("SUPERVGUI_Service::choose")
663 void SUPERVGUI_Service::showEvent(QShowEvent* theEvent) {
664 SUPERVGUI_Main* aMain = Supervision.getMain();
665 if (aMain && (!aMain->isArrayShown())) {
666 aMain->getGraph()->viewportToContents(0, 0, myX, myY);
668 QDialog::showEvent(theEvent);
672 void SUPERVGUI_Service::tabChanged(QWidget* theWidget) {
673 myIsInline = (myTabPane->currentPageIndex() == 1);
678 //*****************************************************
679 // Pane for Python script editing
680 //*****************************************************
681 SUPERVGUI_PythonEditPane::SUPERVGUI_PythonEditPane(QWidget* theParent)
685 QGridLayout* aEditLayout = new QGridLayout(this, 2, 4);
688 QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), this);
689 connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadFile()));
691 aEditLayout->addWidget(aLoadBtn, 0, 2);
693 myNextBtn = new QPushButton(tr("BUT_NEXT"), this);
694 myNextBtn->setEnabled(false);
695 connect(myNextBtn, SIGNAL(clicked()), this, SLOT(readFunction()));
697 aEditLayout->addWidget(myNextBtn, 0, 3);
700 myText = new QTextEdit(this);
701 myText->setWordWrap(QTextEdit::FixedColumnWidth);
702 myText->setWrapColumnOrWidth(80);
704 aEditLayout->addMultiCellWidget(myText, 1, 1, 0, 3);
709 * Load existing Python script
711 void SUPERVGUI_PythonEditPane::loadFile() {
712 QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
715 tr("TIT_LOADSCRIPT"),
717 if (aFileName.isEmpty()) return;
719 myFile = new QFile(aFileName);
720 if (!myFile->open(IO_ReadOnly)) {
721 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
722 tr("MSG_CANT_LOADSCRIPT"));
725 myIStream = new QTextStream(myFile);
727 if (myIStream->atEnd()) {
728 QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"),
729 tr("MSG_EMTY_FILE"));
730 myNextBtn->setEnabled(false);
737 myNextBtn->setEnabled(true);
743 * Finds and Reads a function from current position in the opened file
745 void SUPERVGUI_PythonEditPane::readFunction() {
746 if (!myIStream) return;
748 while (!myIStream->atEnd()) {
749 QString aLine = myIStream->readLine();
750 if (aLine.isNull()) return;
752 // find first function
753 int aDefPos = aLine.find("def");
754 if (aDefPos == 0) { // only not a class members
757 /*int aStart = aLine.find(" ", aDefPos);
758 int aEnd = aLine.find("(", aStart);
759 QString aName = aLine.mid(aStart, (aEnd-aStart));
760 aName = aName.stripWhiteSpace();
761 myNameEdt->setText(aName);*/
765 aEnd = aLine.find(")", aStart);
766 QString aParams = aLine.mid(aStart, (aEnd-aStart));
767 aParams = aParams.stripWhiteSpace();
768 myParamEdt->setText(aParams);*/
770 myText->append(aLine);
772 QString aBodyLine = myIStream->readLine();
773 while ((!aBodyLine.isNull()) && aBodyLine[0].isSpace()) {
774 myText->append(aBodyLine);
775 aBodyLine = myIStream->readLine();
780 QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"),
781 tr("MSG_NOMORE_FUNCTIONS"));
784 myNextBtn->setEnabled(false);
790 QString SUPERVGUI_PythonEditPane::getFuncName() {
792 for (int i=0; i < myText->paragraphs(); i++) {
793 QString aLine = myText->text(i);
794 int aDefPos = aLine.find("def");
796 int aStart = aLine.find(" ", aDefPos);
797 int aEnd = aLine.find("(", aStart);
798 QString aName = aLine.mid(aStart, (aEnd-aStart));
799 return aName.stripWhiteSpace();
806 SUPERV_Strings SUPERVGUI_PythonEditPane::getFunction() {
807 SUPERV_Strings aStrings = new SUPERV::ListOfStrings();
808 aStrings->length(myText->paragraphs());
809 for (int i=0; i < myText->paragraphs(); i++) {
810 aStrings[i] = CORBA::string_dup(myText->text(i).latin1());
812 return aStrings._retn();
816 void SUPERVGUI_PythonEditPane::setFunction(SUPERV_Strings theStr) {
817 int aLen = theStr->length();
818 for (int i=0; i < aLen; i++)
819 myText->append(QString(theStr[i]));
827 SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg(bool isLoop)
828 :QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
830 setSizeGripEnabled( true );
831 setCaption(tr("TIT_FUNC_PYTHON"));
833 QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
835 QTabWidget* aLoopTabPane = new QTabWidget(this);
836 myInitPane = new SUPERVGUI_PythonEditPane(this);
837 aLoopTabPane->addTab(myInitPane, "Init");
839 myMorePane = new SUPERVGUI_PythonEditPane(this);
840 aLoopTabPane->addTab(myMorePane, "More");
842 myNextPane = new SUPERVGUI_PythonEditPane(this);
843 aLoopTabPane->addTab(myNextPane, "Next");
845 aMainLayout->addWidget(aLoopTabPane);
847 myEditPane = new SUPERVGUI_PythonEditPane(this);
848 aMainLayout->addWidget(myEditPane);
850 QGroupBox* aBtnBox = new QGroupBox( this );
851 aBtnBox->setColumnLayout( 0, Qt::Vertical );
852 aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
853 QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
854 aBtnLayout->setAlignment( Qt::AlignTop );
855 aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
857 QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
858 connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
859 aBtnLayout->addWidget( aOKBtn );
861 aBtnLayout->addStretch();
863 QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
864 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
865 aBtnLayout->addWidget( aCancelBtn );
867 aMainLayout->addWidget(aBtnBox);