]> SALOME platform Git repositories - modules/superv.git/blob - src/SUPERVGUI/SUPERVGUI_Service.cxx
Salome HOME
Stream Links show
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Service.cxx
1 //  SUPERV SUPERVGUI : GUI for Supervisor component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SUPERVGUI_Service.cxx
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 using namespace std;
29 #include "SUPERVGUI_Service.h"
30 #include "SUPERVGUI_Main.h"
31 #include "SUPERVGUI.h"
32 #include "QAD_Tools.h"
33 #include "QAD_FileDlg.h"
34
35 #include "SALOME_NamingService.hxx"
36 #include CORBA_CLIENT_HEADER(SALOME_ModuleCatalog)
37 #include <qlayout.h>
38 #include <qtextstream.h>
39
40
41 static const char * ComponentIcon[] = {
42 "20 20 2 1",
43 "       c None",
44 ".      c #000000",
45 "                    ",
46 "                    ",
47 "                    ",
48 " .................. ",
49 " .                . ",
50 " .                . ",
51 " .                . ",
52 " .                . ",
53 " .                . ",
54 " .                . ",
55 " .                . ",
56 " .                . ",
57 " .................. ",
58 "    .     .     .   ",
59 "    .     .     .   ",
60 "   ...   ...   ...  ",
61 "  .. .. .. .. .. .. ",
62 "  .   . .   . .   . ",
63 "  .. .. .. .. .. .. ",
64 "   ...   ...   ...  "};
65
66
67 static const char * InterfaceIcon[] = {
68 "20 20 2 1",
69 "       c None",
70 ".      c #000000",
71 "                    ",
72 "                    ",
73 "                    ",
74 "                    ",
75 "                    ",
76 "            ..      ",
77 "          ......    ",
78 "         ..    ..   ",
79 "         .      .   ",
80 "..........      ..  ",
81 "         .      .   ",
82 "         ..    ..   ",
83 "          ......    ",
84 "            ..      ",
85 "                    ",
86 "                    ",
87 "                    ",
88 "                    ",
89 "                    ",
90 "                    "};
91
92
93
94
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)
98 {
99   setSizeGripEnabled( true );
100   setCaption(tr("TIT_SERVICES"));
101
102   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
103
104   myTabPane = new QTabWidget(this);
105   connect(myTabPane, SIGNAL(currentChanged(QWidget *)), this, SLOT(tabChanged(QWidget *)));
106
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);
112
113   QHBoxLayout* aBaseLayout = new QHBoxLayout(aCorbaPane); //!!
114  
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); //!!
126
127   //QHGroupBox* aAddBox = new QHGroupBox(tr("TIT_ADDNODE"), aCorbaPane); //!!
128   //aAddBox->setInsideSpacing(20); //!!
129
130   QPushButton* aComputeCBtn = new QPushButton(tr("TIT_ADDCNODE"), aCorbaPane); //!!
131   connect(aComputeCBtn, SIGNAL(clicked()), this, SLOT(addComputeNode())); //!!
132   aComputeCBtn->setDefault(false); 
133
134   QPushButton* aComputeBtn = new QPushButton(tr("TIT_ADDFNODE"), aCorbaPane);
135   connect(aComputeBtn, SIGNAL(clicked()), this, SLOT(addFactoryNode()));
136   aComputeBtn->setDefault(true); 
137
138   aBaseLayout->addWidget(aComputeBtn);
139   aBaseLayout->addWidget(aComputeCBtn); //!!
140
141   aBaseLayoutV->insertLayout(-1, aBaseLayout);
142   myTabPane->addTab(aCorbaPane, tr("MODULES_PANE"));
143
144
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);
150
151   // Type pane
152   QHGroupBox* aAddBox2 = new QHGroupBox(tr("TIT_ADDNODE"), aPythonPane);
153   aAddBox2->setInsideSpacing(20);
154
155   QLabel* aTypeLbl = new QLabel(tr("LBL_NODETYPE"), aAddBox2);
156
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)));
164
165   aPythonLayout->addWidget(aAddBox2);
166
167   // Edit pane
168   myStackWidget = new QWidgetStack(aPythonPane);
169
170   // other pane
171   myScriptPane = new SUPERVGUI_PythonEditPane(myStackWidget);
172   myOtherId = myStackWidget->addWidget(myScriptPane);
173
174   // loop pane
175   QTabWidget* aLoopTabPane = new QTabWidget(myStackWidget);
176   myInitPane = new SUPERVGUI_PythonEditPane(myStackWidget); 
177   aLoopTabPane->addTab(myInitPane, "Init");
178
179   myMorePane = new SUPERVGUI_PythonEditPane(myStackWidget);
180   aLoopTabPane->addTab(myMorePane, "More");
181
182   myNextPane = new SUPERVGUI_PythonEditPane(myStackWidget);
183   aLoopTabPane->addTab(myNextPane, "Next");
184   myLoopId = myStackWidget->addWidget(aLoopTabPane);
185
186   myStackWidget->raiseWidget(myOtherId);
187
188   aPythonLayout->addWidget(myStackWidget, 1);
189
190   // Create button
191   QPushButton* aCreateBtn = new QPushButton(tr("TIT_ADDNODE"), aPythonPane);
192   connect(aCreateBtn, SIGNAL(clicked()), this, SLOT(addInlineNode()));
193   aPythonLayout->addWidget(aCreateBtn);
194
195   myTabPane->addTab(aPythonPane, tr("INLINE_PANE"));
196
197   aMainLayout->addWidget(myTabPane);
198
199   // Close button
200   QHBox* aBtnBox = new QHBox(this);
201   QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnBox->layout()); 
202   aBtnLayout->addStretch();
203
204   QPushButton* aCloseBtn = new QPushButton(tr("BUT_CLOSE"), aBtnBox);
205   connect(aCloseBtn, SIGNAL(clicked()), this, SLOT(reject()));
206   
207   aMainLayout->addWidget(aBtnBox);
208
209   initialise();
210   myX = 0;
211   myY = 0;
212   myIsInline = false;
213 }
214
215
216 char* getDataStreamParameterName(int aType)
217 {
218   switch(aType) {
219   case 1:
220     return "integer";
221   case 2:
222     return "float";
223   case 3:
224     return "double";
225   case 4:
226     return "string";
227   case 6:
228     return "boolean";
229   default:
230     return "unknown";
231   }
232 }
233
234 void SUPERVGUI_Service::initialise() {
235   CORBA::Object_ptr obj  = naming->Resolve("/Kernel/ModulCatalog");
236   SALOME_ModuleCatalog::ModuleCatalog_var *aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
237   *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
238   if (CORBA::is_nil(*aModuleCatalog)) {
239     setCaption("Error in Connexion to omniNames with '/Kernel/ModulCatalog'");
240     return;
241   }
242   
243   QAD_ResourceMgr* aResMgr = QAD_Desktop::createResourceManager();
244
245   SALOME_ModuleCatalog::ListOfComponents_var lComponents = (*aModuleCatalog)->GetComponentList();
246   long nbComp = lComponents->length();
247   for (int i=0; i<nbComp; i++) {
248     SALOME_ModuleCatalog::Acomponent_ptr C = (*aModuleCatalog)->GetComponent((char *)lComponents[i]);
249     QListViewItem* myComponentItem = new QListViewItem(components, (char*)lComponents[i]);
250     myComponentItem->setSelectable(false);
251     QString aIconName = C->component_icone();
252     if (!aIconName.isEmpty()) {
253       QString resDir = aResMgr->findFile(aIconName, C->componentname()) ;
254       if (resDir) {
255         resDir = QAD_Tools::addSlash(resDir);
256         QPixmap aIcone(resDir + aIconName);
257         QIconSet aIconSet(aIcone);
258         myComponentItem->setPixmap(0, aIconSet.pixmap(QIconSet::Small, QIconSet::Normal));
259       } else {
260         myComponentItem->setPixmap(0, ComponentIcon);
261       }
262     } else {
263       myComponentItem->setPixmap(0, ComponentIcon);
264     }
265     SALOME_ModuleCatalog::ListOfInterfaces* lInterfaces = C->GetInterfaceList();
266     long nbInterf = lInterfaces->length();
267     for (int j=0; j<nbInterf; j++) {
268       SALOME_ModuleCatalog::DefinitionInterface* Interface = C->GetInterface((char*)(*lInterfaces)[j]);
269       QListViewItem* myInterfaceItem = new QListViewItem(myComponentItem, (char*)Interface->interfacename);
270       myInterfaceItem->setSelectable(false);
271       myInterfaceItem->setPixmap(0, InterfaceIcon);
272       
273       long nbServices = Interface->interfaceservicelist.length();
274       for (int k=0; k<nbServices; k++) {
275         SALOME_ModuleCatalog::Service* Service = &(Interface->interfaceservicelist[k]);
276         QListViewItem* myServiceItem = new QListViewItem(myInterfaceItem, (char*)Service->ServiceName);
277         myServiceItem->setSelectable(true);
278         components->ensureItemVisible(myServiceItem);
279         
280         long nbPortsOut = Service->ServiceoutParameter.length();
281         for (int m=0; m<nbPortsOut; m++) {
282           SALOME_ModuleCatalog::ServicesParameter* PortOut = &(Service->ServiceoutParameter[m]);
283           QListViewItem* myPortOutItem = 
284             new QListViewItem(myServiceItem, (char*)PortOut->Parametername, (char*)PortOut->Parametertype, "Out");
285           myPortOutItem->setSelectable(false);
286         }
287
288         long nbStreamPortsOut = Service->ServiceoutDataStreamParameter.length();
289         for (int m=0; m<nbStreamPortsOut; m++) {
290           SALOME_ModuleCatalog::ServicesDataStreamParameter* PortOut = &(Service->ServiceoutDataStreamParameter[m]);
291           QListViewItem* myPortOutItem = 
292             new QListViewItem(myServiceItem, (char*)PortOut->Parametername, 
293                               getDataStreamParameterName(PortOut->Parametertype), "DataStream Out");
294           myPortOutItem->setSelectable(false);
295         }
296         
297         long nbPortsIn = Service->ServiceinParameter.length();
298         for (int l=0; l<nbPortsIn; l++) {
299           SALOME_ModuleCatalog::ServicesParameter* PortIn = &(Service->ServiceinParameter[l]);
300           QListViewItem* myPortInItem = 
301             new QListViewItem(myServiceItem, (char*)PortIn->Parametername, (char*)PortIn->Parametertype, "In");
302           myPortInItem->setSelectable(false);
303         }
304
305         long nbStreamPortsIn = Service->ServiceinDataStreamParameter.length();
306         for (int l=0; l<nbStreamPortsIn; l++) {
307           SALOME_ModuleCatalog::ServicesDataStreamParameter* PortIn = &(Service->ServiceinDataStreamParameter[l]);
308           QListViewItem* myPortInItem = 
309             new QListViewItem(myServiceItem, (char*)PortIn->Parametername, 
310                               getDataStreamParameterName(PortIn->Parametertype), "DataStream In");
311           myPortInItem->setSelectable(false);
312         }
313       }
314     }
315   }
316 }
317
318
319
320 SUPERVGUI_Service::~SUPERVGUI_Service() {
321     Trace("SUPERVGUI_Service::~SUPERVGUI_Service")
322 }
323
324 void SUPERVGUI_Service::addComputeNode() {
325   SUPERVGUI_Main* aMain = Supervision.getMain();
326   if (aMain==0) {
327     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
328   } else {
329     CORBA::Object_ptr obj  = naming->Resolve("/Kernel/ModulCatalog");
330     SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
331     *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
332     if (CORBA::is_nil(*aModuleCatalog)) {
333       QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
334     } else {
335       QListViewItem*        item;
336       bool                  b = false;
337       QListViewItemIterator i(components);
338       for (; i.current(); ++i) {
339         item = i.current();
340         if (item->isSelected()) {
341           const char* service   = item->text(0).latin1();
342           const char* interface = item->parent()->text(0).latin1();
343           const char* component = item->parent()->parent()->text(0).latin1();
344           SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
345           if (myComponent==NULL) {
346             QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
347           } else {
348             const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
349             b  = true;
350             
351             SUPERV_CNode node = aMain->getDataflow()->CNode(*myService);
352             if (CORBA::is_nil(node)) {
353               QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));   
354               return;
355             }
356             node->Coords(myX, myY);
357             myX += NODE_DX;
358             myY += NODE_DY;
359             aMain->addComputeNode(SUPERV::CNode::_narrow(node));
360           }
361         }
362       }
363       if (!b) {
364         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
365       }
366     }
367   }
368 }
369
370 void SUPERVGUI_Service::addFactoryNode() {
371   SUPERVGUI_Main* aMain = Supervision.getMain();
372   if (aMain==0) {
373     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
374   } else {
375     CORBA::Object_ptr obj  = naming->Resolve("/Kernel/ModulCatalog");
376     SALOME_ModuleCatalog::ModuleCatalog_var* aModuleCatalog = new SALOME_ModuleCatalog::ModuleCatalog_var;
377     *aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
378     if (CORBA::is_nil(*aModuleCatalog)) {
379       QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
380     } else {
381       QListViewItem*        item;
382       bool                  b = false;
383       QListViewItemIterator i(components);
384       for (; i.current(); ++i) {
385         item = i.current();
386         if (item->isSelected()) {
387           const char* service   = item->text(0).latin1();
388           const char* interface = item->parent()->text(0).latin1();
389           const char* component = item->parent()->parent()->text(0).latin1();
390           SALOME_ModuleCatalog::Acomponent_ptr myComponent = (*aModuleCatalog)->GetComponent(component);
391           if (myComponent==NULL) {
392             QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), tr("MSG_CANT_CHOOSE_SERVICE"));
393           } else {
394             const SALOME_ModuleCatalog::Service* myService = myComponent->GetService(interface, service);
395             b  = true;
396             
397             SUPERV_FNode node = aMain->getDataflow()->FNode(component, interface, *myService);
398             if (CORBA::is_nil(node)) {
399               QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));   
400               return;
401             }
402             node->Coords(myX, myY);
403             myX += NODE_DX;
404             myY += NODE_DY;
405             aMain->addComputeNode(SUPERV::CNode::_narrow(node));
406           }
407         }
408       }
409       if (!b) {
410         QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NONODE_TOADD"));
411       }
412     }
413   }
414 }
415
416
417 void SUPERVGUI_Service::addInlineNode() {
418   SUPERVGUI_Main* aMain = Supervision.getMain();
419   if (aMain==0) {
420     QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), tr("MSG_NO_SUPERVISION_WINDOW"));
421   } else {
422     int aSel = myTypeCombo->currentItem();
423     switch (aSel) {
424     case 0: // Computation
425       if (myScriptPane->isDefined()) {  
426         SUPERV_INode aNode = aMain->getDataflow()->INode(myScriptPane->getFuncName().latin1(), 
427                                                          (myScriptPane->getFunction()).in());
428         if (CORBA::is_nil(aNode)) {
429           QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
430           return;
431         }
432         aNode->Coords(myX, myY);
433         myX += NODE_DX;
434         myY += NODE_DY;
435         aMain->addComputeNode(SUPERV::CNode::_narrow(aNode));
436       }
437       break;
438       
439     case 1: // Switch
440       if (myScriptPane->isDefined()) {
441         SUPERV_INode aEndNode;
442         SUPERV_SNode aStartNode = aMain->getDataflow()->SNode(myScriptPane->getFuncName().latin1(),
443                                                               (myScriptPane->getFunction()).in(),
444                                                               aEndNode);
445         if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
446           QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
447           return;
448         }
449         aStartNode->Coords(myX, myY);
450         aEndNode->Coords(myX + LABEL_WIDTH*2, myY);
451         myX += NODE_DX;
452         myY += NODE_DY;
453         aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
454       }
455       break;
456       
457     case 2: // Loop
458       {
459         SUPERV_INode aEndNode;
460         SUPERV_LNode aStartNode = aMain->getDataflow()->LNode(myInitPane->getFuncName().latin1(), (myInitPane->getFunction()).in(),
461                                                               myMorePane->getFuncName().latin1(), (myMorePane->getFunction()).in(),
462                                                               myNextPane->getFuncName().latin1(), (myNextPane->getFunction()).in(),
463                                                               aEndNode);
464         if (CORBA::is_nil(aStartNode) || CORBA::is_nil(aEndNode)) {
465           QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
466           return;
467         }
468         aStartNode->Coords(myX, myY);
469         aEndNode->Coords(myX + LABEL_WIDTH*2, myY);
470         myX += NODE_DX;
471         myY += NODE_DY;
472         aMain->addControlNode(SUPERV::CNode::_narrow(aStartNode), SUPERV::CNode::_narrow(aEndNode), true);
473       }
474       break;
475       
476     case 3: // GoTo
477       {
478         SUPERV_GNode aGotoNode;
479         if (myScriptPane->isDefined()) 
480           aGotoNode = aMain->getDataflow()->GNode(myScriptPane->getFuncName().latin1(), 
481                                                   (myScriptPane->getFunction()).in(), "");
482         else
483           aGotoNode = aMain->getDataflow()->GNode("GoTo", (myScriptPane->getFunction()).in(), "");
484         if (CORBA::is_nil(aGotoNode)) {
485           QMessageBox::warning(0, tr("ERROR"), tr("MSG_CANT_CREATE_NODE"));       
486           return;
487         }
488         aGotoNode->Coords(myX, myY);
489         myX += NODE_DX;
490         myY += NODE_DY;
491         aMain->addGOTONode(SUPERV::GNode::_narrow(aGotoNode));
492       }
493       break;
494     }
495   }
496 }
497
498
499
500 void SUPERVGUI_Service::typeNodeSelected(int theRow) {
501   if (theRow == 2)
502     myStackWidget->raiseWidget(myLoopId);
503   else
504     myStackWidget->raiseWidget(myOtherId);
505 }
506
507
508
509 void SUPERVGUI_Service::choose() {
510     Trace("SUPERVGUI_Service::choose")
511     show();
512     raise();
513 }
514     
515
516 void SUPERVGUI_Service::showEvent(QShowEvent* theEvent) {
517   SUPERVGUI_Main* aMain = Supervision.getMain();
518   if (aMain && (!aMain->isArrayShown())) {
519     aMain->getGraph()->viewportToContents(0, 0, myX, myY);
520   }
521   QDialog::showEvent(theEvent);
522 }
523
524
525 void SUPERVGUI_Service::tabChanged(QWidget* theWidget) {
526   myIsInline = (myTabPane->currentPageIndex() == 1);
527 }
528
529
530
531 //*****************************************************
532 //  Pane for Python script editing
533 //*****************************************************
534 SUPERVGUI_PythonEditPane::SUPERVGUI_PythonEditPane(QWidget* theParent) 
535   : QFrame(theParent),
536     myIStream(0)
537 {
538   QGridLayout* aEditLayout = new QGridLayout(this, 2, 4);
539
540   // First row
541   QPushButton* aLoadBtn = new QPushButton(tr("BUT_LOAD"), this);
542   connect(aLoadBtn, SIGNAL(clicked()), this, SLOT(loadFile()));
543   
544   aEditLayout->addWidget(aLoadBtn, 0, 2);
545
546   myNextBtn = new QPushButton(tr("BUT_NEXT"), this);
547   myNextBtn->setEnabled(false);
548   connect(myNextBtn, SIGNAL(clicked()), this, SLOT(readFunction()));
549   
550   aEditLayout->addWidget(myNextBtn, 0, 3);
551   
552   //Second row
553   myText = new QTextEdit(this);
554   myText->setWordWrap(QTextEdit::FixedColumnWidth);
555   myText->setWrapColumnOrWidth(80);
556
557   aEditLayout->addMultiCellWidget(myText, 1, 1, 0, 3);
558 }
559    
560
561 /**
562  * Load existing Python script
563  */
564 void SUPERVGUI_PythonEditPane::loadFile() {
565   QString aFileName = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
566                                                "",
567                                                "*.py",
568                                                tr("TIT_LOADSCRIPT"),
569                                                true);
570   if (aFileName.isEmpty()) return;
571
572   myFile = new QFile(aFileName);
573   if (!myFile->open(IO_ReadOnly)) {
574     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), 
575                          tr("MSG_CANT_LOADSCRIPT"));
576     return;
577   }
578   myIStream = new QTextStream(myFile);
579
580   if (myIStream->atEnd()) {
581     QMessageBox::warning(QAD_Application::getDesktop(), tr("ERROR"), 
582                          tr("MSG_EMTY_FILE"));
583     myNextBtn->setEnabled(false);
584     delete myIStream;
585     myIStream = 0;
586     myFile->close();
587     delete myFile;
588     return;
589   }
590   myNextBtn->setEnabled(true);
591   readFunction();
592 }
593   
594
595 /**
596  * Finds and Reads a function from current position in the opened file
597  */
598 void SUPERVGUI_PythonEditPane::readFunction() {
599   if (!myIStream) return;
600
601   while (!myIStream->atEnd()) {
602     QString aLine = myIStream->readLine();
603     if (aLine.isNull()) return;
604
605     // find first function
606     int aDefPos = aLine.find("def");
607     if (aDefPos == 0) { // only not a class members
608       myText->clear();
609       // find name
610       /*int aStart = aLine.find(" ", aDefPos);
611       int aEnd = aLine.find("(", aStart);
612       QString aName = aLine.mid(aStart, (aEnd-aStart));
613       aName = aName.stripWhiteSpace();
614       myNameEdt->setText(aName);*/
615       
616       // find input params
617       /*aStart = aEnd+1;
618       aEnd = aLine.find(")", aStart);
619       QString aParams = aLine.mid(aStart, (aEnd-aStart));
620       aParams = aParams.stripWhiteSpace();
621       myParamEdt->setText(aParams);*/
622
623       myText->append(aLine);
624       // read body
625       QString aBodyLine = myIStream->readLine();
626       while ((!aBodyLine.isNull()) && aBodyLine[0].isSpace()) {
627         myText->append(aBodyLine);
628         aBodyLine = myIStream->readLine();
629       }
630       return;
631     }
632   }
633   QMessageBox::warning(QAD_Application::getDesktop(), tr("WARNING"), 
634                          tr("MSG_NOMORE_FUNCTIONS"));
635   delete myIStream;
636   myIStream = 0;
637   myNextBtn->setEnabled(false);
638   myFile->close();
639   delete myFile;
640 }
641
642
643 QString SUPERVGUI_PythonEditPane::getFuncName() {
644   QString aName("");
645   for (int i=0; i < myText->paragraphs(); i++) {
646     QString aLine = myText->text(i);
647     int aDefPos = aLine.find("def");
648     if (aDefPos == 0) {
649       int aStart = aLine.find(" ", aDefPos);
650       int aEnd = aLine.find("(", aStart);
651       QString aName = aLine.mid(aStart, (aEnd-aStart));
652       return aName.stripWhiteSpace();
653     }
654   }
655   return aName;
656 }
657
658
659 SUPERV_Strings SUPERVGUI_PythonEditPane::getFunction() {
660   SUPERV_Strings aStrings = new SUPERV::ListOfStrings();
661   aStrings->length(myText->paragraphs());
662   for (int i=0; i < myText->paragraphs(); i++) {
663     aStrings[i] = CORBA::string_dup(myText->text(i).latin1());
664   }
665   return aStrings._retn();
666 }
667
668
669 void SUPERVGUI_PythonEditPane::setFunction(SUPERV_Strings theStr) {
670   int aLen = theStr->length();
671   for (int i=0; i < aLen; i++)
672     myText->append(QString(theStr[i]));
673 }
674
675
676
677 /*!
678  * Edit Python dialog
679  */
680 SUPERVGUI_EditPythonDlg::SUPERVGUI_EditPythonDlg(bool isLoop)
681   :QDialog(QAD_Application::getDesktop(), 0, true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
682 {
683   setSizeGripEnabled( true );
684   setCaption(tr("TIT_FUNC_PYTHON"));
685   resize( 500, 250 );
686   QVBoxLayout* aMainLayout = new QVBoxLayout(this, 7, 4);
687   if (isLoop) {
688     QTabWidget* aLoopTabPane = new QTabWidget(this);
689     myInitPane = new SUPERVGUI_PythonEditPane(this); 
690     aLoopTabPane->addTab(myInitPane, "Init");
691     
692     myMorePane = new SUPERVGUI_PythonEditPane(this);
693     aLoopTabPane->addTab(myMorePane, "More");
694     
695     myNextPane = new SUPERVGUI_PythonEditPane(this);
696     aLoopTabPane->addTab(myNextPane, "Next");
697
698     aMainLayout->addWidget(aLoopTabPane);    
699   } else {
700     myEditPane = new SUPERVGUI_PythonEditPane(this);
701     aMainLayout->addWidget(myEditPane);
702   }
703   QGroupBox* aBtnBox = new QGroupBox( this );
704   aBtnBox->setColumnLayout( 0, Qt::Vertical );
705   aBtnBox->layout()->setSpacing( 0 ); aBtnBox->layout()->setMargin( 0 );
706   QHBoxLayout* aBtnLayout = new QHBoxLayout( aBtnBox->layout() );
707   aBtnLayout->setAlignment( Qt::AlignTop );
708   aBtnLayout->setSpacing( 6 ); aBtnLayout->setMargin( 11 );
709   
710   QPushButton* aOKBtn = new QPushButton( tr( "BUT_OK" ), aBtnBox );
711   connect( aOKBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
712   aBtnLayout->addWidget( aOKBtn );
713
714   aBtnLayout->addStretch();
715
716   QPushButton* aCancelBtn = new QPushButton( tr("BUT_CANCEL"), aBtnBox );
717   connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
718   aBtnLayout->addWidget( aCancelBtn );
719
720   aMainLayout->addWidget(aBtnBox);
721 }