Salome HOME
Migration to OCCT 7.0
[modules/geom.git] / src / CurveCreator / CurveCreator_Widget.h
1 // Copyright (C) 2013-2016  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, or (at your option) any later version.
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 <SUIT_ViewWindow.h>
28 #include <OCCViewer_ViewWindow.h>
29
30 #include <AIS_InteractiveObject.hxx>
31 #include <AIS_InteractiveContext.hxx>
32 #include <AIS_ListOfInteractive.hxx>
33 #include <Geom_Curve.hxx>
34 #include <V3d_View.hxx>
35 #include <gp_Pnt.hxx>
36
37 #include <QWidget>
38 #include <QMap>
39
40 class CurveCreator_TableView;
41 class CurveCreator_TreeView;
42 class CurveCreator_NewSectionDlg;
43
44 class OCCViewer_Viewer;
45 class OCCViewer_ViewPort3d;
46
47 class QAction;
48 class QPixmap;
49
50 class CURVECREATOR_EXPORT CurveCreator_Widget : public QWidget
51 {
52   Q_OBJECT
53
54 public:
55   enum ActionFlags {
56     NoFlags              = 0x00000000,
57     DisableDetectionMode = 0x00000001,
58     DisableNewSection    = 0x00000002,
59     DisableClosedSection = 0x00000004
60   };
61
62   enum ActionMode {
63     NoneMode,
64     AdditionMode,
65     ModificationMode,
66     DetectionMode
67   };
68
69 public:
70   explicit CurveCreator_Widget( QWidget* parent,
71                                 CurveCreator_ICurve *theCurve,
72                                 const int theActionFlags = NoFlags,
73                                 const QStringList& theCoordTitles = QStringList(),
74                                 Qt::WindowFlags fl=0,
75                                 int theLocalPointRowLimit = 20);
76
77   // OCC viewer manipulation
78   void setOCCViewer( OCCViewer_Viewer* theViewer );
79
80   Handle(AIS_InteractiveContext) getAISContext();
81   OCCViewer_ViewPort3d* getViewPort();
82   int changeInteractionStyle( int theStyle );
83
84   void reset();
85   void setCurve( CurveCreator_ICurve* theCurve );
86
87   QList<int> getSelectedSections();
88   void setSelectedSections( const QList<int>& theSections );
89
90   void  removeSelected();
91   bool  removeEnabled();
92
93   void setActionMode( const ActionMode& theMode );
94   ActionMode getActionMode() const;
95
96   void SetViewer2DMode(const bool To2D);
97
98 signals:
99   void selectionChanged();
100   void subOperationStarted( QWidget*, bool );
101   void subOperationFinished( QWidget* );
102
103 public slots:
104
105 protected slots:
106   void     onAdditionMode(bool checked);
107   void     onModificationMode(bool checked);
108   void     onDetectionMode(bool checked);
109   void     onModeChanged(bool checked);
110   void     onNewSection();
111   void     onSelectionChanged();
112   void     onAddNewSection();
113   void     onEditSection( int theSection );
114   void     onModifySection();
115   void     onCancelSection();
116   void     onJoin();
117   void     onRemove();
118   void     onClearAll();
119   void     onJoinAll();
120   void     onSetSpline();
121   void     onSetPolyline();
122   void     onCloseSections();
123   void     onUncloseSections();
124   void     onUndo();
125   void     onRedo();
126   void     onUndoSettings();
127   void     onContextMenu(QPoint thePoint);
128
129   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
130   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
131   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
132   void     onLastViewClosed( SUIT_ViewManager* theManager );
133
134   void     onMousePress( QMouseEvent* theEvent );
135   void     onMouseRelease( QMouseEvent* theEvent );
136   void     onMouseMove( QMouseEvent* theEvent );
137
138   void     onCellChanged( int theRow, int theColumn );
139
140 protected:
141   void     addCoordsByClick( QMouseEvent* );
142
143 protected:
144   enum ActionId{ NONE_ID,
145                  UNDO_ID, 
146                  REDO_ID, 
147                  NEW_SECTION_ID, 
148                  ADDITION_MODE_ID, 
149                  REMOVE_ID, 
150                  REMOVE_ALL_ID, 
151                  JOIN_ID,
152                  JOIN_ALL_ID, 
153                  CLOSE_SECTIONS_ID, 
154                  UNCLOSE_SECTIONS_ID,
155                  SET_SECTIONS_POLYLINE_ID, 
156                  SET_SECTIONS_SPLINE_ID, 
157                  CLEAR_ALL_ID, 
158                  SEPARATOR_ID, 
159                  MODIFICATION_MODE_ID, 
160                  DETECTION_MODE_ID 
161   };
162
163 private:
164   OCCViewer_Viewer* getOCCViewer();
165
166   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
167                          const QString& theToolTip, const QKeySequence& theShortcut );
168   QAction* getAction(ActionId theId);
169   QAction* getAction(ActionMode theMode);
170
171   void updateActionsStates();
172   void updateUndoRedo();
173
174   void removeSection();
175   void removePoint();
176   void addNewPoint(const CurveCreator::Coordinates& theCoords);
177   void insertPointToSelectedSegment( const int theXPosition,
178                                      const int theYPosition );
179   void moveSelectedPoints( const int theXPosition, const int theYPosition );
180   void updateLocalPointView();
181   void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false );
182
183   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
184
185   void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints );
186   void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& =
187                                CurveCreator_ICurve::SectionToPointList() );
188
189   void stopActionMode();
190
191   void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints,
192                                const bool theFillPoints = true );
193   void finishCurveModification( const CurveCreator_ICurve::SectionToPointList& thePoints = 
194                                       CurveCreator_ICurve::SectionToPointList() );
195
196   // curve algorithm
197   int  findLocalPointIndex( int theSectionId, double theX, double theY );
198   void findSectionsToPoints( const double theX, const double theY,
199                              CurveCreator_ICurve::SectionToPointList& thePoints );
200   void convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
201                 QMap<int, QList<int> >& theConvPoints );
202
203   bool contains( const CurveCreator_ICurve::SectionToPointList& theList,
204                  const CurveCreator_ICurve::SectionToPoint& theValue ) const;
205
206 protected:
207   // Boundary points of mouse to select the points
208   QPoint myStartPoint;
209   QPoint myEndPoint;
210
211 private:
212   QMap<ActionId, QAction*>    myActionMap;
213   CurveCreator_ICurve*        myCurve;
214   CurveCreator_TreeView*      mySectionView;
215   CurveCreator_TableView*     myLocalPointView;
216   CurveCreator_ICurve::SectionToPointList myLocalPoints;
217   CurveCreator_NewSectionDlg* myNewSectionEditor;
218   OCCViewer_Viewer*           myOCCViewer;
219   int                         myLocalPointRowLimit;
220   int                         mySection;
221   int                         myPointNum;
222   bool                        myDragStarted;
223   QPoint                      myDragStartPosition;
224   int                         myDragInteractionStyle;
225   CurveCreator_ICurve::SectionToPointList myDragPoints;
226   QMap<CurveCreator_ICurve::SectionToPoint, CurveCreator::Coordinates> myInitialDragPointsCoords;
227   bool                        myDragged;
228   QByteArray                  myGuiState;
229   OCCViewer_ViewWindow::Mode2dType myOld2DMode;
230 };
231
232 #endif // CURVECREATOR_WIDGET_H