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