Salome HOME
Fix for bug IPAL9817 : SIGSEGV appears after "InLine" node function edition.
[modules/superv.git] / src / SUPERVGUI / SUPERVGUI_Service.h
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.h
25 //  Author : Francis KLOSS
26 //  Module : SUPERV
27
28 #ifndef SUPERVGUI_Service_H
29 #define SUPERVGUI_Service_H
30
31 using namespace std;
32 #include "SUPERVGUI_Def.h"
33 #include <qtabwidget.h>
34 #include <qhgroupbox.h>
35 #include <qwidgetstack.h>
36
37 class QListBox; 
38
39 /*!
40  * Pane for Python script editing
41  */
42 class SUPERVGUI_PythonEditPane: public QFrame {
43
44   Q_OBJECT
45
46 public:
47   SUPERVGUI_PythonEditPane( QWidget* theParent, const bool isNodeCreation, int& theX, int& theY );
48   ~SUPERVGUI_PythonEditPane() {};
49   
50   QString getFuncName();
51
52   bool isDefined()
53     { return (myText->paragraphs() > 1); }
54
55   SUPERV_Strings getFunction();
56   void setFunction(SUPERV_Strings theStr);
57     
58 public slots:
59   // load all functions from an XML file into internal structures 
60   void loadFile();
61
62   // when user presses "Enter" - automatically set indentation of next line
63   void autoIndentLine(); 
64
65   // when user select another function name in combo box - fill myText with its body
66   void readFunction( int i ); 
67
68   // when user presses "Library" button - open a "Create node from Library" dialog
69   void library();
70
71 private:
72   bool         myIsWithLibrary;
73   QTextEdit*   myText;
74   QComboBox*   myFunctionsCombo;
75
76   // fills myPyFunctions list.  called from loadFile() after user selects a file.
77   void         initPyFunctions( QTextStream& );
78
79   // list of Python functions.  filled in loadFile(), strings (functions) retrieved 
80   // in readFunction()
81   QStringList  myPyFunctions; 
82
83   int& myX; // comes from SUPERVGUI_Service 
84   int& myY; // comes from SUPERVGUI_Service 
85
86 };
87
88 /*!
89  * Dialog box for node creation
90  */
91 class SUPERVGUI_Service: public QDialog {
92
93   Q_OBJECT
94
95 public:
96     SUPERVGUI_Service(SALOME_NamingService* ns);
97     ~SUPERVGUI_Service();
98
99     void choose();
100
101     /*!
102      * Do the following actions for newly created Engine's CNode:
103      * 1. Create a presentation for it (CanvasNode)
104      * 2. Place the CanvasNode to the current top-left corner or the current viewport
105      * 3. Increment the coordinates of the next CanvasNode (new nodes are "cascaded" when several of them are created at once)
106      * PS theEndNode is passed only for Loop and Switch nodes (EndLoop and EndSwitch)
107      */ 
108     static void addNode( SUPERV::CNode_var theNode, SUPERV::INode_var theEndNode, int& theX, int& theY );
109
110 protected:
111     void showEvent(QShowEvent* theEvent);
112
113 private:
114     void initialise();
115
116 private slots:
117     void tabChanged(QWidget *);
118     void addComputeNode();
119     void addFactoryNode();
120     void addInlineNode();
121     void addMacroNode();
122     void typeNodeSelected(int theRow);
123     void loadGraph();
124
125 private:
126     QListView* components;
127     SALOME_NamingService* naming;
128     int myX, myY;
129     QWidgetStack* myStackWidget;
130     int myLoopId;
131     int myOtherId;
132
133     SUPERVGUI_PythonEditPane* myScriptPane;
134
135     SUPERVGUI_PythonEditPane* myInitPane;
136     SUPERVGUI_PythonEditPane* myMorePane;
137     SUPERVGUI_PythonEditPane* myNextPane;
138
139     QListView* myMacroPane;
140     QFile*     myMFile;        
141
142     QTabWidget* myTabPane;
143     bool myIsInline;
144
145     QComboBox* myTypeCombo;
146 };
147
148 /*!
149  * Edit Python dialog
150  */
151 class SUPERVGUI_EditPythonDlg: public QDialog {
152
153   Q_OBJECT
154     
155 public:
156   SUPERVGUI_EditPythonDlg(bool isLoop = false);
157   ~SUPERVGUI_EditPythonDlg() {};
158
159   // Not Loop functions
160   QString getFuncName()
161     { return myEditPane->getFuncName(); }
162
163   bool isDefined()
164     { return myEditPane->isDefined(); }
165
166   SUPERV_Strings getFunction()
167     { return myEditPane->getFunction(); }
168
169   void setFunction(SUPERV_Strings theStr)
170     { myEditPane->setFunction(theStr); }
171
172   // Init functions
173   QString getInitFuncName()
174     { return myInitPane->getFuncName(); }
175
176   SUPERV_Strings getInitFunction()
177     { return myInitPane->getFunction(); }
178
179   void setInitFunction(SUPERV_Strings theStr)
180     { myInitPane->setFunction(theStr); }
181
182   // More functions
183   QString getMoreFuncName()
184     { return myMorePane->getFuncName(); }
185
186   SUPERV_Strings getMoreFunction()
187     { return myMorePane->getFunction(); }
188
189   void setMoreFunction(SUPERV_Strings theStr)
190     { myMorePane->setFunction(theStr); }
191
192   // Next functions
193   QString getNextFuncName()
194     { return myNextPane->getFuncName(); }
195
196   SUPERV_Strings getNextFunction()
197     { return myNextPane->getFunction(); }
198
199   void setNextFunction(SUPERV_Strings theStr)
200     { myNextPane->setFunction(theStr); }
201
202 public slots:
203   void clickOnOk();
204
205 private:
206   SUPERVGUI_PythonEditPane* myEditPane;
207   SUPERVGUI_PythonEditPane* myInitPane;
208   SUPERVGUI_PythonEditPane* myMorePane;
209   SUPERVGUI_PythonEditPane* myNextPane;
210 };
211
212 #endif