1 // Copyright (C) 2007-2011 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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : GEOMBase_Tools.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
27 #include "GEOMToolsGUI.h"
28 #include "GEOMToolsGUI_DeleteDlg.h"
30 #include <GeometryGUI.h>
31 #include "GeometryGUI_Operations.h"
33 #include <GEOM_Operation.h>
34 #include <GEOM_Displayer.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_OverrideCursor.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_Tools.h>
40 #include <SUIT_FileDlg.h>
41 #include <SUIT_Desktop.h>
42 #include <SUIT_ViewModel.h>
43 #include <SUIT_ViewManager.h>
45 #include <SalomeApp_Application.h>
46 #include <SalomeApp_Study.h>
47 #include <LightApp_SelectionMgr.h>
48 #include <GEOMImpl_Types.hxx>
50 #include <SALOME_ListIO.hxx>
51 #include <SALOME_ListIteratorOfListIO.hxx>
52 #include <SALOME_Prs.h>
55 #include <QApplication>
60 #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 std::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 std::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 ) {
289 case GEOMOp::OpDelete: // EDIT - DELETE
292 case GEOMOp::OpImport: // FILE - IMPORT
295 case GEOMOp::OpExport: // FILE - EXPORT
298 case GEOMOp::OpCheckGeom: // TOOLS - CHECK GEOMETRY
301 case GEOMOp::OpSelectVertex: // POPUP - SELECT ONLY - VERTEX
302 OnSelectOnly( GEOM_POINT );
304 case GEOMOp::OpSelectEdge: // POPUP - SELECT ONLY - EDGE
305 OnSelectOnly( GEOM_EDGE );
307 case GEOMOp::OpSelectWire: // POPUP - SELECT ONLY - WIRE
308 OnSelectOnly( GEOM_WIRE );
310 case GEOMOp::OpSelectFace: // POPUP - SELECT ONLY - FACE
311 OnSelectOnly( GEOM_FACE );
313 case GEOMOp::OpSelectShell: // POPUP - SELECT ONLY - SHELL
314 OnSelectOnly( GEOM_SHELL );
316 case GEOMOp::OpSelectSolid: // POPUP - SELECT ONLY - SOLID
317 OnSelectOnly( GEOM_SOLID );
319 case GEOMOp::OpSelectCompound: // POPUP - SELECT ONLY - COMPOUND
320 OnSelectOnly( GEOM_COMPOUND );
322 case GEOMOp::OpSelectAll: // POPUP - SELECT ONLY - SELECT ALL
323 OnSelectOnly( GEOM_ALLOBJECTS );
325 case GEOMOp::OpDeflection: // POPUP - DEFLECTION ANGLE
328 case GEOMOp::OpColor: // POPUP - COLOR
331 case GEOMOp::OpSetTexture: // POPUP - TEXTURE
334 case GEOMOp::OpTransparency: // POPUP - TRANSPARENCY
337 case GEOMOp::OpIncrTransparency: // SHORTCUT - INCREASE TRANSPARENCY
338 OnChangeTransparency( true );
340 case GEOMOp::OpDecrTransparency: // SHORTCUT - DECREASE TRANSPARENCY
341 OnChangeTransparency( false );
343 case GEOMOp::OpIsos: // POPUP - ISOS
346 case GEOMOp::OpIncrNbIsos: // SHORTCUT - INCREASE NB ISOLINES
349 case GEOMOp::OpDecrNbIsos: // SHORTCUT - DECREASE NB ISOLINES
352 case GEOMOp::OpAutoColor: // POPUP - AUTO COLOR
355 case GEOMOp::OpNoAutoColor: // POPUP - DISABLE AUTO COLOR
356 OnDisableAutoColor();
358 case GEOMOp::OpShowChildren: // POPUP - SHOW CHILDREN
359 case GEOMOp::OpHideChildren: // POPUP - HIDE CHILDREN
360 OnShowHideChildren( theCommandID == GEOMOp::OpShowChildren );
362 case GEOMOp::OpPointMarker: // POPUP - POINT MARKER
365 case GEOMOp::OpUnpublishObject:// POPUP - UNPUBLISH
368 case GEOMOp::OpPublishObject:// GEOM ROOT OBJECT - POPUP - PUBLISH
372 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
379 //===============================================================================
380 // function : OnEditDelete()
382 //===============================================================================
383 void GEOMToolsGUI::OnEditDelete()
385 SALOME_ListIO selected;
386 SalomeApp_Application* app =
387 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
391 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
392 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
393 if ( !aSelMgr || !appStudy )
397 aSelMgr->selectedObjects( selected, "ObjectBrowser", false );
398 if ( selected.IsEmpty() )
401 _PTR(Study) aStudy = appStudy->studyDS();
403 // check if study is locked
404 if ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() )->IsLocked() ) {
405 SUIT_MessageBox::warning( app->desktop(),
407 tr("WRN_STUDY_LOCKED") );
408 return; // study is locked
411 // get GEOM component
412 CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
413 QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) );
415 // check each selected object: if belongs to GEOM, if not reference...
416 QMap<QString,QString> toBeDeleted;
417 QMap<QString,QString> allDeleted;
418 bool isComponentSelected = false;
420 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
421 Handle(SALOME_InteractiveObject) anIObject = It.Value();
422 if ( !anIObject->hasEntry() )
423 continue; // invalid object
425 QString entry = anIObject->getEntry();
426 _PTR(SObject) obj = aStudy->FindObjectID( entry.toLatin1().data() );
427 // check parent component
428 QString parentComp = getParentComponent( obj );
429 if ( parentComp != geomComp ) {
430 SUIT_MessageBox::warning( app->desktop(),
431 QObject::tr("ERR_ERROR"),
432 QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ) );
433 return; // not GEOM object selected
436 ///////////////////////////////////////////////////////
437 // if GEOM component is selected, so skip other checks
438 if ( isComponentSelected ) continue;
439 ///////////////////////////////////////////////////////
441 // check if object is reference
442 _PTR(SObject) refobj;
443 if ( obj && obj->ReferencedObject( refobj ) ) {
444 // get the main object by reference IPAL 21354
446 entry = obj->GetID().c_str();
449 QString aName = obj->GetName().c_str();
450 if ( entry == geomComp ) {
451 // GEOM component is selected, skip other checks
452 isComponentSelected = true;
455 toBeDeleted.insert( entry, aName );
456 allDeleted.insert( entry, aName ); // skip GEOM component
457 // browse through all children recursively
458 _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) );
459 for ( it->InitEx( true ); it->More(); it->Next() ) {
460 _PTR(SObject) child( it->Value() );
461 if ( child && child->ReferencedObject( refobj ) )
462 continue; // skip references
463 aName = child->GetName().c_str();
464 if ( !aName.isEmpty() )
465 allDeleted.insert( child->GetID().c_str(), aName );
469 // is there is anything to delete?
470 if ( !isComponentSelected && allDeleted.count() <= 0 )
471 return; // nothing to delete
473 // show confirmation dialog box
474 GEOMToolsGUI_DeleteDlg dlg( app->desktop(), allDeleted, isComponentSelected );
476 return; // operation is cancelled by user
478 // get currently opened views
479 QList<SALOME_View*> views;
481 ViewManagerList vmans = app->viewManagers();
482 SUIT_ViewManager* vman;
483 foreach ( vman, vmans ) {
484 SUIT_ViewModel* vmod = vman->getViewModel();
485 view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
487 views.append( view );
490 _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
491 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
493 if ( isComponentSelected ) {
494 // GEOM component is selected: delete all objects recursively
495 _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
498 _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
499 // remove top-level objects only
500 for ( it->InitEx( false ); it->More(); it->Next() ) {
501 _PTR(SObject) child( it->Value() );
502 // remove object from GEOM engine
503 removeObjectWithChildren( child, aStudy, views, disp );
504 // remove object from study
505 aStudyBuilder->RemoveObjectWithChildren( child );
509 // GEOM component is not selected: check if selected objects are in use
510 if ( inUse( aStudy, geomComp, allDeleted ) ) {
511 SUIT_MessageBox::warning( app->desktop(),
512 QObject::tr("WRN_WARNING"),
513 QObject::tr("DEP_OBJECT") );
514 return; // object(s) in use
516 // ... and then delete all objects
517 QMap<QString, QString>::Iterator it;
518 for ( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
519 _PTR(SObject) obj ( aStudy->FindObjectID( it.key().toLatin1().data() ) );
520 // remove object from GEOM engine
521 removeObjectWithChildren( obj, aStudy, views, disp );
522 // remove objects from study
523 aStudyBuilder->RemoveObjectWithChildren( obj );
530 aSelMgr->setSelectedObjects( selected );
531 getGeometryGUI()->updateObjBrowser();
532 app->updateActions(); //SRN: To update a Save button in the toolbar
535 //=====================================================================================
537 // purpose : BRep, Iges, Step, ...
538 //=====================================================================================
539 bool GEOMToolsGUI::Import()
541 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
542 if ( !app ) return false;
544 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
546 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
549 _PTR(Study) aStudy = stud->studyDS();
551 // check if study is locked
552 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
554 SUIT_MessageBox::warning( app->desktop(),
555 QObject::tr("WRN_WARNING"),
556 QObject::tr("WRN_STUDY_LOCKED") );
560 // check if GEOM engine is available
561 GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
562 if ( CORBA::is_nil( eng ) ) {
563 SUIT_MessageBox::critical( app->desktop(),
564 QObject::tr("WRN_WARNING"),
565 QObject::tr( "GEOM Engine is not started" ) );
569 GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
570 if ( aInsOp->_is_nil() )
573 // obtain a list of available import formats
575 GEOM::string_array_var aFormats, aPatterns;
576 aInsOp->ImportTranslators( aFormats, aPatterns );
578 for ( int i = 0, n = aFormats->length(); i < n; i++ )
579 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
581 // select files to be imported
583 QStringList fileNames = getFileNames( app->desktop(), "", aMap,
584 tr( "GEOM_MEN_IMPORT" ), fileType, true );
587 SUIT_OverrideCursor wc;
589 if ( fileNames.count() == 0 )
590 return false; // nothing selected, return
594 QList< GEOM::GEOM_Object_var > objsForDisplay;
596 QStringList anEntryList;
598 // iterate through all selected files
600 SUIT_MessageBox::StandardButton igesAnswer = SUIT_MessageBox::NoButton;
601 SUIT_MessageBox::StandardButton acisAnswer = SUIT_MessageBox::NoButton;
603 for ( int i = 0; i < fileNames.count(); i++ ) {
604 QString fileName = fileNames[i];
606 if ( fileName.isEmpty() )
609 QString aCurrentType;
610 if ( fileType.isEmpty() ) {
611 // file type is not defined, try to detect
612 QString ext = QFileInfo( fileName ).suffix().toUpper();
613 QRegExp re( "\\*\\.(\\w+)" );
614 for ( FilterMap::const_iterator it = aMap.begin();
615 it != aMap.end() && aCurrentType.isEmpty(); ++it ) {
617 while ( re.indexIn( it.key(), pos ) >= 0 ) {
618 QString f = re.cap(1).trimmed().toUpper();
619 if ( ext == f ) { aCurrentType = it.value(); break; }
620 pos = re.pos() + re.cap(1).length() + 2;
625 aCurrentType = fileType;
628 if ( aCurrentType.isEmpty() ) {
629 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNSUPPORTED_TYPE" ) ) );
633 GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
635 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, /*withExten=*/true ) ) );
638 CORBA::String_var fileN = fileName.toLatin1().constData();
639 CORBA::String_var fileT = aCurrentType.toLatin1().constData();
642 if ( aCurrentType == "IGES" ) {
643 GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, "IGES_UNIT" );
644 bool needConvert = false;
645 TCollection_AsciiString aUnitName = aInsOp->GetErrorCode();
646 if ( aUnitName.SubString( 1, 4 ) == "UNIT" )
647 needConvert = aUnitName.SubString( 6, aUnitName.Length() ) != "M";
650 if ( igesAnswer == SUIT_MessageBox::NoToAll ) {
651 // converting for all files is already approved
652 fileT = "IGES_SCALE";
654 else if ( igesAnswer != SUIT_MessageBox::YesToAll ) {
655 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
656 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
657 igesAnswer = SUIT_MessageBox::question( app->desktop(),
658 "Question",//tr("WRN_WARNING"),
659 tr("GEOM_SCALE_DIMENSIONS"),
660 btns | SUIT_MessageBox::Cancel,
661 SUIT_MessageBox::No );
662 switch ( igesAnswer ) {
663 case SUIT_MessageBox::Cancel:
664 return false; // cancel (break) import operation
665 case SUIT_MessageBox::Yes:
666 case SUIT_MessageBox::YesToAll:
667 break; // scaling is confirmed
668 case SUIT_MessageBox::No:
669 case SUIT_MessageBox::NoAll:
670 fileT = "IGES_SCALE";
672 break; // scaling is rejected
673 } // switch ( igesAnswer )
674 } // if ( igeAnswer != NoToAll )
675 } // if ( needConvert )
676 } // if ( aCurrentType == "IGES" )
677 else if ( aCurrentType == "ACIS" ) {
678 if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) {
679 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
680 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
681 acisAnswer = SUIT_MessageBox::question( app->desktop(),
682 "Question",//tr("WRN_WARNING"),
683 tr("GEOM_PUBLISH_NAMED_SHAPES"),
684 btns | SUIT_MessageBox::Cancel,
685 SUIT_MessageBox::No );
686 if ( acisAnswer == SUIT_MessageBox::Cancel )
687 return false; // cancel (break) import operation
688 } // if ( acisAnswer != YesToAll && acisAnswer != NoToAll )
689 } // else if ( aCurrentType == "ACIS" )
691 GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, fileT );
693 if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
694 QString aPublishObjName =
695 GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, /*withExten=*/true ) );
697 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
698 SALOMEDS::SObject_var aSO = GeometryGUI::GetGeomGen()->PublishInStudy( aDSStudy,
699 SALOMEDS::SObject::_nil(),
701 aPublishObjName.toLatin1().constData() );
702 if( ( !aSO->_is_nil() ) )
703 anEntryList.append( aSO->GetID() );
705 objsForDisplay.append( anObj );
707 if ( aCurrentType == "ACIS" ) {
708 if ( acisAnswer == SUIT_MessageBox::Yes || acisAnswer == SUIT_MessageBox::YesToAll )
709 GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy( aDSStudy, anObj );
716 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( aInsOp->GetErrorCode() ) );
719 catch( const SALOME::SALOME_Exception& S_ex ) {
721 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNKNOWN_IMPORT_ERROR" ) ) );
725 // update object browser
726 getGeometryGUI()->updateObjBrowser( true );
728 // browse published objects
729 app->browseObjects( anEntryList );
731 // display imported model (if only one file is selected)
732 if ( objsForDisplay.count() == 1 )
733 GEOM_Displayer( stud ).Display( objsForDisplay[0].in() );
735 if ( errors.count() > 0 ) {
736 SUIT_MessageBox::critical( app->desktop(),
737 QObject::tr( "GEOM_ERROR" ),
738 QObject::tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
741 app->updateActions(); //SRN: To update a Save button in the toolbar
743 return objsForDisplay.count() > 0;
747 //=====================================================================================
749 // purpose : BRep, Iges, Step
750 //=====================================================================================
751 bool GEOMToolsGUI::Export()
753 SalomeApp_Application* app = getGeometryGUI()->getApp();
754 if (!app) return false;
756 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
758 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
761 _PTR(Study) aStudy = stud->studyDS();
763 GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
764 if ( CORBA::is_nil( eng ) ) {
765 SUIT_MessageBox::critical( app->desktop(),
766 QObject::tr("WRN_WARNING"),
767 QObject::tr( "GEOM Engine is not started" ) );
771 GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
772 if ( aInsOp->_is_nil() )
775 // Obtain a list of available export formats
778 GEOM::string_array_var aFormats, aPatterns;
779 aInsOp->ExportTranslators( aFormats, aPatterns );
780 for ( int i = 0, n = aFormats->length(); i < n; i++ ) {
781 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
782 filters.push_back( (char*)aPatterns[i] );
785 // Get selected objects
786 LightApp_SelectionMgr* sm = app->selectionMgr();
790 SALOME_ListIO selectedObjects;
791 sm->selectedObjects( selectedObjects );
792 bool appropriateObj = false;
794 SALOME_ListIteratorOfListIO It( selectedObjects );
795 for(;It.More();It.Next()) {
796 Handle(SALOME_InteractiveObject) IObject = It.Value();
797 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject( IObject );
799 if ( anObj->_is_nil() )
803 QString file = getFileName(app->desktop(), QString( IObject->getName() ), aMap, filters,
804 tr("GEOM_MEN_EXPORT"), false, fileType, true);
806 // User has pressed "Cancel" --> stop the operation
807 if ( file.isEmpty() || fileType.isEmpty() )
810 GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
812 SUIT_OverrideCursor wc;
814 app->putInfo( tr("GEOM_PRP_EXPORT").arg(SUIT_Tools::file( file, /*withExten=*/true )) );
819 aInsOp->Export( anObj, file.toStdString().c_str(), fileType.toLatin1().constData() );
821 if ( aInsOp->IsDone() )
827 SUIT_MessageBox::critical( app->desktop(),
828 QObject::tr( "GEOM_ERROR" ),
829 QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ) );
833 catch (const SALOME::SALOME_Exception& S_ex) {
834 //QtCatchCorbaException(S_ex);
838 appropriateObj = true;
841 if ( !appropriateObj )
842 SUIT_MessageBox::warning( app->desktop(),
843 QObject::tr("WRN_WARNING"),
844 QObject::tr("GEOM_WRN_NO_APPROPRIATE_SELECTION") );
848 //=====================================================================================
849 // function : RemoveObjectWithChildren
850 // purpose : used by OnEditDelete() method
851 //=====================================================================================
852 void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj,
854 QList<SALOME_View*> views,
855 GEOM_Displayer* disp)
857 // iterate through all children of obj
858 for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
859 _PTR(SObject) child (it->Value());
860 removeObjectWithChildren(child, aStudy, views, disp);
863 // erase object and remove it from engine
864 _PTR(GenericAttribute) anAttr;
865 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
866 _PTR(AttributeIOR) anIOR (anAttr);
868 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
870 // Delete shape in Client
871 const TCollection_AsciiString ASCIor ((char*)anIOR->Value().c_str());
872 getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
874 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj);
875 GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
876 if (!CORBA::is_nil(geomObj)) {
878 //Remove visual properties of the object
879 appStudy->removeObjectFromAll(obj->GetID().c_str());
881 // Erase graphical object
882 QListIterator<SALOME_View*> it( views );
883 while ( it.hasNext() )
884 if ( SALOME_View* view = it.next() )
885 disp->Erase(geomObj, true, view);
887 // Remove object from Engine
888 // We can't directly remove object from engine. All we can do is to unpublish the object
889 // from the study. Another client could be using the object.
890 // Unpublishing is done just after in aStudyBuilder->RemoveObjectWithChildren( child );
891 //GeometryGUI::GetGeomGen()->RemoveObject( geomObj );
896 //=================================================================================
897 // function : deactivate()
898 // purpose : Called when GEOM component is deactivated
899 //=================================================================================
900 void GEOMToolsGUI::deactivate()
902 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
904 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
905 GEOM_Displayer aDisp (appStudy);
906 aDisp.GlobalSelection();
907 getGeometryGUI()->setLocalSelectionMode(GEOM_ALLOBJECTS);
911 //=====================================================================================
913 //=====================================================================================
917 __declspec( dllexport )
919 GEOMGUI* GetLibGUI( GeometryGUI* parent )
921 return new GEOMToolsGUI( parent );