Salome HOME
refs #1373 comment out the limit of selected points in the local-point-list
[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
76   // OCC viewer manipulation
77   void setOCCViewer( OCCViewer_Viewer* theViewer );
78
79   Handle(AIS_InteractiveContext) getAISContext();
80   OCCViewer_ViewPort3d* getViewPort();
81   int changeInteractionStyle( int theStyle );
82
83   void reset();
84   void setCurve( CurveCreator_ICurve* theCurve );
85
86   QList<int> getSelectedSections();
87   void setSelectedSections( const QList<int>& theSections );
88
89   void  removeSelected();
90   bool  removeEnabled();
91
92   void setActionMode( const ActionMode& theMode );
93   ActionMode getActionMode() const;
94
95   void SetViewer2DMode(const bool To2D);
96
97   void setSelectedPoints( const CurveCreator_ICurve::SectionToPointList& =
98                                CurveCreator_ICurve::SectionToPointList() );
99
100   void updateLocalPointView();
101   void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false );
102
103 signals:
104   void selectionChanged();
105   void subOperationStarted( QWidget*, bool );
106   void subOperationFinished( QWidget* );
107
108 public slots:
109   void     onAdditionMode(bool checked);
110   void     onModificationMode(bool checked);
111   void     onDetectionMode(bool checked);
112   void     onModeChanged(bool checked);
113   void     onNewSection();
114   void     onSelectionChanged();
115   void     onAddNewSection();
116   void     onEditSection( int theSection );
117   void     onModifySection();
118   void     onCancelSection();
119   void     onJoin();
120   void     onBringTogether();
121   void     onRemove();
122   void     onClearAll();
123   void     onJoinAll();
124   void     onSetSpline();
125   void     onSetPolyline();
126   void     onCloseSections();
127   void     onUncloseSections();
128   void     onUndo();
129   void     onRedo();
130   void     onUndoSettings();
131   void     onContextMenu(QPoint thePoint);
132
133   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
134   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
135   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
136   void     onLastViewClosed( SUIT_ViewManager* theManager );
137
138   void     onMousePress( QMouseEvent* theEvent );
139   void     onMouseRelease( QMouseEvent* theEvent );
140   void     onMouseMove( QMouseEvent* theEvent );
141
142   void     onCellChanged( int theRow, int theColumn );
143
144 protected:
145   void     addCoordsByClick( QMouseEvent* );
146
147 protected:
148   enum ActionId{ NONE_ID,
149                  UNDO_ID, 
150                  REDO_ID, 
151                  NEW_SECTION_ID, 
152                  ADDITION_MODE_ID, 
153                  REMOVE_ID, 
154                  REMOVE_ALL_ID, 
155                  JOIN_ID,
156                  JOIN_ALL_ID, 
157                  CLOSE_SECTIONS_ID, 
158                  UNCLOSE_SECTIONS_ID,
159                  SET_SECTIONS_POLYLINE_ID, 
160                  SET_SECTIONS_SPLINE_ID, 
161                  CLEAR_ALL_ID, 
162                  SEPARATOR_ID, 
163                  MODIFICATION_MODE_ID, 
164                  DETECTION_MODE_ID,
165                  BRING_TOGETHER_ID
166   };
167
168 public:
169   QAction* getAction(ActionId theId);
170   QAction* getAction(ActionMode theMode);
171
172 private:
173   OCCViewer_Viewer* getOCCViewer();
174
175   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
176                          const QString& theToolTip, const QKeySequence& theShortcut );
177
178   void updateActionsStates();
179   void updateUndoRedo();
180
181   void removeSection();
182   void removePoint();
183   void addNewPoint(const CurveCreator::Coordinates& theCoords);
184   void insertPointToSelectedSegment( const int theXPosition,
185                                      const int theYPosition );
186   void moveSelectedPoints( const int theXPosition, const int theYPosition );
187
188   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
189
190   void getSelectedPoints( CurveCreator_ICurve::SectionToPointList& thePoints );
191
192   void stopActionMode();
193
194   void startCurveModification( CurveCreator_ICurve::SectionToPointList& thePoints,
195                                const bool theFillPoints = true );
196   void finishCurveModification( const CurveCreator_ICurve::SectionToPointList& thePoints = 
197                                       CurveCreator_ICurve::SectionToPointList() );
198
199   // curve algorithm
200   int  findLocalPointIndex( int theSectionId, double theX, double theY );
201   void findSectionsToPoints( const double theX, const double theY,
202                              CurveCreator_ICurve::SectionToPointList& thePoints );
203   void convert( const CurveCreator_ICurve::SectionToPointList& thePoints,
204                 QMap<int, QList<int> >& theConvPoints );
205
206   bool contains( const CurveCreator_ICurve::SectionToPointList& theList,
207                  const CurveCreator_ICurve::SectionToPoint& theValue ) const;
208
209 protected:
210   // Boundary points of mouse to select the points
211   QPoint myStartPoint;
212   QPoint myEndPoint;
213
214 private:
215   QMap<ActionId, QAction*>    myActionMap;
216   CurveCreator_ICurve*        myCurve;
217   CurveCreator_TreeView*      mySectionView;
218   CurveCreator_TableView*     myLocalPointView;
219   CurveCreator_ICurve::SectionToPointList myLocalPoints;
220   CurveCreator_NewSectionDlg* myNewSectionEditor;
221   OCCViewer_Viewer*           myOCCViewer;
222   int                         myLocalPointRowLimit;
223   int                         mySection;
224   int                         myPointNum;
225   bool                        myDragStarted;
226   QPoint                      myDragStartPosition;
227   int                         myDragInteractionStyle;
228   CurveCreator_ICurve::SectionToPointList myDragPoints;
229   QMap<CurveCreator_ICurve::SectionToPoint, CurveCreator::Coordinates> myInitialDragPointsCoords;
230   bool                        myDragged;
231   QByteArray                  myGuiState;
232   OCCViewer_ViewWindow::Mode2dType myOld2DMode;
233 };
234
235 #endif // CURVECREATOR_WIDGET_H