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