Salome HOME
Extending the modification mode for a lot of sections.
[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 #include <Geom_Curve.hxx>
34 #include <V3d_View.hxx>
35 #include <gp_Pnt.hxx>
36
37 class OCCViewer_Viewer;
38
39 class QAction;
40 class QPixmap;
41 class QTableWidget;
42 class CurveCreator_ICurve;
43 class CurveCreator_TreeView;
44 class CurveCreator_NewPointDlg;
45 class CurveCreator_NewSectionDlg;
46
47 class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget
48 {
49   Q_OBJECT
50 public:
51   explicit CurveCreator_Widget( QWidget* parent,
52                                 CurveCreator_ICurve *theCurve,
53                                 Qt::WindowFlags fl=0 );
54
55   void setOCCViewer( OCCViewer_Viewer* theViewer );
56   OCCViewer_Viewer* getOCCViewer();
57
58   //virtual bool eventFilter( QObject* theWatched, QEvent* theEvent );
59
60   //! Return unique section name
61   std::string getUniqSectionName(CurveCreator_ICurve* theCurve) const;
62
63   void setCurve( CurveCreator_ICurve* theCurve );
64
65   QList<int> getSelectedSections();
66   QList< QPair< int, int > > getSelectedPoints();
67
68 signals:
69   void selectionChanged();
70   void subOperationStarted( QWidget* );
71   void subOperationFinished( QWidget* );
72
73 public slots:
74
75 protected slots:
76   void     onAdditionMode(bool checked);
77   void     onModificationMode(bool checked);
78   void     onDetectionMode(bool checked);
79   void     onModeChanged(bool checked);
80   void     onNewSection();
81   void     onSelectionChanged();
82   void     onAddNewPoint(const CurveCreator::Coordinates& theCoords);
83   void     onAddNewSection();
84   void     onEditSection( int theSection );
85   void     onModifySection();
86   void     onCancelSection();
87   void     onJoin();
88   void     onRemove();
89   void     onClearAll();
90   void     onJoinAll();
91   void     onSetSpline();
92   void     onSetPolyline();
93   void     onCloseSections();
94   void     onUncloseSections();
95   void     onUndo();
96   void     onRedo();
97   void     onUndoSettings();
98   void     onContextMenu(QPoint thePoint);
99   void     onGetCoordsByClick( QMouseEvent* );
100
101   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
102   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
103   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
104
105   void     onCellChanged( int theRow, int theColumn );
106
107 protected:
108   enum ActionId{ UNDO_ID, 
109                  REDO_ID, 
110                  NEW_SECTION_ID, 
111                  ADDITION_MODE_ID, 
112                  REMOVE_ID, 
113                  REMOVE_ALL_ID, 
114                  JOIN_ID,
115                  JOIN_ALL_ID, 
116                  CLOSE_SECTIONS_ID, 
117                  UNCLOSE_SECTIONS_ID,
118                  SET_SECTIONS_POLYLINE_ID, 
119                  SET_SECTIONS_SPLINE_ID, 
120                  CLEAR_ALL_ID, 
121                  SEPARATOR_ID, 
122                  MODIFICATION_MODE_ID, 
123                  DETECTION_MODE_ID 
124   };
125
126   enum ActionMode {
127     NoneMode,
128     AdditionMode,
129     ModificationMode,
130     DetectionMode
131   };
132
133   typedef QPair< int, int > SectionToPoint;
134   typedef QList< SectionToPoint > SectionToPointList;
135
136 private:
137   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
138                          const QString& theToolTip, const QKeySequence& theShortcut );
139   QAction* getAction(ActionId theId);
140   ActionMode getActionMode() const;
141
142   void     updateUndoRedo();
143
144   void removeSection();
145   void removePoint();
146   void insertPointToSelectedSegment( const int theXPosition,
147                                      const int theYPosition );
148   void moveSelectedPoints( const int theXPosition, const int theYPosition );
149   void updateLocalPointView();
150   void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false );
151   void addLocalPointToTable( const double theX, const double theY );
152
153   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
154
155   void getSelectedPonts( SectionToPointList& thePoints );
156   void setSelectedPonts( const SectionToPointList& = SectionToPointList() );
157
158   void startCurveModification( SectionToPointList& thePoints,
159                                const bool theFillPoints = true );
160   void finishCurveModification( const SectionToPointList& thePoints );
161
162   // curve algorithm
163   int  findLocalPointIndex( int theSectionId, float theX, float theY );
164   void findSectionsToPoints( const double theX, const double theY,
165                              SectionToPointList& thePoints );
166   void convert( const SectionToPointList& thePoints,
167                 QMap<int, QList<int> >& theConvPoints );
168
169   // OCC algorithm
170   bool pointOnObject( Handle(AIS_InteractiveObject) theObject,
171                       const int theX, const int theY,
172                       gp_Pnt& thePoint, gp_Pnt& thePoint1, gp_Pnt& thePoint2 );
173   bool hasProjectPointOnCurve( const int theX, const int theY,
174                                const Handle(Geom_Curve)& theCurve,
175                                Standard_Real& theParameter );
176
177   // local point view table methods
178   int getSectionId( const int theRowId ) const;
179   int getPointId( const int theRowId ) const;
180
181 private:
182   QMap<ActionId, QAction*>    myActionMap;
183   CurveCreator_ICurve*         myCurve;
184   CurveCreator_TreeView*      mySectionView;
185   QTableWidget*               myLocalPointView;
186   CurveCreator_NewSectionDlg* myNewSectionEditor;
187   OCCViewer_Viewer*           myOCCViewer;
188   int                         mySection;
189   int                         myPointNum;
190   bool                        myDragStarted;
191   QPoint                      myDragStartPosition;
192   int                         myDragInteractionStyle;
193   SectionToPointList          myDragPoints;
194   bool                        myDragged;
195   QByteArray                  myGuiState;
196 };
197
198 #endif // CURVECREATOR_WIDGET_H