Back to index

salome-smesh  6.5.0
Public Member Functions | Protected Slots | Protected Member Functions | Private Slots | Private Attributes
SMESHGUI_ShapeByMeshOp Class Reference

Operation to publish a sub-shape of the mesh main shape by selecting mesh elements. More...

#include <SMESHGUI_ShapeByMeshDlg.h>

List of all members.

Public Member Functions

 SMESHGUI_ShapeByMeshOp (bool=false)
 Constructor.
virtual ~SMESHGUI_ShapeByMeshOp ()
 Destructor.
virtual LightApp_Dialog * dlg () const
 Gets dialog of this operation.
void Init ()
void SetMesh (SMESH::SMESH_Mesh_ptr)
SMESH::SMESH_Mesh_ptr GetMesh ()
GEOM::GEOM_Object_ptr GetShape ()

Protected Slots

virtual bool onApply ()

Protected Member Functions

virtual void commitOperation ()
virtual void startOperation ()
void activateSelection ()
void setElementID (const QString &)

Private Slots

void onSelectionDone ()
void onTypeChanged (int)
void onElemIdChanged (const QString &)

Private Attributes

SMESHGUI_ShapeByMeshDlg * myDlg
SMESH::SMESH_Mesh_var myMesh
GEOM::GEOM_Object_var myGeomObj
bool myIsManualIdEnter
bool myHasSolids
bool myIsMultipleAllowed

Detailed Description

Operation to publish a sub-shape of the mesh main shape by selecting mesh elements.

Definition at line 75 of file SMESHGUI_ShapeByMeshDlg.h.


Constructor & Destructor Documentation

SMESHGUI_ShapeByMeshOp::SMESHGUI_ShapeByMeshOp ( bool  isMultipleAllowed = false)

Constructor.

Definition at line 166 of file SMESHGUI_ShapeByMeshDlg.cxx.

                                                                    :
  myIsMultipleAllowed(isMultipleAllowed)
{
  if ( GeometryGUI::GetGeomGen()->_is_nil() )// check that GEOM_Gen exists
    GeometryGUI::InitGeomGen();

  myDlg = new SMESHGUI_ShapeByMeshDlg;
  myDlg->setMultipleAllowed(myIsMultipleAllowed);

  connect(myDlg->myElemTypeGroup, SIGNAL(buttonClicked(int)), SLOT(onTypeChanged(int)));
  connect(myDlg->myElementId, SIGNAL(textChanged(const QString&)), SLOT(onElemIdChanged(const QString&)));
}

Here is the call graph for this function:

Destructor.

Definition at line 202 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  if ( myDlg )
    delete myDlg;
}

Member Function Documentation

Definition at line 438 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  selectionMgr()->clearFilters();
  //SMESH::SetPointRepresentation(false);

  myDlg->myGeomName->setText("");

  QString geomName;
  Selection_Mode mode = EdgeSelection;
  switch ( myDlg->myElemTypeGroup->checkedId() ) {
  case EDGE  :
    mode = EdgeSelection;   geomName = tr("GEOM_EDGE"); break;
  case FACE  :
    mode = FaceSelection;   geomName = tr("GEOM_FACE"); break;
  case VOLUME:
    mode = VolumeSelection; geomName = tr(myHasSolids ? "GEOM_SOLID" : "GEOM_SHELL"); break;
  default: return;
  }
  if ( selectionMode() != mode )
    setSelectionMode( mode );

  myDlg->myGeomName->setText( GEOMBase::GetDefaultName( geomName ));
}

Here is the caller graph for this function:

void SMESHGUI_ShapeByMeshOp::commitOperation ( ) [protected, virtual]

Definition at line 303 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  SMESHGUI_SelectionOp::commitOperation();
  try {
    QStringList aListId = myDlg->myElementId->text().split( " ", QString::SkipEmptyParts);
    if (aListId.count() == 1)
      {
        int elemID = (aListId.first()).toInt();
        myGeomObj = GEOM::GEOM_Object::_duplicate(
            SMESHGUI::GetSMESHGen()->GetGeometryByMeshElement
          ( myMesh.in(), elemID, myDlg->myGeomName->text().toLatin1().constData()) );
      }
    else
      {
        GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
        _PTR(Study) aStudy = SMESH::GetActiveStudyDocument();
        
        if (geomGen->_is_nil() || !aStudy)
          return;
        
        GEOM::GEOM_IShapesOperations_var aShapesOp =
          geomGen->GetIShapesOperations(aStudy->StudyId());
        if (aShapesOp->_is_nil() )
          return;
        
        TopAbs_ShapeEnum aGroupType = TopAbs_SHAPE;
        
        std::map<double, GEOM::GEOM_Object_var> aGeomObjectsMap;
        GEOM::GEOM_Object_var aGeomObject;

        GEOM::GEOM_Object_var aMeshShape = myMesh->GetShapeToMesh();
        
        for ( int i = 0; i < aListId.count(); i++ )
          {
            aGeomObject =
              SMESHGUI::GetSMESHGen()->FindGeometryByMeshElement(myMesh.in(), aListId[i].toInt());

            if (aGeomObject->_is_nil()) continue;
            
            double anId = aShapesOp->GetSubShapeIndex(aMeshShape, aGeomObject);
            if (aShapesOp->IsDone() && aGeomObjectsMap.find(anId) == aGeomObjectsMap.end())
              {
                aGeomObjectsMap[anId] = aGeomObject;

                TopAbs_ShapeEnum aSubShapeType = (TopAbs_ShapeEnum)aGeomObject->GetShapeType();
                if (i == 0)
                  aGroupType = aSubShapeType;
                else if (aSubShapeType != aGroupType)
                  aGroupType = TopAbs_SHAPE;
              }
          }
        
        int aNumberOfGO = aGeomObjectsMap.size();
        if (aNumberOfGO == 1)
          myGeomObj = (*aGeomObjectsMap.begin()).second;
        else if (aNumberOfGO > 1)
          {
            GEOM::GEOM_IGroupOperations_var aGroupOp =
              geomGen->GetIGroupOperations(aStudy->StudyId());
            if(aGroupOp->_is_nil())
              return;
            
            GEOM::ListOfGO_var aGeomObjects = new GEOM::ListOfGO();
            aGeomObjects->length( aNumberOfGO );

            int i = 0;
            std::map<double, GEOM::GEOM_Object_var>::iterator anIter;
            for (anIter = aGeomObjectsMap.begin(); anIter!=aGeomObjectsMap.end(); anIter++)
              aGeomObjects[i++] = (*anIter).second;
          
            //create geometry group
            myGeomObj = aGroupOp->CreateGroup(aMeshShape, aGroupType);
            aGroupOp->UnionList(myGeomObj, aGeomObjects);

            if (!aGroupOp->IsDone())
              return;
          }
        
        // publish the GEOM object in study
        QString aNewGeomGroupName ( myDlg->myGeomName->text() );
          
        SALOMEDS::SObject_var aNewGroupSO =
          geomGen->AddInStudy(SMESHGUI::GetSMESHGen()->GetCurrentStudy(), myGeomObj, 
                              aNewGeomGroupName.toLatin1().data(), aMeshShape);
      }
  }
  catch (const SALOME::SALOME_Exception& S_ex) {
    SalomeApp_Tools::QtCatchCorbaException(S_ex);
  }
  catch (...) {
  }

}

Here is the call graph for this function:

LightApp_Dialog * SMESHGUI_ShapeByMeshOp::dlg ( ) const [virtual]

Gets dialog of this operation.

Return values:
LightApp_Dialog*- pointer to dialog of this operation

Definition at line 214 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  return myDlg;
}
SMESH::SMESH_Mesh_ptr SMESHGUI_ShapeByMeshOp::GetMesh ( )

Definition at line 219 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  return myMesh;
}
GEOM::GEOM_Object_ptr SMESHGUI_ShapeByMeshOp::GetShape ( )

Definition at line 228 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  return myGeomObj.in();
}
bool SMESHGUI_ShapeByMeshOp::onApply ( ) [protected, virtual, slot]

Definition at line 397 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  return true;
}
void SMESHGUI_ShapeByMeshOp::onElemIdChanged ( const QString &  theNewText) [private, slot]

Definition at line 479 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  myDlg->setButtonEnabled( false, QtxDialog::OK );

  if ( myIsManualIdEnter && !myMesh->_is_nil() )
  {
    if ( SMESH_Actor* actor = SMESH::FindActorByObject(myMesh) )
    {
      if ( SMDS_Mesh* aMesh = actor->GetObject()->GetMesh() )
      {
        SMDSAbs_ElementType type = SMDSAbs_Edge;
        switch ( myDlg->myElemTypeGroup->checkedId() ) {
        case EDGE  : type = SMDSAbs_Edge;   break;
        case FACE  : type = SMDSAbs_Face;   break;
        case VOLUME: type = SMDSAbs_Volume; break;
        default: return;
        }
        TColStd_MapOfInteger newIndices;
        QStringList aListId = theNewText.split( " ", QString::SkipEmptyParts);
        for ( int i = 0; i < aListId.count(); i++ ) {
          if ( const SMDS_MeshElement * e = aMesh->FindElement( aListId[ i ].toInt() ))
            if ( e->GetType() == type )
              newIndices.Add( e->GetID() );
        }
        
        if ( !newIndices.IsEmpty() )
        {
          if (!myIsMultipleAllowed && newIndices.Extent() != 1)
            return;
          if ( SVTK_Selector* s = selector() ) {
            s->AddOrRemoveIndex( actor->getIO(), newIndices, false );
            viewWindow()->highlight( actor->getIO(), true, true );
            myDlg->setButtonEnabled( true, QtxDialog::OK );
          }
        }
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SMESHGUI_ShapeByMeshOp::onSelectionDone ( ) [private, slot]

Definition at line 406 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  myDlg->setButtonEnabled( false, QtxDialog::OK );
  setElementID("");

  try {
    SALOME_ListIO aList;
    selectionMgr()->selectedObjects(aList, SVTK_Viewer::Type());
    if (!myIsMultipleAllowed && aList.Extent() != 1)
      return;

    SMESH::SMESH_Mesh_var aMesh = SMESH::GetMeshByIO(aList.First());
    if (aMesh->_is_nil() || myMesh->_is_nil() || aMesh->GetId() != myMesh->GetId() )
      return;

    QString aString;
    int nbElems = SMESH::GetNameOfSelectedElements(selector(),//myViewWindow->GetSelector(),
                                                   aList.First(), aString);
    if (nbElems > 0) {
      if (!myIsMultipleAllowed && nbElems != 1 )
        return;
      setElementID( aString );
      myDlg->setButtonEnabled( true, QtxDialog::OK );
    }
  } catch (...) {
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void SMESHGUI_ShapeByMeshOp::onTypeChanged ( int  theType) [private, slot]

Definition at line 467 of file SMESHGUI_ShapeByMeshDlg.cxx.

Here is the call graph for this function:

Here is the caller graph for this function:

void SMESHGUI_ShapeByMeshOp::setElementID ( const QString &  theText) [protected]

Definition at line 524 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  myIsManualIdEnter = false;
  myDlg->myElementId->setText(theText);
  myIsManualIdEnter = true;
}

Here is the caller graph for this function:

void SMESHGUI_ShapeByMeshOp::SetMesh ( SMESH::SMESH_Mesh_ptr  thePtr)

Definition at line 238 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  myMesh    = SMESH::SMESH_Mesh::_duplicate(thePtr);
  myGeomObj = GEOM::GEOM_Object::_nil();
  myHasSolids = false;

  std::vector< bool > hasElement (myDlg->myElemTypeGroup->buttons().count(), false);
  if (!myMesh->_is_nil() )
    {
      //     _PTR(SObject) aSobj = SMESH::FindSObject(myMesh.in());
      //     SUIT_DataOwnerPtr anIObj (new LightApp_DataOwner(aSobj->GetID().c_str()));

      std::vector< int > nbShapes( TopAbs_SHAPE, 0 );
      int shapeDim = 0; // max dim with several shapes
      //if ( /*mySelectionMgr*/ selectionMgr()->isOk(anIObj) ) // check that the mesh has a valid shape
      {
        _PTR(SObject) aSO = SMESH::FindSObject(myMesh.in());
        GEOM::GEOM_Object_var mainShape = SMESH::GetGeom(aSO);
        if ( !mainShape->_is_nil() ) 
          {
            TopoDS_Shape aShape;
            if ( GEOMBase::GetShape(mainShape, aShape))
              {
                TopAbs_ShapeEnum types[4] = { TopAbs_EDGE, TopAbs_FACE, TopAbs_SHELL, TopAbs_SOLID };
                for ( int dim = 4; dim > 0; --dim ) {
                  TopAbs_ShapeEnum type = types[ dim - 1 ];
                  TopAbs_ShapeEnum avoid = ( type == TopAbs_SHELL ) ? TopAbs_SOLID : TopAbs_SHAPE;
                  TopExp_Explorer exp( aShape, type, avoid );
                  for ( ; nbShapes[ type ] < 2 && exp.More(); exp.Next() )
                    ++nbShapes[ type ];
                  if ( nbShapes[ type ] > 1 ) {
                    shapeDim = dim;
                    break;
                  }
                }
              }
          }
      }
      if (shapeDim > 0)
        {
          if ( nbShapes[ TopAbs_SHELL ] + nbShapes[ TopAbs_SOLID ] > 1 )
            shapeDim = 3;
          hasElement[ EDGE ]   = shapeDim > 0 && myMesh->NbEdges();
          hasElement[ FACE ]   = shapeDim > 1 && myMesh->NbFaces();
          hasElement[ VOLUME ] = shapeDim > 2 && myMesh->NbVolumes();
        }
      myHasSolids = nbShapes[ TopAbs_SOLID ];
    }

  // disable inexistant elem types
  for ( int i = 0; i < myDlg->myElemTypeGroup->buttons().count(); ++i ) {
    if ( QAbstractButton* button = myDlg->myElemTypeGroup->button( i ) )
      button->setEnabled( hasElement[ i ] );
  }
  myDlg->myElementId->setEnabled( hasElement[ EDGE ] );
  myDlg->myGeomName-> setEnabled( hasElement[ EDGE ] );

  setElementID("");
}

Here is the call graph for this function:

void SMESHGUI_ShapeByMeshOp::startOperation ( ) [protected, virtual]

Definition at line 184 of file SMESHGUI_ShapeByMeshDlg.cxx.

{
  //SetMesh( SMESH::SMESH_Mesh::_nil() );
  myIsManualIdEnter = false;

  SMESHGUI_SelectionOp::startOperation();

  //activateSelection(); // set filters
  onSelectionDone(); // desable/enable [ OK ]

  myDlg->show();
}

Here is the call graph for this function:


Member Data Documentation

SMESHGUI_ShapeByMeshDlg* SMESHGUI_ShapeByMeshOp::myDlg [private]

Definition at line 106 of file SMESHGUI_ShapeByMeshDlg.h.

GEOM::GEOM_Object_var SMESHGUI_ShapeByMeshOp::myGeomObj [private]

Definition at line 108 of file SMESHGUI_ShapeByMeshDlg.h.

Definition at line 111 of file SMESHGUI_ShapeByMeshDlg.h.

Definition at line 110 of file SMESHGUI_ShapeByMeshDlg.h.

Definition at line 112 of file SMESHGUI_ShapeByMeshDlg.h.

SMESH::SMESH_Mesh_var SMESHGUI_ShapeByMeshOp::myMesh [private]

Definition at line 107 of file SMESHGUI_ShapeByMeshDlg.h.


The documentation for this class was generated from the following files: