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