]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_VtkDocumentGraphicView.hxx
Salome HOME
Merge from V6_main 01/04/2013
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_VtkDocumentGraphicView.hxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
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 _HEXABLOCKGUI_VTKDOCUMENTGRAPHICVIEW_HXX_
21 #define _HEXABLOCKGUI_VTKDOCUMENTGRAPHICVIEW_HXX_
22
23 // SALOME GUI includes
24 #include <LightApp_Displayer.h>
25 // #include <SVTK_ViewWindow.h>
26 #include <SUIT_ViewWindow.h>
27 #include <SALOME_Actor.h>
28 #include <SVTK_InteractorStyle.h>
29 #include <QAbstractItemView>
30 #include <QMap>
31
32 // #include <QContextMenuEvent>
33 // #include <QAction>
34 // #include <QGraphicsRectItem>
35
36 #include <HexVertex.hxx>
37 #include <HexQuad.hxx>
38 #include <HexEdge.hxx>
39 #include <HexHexa.hxx>
40 #include <HexDocument.hxx>
41 #include <vtkInteractorStyleTrackballCamera.h>
42 #include <SVTK_RenderWindowInteractor.h>
43 #include <vtkActor2D.h>
44 #include <SVTK_ViewWindow.h>
45
46 #include "HEXABLOCKGUI_DocumentModel.hxx"
47 #include "HEXABLOCKGUI_DocumentSelectionModel.hxx"
48
49 // class LightApp_Displayer;
50 // class SalomeApp_Application;
51 class LightApp_Application;
52 class SALOME_Actor;
53
54 // class vtkLookupTable ;
55 // class vtkPoints ;
56 // class vtkCellArray ;
57 // class vtkFloatArray ;
58 // class vtkActor ;
59 // class vtkPolyData;
60
61
62 class vtkUnstructuredGrid;
63
64
65
66 namespace HEXABLOCK
67 {
68
69     namespace GUI
70     {
71 //              class hexablockInteractorStyle : public SVTK_InteractorStyle
72 //              {
73 //              public:
74 //                      hexablockInteractorStyle() {};
75 //                      virtual ~hexablockInteractorStyle() {};
76 //
77 //              public:
78 //                      static hexablockInteractorStyle* New()
79 //                      {
80 //                              return new hexablockInteractorStyle;
81 //                      };
82 //                      virtual void HighlightActor2D(vtkActor2D* actor2D) {MESSAGE("% HIGHLIGHT PROP 2D %");}
83 //                      virtual void HighlightProp(vtkProp* prop) {MESSAGE("% HIGHLIGHT PROP %");}
84 //                      virtual void HighlightProp3D(vtkProp3D* prop3D) {MESSAGE("% HIGHLIGHT PROP 3D %");}
85 //              };
86
87         class Document_Actor : public SALOME_Actor
88         {
89           public:
90             Document_Actor(HEXA_NS::Document* doc, const QString& entry);
91             virtual ~Document_Actor();
92
93             std::map<int,vtkIdType>   vtkElemsId;
94             std::map<vtkIdType, int>  hexaElemsId;
95
96             vtkUnstructuredGrid* getUnstructuredGrid();
97           private:
98             HEXA_NS::Document* _doc;
99         };
100
101                                                      // Abu
102         class Associate_Actor : public SALOME_Actor
103         {
104           public:
105             Associate_Actor(HEXA_NS::Document* doc, const QString& entry);
106             virtual ~Associate_Actor() {}
107
108             std::map<int,vtkIdType>   vtkElemsId;
109             std::map<vtkIdType, int>  hexaElemsId;
110
111             vtkUnstructuredGrid* getUnstructuredGrid();
112           private:
113             HEXA_NS::Document* _doc;
114         };
115
116
117         /********************************************************************************
118          *                          VtkDocumentGraphicView
119          ********************************************************************************/
120         class VtkDocumentGraphicView : public QAbstractItemView
121         {
122             Q_OBJECT
123
124             public:
125             VtkDocumentGraphicView(DocumentModel* docModel, SVTK_ViewWindow* view, QWidget* parent=NULL);
126             virtual ~VtkDocumentGraphicView();
127             
128                 void setModel ( QAbstractItemModel * model );
129                 bool isEmpty() const { return getDocumentModel()->isEmpty(); }
130                 void highlight( const QModelIndex& ielt );
131                 void highlight( const QModelIndexList& elts );
132                 void highlightGroups( const QModelIndex& eltIndex );
133                 void highlightPropagation( const QModelIndex& eltIndex );
134
135             void setSelectionMode( const Selection_Mode theMode );
136             void setSelectionMode( const QModelIndex& eltIndex );
137             int getSelectionMode() const { return selectionMode;}
138             void clearSelection();
139
140                 void loadDocument(const QString& file); //Loads a selected document
141                 void loadDocument(); //Loads the current document
142                 void saveDocument(const QString& file);
143                 void update();//mise à jours de la vue : reconstruction complète
144                 void removeActor();
145
146                 QModelIndex indexAt(const QPoint &point) const;
147                 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
148                 QRect visualRect(const QModelIndex &index) const;
149
150                 SVTK_ViewWindow* getViewWindow() const { return viewWindow; }
151                 void setViewWindow(SVTK_ViewWindow* view) { viewWindow = view; }
152                 Document_Actor* getDocumentActor() const { return documentActor; }
153
154                 DocumentModel*      getDocumentModel() const {
155                     return dynamic_cast<DocumentModel*>(model());
156                 }
157                 PatternDataSelectionModel* getPatternDataSelectionModel() const
158                 { return patternDataSelectionModel; }
159
160                 PatternBuilderSelectionModel* getPatternBuilderSelectionModel() const
161                 { return patternBuilderSelectionModel; }
162
163                 PatternGeomSelectionModel* getPatternGeomSelectionModel() const
164             { return patternGeomSelectionModel;}
165
166                 GroupsSelectionModel* getGroupsSelectionModel() const
167                 { return groupsSelectionModel; }
168
169                 MeshSelectionModel* getMeshSelectionModel() const
170                 { return meshSelectionModel; }
171
172                 PatternDataModel*    getPatternDataModel() const {return patternDataModel;}
173                 PatternBuilderModel* getPatternBuilderModel() const {return patternBuilderModel;}
174                 PatternGeomModel*    getPatternGeomModel() const { return patternGeomModel;}
175                 GroupsModel*         getGroupsModel() const {return groupsModel;}
176                 MeshModel*           getMeshModel() const {return meshModel;}
177
178         public slots:
179           void setWindowTitle(const QString& title);
180           void onPatternDatachanged();
181           void setVertexSelection();
182           void setEdgeSelection();
183           void setQuadSelection();
184           void setHexaSelection();
185           void setAllSelection();
186
187         protected slots:
188           virtual void  closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint );
189           virtual void  commitData ( QWidget * editor );
190           virtual void  currentChanged ( const QModelIndex & current, const QModelIndex & previous );
191           virtual void  dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight );
192           virtual void  editorDestroyed ( QObject * editor );
193           virtual void  rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end );
194           virtual void  rowsInserted ( const QModelIndex & parent, int start, int end );
195           virtual void  selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected );
196           virtual void  updateGeometries ();
197
198         protected:
199             int horizontalOffset() const;
200             bool isIndexHidden(const QModelIndex &index) const;
201             QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction,
202                                    Qt::KeyboardModifiers modifiers);
203             void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command);
204             int verticalOffset() const;
205             QRegion visualRegionForSelection(const QItemSelection &selection) const;
206
207 //         protected:
208 //           virtual SALOME_Prs* buildPresentation( const QString&, SALOME_View* = 0 );
209
210         private:
211             SVTK_ViewWindow*  viewWindow;
212             int selectionMode;
213             bool state;
214
215             Document_Actor*   documentActor;
216             Associate_Actor*  associateActor;
217
218             PatternDataSelectionModel*     patternDataSelectionModel;
219             PatternBuilderSelectionModel*  patternBuilderSelectionModel;
220             PatternGeomSelectionModel*     patternGeomSelectionModel;
221             GroupsSelectionModel*          groupsSelectionModel;
222             MeshSelectionModel*            meshSelectionModel;
223
224             PatternDataModel*              patternDataModel;
225             PatternBuilderModel*           patternBuilderModel;
226             PatternGeomModel*              patternGeomModel;
227             GroupsModel*                   groupsModel;
228             MeshModel*                     meshModel;
229
230             bool _currentChanged;
231             bool firstUpdate;
232         };
233     }
234 }
235
236
237
238
239 #endif