Salome HOME
9058cf19e093a0fa217328cf152f67140bc0c2ed
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_GraphicViewsHandler.cxx
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 //Salome
21 #include <SalomeApp_Application.h>
22 #include <SUIT_Session.h>
23 #include <SUIT_ViewManager.h>
24 #include <SVTK_ViewModel.h>
25 #include <SOCC_ViewModel.h>
26
27 //HexaBlock
28 #include "HEXABLOCKGUI_GraphicViewsHandler.hxx"
29 #include "utilities.h"
30
31
32
33 using namespace HEXABLOCK::GUI;
34
35
36
37 /*====================================================== createDocumentGraphicView
38  * Create a new document
39  * Returns the new document's window
40  *=============================================================================*/
41 VtkDocumentGraphicView* GraphicViewsHandler::createDocumentGraphicView(DocumentModel* docModel,
42                                                                      SVTK_ViewWindow* wnd, QWidget* parent)
43 {
44
45 //    if (wnd == NULL) return NULL;
46 //    VtkDocumentGraphicView* dgview = getDocumentGraphicView(wnd);
47 //    if (dgview != NULL) return dgview;
48 //
49 //    docGraphicViews[wnd] = new VtkDocumentGraphicView(docModel, wnd, parent);
50 //    return docGraphicViews[wnd];
51     return new VtkDocumentGraphicView(docModel, wnd, parent);
52 }
53
54 /*====================================================== getDocumentGraphicView
55  * Returns the document corresponding to a vtk window (view)
56  *=============================================================================*/
57 VtkDocumentGraphicView* GraphicViewsHandler::getDocumentGraphicView(SVTK_ViewWindow* view) const
58 {
59     if (view == NULL || !docGraphicViews.contains(view)) return NULL;
60     return docGraphicViews[view];
61 }
62
63 /*====================================================== getOrCreateVtkWindow
64 /// Returns the active vtk window if there's one,
65 /// create one and return it otherwise.
66  *=============================================================================*/
67 SVTK_ViewWindow* GraphicViewsHandler::getOrCreateVtkWindow() const
68 {
69     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
70     if( anApp == NULL) return NULL;
71     SUIT_ViewManager* vmgr = anApp->getViewManager( SVTK_Viewer::Type(), true);
72
73     return dynamic_cast<SVTK_ViewWindow*>(vmgr->getActiveView());
74 }
75
76
77 /*====================================================== createVtkWindow
78 /// Create a vtk window and return it
79  *=============================================================================*/
80 SVTK_ViewWindow* GraphicViewsHandler::createVtkWindow() const
81 {
82     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
83     if( anApp == NULL) return NULL;
84
85     SUIT_ViewManager* vmgr = anApp->newViewManager (SVTK_Viewer::Type());
86     SVTK_ViewWindow* view = dynamic_cast<SVTK_ViewWindow*>(vmgr->getActiveView());
87     if (view == NULL) return NULL;
88     view->setWindowTitle(QObject::tr("HEXABLOCK") + " : " + view->windowTitle());
89
90     return view;
91 }
92
93
94 /*====================================================== getOrCreateOccWindow
95 /// Returns the active occ window if there's one,
96 /// create one and return it otherwise.
97  *=============================================================================*/
98 OCCViewer_ViewWindow* GraphicViewsHandler::getOrCreateOccWindow() const
99 {
100     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
101     if( anApp == NULL) return NULL;
102     SUIT_ViewManager* vmgr = anApp->getViewManager(OCCViewer_Viewer::Type(), true);
103
104     return dynamic_cast<OCCViewer_ViewWindow*>(vmgr->getActiveView());
105 }
106
107
108 /*====================================================== createOccWindow
109 /// Create an open cascade window and return it
110  *=============================================================================*/
111 OCCViewer_ViewWindow* GraphicViewsHandler::createOccWindow() const
112 {
113     SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
114     if( anApp == NULL) return NULL;
115
116     SUIT_ViewManager* vmgr = anApp->newViewManager (OCCViewer_Viewer::Type());
117     OCCViewer_ViewWindow* view = dynamic_cast<OCCViewer_ViewWindow*>(vmgr->getActiveView());
118     if (view == NULL) return NULL;
119     view->setWindowTitle(QObject::tr("HEXABLOCK") + " : " + view->windowTitle());
120
121     return view;
122 }
123
124
125 /*====================================================== createDocumentGraphicView
126  * Close a document graphic view
127  *=============================================================================*/
128 void GraphicViewsHandler::closeDocumentGraphicView(SVTK_ViewWindow* window)
129 {
130     VtkDocumentGraphicView* dgview = getDocumentGraphicView(window);
131     if (dgview == NULL) return; //There's nothing to do if the window has no document
132
133     //remove the document
134     docGraphicViews.remove(window);
135     delete dgview;
136 }
137
138