Version: 6.3.1
Public Member Functions | Static Public Member Functions | Private Slots | Private Member Functions | Private Attributes

StdMeshersGUI_SubShapeSelectorWdg Class Reference

#include <StdMeshersGUI_SubShapeSelectorWdg.h>

Inheritance diagram for StdMeshersGUI_SubShapeSelectorWdg:
Inheritance graph
[legend]

Public Member Functions

 StdMeshersGUI_SubShapeSelectorWdg (QWidget *parent=0, TopAbs_ShapeEnum aSubShType=TopAbs_EDGE)
 Constructor.
 ~StdMeshersGUI_SubShapeSelectorWdg ()
 Destructor.
SMESH::long_array_var GetListOfIDs ()
void SetListOfIDs (SMESH::long_array_var)
void SetGeomShapeEntry (const QString &theEntry)
const char * GetGeomShapeEntry ()
void SetMainShapeEntry (const QString &theEntry)
const char * GetMainShapeEntry ()
TopoDS_Shape GetGeomShape ()
TopoDS_Shape GetMainShape ()
QList< intGetCorrectedListOfIDs (bool fromSubshapeToMainshape=true)
QString GetValue () const
void showPreview (bool)
 Create a layout, initialize fields.
int GetListSize ()
void SetMaxSize (int aMaxSize)

Static Public Member Functions

static GEOM::GEOM_Object_var GetGeomObjectByEntry (const QString &)
static TopoDS_Shape GetTopoDSByEntry (const QString &)

Private Slots

void onAdd ()
void onRemove ()
void SelectionIntoArgument ()
void onListSelectionChanged ()

Private Member Functions

void updateState ()
void setFilter ()
 Install filters to select sub-shapes of mySubShType or their groups.
void init ()
 Create a layout, initialize fields.

Private Attributes

SMESHGUImySMESHGUI
LightApp_SelectionMgr * mySelectionMgr
SVTK_Selector * mySelector
SMESH::SMESH_Mesh_var myMesh
TopoDS_Shape myGeomShape
TopoDS_Shape myMainShape
QString myEntry
QString myMainEntry
vtkRenderer * myRenderer
QListWidget * myListWidget
QPushButton * myAddButton
QPushButton * myRemoveButton
QList< intmySelectedIDs
QList< intmyListOfIDs
QString myParamValue
bool myIsShown
bool myIsNotCorrected
int myMaxSize
TopAbs_ShapeEnum mySubShType
SMESH_PreviewActorsCollectionmyPreviewActor
QList< SUIT_SelectionFilter * > myGeomFilters
SUIT_SelectionFiltermyFilter

Detailed Description

Definition at line 50 of file StdMeshersGUI_SubShapeSelectorWdg.h.


Constructor & Destructor Documentation

StdMeshersGUI_SubShapeSelectorWdg::StdMeshersGUI_SubShapeSelectorWdg ( QWidget parent = 0,
TopAbs_ShapeEnum  aSubShType = TopAbs_EDGE 
)

Constructor.

Definition at line 85 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESH.GetResourceMgr(), MARGIN, and SPACING.

                                                                                  : 
  QWidget( parent ),
  myPreviewActor( 0 ),
  myMaxSize( -1 )
{
  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 );      
  myListWidget->setSelectionMode( QListWidget::ExtendedSelection );

  edgesLayout->addWidget(myListWidget,   0, 0, 3, 3);
  edgesLayout->addWidget(myAddButton,    0, 4);
  edgesLayout->addWidget(myRemoveButton, 1, 4);

  //edgesLayout->setRowStretch(2, 5);
  edgesLayout->setColumnStretch(2, 5);

  setLayout( edgesLayout );
  setMinimumWidth( 300 );

  mySubShType = aSubShType;

  init();
}
StdMeshersGUI_SubShapeSelectorWdg::~StdMeshersGUI_SubShapeSelectorWdg ( )

Destructor.

Definition at line 122 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESH.GetViewWindow(), myEntry, myFilter, myGeomFilters, myMainShape, myParamValue, myPreviewActor, myRenderer, mySelectionMgr, mySMESHGUI, and SMESH_PreviewActorsCollection.RemoveFromRender().

{
  if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI )) {
    if ( myPreviewActor ) {
      myPreviewActor->RemoveFromRender( myRenderer );
      aViewWindow->Repaint();

      delete myPreviewActor;
      myPreviewActor = 0;
    }
  }
  myEntry = "";
  myParamValue = "";
  myMainShape.Nullify();

  if ( mySelectionMgr && myFilter )
    mySelectionMgr->removeFilter( myFilter );
  delete myFilter; myFilter=0;

  SUIT_SelectionFilter* filter;
  foreach( filter, myGeomFilters )
    delete filter;
}

Member Function Documentation

QList< int > StdMeshersGUI_SubShapeSelectorWdg::GetCorrectedListOfIDs ( bool  fromSubshapeToMainshape = true)

Definition at line 523 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References myGeomShape, myIsNotCorrected, myListOfIDs, myMainShape, mySelectedIDs, and ex21_lamp.size.

Referenced by GetListOfIDs(), and SetListOfIDs().

{
  if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) &&  fromSubshapeToMainshape )
    return myListOfIDs;
  else   if ( ( myMainShape.IsNull() || myGeomShape.IsNull() ) &&  !fromSubshapeToMainshape )
    return mySelectedIDs;

  QList<int> aList;
  TopTools_IndexedMapOfShape   aGeomMap;
  TopTools_IndexedMapOfShape   aMainMap;
  TopExp::MapShapes(myGeomShape, aGeomMap);
  TopExp::MapShapes(myMainShape, aMainMap);

  if ( fromSubshapeToMainshape ) { // convert indexes from subshape to mainshape
    int size = myListOfIDs.size();
    for (int i = 0; i < size; i++) {
      TopoDS_Shape aSubShape = aGeomMap.FindKey( myListOfIDs.at(i) );
      int index = aMainMap.FindIndex( aSubShape );
      aList.append( index );
    }
    myIsNotCorrected = false;
  } else { // convert indexes from main shape to subshape
    int size = mySelectedIDs.size();
    for (int i = 0; i < size; i++) {
      TopoDS_Shape aSubShape = aMainMap.FindKey( mySelectedIDs.at(i) );
      int index = aGeomMap.FindIndex( aSubShape );
      aList.append( index );
    }
  }

  return aList;
}
GEOM::GEOM_Object_var StdMeshersGUI_SubShapeSelectorWdg::GetGeomObjectByEntry ( const QString &  theEntry) [static]

Definition at line 429 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESHGUI.GetSMESHGen().

Referenced by GetTopoDSByEntry(), and SelectionIntoArgument().

{
  GEOM::GEOM_Object_var aGeomObj;
  SALOMEDS::Study_var aStudy = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
  if (aStudy != 0) {
    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);
      aGeomObj = GEOM::GEOM_Object::_narrow(obj);
    }
  }
  return aGeomObj;
}
TopoDS_Shape StdMeshersGUI_SubShapeSelectorWdg.GetGeomShape ( )

Definition at line 68 of file StdMeshersGUI_SubShapeSelectorWdg.h.

{ return myGeomShape; }
const char* StdMeshersGUI_SubShapeSelectorWdg.GetGeomShapeEntry ( )

Definition at line 63 of file StdMeshersGUI_SubShapeSelectorWdg.h.

{ return myEntry.toLatin1().data();}
SMESH::long_array_var StdMeshersGUI_SubShapeSelectorWdg::GetListOfIDs ( )

Definition at line 463 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References GetCorrectedListOfIDs(), myIsNotCorrected, myListOfIDs, myMainEntry, and ex21_lamp.size.

Referenced by StdMeshersGUI_StdHypothesisCreator.storeParams(), and StdMeshersGUI_NbSegmentsCreator.storeParamsToHypo().

{
  SMESH::long_array_var anArray = new SMESH::long_array;

  if ( myMainEntry != "" && myIsNotCorrected )
    myListOfIDs = GetCorrectedListOfIDs( true );

  int size = myListOfIDs.size();
  anArray->length( size );
  if ( size ) {
    for (int i = 0; i < size; i++) {
        anArray[i] = myListOfIDs.at(i);
    }
  }
  return anArray;
}
int StdMeshersGUI_SubShapeSelectorWdg.GetListSize ( )

Definition at line 80 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Referenced by StdMeshersGUI_StdHypothesisCreator.storeParams().

{ return myListOfIDs.size(); }
TopoDS_Shape StdMeshersGUI_SubShapeSelectorWdg.GetMainShape ( )

Definition at line 69 of file StdMeshersGUI_SubShapeSelectorWdg.h.

{ return myMainShape; }
const char * StdMeshersGUI_SubShapeSelectorWdg::GetMainShapeEntry ( )

Definition at line 511 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References myEntry, and myMainEntry.

Referenced by StdMeshersGUI_StdHypothesisCreator.storeParams(), and StdMeshersGUI_NbSegmentsCreator.storeParamsToHypo().

{
  if ( myMainEntry == "")
    return myEntry.toLatin1().data();

  return myMainEntry.toLatin1().data();
}
TopoDS_Shape StdMeshersGUI_SubShapeSelectorWdg::GetTopoDSByEntry ( const QString &  theEntry) [static]

Definition at line 451 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References GetGeomObjectByEntry(), and SMESH_fixation.shape.

Referenced by SetGeomShapeEntry(), and SetMainShapeEntry().

{
  TopoDS_Shape shape;
  GEOM::GEOM_Object_var aGeomObj = GetGeomObjectByEntry( theEntry );
  GEOMBase::GetShape(aGeomObj, shape);
  return shape;
}
QString StdMeshersGUI_SubShapeSelectorWdg.GetValue ( ) const
void StdMeshersGUI_SubShapeSelectorWdg::init ( ) [private]

Create a layout, initialize fields.

Definition at line 152 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESH.GetSelectionMgr(), SMESH.GetSelector(), SMESHGUI.GetSMESHGUI(), SMESH.GetViewWindow(), myAddButton, myFilter, myIsNotCorrected, myListOfIDs, myListWidget, myParamValue, myRemoveButton, mySelectedIDs, mySelectionMgr, mySelector, mySMESHGUI, onAdd(), onListSelectionChanged(), onRemove(), SelectionIntoArgument(), and updateState().

{
  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();

  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()));
  
  connect( mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
  connect( myListWidget,   SIGNAL(itemSelectionChanged()),    this, SLOT(onListSelectionChanged()));

  updateState();
}
void StdMeshersGUI_SubShapeSelectorWdg::onAdd ( ) [private, slot]

Definition at line 315 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References myAddButton, myListOfIDs, myListWidget, myMaxSize, mySelectedIDs, and onListSelectionChanged().

Referenced by init(), and SetListOfIDs().

{
  if ( mySelectedIDs.size() < 1 )
    return;

  myListWidget->blockSignals( true );
  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) );

      QListWidgetItem* anItem = new QListWidgetItem( anID, myListWidget );
      anItem->setSelected(true);
      
      myListOfIDs.append( mySelectedIDs.at(i) );
    }
  }
  onListSelectionChanged();
  myListWidget->blockSignals( false );
  myAddButton->setEnabled( myMaxSize == -1 || myListOfIDs.size() < myMaxSize );
}
void StdMeshersGUI_SubShapeSelectorWdg::onListSelectionChanged ( ) [private, slot]

Definition at line 367 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESH_PreviewActorsCollection.HighlightID(), myListWidget, myPreviewActor, myRemoveButton, and mySelectionMgr.

Referenced by init(), onAdd(), and onRemove().

{
  if ( !myPreviewActor )
    return;

  mySelectionMgr->clearSelected();
  TColStd_MapOfInteger aIndexes;
  QList<QListWidgetItem*> selItems = myListWidget->selectedItems();
  QListWidgetItem* anItem;
  foreach(anItem, selItems)
    myPreviewActor->HighlightID( anItem->text().toInt() );

  // update remove button
  myRemoveButton->setEnabled( selItems.size() > 0 );
}
void StdMeshersGUI_SubShapeSelectorWdg::onRemove ( ) [private, slot]

Definition at line 340 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References myAddButton, myListOfIDs, myListWidget, and onListSelectionChanged().

Referenced by init().

{
  if ( myListWidget->count() < 1 )
    return;

  myListWidget->blockSignals( true );
  QList<QListWidgetItem*> selItems = myListWidget->selectedItems();
  QListWidgetItem* item;
  foreach(item, selItems) {
    QString idStr = item->text();
    int id = idStr.toInt();

    int index = myListOfIDs.indexOf( id );
    myListOfIDs.removeAt( index );
    delete item;
  }

  onListSelectionChanged();
  myListWidget->blockSignals( false );
  
  myAddButton->setEnabled( true );
}
void StdMeshersGUI_SubShapeSelectorWdg::SelectionIntoArgument ( ) [private, slot]

Definition at line 224 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References GetGeomObjectByEntry(), SMESH_PreviewActorsCollection.GetIndexByShape(), Handle(), SMESH_PreviewActorsCollection.HighlightID(), SMESH_test.ind, myAddButton, myEntry, myListWidget, myMaxSize, myPreviewActor, mySelectedIDs, mySelectionMgr, mySubShType, and SMESH_fixation.shape.

Referenced by init().

{
  if ( !myPreviewActor )
    return;

  mySelectedIDs.clear();

  // get selected mesh
  SALOME_ListIO aList;
  mySelectionMgr->selectedObjects( aList );
  int nbSel = aList.Extent();

  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();
        }
        
        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 );
      }
    }
  }
  // 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<QListWidgetItem*> anItems = myListWidget->findItems ( anID, Qt::MatchExactly );
      QListWidgetItem* item;
      foreach(item, anItems)
        item->setSelected(true);
    }
  }
}
void StdMeshersGUI_SubShapeSelectorWdg::setFilter ( ) [private]

Install filters to select sub-shapes of mySubShType or their groups.

Definition at line 187 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESHGUI.activeStudy(), SMESH_LogicalFilter.LO_OR, myFilter, myGeomFilters, mySelectionMgr, mySMESHGUI, and mySubShType.

{
  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 );
}
void StdMeshersGUI_SubShapeSelectorWdg::SetGeomShapeEntry ( const QString &  theEntry)
void StdMeshersGUI_SubShapeSelectorWdg::SetListOfIDs ( SMESH::long_array_var  theIds)

Definition at line 484 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References GetCorrectedListOfIDs(), myListOfIDs, mySelectedIDs, onAdd(), and ex21_lamp.size.

Referenced by StdMeshersGUI_NbSegmentsCreator.buildFrame(), and StdMeshersGUI_StdHypothesisCreator.stdParams().

{
  mySelectedIDs.clear();
  myListOfIDs.clear();
  int size = theIds->length();
  for ( int i = 0; i < size; i++ )
    mySelectedIDs.append( theIds[ i ] );

  mySelectedIDs = GetCorrectedListOfIDs( false );
  onAdd();
}
void StdMeshersGUI_SubShapeSelectorWdg::SetMainShapeEntry ( const QString &  theEntry)
void StdMeshersGUI_SubShapeSelectorWdg.SetMaxSize ( int  aMaxSize)

Definition at line 82 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Referenced by StdMeshersGUI_StdHypothesisCreator.stdParams().

{ myMaxSize = aMaxSize; }
void StdMeshersGUI_SubShapeSelectorWdg::showPreview ( bool  visible)

Create a layout, initialize fields.

Definition at line 205 of file StdMeshersGUI_SubShapeSelectorWdg.cxx.

References SMESH.GetViewWindow(), myIsShown, myPreviewActor, mySMESHGUI, and SMESH_PreviewActorsCollection.SetShown().

Referenced by StdMeshersGUI_NbSegmentsCreator.onValueChanged(), and StdMeshersGUI_StdHypothesisCreator.stdParams().

{
  if ( !myPreviewActor )
    return;

  if ( myIsShown != visible ) {
    myPreviewActor->SetShown( visible );
    
    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
      aViewWindow->Repaint();

    myIsShown = visible;
  }
}
void StdMeshersGUI_SubShapeSelectorWdg::updateState ( ) [private]

Field Documentation

Definition at line 116 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Referenced by showPreview(), and updateState().

Definition at line 120 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Referenced by onAdd(), and SelectionIntoArgument().

SMESH::SMESH_Mesh_var StdMeshersGUI_SubShapeSelectorWdg.myMesh [private]

Definition at line 102 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Definition at line 111 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Referenced by init(), and onListSelectionChanged().

LightApp_SelectionMgr* StdMeshersGUI_SubShapeSelectorWdg.mySelectionMgr [private]

Definition at line 101 of file StdMeshersGUI_SubShapeSelectorWdg.h.

Referenced by init(), and updateState().

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS