Salome HOME
Bug #183: regression: polyline - unnecessary table in Additition mode.
[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   };
61
62 public:
63   explicit CurveCreator_Widget( QWidget* parent,
64                                 CurveCreator_ICurve *theCurve,
65                                 const int theActionFlags = NoFlags,
66                                 Qt::WindowFlags fl=0,
67                                 int theLocalPointRowLimit = 20);
68
69   // OCC viewer manipulation
70   void setOCCViewer( OCCViewer_Viewer* theViewer );
71
72   Handle(AIS_InteractiveContext) getAISContext();
73   OCCViewer_ViewPort3d* getViewPort();
74   int changeInteractionStyle( int theStyle );
75
76   void reset();
77   void setCurve( CurveCreator_ICurve* theCurve );
78
79   QList<int> getSelectedSections();
80   QList< QPair< int, int > > getSelectedPoints();
81
82   void  removeSelected();
83   bool  removeEnabled();
84
85 signals:
86   void selectionChanged();
87   void subOperationStarted( QWidget* );
88   void subOperationFinished( QWidget* );
89
90 public slots:
91
92 protected slots:
93   void     onAdditionMode(bool checked);
94   void     onModificationMode(bool checked);
95   void     onDetectionMode(bool checked);
96   void     onModeChanged(bool checked);
97   void     onNewSection();
98   void     onSelectionChanged();
99   void     onAddNewSection();
100   void     onEditSection( int theSection );
101   void     onModifySection();
102   void     onCancelSection();
103   void     onJoin();
104   void     onRemove();
105   void     onClearAll();
106   void     onJoinAll();
107   void     onSetSpline();
108   void     onSetPolyline();
109   void     onCloseSections();
110   void     onUncloseSections();
111   void     onUndo();
112   void     onRedo();
113   void     onUndoSettings();
114   void     onContextMenu(QPoint thePoint);
115
116   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
117   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
118   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
119   void     onLastViewClosed( SUIT_ViewManager* theManager );
120
121   void     onMousePress( QMouseEvent* theEvent );
122   void     onMouseRelease( QMouseEvent* theEvent );
123   void     onMouseMove( QMouseEvent* theEvent );
124
125   void     onCellChanged( int theRow, int theColumn );
126
127 protected:
128   void     addCoordsByClick( QMouseEvent* );
129
130 protected:
131   enum ActionId{ UNDO_ID, 
132                  REDO_ID, 
133                  NEW_SECTION_ID, 
134                  ADDITION_MODE_ID, 
135                  REMOVE_ID, 
136                  REMOVE_ALL_ID, 
137                  JOIN_ID,
138                  JOIN_ALL_ID, 
139                  CLOSE_SECTIONS_ID, 
140                  UNCLOSE_SECTIONS_ID,
141                  SET_SECTIONS_POLYLINE_ID, 
142                  SET_SECTIONS_SPLINE_ID, 
143                  CLEAR_ALL_ID, 
144                  SEPARATOR_ID, 
145                  MODIFICATION_MODE_ID, 
146                  DETECTION_MODE_ID 
147   };
148
149   enum ActionMode {
150     NoneMode,
151     AdditionMode,
152     ModificationMode,
153     DetectionMode
154   };
155
156 private:
157   OCCViewer_Viewer* getOCCViewer();
158
159   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
160                          const QString& theToolTip, const QKeySequence& theShortcut );
161   QAction* getAction(ActionId theId);
162   ActionMode getActionMode() const;
163
164   void updateActionsStates();
165   void updateUndoRedo();
166
167   void removeSection();
168   void removePoint();
169   void addNewPoint(const CurveCreator::Coordinates& theCoords);
170   void insertPointToSelectedSegment( const int theXPosition,
171                                      const int theYPosition );
172   void moveSelectedPoints( const int theXPosition, const int theYPosition );
173   void updateLocalPointView();
174   void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false );
175
176   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
177
178   void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints );
179   void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& =
180                                CurveCreator_ICurve::SectionToPointList() );
181
182   void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints,
183                                const bool theFillPoints = true );
184   void finishCurveModification( const CurveCreator_ICurve::SectionToPointList& thePoints = 
185                                       CurveCreator_ICurve::SectionToPointList() );
186
187   // curve algorithm
188   int  findLocalPointIndex( int theSectionId, float theX, float theY );
189   void findSectionsToPoints( const double theX, const double theY,
190                              CurveCreator_ICurve::SectionToPointList& thePoints );
191   void convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
192                 QMap<int, QList<int> >& theConvPoints );
193
194   bool contains( const CurveCreator_ICurve::SectionToPointList& theList,
195                  const CurveCreator_ICurve::SectionToPoint& theValue ) const;
196
197 private:
198   QMap<ActionId, QAction*>    myActionMap;
199   CurveCreator_ICurve*        myCurve;
200   CurveCreator_TreeView*      mySectionView;
201   CurveCreator_TableView*     myLocalPointView;
202   CurveCreator_ICurve::SectionToPointList myLocalPoints;
203   CurveCreator_NewSectionDlg* myNewSectionEditor;
204   OCCViewer_Viewer*           myOCCViewer;
205   int                         myLocalPointRowLimit;
206   int                         mySection;
207   int                         myPointNum;
208   bool                        myDragStarted;
209   QPoint                      myDragStartPosition;
210   int                         myDragInteractionStyle;
211   CurveCreator_ICurve::SectionToPointList myDragPoints;
212   bool                        myDragged;
213   QByteArray                  myGuiState;
214 };
215
216 #endif // CURVECREATOR_WIDGET_H