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