X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshersGUI%2FStdMeshersGUI_SubShapeSelectorWdg.cxx;h=03eeb40826441d93012ab4ab671c4542983a4bb7;hp=af60f62de26cb5b67236e7ed58043d1d2e63865d;hb=dca6c871d2836c5f501367c26d81454a3010b262;hpb=bbca2cb797c37bb7695d3f35490bcd328fbddd4e diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index af60f62de..03eeb4082 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -70,41 +71,72 @@ //================================================================================ StdMeshersGUI_SubShapeSelectorWdg -::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent, TopAbs_ShapeEnum aSubShType ): +::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent, + TopAbs_ShapeEnum subShType, + const bool toShowList, + const bool toShowActivateBtn ): QWidget( parent ), - myPreviewActor( 0 ), - myMaxSize( -1 ) + myMaxSize( -1 ), + myPreviewActor( 0 ) { QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) ); - QGridLayout* edgesLayout = new QGridLayout( this ); - edgesLayout->setMargin( MARGIN ); - edgesLayout->setSpacing( SPACING ); - - myListWidget = new QListWidget( this ); - myAddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), this ); - myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this ); + QGridLayout* layout = new QGridLayout( this ); + layout->setMargin( MARGIN ); + layout->setSpacing( SPACING ); + + if ( toShowList ) + { + QPixmap iconSelect (SUIT_Session::session()->resourceMgr()->loadPixmap("SMESH", tr("ICON_SELECT"))); + myListWidget = new QListWidget( this ); + myActivateButton = new QPushButton( iconSelect, "", this ); + myAddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), this ); + myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this ); + myListWidget->setSelectionMode( QListWidget::ExtendedSelection ); + myListWidget->setMinimumWidth(300); + myListWidget->setWrapping(true); + myActivateButton->setCheckable( true ); + } + else + { + myListWidget = 0; + myActivateButton = 0; + myAddButton = 0; + myRemoveButton = 0; + } myInfoLabel = new QLabel( this ); myPrevButton = new QPushButton( "<<", this ); myNextButton = new QPushButton( ">>", this ); - myListWidget->setSelectionMode( QListWidget::ExtendedSelection ); - - edgesLayout->addWidget(myListWidget, 0, 0, 3, 3); - edgesLayout->addWidget(myAddButton, 0, 3); - edgesLayout->addWidget(myRemoveButton, 1, 3); - edgesLayout->addWidget(myInfoLabel, 3, 0, 1, 3); - edgesLayout->addWidget(myPrevButton, 4, 0); - edgesLayout->addWidget(myNextButton, 4, 2); - - edgesLayout->setRowStretch(2, 5); - edgesLayout->setColumnStretch(1, 5); - myListWidget->setMinimumWidth(300); - myInfoLabel->setMinimumWidth(300); - myInfoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + if ( myListWidget ) + { + int row = 0; + layout->addWidget(myListWidget, row, 0, 3+toShowActivateBtn, 3); + if ( toShowActivateBtn ) + layout->addWidget( myActivateButton, row++, 3 ); + else + myActivateButton->hide(); + layout->addWidget(myAddButton, row, 3); + layout->addWidget(myRemoveButton, ++row, 3); + ++row; + layout->addWidget(myInfoLabel, ++row, 0, 1, 3); + layout->addWidget(myPrevButton, ++row, 0); + layout->addWidget(myNextButton, row, 2); + + layout->setRowStretch(row-2, 5); + layout->setColumnStretch(1, 5); + } + else // show only Prev and Next buttons + { + layout->addWidget(myInfoLabel, 0, 0, 1, 2); + layout->addWidget(myPrevButton, 1, 0); + layout->addWidget(myNextButton, 1, 1); + } + //myInfoLabel->setMinimumWidth(300); + //myInfoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); myInfoLabel->setAlignment(Qt::AlignCenter); - mySubShType = aSubShType; + mySubShType = subShType; init(); } @@ -134,6 +166,8 @@ StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg() mySelectionMgr->removeFilter( myFilter ); delete myFilter; myFilter=0; + mySelectionMgr->clearSelected(); + SUIT_SelectionFilter* filter; foreach( filter, myGeomFilters ) delete filter; @@ -148,30 +182,32 @@ StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg() void StdMeshersGUI_SubShapeSelectorWdg::init() { myParamValue = ""; - myIsNotCorrected = true; // to dont call the GetCorrectedValue method twice myListOfIDs.clear(); mySelectedIDs.clear(); - myAddButton->setEnabled( false ); - myRemoveButton->setEnabled( false ); - mySMESHGUI = SMESHGUI::GetSMESHGUI(); mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI ); - mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); + mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode( ActorSelection ); myFilter=0; - //setFilter(); - connect( myAddButton, SIGNAL(clicked()), SLOT(onAdd())); - connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove())); + if ( myListWidget ) + { + myAddButton->setEnabled( false ); + myRemoveButton->setEnabled( false ); + + connect( myListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); + connect( myActivateButton, SIGNAL( toggled(bool) ), SLOT( ActivateSelection(bool))); + connect( myAddButton, SIGNAL(clicked()), SLOT(onAdd())); + connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove())); + } connect( myPrevButton, SIGNAL(clicked()), SLOT(onPrevious())); connect( myNextButton, SIGNAL(clicked()), SLOT(onNext())); - + connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(selectionIntoArgument())); - connect( myListWidget, SIGNAL(itemSelectionChanged()), this, SLOT(onListSelectionChanged())); updateState(); } @@ -184,14 +220,17 @@ void StdMeshersGUI_SubShapeSelectorWdg::init() void StdMeshersGUI_SubShapeSelectorWdg::setFilter() { - SalomeApp_Study* study = mySMESHGUI->activeStudy(); - GEOM_TypeFilter* typeFilter = new GEOM_TypeFilter(study, mySubShType, /*isShapeType=*/true ); - GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study); - gpoupFilter->addSubType( mySubShType ); - myGeomFilters.append( typeFilter ); - myGeomFilters.append( gpoupFilter ); - myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR ); - mySelectionMgr->installFilter( myFilter ); + // if ( !myFilter ) + // { + // SalomeApp_Study* study = mySMESHGUI->activeStudy(); + // GEOM_TypeFilter* typeFilter = new GEOM_TypeFilter(study, mySubShType, /*isShapeType=*/true ); + // GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study); + // gpoupFilter->addSubType( mySubShType ); + // myGeomFilters.append( typeFilter ); + // myGeomFilters.append( gpoupFilter ); + // myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR ); + // } + // mySelectionMgr->installFilter( myFilter ); } //================================================================================ @@ -215,6 +254,38 @@ void StdMeshersGUI_SubShapeSelectorWdg::ShowPreview( bool visible) } } +//================================================================================ +/*! + * \brief Connect/disconnect to change of selection + */ +//================================================================================ + +void StdMeshersGUI_SubShapeSelectorWdg::ActivateSelection( bool toActivate ) +{ + // adjust state of myActivateButton + if ( myActivateButton && + myActivateButton != sender() && + myActivateButton->isChecked() != toActivate ) + { + myActivateButton->toggle(); + return; + } + + if ( !mySelectionMgr ) return; + + if ( toActivate ) + { + connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(selectionIntoArgument())); + } + else + { + disconnect(mySelectionMgr, 0, this, 0 ); + } + + if ( sender() == myActivateButton ) + ShowPreview( toActivate ); +} + //================================================================================ /*! * \brief Clears selected IDs. This is a workaround of a bug that @@ -230,7 +301,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::ClearSelected() //================================================================================= // function : selectionIntoArgument() -// purpose : Called when selection as changed or other case +// purpose : Called when selection has changed or in other cases //================================================================================= void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument() { @@ -253,24 +324,27 @@ void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument() GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study - GEOM::GEOM_Object_var aGeomFatherObj = aGeomObj->GetMainShape(); - QString aFatherEntry = ""; - QString aMainFatherEntry = ""; - TopoDS_Shape shape; - if ( !CORBA::is_nil( aGeomFatherObj ) ) { - // Get Main Shape - GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry.c_str() ); - if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) { // Main Shape is a Group - GEOM::GEOM_Object_var aMainFatherObj = aGeomMain->GetMainShape(); - if ( !CORBA::is_nil( aMainFatherObj ) ) - aMainFatherEntry = aMainFatherObj->GetStudyEntry(); - } - aFatherEntry = aGeomFatherObj->GetStudyEntry(); - } - - if (( ! aFatherEntry.isEmpty() ) && - ( aFatherEntry == myEntry.c_str() || aFatherEntry == aMainFatherEntry ) ) + // commented for IPAL52836 + // + // GEOM::GEOM_Object_var aGeomFatherObj = aGeomObj->GetMainShape(); + // QString aFatherEntry = ""; + // QString aMainFatherEntry = ""; + // TopoDS_Shape shape; + // if ( !CORBA::is_nil( aGeomFatherObj ) ) { + // // Get Main Shape + // GEOM::GEOM_Object_var aGeomMain = GetGeomObjectByEntry( myEntry.c_str() ); + // if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) { // Main Shape is a Group + // GEOM::GEOM_Object_var aMainFatherObj = aGeomMain->GetMainShape(); + // if ( !CORBA::is_nil( aMainFatherObj ) ) + // aMainFatherEntry = aMainFatherObj->GetStudyEntry(); + // } + // aFatherEntry = aGeomFatherObj->GetStudyEntry(); + // } + + // if (( ! aFatherEntry.isEmpty() ) && + // ( aFatherEntry == myEntry.c_str() || aFatherEntry == aMainFatherEntry ) ) { + TopoDS_Shape shape; if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object GEOMBase::GetShape(aGeomObj, shape); if ( !shape.IsNull() ) { @@ -283,8 +357,10 @@ void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument() } } } - } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/ ) { - GEOMBase::GetShape(aGeomObj, shape); + } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/ || + myEntry == IO->getEntry() ) + { + GEOMBase::GetShape(aGeomObj, shape); if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) { int index = myPreviewActor->GetIndexByShape( shape ); if ( index ) { @@ -306,23 +382,28 @@ void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument() } } // update add button - myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) && - mySelectedIDs.size() > 0 && - ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) ); - - //Connect Selected Ids in viewer and dialog's Ids list - bool signalsBlocked = myListWidget->blockSignals( true ); - myListWidget->clearSelection(); - if ( mySelectedIDs.size() > 0 ) { - for (int i = 0; i < mySelectedIDs.size(); i++) { - QString anID = QString(" %1").arg( mySelectedIDs.at(i) ); - QList anItems = myListWidget->findItems ( anID, Qt::MatchExactly ); - QListWidgetItem* item; - foreach(item, anItems) - item->setSelected(true); + if ( myListWidget ) + { + myAddButton->setEnabled(( myListWidget->count() < myMaxSize || myMaxSize == -1 ) && + ( mySelectedIDs.size() > 0 ) && + ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) ); + + //Connect Selected Ids in viewer and dialog's Ids list + bool signalsBlocked = myListWidget->blockSignals( true ); + myListWidget->clearSelection(); + if ( mySelectedIDs.size() > 0 ) { + for (int i = 0; i < mySelectedIDs.size(); i++) { + QString anID = QString(" %1").arg( mySelectedIDs.at(i) ); + QList anItems = myListWidget->findItems ( anID, Qt::MatchExactly ); + QListWidgetItem* item; + foreach(item, anItems) + item->setSelected(true); + } } + myListWidget->blockSignals( signalsBlocked ); } - myListWidget->blockSignals( signalsBlocked ); + + emit shapeSelected(); } //================================================================================= @@ -331,7 +412,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::selectionIntoArgument() //================================================================================= void StdMeshersGUI_SubShapeSelectorWdg::onAdd() { - if ( mySelectedIDs.size() < 1 ) + if ( mySelectedIDs.size() < 1 || !myListWidget ) return; myListWidget->blockSignals( true ); @@ -358,7 +439,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::onAdd() //================================================================================= void StdMeshersGUI_SubShapeSelectorWdg::onRemove() { - if ( myListWidget->count() < 1 ) + if ( myListWidget->count() < 1 || !myListWidget ) return; myListWidget->blockSignals( true ); @@ -383,7 +464,8 @@ void StdMeshersGUI_SubShapeSelectorWdg::onPrevious() { if ( myPreviewActor ) { myPreviewActor->previous(); - myListWidget->clearSelection(); + if ( myListWidget ) + myListWidget->clearSelection(); updateButtons(); if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->Repaint(); @@ -394,7 +476,8 @@ void StdMeshersGUI_SubShapeSelectorWdg::onNext() { if ( myPreviewActor ) { myPreviewActor->next(); - myListWidget->clearSelection(); + if ( myListWidget ) + myListWidget->clearSelection(); updateButtons(); if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->Repaint(); @@ -410,15 +493,19 @@ void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged() if ( !myPreviewActor ) return; - mySelectionMgr->clearSelected(); - TColStd_MapOfInteger aIndexes; + myPreviewActor->HighlightAll( false ); QList selItems = myListWidget->selectedItems(); QListWidgetItem* anItem; foreach(anItem, selItems) myPreviewActor->HighlightID( anItem->text().toInt() ); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->Repaint(); + // update remove button myRemoveButton->setEnabled( selItems.size() > 0 ); + + emit selectionChanged(); } //================================================================================= @@ -446,7 +533,6 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEnt else myMainShape = GetTopoDSByEntry( myMainEntry.c_str() ); updateState(); - myIsNotCorrected = true; } } @@ -456,19 +542,21 @@ void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry( const QString& theEnt //================================================================================= void StdMeshersGUI_SubShapeSelectorWdg::updateState() { - bool state = false; - if ( !myGeomShape.IsNull() ) - state = true; - myInfoLabel->setVisible( false ); + bool state = ( !myGeomShape.IsNull() ); + + myInfoLabel ->setVisible( false ); myPrevButton->setVisible( false ); myNextButton->setVisible( false ); - - myListWidget->setEnabled( state ); - myAddButton->setEnabled( mySelectedIDs.size() > 0 ); - - if (state) { + + if ( myListWidget ) + { + myListWidget->setEnabled( state ); + myAddButton->setEnabled( mySelectedIDs.size() > 0 ); + } + if ( state ) { SUIT_OverrideCursor wc; - myPreviewActor = new SMESH_PreviewActorsCollection(); + if ( !myPreviewActor ) + myPreviewActor = new SMESH_PreviewActorsCollection(); myPreviewActor->SetSelector( mySelector ); myPreviewActor->Init( myGeomShape, myMainShape, mySubShType, myEntry.c_str() ); myPreviewActor->SetShown( false ); @@ -523,9 +611,6 @@ SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs() { SMESH::long_array_var anArray = new SMESH::long_array; - // if ( myMainEntry != "" && myIsNotCorrected ) - // myListOfIDs = GetCorrectedListOfIDs( true ); - int size = myListOfIDs.size(); anArray->length( size ); for (int i = 0; i < size; i++) @@ -546,9 +631,12 @@ bool StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theI for ( int i = 0; i < size; i++ ) mySelectedIDs.append( theIds[ i ] ); - myListWidget->blockSignals( true ); - myListWidget->clear(); - myListWidget->blockSignals( false ); + if ( myListWidget ) + { + myListWidget->blockSignals( true ); + myListWidget->clear(); + myListWidget->blockSignals( false ); + } bool isOk = true; if ( myPreviewActor ) @@ -563,22 +651,10 @@ bool StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs( SMESH::long_array_var theI for ( int i = 0; i < size && isOk; i++ ) isOk = ( theIds[ i ] > 0 && theIds[ i ] <= aMainMap.Extent() ); } - // mySelectedIDs = GetCorrectedListOfIDs( false, &isOk ); onAdd(); return isOk; } -//================================================================================= -// function : SetMainShapeEntry -// purpose : Called to set the Entry of main shape of the mesh -//================================================================================= -// void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry( const QString& theEntry ) -// { -// myMainEntry = theEntry; -// myMainShape = GetTopoDSByEntry( theEntry ); -// myIsNotCorrected = true; -// } - //================================================================================= // function : GetMainShapeEntry // purpose : Called to get the Main Object Entry @@ -589,82 +665,6 @@ const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry() return myMainEntry.c_str(); } -//================================================================================= -// function : GetCorrectedListOfIds -// purpose : Called to convert the list of IDs from sub-shape IDs to main shape IDs -//================================================================================= -// QList -// StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape, -// bool* isOK ) -// { -// if (( myMainShape.IsNull() || myGeomShape.IsNull() ) && fromSubshapeToMainshape ) -// return myListOfIDs; -// else if (( myMainShape.IsNull() /*||*/&& myGeomShape.IsNull() ) && !fromSubshapeToMainshape ) -// return mySelectedIDs; - -// if ( !fromSubshapeToMainshape ) // called from SetListOfIDs -// { -// if ( myMainShape.IsNull() ) -// std::swap( myMainShape, myGeomShape ); -// } - -// QList aList; -// TopTools_IndexedMapOfShape aGeomMap, aMainMap; -// TopExp::MapShapes(myMainShape, aMainMap); -// if ( !myGeomShape.IsNull() ) -// TopExp::MapShapes(myGeomShape, aGeomMap); - -// bool ok = true; -// if ( fromSubshapeToMainshape ) // convert indexes from sub-shape to mainshape -// { -// int size = myListOfIDs.size(); -// for (int i = 0; i < size; i++) { -// int index = myListOfIDs.at(i); -// if ( aGeomMap.Extent() < index ) -// { -// ok = false; -// } -// else -// { -// TopoDS_Shape aSubShape = aGeomMap.FindKey( index ); -// if ( mySubShType != aSubShape.ShapeType() ) -// ok = false; -// if ( !aMainMap.Contains( aSubShape )) -// ok = false; -// else -// index = aMainMap.FindIndex( aSubShape ); -// } -// aList.append( index ); -// } -// myIsNotCorrected = false; -// } -// else // convert indexes from main shape to sub-shape, or just check indices -// { -// int size = mySelectedIDs.size(); -// for (int i = 0; i < size; i++) { -// int index = mySelectedIDs.at(i); -// if ( aMainMap.Extent() < index ) -// { -// ok = false; -// } -// else -// { -// TopoDS_Shape aSubShape = aMainMap.FindKey( index ); -// if ( mySubShType != aSubShape.ShapeType() ) -// ok = false; -// if ( !aGeomMap.Contains( aSubShape ) && !aGeomMap.IsEmpty() ) -// ok = false; -// else -// index = aGeomMap.FindIndex( aSubShape ); -// } -// aList.append( index ); -// } -// } -// if ( isOK ) *isOK = ok; - -// return aList; -// } - void StdMeshersGUI_SubShapeSelectorWdg::updateButtons() { if ( myPreviewActor ) {