Salome HOME
Minor changes.
[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_Macro.hxx"
24 #include "CurveCreator.hxx"
25 #include "CurveCreator_ICurve.hxx"
26
27 #include <QWidget>
28 #include <QMap>
29
30 #include <SUIT_ViewWindow.h>
31 #include <AIS_InteractiveObject.hxx>
32 #include <AIS_InteractiveContext.hxx>
33
34 #include <Geom_Curve.hxx>
35 #include <V3d_View.hxx>
36 #include <gp_Pnt.hxx>
37 #include <TopoDS_Vertex.hxx> // TODO - remove
38
39 class OCCViewer_Viewer;
40 class OCCViewer_ViewPort3d;
41
42 class AIS_ListOfInteractive;
43
44 class QAction;
45 class QPixmap;
46 class CurveCreator_TableView;
47 class CurveCreator_TreeView;
48 class CurveCreator_NewPointDlg;
49 class CurveCreator_NewSectionDlg;
50
51 class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget
52 {
53   Q_OBJECT
54
55 public:
56   enum ActionFlags {
57     NoFlags              = 0x00000000,
58     DisableDetectionMode = 0x00000001,
59     DisableNewSection    = 0x00000002,
60     DisableClosedSection = 0x00000004
61   };
62
63   enum ActionMode {
64     NoneMode,
65     AdditionMode,
66     ModificationMode,
67     DetectionMode
68   };
69
70 public:
71   explicit CurveCreator_Widget( QWidget* parent,
72                                 CurveCreator_ICurve *theCurve,
73                                 const int theActionFlags = NoFlags,
74                                 const QStringList& theCoordTitles = QStringList(),
75                                 Qt::WindowFlags fl=0,
76                                 int theLocalPointRowLimit = 20);
77
78   // OCC viewer manipulation
79   void setOCCViewer( OCCViewer_Viewer* theViewer );
80
81   Handle(AIS_InteractiveContext) getAISContext();
82   OCCViewer_ViewPort3d* getViewPort();
83   int changeInteractionStyle( int theStyle );
84
85   void reset();
86   void setCurve( CurveCreator_ICurve* theCurve );
87
88   QList<int> getSelectedSections();
89   void setSelectedSections( const QList<int>& theSections );
90
91   void  removeSelected();
92   bool  removeEnabled();
93
94   void setActionMode( const ActionMode& theMode );
95   ActionMode getActionMode() const;
96
97 signals:
98   void selectionChanged();
99   void subOperationStarted( QWidget*, bool );
100   void subOperationFinished( QWidget* );
101
102 public slots:
103
104 protected slots:
105   void     onAdditionMode(bool checked);
106   void     onModificationMode(bool checked);
107   void     onDetectionMode(bool checked);
108   void     onModeChanged(bool checked);
109   void     onNewSection();
110   void     onSelectionChanged();
111   void     onAddNewSection();
112   void     onEditSection( int theSection );
113   void     onModifySection();
114   void     onCancelSection();
115   void     onJoin();
116   void     onRemove();
117   void     onClearAll();
118   void     onJoinAll();
119   void     onSetSpline();
120   void     onSetPolyline();
121   void     onCloseSections();
122   void     onUncloseSections();
123   void     onUndo();
124   void     onRedo();
125   void     onUndoSettings();
126   void     onContextMenu(QPoint thePoint);
127
128   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
129   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
130   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
131   void     onLastViewClosed( SUIT_ViewManager* theManager );
132
133   void     onMousePress( QMouseEvent* theEvent );
134   void     onMouseRelease( QMouseEvent* theEvent );
135   void     onMouseMove( QMouseEvent* theEvent );
136
137   void     onCellChanged( int theRow, int theColumn );
138
139 protected:
140   void     addCoordsByClick( QMouseEvent* );
141
142 protected:
143   enum ActionId{ NONE_ID,
144                  UNDO_ID, 
145                  REDO_ID, 
146                  NEW_SECTION_ID, 
147                  ADDITION_MODE_ID, 
148                  REMOVE_ID, 
149                  REMOVE_ALL_ID, 
150                  JOIN_ID,
151                  JOIN_ALL_ID, 
152                  CLOSE_SECTIONS_ID, 
153                  UNCLOSE_SECTIONS_ID,
154                  SET_SECTIONS_POLYLINE_ID, 
155                  SET_SECTIONS_SPLINE_ID, 
156                  CLEAR_ALL_ID, 
157                  SEPARATOR_ID, 
158                  MODIFICATION_MODE_ID, 
159                  DETECTION_MODE_ID 
160   };
161
162 private:
163   OCCViewer_Viewer* getOCCViewer();
164
165   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
166                          const QString& theToolTip, const QKeySequence& theShortcut );
167   QAction* getAction(ActionId theId);
168   QAction* getAction(ActionMode theMode);
169
170   void updateActionsStates();
171   void updateUndoRedo();
172
173   void removeSection();
174   void removePoint();
175   void addNewPoint(const CurveCreator::Coordinates& theCoords);
176   void insertPointToSelectedSegment( const int theXPosition,
177                                      const int theYPosition );
178   void moveSelectedPoints( const int theXPosition, const int theYPosition );
179   void updateLocalPointView();
180   void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false );
181
182   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
183
184   void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints );
185   void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& =
186                                CurveCreator_ICurve::SectionToPointList() );
187
188   void stopActionMode();
189
190   void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints,
191                                const bool theFillPoints = true );
192   void finishCurveModification( const CurveCreator_ICurve::SectionToPointList& thePoints = 
193                                       CurveCreator_ICurve::SectionToPointList() );
194
195   // curve algorithm
196   int  findLocalPointIndex( int theSectionId, float theX, float theY );
197   void findSectionsToPoints( const double theX, const double theY,
198                              CurveCreator_ICurve::SectionToPointList& thePoints );
199   void convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
200                 QMap<int, QList<int> >& theConvPoints );
201
202   bool contains( const CurveCreator_ICurve::SectionToPointList& theList,
203                  const CurveCreator_ICurve::SectionToPoint& theValue ) const;
204
205 private:
206   QMap<ActionId, QAction*>    myActionMap;
207   CurveCreator_ICurve*        myCurve;
208   CurveCreator_TreeView*      mySectionView;
209   CurveCreator_TableView*     myLocalPointView;
210   CurveCreator_ICurve::SectionToPointList myLocalPoints;
211   CurveCreator_NewSectionDlg* myNewSectionEditor;
212   OCCViewer_Viewer*           myOCCViewer;
213   int                         myLocalPointRowLimit;
214   int                         mySection;
215   int                         myPointNum;
216   bool                        myDragStarted;
217   QPoint                      myDragStartPosition;
218   int                         myDragInteractionStyle;
219   CurveCreator_ICurve::SectionToPointList myDragPoints;
220   QMap<CurveCreator_ICurve::SectionToPoint, CurveCreator::Coordinates> myInitialDragPointsCoords;
221   bool                        myDragged;
222   QByteArray                  myGuiState;
223   int                         myPressedX;
224   int                         myPressedY;
225 };
226
227 #endif // CURVECREATOR_WIDGET_H