Salome HOME
43de107d7a6400a056b16c188bb369e467e5c7d7
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_VtkDocumentGraphicView.hxx
1 // Copyright (C) 2009-2023  CEA, EDF
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, or (at your option) any later version.
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 HEXABLOCK_EXPORT 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          *                          VtkDocumentGraphicView
95          ********************************************************************************/
96         class HEXABLOCK_EXPORT VtkDocumentGraphicView : public QAbstractItemView
97         {
98             Q_OBJECT
99
100             public:
101             VtkDocumentGraphicView(DocumentModel* docModel, SVTK_ViewWindow* view, QWidget* parent=NULL);
102             virtual ~VtkDocumentGraphicView();
103             
104                 void setModel ( QAbstractItemModel * model );
105                 bool isEmpty() const { return getDocumentModel()->isEmpty(); }
106                 void highlight( const QModelIndex& ielt );
107                 void highlight( const QModelIndexList& elts );
108                 void highlightGroups( const QModelIndex& eltIndex );
109                 void highlightPropagation( const QModelIndex& eltIndex );
110
111             void setSelectionMode( const Selection_Mode theMode );
112             void setSelectionMode( const QModelIndex& eltIndex );
113             int getSelectionMode() const { return selectionMode; }
114             void getSelected(SALOME_ListIO& selectedObjects);
115             void clearSelection();
116
117                 void loadDocument(const QString& file); //Loads a selected document
118                 void loadDocument(); //Loads the current document
119                 void saveDocument(const QString& file);
120                 void update();//mise à jours de la vue : reconstruction complète
121                 void removeActor();
122
123                 QModelIndex indexAt(const QPoint &point) const;
124                 void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
125                 QRect visualRect(const QModelIndex &index) const;
126
127                 SVTK_ViewWindow* getViewWindow() const { return viewWindow; }
128                 void setViewWindow(SVTK_ViewWindow* view) { viewWindow = view; }
129                 Document_Actor* getDocumentActor() const { return documentActor; }
130
131                 DocumentModel*      getDocumentModel() const {
132                     return dynamic_cast<DocumentModel*>(model());
133                 }
134                 PatternDataSelectionModel* getPatternDataSelectionModel() const
135                 { return patternDataSelectionModel; }
136
137                 PatternGeomSelectionModel* getPatternGeomSelectionModel() const
138             { return patternGeomSelectionModel;}
139
140                 GroupsSelectionModel* getGroupsSelectionModel() const
141                 { return groupsSelectionModel; }
142
143                 MeshSelectionModel* getMeshSelectionModel() const
144                 { return meshSelectionModel; }
145
146                 PatternDataModel*    getPatternDataModel() const {return patternDataModel;}
147                 PatternGeomModel*    getPatternGeomModel() const { return patternGeomModel;}
148                 GroupsModel*         getGroupsModel() const {return groupsModel;}
149                 MeshModel*           getMeshModel() const {return meshModel;}
150
151         public slots:
152           void setWindowTitle(const QString& title);
153           void onPatternDatachanged();
154           void setVertexSelection();
155           void setEdgeSelection();
156           void setQuadSelection();
157           void setHexaSelection();
158           void setAllSelection();
159
160         protected slots:
161           virtual void  closeEditor ( QWidget * editor, QAbstractItemDelegate::EndEditHint hint );
162           virtual void  commitData ( QWidget * editor );
163           virtual void  currentChanged ( const QModelIndex & current, const QModelIndex & previous );
164           virtual void  dataChanged ( const QModelIndex & topLeft, const QModelIndex & bottomRight );
165           virtual void  editorDestroyed ( QObject * editor );
166           virtual void  rowsAboutToBeRemoved ( const QModelIndex & parent, int start, int end );
167           virtual void  rowsInserted ( const QModelIndex & parent, int start, int end );
168           virtual void  selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected );
169           virtual void  updateGeometries ();
170
171         protected:
172             int horizontalOffset() const;
173             bool isIndexHidden(const QModelIndex &index) const;
174             QModelIndex moveCursor(QAbstractItemView::CursorAction cursorAction,
175                                    Qt::KeyboardModifiers modifiers);
176             void setSelection(const QRect&, QItemSelectionModel::SelectionFlags command);
177             int verticalOffset() const;
178             QRegion visualRegionForSelection(const QItemSelection &selection) const;
179
180         private:
181             SVTK_ViewWindow*  viewWindow;
182             int selectionMode;
183             bool state;
184
185             Document_Actor*   documentActor;
186             Associate_Actor*  associateActor;
187
188             PatternDataSelectionModel*     patternDataSelectionModel;
189             PatternGeomSelectionModel*     patternGeomSelectionModel;
190             GroupsSelectionModel*          groupsSelectionModel;
191             MeshSelectionModel*            meshSelectionModel;
192
193             PatternDataModel*              patternDataModel;
194             PatternGeomModel*              patternGeomModel;
195             GroupsModel*                   groupsModel;
196             MeshModel*                     meshModel;
197
198             bool _currentChanged;
199             bool firstUpdate;
200         };
201     }
202 }
203
204
205
206
207 #endif