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