X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESHGUI%2FSMESHGUI_ClippingDlg.cxx;h=57ef81746648126217e11be46eaf568696829a23;hp=9078e7b6ebb7106f99143b7f47e5d7fe1a345ef8;hb=88141f757b048eaa5aae0be49faaf274448bbcaf;hpb=824f011cef0dc8fee10a7eaca511e9f61690766b diff --git a/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx b/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx index 9078e7b6e..57ef81746 100644 --- a/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_ClippingDlg.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -6,7 +6,7 @@ // 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. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -32,6 +32,9 @@ #include "SMESHGUI_VTKUtils.h" #include "SMESHGUI_SpinBox.h" +#include +#include + #include #include @@ -79,8 +82,6 @@ #include #include -#include - #define SPACING 6 #define MARGIN 11 #define SIZEFACTOR 1.1 @@ -230,34 +231,37 @@ SMESH::OrientedPlane::~OrientedPlane() myPlaneSource->Delete(); } -/*! - Definition of class ActorItem - */ -class ActorItem : public QListWidgetItem +namespace { -public: - ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) : - QListWidgetItem( theName, theListWidget ), - myActor( theActor ) {} + /*! + Definition of class ActorItem + */ + class ActorItem : public QListWidgetItem + { + public: + ActorItem( SMESH_Actor* theActor, const QString& theName, QListWidget* theListWidget ) : + QListWidgetItem( theName, theListWidget ), + myActor( theActor ) {} - SMESH_Actor* getActor() const { return myActor; } + SMESH_Actor* getActor() const { return myActor; } -private: - SMESH_Actor* myActor; -}; + private: + SMESH_Actor* myActor; + }; -/*! - Definition of class TSetVisibility - */ -struct TSetVisibility { - // Set visibility of cutting plane - TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){} - void operator()(SMESH::TPlaneData& thePlaneData){ - bool anIsEmpty = thePlaneData.ActorList.empty(); - thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty); - } - int myIsVisible; -}; + /*! + Definition of class TSetVisibility + */ + struct TSetVisibility { + // Set visibility of cutting plane + TSetVisibility(int theIsVisible): myIsVisible(theIsVisible){} + void operator()(SMESH::TPlaneData& thePlaneData){ + bool anIsEmpty = thePlaneData.ActorList.empty(); + thePlaneData.Plane.GetPointer()->myActor->SetVisibility(myIsVisible && !anIsEmpty); + } + int myIsVisible; + }; +} /********************************************************************************* ********************* class SMESHGUI_ClippingDlg ********************* @@ -465,72 +469,38 @@ SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow CBRelativeOrientation->addItem( tr("ALONG_ZX") ); GroupParametersLayout->addWidget( CBRelativeOrientation, 0, 1 ); - TLValueDistance = new QLabel( GroupParameters ); - TLValueDistance->setObjectName( "TLValueDistance" ); - TLValueDistance->setAlignment( Qt::AlignCenter ); - TLValueDistance->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - QFont fnt = TLValueDistance->font(); fnt.setBold( true ); TLValueDistance->setFont( fnt ); - GroupParametersLayout->addWidget( TLValueDistance, 1, 1 ); - TextLabelDistance = new QLabel( tr("SMESH_DISTANCE"), GroupParameters ); TextLabelDistance->setObjectName( "TextLabelDistance" ); - GroupParametersLayout->addWidget( TextLabelDistance, 2, 0 ); - - SliderDistance = new QSlider( Qt::Horizontal, GroupParameters ); - SliderDistance->setObjectName( "SliderDistance" ); - SliderDistance->setFocusPolicy( Qt::NoFocus ); - SliderDistance->setMinimumSize( 300, 0 ); - SliderDistance->setMinimum( 0 ); - SliderDistance->setMaximum( 100 ); - SliderDistance->setSingleStep( 1 ); - SliderDistance->setPageStep( 10 ); - SliderDistance->setTracking( false ); - GroupParametersLayout->addWidget( SliderDistance, 2, 1 ); - - TLValueRotation1 = new QLabel( GroupParameters ); - TLValueRotation1->setObjectName( "TLValueRotation1" ); - TLValueRotation1->setAlignment( Qt::AlignCenter ); - TLValueRotation1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - TLValueRotation1->setFont( fnt ); - GroupParametersLayout->addWidget( TLValueRotation1, 3, 1 ); + GroupParametersLayout->addWidget( TextLabelDistance, 1, 0 ); + + SpinSliderDistance = new QtxDoubleSpinSlider( 0., 1., 0.01, GroupParameters ); + SpinSliderDistance->setObjectName( "SpinSliderDistance" ); + SpinSliderDistance->setPrecision( precision ); + QFont fnt = SpinSliderDistance->font(); fnt.setBold( true ); SpinSliderDistance->setFont( fnt ); + GroupParametersLayout->addWidget( SpinSliderDistance, 1, 1 ); + + QString aUnitRot = QString(QChar(0xB0)); TextLabelRotation1 = new QLabel( tr("ROTATION_AROUND_X_Y2Z"), GroupParameters ); TextLabelRotation1->setObjectName( "TextLabelRotation1" ); - GroupParametersLayout->addWidget( TextLabelRotation1, 4, 0 ); - - SliderRotation1 = new QSlider( Qt::Horizontal, GroupParameters ); - SliderRotation1->setObjectName( "SliderRotation1" ); - SliderRotation1->setFocusPolicy( Qt::NoFocus ); - SliderRotation1->setMinimumSize( 300, 0 ); - SliderRotation1->setMinimum( -180 ); - SliderRotation1->setMaximum( 180 ); - SliderRotation1->setSingleStep( 1 ); - SliderRotation1->setPageStep( 10 ); - SliderRotation1->setTracking(false); - GroupParametersLayout->addWidget( SliderRotation1, 4, 1 ); - - TLValueRotation2 = new QLabel( GroupParameters ); - TLValueRotation2->setObjectName( "TLValueRotation2" ); - TLValueRotation2->setAlignment( Qt::AlignCenter ); - TLValueRotation2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) ); - TLValueRotation2->setFont( fnt ); - GroupParametersLayout->addWidget( TLValueRotation2, 5, 1 ); + GroupParametersLayout->addWidget( TextLabelRotation1, 2, 0 ); + + SpinSliderRotation1 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters ); + SpinSliderRotation1->setObjectName( "SpinSliderRotation1" ); + SpinSliderRotation1->setUnit( aUnitRot ); + SpinSliderRotation1->setFont( fnt ); + GroupParametersLayout->addWidget( SpinSliderRotation1, 2, 1 ); TextLabelRotation2 = new QLabel(tr("ROTATION_AROUND_Y_X2Z"), GroupParameters); TextLabelRotation2->setObjectName( "TextLabelRotation2" ); TextLabelRotation2->setObjectName( "TextLabelRotation2" ); - GroupParametersLayout->addWidget( TextLabelRotation2, 6, 0 ); - - SliderRotation2 = new QSlider( Qt::Horizontal, GroupParameters ); - SliderRotation2->setObjectName( "SliderRotation2" ); - SliderRotation2->setFocusPolicy( Qt::NoFocus ); - SliderRotation2->setMinimumSize( 300, 0 ); - SliderRotation2->setMinimum( -180 ); - SliderRotation2->setMaximum( 180 ); - SliderRotation2->setSingleStep( 1 ); - SliderRotation2->setPageStep( 10 ); - SliderRotation2->setTracking(false); - GroupParametersLayout->addWidget( SliderRotation2, 6, 1 ); + GroupParametersLayout->addWidget( TextLabelRotation2, 3, 0 ); + + SpinSliderRotation2 = new QtxIntSpinSlider( -180, 180, 1, GroupParameters ); + SpinSliderRotation2->setObjectName( "SpinSliderRotation2" ); + SpinSliderRotation2->setUnit( aUnitRot ); + SpinSliderRotation2->setFont( fnt ); + GroupParametersLayout->addWidget( SpinSliderRotation2, 3, 1 ); /***************************************************************/ QWidget* CheckBoxWidget = new QWidget( this ); @@ -582,7 +552,7 @@ SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow myIsSelectPlane = false; - myHelpFileName = "clipping_page.html"; + myHelpFileName = "clipping.html"; // signals and slots connections : connect( ComboBoxPlanes, SIGNAL( activated( int ) ), this, SLOT( onSelectPlane( int ) ) ); @@ -603,12 +573,9 @@ SMESHGUI_ClippingDlg::SMESHGUI_ClippingDlg( SMESHGUI* theModule, SVTK_ViewWindow connect( CBAbsoluteOrientation, SIGNAL ( activated ( int ) ), this, SLOT( onSelectAbsoluteOrientation( int ) ) ) ; connect( CBRelativeOrientation, SIGNAL( activated( int ) ), this, SLOT( onSelectRelativeOrientation( int ) ) ); - connect( SliderDistance, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) ); - connect( SliderDistance, SIGNAL( valueChanged( int ) ), this, SLOT( SliderDistanceHasMoved( int ) ) ); - connect( SliderRotation1, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) ); - connect( SliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation1HasMoved( int ) ) ); - connect( SliderRotation2, SIGNAL( sliderMoved( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) ); - connect( SliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SliderRotation2HasMoved( int ) ) ); + connect( SpinSliderDistance, SIGNAL( valueChanged( double ) ), this, SLOT( SetCurrentPlaneParam() ) ); + connect( SpinSliderRotation1, SIGNAL( valueChanged( int ) ), this, SLOT( SetCurrentPlaneParam() ) ); + connect( SpinSliderRotation2, SIGNAL( valueChanged( int ) ), this, SLOT( SetCurrentPlaneParam() ) ); connect( PreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( OnPreviewToggle( bool ) ) ); connect( AutoApplyCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onAutoApply( bool ) ) ); @@ -637,12 +604,12 @@ SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg() if (myViewWindow) SMESH::RenderViewWindow(myViewWindow); - for( int i=0; i< myPlanes.size(); i++ ) { + for ( size_t i = 0; i < myPlanes.size(); i++ ) { SMESH::TPlaneData aPlaneData = myPlanes[i]; aPlaneData.Plane->Delete(); } - if (myPreviewWidget) { + if ( myPreviewWidget ) { myPreviewWidget->Off(); myPreviewWidget->Delete(); } @@ -657,7 +624,7 @@ SMESHGUI_ClippingDlg::~SMESHGUI_ClippingDlg() */ double SMESHGUI_ClippingDlg::getDistance() const { - return TLValueDistance->text().toDouble(); + return SpinSliderDistance->value(); } /*! @@ -665,7 +632,7 @@ double SMESHGUI_ClippingDlg::getDistance() const */ void SMESHGUI_ClippingDlg::setDistance( const double theDistance ) { - SliderDistance->setValue( theDistance*100 ); + SpinSliderDistance->setValue( theDistance ); } /*! @@ -673,7 +640,7 @@ void SMESHGUI_ClippingDlg::setDistance( const double theDistance ) */ double SMESHGUI_ClippingDlg::getRotation1() const { - return TLValueRotation1->text().remove("\xB0").toInt(); + return SpinSliderRotation1->value(); } /*! @@ -681,7 +648,7 @@ double SMESHGUI_ClippingDlg::getRotation1() const */ double SMESHGUI_ClippingDlg::getRotation2() const { - return TLValueRotation2->text().remove("\xB0").toInt(); + return SpinSliderRotation2->value(); } /*! @@ -689,8 +656,8 @@ double SMESHGUI_ClippingDlg::getRotation2() const */ void SMESHGUI_ClippingDlg::setRotation (const double theRot1, const double theRot2) { - SliderRotation1->setValue( theRot1 ); - SliderRotation2->setValue( theRot2 ); + SpinSliderRotation1->setValue( int(floor(theRot1)) ); + SpinSliderRotation2->setValue( int(floor(theRot2)) ); } /*! @@ -749,46 +716,66 @@ vtkImplicitPlaneWidget* SMESHGUI_ClippingDlg::createPreviewWidget() return aPlaneWgt; } -/*! - Translate two angles of plane to normal -*/ -void rotationToNormal ( double theRotation[2], - int theOrientation, - double theNormal[3], - double theDir[2][3] ) +namespace { - static double aCoeff = M_PI/180.0; - - double anU[2] = { cos( aCoeff * theRotation[0] ), cos( aCoeff * theRotation[1] ) }; - double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) }; - aV[0] = theRotation[0] > 0? aV[0]: -aV[0]; - aV[1] = theRotation[1] > 0? aV[1]: -aV[1]; + /*! + Translate two angles of plane to normal + */ + void rotationToNormal ( double theRotation[2], + int theOrientation, + double theNormal[3], + double theDir[2][3] ) + { + static double aCoeff = M_PI/180.0; + + double anU[2] = { cos( aCoeff * theRotation[0] ), cos( aCoeff * theRotation[1] ) }; + double aV[2] = { sqrt( 1.0 - anU[0]*anU[0] ), sqrt( 1.0 - anU[1] * anU[1] ) }; + aV[0] = theRotation[0] > 0? aV[0]: -aV[0]; + aV[1] = theRotation[1] > 0? aV[1]: -aV[1]; + + switch ( theOrientation ) { + case 0: + case 1: + theDir[0][1] = anU[0]; + theDir[0][2] = aV[0]; + theDir[1][0] = anU[1]; + theDir[1][2] = aV[1]; + break; + case 2: + theDir[0][2] = anU[0]; + theDir[0][0] = aV[0]; + theDir[1][1] = anU[1]; + theDir[1][0] = aV[1]; + break; + case 3: + theDir[0][0] = anU[0]; + theDir[0][1] = aV[0]; + theDir[1][2] = anU[1]; + theDir[1][1] = aV[1]; + break; + } - switch ( theOrientation ) { - case 0: - case 1: - theDir[0][1] = anU[0]; - theDir[0][2] = aV[0]; - theDir[1][0] = anU[1]; - theDir[1][2] = aV[1]; - break; - case 2: - theDir[0][2] = anU[0]; - theDir[0][0] = aV[0]; - theDir[1][1] = anU[1]; - theDir[1][0] = aV[1]; - break; - case 3: - theDir[0][0] = anU[0]; - theDir[0][1] = aV[0]; - theDir[1][2] = anU[1]; - theDir[1][1] = aV[1]; - break; + vtkMath::Cross( theDir[1], theDir[0], theNormal ); + vtkMath::Normalize( theNormal ); + vtkMath::Cross( theNormal, theDir[1], theDir[0] ); } - vtkMath::Cross( theDir[1], theDir[0], theNormal ); - vtkMath::Normalize( theNormal ); - vtkMath::Cross( theNormal, theDir[1], theDir[0] ); + /*! + * \brief Return a name of a father mesh if any + */ + QString getFatherName( _PTR(SObject)& theSObj ) + { + _PTR(SComponent) objComponent = theSObj->GetFatherComponent(); + const int theMeshDepth = 1 + objComponent->Depth(); + if ( theSObj->Depth() <= theMeshDepth ) + return QString(); // theSObj is a mesh + + _PTR(SObject) sobj = theSObj->GetFather(); + while ( sobj && sobj->Depth() > theMeshDepth ) + sobj = sobj->GetFather(); + + return sobj ? sobj->GetName().c_str() : ""; + } } /*! @@ -802,14 +789,14 @@ bool SMESHGUI_ClippingDlg::AddPlane ( SMESH::TActorList theActorList, double aDir[2][3] = {{0, 0, 0}, {0, 0, 0}}; static double aCoeff = vtkMath::Pi()/180.0; - int anOrientation; + int anOrientation = 0; if ( thePlane->PlaneMode == SMESH::Absolute ) - anOrientation = thePlane->myAbsoluteOrientation; + anOrientation = thePlane->myAbsoluteOrientation; else if ( thePlane->PlaneMode == SMESH::Relative ) - anOrientation = thePlane->myRelativeOrientation + 1; + anOrientation = thePlane->myRelativeOrientation + 1; if ( anOrientation == 0 ) { - // compute a direction for plane in absolute mode + // compute a direction for plane in absolute mode double znam = sqrt( thePlane->Dx*thePlane->Dx + thePlane->Dy*thePlane->Dy + thePlane->Dz*thePlane->Dz ); double aRotation = acos( thePlane->Dy/znam )/aCoeff; if ( thePlane->Dy >= 0.0 && thePlane->Dz >= 0.0 ) thePlane->myAngle[0] = 90.0 + aRotation; @@ -910,10 +897,10 @@ bool SMESHGUI_ClippingDlg::AddPlane ( SMESH::TActorList theActorList, for ( ; anIter != theActorList.end(); anIter++ ) if( vtkActor* aVTKActor = *anIter ) if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) { - if( thePlane->IsOpenGLClipping ) + if( thePlane->IsOpenGLClipping ) anActor->AddOpenGLClippingPlane( thePlane->InvertPlane() ); - else - anActor->AddClippingPlane( thePlane ); + else + anActor->AddClippingPlane( thePlane ); } return true; @@ -1013,13 +1000,10 @@ void SMESHGUI_ClippingDlg::initParam() CBAbsoluteOrientation->setCurrentIndex(0); - TLValueDistance->setText( "0.5" ); - TLValueRotation1->setText( "0\xB0" ); - TLValueRotation2->setText( "0\xB0" ); + SpinSliderDistance->setValue( 0.5 ); + SpinSliderRotation1->setValue( 0 ); + SpinSliderRotation2->setValue( 0 ); CBRelativeOrientation->setCurrentIndex( 0 ); - SliderDistance->setValue( 50 ); - SliderRotation1->setValue( 0 ); - SliderRotation2->setValue( 0 ); } /*! @@ -1071,9 +1055,9 @@ void SMESHGUI_ClippingDlg::synchronize() } else if ( CurrentMode == SMESH::Relative ) { CBRelativeOrientation->setEnabled( anIsControlsEnable ); - SliderDistance->setEnabled( anIsControlsEnable ); - SliderRotation1->setEnabled( anIsControlsEnable ); - SliderRotation2->setEnabled( anIsControlsEnable ); + SpinSliderDistance->setEnabled( anIsControlsEnable ); + SpinSliderRotation1->setEnabled( anIsControlsEnable ); + SpinSliderRotation2->setEnabled( anIsControlsEnable ); } } @@ -1102,6 +1086,8 @@ void SMESHGUI_ClippingDlg::updateActorList() std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) ); aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false ); + std::map< std::string, QListWidgetItem* > itemMap; // used to sort items by entry + VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() ); vtkActorCollection* anAllActors = aCopy.GetActors(); anAllActors->InitTraversal(); @@ -1123,13 +1109,24 @@ void SMESHGUI_ClippingDlg::updateActorList() } } QString aName = QString( aSObj->GetName().c_str() ); - QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList ); + QString aFatherName = getFatherName( aSObj ); + if ( !aFatherName.isEmpty() ) + aName = aFatherName + " / " + aName; + aName += QString(" (%1)").arg( aSObj->GetID().c_str() ); + QListWidgetItem* anItem = new ActorItem( anActor, aName, 0 ); anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked ); - updateActorItem( anItem, true, false ); + itemMap.insert( std::make_pair( aSObj->GetID(), anItem )); } } } } + std::map< std::string, QListWidgetItem* >::iterator s2i = itemMap.begin(); + for ( ; s2i != itemMap.end(); ++s2i ) + { + QListWidgetItem* anItem = s2i->second; + ActorList->addItem( anItem ); + } + updateActorItem( 0, true, false ); } /*! @@ -1172,9 +1169,14 @@ void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem, else if( theItem->checkState() == Qt::Unchecked && anIsPushed ) anActorList.remove( anActor ); - SMESH::ComputeBounds( anActorList, myBounds ); - myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2], - myBounds[3], myBounds[4], myBounds[5] ); + if( SMESH::ComputeBounds( anActorList, myBounds ) ) { + myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2], + myBounds[3], myBounds[4], myBounds[5] ); + if( PreviewCheckBox->isChecked() ) + myPreviewWidget->On(); + } + else + myPreviewWidget->Off(); } } } @@ -1265,16 +1267,19 @@ void SMESHGUI_ClippingDlg::ClickOnNew() SMESH::OrientedPlane* aPlane = SMESH::OrientedPlane::New(myViewWindow); SMESH::TPlane aTPlane(aPlane); aPlane->PlaneMode = CurrentMode; - SMESH::TActorList anActorList; + SMESH::TActorList anActorList, aVisibleActorList; VTK::ActorCollectionCopy aCopy( myViewWindow->getRenderer()->GetActors() ); vtkActorCollection* anAllActors = aCopy.GetActors(); anAllActors->InitTraversal(); while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) + { anActorList.push_back( anActor ); - - SMESH::TPlaneData aPlaneData(aTPlane, anActorList); - + if ( anActor->GetVisibility() ) + aVisibleActorList.push_back( anActor ); + } + SMESH::TPlaneData aPlaneData(aTPlane, + aVisibleActorList.empty() ? anActorList : aVisibleActorList); myPlanes.push_back(aPlaneData); @@ -1283,9 +1288,15 @@ void SMESHGUI_ClippingDlg::ClickOnNew() bool anIsBlocked = ActorList->blockSignals( true ); - SMESH::ComputeBounds( anActorList, myBounds ); - myPreviewWidget->PlaceWidget( myBounds[0],myBounds[1],myBounds[2], - myBounds[3],myBounds[4],myBounds[5] ); + if( SMESH::ComputeBounds( anActorList, myBounds ) ) { + myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2], + myBounds[3], myBounds[4], myBounds[5] ); + if( PreviewCheckBox->isChecked() ) + myPreviewWidget->On(); + } + else + myPreviewWidget->Off(); + synchronize(); SetCurrentPlaneParam(); @@ -1370,9 +1381,16 @@ void SMESHGUI_ClippingDlg::onSelectPlane ( int theIndex ) } } myIsSelectPlane = false; - SMESH::ComputeBounds( aPlaneData.ActorList, myBounds ); - myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2], - myBounds[3], myBounds[4], myBounds[5] ); + + if( SMESH::ComputeBounds( aPlaneData.ActorList, myBounds ) ) { + myPreviewWidget->PlaceWidget( myBounds[0], myBounds[1], myBounds[2], + myBounds[3], myBounds[4], myBounds[5] ); + if( PreviewCheckBox->isChecked() ) + myPreviewWidget->On(); + } + else + myPreviewWidget->Off(); + SetCurrentPlaneParam(); // Actors @@ -1457,11 +1475,11 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam() static double aCoeff = vtkMath::Pi()/180.0; double aRot[2] = { getRotation1(), getRotation2() }; - int anOrient; + int anOrient = 0; if ( aPlane->PlaneMode == SMESH::Absolute ) - anOrient = CBAbsoluteOrientation->currentIndex(); + anOrient = CBAbsoluteOrientation->currentIndex(); else if ( aPlane->PlaneMode == SMESH::Relative ) - anOrient = CBRelativeOrientation->currentIndex() + 1; + anOrient = CBRelativeOrientation->currentIndex() + 1; if ( aPlane->PlaneMode == SMESH::Relative ) { aPlane->myAngle[0] = aRot[0]; @@ -1471,7 +1489,7 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam() } if ( anOrient == 0 ) { - // compute a direction for plane in absolute mode + // compute a direction for plane in absolute mode double znam = sqrt( aPlane->Dx*aPlane->Dx + aPlane->Dy*aPlane->Dy + aPlane->Dz*aPlane->Dz ); double aRotation = acos( aPlane->Dy/znam )/aCoeff; if ( aPlane->Dy >= 0.0 && aPlane->Dz >= 0.0 ) aRot[0] = 90.0 + aRotation; @@ -1513,7 +1531,7 @@ void SMESHGUI_ClippingDlg::SetCurrentPlaneParam() anOrigin[1] = aPlane->Y; anOrigin[2] = aPlane->Z; } - + if( anIsOk ) { aPlane->SetNormal( aNormal ); aPlane->SetOrigin( anOrigin ); @@ -1619,7 +1637,7 @@ void SMESHGUI_ClippingDlg::setBoundsForPreviewWidget() if( anOrigin[2] < aBounds[4] ) { myBounds[4] = anOrigin[2]; isBoundsChanged = true; } if( anOrigin[2] > aBounds[5] ) { - myBounds[5] = anOrigin[2]; isBoundsChanged = true; } + myBounds[5] = anOrigin[2]; isBoundsChanged = true; } } if( isBoundsChanged ) @@ -1644,8 +1662,8 @@ void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double double eps = 0.0001; int anOrientation = CBRelativeOrientation->currentIndex(); - double aDirection[3]; - double aRotation1, aRotation2; + double aDirection[3] = { 0.,0.,0. }; + double aRotation1 = 0, aRotation2 = 0; switch( anOrientation ) { case 0: aDirection[0] = theDir[0] + eps; @@ -1703,10 +1721,8 @@ void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double else if( aDirection[0] < 0 && aDirection[1] < 0 && aDirection[2] < 0 && aRot[0] > 0 ) { aRot[0] = aRotation1 + 270.0; aRot[1] = aRotation2 + 90.0; } - SliderRotation1HasMoved( round( aRot[0] ) ); - SliderRotation1->setValue( round( aRot[0] ) ); - SliderRotation2HasMoved( round( aRot[1] ) ); - SliderRotation2->setValue( round( aRot[1] ) ); + SpinSliderRotation1->setValue( qRound( aRot[0] ) ); + SpinSliderRotation2->setValue( qRound( aRot[1] ) ); int aCurPlaneIndex = ComboBoxPlanes->currentIndex(); const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ]; @@ -1722,8 +1738,7 @@ void SMESHGUI_ClippingDlg::absolutePlaneToRelative ( double theOrigin[3], double else if( aDist < 0.0 ) aDist = 0.0; - SliderDistanceHasMoved( round( aDist*100 ) ); - SliderDistance->setValue( round( aDist*100 ) ); + SpinSliderDistance->setValue( qRound( aDist*100 ) ); return; } @@ -1808,10 +1823,10 @@ void SMESHGUI_ClippingDlg::ClickOnApply() for( ; anIter3 != anActorList.end(); anIter3++ ) if( vtkActor* aVTKActor = *anIter3 ) if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) { - if( anOrientedPlane->IsOpenGLClipping ) + if( anOrientedPlane->IsOpenGLClipping ) anActor->AddOpenGLClippingPlane( anOrientedPlane->InvertPlane() ); - else - anActor->AddClippingPlane( anOrientedPlane ); + else + anActor->AddClippingPlane( anOrientedPlane ); } SMESH::ClippingPlaneInfo aClippingPlaneInfo; @@ -1821,11 +1836,9 @@ void SMESHGUI_ClippingDlg::ClickOnApply() aClippingPlaneInfoList.push_back( aClippingPlaneInfo ); } - SMESH_Actor* anSMESHActor; anAllActors->InitTraversal(); while( vtkActor* aVTKActor = anAllActors->GetNextActor() ) if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) ) { - anSMESHActor = anActor; anActor->SetOpenGLClippingPlane(); } @@ -1856,34 +1869,6 @@ void SMESHGUI_ClippingDlg::ClickOnHelp() } } -/*! - SLOT: Called when value of slider distance change -*/ -void SMESHGUI_ClippingDlg::SliderDistanceHasMoved( int value ) -{ - double new_value = value/100.; - TLValueDistance->setText( QString("%1").arg( new_value ) ); - SetCurrentPlaneParam(); -} - -/*! - SLOT: Called when value of slider rotation1 change -*/ -void SMESHGUI_ClippingDlg::SliderRotation1HasMoved( int value ) -{ - TLValueRotation1->setText( QString("%1\xB0").arg( value ) ); - SetCurrentPlaneParam(); -} - -/*! - SLOT: Called when value of slider rotation2 change -*/ -void SMESHGUI_ClippingDlg::SliderRotation2HasMoved( int value ) -{ - TLValueRotation2->setText( QString("%1\xB0").arg( value ) ); - SetCurrentPlaneParam(); -} - void SMESHGUI_ClippingDlg::onSelectAbsoluteOrientation( int mode ) { bool isUserMode = (mode==0);