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