X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FStdMeshersGUI%2FStdMeshersGUI_SubShapeSelectorWdg.cxx;h=9a8e3827cdba266006dc49908b8f40e824c8512e;hb=b3fe66157cc51539413e4a7a524627c74c61321d;hp=0705f57119068a14b52bb219877f903518cd4ca7;hpb=a89c4cb3330fa8b0e3420e4e5d8573b45b3810c1;p=modules%2Fsmesh.git diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index 0705f5711..9a8e3827c 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -1,7 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE -// -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2007-2010 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 @@ -19,22 +16,23 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : StdMeshersGUI_SubShapeSelectorWdg.cxx // Author : Open CASCADE S.A.S. (dmv) // SMESH includes // - #include "StdMeshersGUI_SubShapeSelectorWdg.h" // SMESH Includes -#include +#include "SMESH_Type.h" #include "SMESHGUI_MeshUtils.h" -#include -#include -#include +#include "SMESH_Actor.h" +#include "SMESH_PreviewActorsCollection.h" +#include "SMESH_ActorUtils.h" #include "SMESHGUI_GroupUtils.h" #include "SMESH_Gen_i.hxx" #include "SMESHGUI_GEOMGenUtils.h" +#include "SMESH_LogicalFilter.hxx" // SVTK Includes #include @@ -52,6 +50,8 @@ // GEOM Includes #include +#include +#include // Qt includes #include @@ -66,10 +66,12 @@ #include #include #include +#include // SALOME KERNEL includes #include + #define SPACING 6 #define MARGIN 0 @@ -82,7 +84,8 @@ StdMeshersGUI_SubShapeSelectorWdg ::StdMeshersGUI_SubShapeSelectorWdg( QWidget * parent ): QWidget( parent ), - myPreviewActor( 0 ) + myPreviewActor( 0 ), + myMaxSize( -1 ) { QPixmap image0( SMESH::GetResourceMgr( mySMESHGUI )->loadPixmap( "SMESH", tr( "ICON_SELECT" ) ) ); @@ -105,7 +108,6 @@ StdMeshersGUI_SubShapeSelectorWdg setLayout( edgesLayout ); setMinimumWidth( 300 ); - myMaxSize = 1000; mySubShType = TopAbs_EDGE; init(); @@ -131,6 +133,14 @@ StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg() myEntry = ""; myParamValue = ""; myMainShape.Nullify(); + + if ( mySelectionMgr && myFilter ) + mySelectionMgr->removeFilter( myFilter ); + delete myFilter; myFilter=0; + + SUIT_SelectionFilter* filter; + foreach( filter, myGeomFilters ) + delete filter; } //================================================================================ @@ -146,6 +156,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::init() myListOfIDs.clear(); mySelectedIDs.clear(); + myAddButton->setEnabled( false ); + myRemoveButton->setEnabled( false ); + mySMESHGUI = SMESHGUI::GetSMESHGUI(); mySelectionMgr = SMESH::GetSelectionMgr( mySMESHGUI ); mySelector = (SMESH::GetViewWindow( mySMESHGUI ))->GetSelector(); @@ -153,6 +166,16 @@ void StdMeshersGUI_SubShapeSelectorWdg::init() if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) aViewWindow->SetSelectionMode( ActorSelection ); + + SalomeApp_Study* study = mySMESHGUI->activeStudy(); + GEOM_EdgeFilter* edgeFilter = new GEOM_EdgeFilter(study,StdSelect_AnyEdge); + GEOM_CompoundFilter* gpoupFilter = new GEOM_CompoundFilter(study); + gpoupFilter->addSubType( TopAbs_EDGE ); + myGeomFilters.append( edgeFilter ); + myGeomFilters.append( gpoupFilter ); + myFilter = new SMESH_LogicalFilter( myGeomFilters, SMESH_LogicalFilter::LO_OR ); + mySelectionMgr->installFilter( myFilter ); + connect( myAddButton, SIGNAL(clicked()), SLOT(onAdd())); connect( myRemoveButton, SIGNAL(clicked()), SLOT(onRemove())); @@ -199,63 +222,77 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() mySelectionMgr->selectedObjects( aList ); int nbSel = aList.Extent(); - if (nbSel < 1) - return; - - SALOME_ListIteratorOfListIO anIt (aList); + if (nbSel > 0) { + SALOME_ListIteratorOfListIO anIt (aList); - for ( ; anIt.More(); anIt.Next()) { // Loop on selected objects - Handle(SALOME_InteractiveObject) IO = anIt.Value(); - - GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); - if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study - GEOM::GEOM_Object_ptr 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 ); - if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) { // Main Shape is a Group - GEOM::GEOM_Object_ptr aMainFatherObj = aGeomMain->GetMainShape(); - if ( !CORBA::is_nil( aMainFatherObj ) ) - aMainFatherEntry = aMainFatherObj->GetStudyEntry(); - } - aFatherEntry = aGeomFatherObj->GetStudyEntry(); - } + for ( ; anIt.More(); anIt.Next()) { // Loop on selected objects + Handle(SALOME_InteractiveObject) IO = anIt.Value(); - if ( aFatherEntry != "" && ( aFatherEntry == myEntry || aFatherEntry == aMainFatherEntry ) ) { - if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object - GEOMBase::GetShape(aGeomObj, shape); - if ( !shape.IsNull() ) { - TopExp_Explorer exp( shape, mySubShType ); - for ( ; exp.More(); exp.Next() ) { - int index = myPreviewActor->GetIndexByShape( exp.Current() ); - if ( index ) { - mySelectedIDs.append( index ); - myPreviewActor->HighlightID( index ); - } - } - } - } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/ ) { - GEOMBase::GetShape(aGeomObj, shape); - if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) { - int index = myPreviewActor->GetIndexByShape( shape ); - if ( index ) { - mySelectedIDs.append( index ); - myPreviewActor->HighlightID( index ); - } - } - } + GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); + if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study + GEOM::GEOM_Object_ptr 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 ); + if ( !CORBA::is_nil( aGeomMain ) && aGeomMain->GetType() == 37 ) { // Main Shape is a Group + GEOM::GEOM_Object_ptr aMainFatherObj = aGeomMain->GetMainShape(); + if ( !CORBA::is_nil( aMainFatherObj ) ) + aMainFatherEntry = aMainFatherObj->GetStudyEntry(); + } + aFatherEntry = aGeomFatherObj->GetStudyEntry(); + } + + if ( aFatherEntry != "" && ( aFatherEntry == myEntry || aFatherEntry == aMainFatherEntry ) ) + { + if ( aGeomObj->GetType() == 37 /*GEOM_GROUP*/ ) { // Selected Group that belongs the main object + GEOMBase::GetShape(aGeomObj, shape); + if ( !shape.IsNull() ) { + TopExp_Explorer exp( shape, mySubShType ); + for ( ; exp.More(); exp.Next() ) { + int index = myPreviewActor->GetIndexByShape( exp.Current() ); + if ( index ) { + mySelectedIDs.append( index ); + myPreviewActor->HighlightID( index ); + } + } + } + } else if ( aGeomObj->GetType() == 28 /*GEOM_SUBSHAPE*/ ) { + GEOMBase::GetShape(aGeomObj, shape); + if ( !shape.IsNull() && shape.ShapeType() == mySubShType ) { + int index = myPreviewActor->GetIndexByShape( shape ); + if ( index ) { + mySelectedIDs.append( index ); + myPreviewActor->HighlightID( index ); + } + } + } + } + } else { // Selected Actor from Actor Collection + QString anEntry = IO->getEntry(); + QString str = "_"; + int index = anEntry.lastIndexOf( str ); + anEntry.remove(0, index+1); + int ind = anEntry.toInt(); + if ( ind ) + mySelectedIDs.append( ind ); } - } else { // Selected Actor from Actor Collection - QString anEntry = IO->getEntry(); - QString str = "_"; - int index = anEntry.lastIndexOf( str ); - anEntry.remove(0, index+1); - int ind = anEntry.toInt(); - if ( ind ) - mySelectedIDs.append( ind ); + } + } + // 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 + 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); } } } @@ -270,7 +307,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::onAdd() return; myListWidget->blockSignals( true ); - for (int i = 0; i < mySelectedIDs.size(); i++) { + for (int i = 0; i < mySelectedIDs.size() && (myMaxSize == -1 || myListOfIDs.size() < myMaxSize); i++) { if ( myListOfIDs.indexOf( mySelectedIDs.at(i) ) == -1 ) { QString anID = QString(" %1").arg( mySelectedIDs.at(i) ); @@ -281,13 +318,10 @@ void StdMeshersGUI_SubShapeSelectorWdg::onAdd() } } onListSelectionChanged(); - myListWidget->blockSignals( false ); - - if( myListOfIDs.size() >= myMaxSize ) - myAddButton->setEnabled( false ); + myAddButton->setEnabled( myMaxSize == -1 || myListOfIDs.size() < myMaxSize ); } - + //================================================================================= // function : onRemove() // purpose : Called when Remove Button Clicked @@ -330,6 +364,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged() QListWidgetItem* anItem; foreach(anItem, selItems) myPreviewActor->HighlightID( anItem->text().toInt() ); + + // update remove button + myRemoveButton->setEnabled( selItems.size() > 0 ); } //================================================================================= @@ -358,8 +395,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState() state = true; myListWidget->setEnabled( state ); - myAddButton->setEnabled( state ); - myRemoveButton->setEnabled( state ); + myAddButton->setEnabled( mySelectedIDs.size() > 0 ); if (state) { myPreviewActor = new SMESH_PreviewActorsCollection(); @@ -424,7 +460,7 @@ SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs() anArray->length( size ); if ( size ) { for (int i = 0; i < size; i++) { - anArray[i] = myListOfIDs.at(i); + anArray[i] = myListOfIDs.at(i); } } return anArray; @@ -475,8 +511,10 @@ const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry() //================================================================================= QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape ) { - if ( myMainShape.IsNull() || myGeomShape.IsNull() ) + if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) && fromSubshapeToMainshape ) return myListOfIDs; + else if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) && !fromSubshapeToMainshape ) + return mySelectedIDs; QList aList; TopTools_IndexedMapOfShape aGeomMap;