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