+namespace
+{
+ const char* getLabelText( int typeIndex, bool objSelection )
+ {
+ const char* typeLbl[3] = { "SMESH_ID_NODES", "SMESH_ID_EDGES", "SMESH_ID_FACES" };
+ const char* obj = "SMESH_OBJECTS";
+ return objSelection ? obj : typeLbl[ typeIndex ];
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Constructor
+ */
+//================================================================================
+
+SMESHGUI_3TypesSelector::SMESHGUI_3TypesSelector( QWidget * parent ):
+ QWidget( parent )
+{
+ SMESHGUI* gui = SMESHGUI::GetSMESHGUI();
+ mySelectionMgr = SMESH::GetSelectionMgr( gui );
+ mySelector = SMESH::GetViewWindow( gui )->GetSelector();
+ myFilterDlg = 0;
+ myIdValidator = new SMESHGUI_IdValidator(this);
+
+ QPixmap image( SMESH::GetResourceMgr( gui )->loadPixmap("SMESH", tr("ICON_SELECT")));
+
+ mySelectBtnGrp = new QButtonGroup( this );
+ mySelectBtnGrp->setExclusive( true );
+
+ QVBoxLayout* mainLayout = new QVBoxLayout( this );
+ mainLayout->setSpacing( SPACING );
+ mainLayout->setMargin( 0 );
+
+ const char* groupLbl[3] = { "SMESH_NODES", "SMESH_EDGES", "SMESH_FACES" };
+
+ for ( int i = 0; i < 3; ++i )
+ {
+ myGroups[i] = new QGroupBox( tr( groupLbl[i] ), this );
+ mainLayout->addWidget( myGroups[i] );
+ QGridLayout* layout = new QGridLayout( myGroups[i] );
+ layout->setSpacing( SPACING );
+ layout->setMargin( MARGIN );
+
+ QPushButton* selBtn = new QPushButton( myGroups[i] );
+ selBtn->setIcon( image );
+ selBtn->setCheckable( true );
+ mySelectBtnGrp->addButton( selBtn, i );
+ myLabel [i] = new QLabel( myGroups[i] );
+ myLineEdit [i] = new QLineEdit( myGroups[i] );
+ myMeshChk [i] = new QCheckBox( tr("SMESH_SELECT_WHOLE_MESH"), myGroups[i] );
+ myFilterBtn[i] = new QPushButton( tr( "SMESH_BUT_FILTER" ), myGroups[i] );
+
+ myLineEdit[i]->setMaxLength(-1);
+ myLabel [i]->setText( tr( getLabelText( i, true )));
+
+ layout->addWidget(myLabel [i], 0, 0);
+ layout->addWidget(selBtn, 0, 1);
+ layout->addWidget(myLineEdit [i], 0, 2, 1, 2);
+ layout->addWidget(myFilterBtn[i], 0, 4);
+ layout->addWidget(myMeshChk [i], 1, 0, 1, 5);
+ layout->setColumnStretch( 2, 10 );
+
+ connect( myMeshChk [i], SIGNAL(toggled(bool)), SLOT(onSelectMesh(bool)));
+ connect( myFilterBtn[i], SIGNAL(clicked()), SLOT(setFilters()));
+ connect( myLineEdit [i], SIGNAL(textChanged(const QString&)), SLOT(onTextChange(const QString&)));
+ myIDSource[i] = new SMESH::ListOfIDSources;
+ }
+ connect( mySelectBtnGrp, SIGNAL(buttonClicked (int)), SLOT(onSelectType(int)));
+ connect(mySelectionMgr, SIGNAL( currentSelectionChanged()), SLOT(selectionIntoArgument()));
+
+ // Costruction of the logical filter for the elements: mesh/sub-mesh/group
+ QList<SUIT_SelectionFilter*> aListOfFilters;
+ aListOfFilters.append(new SMESH_TypeFilter (SMESH::MESH));
+ aListOfFilters.append(new SMESH_TypeFilter (SMESH::SUBMESH_VERTEX));
+ aListOfFilters.append(new SMESH_TypeFilter (SMESH::GROUP_NODE));
+ myFilter[0] =
+ new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
+ aListOfFilters.append(0);
+ aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
+ aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_EDGE);
+ aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_EDGE);
+ aListOfFilters[3] = new SMESH_TypeFilter (SMESH::IDSOURCE_EDGE); // for sub-mesh on group of EDGEs
+ myFilter[1] =
+ new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
+ aListOfFilters[0] = new SMESH_TypeFilter (SMESH::MESH);
+ aListOfFilters[1] = new SMESH_TypeFilter (SMESH::SUBMESH_FACE);
+ aListOfFilters[2] = new SMESH_TypeFilter (SMESH::GROUP_FACE);
+ aListOfFilters[3] = new SMESH_TypeFilter (SMESH::IDSOURCE_FACE); // for sub-mesh on group of FACEs
+ myFilter[2] =
+ new SMESH_LogicalFilter (aListOfFilters, SMESH_LogicalFilter::LO_OR, /*takeOwnership=*/true);
+
+ myBusy = false;
+
+ myMeshChk[0]->setChecked( true );
+ myMeshChk[1]->setChecked( true );
+ myMeshChk[2]->setChecked( true );
+ mySelectBtnGrp->button(0)->click();
+}
+
+//================================================================================
+/*!
+ * \brief Destructor
+ */
+//================================================================================
+
+SMESHGUI_3TypesSelector::~SMESHGUI_3TypesSelector()
+{
+ myIDSource[0].out();
+ myIDSource[1].out();
+ myIDSource[2].out();
+
+ delete myFilter[0];
+ delete myFilter[1];
+ delete myFilter[2];
+
+ if ( myFilterDlg )
+ {
+ myFilterDlg->setParent( 0 );
+ delete myFilterDlg;
+ myFilterDlg = 0;
+ }
+ disconnect(mySelectionMgr, 0, this, 0);
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when selection changes
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::selectionIntoArgument()
+{
+ if (myBusy) return;
+
+ // return if dialog box is inactive
+ if ( !isEnabled() )
+ return;
+
+ // get a current element type
+ int iType = mySelectBtnGrp->checkedId();
+ if ( iType < 0 || iType > 2 )
+ return;
+
+ QString aString = "";
+ int nbObjects = 0;
+
+ // clear
+ myBusy = true;
+ myLineEdit[ iType ]->setText(aString);
+ myIDSource[ iType ]->length (nbObjects);
+ myBusy = false;
+ if ( !myGroups[ iType ]->isEnabled() )
+ return;
+
+ SMESH::SetPointRepresentation(false);
+
+ SALOME_ListIO selected;
+ mySelectionMgr->selectedObjects( selected );
+
+ if ( myMeshChk[ iType ]->isChecked() ) // objects selection
+ myIDSource[ iType ]->length( selected.Extent() ); // reserve
+ myIDSource[ iType ]->length(0);
+
+ SALOME_ListIteratorOfListIO It( selected );
+ for ( ; It.More(); It.Next() )
+ {
+ Handle(SALOME_InteractiveObject) IO = It.Value();
+
+ // get selected mesh
+ SMESH::SMESH_Mesh_var mesh = SMESH::GetMeshByIO(IO);
+ if ( mesh->_is_nil() )
+ continue;
+ if ( !myMesh->_is_nil() &&
+ IsAnythingSelected() &&
+ myMesh->GetId() != mesh->GetId() )
+ continue; // other mesh
+ myMesh = mesh;
+ myIO = IO;
+ myActor = SMESH::FindActorByEntry( IO->getEntry() );
+
+ if ( myMeshChk[ iType ]->isChecked() ) // objects selection
+ {
+ SMESH::SMESH_IDSource_var idSrc = SMESH::IObjectToInterface<SMESH::SMESH_IDSource>(IO);
+ if ( idSrc->_is_nil() )
+ continue;
+ mesh = SMESH::SMESH_Mesh::_narrow( idSrc );
+ if ( !mesh->_is_nil() ) // if a mesh is selected, stop iteration
+ {
+ nbObjects = 1;
+ myIDSource[ iType ]->length( nbObjects );
+ myIDSource[ iType ][ 0 ] = idSrc;
+ aString = IO->getName();
+ break;
+ }
+ else // several groups can be selected
+ {
+ myIDSource[ iType ]->length( nbObjects + 1 );
+ myIDSource[ iType ][ nbObjects++ ] = idSrc;
+ aString += " " + QString( IO->getName() ) + " ";
+ }
+ }
+ else // get indices of selected elements
+ {
+ TColStd_IndexedMapOfInteger aMapIndex;
+ mySelector->GetIndex(IO,aMapIndex);
+ int nbElements = aMapIndex.Extent();
+ if ( nbElements > 0 )
+ {
+ SMESH::long_array_var ids = new SMESH::long_array;
+ ids->length( nbElements );
+ for ( int i = 0; i < nbElements; ++i )
+ aString += QString(" %1").arg( ids[ i ] = aMapIndex( i+1 ));
+ addTmpIdSource( ids, iType, nbObjects++ );
+ }
+ break;
+ }
+ }
+
+ myIDSource[ iType ]->length( nbObjects );
+
+ myBusy = true;
+ myLineEdit[ iType ]->setText(aString);
+ myBusy = false;
+
+ emit selectionChanged();
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when text changes in myLineEdit
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::onTextChange( const QString& theNewText )
+{
+ // return if busy
+ if (myBusy) return;
+
+ // get a current element type
+ int iType = 0;
+ QLineEdit* le = (QLineEdit*) sender();
+ for ( ; iType < 3; ++iType )
+ if ( myLineEdit[ iType ] == le )
+ break;
+ if ( iType < 0 || iType > 2 )
+ return;
+ if ( !myGroups[ iType ]->isEnabled() )
+ return;
+
+ myBusy = true;
+
+ // highlight entered elements/nodes
+
+ myIDSource[ iType ]->length( 0 );
+
+ if ( !myMesh->_is_nil() )
+ {
+ QStringList aListId = theNewText.split(" ", QString::SkipEmptyParts);
+ if ( aListId.count() > 0 )
+ {
+ SMDS_Mesh* aMesh = myActor ? myActor->GetObject()->GetMesh() : 0;
+
+ SMESH::ElementType SMESHType = SMESH::ElementType ( iType+1 );
+ SMDSAbs_ElementType SMDSType = SMDSAbs_ElementType( iType+1 );
+ const bool isNode = ( SMDSType == SMDSAbs_Node );
+
+ SMESH::long_array_var ids = new SMESH::long_array;
+ ids->length( aListId.count() );
+ TColStd_MapOfInteger newIndices;
+ for (int i = 0; i < aListId.count(); i++) {
+ int id = aListId[ i ].toInt();
+ bool validId = false;
+ if ( id > 0 ) {
+ if ( aMesh ) {
+ const SMDS_MeshElement * e;
+ if ( isNode ) e = aMesh->FindNode( id );
+ else e = aMesh->FindElement( id );
+ validId = ( e && e->GetType() == SMDSType );
+ } else {
+ validId = ( myMesh->GetElementType( id, !isNode ) == SMESHType );
+ }
+ }
+ if ( validId && newIndices.Add( id ))
+ ids[ newIndices.Extent()-1 ] = id;
+ }
+ if ( !newIndices.IsEmpty() ) {
+ ids->length( newIndices.Extent() );
+ addTmpIdSource( ids, iType, 0 );
+ }
+ mySelector->AddOrRemoveIndex(myIO, newIndices, false);
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView() )
+ aViewWindow->highlight( myIO, true, true );
+ }
+ }
+
+ emit selectionChanged();
+
+ myBusy = false;
+}
+
+//================================================================================
+/*!
+ * \brief Creates from ids and stores a temporary IDSource
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::addTmpIdSource( SMESH::long_array_var& ids, int iType, int index )
+{
+ SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
+ SMESH::SMESH_IDSource_var idSrc =
+ aMeshEditor->MakeIDSource( ids, SMESH::ElementType( iType+1 ));
+
+ if ( (int) myIDSource[ iType ]->length() <= index )
+ myIDSource[ iType ]->length( index + 1 );
+ myIDSource[ iType ][ index ] = idSrc;
+
+ myTmpIDSourceList.push_back( idSrc );
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when myMeshChk is checked
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::onSelectMesh( bool on )
+{
+ QCheckBox* send = (QCheckBox*)sender();
+ for ( int iType = 0; iType < 3; ++iType )
+ if ( send == myMeshChk[ iType ])
+ {
+ myLabel[ iType ]->setText( tr( getLabelText( iType, on )));
+ myFilterBtn[ iType ]->setEnabled( !on );
+ myIDSource [ iType ]->length(0);
+ myBusy = true;
+ myLineEdit [ iType ]->setText("");
+ myBusy = false;
+ myLineEdit [ iType ]->setReadOnly( on );
+ myLineEdit [ iType ]->setValidator( on ? 0 : myIdValidator );
+ mySelectBtnGrp->button(iType)->click();
+ break;
+ }
+ else
+ {
+
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when a selection button is clicked
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::onSelectType(int iType)
+{
+ if ( iType < 0 || iType > 2 )
+ return;
+
+ myIDSource[ iType ]->length(0);
+ myLineEdit[ iType ]->setText("");
+
+ disconnect(mySelectionMgr, 0, this, 0);
+ mySelectionMgr->clearFilters();
+
+ SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
+ if ( myMeshChk[ iType ]->isChecked() )
+ {
+ if ( aViewWindow ) aViewWindow->SetSelectionMode(ActorSelection);
+ mySelectionMgr->installFilter( myFilter[ iType ]);
+ }
+ else if ( aViewWindow )
+ {
+ switch ( iType+1 ) {
+ case SMESH::NODE: aViewWindow->SetSelectionMode(NodeSelection); break;
+ case SMESH::EDGE: aViewWindow->SetSelectionMode(EdgeSelection); break;
+ case SMESH::FACE: aViewWindow->SetSelectionMode(FaceSelection); break;
+ }
+ }
+
+ myLineEdit[ iType ]->setFocus();
+
+ connect(mySelectionMgr, SIGNAL( currentSelectionChanged()), SLOT( selectionIntoArgument()));
+ selectionIntoArgument();
+}
+
+//================================================================================
+/*!
+ * \brief Slot called when "Set filter" is clicked
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::setFilters()
+{
+ if ( myMesh->_is_nil() ) {
+ SUIT_MessageBox::critical(this,
+ tr("SMESH_ERROR"),
+ tr("NO_MESH_SELECTED"));
+ return;
+ }
+ if ( !myFilterDlg )
+ {
+ QList<int> types;
+ types.append( SMESH::NODE );
+ types.append( SMESH::EDGE );
+ types.append( SMESH::FACE );
+ myFilterDlg = new SMESHGUI_FilterDlg( SMESHGUI::GetSMESHGUI(), types );
+ }
+
+ QPushButton* send = (QPushButton*)sender();
+ for ( int iType = 0; iType < 3; ++iType )
+ if ( send == myFilterBtn[ iType ])
+ {
+ mySelectBtnGrp->button(iType)->click();
+
+ myFilterDlg->Init( SMESH::ElementType( iType+1 ) );
+ myFilterDlg->SetSelection();
+ myFilterDlg->SetMesh( myMesh );
+ myFilterDlg->SetSourceWg( myLineEdit[ iType ]);
+ myFilterDlg->show();
+ break;
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Clear selection
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::Clear()
+{
+ myBusy = true;
+ for ( int iType = 0; iType < 3; ++iType )
+ {
+ myIDSource[ iType ]->length(0);
+ myLineEdit[ iType ]->setText("");
+ }
+ myBusy = false;
+ selectionIntoArgument();
+}
+
+//================================================================================
+/*!
+ * \brief Enable/disable controls of a type
+ */
+//================================================================================
+
+void SMESHGUI_3TypesSelector::SetEnabled( bool enable, SMESH::ElementType type )
+{
+ myBusy = true;
+ for ( int iType = 0; iType < 3; ++iType )
+ if ( iType+1 == type || type == SMESH::ALL )
+ {
+ myGroups[ iType ]->setEnabled( enable );
+ if ( !enable ) {
+ myIDSource[ iType ]->length(0);
+ myLineEdit[ iType ]->setText("");
+ }
+ }
+ myBusy = false;
+ selectionIntoArgument();
+}
+
+//================================================================================
+/*!
+ * \brief Checks if anything is selected
+ */
+//================================================================================
+
+bool SMESHGUI_3TypesSelector::IsAnythingSelected( SMESH::ElementType type )
+{
+ int nbSel = 0;
+
+ for ( int iType = 0; iType < 3; ++iType )
+ if ( iType+1 == type || type == SMESH::ALL )
+ nbSel += myIDSource[ iType ]->length();
+
+ return nbSel;
+}
+
+//================================================================================
+/*!
+ * \brief Returns selected elements and most complex type of selected elements
+ */
+//================================================================================
+
+SMESH::ElementType SMESHGUI_3TypesSelector::GetSelected( SMESH::ListOfIDSources & nodes,
+ SMESH::ListOfIDSources & edges,
+ SMESH::ListOfIDSources & faces )
+{
+ nodes = myIDSource[0];
+ edges = myIDSource[1];
+ faces = myIDSource[2];
+
+ if ( myIDSource[2]->length() > 0 ) return SMESH::FACE;
+ if ( myIDSource[1]->length() > 0 ) return SMESH::EDGE;
+ if ( myIDSource[0]->length() > 0 ) return SMESH::NODE;
+ return SMESH::ALL;
+}
+