1 // Copyright (C) 2009-2015 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
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>
28 #include "HEXABLOCKGUI_GraphicViewsHandler.hxx"
29 #include "utilities.h"
33 using namespace HEXABLOCK::GUI;
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)
45 // if (wnd == NULL) return NULL;
46 // VtkDocumentGraphicView* dgview = getDocumentGraphicView(wnd);
47 // if (dgview != NULL) return dgview;
49 // docGraphicViews[wnd] = new VtkDocumentGraphicView(docModel, wnd, parent);
50 // return docGraphicViews[wnd];
51 return new VtkDocumentGraphicView(docModel, wnd, parent);
54 /*====================================================== getDocumentGraphicView
55 * Returns the document corresponding to a vtk window (view)
56 *=============================================================================*/
57 VtkDocumentGraphicView* GraphicViewsHandler::getDocumentGraphicView(SVTK_ViewWindow* view) const
59 if (view == NULL || !docGraphicViews.contains(view)) return NULL;
60 return docGraphicViews[view];
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
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);
73 return dynamic_cast<SVTK_ViewWindow*>(vmgr->getActiveView());
77 /*====================================================== createVtkWindow
78 /// Create a vtk window and return it
79 *=============================================================================*/
80 SVTK_ViewWindow* GraphicViewsHandler::createVtkWindow() const
82 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
83 if( anApp == NULL) return NULL;
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());
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
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);
104 return dynamic_cast<OCCViewer_ViewWindow*>(vmgr->getActiveView());
108 /*====================================================== createOccWindow
109 /// Create an open cascade window and return it
110 *=============================================================================*/
111 OCCViewer_ViewWindow* GraphicViewsHandler::createOccWindow() const
113 SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(SUIT_Session::session()->activeApplication());
114 if( anApp == NULL) return NULL;
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());
125 /*====================================================== createDocumentGraphicView
126 * Close a document graphic view
127 *=============================================================================*/
128 void GraphicViewsHandler::closeDocumentGraphicView(SVTK_ViewWindow* window)
130 VtkDocumentGraphicView* dgview = getDocumentGraphicView(window);
131 if (dgview == NULL) return; //There's nothing to do if the window has no document
133 //remove the document
134 docGraphicViews.remove(window);