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