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