+/*!
+ Initialize the planes's data when the dialog opened
+*/
+void SMESHGUI_ClippingDlg::initializePlaneData()
+{
+ const SMESHGUI_ClippingPlaneInfoMap& aClippingPlaneInfoMap = mySMESHGUI->getClippingPlaneInfoMap();
+ SMESHGUI_ClippingPlaneInfoMap::const_iterator anIter1 = aClippingPlaneInfoMap.find( myViewWindow->getViewManager() );
+ if( anIter1 != aClippingPlaneInfoMap.end() ) {
+ const SMESHGUI_ClippingPlaneInfoList& aClippingPlaneInfoList = anIter1->second;
+ SMESHGUI_ClippingPlaneInfoList::const_iterator anIter2 = aClippingPlaneInfoList.begin();
+ for( ; anIter2 != aClippingPlaneInfoList.end(); anIter2++ ) {
+ const SMESH::ClippingPlaneInfo& aClippingPlaneInfo = *anIter2;
+ SMESH::OrientedPlane* anOrientedPlane = SMESH::OrientedPlane::New(myViewWindow);
+ anOrientedPlane->ShallowCopy(aClippingPlaneInfo.Plane);
+ SMESH::TPlane aTPlane( anOrientedPlane );
+ SMESH::TPlaneData aPlaneData( aTPlane, aClippingPlaneInfo.ActorList );
+ myPlanes.push_back( aPlaneData );
+ }
+ }
+ std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
+ if( myPlanes.size() )
+ myPreviewWidget->SetEnabled( PreviewCheckBox->isChecked() );
+}
+
+/*!
+ Initialization of initial values of widgets
+*/
+void SMESHGUI_ClippingDlg::initParam()
+{
+ SpinBox_X->setValue( 0.0 );
+ SpinBox_Y->setValue( 0.0 );
+ SpinBox_Z->setValue( 0.0 );
+
+ SpinBox_Dx->setValue( 1.0 );
+ SpinBox_Dy->setValue( 1.0 );
+ SpinBox_Dz->setValue( 1.0 );
+
+ CBAbsoluteOrientation->setCurrentIndex(0);
+
+ TLValueDistance->setText( "0.5" );
+ TLValueRotation1->setText( "0\xB0" );
+ TLValueRotation2->setText( "0\xB0" );
+ CBRelativeOrientation->setCurrentIndex( 0 );
+ SliderDistance->setValue( 50 );
+ SliderRotation1->setValue( 0 );
+ SliderRotation2->setValue( 0 );
+}
+
+/*!
+ Synchronize dialog's widgets with data
+*/
+void SMESHGUI_ClippingDlg::synchronize()
+{
+ int aNbPlanes = myPlanes.size();
+ ComboBoxPlanes->clear();
+
+ QString aName;
+ for( int i = 1; i<=aNbPlanes; i++ ) {
+ aName = QString( tr( "PLANE_NUM" ) ).arg(i);
+ ComboBoxPlanes->addItem( aName );
+ }
+
+ int aPos = ComboBoxPlanes->count() - 1;
+ ComboBoxPlanes->setCurrentIndex( aPos );
+
+ bool anIsControlsEnable = ( aPos >= 0 );
+ if ( anIsControlsEnable ) {
+ onSelectPlane( aPos );
+ updateActorList();
+ if( PreviewCheckBox->isChecked() )
+ myPreviewWidget->On();
+ }
+ else {
+ ComboBoxPlanes->addItem( tr( "NO_PLANES" ) );
+ ActorList->clear();
+ initParam();
+ if( PreviewCheckBox->isChecked() )
+ myPreviewWidget->Off();
+ }
+
+ isOpenGLClipping->setEnabled( anIsControlsEnable );
+ ActorList->setEnabled( anIsControlsEnable );
+ SelectAllCheckBox->setEnabled( anIsControlsEnable );
+ buttonDelete->setEnabled( anIsControlsEnable );
+ if ( CurrentMode == SMESH::Absolute ) {
+ SpinBox_X->setEnabled( anIsControlsEnable );
+ SpinBox_Y->setEnabled( anIsControlsEnable );
+ SpinBox_Z->setEnabled( anIsControlsEnable );
+ SpinBox_Dx->setEnabled( anIsControlsEnable );
+ SpinBox_Dy->setEnabled( anIsControlsEnable );
+ SpinBox_Dz->setEnabled( anIsControlsEnable );
+ CBAbsoluteOrientation->setEnabled( anIsControlsEnable );
+ invertButton->setEnabled( anIsControlsEnable );
+ resetButton->setEnabled( anIsControlsEnable );
+ }
+ else if ( CurrentMode == SMESH::Relative ) {
+ CBRelativeOrientation->setEnabled( anIsControlsEnable );
+ SliderDistance->setEnabled( anIsControlsEnable );
+ SliderRotation1->setEnabled( anIsControlsEnable );
+ SliderRotation2->setEnabled( anIsControlsEnable );
+ }
+}
+
+/*!
+ Update the list of actors
+*/
+void SMESHGUI_ClippingDlg::updateActorList()
+{
+ ActorList->clear();
+
+ SalomeApp_Study* anAppStudy = SMESHGUI::activeStudy();
+ if( !anAppStudy )
+ return;
+
+ _PTR(Study) aStudy = anAppStudy->studyDS();
+ if( !aStudy )
+ return;
+
+ if( !myViewWindow )
+ return;
+
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ const SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
+ const SMESH::TActorList& anActorList = aPlaneData.ActorList;
+
+ std::for_each( myPlanes.begin(),myPlanes.end(), TSetVisibility( PreviewCheckBox->isChecked() ) );
+ aPlaneData.Plane.GetPointer()->myActor->SetVisibility( false );
+
+ 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 ) ) {
+ if( anActor->hasIO() ) {
+ Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+ if( _PTR(SObject) aSObj = aStudy->FindObjectID( anIO->getEntry() ) ) {
+ bool anIsChecked = false;
+ SMESH::TActorList::const_iterator anIter = anActorList.begin();
+ for ( ; anIter != anActorList.end(); anIter++ ) {
+ if( vtkActor* aVTKActorRef = *anIter ) {
+ if( SMESH_Actor* anActorRef = SMESH_Actor::SafeDownCast( aVTKActorRef ) ) {
+ if( anActorRef == anActor ) {
+ anIsChecked = true;
+ break;
+ }
+ }
+ }
+ }
+ QString aName = QString( aSObj->GetName().c_str() );
+ QListWidgetItem* anItem = new ActorItem( anActor, aName, ActorList );
+ anItem->setCheckState( anIsChecked ? Qt::Checked : Qt::Unchecked );
+ updateActorItem( anItem, true, false );
+ }
+ }
+ }
+ }
+}
+
+/*!
+ Update an actor in actor's list
+*/
+void SMESHGUI_ClippingDlg::updateActorItem( QListWidgetItem* theItem,
+ bool theUpdateSelectAll,
+ bool theUpdateClippingPlaneMap )
+{
+ // update Select All check box
+ if( theUpdateSelectAll ) {
+ int aNbItems = ActorList->count(), aNbChecked = 0;
+ for( int i = 0; i < aNbItems; i++ )
+ if( QListWidgetItem* anItem = ActorList->item( i ) )
+ if( anItem->checkState() == Qt::Checked )
+ aNbChecked++;
+
+ bool anIsBlocked = SelectAllCheckBox->blockSignals( true );
+ SelectAllCheckBox->setCheckState( aNbChecked == aNbItems ? Qt::Checked : Qt::Unchecked);
+ SelectAllCheckBox->blockSignals( anIsBlocked );
+ }
+
+ // update clipping plane map
+ if( theUpdateClippingPlaneMap ) {
+ int aCurPlaneIndex = ComboBoxPlanes->currentIndex();
+ if( ActorItem* anItem = dynamic_cast<ActorItem*>( theItem ) ) {
+ if( SMESH_Actor* anActor = anItem->getActor() ) {
+ SMESH::TPlaneData& aPlaneData = myPlanes[ aCurPlaneIndex ];
+ SMESH::TActorList& anActorList = aPlaneData.ActorList;
+ bool anIsPushed = false;
+ SMESH::TActorList::iterator anIter = anActorList.begin();
+ for ( ; anIter != anActorList.end(); anIter++ ) {
+ if( anActor == *anIter ) {
+ anIsPushed = true;
+ break;
+ }
+ }
+ if( theItem->checkState() == Qt::Checked && !anIsPushed )
+ anActorList.push_back( anActor );
+ 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] );
+ }
+ }
+ }
+}
+
+/*!
+ Get the list of current actors
+*/
+SMESH::TActorList SMESHGUI_ClippingDlg::getCurrentActors()
+{
+ SMESH::TActorList anActorList;
+ for( int i = 0, n = ActorList->count(); i < n; i++ )
+ if( ActorItem* anItem = dynamic_cast<ActorItem*>( ActorList->item( i ) ) )
+ if( anItem->checkState() == Qt::Checked )
+ if( SMESH_Actor* anActor = anItem->getActor() )
+ anActorList.push_back( anActor );
+ return anActorList;
+}
+
+/*!
+ Dump the parameters of clipping planes
+*/
+void SMESHGUI_ClippingDlg::dumpPlaneData() const
+{
+ printf( "----------- Plane Data -----------\n" );
+ int anId = 1;
+ SMESH::TPlaneDataVector::const_iterator anIter1 = myPlanes.begin();
+ for ( ; anIter1 != myPlanes.end(); anIter1++, anId++ ) {
+ SMESH::TPlaneData aPlaneData = *anIter1;
+ SMESH::TPlane aPlane = aPlaneData.Plane;
+ double* aNormal = aPlane->GetNormal();
+ double* anOrigin = aPlane->GetOrigin();
+ printf( "Plane N%d:\n", anId );
+ printf( " Normal = ( %f, %f, %f )\n", aNormal[0], aNormal[1], aNormal[2] );
+ printf( " Origin = ( %f, %f, %f )\n", anOrigin[0], anOrigin[1], anOrigin[2] );
+
+ SMESH::TActorList anActorList = aPlaneData.ActorList;
+ SMESH::TActorList::const_iterator anIter2 = anActorList.begin();
+ for ( ; anIter2 != anActorList.end(); anIter2++ ) {
+ if( vtkActor* aVTKActor = *anIter2 ) {
+ if( SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( aVTKActor ) )
+ printf( " - Actor: '%s'\n", anActor->getName() );
+ }
+ else
+ printf( " - Actor: NULL\n");
+ }
+ }
+ printf( "----------------------------------\n" );
+}
+
+/*!
+ SLOT on close button click: rejects dialog
+*/
+void SMESHGUI_ClippingDlg::reject()
+{
+ //here we can insert actions to do at close.
+ QDialog::reject();
+}
+
+/*!
+ Set absolute mode of clipping plane
+*/
+void SMESHGUI_ClippingDlg::onModeAbsolute()
+{
+ ModeStackedLayout->setCurrentIndex(0);
+ CurrentMode = SMESH::Absolute;
+ ClickOnNew();