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