Salome HOME
0022171: EDF 2477 GUI: Redesign of the "split" action and addition of a "tile" action
[modules/gui.git] / src / OCCViewer / OCCViewer_ClippingDlg.cxx
index 106e28b8f936830b36ecdabc02cf7ed7b8e78423..4c4865f675dad18ca68c6eeb069cdc0b22394236 100644 (file)
@@ -1,11 +1,14 @@
-// Copyright (C) 2005  CEA/DEN, EDF R&D, OPEN CASCADE, PRINCIPIA R&D
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
 // 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.
 //
-// This library is distributed in the hope that it will be useful
+// 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.
 //
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #include "OCCViewer_ClippingDlg.h"
 
-#include <QtxDblSpinBox.h>
+#include <QtxDoubleSpinBox.h>
 #include <QtxAction.h>
 
 #include "SUIT_Session.h"
 #include "SUIT_ViewWindow.h"
+#include "SUIT_ViewManager.h"
 #include "OCCViewer_ViewWindow.h"
 #include "OCCViewer_ViewPort3d.h"
+#include "OCCViewer_ViewModel.h"
 
 #include <V3d_View.hxx>
-//#include <V3d.hxx>
 #include <Geom_Plane.hxx>
 #include <Prs3d_Presentation.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 #include <gp_Pln.hxx>
 
 // QT Includes
-#include <qapplication.h>
-#include <qgroupbox.h>
-#include <qlayout.h>
-#include <qlabel.h>
-#include <qpushbutton.h>
-#include <qcombobox.h>
-#include <qcheckbox.h>
+#include <QApplication>
+#include <QGroupBox>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QGridLayout>
+#include <QLabel>
+#include <QPushButton>
+#include <QComboBox>
+#include <QCheckBox>
 
 /*!
   Constructor
   \param modal - is this dialog modal
   \param fl - flags
 */
-OCCViewer_ClippingDlg::OCCViewer_ClippingDlg( OCCViewer_ViewWindow* view, QWidget* parent, const char* name, bool modal, WFlags fl )
-: QDialog( parent, "OCCViewer_ClippingDlg", modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu ),
+OCCViewer_ClippingDlg::OCCViewer_ClippingDlg( OCCViewer_ViewWindow* view, const char* name, bool modal, Qt::WindowFlags fl )
+: QDialog( view, Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
   myView( view )
 {
-  setCaption( tr( "Clipping" ) );
+  setObjectName( "OCCViewer_ClippingDlg" );
+  setModal( modal );
+
+  setWindowTitle( tr( "Clipping" ) );
   
   QVBoxLayout* topLayout = new QVBoxLayout( this );
   topLayout->setMargin( 11 ); topLayout->setSpacing( 6 );
   
   /***************************************************************/
-  GroupPoint = new QGroupBox( this, "GroupPoint" );
+  GroupPoint = new QGroupBox( this );
+  GroupPoint->setObjectName( "GroupPoint" );
   GroupPoint->setTitle( tr("Base point") );
-  GroupPoint->setColumnLayout(0, Qt::Vertical );
-  GroupPoint->layout()->setSpacing( 0 );
-  GroupPoint->layout()->setMargin( 0 );
-  QGridLayout* GroupPointLayout = new QGridLayout( GroupPoint->layout() );
+  QGridLayout* GroupPointLayout = new QGridLayout( GroupPoint );
   GroupPointLayout->setAlignment( Qt::AlignTop );
   GroupPointLayout->setSpacing( 6 );
   GroupPointLayout->setMargin( 11 );
   
   // Controls
-  const double min = -1e+16;
-  const double max =  1e+16;
+  const double min = -1e+7;
+  const double max =  1e+7;
   const double step = 5;
-  const int precision = -6; // PAL12789. Minus is for using 'g' double->string conversion specifier,
-  //                          see QtxDblSpinBox::mapValueToText( double v )
+  const int precision = -7;
 
-  TextLabelX = new QLabel( GroupPoint, "TextLabelX" );
+  TextLabelX = new QLabel( GroupPoint );
+  TextLabelX->setObjectName( "TextLabelX" );
   TextLabelX->setText( tr("X:") );
   GroupPointLayout->addWidget( TextLabelX, 0, 0 );
   
-  SpinBox_X = new QtxDblSpinBox( min, max, step, GroupPoint, "SpinBox_X" );
+  SpinBox_X = new QtxDoubleSpinBox( min, max, step, GroupPoint );
+  SpinBox_X->setObjectName("SpinBox_X" );
   SpinBox_X->setPrecision( precision );
   GroupPointLayout->addWidget( SpinBox_X, 0, 1 );
 
-  TextLabelY = new QLabel( GroupPoint, "TextLabelY" );
+  TextLabelY = new QLabel( GroupPoint );
+  TextLabelY->setObjectName( "TextLabelY" );
   TextLabelY->setText( tr("Y:") );
   GroupPointLayout->addWidget( TextLabelY, 0, 2 );
 
-  SpinBox_Y = new QtxDblSpinBox( min, max, step, GroupPoint, "SpinBox_Y" );
+  SpinBox_Y = new QtxDoubleSpinBox( min, max, step, GroupPoint );
+  SpinBox_Y->setObjectName("SpinBox_Y" );
   SpinBox_Y->setPrecision( precision );
   GroupPointLayout->addWidget( SpinBox_Y, 0, 3 );
 
-  TextLabelZ = new QLabel( GroupPoint, "TextLabelZ" );
+  TextLabelZ = new QLabel( GroupPoint );
+  TextLabelZ->setObjectName( "TextLabelZ" );
   TextLabelZ->setText( tr("Z:") );
   GroupPointLayout->addWidget( TextLabelZ, 0, 4 );
 
-  SpinBox_Z = new QtxDblSpinBox( min, max, step, GroupPoint, "SpinBox_Z" );
+  SpinBox_Z = new QtxDoubleSpinBox( min, max, step, GroupPoint );
+  SpinBox_Z->setObjectName("SpinBox_Z" );
   SpinBox_Z->setPrecision( precision );
   GroupPointLayout->addWidget( SpinBox_Z, 0, 5 );
 
-  resetButton  = new QPushButton( GroupPoint, "resetButton" );
+  resetButton  = new QPushButton( GroupPoint );
+  resetButton->setObjectName( "resetButton" );
   resetButton->setText( tr( "Reset"  ) );
   GroupPointLayout->addWidget( resetButton, 0, 6 );
 
   /***************************************************************/
-  GroupDirection = new QGroupBox( this, "GroupDirection" );
+  GroupDirection = new QGroupBox( this );
+  GroupDirection->setObjectName( "GroupDirection" );
   GroupDirection->setTitle( tr("Direction") );
-  GroupDirection->setColumnLayout(0, Qt::Vertical );
-  GroupDirection->layout()->setSpacing( 0 );
-  GroupDirection->layout()->setMargin( 0 );
-  QGridLayout* GroupDirectionLayout = new QGridLayout( GroupDirection->layout() );
+  QGridLayout* GroupDirectionLayout = new QGridLayout( GroupDirection );
   GroupDirectionLayout->setAlignment( Qt::AlignTop );
   GroupDirectionLayout->setSpacing( 6 );
   GroupDirectionLayout->setMargin( 11 );
   
   // Controls
-  TextLabelDx = new QLabel( GroupDirection, "TextLabelDx" );
+  TextLabelDx = new QLabel( GroupDirection );
+  TextLabelDx->setObjectName( "TextLabelDx" );
   TextLabelDx->setText( tr("Dx:") );
   GroupDirectionLayout->addWidget( TextLabelDx, 0, 0 );
   
-  SpinBox_Dx = new QtxDblSpinBox( min, max, step, GroupDirection, "SpinBox_Dx" );
+  SpinBox_Dx = new QtxDoubleSpinBox( min, max, step, GroupDirection );
+  SpinBox_Dx->setObjectName("SpinBox_Dx" );
   SpinBox_Dx->setPrecision( precision );
   GroupDirectionLayout->addWidget( SpinBox_Dx, 0, 1 );
 
-  TextLabelDy = new QLabel( GroupDirection, "TextLabelDy" );
+  TextLabelDy = new QLabel( GroupDirection );
+  TextLabelDy->setObjectName( "TextLabelDy" );
   TextLabelDy->setText( tr("Dy:") );
   GroupDirectionLayout->addWidget( TextLabelDy, 0, 2 );
   
-  SpinBox_Dy = new QtxDblSpinBox( min, max, step, GroupDirection, "SpinBox_Dy" );
+  SpinBox_Dy = new QtxDoubleSpinBox( min, max, step, GroupDirection );
+  SpinBox_Dy->setObjectName("SpinBox_Dy" );
   SpinBox_Dy->setPrecision( precision );
   GroupDirectionLayout->addWidget( SpinBox_Dy, 0, 3 );
 
-  TextLabelDz = new QLabel( GroupDirection, "TextLabelDz" );
+  TextLabelDz = new QLabel( GroupDirection );
+  TextLabelDz->setObjectName( "TextLabelDz" );
   TextLabelDz->setText( tr("Dz:") );
   GroupDirectionLayout->addWidget( TextLabelDz, 0, 4 );
   
-  SpinBox_Dz = new QtxDblSpinBox( min, max, step, GroupDirection, "SpinBox_Dz" );
+  SpinBox_Dz = new QtxDoubleSpinBox( min, max, step, GroupDirection );
+  SpinBox_Dz->setObjectName("SpinBox_Dz" );
   SpinBox_Dz->setPrecision( precision );
   GroupDirectionLayout->addWidget( SpinBox_Dz, 0, 5 );
 
-  invertButton  = new QPushButton( GroupDirection, "invertButton" );
+  invertButton  = new QPushButton( GroupDirection );
+  invertButton->setObjectName( "invertButton" );
   invertButton->setText( tr( "Invert"  ) );
   GroupDirectionLayout->addWidget( invertButton, 0, 6 );
  
-  DirectionCB = new QComboBox( GroupDirection, "DirectionCB" );
-  DirectionCB->insertItem(tr("CUSTOM"));
-  DirectionCB->insertItem(tr("||X-Y"));
-  DirectionCB->insertItem(tr("||Y-Z"));
-  DirectionCB->insertItem(tr("||Z-X"));
-  GroupDirectionLayout->addMultiCellWidget( DirectionCB, 1, 1, 0, 5 );
+  DirectionCB = new QComboBox( GroupDirection );
+  DirectionCB->setObjectName( "DirectionCB" );
+  DirectionCB->insertItem(DirectionCB->count(),tr("CUSTOM"));
+  DirectionCB->insertItem(DirectionCB->count(),tr("||X-Y"));
+  DirectionCB->insertItem(DirectionCB->count(),tr("||Y-Z"));
+  DirectionCB->insertItem(DirectionCB->count(),tr("||Z-X"));
+  GroupDirectionLayout->addWidget( DirectionCB, 1, 0, 1, 6 );
   
   /***************************************************************/
   
-  PreviewChB = new QCheckBox( tr("Preview") ,this, "PreviewChB" );
+  PreviewChB = new QCheckBox( tr("Preview") ,this );
+  PreviewChB->setObjectName( "PreviewChB" );
   PreviewChB->setChecked( true );
   
   /***************************************************************/
-  QGroupBox* GroupButtons = new QGroupBox( this, "GroupButtons" );
-  GroupButtons->setColumnLayout(0, Qt::Vertical );
-  GroupButtons->layout()->setMargin( 0 ); GroupButtons->layout()->setSpacing( 0 ); 
-  QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons->layout() );
+  QGroupBox* GroupButtons = new QGroupBox( this );
+  GroupButtons->setObjectName( "GroupButtons" );
+  QHBoxLayout* GroupButtonsLayout = new QHBoxLayout( GroupButtons );
   GroupButtonsLayout->setAlignment( Qt::AlignTop );
   GroupButtonsLayout->setMargin( 11 ); GroupButtonsLayout->setSpacing( 6 );
   
-  buttonApply = new QPushButton( GroupButtons, "buttonApply" );
+  buttonApply = new QPushButton( GroupButtons );
+  buttonApply->setObjectName( "buttonApply" );
   buttonApply->setText( tr( "BUT_APPLY"  ) );
   buttonApply->setAutoDefault( TRUE ); 
   buttonApply->setDefault( TRUE );
@@ -178,10 +199,12 @@ OCCViewer_ClippingDlg::OCCViewer_ClippingDlg( OCCViewer_ViewWindow* view, QWidge
   
   GroupButtonsLayout->addStretch();
   
-  buttonClose = new QPushButton( GroupButtons, "buttonClose" );
+  buttonClose = new QPushButton( GroupButtons );
+  buttonClose->setObjectName( "buttonClose" );
   buttonClose->setText( tr( "BUT_CLOSE"  ) );
   buttonClose->setAutoDefault( TRUE );
   GroupButtonsLayout->addWidget( buttonClose );
+
   /***************************************************************/
   
   topLayout->addWidget( GroupPoint );
@@ -243,12 +266,11 @@ void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e )
   erasePreview();
   
   // Set the clipping plane back
-  Handle(V3d_View) aView3d = myView->getViewPort()->getView();
+  /*Handle(V3d_View) aView3d = myView->getViewPort()->getView();
   if ( !aView3d.IsNull() && !myClippingPlane.IsNull() )
-    aView3d->SetPlaneOn( myClippingPlane );
+  aView3d->SetPlaneOn( myClippingPlane );*/
   
-  if (!myView->isCuttingPlane())
-    myAction->setOn( false );
+  myAction->setChecked( false );
   
   QDialog::closeEvent( e );
 }
@@ -259,7 +281,7 @@ void OCCViewer_ClippingDlg::closeEvent( QCloseEvent* e )
 */
 void OCCViewer_ClippingDlg::showEvent( QShowEvent* e )
 {
-  ReserveClippingPlane();
+  //ReserveClippingPlane();
   
   QDialog::showEvent( e );
   onPreview( PreviewChB->isChecked() );
@@ -284,12 +306,11 @@ void OCCViewer_ClippingDlg::ClickOnClose()
   erasePreview();
 
   // Set the clipping plane back
-  Handle(V3d_View) aView3d = myView->getViewPort()->getView();
+  /*Handle(V3d_View) aView3d = myView->getViewPort()->getView();
   if ( !aView3d.IsNull() && !myClippingPlane.IsNull() )
     aView3d->SetPlaneOn( myClippingPlane );
-
-  if (!myView->isCuttingPlane())
-    myAction->setOn( false );
+  */
+  myAction->setChecked( false );
   
   reject();
 }
@@ -305,13 +326,13 @@ void OCCViewer_ClippingDlg::ClickOnApply()
   qApp->processEvents();
   
   myView->setCuttingPlane( true, SpinBox_X->value() , SpinBox_Y->value() , SpinBox_Z->value(),
-                                SpinBox_Dx->value(), SpinBox_Dy->value(), SpinBox_Dz->value() );
+                                 SpinBox_Dx->value(), SpinBox_Dy->value(), SpinBox_Dz->value() );
   
   QApplication::restoreOverrideCursor(); 
   
   erasePreview();
   
-  ReserveClippingPlane();
+  //ReserveClippingPlane();
 }
 
 /*!
@@ -451,9 +472,9 @@ void OCCViewer_ClippingDlg::displayPreview()
         isFound = true;
         double xmin, ymin, zmin, xmax, ymax, zmax;
         aPrs->MinMaxValues( xmin, ymin, zmin, xmax, ymax, zmax );
-        aXMin = QMIN( aXMin, xmin );  aXMax = QMAX( aXMax, xmax );
-        aYMin = QMIN( aYMin, ymin );  aYMax = QMAX( aYMax, ymax );
-        aZMin = QMIN( aZMin, zmin );  aZMax = QMAX( aZMax, zmax );
+        aXMin = qMin( aXMin, xmin );  aXMax = qMax( aXMax, xmax );
+        aYMin = qMin( aYMin, ymin );  aYMax = qMax( aYMax, ymax );
+        aZMin = qMin( aZMin, zmin );  aZMax = qMax( aZMax, zmax );
       }
     }
   }
@@ -476,14 +497,15 @@ void OCCViewer_ClippingDlg::displayPreview()
       
       intersector.Perform( gp_Lin( aCenter, aNormal), gp_Pln( aBasePnt, aNormal), Precision::Confusion() );
       if ( intersector.IsDone() && intersector.NbPoints() == 1 )
-       aBasePnt = intersector.Point( 1 );
+        aBasePnt = intersector.Point( 1 );
     }
   
   myPreviewPlane = new AIS_Plane( new Geom_Plane( aBasePnt, aNormal ) );
   myPreviewPlane->SetSize( aSize, aSize );
   
   // Deactivate clipping planes
-  myView->getViewPort()->getView()->SetPlaneOff();
+  //myView->getViewPort()->getView()->SetPlaneOff();
+  //myView->setPlaneOff();
 
   ic->Display( myPreviewPlane, 1, -1, false );
   ic->SetWidth( myPreviewPlane, 10, false );
@@ -554,18 +576,18 @@ bool OCCViewer_ClippingDlg::isValid()
 */
 void OCCViewer_ClippingDlg::ReserveClippingPlane()
 {
-  Handle(V3d_View) aView3d = myView->getViewPort()->getView();
+  /*Handle(V3d_View) aView3d = myView->getViewPort()->getView();
   if ( !aView3d.IsNull() )
     {
       aView3d->InitActivePlanes();
       if ( aView3d->MoreActivePlanes() )
-       myClippingPlane = aView3d->ActivePlane();
-    }
+        myClippingPlane = aView3d->ActivePlane();
+        }*/
 }
 
 void OCCViewer_ClippingDlg::onViewShow()
 {
-  if(myAction->isOn())
+  if(myAction->isChecked())
     show();
   else
     hide();