]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROCurveCreator/CurveCreator_Widget.h
Salome HOME
bbc58f69476e2420b5c202a6229ef57848b1ae59
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.h
1 // Copyright (C) 2013  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.
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 #ifndef CURVECREATOR_WIDGET_H
21 #define CURVECREATOR_WIDGET_H
22
23 //#include "CurveCreator_ICurve.hxx"
24 #include "CurveCreator.hxx"
25 #include "CurveCreator_Macro.hxx"
26
27 #include <QWidget>
28 #include <QMap>
29
30 #include <SUIT_ViewWindow.h>
31 #include <AIS_InteractiveObject.hxx>
32
33 class OCCViewer_Viewer;
34
35 class QAction;
36 class QPixmap;
37 class QTableWidget;
38 class CurveCreator_ICurve;
39 class CurveCreator_TreeView;
40 class CurveCreator_NewPointDlg;
41 class CurveCreator_NewSectionDlg;
42
43 class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget
44 {
45   Q_OBJECT
46 public:
47   explicit CurveCreator_Widget( QWidget* parent,
48                                 CurveCreator_ICurve *theCurve,
49                                 Qt::WindowFlags fl=0 );
50
51   void setOCCViewer( OCCViewer_Viewer* theViewer );
52   OCCViewer_Viewer* getOCCViewer();
53
54   //virtual bool eventFilter( QObject* theWatched, QEvent* theEvent );
55
56   //! Return unique section name
57   std::string getUniqSectionName(CurveCreator_ICurve* theCurve) const;
58
59   void setCurve( CurveCreator_ICurve* theCurve );
60
61   QList<int> getSelectedSections();
62   QList< QPair< int, int > > getSelectedPoints();
63
64 signals:
65   void selectionChanged();
66   void subOperationStarted( QWidget* );
67   void subOperationFinished( QWidget* );
68
69 public slots:
70
71 protected slots:
72   void     onAdditionMode(bool checked);
73   void     onModificationMode(bool checked);
74   void     onDetectionMode(bool checked);
75   void     onModeChanged(bool checked);
76   void     onNewSection();
77   void     onSelectionChanged();
78   void     onAddNewPoint(const CurveCreator::Coordinates& theCoords);
79   void     onAddNewSection();
80   void     onEditSection( int theSection );
81   void     onModifySection();
82   void     onCancelSection();
83   void     onJoin();
84   void     onRemove();
85   void     onClearAll();
86   void     onJoinAll();
87   void     onSetSpline();
88   void     onSetPolyline();
89   void     onCloseSections();
90   void     onUncloseSections();
91   void     onUndo();
92   void     onRedo();
93   void     onUndoSettings();
94   void     onContextMenu(QPoint thePoint);
95   void     onGetCoordsByClick( QMouseEvent* );
96
97   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
98   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
99   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
100
101   void     onLocalPointChanged( int theRow, int theColumn );
102
103 protected:
104   enum ActionId{ UNDO_ID, 
105                  REDO_ID, 
106                  NEW_SECTION_ID, 
107                  ADDITION_MODE_ID, 
108                  REMOVE_ID, 
109                  REMOVE_ALL_ID, 
110                  JOIN_ID,
111                  JOIN_ALL_ID, 
112                  CLOSE_SECTIONS_ID, 
113                  UNCLOSE_SECTIONS_ID,
114                  SET_SECTIONS_POLYLINE_ID, 
115                  SET_SECTIONS_SPLINE_ID, 
116                  CLEAR_ALL_ID, 
117                  SEPARATOR_ID, 
118                  MODIFICATION_MODE_ID, 
119                  DETECTION_MODE_ID 
120   };
121
122   enum ActionMode {
123     AdditionMode,
124     ModificationMode,
125     DetectionMode,
126     NoneMode
127   };
128
129 private:
130   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
131                          const QString& theToolTip, const QKeySequence& theShortcut );
132   QAction* getAction(ActionId theId);
133   ActionMode getActionMode() const;
134
135   void     updateUndoRedo();
136
137   void removeSection();
138   void removePoint();
139   bool insertPointToSelectedSegment( const int theXPosition,
140                                      const int theYPosition );
141   void updateLocalPointView();
142   void setLocalPointContext( const bool theOpen );
143   void addLocalPointToTable( const double theX, const double theY );
144
145   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
146
147   void getSelectedPonts( const int theSectionId, QList<int>& thePoints );
148   void setSelectedPonts( const int theSectionId, const QList<int>& thePoints = QList<int>() );
149
150
151   // curve algorithm
152   int  findLocalPointIndex( int theSectionId, float theX, float theY );
153
154   // OCC algorithm
155   bool pointOnObject( Handle(AIS_InteractiveObject) theObject,
156                       const int theX, const int theY,
157                       gp_Pnt& thePoint, int& thePoint1, int& thePoint2 );
158
159 private:
160   QMap<ActionId, QAction*>    myActionMap;
161   CurveCreator_ICurve*         myCurve;
162   CurveCreator_TreeView*      mySectionView;
163   QTableWidget*               myLocalPointView;
164   CurveCreator_NewSectionDlg* myNewSectionEditor;
165   OCCViewer_Viewer*           myOCCViewer;
166   int                         mySection;
167   int                         myPointNum;
168   bool                        myDragStarted;
169   QList<int>                  myDragPoints;
170   QPoint                      myDragStartPosition;
171   QByteArray                  myGuiState;
172 };
173
174 #endif // CURVECREATOR_WIDGET_H