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