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