1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROGUI_ViewerDlg.h"
25 #include "HYDROGUI_Module.h"
26 #include "HYDROGUI_Tool.h"
27 #include "HYDROGUI_AISTrihedron.h"
29 #include <CurveCreator_Widget.h>
30 #include <CurveCreator_ICurve.hxx>
31 #include <CurveCreator_Utils.hxx>
33 #include <OCCViewer_ViewPort3d.h>
34 #include <OCCViewer_Utilities.h>
35 #include <OCCViewer_ViewManager.h>
36 #include <OCCViewer_ViewFrame.h>
37 #include <LightApp_Application.h>
39 #include <SUIT_Session.h>
40 #include <SUIT_ResourceMgr.h>
43 #include <QHBoxLayout>
46 #include <QMouseEvent>
48 HYDROGUI_ViewerDlg::HYDROGUI_ViewerDlg( HYDROGUI_Module* theModule, const QString& theTitle )
49 : HYDROGUI_InputPanel( theModule, theTitle )
51 QWidget* viewMain = new QWidget( mainFrame() );
52 QVBoxLayout* viewBase = new QVBoxLayout( viewMain );
53 viewBase->setMargin( 0 );
55 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
56 myViewManager = new OCCViewer_ViewManager( theModule->getApp()->activeStudy(), 0 );
57 OCCViewer_Viewer* aViewer = new OCCViewer_Viewer( false );
59 aViewer->setBackground( OCCViewer_ViewFrame::TOP_LEFT,
60 aResMgr->backgroundValue( "OCCViewer", "xz_background", aViewer->background(OCCViewer_ViewFrame::TOP_LEFT) ) );
61 aViewer->setBackground( OCCViewer_ViewFrame::TOP_RIGHT,
62 aResMgr->backgroundValue( "OCCViewer", "yz_background", aViewer->background(OCCViewer_ViewFrame::TOP_RIGHT) ) );
63 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_LEFT,
64 aResMgr->backgroundValue( "OCCViewer", "xy_background", aViewer->background(OCCViewer_ViewFrame::BOTTOM_LEFT) ) );
65 aViewer->setBackground( OCCViewer_ViewFrame::BOTTOM_RIGHT,
66 aResMgr->backgroundValue( "OCCViewer", "background", aViewer->background(OCCViewer_ViewFrame::MAIN_VIEW) ) );
68 aViewer->setTrihedronSize( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ),
69 aResMgr->booleanValue( "3DViewer", "relative_size", aViewer->trihedronRelative() ));
70 aViewer->setInteractionStyle( aResMgr->integerValue( "3DViewer", "navigation_mode", aViewer->interactionStyle() ) );
71 aViewer->setZoomingStyle( aResMgr->integerValue( "3DViewer", "zooming_mode", aViewer->zoomingStyle() ) );
72 aViewer->enablePreselection( aResMgr->booleanValue( "OCCViewer", "enable_preselection", aViewer->isPreselectionEnabled() ) );
73 aViewer->enableSelection( aResMgr->booleanValue( "OCCViewer", "enable_selection", aViewer->isSelectionEnabled() ) );
75 myViewManager->setViewModel( aViewer );// custom view model, which extends SALOME_View interface
77 SUIT_ViewWindow* aViewWin = myViewManager->createViewWindow();
78 aViewer->setStaticTrihedronDisplayed( false );
79 Handle(AIS_Trihedron) aTrihedron =
80 HYDROGUI_AISTrihedron::createTrihedron( aResMgr->doubleValue( "3DViewer", "trihedron_size", aViewer->trihedronSize() ) );
81 Handle(AIS_InteractiveContext) anAISContext = aViewer->getAISContext();
82 if ( !anAISContext.IsNull() )
84 anAISContext->Display( aTrihedron );
85 anAISContext->Deactivate( aTrihedron );
88 viewBase->addWidget( aViewWin );
91 connect( myViewManager, SIGNAL( mouseMove( SUIT_ViewWindow*, QMouseEvent* ) ),
92 this, SLOT( onMouseMove( SUIT_ViewWindow*, QMouseEvent* ) ) );
96 OCCViewer_ViewFrame* aViewFrame = dynamic_cast<OCCViewer_ViewFrame*>( aViewWin );
97 if ( aViewFrame && aViewFrame->getViewPort() )
98 aViewFrame->getViewPort()->installEventFilter( this );
101 myCoordLabel = new QLabel( viewMain );
102 viewBase->addWidget( myCoordLabel );
105 HYDROGUI_ViewerDlg::~HYDROGUI_ViewerDlg()
107 delete myViewManager;
110 bool HYDROGUI_ViewerDlg::event( QEvent* e )
112 if ( e->type() == QEvent::Polish )
113 addWidget( myCoordLabel->parentWidget(), 4 );
115 return HYDROGUI_InputPanel::event( e );
118 Handle(AIS_InteractiveContext) HYDROGUI_ViewerDlg::getAISContext()
120 OCCViewer_Viewer* aViewer = (OCCViewer_Viewer*)myViewManager->getViewModel();
121 return aViewer ? aViewer->getAISContext() : 0;
124 OCCViewer_Viewer* HYDROGUI_ViewerDlg::viewer() const
126 return ::qobject_cast<OCCViewer_Viewer*>( myViewManager->getViewModel() );
129 OCCViewer_ViewManager* HYDROGUI_ViewerDlg::viewManager() const
131 return myViewManager;
134 void HYDROGUI_ViewerDlg::onMouseMove( SUIT_ViewWindow* theViewWindow, QMouseEvent* theEvent )
136 OCCViewer_ViewWindow* anOCCViewWindow =
137 dynamic_cast<OCCViewer_ViewWindow*>(theViewWindow);
138 if ( anOCCViewWindow && anOCCViewWindow->getViewPort() )
140 gp_Pnt aPnt = CurveCreator_Utils::ConvertClickToPoint( theEvent->x(), theEvent->y(), anOCCViewWindow->getViewPort()->getView() );
142 // Show the coordinates
143 QString aX = HYDROGUI_Tool::GetCoordinateString( aPnt.X(), true );
144 QString anY = HYDROGUI_Tool::GetCoordinateString( aPnt.Y(), true );
145 myCoordLabel->setText( tr("UZ_COORDINATES_INFO").arg( aX ).arg( anY ) );
149 bool HYDROGUI_ViewerDlg::eventFilter( QObject* theObj, QEvent* theEvent )
151 if ( theObj->inherits( "OCCViewer_ViewPort" ) )
153 if ( theEvent->type() == QEvent::Leave )
154 myCoordLabel->clear();
159 return HYDROGUI_InputPanel::eventFilter( theObj, theEvent );