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