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