X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FStdMeshersGUI%2FStdMeshersGUI_SubShapeSelectorWdg.cxx;h=03b6750b641a71b3691ed7c7396b0f6907ffbd90;hp=a51d6a16d8d269a32e045c906d754814691dbbcf;hb=20c126bc220757c06b5576f71ed6f34ae85e3e40;hpb=b0cd839dd01eea9e46bb1098acdaca42007f1dc8 diff --git a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx index a51d6a16d..03b6750b6 100644 --- a/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx +++ b/src/StdMeshersGUI/StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -1,20 +1,20 @@ -// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 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 -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // File : StdMeshersGUI_SubShapeSelectorWdg.cxx @@ -68,9 +68,6 @@ #include #include -// SALOME KERNEL includes -#include - #define SPACING 6 #define MARGIN 0 @@ -93,20 +90,28 @@ StdMeshersGUI_SubShapeSelectorWdg edgesLayout->setMargin( MARGIN ); edgesLayout->setSpacing( SPACING ); - myListWidget = new QListWidget( this ); + myListWidget = new QListWidget( this ); myAddButton = new QPushButton( tr( "SMESH_BUT_ADD" ), this ); myRemoveButton = new QPushButton( tr( "SMESH_BUT_REMOVE" ), this ); + 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, 4); - edgesLayout->addWidget(myRemoveButton, 1, 4); + 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(2, 5); + edgesLayout->setColumnStretch(1, 5); - setLayout( edgesLayout ); - setMinimumWidth( 300 ); + myListWidget->setMinimumWidth(300); + myInfoLabel->setMinimumWidth(300); + myInfoLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); + myInfoLabel->setAlignment(Qt::AlignCenter); mySubShType = aSubShType; @@ -171,6 +176,8 @@ void StdMeshersGUI_SubShapeSelectorWdg::init() 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())); @@ -239,9 +246,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() for ( ; anIt.More(); anIt.Next()) { // Loop on selected objects Handle(SALOME_InteractiveObject) IO = anIt.Value(); - GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); + GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( IO->getEntry() ); if ( !CORBA::is_nil( aGeomObj ) ) { // Selected Object From Study - GEOM::GEOM_Object_ptr aGeomFatherObj = aGeomObj->GetMainShape(); + GEOM::GEOM_Object_var aGeomFatherObj = aGeomObj->GetMainShape(); QString aFatherEntry = ""; QString aMainFatherEntry = ""; TopoDS_Shape shape; @@ -249,13 +256,13 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() // 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(); + GEOM::GEOM_Object_var 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 @@ -293,9 +300,12 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() } } // update add button - myAddButton->setEnabled( ( myListWidget->count() < myMaxSize || myMaxSize == -1 ) && mySelectedIDs.size() > 0 && ( mySelectedIDs.size() <= myMaxSize || myMaxSize == -1 ) ); + 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++) { @@ -306,6 +316,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument() item->setSelected(true); } } + myListWidget->blockSignals( signalsBlocked ); } //================================================================================= @@ -360,6 +371,28 @@ void StdMeshersGUI_SubShapeSelectorWdg::onRemove() myAddButton->setEnabled( true ); } +void StdMeshersGUI_SubShapeSelectorWdg::onPrevious() +{ + if ( myPreviewActor ) { + myPreviewActor->previous(); + myListWidget->clearSelection(); + updateButtons(); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->Repaint(); + } +} + +void StdMeshersGUI_SubShapeSelectorWdg::onNext() +{ + if ( myPreviewActor ) { + myPreviewActor->next(); + myListWidget->clearSelection(); + updateButtons(); + if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) + aViewWindow->Repaint(); + } +} + //================================================================================= // function : onListSelectionChanged() // purpose : Called when selection in element list is changed @@ -404,6 +437,9 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState() bool state = false; if ( !myGeomShape.IsNull() ) state = true; + myInfoLabel->setVisible( false ); + myPrevButton->setVisible( false ); + myNextButton->setVisible( false ); myListWidget->setEnabled( state ); myAddButton->setEnabled( mySelectedIDs.size() > 0 ); @@ -419,6 +455,7 @@ void StdMeshersGUI_SubShapeSelectorWdg::updateState() myPreviewActor->AddToRender( myRenderer ); aViewWindow->Repaint(); } + updateButtons(); } } @@ -430,18 +467,17 @@ GEOM::GEOM_Object_var StdMeshersGUI_SubShapeSelectorWdg::GetGeomObjectByEntry( c { GEOM::GEOM_Object_var aGeomObj; SALOMEDS::Study_var aStudy = SMESHGUI::GetSMESHGen()->GetCurrentStudy(); - if (aStudy != 0) { + if ( !aStudy->_is_nil() ) + { SALOMEDS::SObject_var aSObj = aStudy->FindObjectID( theEntry.toLatin1().data() ); - SALOMEDS::GenericAttribute_var anAttr; - - if (!aSObj->_is_nil() && aSObj->FindAttribute(anAttr, "AttributeIOR")) { - SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); - CORBA::String_var aVal = anIOR->Value(); - CORBA::Object_var obj = aStudy->ConvertIORToObject(aVal); + if (!aSObj->_is_nil() ) + { + CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); + aSObj->UnRegister(); } } - return aGeomObj; + return aGeomObj._retn(); } //================================================================================= @@ -518,7 +554,7 @@ const char* StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry() //================================================================================= // function : GetCorrectedListOfIds -// purpose : Called to convert the list of IDs from subshape IDs to main shape IDs +// purpose : Called to convert the list of IDs from sub-shape IDs to main shape IDs //================================================================================= QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSubshapeToMainshape ) { @@ -533,7 +569,7 @@ QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSu TopExp::MapShapes(myGeomShape, aGeomMap); TopExp::MapShapes(myMainShape, aMainMap); - if ( fromSubshapeToMainshape ) { // convert indexes from subshape to mainshape + if ( fromSubshapeToMainshape ) { // convert indexes from sub-shape to mainshape int size = myListOfIDs.size(); for (int i = 0; i < size; i++) { TopoDS_Shape aSubShape = aGeomMap.FindKey( myListOfIDs.at(i) ); @@ -541,7 +577,7 @@ QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSu aList.append( index ); } myIsNotCorrected = false; - } else { // convert indexes from main shape to subshape + } else { // convert indexes from main shape to sub-shape int size = mySelectedIDs.size(); for (int i = 0; i < size; i++) { TopoDS_Shape aSubShape = aMainMap.FindKey( mySelectedIDs.at(i) ); @@ -552,3 +588,21 @@ QList StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs( bool fromSu return aList; } + +void StdMeshersGUI_SubShapeSelectorWdg::updateButtons() +{ + if ( myPreviewActor ) { + int total = myPreviewActor->count(); + int chunk = myPreviewActor->currentChunk(); + int chunkSize = myPreviewActor->chunkSize(); + int imin = chunk*chunkSize+1; + int imax = std::min((chunk+1)*chunkSize, total); + bool vis = imax > 0 && total > chunkSize; + myInfoLabel->setVisible( vis ); + myPrevButton->setVisible( vis ); + myNextButton->setVisible( vis ); + myInfoLabel->setText( tr( "X_FROM_Y_ITEMS_SHOWN" ).arg(imin).arg(imax).arg(total) ); + myPrevButton->setEnabled( myPreviewActor->hasPrevious() ); + myNextButton->setEnabled( myPreviewActor->hasNext() ); + } +}