geom/src/OperationGUI/OperationGUI_ClippingDlg.cxx

345 lines
12 KiB
C++
Raw Normal View History

2012-08-09 13:58:02 +06:00
// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
2004-12-01 15:39:14 +05:00
//
2012-08-09 13:58:02 +06:00
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
2009-02-13 17:16:39 +05:00
//
2012-08-09 13:58:02 +06:00
2009-02-13 17:16:39 +05:00
// GEOM GEOMGUI : GUI for Geometry component
// File : OperationGUI_ClippingDlg.cxx
// Author : Michael Zorin, Open CASCADE S.A.S. (mikhail.zorin@opencascade.com)
2004-12-01 15:39:14 +05:00
//
#include "OperationGUI_ClippingDlg.h"
2009-02-13 17:16:39 +05:00
#include <DlgRef.h>
#include <GeometryGUI.h>
#include <GEOMBase.h>
2012-08-09 13:58:02 +06:00
#include <SalomeApp_DoubleSpinBox.h>
2009-02-13 17:16:39 +05:00
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewManager.h>
#include <SVTK_ViewWindow.h>
#include <SVTK_ViewModel.h>
2009-02-13 17:16:39 +05:00
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewWindow.h>
#include <OCCViewer_ViewPort3d.h>
2009-02-13 17:16:39 +05:00
#include <VTKViewer.h>
// OCC Includes
2004-12-01 15:39:14 +05:00
#include <V3d_View.hxx>
#include <V3d.hxx>
// VTK Includes
#include <vtkCamera.h>
#include <vtkRenderer.h>
//=================================================================================
// class : OperationGUI_ClippingDlg()
2009-02-13 17:16:39 +05:00
// purpose :
2004-12-01 15:39:14 +05:00
//=================================================================================
2009-02-13 17:16:39 +05:00
OperationGUI_ClippingDlg::OperationGUI_ClippingDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
: GEOMBase_Skeleton( theGeometryGUI, parent, false )
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
setWindowTitle( tr( "Change clipping range" ) );
2009-02-13 17:16:39 +05:00
mainFrame()->GroupConstructors->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->GroupConstructors->close();
mainFrame()->GroupBoxName->setAttribute( Qt::WA_DeleteOnClose );
mainFrame()->GroupBoxName->close();
2004-12-01 15:39:14 +05:00
/***************************************************************/
2009-02-13 17:16:39 +05:00
GroupArguments = new QGroupBox( centralWidget() );
QGridLayout* GroupArgumentsLayout = new QGridLayout( GroupArguments );
2004-12-01 15:39:14 +05:00
GroupArgumentsLayout->setSpacing( 6 );
2009-02-13 17:16:39 +05:00
GroupArgumentsLayout->setMargin( 9 );
2004-12-01 15:39:14 +05:00
// Controls
2009-02-13 17:16:39 +05:00
TextLabelNear = new QLabel( tr( "Near" ), GroupArguments );
2004-12-01 15:39:14 +05:00
GroupArgumentsLayout->addWidget( TextLabelNear, 0, 0 );
2012-08-09 13:58:02 +06:00
SpinBox_Near = new SalomeApp_DoubleSpinBox( GroupArguments );
initSpinBox( SpinBox_Near, COORD_MIN, COORD_MAX, 10.0, "length_precision" );
2004-12-01 15:39:14 +05:00
GroupArgumentsLayout->addWidget( SpinBox_Near, 0, 1 );
2009-02-13 17:16:39 +05:00
TextLabelFar = new QLabel( tr( "Far" ), GroupArguments );
2004-12-01 15:39:14 +05:00
GroupArgumentsLayout->addWidget( TextLabelFar, 0, 2 );
2012-08-09 13:58:02 +06:00
SpinBox_Far = new SalomeApp_DoubleSpinBox( GroupArguments );
initSpinBox( SpinBox_Far, COORD_MIN, COORD_MAX, 10.0, "length_precision" );
2004-12-01 15:39:14 +05:00
GroupArgumentsLayout->addWidget( SpinBox_Far, 0, 3 );
2009-02-13 17:16:39 +05:00
resetButton = new QPushButton( tr( "Reset" ), GroupArguments );
2004-12-01 15:39:14 +05:00
GroupArgumentsLayout->addWidget( resetButton, 0, 4 );
2009-02-13 17:16:39 +05:00
TypeCB = new QComboBox( GroupArguments );
TypeCB->addItem( tr( "OFF" ) );
TypeCB->addItem( tr( "BACK" ) );
TypeCB->addItem( tr( "FRONT" ) );
TypeCB->addItem( tr( "SLICE" ) );
GroupArgumentsLayout->addWidget( TypeCB, 1, 0, 1, 5 );
2009-02-13 17:16:39 +05:00
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupArguments );
2004-12-01 15:39:14 +05:00
/* signals and slots connections */
2009-02-13 17:16:39 +05:00
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
2009-02-13 17:16:39 +05:00
connect( resetButton, SIGNAL( clicked() ), this, SLOT( onReset() ) ) ;
2009-02-13 17:16:39 +05:00
setHelpFileName( "none.htm" );
2004-12-01 15:39:14 +05:00
Init();
}
//=================================================================================
// function : ~ OperationGUI_ClippingDlg()
// purpose : Destroys the object and frees any allocated resources
//=================================================================================
OperationGUI_ClippingDlg::~ OperationGUI_ClippingDlg()
{
// no need to delete child widgets, Qt does it all for us
}
//=================================================================================
// function : Init()
// purpose :
//=================================================================================
void OperationGUI_ClippingDlg::Init()
{
2009-02-13 17:16:39 +05:00
SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
if ( !anActiveWindow )
return;
2009-02-13 17:16:39 +05:00
if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
if ( !aVTKFrame )
return;
2009-02-13 17:16:39 +05:00
TextLabelNear->setText( tr( "Near" ) );
TextLabelFar->setText( tr( "Far" ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
TypeCB->hide();
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
vtkRenderer* aRenderer = aVTKFrame->getRenderer();
if ( !aRenderer ) return;
2009-02-13 17:16:39 +05:00
vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
if ( anActiveCamera == NULL ) {
return;
}
2004-12-01 15:39:14 +05:00
// Find the plane equation for the camera view plane
2009-02-13 17:16:39 +05:00
double vn[3];
anActiveCamera->GetViewPlaneNormal( vn );
double position[3];
anActiveCamera->GetPosition( position );
2013-03-01 19:10:52 +06:00
double bounds[6];
2009-02-13 17:16:39 +05:00
aRenderer->ComputeVisiblePropBounds( bounds );
2009-02-13 17:16:39 +05:00
double center[3];
center[0] = ( bounds[0] + bounds[1] ) / 2.0;
center[1] = ( bounds[2] + bounds[3] ) / 2.0;
center[2] = ( bounds[4] + bounds[5] ) / 2.0;
2009-02-13 17:16:39 +05:00
double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
2012-08-09 13:58:02 +06:00
( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
2009-02-13 17:16:39 +05:00
double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
2012-08-09 13:58:02 +06:00
( position[1]-center[1] ) * ( position[1]-center[1] ) +
( position[2]-center[2] ) * ( position[2]-center[2] ) );
2013-03-01 19:10:52 +06:00
double range[2] = { distance - width/2.0, distance + width/2.0 };
2009-02-13 17:16:39 +05:00
SpinBox_Near->setValue( range[0] );
SpinBox_Far->setValue( range[1] );
2009-02-13 17:16:39 +05:00
return;
}
else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
2009-02-13 17:16:39 +05:00
TextLabelNear->setText( tr( "Depth" ) );
TextLabelFar->setText( tr( "Thickness" ) );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
double depth, thickness;
int ztype = view3d->ZClipping( depth, thickness );
SpinBox_Near->setValue( depth );
SpinBox_Far->setValue( thickness );
TypeCB->setCurrentIndex( ztype );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
//Handle(V3d_Plane) aPlane = new V3d_Plane( aOCCFrame->getViewer()->getViewer3d() ,0, 0, 1, -100);
//aPlane->Display(view3d);
}
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : ClickOnApply()
// purpose :
//=================================================================================
bool OperationGUI_ClippingDlg::ClickOnApply()
{
2009-02-13 17:16:39 +05:00
SUIT_ViewWindow* anActiveWindow = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
if ( !anActiveWindow )
return false;
2009-02-13 17:16:39 +05:00
if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
if ( !aVTKFrame )
return false;
2009-02-13 17:16:39 +05:00
vtkRenderer* aRenderer = aVTKFrame->getRenderer();
if ( !aRenderer ) return false;
2009-02-13 17:16:39 +05:00
vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
if ( anActiveCamera == NULL ) {
return false;
}
2013-03-01 19:10:52 +06:00
double range[2] = { SpinBox_Near->value(), SpinBox_Far->value() };
2009-02-13 17:16:39 +05:00
if ( range[0] < 0.0 ) range[0] = 0.0;
anActiveCamera->SetClippingRange( range );
2009-02-13 17:16:39 +05:00
return true;
}
else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
2009-02-13 17:16:39 +05:00
Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
2009-02-13 17:16:39 +05:00
double depth = SpinBox_Near->value();
double thickness = SpinBox_Far->value();
int aType = TypeCB->currentIndex();
2009-02-13 17:16:39 +05:00
view3d->SetZClippingType( V3d_TypeOfZclipping( aType ) );
view3d->SetZClippingDepth( depth );
view3d->SetZClippingWidth( thickness );
}
2004-12-01 15:39:14 +05:00
return true;
}
//=================================================================================
// function : ClickOnOk()
// purpose :
//=================================================================================
void OperationGUI_ClippingDlg::ClickOnOk()
{
2012-08-09 13:58:02 +06:00
setIsApplyAndClose( true );
2009-02-13 17:16:39 +05:00
if ( ClickOnApply() )
ClickOnCancel();
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : onActivate()
// purpose :
//=================================================================================
void OperationGUI_ClippingDlg::onActivate()
{
GEOMBase_Skeleton::ActivateThisDialog();
}
//=================================================================================
// function : enterEvent()
// purpose :
//=================================================================================
2009-02-13 17:16:39 +05:00
void OperationGUI_ClippingDlg::enterEvent( QEvent* )
2004-12-01 15:39:14 +05:00
{
2009-02-13 17:16:39 +05:00
this->setEnabled( true );
2004-12-01 15:39:14 +05:00
}
//=================================================================================
// function : onReset()
// purpose :
//=================================================================================
void OperationGUI_ClippingDlg::onReset()
{
SUIT_ViewWindow* anActiveWindow =
SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
2009-02-13 17:16:39 +05:00
if ( !anActiveWindow )
return;
2009-02-13 17:16:39 +05:00
if ( anActiveWindow->getViewManager()->getType() == SVTK_Viewer::Type() ) {
SVTK_ViewWindow* aVTKFrame = dynamic_cast<SVTK_ViewWindow*>( anActiveWindow );
if ( !aVTKFrame )
return;
2009-02-13 17:16:39 +05:00
vtkRenderer* aRenderer = aVTKFrame->getRenderer();
if ( !aRenderer ) return;
2009-02-13 17:16:39 +05:00
vtkCamera* anActiveCamera = aRenderer->GetActiveCamera();
if ( anActiveCamera == NULL ) {
return;
}
2004-12-01 15:39:14 +05:00
// Find the plane equation for the camera view plane
2009-02-13 17:16:39 +05:00
double vn[3];
anActiveCamera->GetViewPlaneNormal( vn );
double position[3];
anActiveCamera->GetPosition( position );
2013-03-01 19:10:52 +06:00
double bounds[6];
2009-02-13 17:16:39 +05:00
aRenderer->ComputeVisiblePropBounds( bounds );
2009-02-13 17:16:39 +05:00
double center[3];
center[0] = ( bounds[0] + bounds[1] ) / 2.0;
center[1] = ( bounds[2] + bounds[3] ) / 2.0;
center[2] = ( bounds[4] + bounds[5] ) / 2.0;
2009-02-13 17:16:39 +05:00
double width = sqrt( ( bounds[1]-bounds[0] ) * ( bounds[1]-bounds[0] ) +
2012-08-09 13:58:02 +06:00
( bounds[3]-bounds[2] ) * ( bounds[3]-bounds[2] ) +
( bounds[5]-bounds[4] ) * ( bounds[5]-bounds[4] ) );
2009-02-13 17:16:39 +05:00
double distance = sqrt( ( position[0]-center[0] ) * ( position[0]-center[0] ) +
2012-08-09 13:58:02 +06:00
( position[1]-center[1] ) * ( position[1]-center[1] ) +
( position[2]-center[2] ) * ( position[2]-center[2] ) );
2013-03-01 19:10:52 +06:00
double range[2] = { distance - width/2.0, distance + width/2.0 };
2009-02-13 17:16:39 +05:00
SpinBox_Near->setValue( range[0] );
SpinBox_Far->setValue( range[1] );
2004-12-01 15:39:14 +05:00
2009-02-13 17:16:39 +05:00
return;
}
else if ( anActiveWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() ) {
OCCViewer_ViewWindow* aOCCFrame = dynamic_cast<OCCViewer_ViewWindow*>( anActiveWindow );
TextLabelNear->setText( tr( "Depth" ) );
TextLabelFar->setText( tr( "Thickness" ) );
Handle(V3d_View) view3d = ( (OCCViewer_ViewPort3d*)aOCCFrame->getViewPort() )->getView();
view3d->SetZClippingType( V3d_TypeOfZclipping( 0 ) );
view3d->ZFitAll();
double depth, thickness;
int ztype= view3d->ZClipping( depth, thickness );
SpinBox_Near->setValue( 0 );
SpinBox_Far->setValue( 1000 );
TypeCB->setCurrentIndex( ztype );
}
2004-12-01 15:39:14 +05:00
}