1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROGUI_ViewerDlg.h"
21 #include "HYDROGUI_Module.h"
22 #include "HYDROGUI_Tool.h"
23 #include "HYDROGUI_AISTrihedron.h"
25 #include <CurveCreator_Widget.h>
26 #include <CurveCreator_ICurve.hxx>
27 #include <CurveCreator_Utils.hxx>
29 #include <OCCViewer_ViewPort3d.h>
30 #include <OCCViewer_Utilities.h>
31 #include <OCCViewer_ViewManager.h>
32 #include <OCCViewer_ViewFrame.h>
34 #include <LightApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <SUIT_Session.h>
38 #include <SUIT_ResourceMgr.h>
41 #include <QHBoxLayout>
44 #include <QMouseEvent>
46 HYDROGUI_ViewerDlg::HYDROGUI_ViewerDlg( HYDROGUI_Module* theModule, const QString& theTitle, bool isSplitter )
47 : HYDROGUI_InputPanel( theModule, theTitle, true, isSplitter )
49 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
50 myViewManager = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 );
51 OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( true );
53 aViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
54 aResMgr->backgroundValue( "OCCViewer", "xz_background", aViewer->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
55 aViewer->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
56 aResMgr->backgroundValue( "OCCViewer", "yz_background", aViewer->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
57 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
58 aResMgr->backgroundValue( "OCCViewer", "xy_background", aViewer->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
59 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
60 aResMgr->backgroundValue( "OCCViewer", "background", aViewer->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
62 aViewer->setTrihedronSize( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ),
63 aResMgr->booleanValue( "3DViewer", "relative_size", aViewer->trihedronRelative() ));
64 aViewer->setInteractionStyle( aResMgr->integerValue( "3DViewer", "navigation_mode", aViewer->interactionStyle() ) );
65 aViewer->setZoomingStyle( aResMgr->integerValue( "3DViewer", "zooming_mode", aViewer->zoomingStyle() ) );
66 aViewer->enablePreselection( aResMgr->booleanValue( "OCCViewer", "enable_preselection", aViewer->isPreselectionEnabled() ) );
67 aViewer->enableSelection( aResMgr->booleanValue( "OCCViewer", "enable_selection", aViewer->isSelectionEnabled() ) );
69 myViewManager->setViewModel( aViewer );// custom view model, which extends SALOME_View interface
71 //aViewer->enableMultiselection( false );
73 SUIT_ViewWindow* aViewWin = myViewManager->createViewWindow();
74 aViewer->setStaticTrihedronDisplayed( false );
76 Handle(AIS_Trihedron) aTrihedron =
77 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ) );
78 Handle(AIS_InteractiveContext) anAISContext = aViewer->getAISContext();
79 if ( !anAISContext.IsNull() )
81 anAISContext->Display( aTrihedron );
82 anAISContext->Deactivate( aTrihedron );
85 addWidget( aViewWin, 1 );
88 connect( myViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
89 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
93 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWin );
94 if ( aViewFrame && aViewFrame->getViewPort() )
95 aViewFrame->getViewPort()->installEventFilter( this );
98 myCoordLabel = new QLabel( mainFrame() );
99 addWidget( myCoordLabel, 0 );
102 HYDROGUI_ViewerDlg::~HYDROGUI_ViewerDlg()
104 myViewManager->closeAllViews();
105 delete myViewManager;
108 bool HYDROGUI_ViewerDlg::event( QEvent* e )
110 if ( e->type() == QEvent::Polish )
112 //addWidget( myCoordLabel->parentWidget(), 4 );
114 Handle(AIS_Trihedron) aTrihedron = trihedron();
115 Handle(AIS_InteractiveContext) anAISContext = getAISContext();
116 if ( !anAISContext.IsNull() && !aTrihedron.IsNull() )
118 viewer()->setTrihedronShown( false );
119 anAISContext->Display( aTrihedron );
120 anAISContext->Deactivate( aTrihedron );
124 return HYDROGUI_InputPanel::event( e );
127 Handle(AIS_InteractiveContext) HYDROGUI_ViewerDlg::getAISContext()
129 OCCViewer_Viewer* aViewer = (OCCViewer_Viewer*)myViewManager->getViewModel();
130 return aViewer ? aViewer->getAISContext() : 0;
133 OCCViewer_Viewer* HYDROGUI_ViewerDlg::viewer() const
135 return ::qobject_cast<OCCViewer_Viewer*>( myViewManager->getViewModel() );
138 OCCViewer_ViewManager* HYDROGUI_ViewerDlg::viewManager() const
140 return myViewManager;
143 SUIT_SelectionMgr* HYDROGUI_ViewerDlg::selectionMgr() const
145 SUIT_SelectionMgr* aSelMgr = 0;
148 LightApp_Application* app = module()->getApp();
150 aSelMgr = app->selectionMgr();
155 void HYDROGUI_ViewerDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
157 OCCViewer_ViewWindow* anOCCViewWindow =
158 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
159 if ( anOCCViewWindow && anOCCViewWindow->getViewPort() )
161 gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() );
163 // Show the coordinates
164 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), true );
165 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), true );
166 myCoordLabel->setText( tr("UZ_COORDINATES_INFO").arg( aX ).arg( anY ) );
170 bool HYDROGUI_ViewerDlg::eventFilter( QObject* theObj, QEvent* theEvent )
172 if ( theObj->inherits( "OCCViewer_ViewPort" ) )
174 if ( theEvent->type() == QEvent::Leave )
175 myCoordLabel->clear();
180 return HYDROGUI_InputPanel::eventFilter( theObj, theEvent );
183 Handle(AIS_Trihedron) HYDROGUI_ViewerDlg::trihedron()
185 return Handle(AIS_Trihedron)();