+
+int SMESHGUI_SplitVolumesDlg::nbElemsInMesh()
+{
+ return isIntoPrisms() ? myMesh->NbHexas() : myMesh->NbVolumes() - myMesh->NbTetras();
+}
+
+bool SMESHGUI_SplitVolumesDlg::isIntoPrisms()
+{
+ return ( myEntityTypeGrp->checkedId() == 1 );
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when a target element type changes
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::on3d2dChanged(int isPrism)
+{
+ if ( isPrism )
+ {
+ myFacetSelGrp->show();
+ myAllDomainsChk->show();
+ myGroupChoice->button(2)->hide();
+ myGroupChoice->button(0)->setText( tr("SPLIT_HEX_TO_2_PRISMS"));
+ myGroupChoice->button(1)->setText( tr("SPLIT_HEX_TO_4_PRISMS"));
+ }
+ else
+ {
+ myFacetSelGrp->hide();
+ myAllDomainsChk->hide();
+ myGroupChoice->button(2)->show();
+ myGroupChoice->button(0)->setText( tr("SPLIT_HEX_TO_5_TETRA"));
+ myGroupChoice->button(1)->setText( tr("SPLIT_HEX_TO_6_TETRA"));
+ myGroupChoice->button(2)->setText( tr("SPLIT_HEX_TO_24_TETRA"));
+ }
+ SMESHGUI_MultiEditDlg::on3d2dChanged( !myEntityType );
+ myEntityType = 1; // == VOLUME
+ myChoiceWidget->hide();
+ myChoiceWidget->show();
+ resize(minimumSizeHint());
+ onSelectionDone();
+}
+
+//================================================================================
+/*!
+ * \brief Set selection mode
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::setSelectionMode()
+{
+ if ( myBusy || !isEnabled() ) return;
+
+ SMESH::RemoveFilters();
+
+ mySelectionMgr->clearFilters();
+
+ if (mySubmeshChk->isChecked()) {
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ aViewWindow->SetSelectionMode(ActorSelection);
+ mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::SUBMESH));
+ myFacetSelBtn->setChecked( false );
+ }
+ else if (myGroupChk->isChecked()) {
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ aViewWindow->SetSelectionMode(ActorSelection);
+ mySelectionMgr->installFilter(new SMESH_TypeFilter(SMESH::GROUP));
+ myFacetSelBtn->setChecked( false );
+ }
+
+ if ( myFacetSelBtn->isChecked() )
+ {
+ // facet selection - select any element
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ aViewWindow->SetSelectionMode( CellSelection );
+ myFilterType = SMESH::AllElementsFilter;
+ }
+ else
+ {
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ aViewWindow->SetSelectionMode( VolumeSelection );
+ if ( isIntoPrisms() )
+ {
+ SMESH::SetFilter(new SMESHGUI_VolumeShapeFilter( SMDSGeom_HEXA ));
+ myFilterType = SMESHGUI_VolumeShapeFilter::GetId( SMDSGeom_HEXA );
+ }
+ else // to tetrahedra
+ {
+ SMESH::SetFilter(new SMESHGUI_VolumesFilter());
+ myFilterType = SMESH::VolumeFilter;
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when selection changed
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::onSelectionDone()
+{
+ if (myBusy || !isEnabled()) return;
+
+ if ( !myFacetSelBtn->isChecked() )
+ {
+ SMESHGUI_MultiEditDlg::onSelectionDone();
+ }
+ else // set point and normal by a selected element
+ {
+ const SALOME_ListIO& aList = mySelector->StoredIObjects();
+ int nbSel = aList.Extent();
+ if (nbSel > 0)
+ {
+ Handle(SALOME_InteractiveObject) anIO = aList.First();
+
+ myActor = SMESH::FindActorByEntry( anIO->getEntry() );
+
+ SMESH::SMESH_Mesh_var aSelMesh = SMESH::GetMeshByIO(anIO);
+ if (!aSelMesh->_is_nil())
+ myMesh = aSelMesh;
+
+ TColStd_IndexedMapOfInteger aMapIndex;
+ mySelector->GetIndex( anIO, aMapIndex );
+ if ( !aMapIndex.IsEmpty() )
+ showFacetByElement( aMapIndex(1) );
+ else if ( myCellSize < 0 )
+ showFacetByElement( 1 );
+ }
+ updateButtons();
+ }
+
+ myCriterionGrp->setEnabled( !myMesh->_is_nil() && nbElemsInMesh() > 0 );
+}
+
+//================================================================================
+/*!
+ * \brief Show facet normal by a selected element
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::showFacetByElement( int elemID )
+{
+ if ( !isIntoPrisms() || !myActor )
+ {
+ mySimulation->SetVisibility( false );
+ return;
+ }
+ SMDS_Mesh* mesh = myActor->GetObject()->GetMesh();
+ const SMDS_MeshElement* elem = mesh->FindElement( elemID );
+ if ( !elem ) return;
+
+ // set point XYZ by the element barycenter
+ gp_XYZ bc( 0,0,0 );
+ Bnd_B3d bbox;
+ SMDS_NodeIteratorPtr nIt = elem->nodeIterator();
+ std::vector< const SMDS_MeshNode* > nodes;
+ nodes.reserve( elem->NbNodes() );
+ while ( nIt->more() )
+ {
+ nodes.push_back( nIt->next() );
+ gp_XYZ p = SMESH_TNodeXYZ( nodes.back() );
+ bc += p;
+ bbox.Add( p );
+ }
+ bc /= nodes.size();
+
+ myPointSpin[0]->SetValue( bc.X() );
+ myPointSpin[1]->SetValue( bc.Y() );
+ myPointSpin[2]->SetValue( bc.Z() );
+
+ // set size
+ myCellSize = sqrt( bbox.SquareExtent() );
+
+ // set normal and size
+ gp_XYZ norm;
+ switch ( elem->GetType())
+ {
+ case SMDSAbs_Edge:
+ {
+ norm = SMESH_TNodeXYZ( nodes[1] ) - SMESH_TNodeXYZ( nodes[0] );
+ break;
+ }
+ case SMDSAbs_Face:
+ {
+ if ( !SMESH_MeshAlgos::FaceNormal( elem, norm, /*normalized=*/false ))
+ return;
+ break;
+ }
+ case SMDSAbs_Volume:
+ {
+ SMDS_VolumeTool vTool( elem );
+ vTool.SetExternalNormal();
+ bool freeFacetFound = false;
+ double n[3];
+ for ( int i = 0; i < vTool.NbFaces() && !freeFacetFound; ++i )
+ if (( freeFacetFound = vTool.IsFreeFace( i )))
+ vTool.GetFaceNormal( i, n[0], n[1], n[2] );
+ if ( !freeFacetFound )
+ vTool.GetFaceNormal( 0, n[0], n[1], n[2] );
+ norm.SetCoord( n[0], n[1], n[2] );
+ break;
+ }
+ default: return;
+ }
+
+ double size = norm.Modulus();
+ if ( size < 1e-20 )
+ return;
+ norm /= size;
+
+ myDirSpin[0]->SetValue( norm.X() );
+ myDirSpin[1]->SetValue( norm.Y() );
+ myDirSpin[2]->SetValue( norm.Z() );
+
+ if ( myCellSize > 0. )
+ updateNormalPreview();
+}
+
+//================================================================================
+/*!
+ * \brief SLOT called when a point or a normal changes
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::updateNormalPreview(const QString&)
+{
+ if ( myCellSize < 0. )
+ {
+ showFacetByElement( 1 );
+ return;
+ }
+
+ gp_Pnt point ( myPointSpin[0]->GetValue(),
+ myPointSpin[1]->GetValue(),
+ myPointSpin[2]->GetValue() );
+ gp_XYZ norm ( myDirSpin[0]->GetValue(),
+ myDirSpin[1]->GetValue(),
+ myDirSpin[2]->GetValue() );
+ if ( norm.Modulus() < 1e-20 )
+ return;
+
+ vtkUnstructuredGrid* grid = mySimulation->GetGrid();
+
+ // Initialize the preview mesh of an arrow
+ if ( grid->GetNumberOfPoints() == 0 )
+ {
+ mySimulation->SetArrowShapeAndNb( /*nb=*/1, /*hLen=*/0.3, /*R=*/0.1, /*start=*/0 );
+ }
+
+ // Compute new coordinates of the grid according to the dialog controls
+
+ gp_Ax1 axis( point, norm );
+ mySimulation->SetArrows( &axis, 4 * myCellSize );
+ mySimulation->SetVisibility(true);
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when facet selection button is clicked
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::onFacetSelection(bool isFacetSelection)
+{
+ setSelectionMode();
+ onSelectionDone();
+ mySelGrp->setEnabled( !isFacetSelection );
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when an || axis button is clicked
+ */
+//================================================================================
+
+void SMESHGUI_SplitVolumesDlg::onSetDir()
+{
+ myDirSpin[0]->SetValue(0.);
+ myDirSpin[1]->SetValue(0.);
+ myDirSpin[2]->SetValue(0.);
+ int i = 0;
+ for ( ; i < 3; ++i )
+ if ( sender() == myAxisBtn[i] )
+ break;
+ if ( i == 3 )
+ i = 0;
+ myDirSpin[i]->SetValue(1.);
+
+ if ( myActor && !myMesh->_is_nil() && myMesh->NbNodes() > 0 )
+ {
+ double b[6];
+ myActor->GetUnstructuredGrid()->GetBounds(b);
+ gp_XYZ center( 0.5 * ( b[0] + b[1] ),
+ 0.5 * ( b[2] + b[3] ),
+ 0.5 * ( b[4] + b[5] ));
+ gp_XYZ point ( myPointSpin[0]->GetValue(),
+ myPointSpin[1]->GetValue(),
+ myPointSpin[2]->GetValue() );
+ gp_XYZ norm ( myDirSpin[0]->GetValue(),
+ myDirSpin[1]->GetValue(),
+ myDirSpin[2]->GetValue() );
+
+ gp_Vec cp( center, point );
+ if ( cp.Dot( norm ) < 0. )
+ myDirSpin[i]->SetValue(-1.);
+ }
+
+ updateNormalPreview();
+}