Back to index

salome-geom  6.5.0
Typedefs | Functions | Variables
GEOMToolsGUI.cxx File Reference
#include "GEOMToolsGUI.h"
#include "GEOMToolsGUI_DeleteDlg.h"
#include <GeometryGUI.h>
#include "GeometryGUI_Operations.h"
#include <GEOMBase.h>
#include <GEOM_Operation.h>
#include <GEOM_Displayer.h>
#include <SUIT_Session.h>
#include <SUIT_OverrideCursor.h>
#include <SUIT_MessageBox.h>
#include <SUIT_Tools.h>
#include <SUIT_FileDlg.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewModel.h>
#include <SUIT_ViewManager.h>
#include <SalomeApp_Application.h>
#include <SalomeApp_Study.h>
#include <LightApp_SelectionMgr.h>
#include <GEOMImpl_Types.hxx>
#include <SALOME_ListIO.hxx>
#include <SALOME_ListIteratorOfListIO.hxx>
#include <SALOME_Prs.h>
#include <QApplication>
#include <QMap>
#include <QRegExp>
#include <TCollection_AsciiString.hxx>

Go to the source code of this file.

Typedefs

typedef QMap< QString, QString > FilterMap

Functions

static QString getFileName (QWidget *parent, const QString &initial, const FilterMap &filterMap, const QStringList &filters, const QString &caption, bool open, QString &format, bool showCurrentDirInitially=false)
static QStringList getFileNames (QWidget *parent, const QString &initial, const FilterMap &filterMap, const QString &caption, QString &format, bool showCurrentDirInitially=false)
static QString getParentComponent (_PTR(SObject) obj)
static bool inUse (_PTR(Study) study, const QString &component, const QMap< QString, QString > &objects)
GEOMGUI * GetLibGUI (GeometryGUI *parent)

Variables

static QString lastUsedFilter

Typedef Documentation

typedef QMap<QString, QString> FilterMap

Definition at line 62 of file GEOMToolsGUI.cxx.


Function Documentation

static QString getFileName ( QWidget *  parent,
const QString &  initial,
const FilterMap filterMap,
const QStringList &  filters,
const QString &  caption,
bool  open,
QString &  format,
bool  showCurrentDirInitially = false 
) [static]

Definition at line 70 of file GEOMToolsGUI.cxx.

{
  //QStringList filters;
  QString aBrepFilter;
  for (FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it) {
    //filters.push_back( it.key() );
    if (it.key().contains( "BREP", Qt::CaseInsensitive ))
      aBrepFilter = it.key();
  }

  SUIT_FileDlg* fd = new SUIT_FileDlg( parent, open, true, true );
  if ( !caption.isEmpty() )
    fd->setWindowTitle( caption );

  if ( !initial.isEmpty() )
    fd->selectFile( initial );

  if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
    fd->setDirectory( QDir::currentPath() );

  fd->setFilters( filters );

  if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) ) {
    fd->selectFilter( lastUsedFilter );
  }
  else if ( !aBrepFilter.isEmpty() ) {
    fd->selectFilter( aBrepFilter );
  }

  QString filename;
  if ( fd->exec() == QDialog::Accepted ) {
    filename = fd->selectedFile();
    format = filterMap[fd->selectedFilter()];
    lastUsedFilter = fd->selectedFilter();
  }

  delete fd;
  qApp->processEvents();
  return filename;
}
static QStringList getFileNames ( QWidget *  parent,
const QString &  initial,
const FilterMap filterMap,
const QString &  caption,
QString &  format,
bool  showCurrentDirInitially = false 
) [static]

Definition at line 123 of file GEOMToolsGUI.cxx.

{
  QString aBrepFilter;
  QStringList allFilters;
  QStringList filters;
  QRegExp re( "\\((.*)\\)" );
  re.setMinimal( true );
  for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
    if ( it.value().contains( "BREP", Qt::CaseInsensitive ) && aBrepFilter.isEmpty() )
      aBrepFilter = it.key();
    filters.append( it.key() );
    int pos = 0;
    while ( re.indexIn( it.key(), pos ) >= 0 ) {
      QString f = re.cap(1);
      pos = re.pos() + f.length() + 2;
      allFilters.append( f.simplified() );
    }
  }
  filters.append( QObject::tr( "GEOM_ALL_IMPORT_FILES" ).arg( allFilters.join( " " ) ) );

  SUIT_FileDlg fd( parent, true, true, true );
  fd.setFileMode( SUIT_FileDlg::ExistingFiles );
  if ( !caption.isEmpty() )
    fd.setWindowTitle( caption );
  if ( !initial.isEmpty() )
    fd.selectFile( initial );

  if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
    fd.setDirectory( QDir::currentPath() );

  fd.setFilters( filters );

  if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
    fd.selectFilter( lastUsedFilter );
  else if ( !aBrepFilter.isEmpty() )
    fd.selectFilter( aBrepFilter );

  QStringList filenames;
  if ( fd.exec() ) {
    filenames = fd.selectedFiles();
    format = filterMap.contains( fd.selectedFilter() ) ? filterMap[ fd.selectedFilter() ] : QString();
    lastUsedFilter = fd.selectedFilter();
  }
  qApp->processEvents();
  return filenames;
}
GEOMGUI* GetLibGUI ( GeometryGUI *  parent)

Definition at line 926 of file GEOMToolsGUI.cxx.

  {
    return new GEOMToolsGUI( parent );
  }
static QString getParentComponent ( _PTR(SObject)  obj) [static]

Definition at line 179 of file GEOMToolsGUI.cxx.

{
  if ( obj ) {
    _PTR(SComponent) comp = obj->GetFatherComponent();
    if ( comp )
      return QString( comp->GetID().c_str() );
  }
  return QString();
}
static bool inUse ( _PTR(Study)  study,
const QString &  component,
const QMap< QString, QString > &  objects 
) [static]

Definition at line 194 of file GEOMToolsGUI.cxx.

{
  _PTR(SObject) comp = study->FindObjectID( component.toLatin1().data() );
  if ( !comp )
    return false;

  // collect all GEOM objects being deleted
  QMap<QString, GEOM::GEOM_Object_var> gobjects;
  QMap<QString, QString>::ConstIterator oit;
  std::list<_PTR(SObject)> aSelectedSO;
  for ( oit = objects.begin(); oit != objects.end(); ++oit ) {
    _PTR(SObject) so = study->FindObjectID( oit.key().toLatin1().data() );
    if ( !so )
      continue;
    aSelectedSO.push_back(so);
    CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject( so );
    GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
    if( CORBA::is_nil( geomObj_rem ) )
      continue;
    gobjects.insert( oit.key(), geomObj_rem );
  }

  // Search References with other Modules
  std::list< _PTR(SObject) >::iterator itSO = aSelectedSO.begin();
  for ( ; itSO != aSelectedSO.end(); ++itSO ) {
    std::vector<_PTR(SObject)> aReferences = study->FindDependances( *itSO  );
    int aRefLength = aReferences.size();
    if (aRefLength) {
      for (int i = 0; i < aRefLength; i++) {
        _PTR(SObject) firstSO( aReferences[i] );
        _PTR(SComponent) aComponent = firstSO->GetFatherComponent();
        QString type = aComponent->ComponentDataType().c_str();
        if ( type == "SMESH" )
          return true;
      }
    }
  }

  // browse through all GEOM data tree
  _PTR(ChildIterator) it ( study->NewChildIterator( comp ) );
  for ( it->InitEx( true ); it->More(); it->Next() ) {
    _PTR(SObject) child( it->Value() );
    CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
    GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
    if( CORBA::is_nil( geomObj ) )
      continue;

    GEOM::ListOfGO_var list = geomObj->GetDependency();
    if( list->length() == 0 )
      continue;

    for( int i = 0; i < list->length(); i++ ) {
      bool depends = false;
      bool deleted = false;
      QMap<QString, GEOM::GEOM_Object_var>::Iterator git;
      for ( git = gobjects.begin(); git != gobjects.end() && ( !depends || !deleted ); ++git ) {
        depends = depends || list[i]->_is_equivalent( *git );
        deleted = deleted || git.key() == child->GetID().c_str() ;//geomObj->_is_equivalent( *git );
      }
      if ( depends && !deleted )
        return true;
    }
  }
  return false;
}

Variable Documentation

QString lastUsedFilter [static]

Definition at line 63 of file GEOMToolsGUI.cxx.