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