+//=======================================================================
+// function : getFileNames
+// purpose : Select list of files for Import operation. Returns also
+// the selected file type code through <format> argument.
+//=======================================================================
+static QStringList getFileNames( QWidget* parent,
+ const QString& initial,
+ const FilterMap& filterMap,
+ const QString& caption,
+ QString& format,
+ bool showCurrentDirInitially = false)
+{
+ 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;
+}
+
+//=======================================================================
+// function : getParentComponent
+// purpose : Get object's parent component entry
+//=======================================================================
+static QString getParentComponent( _PTR( SObject ) obj )
+{
+ if ( obj ) {
+ _PTR(SComponent) comp = obj->GetFatherComponent();
+ if ( comp )
+ return QString( comp->GetID().c_str() );
+ }
+ return QString();
+}
+
+//=====================================================================================
+// function : inUse
+// purpose : check if the object(s) passed as the the second arguments are used
+// by the other objects in the study
+//=====================================================================================
+static bool inUse( _PTR(Study) study, const QString& component, const QMap<QString,QString>& objects )
+{
+ _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;
+ 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
+ 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;
+}
+
+