Salome HOME
Update copyrights 2014.
[modules/gui.git] / src / SalomeApp / SalomeApp_NoteBook.h
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // File:    SalomeApp_NoteBook.h
21 // Author : Roman NIKOLAEV, Open CASCADE S.A.S.
22 // Module : GUI
23 //
24 #ifndef SALOMEAPP_NOTEBOOK_H
25 #define SALOMEAPP_NOTEBOOK_H
26
27 #include "SalomeApp.h"
28
29 #include "SALOMEDSClient_ClientFactory.hxx" 
30 #include CORBA_SERVER_HEADER(SALOMEDS)
31
32 #include <QWidget>
33 #include <QTableWidget>
34 #include <QList>
35
36 class QWidget;
37 class QPushButton;
38 class QTableWidgetItem;
39 class NoteBook_Table;
40
41 struct NoteBoox_Variable
42 {
43   NoteBoox_Variable() {}
44   NoteBoox_Variable( const QString& theName, const QString& theValue )
45   {
46     Name = theName;
47     Value = theValue;
48   }
49   QString Name;
50   QString Value;
51 };
52
53 typedef QMap< int, NoteBoox_Variable > VariableMap;
54
55 class SALOMEAPP_EXPORT NoteBook_TableRow : public QWidget
56 {
57  public:
58   NoteBook_TableRow(int, NoteBook_Table* parentTable, QWidget* parent=0 );
59   virtual ~NoteBook_TableRow();
60
61   int  GetIndex() const { return myIndex; }
62   
63   void AddToTable(QTableWidget *theTable);
64   
65   void SetName(const QString theName);
66   void SetValue(const QString theValue);
67
68   QString GetValue() const;
69   QString GetName() const;
70
71   bool CheckName();
72   bool CheckValue();
73
74   QTableWidgetItem* GetVariableItem();
75   QTableWidgetItem* GetNameItem();
76   QTableWidgetItem* GetHeaderItem();
77
78   static bool IsRealValue(const QString theValue, double* theResult = 0);
79   static bool IsIntegerValue(const QString theValue, int* theResult = 0);
80   static bool IsBooleanValue(const QString theValue, bool* theResult = 0);
81   bool IsValidStringValue(const QString theName);
82   
83  private:
84   int               myIndex;
85   NoteBook_Table*   myParentTable;
86   QTableWidgetItem* myRowHeader;
87   QTableWidgetItem* myVariableName;
88   QTableWidgetItem* myVariableValue;
89 };
90
91 class SALOMEAPP_EXPORT NoteBook_Table : public QTableWidget
92 {
93   Q_OBJECT
94  public:
95   NoteBook_Table(QWidget * parent = 0);
96   virtual ~NoteBook_Table();
97
98   void Init(_PTR(Study) theStudy);
99   static QString Variable2String(const std::string& theVarName,
100                                  _PTR(Study) theStudy);
101
102   bool IsValid() const;
103
104   void AddRow( const QString& theName = QString::null, const QString& theValue = QString::null );
105   void AddEmptyRow();
106   NoteBook_TableRow* GetRowByItem(const QTableWidgetItem* theItem) const;
107   bool IsLastRow(const NoteBook_TableRow* aRow) const;
108
109   void RemoveSelected();
110
111   void SetProcessItemChangedSignalFlag(const bool enable);
112   bool GetProcessItemChangedSignalFlag()const;
113
114   bool IsUniqueName(const NoteBook_TableRow* theRow) const;
115   QList<NoteBook_TableRow*> GetRows() const;
116
117   const bool         IsModified() const { return myIsModified; }
118   const QList<int>&  GetRemovedRows() const { return myRemovedRows; }
119   const VariableMap& GetVariableMap() const { return myVariableMap; }
120   const VariableMap& GetVariableMapRef() const { return myVariableMapRef; }
121   void  RenumberRowItems();
122
123   void ResetMaps();
124
125   QList<NoteBook_TableRow*>          myRows;
126
127   public slots:
128     void onItemChanged(QTableWidgetItem* theItem);
129
130  private:
131     int  getUniqueIndex() const;
132     
133  private:
134   bool isProcessItemChangedSignal;
135
136   bool        myIsModified;
137   QList<int>  myRemovedRows;
138   VariableMap myVariableMapRef;
139   VariableMap myVariableMap;
140
141   _PTR(Study)      myStudy;
142 };
143
144 class SALOMEAPP_EXPORT SalomeApp_NoteBook : public QWidget 
145 {
146   Q_OBJECT
147  public:
148   SalomeApp_NoteBook(QWidget * parent , _PTR(Study) theStudy);
149   virtual ~SalomeApp_NoteBook();
150
151   void Init(_PTR(Study) theStudy);
152
153   QString getDumpedStudyName() { return myDumpedStudyName; }
154   void setDumpedStudyName(QString theName) { myDumpedStudyName = theName; }
155   
156   QString getDumpedStudyScript() { return myDumpedStudyScript; }
157   void setDumpedStudyScript(QString theScript) { myDumpedStudyScript = theScript; }
158
159   bool isDumpedStudySaved() { return myIsDumpedStudySaved; }
160   void setIsDumpedStudySaved(bool isSaved) { myIsDumpedStudySaved = isSaved; }
161   
162  public slots:
163    void onApply();
164    void onRemove();
165    void onUpdateStudy();
166    void onVarUpdate( QString theVarName );
167
168  private:
169   NoteBook_Table*  myTable;
170   QPushButton*     myRemoveButton;
171   QPushButton*     myUpdateStudyBtn;
172   
173   _PTR(Study)      myStudy;
174   QString          myDumpedStudyScript; // path to script of dumped study
175   QString          myDumpedStudyName;
176   bool             myIsDumpedStudySaved;
177 };
178
179 #endif //SALOMEAPP_NOTEBOOK_H