- if (CORBA::is_nil(myGroupOnFilter)) // creation
- {
- if (myMesh->_is_nil())
- return false;
-
- myGroupOnFilter = myMesh->CreateGroupFromFilter(aType,
- myName->text().toUtf8(),
- myFilter);
- resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
- isCreation = true;
- }
- else
- {
- myGroupOnFilter->SetFilter( myFilter );
-
- resultGroup = SMESH::SMESH_GroupBase::_narrow( myGroupOnFilter );
- isCreation = false;
- }
- anIsOk = true;
- }
-
- if ( anIsOk )
- {
- SALOMEDS::Color aColor = getGroupColor();
- resultGroup->SetColor(aColor);
-
- _PTR(SObject) aMeshGroupSO = SMESH::FindSObject( resultGroup );
- if( aMeshGroupSO )
- anEntryList.append( aMeshGroupSO->GetID().c_str() );
-
- resultGroup->SetName(myName->text().trimmed().toUtf8());
-
- if ( isCreation )
- {
- SMESH::setFileType ( aMeshGroupSO, "COULEURGROUP" );
-
- /* init for the next operation */
- setDefaultName();
- myElements->clear();
- myGroup = SMESH::SMESH_Group::_nil();
- myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
- myGroupOnFilter = SMESH::SMESH_GroupOnFilter::_nil();
- myFilter = SMESH::Filter::_nil();
-
- setDefaultGroupColor(); // reset color for case if 'auto-color' feature is enabled.
- }
- else
- {
- if ( aMeshGroupSO )
- {
- if ( SMESH_Actor *anActor = SMESH::FindActorByEntry(aMeshGroupSO->GetID().c_str()))
- {
- Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
- if ( isConversion ) { // need to reset TVisualObj and actor
- SMESH::RemoveVisualObjectWithActors( anIO->getEntry(), true );
- SMESH::Update( anIO,true);
- myActorsList.clear();
- anActor = SMESH::FindActorByEntry( anIO->getEntry() );
- if ( !anActor ) return false;
- myActorsList.append( anActor );
- }
- anActor->setName(myName->text().toUtf8());
- QColor c;
- int delta;
- switch ( myTypeId ) {
- case grpNodeSelection: anActor->SetNodeColor( aColor.R, aColor.G, aColor.B ); break;
- case grp0DSelection: anActor->Set0DColor ( aColor.R, aColor.G, aColor.B ); break;
- case grpBallSelection: anActor->SetBallColor( aColor.R, aColor.G, aColor.B ); break;
- case grpEdgeSelection: anActor->SetEdgeColor( aColor.R, aColor.G, aColor.B ); break;
- case grpVolumeSelection:
- SMESH::GetColor("SMESH", "volume_color", c , delta, "255,0,170|-100");
- anActor->SetVolumeColor( aColor.R, aColor.G, aColor.B, delta ); break;
- break;
- case grpFaceSelection:
- default:
- SMESH::GetColor("SMESH", "fill_color", c , delta, "0,170,255|-100");
- anActor->SetSufaceColor( aColor.R, aColor.G, aColor.B, delta ); break;
- break;
- }
- // update a visible group according to a changed contents
- if ( !isConversion && anActor->GetVisibility() )
- {
- SMESH::Update( anIO, true );
- SMESH::RepaintCurrentView();
- }
- }
- }
- }
- SMESHGUI::Modified();
- mySMESHGUI->updateObjBrowser(true);
- mySelectionMgr->clearSelected();
-
- if( LightApp_Application* anApp =
- dynamic_cast<LightApp_Application*>( SUIT_Session::session()->activeApplication() ) )
- myObjectToSelect = anApp->browseObjects( anEntryList, isApplyAndClose() );
- }
- return anIsOk;
-}
-
-//=================================================================================
-// function : onOK()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onOK()
-{
- setIsApplyAndClose( true );
- if ( onApply() )
- reject();
- setIsApplyAndClose( false );
-
- if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
-}
-
-//=================================================================================
-// function : onListSelectionChanged()
-// purpose : Called when selection in element list is changed
-//=================================================================================
-void SMESHGUI_AdaptDlg::onListSelectionChanged()
-{
- //MESSAGE( "SMESHGUI_AdaptDlg::onListSelectionChanged(); myActorsList.count() = " << myActorsList.count());
- if( myIsBusy || myActorsList.count() == 0 ) return;
- myIsBusy = true;
-
- if (myCurrentLineEdit == 0) {
- mySelectionMgr->clearSelected();
- TColStd_MapOfInteger aIndexes;
- QList<QListWidgetItem*> selItems = myElements->selectedItems();
- QListWidgetItem* anItem;
- foreach(anItem, selItems) aIndexes.Add(anItem->text().toInt());
- mySelector->AddOrRemoveIndex(myActorsList.first()->getIO(), aIndexes, false);
- SALOME_ListIO aList;
- aList.Append(myActorsList.first()->getIO());
- mySelectionMgr->setSelectedObjects(aList,false);
- }
- myIsBusy = false;
-}
-
-//=================================================================================
-// function : onObjectSelectionChanged()
-// purpose : Called when selection in 3D view or ObjectBrowser is changed
-//=================================================================================
-void SMESHGUI_AdaptDlg::onObjectSelectionChanged()
-{
- if ( myIsBusy || !isEnabled()) return;
- if (myCurrentLineEdit == myGeomGroupLine && !myGeomGroupBtn->isChecked()) return;
-
- myIsBusy = true;
-
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- int aNbSel = aList.Extent();
- myElements->clearSelection();
-
- if (myCurrentLineEdit)
- {
- myCurrentLineEdit->setText( "" );
- QString aString = "";
-
- if (myCurrentLineEdit == myMeshGroupLine)
- {
- mySelectSubMesh->setEnabled(false);
- mySelectGroup->setEnabled(false);
- myGroupLine->setText( "" );
- mySubMeshLine->setText( "" );
-
- myGeomGroupBtn->setEnabled(false);
- myGeomGroupLine->setEnabled(false);
- myGeomGroupLine->setText( "" );
- myGeomObjects = new GEOM::ListOfGO();
- myGeomObjects->length(0);
-
- if (myGeomGroupBtn->isChecked())
- myGeomGroupBtn->setChecked(false);
- if (!myCreate)
- myName->setText( "" );
-
- myElements->clear();
-
- if (aNbSel != 1 ) {
- myGroup = SMESH::SMESH_Group::_nil();
- myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
- restoreShowEntityMode();
- myMesh = SMESH::SMESH_Mesh::_nil();
- updateGeomPopup();
- updateButtons();
- myIsBusy = false;
- return;
- }
- Handle(SALOME_InteractiveObject) IO = aList.First();
-
- if (myCreate) {
- restoreShowEntityMode();
- myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(IO);
- setShowEntityMode();
- updateGeomPopup();
- if (myMesh->_is_nil())
- {
- updateButtons();
- myIsBusy = false;
- return;
- }
-
- if ( myFilterDlg && !myMesh->_is_nil()){
- myFilterDlg->SetMesh( myMesh );
- }
- myGroup = SMESH::SMESH_Group::_nil();
-
- // NPAL19389: create a group with a selection in another group
- // set actor of myMesh, if it is visible, else try
- // any visible actor of group or submesh of myMesh
- SetAppropriateActor();
-
- setDefaultGroupColor();
- if (myName->text().isEmpty())
- setDefaultName();
-
- aString = aList.First()->getName();
- myMeshGroupLine->setText(aString);
- myMeshGroupLine->home( false );
-
- mySelectSubMesh->setEnabled(true);
- mySelectGroup->setEnabled(true);
- myGeomGroupBtn->setEnabled(true);
- myGeomGroupLine->setEnabled(true);
- updateButtons();
- }
- else {
- SMESH::SMESH_GroupBase_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(IO);
- if (aGroup->_is_nil())
- {
- myIsBusy = false;
- return;
- }
- myIsBusy = false;
-
- myGroup = SMESH::SMESH_Group::_nil();
- myGroupOnGeom = SMESH::SMESH_GroupOnGeom::_nil();
-
- init(aGroup);
- myIsBusy = true;
- mySelectSubMesh->setEnabled(true);
- mySelectGroup->setEnabled(true);
- }
- myCurrentLineEdit = 0;
- myIsBusy = false;
- if (!myCreate)
- return;
-
- if (myGrpTypeId == 0)
- {
- if (myTypeId == -1)
- onTypeChanged(0);
- else
- {
- myElements->clear();
- setSelectionMode(myTypeId);
- }
- }
-
- myIsBusy = false;
- return;
-
- }
- else if (myCurrentLineEdit == myGeomGroupLine)
- {
- myGeomObjects = new GEOM::ListOfGO();
-
- // The mesh SObject
- _PTR(SObject) aMeshSO = SMESH::FindSObject(myMesh);
-
- if (aNbSel == 0 || !aMeshSO)
- {
- myGeomObjects->length(0);
- updateButtons();
- myIsBusy = false;
- return;
- }
-
- myGeomObjects->length(aNbSel);
-
- GEOM::GEOM_Object_var aGeomGroup;
- int i = 0;
-
- SALOME_ListIteratorOfListIO anIt (aList);
- for (; anIt.More(); anIt.Next())
- {
- aGeomGroup = GEOMBase::ConvertIOinGEOMObject(anIt.Value());
-
- // Check if the object is a geometry group
- if (CORBA::is_nil(aGeomGroup))
- continue;
-
- // Check if group constructed on the same shape as a mesh or on its child
-
- // The main shape of the group
- GEOM::GEOM_Object_var aGroupMainShape;
- if (aGeomGroup->GetType() == 37)
- {
- GEOM::GEOM_IGroupOperations_wrap anOp =
- SMESH::GetGEOMGen( aGeomGroup )->GetIGroupOperations();
- aGroupMainShape = anOp->GetMainShape( aGeomGroup );
- // aGroupMainShape is an existing servant => GEOM_Object_var not GEOM_Object_wrap
- }
- else
- {
- aGroupMainShape = aGeomGroup;
- aGroupMainShape->Register();
- }
- CORBA::String_var entry = aGroupMainShape->GetStudyEntry();
- _PTR(SObject) aGroupMainShapeSO =
- SMESH::getStudy()->FindObjectID( entry.in() );
-
- _PTR(SObject) anObj, aRef;
- bool isRefOrSubShape = false;
- if (aMeshSO->FindSubObject(1, anObj) && anObj->ReferencedObject(aRef)) {
- if (aRef->GetID() == aGroupMainShapeSO->GetID()) {
- isRefOrSubShape = true;
- } else {
- _PTR(SObject) aFather = aGroupMainShapeSO->GetFather();
- _PTR(SComponent) aComponent = aGroupMainShapeSO->GetFatherComponent();
- while (!isRefOrSubShape && aFather->GetID() != aComponent->GetID()) {
- if (aRef->GetID() == aFather->GetID())
- isRefOrSubShape = true;
- else
- aFather = aFather->GetFather();
- }
- }
- }
- if (isRefOrSubShape)
- myGeomObjects[i++] = aGeomGroup;
- }
-
- myGeomObjects->length(i);
- if ( i == 0 )
- {
- myIsBusy = false;
- return;
- }
-
- aNbSel = i;
- }
-
- if (aNbSel >= 1) {
- if (aNbSel > 1) {
- if (myCurrentLineEdit == mySubMeshLine)
- aString = tr( "SMESH_SUBMESH_SELECTED" ).arg(aNbSel);
- else if (myCurrentLineEdit == myGroupLine)
- aString = tr( "SMESH_GROUP_SELECTED" ).arg(aNbSel);
- else if (myCurrentLineEdit == myGeomGroupLine)
- aString = tr( "%1 Objects" ).arg(aNbSel);
- }
- else {
- aString = aList.First()->getName();
- }
- }
-
- myCurrentLineEdit->setText(aString);
- myCurrentLineEdit->home(false);
- // 07.06.2008 skl for IPAL19574:
- // change name of group only if it is empty
- if( myName->text().trimmed().isEmpty() || !myNameChanged ) {
- myOldName = myName->text();
- myName->blockSignals(true);
- myName->setText(aString);
- myName->blockSignals(false);
- }
-
- updateButtons();
- }
- else // !myCurrentLineEdit: local selection of nodes or elements
- {
- if (aNbSel == 1 && myActorsList.count() > 0 )
- {
- // NPAL19389: create a group with a selection in another group
- // Switch myActor to the newly selected one, if the last
- // is visible and belongs to group or submesh of myMesh
- /* Handle(SALOME_InteractiveObject) curIO = myActor->getIO();
- Handle(SALOME_InteractiveObject) selIO = aList.First();
- if (curIO->hasEntry() && selIO->hasEntry()) {
- const char* selEntry = selIO->getEntry();
- if (strcmp(curIO->getEntry(), selEntry) != 0) {
- // different objects: selected and myActor
- SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
- if (aViewWindow && aViewWindow->isVisible(selIO)) {
- // newly selected actor is visible
-
- // mesh entry
- _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
- if (aSObject) {
- CORBA::String_var meshEntry = aSObject->GetID().c_str();
- int len = strlen(meshEntry);
-
- if (strncmp(selEntry, meshEntry, len) == 0) {
- // selected object is myMesh or a part of it
- SMESH_Actor* anActor = SMESH::FindActorByEntry(selEntry);
- if (anActor) {
- myActor = anActor;
- SMESH::SetPickable(myActor);
- }
- }
- }
- }
- }
- }*/
- // NPAL19389 END
-
- QString aListStr = "";
- int aNbItems = 0;
- if (myTypeId == 0) {
- QListIterator<SMESH_Actor*> it( myActorsList );
- while ( it.hasNext() ) {
- QString tmpStr;
- aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
- aListStr += tmpStr;
- }
- } else {
- QListIterator<SMESH_Actor*> it( myActorsList );
- while ( it.hasNext() ) {
- QString tmpStr;
- aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
- aListStr += tmpStr;
- }
- }
- if (aNbItems > 0) {
- QListWidgetItem* anItem;
- QList<QListWidgetItem*> listItemsToSel;
- QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
- for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
- QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
- foreach(anItem, found)
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- bool blocked = myElements->signalsBlocked();
- myElements->blockSignals(true);
- foreach(anItem, listItemsToSel) anItem->setSelected(true);
- myElements->blockSignals(blocked);
- onListSelectionChanged();
- listItemsToSel.clear();
- }
- }
- }
-
- if (myActorsList.count() == 0) {
- if (!myGroup->_is_nil()) {
- SMESH_Actor* anActor = SMESH::FindActorByObject(myGroup);
- if ( anActor )
- myActorsList.append( anActor );
- }
- else if(!myGroupOnGeom->_is_nil()) {
- SMESH_Actor* anActor = SMESH::FindActorByObject(myGroupOnGeom);
- if ( anActor )
- myActorsList.append( anActor );
- }
- else {
- SMESH_Actor* anActor = SMESH::FindActorByObject( myMesh );
- if ( anActor )
- myActorsList.append( anActor );
- }
- }
-
- // somehow, if we display the mesh, while selecting from another actor,
- // the mesh becomes pickable, and there is no way to select any element
- if (myActorsList.count() > 0) {
- QListIterator<SMESH_Actor*> it( myActorsList );
- while ( it.hasNext() ) {
- SMESH_Actor* anActor = it.next();
- if ( IsActorVisible(anActor) )
- anActor->SetPickable(true);
- }
- }
-
- myIsBusy = false;
-}
-
-//=================================================================================
-// function : onSelectAll()
-// purpose : Called when "Select all" is checked
-//=================================================================================
-void SMESHGUI_AdaptDlg::onSelectAll()
-{
- bool noElemsModif = ( mySelectAll->isChecked() || !myAllowElemsModif->isChecked() );
-
- myElementsLab->setEnabled( !noElemsModif );
- myElements->setEnabled ( !noElemsModif );
- myFilterBtn->setEnabled ( !noElemsModif );
- myAddBtn->setEnabled ( !noElemsModif );
- myRemoveBtn->setEnabled ( !noElemsModif );
- mySortBtn->setEnabled ( !noElemsModif );
- mySelectBox->setEnabled ( !noElemsModif );
- myAllowElemsModif->setEnabled( !mySelectAll->isChecked() );
- if ( noElemsModif ) mySMESHGUI->ResetState();
- else mySMESHGUI->SetState(800);
-
- int selMode = mySelectionMode;
- mySelectionMode = grpNoSelection;
- setSelectionMode( selMode );
- updateButtons();
-}
-
-//=================================================================================
-// function : onSelectSubMesh()
-// purpose : Called when selection in 3D view or ObjectBrowser is changed
-//=================================================================================
-void SMESHGUI_AdaptDlg::onSelectSubMesh(bool on)
-{
- if (on) {
- if (mySelectGroup->isChecked()) {
- mySelectGroup->setChecked(false);
- }
- //VSR: else if (mySelectGeomGroup->isChecked()) {
- //VSR: mySelectGeomGroup->setChecked(false);
- //VSR: }
- myCurrentLineEdit = mySubMeshLine;
- setSelectionMode(grpSubMeshSelection);
- }
- else {
- mySubMeshLine->setText( "" );
- myCurrentLineEdit = 0;
- if (myTypeId != -1)
- setSelectionMode(myTypeId);
- }
- mySubMeshBtn->setEnabled(on);
- mySubMeshLine->setEnabled(on);
-}
-
-
-//=================================================================================
-// function : (onSelectGroup)
-// purpose : Called when selection in 3D view or ObjectBrowser is changed
-//=================================================================================
-void SMESHGUI_AdaptDlg::onSelectGroup(bool on)
-{
- if (on) {
- if (mySelectSubMesh->isChecked()) {
- mySelectSubMesh->setChecked(false);
- }
- myCurrentLineEdit = myGroupLine;
- setSelectionMode(grpGroupSelection);
- }
- else {
- myGroupLine->setText( "" );
- myCurrentLineEdit = 0;
- if (myTypeId != -1)
- setSelectionMode(myTypeId);
- }
- myGroupBtn->setEnabled(on);
- myGroupLine->setEnabled(on);
-}
-
-
-//=================================================================================
-// function : (onSelectGeomGroup)
-// purpose : Called when group type changed. on == "on geometry" or "on filter"
-//=================================================================================
-void SMESHGUI_AdaptDlg::onSelectGeomGroup(bool on)
-{
- if (on) {
- if (mySelectSubMesh->isChecked()) {
- mySelectSubMesh->setChecked(false);
- }
- else if (mySelectGroup->isChecked()) {
- mySelectGroup->setChecked(false);
- }
- if ( myGrpTypeId == 1 ) { // on geometry
- myCurrentLineEdit = myGeomGroupLine;
- updateGeomPopup();
- }
- else { // on filter
- myCurrentLineEdit = 0;
- }
- setSelectionMode(grpAllSelection);
- }
- else {
- myGeomGroupBtn->setChecked(false);
- myGeomObjects->length(0);
- myGeomGroupLine->setText( "" );
- myCurrentLineEdit = 0;
- if (myTypeId != -1)
- setSelectionMode( myTypeId );
- }
-}
-
-//=================================================================================
-// function : setCurrentSelection()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::setCurrentSelection()
-{
- QPushButton* send = (QPushButton*)sender();
- myCurrentLineEdit = 0;
- if (send == myMeshGroupBtn) {
- disconnect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
- mySelectionMgr->clearSelected();
- if (myCreate)
- setSelectionMode(grpMeshSelection);
- else
- setSelectionMode(grpGroupSelection);
- connect(myMeshGroupBtn, SIGNAL(clicked()), this, SLOT(setCurrentSelection()));
- myCurrentLineEdit = myMeshGroupLine;
- onObjectSelectionChanged();
- }
- else if (send == mySubMeshBtn) {
- myCurrentLineEdit = mySubMeshLine;
- onObjectSelectionChanged();
- }
- else if (send == myGroupBtn) {
- myCurrentLineEdit = myGroupLine;
- onObjectSelectionChanged();
- }
-}
-
-
-//=================================================================================
-// function : setFilters()
-// purpose : SLOT. Called when "Filter" button pressed.
-//=================================================================================
-void SMESHGUI_AdaptDlg::setFilters()
-{
- if(myMesh->_is_nil()) {
- SUIT_MessageBox::critical(this,
- tr("SMESH_ERROR"),
- tr("NO_MESH_SELECTED"));
- return;
- }
-
- SMESH::ElementType aType = SMESH::ALL;
- switch ( myTypeId )
- {
- case grpNodeSelection: aType = SMESH::NODE; break;
- case grp0DSelection: aType = SMESH::ELEM0D; break;
- case grpBallSelection: aType = SMESH::BALL; break;
- case grpEdgeSelection: aType = SMESH::EDGE; break;
- case grpFaceSelection: aType = SMESH::FACE; break;
- case grpVolumeSelection: aType = SMESH::VOLUME; break;
- default: return;
- }
-
- if ( myFilterDlg == 0 )
- {
- myFilterDlg = new SMESHGUI_FilterDlg( mySMESHGUI, aType );
- connect( myFilterDlg, SIGNAL( Accepted() ), SLOT( onFilterAccepted() ) );
- }
- else
- myFilterDlg->Init( aType );
-
- if ( !myGroupOnFilter->_is_nil() )
- {
- myFilterDlg->SetFilter( myFilter, aType );
- myFilterDlg->Init( aType );
- }
-
- bool isStandalone = ( sender() == myFilterBtn );
- myFilterDlg->SetEnabled( /*setInViewer=*/isStandalone,
- /*diffSources=*/isStandalone );
- myFilterDlg->SetMesh( myMesh );
- myFilterDlg->SetGroup( myGroupOnFilter );
- myFilterDlg->SetSelection();
- myFilterDlg->SetSourceWg( myElements, false );
-
- myFilterDlg->show();
-}
-
-//=================================================================================
-// function : onFilterAccepted()
-// purpose : SLOT. Called when Filter dlg closed with OK button.
-// Uncheck "Select submesh" and "Select group" checkboxes
-//=================================================================================
-void SMESHGUI_AdaptDlg::onFilterAccepted()
-{
- if ( mySelectSubMesh->isChecked() || mySelectGroup->isChecked() )
- {
- mySelectionMode = myTypeId;
- mySelectSubMesh->setChecked( false );
- mySelectGroup->setChecked( false );
- }
- // get a filter from myFilterDlg
- myFilter = myFilterDlg->GetFilter();
- if ( !myFilter->_is_nil() ) {
- SMESH::Predicate_var perdicate = myFilter->GetPredicate();
- if ( perdicate->_is_nil() )
- myFilter = SMESH::Filter::_nil();
- }
- // set mesh to myFilter
- if ( !myFilter->_is_nil() ) {
- SMESH::SMESH_Mesh_var mesh = myMesh;
- if ( mesh->_is_nil() ) {
- if ( !myGroup->_is_nil() )
- mesh = myGroup->GetMesh();
- else if ( !myGroupOnGeom->_is_nil() )
- mesh = myGroupOnGeom->GetMesh();
- else if ( !myGroupOnFilter->_is_nil() )
- mesh = myGroupOnFilter->GetMesh();
- }
- myFilter->SetMesh( mesh );
-
- // highlight ids if selection changed in the Viewer (IPAL52924)
- myCurrentLineEdit = 0;
- onObjectSelectionChanged();
- }
-
- updateButtons();
-}
-
-//=================================================================================
-// function : onAdd()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onAdd()
-{
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- int aNbSel = aList.Extent();
-
- if (aNbSel == 0 || myActorsList.count() == 0 || myMesh->_is_nil()) return;
-
- SUIT_OverrideCursor wc;
-
- myIsBusy = true;
- int sizeBefore = myElements->count();
-
- SMESH::ElementType aType = SMESH::ALL;
- switch(myTypeId) {
- case grpNodeSelection:
- aType = SMESH::NODE;
- mySelector->SetSelectionMode(NodeSelection);
- break;
- case grpBallSelection:
- aType = SMESH::BALL;
- mySelector->SetSelectionMode(BallSelection);
- break;
- case grp0DSelection:
- aType = SMESH::ELEM0D;
- mySelector->SetSelectionMode(Elem0DSelection);
- break;
- case grpEdgeSelection:
- aType = SMESH::EDGE;
- mySelector->SetSelectionMode(EdgeSelection);
- break;
- case grpFaceSelection:
- aType = SMESH::FACE;
- mySelector->SetSelectionMode(FaceSelection);
- break;
- case grpVolumeSelection:
- aType = SMESH::VOLUME;
- mySelector->SetSelectionMode(VolumeSelection);
- break;
- default:
- mySelector->SetSelectionMode(ActorSelection);
- }
-
- QListWidgetItem* anItem = 0;
- QList<QListWidgetItem*> listItemsToSel;
-
- if ( myCurrentLineEdit == 0 )
- {
- //if (aNbSel != 1) { myIsBusy = false; return; }
- QString aListStr = "";
- int aNbItems = 0;
- if (myTypeId == 0) {
- QListIterator<SMESH_Actor*> it( myActorsList );
- while ( it.hasNext() ) {
- QString tmpStr;
- aNbItems += SMESH::GetNameOfSelectedNodes(mySelector, it.next()->getIO(), tmpStr);
- aListStr += tmpStr;
- }
- }
- else {
- QListIterator<SMESH_Actor*> it( myActorsList );
- while ( it.hasNext() ) {
- QString tmpStr;
- aNbItems += SMESH::GetNameOfSelectedElements(mySelector, it.next()->getIO(), tmpStr);
- aListStr += tmpStr;
- }
- }
- if (aNbItems > 0) {
- QStringList anElements = aListStr.split( " ", QString::SkipEmptyParts);
- for (QStringList::iterator it = anElements.begin(); it != anElements.end(); ++it) {
- QList<QListWidgetItem*> found = myElements->findItems(*it, Qt::MatchExactly);
- if (found.count() == 0) {
- anItem = new QListWidgetItem(*it);
- myElements->addItem(anItem);
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- else {
- foreach(anItem, found)
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- }
- bool blocked = myElements->signalsBlocked();
- myElements->blockSignals(true);
- foreach(anItem, listItemsToSel) anItem->setSelected(true);
- myElements->blockSignals(blocked);
- onListSelectionChanged();
- listItemsToSel.clear();
- }
- }
- else if ( myCurrentLineEdit == mySubMeshLine )
- {
- //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
-
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- SALOME_ListIteratorOfListIO anIt (aList);
- for ( ; anIt.More(); anIt.Next()) {
- SMESH::SMESH_subMesh_var aSubMesh =
- SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
- if (!aSubMesh->_is_nil()) {
- // check if mesh is the same
- if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
- try {
- SMESH::long_array_var anElements = aSubMesh->GetElementsByType(aType);
- int k = anElements->length();
- for (int i = 0; i < k; i++) {
- QString aText = QString::number(anElements[i]);
- QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
- if (found.count() == 0) {
- anItem = new QListWidgetItem(aText);
- myElements->addItem(anItem);
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- else {
- foreach(anItem, found)
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- }
- bool blocked = myElements->signalsBlocked();
- myElements->blockSignals(true);
- foreach(anItem, listItemsToSel) anItem->setSelected(true);
- myElements->blockSignals(blocked);
- onListSelectionChanged();
- listItemsToSel.clear();
- }
- catch (const SALOME::SALOME_Exception& ex) {
- SalomeApp_Tools::QtCatchCorbaException(ex);
- }
- }
- }
- }
- mySelectSubMesh->setChecked(false);
- myIsBusy = false;
- onListSelectionChanged();
-
- }
- else if ( myCurrentLineEdit == myGroupLine )
- {
- //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- SALOME_ListIteratorOfListIO anIt (aList);
- for ( ; anIt.More(); anIt.Next()) {
- SMESH::SMESH_GroupBase_var aGroup =
- SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIt.Value());
- if (!aGroup->_is_nil()) {
- // check if mesh is the same
- if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
- SMESH::long_array_var anElements = aGroup->GetListOfID();
- int k = anElements->length();
- for (int i = 0; i < k; i++) {
- QString aText = QString::number(anElements[i]);
- QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
- if (found.count() == 0) {
- anItem = new QListWidgetItem(aText);
- myElements->addItem(anItem);
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- else {
- foreach(anItem, found)
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- }
- bool blocked = myElements->signalsBlocked();
- myElements->blockSignals(true);
- foreach(anItem, listItemsToSel) anItem->setSelected(true);
- myElements->blockSignals(blocked);
- onListSelectionChanged();
- listItemsToSel.clear();
- }
- }
- }
- mySelectGroup->setChecked(false);
- myIsBusy = false;
- onListSelectionChanged();
-
- }
- else if ( myCurrentLineEdit == myGeomGroupLine && myGeomObjects->length() == 1 )
- {
- GEOM::GEOM_IGroupOperations_wrap aGroupOp =
- SMESH::GetGEOMGen( myGeomObjects[0] )->GetIGroupOperations();
-
- SMESH::ElementType aGroupType = SMESH::ALL;
- switch(aGroupOp->GetType(myGeomObjects[0])) {
- case TopAbs_VERTEX: aGroupType = SMESH::NODE; break;
- case TopAbs_EDGE: aGroupType = SMESH::EDGE; break;
- case TopAbs_FACE: aGroupType = SMESH::FACE; break;
- case TopAbs_SOLID: aGroupType = SMESH::VOLUME; break;
- default: myIsBusy = false; return;
- }
-
- if (aGroupType == aType) {
- _PTR(SObject) aGroupSO =
- //SMESH::getStudy()->FindObjectIOR(SMESH::getStudy()->ConvertObjectToIOR(myGeomGroup));
- SMESH::getStudy()->FindObjectID(myGeomObjects[0]->GetStudyEntry());
- // Construct filter
- SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
- SMESH::Filter_var aFilter = aFilterMgr->CreateFilter();
- SMESH::BelongToGeom_var aBelongToGeom = aFilterMgr->CreateBelongToGeom();
- aBelongToGeom->SetGeom(myGeomObjects[0]);
- aBelongToGeom->SetShapeName(aGroupSO->GetName().c_str());
- aBelongToGeom->SetElementType(aType);
- aFilter->SetPredicate(aBelongToGeom);
-
- SMESH::long_array_var anElements = aFilter->GetElementsId(myMesh);
-
- int k = anElements->length();
- for (int i = 0; i < k; i++) {
- QString aText = QString::number(anElements[i]);
- QList<QListWidgetItem*> found = myElements->findItems(aText, Qt::MatchExactly);
- if (found.count() == 0) {
- anItem = new QListWidgetItem(aText);
- myElements->addItem(anItem);
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- else {
- foreach(anItem, found)
- if (!anItem->isSelected())
- listItemsToSel.push_back(anItem);
- }
- }
- bool blocked = myElements->signalsBlocked();
- myElements->blockSignals(true);
- foreach(anItem, listItemsToSel) anItem->setSelected(true);
- myElements->blockSignals(blocked);
- onListSelectionChanged();
- listItemsToSel.clear();
- }
-
- //VSR: mySelectGeomGroup->setChecked(false);
- myIsBusy = false;
- onListSelectionChanged();
- }
- myIsBusy = false;
- if ( sizeBefore < myElements->count() )
- ++myNbChangesOfContents;
- // mySelectionMgr->clearSelected();
- updateButtons();
-}
-
-//=================================================================================
-// function : onRemove()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onRemove()
-{
- myIsBusy = true;
- int sizeBefore = myElements->count();
-
- if (myCurrentLineEdit == 0) {
- QList<QListWidgetItem*> selItems = myElements->selectedItems();
- QListWidgetItem* item;
- foreach(item, selItems) delete item;
- } else {
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- int aNbSel = aList.Extent();
-
- if (aNbSel == 0) { myIsBusy = false; return; }
-
- SMESH::ElementType aType = SMESH::ALL;
- switch(myTypeId) {
- case grpNodeSelection: aType = SMESH::NODE; break;
- case grp0DSelection: aType = SMESH::ELEM0D; break;
- case grpBallSelection: aType = SMESH::BALL; break;
- case grpEdgeSelection: aType = SMESH::EDGE; break;
- case grpFaceSelection: aType = SMESH::FACE; break;
- case grpVolumeSelection: aType = SMESH::VOLUME; break;
- }
-
- if (myCurrentLineEdit == mySubMeshLine) {
- //SALOME_ListIteratorOfListIO anIt (mySelectionMgr->StoredIObjects());
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- SALOME_ListIteratorOfListIO anIt (aList);
- for ( ; anIt.More(); anIt.Next()) {
- SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIt.Value());
- if (!aSubMesh->_is_nil()) {
- // check if mesh is the same
- if (aSubMesh->GetFather()->GetId() == myMesh->GetId()) {
- if (aType == SMESH::NODE) {
- try {
- SMESH::long_array_var anElements = aSubMesh->GetNodesId();
- int k = anElements->length();
- for (int i = 0; i < k; i++) {
- QList<QListWidgetItem*> found =
- myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
- QListWidgetItem* anItem;
- foreach(anItem, found) delete anItem;
- }
- }
- catch (const SALOME::SALOME_Exception& ex) {
- SalomeApp_Tools::QtCatchCorbaException(ex);
- }
- }
- else {
- try {
- SMESH::long_array_var anElements = aSubMesh->GetElementsId();
- int k = anElements->length();
- for (int i = 0; i < k; i++) {
- QList<QListWidgetItem*> found =
- myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
- QListWidgetItem* anItem;
- foreach(anItem, found) delete anItem;
- }
- }
- catch (const SALOME::SALOME_Exception& ex) {
- SalomeApp_Tools::QtCatchCorbaException(ex);
- }
- }
- }
- }
- }
- }
- else if (myCurrentLineEdit == myGroupLine) {
- SALOME_ListIO aList;
- mySelectionMgr->selectedObjects( aList );
-
- SALOME_ListIteratorOfListIO anIt (aList);
- for ( ; anIt.More(); anIt.Next()) {
- SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>(anIt.Value());
- if (!aGroup->_is_nil()) {
- // check if mesh is the same
- if (aGroup->GetType() == aType && aGroup->GetMesh()->GetId() == myMesh->GetId()) {
- SMESH::long_array_var anElements = aGroup->GetListOfID();
- int k = anElements->length();
- for (int i = 0; i < k; i++) {
- QList<QListWidgetItem*> found =
- myElements->findItems(QString::number(anElements[i]), Qt::MatchExactly);
- QListWidgetItem* anItem;
- foreach(anItem, found) delete anItem;
- }
- }
- }
- }
- }
- }
- myIsBusy = false;
- if ( sizeBefore > myElements->count() )
- myNbChangesOfContents += 2; // it's used to detect that "Add" was only once
- updateButtons();
-}
-
-//=================================================================================
-// function : onSort()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onSort()
-{
- // PAL5412: sorts items in ascending by "string" value
- // myElements->sort(true);
- // myElements->update();
- int i, k = myElements->count();
- if (k > 0) {
- myIsBusy = true;
- QList<int> aSelected;
- std::vector<int> anArray(k);
- // QMemArray<int> anArray(k);
- // fill the array
- for (i = 0; i < k; i++) {
- int id = myElements->item(i)->text().toInt();
- anArray[i] = id;
- if (myElements->item(i)->isSelected())
- aSelected.append(id);
- }
- // sort & update list
- std::sort(anArray.begin(), anArray.end());
- // anArray.sort();
- myElements->clear();
- QListWidgetItem* anItem;
- QList<QListWidgetItem*> listItemsToSel;
- for (i = 0; i < k; i++) {
- anItem = new QListWidgetItem(QString::number(anArray[i]));
- myElements->addItem(anItem);
- if (aSelected.contains(anArray[i]))
- listItemsToSel.push_back(anItem);
- }
- bool blocked = myElements->signalsBlocked();
- myElements->blockSignals(true);
- foreach(anItem, listItemsToSel) anItem->setSelected(true);
- myElements->blockSignals(blocked);
- listItemsToSel.clear();
- myIsBusy = false;
- }
-}
-
-//=================================================================================
-// function : onVisibilityChanged()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onVisibilityChanged()
-{
- SetAppropriateActor();
-}
-
-//=================================================================================
-// function : SMESHGUI_AdaptDlg::reject
-// purpose : SLOT called when "Close" button pressed. Close dialog
-//=================================================================================
-void SMESHGUI_AdaptDlg::reject()
-{
- if (SMESH::GetCurrentVtkView()) {
- SMESH::RemoveFilters(); // PAL6938 -- clean all mesh entity filters
- SMESH::SetPointRepresentation(false);
- SMESH::SetPickable();
- restoreShowEntityMode();
- }
-
- if( isApplyAndClose() && !myObjectToSelect.isEmpty() ) {
- SUIT_DataOwnerPtrList aList;
- aList.append( new LightApp_DataOwner( myObjectToSelect ) );
- mySelectionMgr->setSelected( aList );
- }
- else
- mySelectionMgr->clearSelected();
- if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
- aViewWindow->SetSelectionMode(ActorSelection);
- mySelectionMgr->clearFilters();
- mySMESHGUI->ResetState();
-
- QDialog::reject();
-
- if ( myFilterDlg ) myFilterDlg->UnRegisterFilters();
-}
-
-//=================================================================================
-// function : onOpenView()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onOpenView()
-{
- if ( mySelector ) {
- SMESH::SetPointRepresentation(false);
- }
- else {
- mySelector = SMESH::GetViewWindow( mySMESHGUI )->GetSelector();
- mySMESHGUI->EmitSignalDeactivateDialog();
- setEnabled(true);
- }
-}
-
-//=================================================================================
-// function : onCloseView()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onCloseView()
-{
- onDeactivate();
- mySelector = 0;
-}
-
-//=================================================================================
-// function : onHelp()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onHelp()
-{
- LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
- if (app)
- {
- app->onHelpContextModule
- ( mySMESHGUI ? app->moduleName( mySMESHGUI->moduleName() ) : QString(""), myHelpFileName );
- }
- else
- {
-#ifdef WIN32
- QString platform = "winapplication";
-#else
- QString platform = "application";
-#endif
- SUIT_MessageBox::warning(this, tr( "WRN_WARNING" ),
- tr( "EXTERNAL_BROWSER_CANNOT_SHOW_PAGE" ).
- arg(app->resourceMgr()->stringValue( "ExternalBrowser", platform)).
- arg(myHelpFileName));
- }
-}
-
-//=================================================================================
-// function : SMESHGUI_AdaptDlg::onDeactivate
-// purpose : SLOT called when dialog must be deactivated
-//=================================================================================
-void SMESHGUI_AdaptDlg::onDeactivate()
-{
- mySMESHGUI->ResetState();
- setEnabled(false);
-}
-
-//=================================================================================
-// function : SMESHGUI_AdaptDlg::enterEvent
-// purpose : Event filter
-//=================================================================================
-void SMESHGUI_AdaptDlg::enterEvent (QEvent*)
-{
- if (!isEnabled()) {
- SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
- if ( aViewWindow && !mySelector) {
- mySelector = aViewWindow->GetSelector();
- }
- mySMESHGUI->EmitSignalDeactivateDialog();
- setEnabled(true);
- mySelectionMode = grpNoSelection;
- setSelectionMode(myTypeId);
- mySMESHGUI->SetActiveDialogBox(this);
- if ( mySelectBox->isEnabled() ) mySMESHGUI->SetState(800);
- else mySMESHGUI->ResetState();
- }
-}
-
-//=================================================================================
-// function : keyPressEvent()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::keyPressEvent( QKeyEvent* e )
-{
- QDialog::keyPressEvent( e );
- if ( e->isAccepted() )
- return;
-
- if ( e->key() == Qt::Key_F1 )
- {
- e->accept();
- onHelp();
- }
-}
-
-//================================================================================
-/*!
- * \brief Enable showing of the popup when Geometry selection btn is clicked
- * \param enable - true to enable
- */
-//================================================================================
-
-enum { DIRECT_GEOM_INDEX = 0, GEOM_BY_MESH_INDEX };
-
-void SMESHGUI_AdaptDlg::updateGeomPopup()
-{
- bool enable = false;
-
- if ( !myMesh->_is_nil() )
- enable = myMesh->NbEdges() > 0;
-
- if ( myGeomGroupBtn )
- {
- disconnect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
- if ( enable ) {
- if ( !myGeomPopup ) {
- myGeomPopup = new QMenu(this);
- myActions[myGeomPopup->addAction( tr( "DIRECT_GEOM_SELECTION" ) )] = DIRECT_GEOM_INDEX;
- myActions[myGeomPopup->addAction( tr( "GEOM_BY_MESH_ELEM_SELECTION" ) )] = GEOM_BY_MESH_INDEX;
- connect( myGeomPopup, SIGNAL( triggered( QAction* ) ), SLOT( onGeomPopup( QAction* ) ) );
- }
- connect( myGeomGroupBtn, SIGNAL( toggled(bool) ), this, SLOT( onGeomSelectionButton(bool) ));
- }
- }
-}
-
-
-//=================================================================================
-// function : onGeomSelectionButton()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onGeomSelectionButton(bool isBtnOn)
-{
- if ( myGeomPopup && isBtnOn )
- {
- myCurrentLineEdit = myGeomGroupLine;
- QAction* a = myGeomPopup->exec( QCursor::pos() );
- if (!a || myActions[a] == DIRECT_GEOM_INDEX)
- setSelectionMode(grpGeomSelection);
- }
- else if (!isBtnOn)
- {
- myCurrentLineEdit = 0;
- setSelectionMode(grpAllSelection);
- }
-}
-
-//=================================================================================
-// function : onGeomPopup()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::onGeomPopup( QAction* a )
-{
- int index = myActions[a];
- if ( index == GEOM_BY_MESH_INDEX )
- {
- mySelectionMode = grpNoSelection;
- if ( !myShapeByMeshOp ) {
- myShapeByMeshOp = new SMESHGUI_ShapeByMeshOp(true);
- connect(myShapeByMeshOp, SIGNAL(committed(SUIT_Operation*)),
- SLOT(onPublishShapeByMeshDlg(SUIT_Operation*)));
- connect(myShapeByMeshOp, SIGNAL(aborted(SUIT_Operation*)),
- SLOT(onCloseShapeByMeshDlg(SUIT_Operation*)));
- }
- // set mesh object to SMESHGUI_ShapeByMeshOp and start it
- if ( !myMesh->_is_nil() ) {
- myIsBusy = true;
- hide(); // stop processing selection
- myIsBusy = false;
- myShapeByMeshOp->setModule( mySMESHGUI );
- myShapeByMeshOp->setStudy( 0 ); // it's really necessary
- myShapeByMeshOp->SetMesh( myMesh );
- myShapeByMeshOp->start();
- }
- }
-}
-
-//================================================================================
-/*!
- * \brief SLOT. Is called when Ok is pressed in SMESHGUI_ShapeByMeshDlg
- */
-//================================================================================
-
-void SMESHGUI_AdaptDlg::onPublishShapeByMeshDlg(SUIT_Operation* op)
-{
- if ( myShapeByMeshOp == op ) {
- mySMESHGUI->getApp()->updateObjectBrowser();
- show();
- // Select a found geometry object
- GEOM::GEOM_Object_var aGeomVar = myShapeByMeshOp->GetShape();
- if ( !aGeomVar->_is_nil() )
- {
- QString ID = aGeomVar->GetStudyEntry();
- if ( _PTR(SObject) aGeomSO = SMESH::getStudy()->FindObjectID( ID.toLatin1().data() )) {
- SALOME_ListIO anIOList;
- Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
- ( aGeomSO->GetID().c_str(), "SMESH", aGeomSO->GetName().c_str() );
- anIOList.Append( anIO );
- mySelectionMgr->setSelectedObjects( anIOList, false );
- onObjectSelectionChanged();
- }
- }
- }
-}
-
-//================================================================================
-/*!
- * \brief SLOT. Is called when Close is pressed in SMESHGUI_ShapeByMeshDlg
- */
-//================================================================================
-
-void SMESHGUI_AdaptDlg::onCloseShapeByMeshDlg(SUIT_Operation* op)
-{
- if ( myShapeByMeshOp == op )
- {
- show();
- setSelectionMode(grpGeomSelection);
- }
-}
-
-//=================================================================================
-// function : setGroupColor()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::setGroupColor( const SALOMEDS::Color& theColor )
-{
- QColor aQColor( (int)( theColor.R * 255.0 ),
- (int)( theColor.G * 255.0 ),
- (int)( theColor.B * 255.0 ) );
- setGroupQColor( aQColor );
-}
-
-//=================================================================================
-// function : getGroupColor()
-// purpose :
-//=================================================================================
-SALOMEDS::Color SMESHGUI_AdaptDlg::getGroupColor() const
-{
- QColor aQColor = getGroupQColor();
-
- SALOMEDS::Color aColor;
- aColor.R = (float)aQColor.red() / 255.0;
- aColor.G = (float)aQColor.green() / 255.0;
- aColor.B = (float)aQColor.blue() / 255.0;
-
- return aColor;
-}
-
-//=================================================================================
-// function : setGroupQColor()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::setGroupQColor( const QColor& theColor )
-{
- if( theColor.isValid() )
- myColorBtn->setColor( theColor );
-}
-
-//=================================================================================
-// function : getGroupQColor()
-// purpose :
-//=================================================================================
-QColor SMESHGUI_AdaptDlg::getGroupQColor() const
-{
- return myColorBtn->color();
-}
-
-//=================================================================================
-// function : setDefaultGroupColor()
-// purpose :
-//=================================================================================
-void SMESHGUI_AdaptDlg::setDefaultGroupColor()
-{
- if( myMesh->_is_nil() )
- return;
-
- bool isAutoColor = myMesh->GetAutoColor();
-
- QColor aQColor = myColorBtn->color();
- if( !isAutoColor )
- {
- if ( !aQColor.isValid() ) {
- int r = 0, g = 0, b = 0;
- SMESH::GetColor( "SMESH", "default_grp_color", r, g, b, QColor( 255, 170, 0 ) );
- aQColor.setRgb( r, g, b );
- }
- }
- else
- {
-#ifdef SIMPLE_AUTOCOLOR // simplified algorithm for auto-colors
- SALOMEDS::Color aColor = SMESHGUI::getPredefinedUniqueColor();
-#else // old algorithm for auto-colors
- SMESH::ListOfGroups aListOfGroups = *myMesh->GetGroups();
-
- QList<SALOMEDS::Color> aReservedColors;
- for( int i = 0, n = aListOfGroups.length(); i < n; i++ )
- {
- SMESH::SMESH_GroupBase_var aGroupObject = aListOfGroups[i];
- SALOMEDS::Color aReservedColor = aGroupObject->GetColor();
- aReservedColors.append( aReservedColor );
- }
-
- SALOMEDS::Color aColor = SMESHGUI::getUniqueColor( aReservedColors );
-#endif // SIMPLE_AUTOCOLOR
-
- aQColor.setRgb( (int)( aColor.R * 255.0 ),
- (int)( aColor.G * 255.0 ),
- (int)( aColor.B * 255.0 ) );
-
- }
-
- setGroupQColor( aQColor );
-}
-
-//=================================================================================
-// function : SetAppropriateActor()
-// purpose : Find more appropriate of visible actors, set it to myActor, allow picking
-// NPAL19389: create a group with a selection in another group.
-// if mesh actor is not visible - find any first visible group or sub-mesh
-//=================================================================================
-bool SMESHGUI_AdaptDlg::SetAppropriateActor()
-{
- bool isActor = false;
- myActorsList.clear();
-
- if (myMesh->_is_nil()) return false;
-
- SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
-
- if (myGrpTypeGroup->checkedId() > 0) { // try current group on geometry actor
- SMESH_Actor* anActor = 0;
- if (!myGroupOnGeom->_is_nil())
- anActor = SMESH::FindActorByObject(myGroupOnGeom);
- if (!myGroupOnFilter->_is_nil())
- anActor = SMESH::FindActorByObject(myGroupOnFilter);
- if (anActor && anActor->hasIO())
- {
- isActor = true;
- if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
- isActor = false;
- else
- myActorsList.append(anActor);
- }
- return anActor;
- }
- else {
- // try mesh actor
- SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
- if (anActor && anActor->hasIO()) {
- isActor = true;
- if (aViewWindow && !aViewWindow->isVisible(anActor->getIO()))
- isActor = false;
- else
- myActorsList.append(anActor);
- }
-
- // try group actor
- SMESH_Actor* aGroupActor = 0;
- if (!isActor && !myGroup->_is_nil()) {
- aGroupActor = SMESH::FindActorByObject(myGroup);
- if (aGroupActor && aGroupActor->hasIO())
- myActorsList.append(aGroupActor);
- }
-
- // try any visible actor of group or sub-mesh of current mesh
- if (aViewWindow) {
- // mesh entry
- _PTR(SObject) aSObject = SMESH::FindSObject(myMesh);
- if (aSObject) {
- CORBA::String_var meshEntry = aSObject->GetID().c_str();
- int len = strlen(meshEntry);
-
- // iterate on all actors in current view window, search for
- // any visible actor, that belongs to group or submesh of current mesh
- VTK::ActorCollectionCopy aCopy(aViewWindow->getRenderer()->GetActors());
- vtkActorCollection *aCollection = aCopy.GetActors();
- int nbItems = aCollection->GetNumberOfItems();
- for (int i=0; i<nbItems && !isActor; i++)
- {
- SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(aCollection->GetItemAsObject(i));
- if (anActor && anActor->hasIO()) {
- Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
- if (aViewWindow->isVisible(anIO)) {
- if (anIO->hasEntry() && strncmp(anIO->getEntry(), meshEntry, len) == 0 && !myActorsList.contains(anActor) )
- myActorsList.append(anActor);
- }
- }
- }
- }
- }
-
- // Show a standalone group if nothing else is visible (IPAL52227)
- if ( myActorsList.count() == 1 &&
- myActorsList[0] == aGroupActor &&
- aViewWindow && !aViewWindow->isVisible(aGroupActor->getIO()))
- SMESH::UpdateView( aViewWindow, SMESH::eDisplay, aGroupActor->getIO()->getEntry() );
- }
-
-
- if (myActorsList.count() > 0) {
- QListIterator<SMESH_Actor*> it( myActorsList );
- while ( it.hasNext() ) {
- SMESH_Actor* anActor = it.next();
- if ( IsActorVisible(anActor) )
- anActor->SetPickable(true);
- }
- }
-
- return ( isActor || (myActorsList.count() > 0) );
-}
-
-//=======================================================================
-//function : setShowEntityMode
-//purpose : make shown only entity corresponding to my type
-//=======================================================================
-void SMESHGUI_AdaptDlg::setShowEntityMode()
-{
- if ( !myMesh->_is_nil() ) {
- if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
- if (!myStoredShownEntity)
- myStoredShownEntity = actor->GetEntityMode();
- switch ( myTypeId ) {
- case grpNodeSelection: restoreShowEntityMode(); break;
- case grp0DSelection: actor->SetEntityMode( SMESH_Actor::e0DElements ); break;
- case grpBallSelection: actor->SetEntityMode( SMESH_Actor::eBallElem ); break;
- case grpEdgeSelection: actor->SetEntityMode( SMESH_Actor::eEdges ); break;
- case grpFaceSelection: actor->SetEntityMode( SMESH_Actor::eFaces ); break;
- case grpVolumeSelection: actor->SetEntityMode( SMESH_Actor::eVolumes ); break;
- }
- }
- }
-}
-
-//=======================================================================
-//function : restoreShowEntityMode
-//purpose : restore ShowEntity mode of myActor
-//=======================================================================
-void SMESHGUI_AdaptDlg::restoreShowEntityMode()
-{
- if ( myStoredShownEntity && !myMesh->_is_nil() ) {
- if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) ) {
- actor->SetEntityMode(myStoredShownEntity);
- }
- }
- myStoredShownEntity = 0;
-}
-
-//=======================================================================
-//function : IsActorVisible
-//purpose : return visibility of the actor
-//=======================================================================
-bool SMESHGUI_AdaptDlg::IsActorVisible( SMESH_Actor* theActor )
-{
- SVTK_ViewWindow* aViewWindow = SMESH::GetCurrentVtkView();
- if (theActor && aViewWindow)
- return aViewWindow->isVisible(theActor->getIO());
- return false;
-}
-
-//================================================================
-//function : setIsApplyAndClose
-//purpose : Set value of the flag indicating that the dialog is
-// accepted by Apply & Close button
-//================================================================
-void SMESHGUI_AdaptDlg::setIsApplyAndClose( const bool theFlag )
-{
- myIsApplyAndClose = theFlag;
-}
-
-//================================================================
-//function : isApplyAndClose
-//purpose : Get value of the flag indicating that the dialog is
-// accepted by Apply & Close button
-//================================================================
-bool SMESHGUI_AdaptDlg::isApplyAndClose() const
-{
- return myIsApplyAndClose;
-}