Salome HOME
Remove OCCViewer_ViewWidget
[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_ICurve.hxx"
24 #include "CurveCreator.hxx"
25 #include "CurveCreator_Macro.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
38 class OCCViewer_Viewer;
39 class OCCViewer_ViewPort3d;
40
41 class AIS_ListOfInteractive;
42
43 class QAction;
44 class QPixmap;
45 class QTableWidget;
46 class CurveCreator_ICurve;
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
59   // OCC viewer manipulation
60   void setOCCViewer( OCCViewer_Viewer* theViewer );
61
62   Handle(AIS_InteractiveContext) getAISContext();
63   OCCViewer_ViewPort3d* getViewPort();
64   int changeInteractionStyle( int theStyle );
65   void setObjectsSelected(const AIS_ListOfInteractive& theList);
66
67   void reset();
68
69   //! Return unique section name
70   std::string getUniqSectionName(CurveCreator_ICurve* theCurve) const;
71
72   void setCurve( CurveCreator_ICurve* theCurve );
73
74   QList<int> getSelectedSections();
75   QList< QPair< int, int > > getSelectedPoints();
76
77   void  removeSelected();
78   bool  removeEnabled();
79
80 signals:
81   void selectionChanged();
82   void subOperationStarted( QWidget* );
83   void subOperationFinished( QWidget* );
84
85 public slots:
86
87 protected slots:
88   void     onAdditionMode(bool checked);
89   void     onModificationMode(bool checked);
90   void     onDetectionMode(bool checked);
91   void     onModeChanged(bool checked);
92   void     onNewSection();
93   void     onSelectionChanged();
94   void     onAddNewPoint(const CurveCreator::Coordinates& theCoords);
95   void     onAddNewSection();
96   void     onEditSection( int theSection );
97   void     onModifySection();
98   void     onCancelSection();
99   void     onJoin();
100   void     onRemove();
101   void     onClearAll();
102   void     onJoinAll();
103   void     onSetSpline();
104   void     onSetPolyline();
105   void     onCloseSections();
106   void     onUncloseSections();
107   void     onUndo();
108   void     onRedo();
109   void     onUndoSettings();
110   void     onContextMenu(QPoint thePoint);
111   void     onGetCoordsByClick( QMouseEvent* );
112
113   void     onMousePress( SUIT_ViewWindow*, QMouseEvent* theEvent );
114   void     onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEvent );
115   void     onMouseMove( SUIT_ViewWindow*, QMouseEvent* theEvent );
116   void     onLastViewClosed( SUIT_ViewManager* theManager );
117
118   void     onMousePress( QMouseEvent* theEvent );
119   void     onMouseRelease( QMouseEvent* theEvent );
120   void     onMouseMove( QMouseEvent* theEvent );
121
122   void     onCellChanged( int theRow, int theColumn );
123
124 protected:
125   enum ActionId{ UNDO_ID, 
126                  REDO_ID, 
127                  NEW_SECTION_ID, 
128                  ADDITION_MODE_ID, 
129                  REMOVE_ID, 
130                  REMOVE_ALL_ID, 
131                  JOIN_ID,
132                  JOIN_ALL_ID, 
133                  CLOSE_SECTIONS_ID, 
134                  UNCLOSE_SECTIONS_ID,
135                  SET_SECTIONS_POLYLINE_ID, 
136                  SET_SECTIONS_SPLINE_ID, 
137                  CLEAR_ALL_ID, 
138                  SEPARATOR_ID, 
139                  MODIFICATION_MODE_ID, 
140                  DETECTION_MODE_ID 
141   };
142
143   enum ActionMode {
144     NoneMode,
145     AdditionMode,
146     ModificationMode,
147     DetectionMode
148   };
149
150   typedef std::pair< int, int > SectionToPoint;
151   typedef std::deque< SectionToPoint > SectionToPointList;
152
153 private:
154   OCCViewer_Viewer* getOCCViewer();
155
156   QAction* createAction( ActionId theId, const QString& theName, const QPixmap& theImage,
157                          const QString& theToolTip, const QKeySequence& theShortcut );
158   QAction* getAction(ActionId theId);
159   ActionMode getActionMode() const;
160
161   void     updateUndoRedo();
162
163   void removeSection();
164   void removePoint();
165   void insertPointToSelectedSegment( const int theXPosition,
166                                      const int theYPosition );
167   void moveSelectedPoints( const int theXPosition, const int theYPosition );
168   void updateLocalPointView();
169   void setLocalPointContext( const bool theOpen, const bool isUpdateTable = false );
170   void addLocalPointToTable( const double theX, const double theY );
171
172   void setDragStarted( const bool theState, const QPoint& thePoint = QPoint() );
173
174   void getSelectedPonts( SectionToPointList& thePoints );
175   void setSelectedPonts( const SectionToPointList& = SectionToPointList() );
176
177   void startCurveModification( SectionToPointList& thePoints,
178                                const bool theFillPoints = true );
179   void finishCurveModification( const SectionToPointList& thePoints = SectionToPointList() );
180
181   // curve algorithm
182   int  findLocalPointIndex( int theSectionId, float theX, float theY );
183   void findSectionsToPoints( const double theX, const double theY,
184                              SectionToPointList& thePoints );
185   void convert( const SectionToPointList& thePoints,
186                 QMap<int, QList<int> >& theConvPoints );
187
188   // OCC algorithm
189   bool pointOnObject( Handle(AIS_InteractiveObject) theObject,
190                       const int theX, const int theY,
191                       gp_Pnt& thePoint, gp_Pnt& thePoint1, gp_Pnt& thePoint2 );
192   bool hasProjectPointOnCurve( const int theX, const int theY,
193                                const Handle(Geom_Curve)& theCurve,
194                                Standard_Real& theParameter );
195
196   // local point view table methods
197   int getSectionId( const int theRowId ) const;
198   int getPointId( const int theRowId ) const;
199
200   bool contains( const SectionToPointList& theList, const SectionToPoint& theValue ) const;
201
202 private:
203   QMap<ActionId, QAction*>    myActionMap;
204   CurveCreator_ICurve*         myCurve;
205   CurveCreator_TreeView*      mySectionView;
206   QTableWidget*               myLocalPointView;
207   CurveCreator_NewSectionDlg* myNewSectionEditor;
208   OCCViewer_Viewer*           myOCCViewer;
209   int                         mySection;
210   int                         myPointNum;
211   bool                        myDragStarted;
212   QPoint                      myDragStartPosition;
213   int                         myDragInteractionStyle;
214   SectionToPointList          myDragPoints;
215   bool                        myDragged;
216   QByteArray                  myGuiState;
217 };
218
219 #endif // CURVECREATOR_WIDGET_H