1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : GEOMBase_Tools.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 #include "GEOMToolsGUI.h"
27 #include "GEOMToolsGUI_DeleteDlg.h"
29 #include <GeometryGUI.h>
31 #include <GEOM_Operation.h>
32 #include <GEOM_Displayer.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_OverrideCursor.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_Tools.h>
38 #include <SUIT_FileDlg.h>
39 #include <SUIT_Desktop.h>
40 #include <SUIT_ViewModel.h>
41 #include <SUIT_ViewManager.h>
43 #include <SalomeApp_Application.h>
44 #include <SalomeApp_Study.h>
45 #include <LightApp_SelectionMgr.h>
46 #include <GEOMImpl_Types.hxx>
48 #include <SALOME_ListIO.hxx>
49 #include <SALOME_ListIteratorOfListIO.hxx>
50 #include <SALOME_Prs.h>
53 #include <QApplication>
58 #include <TCollection_AsciiString.hxx>
62 typedef QMap<QString, QString> FilterMap;
63 static QString lastUsedFilter;
65 //=======================================================================
66 // function : getFileName
67 // purpose : Selection of a file name for Import/Export. Returns also
68 // the selected file type code through <filter> argument.
69 //=======================================================================
70 static QString getFileName( QWidget* parent,
71 const QString& initial,
72 const FilterMap& filterMap,
73 const QStringList& filters,
74 const QString& caption,
77 bool showCurrentDirInitially = false )
79 //QStringList filters;
81 for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
82 //filters.push_back( it.key() );
83 if ( it.key().contains( "BREP", Qt::CaseInsensitive ) )
84 aBrepFilter = it.key();
87 SUIT_FileDlg* fd = new SUIT_FileDlg( parent, open, true, true );
88 if ( !caption.isEmpty() )
89 fd->setWindowTitle( caption );
91 if ( !initial.isEmpty() )
92 fd->selectFile( initial );
94 if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
95 fd->setDirectory( QDir::currentPath() );
97 fd->setFilters( filters );
99 if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) ) {
100 fd->selectFilter( lastUsedFilter );
102 else if ( !aBrepFilter.isEmpty() ) {
103 fd->selectFilter( aBrepFilter );
107 if ( fd->exec() == QDialog::Accepted ) {
108 filename = fd->selectedFile();
109 format = filterMap[fd->selectedFilter()];
110 lastUsedFilter = fd->selectedFilter();
114 qApp->processEvents();
118 //=======================================================================
119 // function : getFileNames
120 // purpose : Select list of files for Import operation. Returns also
121 // the selected file type code through <format> argument.
122 //=======================================================================
123 static QStringList getFileNames( QWidget* parent,
124 const QString& initial,
125 const FilterMap& filterMap,
126 const QString& caption,
128 bool showCurrentDirInitially = false)
131 QStringList allFilters;
133 QRegExp re( "\\((.*)\\)" );
134 re.setMinimal( true );
135 for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
136 if ( it.value().contains( "BREP", Qt::CaseInsensitive ) && aBrepFilter.isEmpty() )
137 aBrepFilter = it.key();
138 filters.append( it.key() );
140 while ( re.indexIn( it.key(), pos ) >= 0 ) {
141 QString f = re.cap(1);
142 pos = re.pos() + f.length() + 2;
143 allFilters.append( f.simplified() );
146 filters.append( QObject::tr( "GEOM_ALL_IMPORT_FILES" ).arg( allFilters.join( " " ) ) );
148 SUIT_FileDlg fd( parent, true, true, true );
149 fd.setFileMode( SUIT_FileDlg::ExistingFiles );
150 if ( !caption.isEmpty() )
151 fd.setWindowTitle( caption );
152 if ( !initial.isEmpty() )
153 fd.selectFile( initial );
155 if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
156 fd.setDirectory( QDir::currentPath() );
158 fd.setFilters( filters );
160 if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
161 fd.selectFilter( lastUsedFilter );
162 else if ( !aBrepFilter.isEmpty() )
163 fd.selectFilter( aBrepFilter );
165 QStringList filenames;
167 filenames = fd.selectedFiles();
168 format = filterMap.contains( fd.selectedFilter() ) ? filterMap[ fd.selectedFilter() ] : QString();
169 lastUsedFilter = fd.selectedFilter();
171 qApp->processEvents();
175 //=======================================================================
176 // function : getParentComponent
177 // purpose : Get object's parent component entry
178 //=======================================================================
179 static QString getParentComponent( _PTR( SObject ) obj )
182 _PTR(SComponent) comp = obj->GetFatherComponent();
184 return QString( comp->GetID().c_str() );
189 //=====================================================================================
191 // purpose : check if the object(s) passed as the the second arguments are used
192 // by the other objects in the study
193 //=====================================================================================
194 static bool inUse( _PTR(Study) study, const QString& component, const QMap<QString,QString>& objects )
196 _PTR(SObject) comp = study->FindObjectID( component.toLatin1().data() );
200 // collect all GEOM objects being deleted
201 QMap<QString, GEOM::GEOM_Object_var> gobjects;
202 QMap<QString, QString>::ConstIterator oit;
203 list<_PTR(SObject)> aSelectedSO;
204 for ( oit = objects.begin(); oit != objects.end(); ++oit ) {
205 _PTR(SObject) so = study->FindObjectID( oit.key().toLatin1().data() );
208 aSelectedSO.push_back(so);
209 CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject( so );
210 GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
211 if( CORBA::is_nil( geomObj_rem ) )
213 gobjects.insert( oit.key(), geomObj_rem );
216 // Search References with other Modules
217 list< _PTR(SObject) >::iterator itSO = aSelectedSO.begin();
218 for ( ; itSO != aSelectedSO.end(); ++itSO ) {
219 std::vector<_PTR(SObject)> aReferences = study->FindDependances( *itSO );
220 int aRefLength = aReferences.size();
222 for (int i = 0; i < aRefLength; i++) {
223 _PTR(SObject) firstSO( aReferences[i] );
224 _PTR(SComponent) aComponent = firstSO->GetFatherComponent();
225 QString type = aComponent->ComponentDataType().c_str();
226 if ( type == "SMESH" )
232 // browse through all GEOM data tree
233 _PTR(ChildIterator) it ( study->NewChildIterator( comp ) );
234 for ( it->InitEx( true ); it->More(); it->Next() ) {
235 _PTR(SObject) child( it->Value() );
236 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
237 GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
238 if( CORBA::is_nil( geomObj ) )
241 GEOM::ListOfGO_var list = geomObj->GetDependency();
242 if( list->length() == 0 )
245 for( int i = 0; i < list->length(); i++ ) {
246 bool depends = false;
247 bool deleted = false;
248 QMap<QString, GEOM::GEOM_Object_var>::Iterator git;
249 for ( git = gobjects.begin(); git != gobjects.end() && ( !depends || !deleted ); ++git ) {
250 depends = depends || list[i]->_is_equivalent( *git );
251 deleted = deleted || git.key() == child->GetID().c_str() ;//geomObj->_is_equivalent( *git );
253 if ( depends && !deleted )
261 //=======================================================================
262 // function : GEOMToolsGUI()
263 // purpose : Constructor
264 //=======================================================================
265 GEOMToolsGUI::GEOMToolsGUI( GeometryGUI* parent )
271 //=======================================================================
272 // function : ~GEOMToolsGUI()
273 // purpose : Destructor
274 //=======================================================================
275 GEOMToolsGUI::~GEOMToolsGUI()
280 //=======================================================================
281 // function : OnGUIEvent()
283 //=======================================================================
284 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
286 getGeometryGUI()->EmitSignalDeactivateDialog();
288 switch (theCommandID)
300 case 111: // IMPORT BREP
301 case 112: // IMPORT IGES
302 case 113: // IMPORT STEP
307 case 121: // EXPORT BREP
308 case 122: // EXPORT IGES
309 case 123: // EXPORT STEP
314 case 2171: // POPUP VIEWER - SELECT ONLY - VERTEX
316 OnSelectOnly( GEOM_POINT );
319 case 2172: // POPUP VIEWER - SELECT ONLY - EDGE
321 OnSelectOnly( GEOM_EDGE );
324 case 2173: // POPUP VIEWER - SELECT ONLY - WIRE
326 OnSelectOnly( GEOM_WIRE );
329 case 2174: // POPUP VIEWER - SELECT ONLY - FACE
331 OnSelectOnly( GEOM_FACE );
334 case 2175: // POPUP VIEWER - SELECT ONLY - SHELL
336 OnSelectOnly( GEOM_SHELL );
339 case 2176: // POPUP VIEWER - SELECT ONLY - SOLID
341 OnSelectOnly( GEOM_SOLID );
344 case 2177: // POPUP VIEWER - SELECT ONLY - COMPOUND
346 OnSelectOnly( GEOM_COMPOUND );
349 case 2178: // POPUP VIEWER - SELECT ONLY - SELECT ALL
351 OnSelectOnly( GEOM_ALLOBJECTS );
354 case 411: // SETTINGS - ADD IN STUDY
356 // SAN -- TO BE REMOVED !!!
359 case 412: // SETTINGS - SHADING COLOR
364 case 804: // ADD IN STUDY - POPUP VIEWER
366 // SAN -- TO BE REMOVED !!!!
374 case 5103: // CHECK GEOMETRY
379 case 8032: // COLOR - POPUP VIEWER
384 case 8033: // TRANSPARENCY - POPUP VIEWER
389 case 8034: // ISOS - POPUP VIEWER
394 case 8035: // AUTO COLOR - POPUP VIEWER
399 case 8036: // DISABLE AUTO COLOR - POPUP VIEWER
401 OnDisableAutoColor();
404 case 9024 : // OPEN - OBJBROSER POPUP
411 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
419 //===============================================================================
420 // function : OnEditDelete()
422 //===============================================================================
423 void GEOMToolsGUI::OnEditDelete()
425 SALOME_ListIO selected;
426 SalomeApp_Application* app =
427 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
431 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
432 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
433 if ( !aSelMgr || !appStudy )
437 aSelMgr->selectedObjects( selected, "ObjectBrowser", false );
438 if ( selected.IsEmpty() )
441 _PTR(Study) aStudy = appStudy->studyDS();
443 // check if study is locked
444 if ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() )->IsLocked() ) {
445 SUIT_MessageBox::warning( app->desktop(),
447 tr("WRN_STUDY_LOCKED") );
448 return; // study is locked
451 // get GEOM component
452 CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
453 QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) );
455 // check each selected object: if belongs to GEOM, if not reference...
456 QMap<QString,QString> toBeDeleted;
457 QMap<QString,QString> allDeleted;
458 bool isComponentSelected = false;
459 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
460 Handle(SALOME_InteractiveObject) anIObject = It.Value();
461 if ( !anIObject->hasEntry() )
462 continue; // invalid object
464 QString entry = anIObject->getEntry();
465 _PTR(SObject) obj = aStudy->FindObjectID( entry.toLatin1().data() );
466 // check parent component
467 QString parentComp = getParentComponent( obj );
468 if ( parentComp != geomComp ) {
469 SUIT_MessageBox::warning( app->desktop(),
470 QObject::tr("ERR_ERROR"),
471 QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ) );
472 return; // not GEOM object selected
475 ///////////////////////////////////////////////////////
476 // if GEOM component is selected, so skip other checks
477 if ( isComponentSelected ) continue;
478 ///////////////////////////////////////////////////////
480 // check if object is reference
481 _PTR(SObject) refobj;
482 if ( obj && obj->ReferencedObject( refobj ) )
483 continue; // skip references
485 QString aName = obj->GetName().c_str();
486 if ( entry == geomComp ) {
487 // GEOM component is selected, skip other checks
488 isComponentSelected = true;
491 toBeDeleted.insert( entry, aName );
492 allDeleted.insert( entry, aName ); // skip GEOM component
493 // browse through all children recursively
494 _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) );
495 for ( it->InitEx( true ); it->More(); it->Next() ) {
496 _PTR(SObject) child( it->Value() );
497 if ( child && child->ReferencedObject( refobj ) )
498 continue; // skip references
499 aName = child->GetName().c_str();
500 if ( !aName.isEmpty() )
501 allDeleted.insert( child->GetID().c_str(), aName );
505 // is there is anything to delete?
506 if ( !isComponentSelected && allDeleted.count() <= 0 )
507 return; // nothing to delete
509 // show confirmation dialog box
510 GEOMToolsGUI_DeleteDlg dlg( app->desktop(), allDeleted, isComponentSelected );
512 return; // operation is cancelled by user
514 // get currently opened views
515 QList<SALOME_View*> views;
517 ViewManagerList vmans = app->viewManagers();
518 SUIT_ViewManager* vman;
519 foreach ( vman, vmans ) {
520 SUIT_ViewModel* vmod = vman->getViewModel();
521 view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
523 views.append( view );
526 _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
527 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
529 if ( isComponentSelected ) {
530 // GEOM component is selected: delete all objects recursively
531 _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
534 _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
535 // remove top-level objects only
536 for ( it->InitEx( false ); it->More(); it->Next() ) {
537 _PTR(SObject) child( it->Value() );
538 // remove object from GEOM engine
539 removeObjectWithChildren( child, aStudy, views, disp );
540 // remove object from study
541 aStudyBuilder->RemoveObjectWithChildren( child );
545 // GEOM component is not selected: check if selected objects are in use
546 if ( inUse( aStudy, geomComp, allDeleted ) ) {
547 SUIT_MessageBox::warning( app->desktop(),
548 QObject::tr("WRN_WARNING"),
549 QObject::tr("DEP_OBJECT") );
550 return; // object(s) in use
552 // ... and then delete all objects
553 QMap<QString, QString>::Iterator it;
554 for ( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
555 _PTR(SObject) obj ( aStudy->FindObjectID( it.key().toLatin1().data() ) );
556 // remove object from GEOM engine
557 removeObjectWithChildren( obj, aStudy, views, disp );
558 // remove objects from study
559 aStudyBuilder->RemoveObjectWithChildren( obj );
564 aSelMgr->setSelectedObjects( selected );
565 getGeometryGUI()->updateObjBrowser();
566 app->updateActions(); //SRN: To update a Save button in the toolbar
570 //==============================================================================
571 // function : OnEditCopy()
573 //==============================================================================
574 void GEOMToolsGUI::OnEditCopy()
577 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
578 GEOM::string_array_var listIOR = new GEOM::string_array;
580 const SALOME_ListIO& List = Sel->StoredIObjects();
582 myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
584 Sel->ClearIObjects();
586 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
587 int aStudyID = aStudy->StudyId();
589 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
590 GEOM::GEOM_Object_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
592 GEOM::GEOM_IInsertOperations_var IOp = myGeom->GetIInsertOperations(aStudyID);
593 GEOM::GEOM_Object_var result = IOp->MakeCopy(aShapeInit);
594 myGeomBase->Display(result);
596 catch (const SALOME::SALOME_Exception& S_ex) {
597 QtCatchCorbaException(S_ex);
601 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
605 //=====================================================================================
607 // purpose : BRep, Iges, Step
608 //=====================================================================================
609 bool GEOMToolsGUI::Import()
611 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
612 if (! app) return false;
614 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
616 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
619 _PTR(Study) aStudy = stud->studyDS();
621 // check if study is locked
622 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
624 SUIT_MessageBox::warning( app->desktop(),
625 QObject::tr("WRN_WARNING"),
626 QObject::tr("WRN_STUDY_LOCKED") );
630 // check if GEOM engine is available
631 GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
632 if ( CORBA::is_nil( eng ) ) {
633 SUIT_MessageBox::critical( app->desktop(),
634 QObject::tr("WRN_WARNING"),
635 QObject::tr( "GEOM Engine is not started" ) );
639 GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
640 if ( aInsOp->_is_nil() )
643 // obtain a list of available import formats
645 GEOM::string_array_var aFormats, aPatterns;
646 aInsOp->ImportTranslators( aFormats, aPatterns );
648 for ( int i = 0, n = aFormats->length(); i < n; i++ )
649 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
651 // select files to be imported
653 QStringList fileNames = getFileNames( app->desktop(), "", aMap,
654 tr( "GEOM_MEN_IMPORT" ), fileType, true );
657 SUIT_OverrideCursor wc;
659 if ( fileNames.count() == 0 )
660 return false; // nothing selected, return
664 QList< GEOM::GEOM_Object_var > objsForDisplay;
666 // iterate through all selected files
667 for ( QStringList::ConstIterator it = fileNames.begin(); it != fileNames.end(); ++it ) {
668 QString fileName = *it;
670 if ( fileName.isEmpty() )
673 QString aCurrentType;
674 if ( fileType.isEmpty() ) {
675 // file type is not defined, try to detect
676 QString ext = QFileInfo( fileName ).suffix().toUpper();
677 QRegExp re( "\\*\\.(\\w+)" );
678 for ( FilterMap::const_iterator it = aMap.begin();
679 it != aMap.end() && aCurrentType.isEmpty(); ++it ) {
681 while ( re.indexIn( it.key(), pos ) >= 0 ) {
682 QString f = re.cap(1).trimmed().toUpper();
683 if ( ext == f ) { aCurrentType = it.value(); break; }
684 pos = re.pos() + re.cap(1).length() + 2;
689 aCurrentType = fileType;
692 if ( aCurrentType.isEmpty() ) {
693 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNSUPPORTED_TYPE" ) ) );
698 GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
700 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, /*withExten=*/true ) ) );
703 CORBA::String_var fileN = fileName.toLatin1().constData();
704 CORBA::String_var fileT = aCurrentType.toLatin1().constData();
707 if( aCurrentType == "IGES" ) {
708 GEOM::GEOM_Object_var anObj = aInsOp->Import( fileN, "IGES_UNIT" );
709 TCollection_AsciiString aUnitName = aInsOp->GetErrorCode();
710 //cout<<"GUI: aUnitName = "<<aUnitName.ToCString()<<endl;
711 if( aUnitName.SubString(1,4) == "UNIT" ) {
712 aUnitName = aUnitName.SubString(6,aUnitName.Length());
713 if( aUnitName != "M" ) {
714 if( SUIT_MessageBox::question( app->desktop(),
715 "Question",//tr("WRN_WARNING"),
716 "Length unit in given file is not a 'meter'. Is it needed to scale a model?",
717 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
718 SUIT_MessageBox::No) == SUIT_MessageBox::Yes ) {
719 fileT = "IGES_SCALE";
725 GEOM::GEOM_Object_var anObj = aInsOp->Import( fileN, fileT );
727 if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
728 QString aPublishObjName =
729 GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, /*withExten=*/true ) );
731 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
732 GeometryGUI::GetGeomGen()->PublishInStudy( aDSStudy,
733 SALOMEDS::SObject::_nil(),
735 aPublishObjName.toLatin1().constData() );
737 objsForDisplay.append( anObj );
739 if( aCurrentType == "ACIS" ) {
740 if( SUIT_MessageBox::question( app->desktop(),
741 "Question",//tr("WRN_WARNING"),
742 "Given file contents some names. Is it needed to create groups for named shapes?",
743 SUIT_MessageBox::Yes | SUIT_MessageBox::No,
744 SUIT_MessageBox::No) == SUIT_MessageBox::Yes ) {
745 GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy(aDSStudy, anObj);
753 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( aInsOp->GetErrorCode() ) );
756 catch( const SALOME::SALOME_Exception& S_ex ) {
758 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNKNOWN_IMPORT_ERROR" ) ) );
762 // update object browser
763 getGeometryGUI()->updateObjBrowser( true );
765 // display imported model (if only one file is selected)
766 if ( objsForDisplay.count() == 1 )
767 GEOM_Displayer( stud ).Display( objsForDisplay[0].in() );
769 if ( errors.count() > 0 ) {
770 SUIT_MessageBox::critical( app->desktop(),
771 QObject::tr( "GEOM_ERROR" ),
772 QObject::tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
775 app->updateActions(); //SRN: To update a Save button in the toolbar
777 return objsForDisplay.count() > 0;
781 //=====================================================================================
783 // purpose : BRep, Iges, Step
784 //=====================================================================================
785 bool GEOMToolsGUI::Export()
787 SalomeApp_Application* app = getGeometryGUI()->getApp();
788 if (!app) return false;
790 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
792 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
795 _PTR(Study) aStudy = stud->studyDS();
797 GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
798 if ( CORBA::is_nil( eng ) ) {
799 SUIT_MessageBox::critical( app->desktop(),
800 QObject::tr("WRN_WARNING"),
801 QObject::tr( "GEOM Engine is not started" ) );
805 GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
806 if ( aInsOp->_is_nil() )
809 // Obtain a list of available export formats
812 GEOM::string_array_var aFormats, aPatterns;
813 aInsOp->ExportTranslators( aFormats, aPatterns );
814 for ( int i = 0, n = aFormats->length(); i < n; i++ ) {
815 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
816 filters.push_back( (char*)aPatterns[i] );
819 // Get selected objects
820 LightApp_SelectionMgr* sm = app->selectionMgr();
824 SALOME_ListIO selectedObjects;
825 sm->selectedObjects( selectedObjects );
826 bool appropriateObj = false;
828 SALOME_ListIteratorOfListIO It( selectedObjects );
829 for(;It.More();It.Next()) {
830 Handle(SALOME_InteractiveObject) IObject = It.Value();
831 Standard_Boolean found;
832 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(IObject, found);
834 if ( !found || anObj->_is_nil() )
838 QString file = getFileName(app->desktop(), QString( IObject->getName() ), aMap, filters,
839 tr("GEOM_MEN_EXPORT"), false, fileType, true);
841 // User has pressed "Cancel" --> stop the operation
842 if ( file.isEmpty() || fileType.isEmpty() )
845 GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
847 SUIT_OverrideCursor wc;
849 app->putInfo( tr("GEOM_PRP_EXPORT").arg(SUIT_Tools::file( file, /*withExten=*/true )) );
854 aInsOp->Export( anObj, file.toStdString().c_str(), fileType.toLatin1().constData() );
856 if ( aInsOp->IsDone() )
862 SUIT_MessageBox::critical( app->desktop(),
863 QObject::tr( "GEOM_ERROR" ),
864 QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ) );
868 catch (const SALOME::SALOME_Exception& S_ex) {
869 //QtCatchCorbaException(S_ex);
873 appropriateObj = true;
876 if ( !appropriateObj )
877 SUIT_MessageBox::warning( app->desktop(),
878 QObject::tr("WRN_WARNING"),
879 QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
883 //=====================================================================================
884 // function : RemoveObjectWithChildren
885 // purpose : to be used by OnEditDelete() method
886 //=====================================================================================
887 void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj,
889 QList<SALOME_View*> views,
890 GEOM_Displayer* disp)
892 // iterate through all children of obj
893 for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
894 _PTR(SObject) child (it->Value());
895 removeObjectWithChildren(child, aStudy, views, disp);
898 // erase object and remove it from engine
899 _PTR(GenericAttribute) anAttr;
900 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
901 _PTR(AttributeIOR) anIOR (anAttr);
903 // Delete shape in Client
904 const TCollection_AsciiString ASCIor ((char*)anIOR->Value().c_str());
905 getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
907 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj);
908 GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
909 if (!CORBA::is_nil(geomObj)) {
910 // Erase graphical object
911 QListIterator<SALOME_View*> it( views );
912 while ( it.hasNext() )
913 if ( SALOME_View* view = it.next() )
914 disp->Erase(geomObj, true, view);
916 // Remove object from Engine
917 GeometryGUI::GetGeomGen()->RemoveObject( geomObj );
922 //=================================================================================
923 // function : deactivate()
924 // purpose : Called when GEOM component is deactivated
925 //=================================================================================
926 void GEOMToolsGUI::deactivate()
928 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
930 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
931 GEOM_Displayer aDisp (appStudy);
932 aDisp.GlobalSelection();
933 getGeometryGUI()->setLocalSelectionMode(GEOM_ALLOBJECTS);
937 //=====================================================================================
939 //=====================================================================================
943 __declspec( dllexport )
945 GEOMGUI* GetLibGUI( GeometryGUI* parent )
947 return new GEOMToolsGUI( parent );