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
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>
30 #include "GeometryGUI_Operations.h"
32 #include <GEOM_Operation.h>
33 #include <GEOM_Displayer.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_OverrideCursor.h>
37 #include <SUIT_MessageBox.h>
38 #include <SUIT_Tools.h>
39 #include <SUIT_FileDlg.h>
40 #include <SUIT_Desktop.h>
41 #include <SUIT_ViewModel.h>
42 #include <SUIT_ViewManager.h>
44 #include <SalomeApp_Application.h>
45 #include <SalomeApp_Study.h>
46 #include <LightApp_SelectionMgr.h>
47 #include <GEOMImpl_Types.hxx>
49 #include <SALOME_ListIO.hxx>
50 #include <SALOME_ListIteratorOfListIO.hxx>
51 #include <SALOME_Prs.h>
54 #include <QApplication>
59 #include <TCollection_AsciiString.hxx>
61 typedef QMap<QString, QString> FilterMap;
62 static QString lastUsedFilter;
64 //=======================================================================
65 // function : getFileName
66 // purpose : Selection of a file name for Import/Export. Returns also
67 // the selected file type code through <filter> argument.
68 //=======================================================================
69 static QString getFileName( QWidget* parent,
70 const QString& initial,
71 const FilterMap& filterMap,
72 const QStringList& filters,
73 const QString& caption,
76 bool showCurrentDirInitially = false )
78 //QStringList filters;
80 for (FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it) {
81 //filters.push_back( it.key() );
82 if (it.key().contains( "BREP", Qt::CaseInsensitive ))
83 aBrepFilter = it.key();
86 SUIT_FileDlg* fd = new SUIT_FileDlg( parent, open, true, true );
87 if ( !caption.isEmpty() )
88 fd->setWindowTitle( caption );
90 if ( !initial.isEmpty() )
91 fd->selectFile( initial );
93 if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
94 fd->setDirectory( QDir::currentPath() );
96 fd->setFilters( filters );
98 if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) ) {
99 fd->selectFilter( lastUsedFilter );
101 else if ( !aBrepFilter.isEmpty() ) {
102 fd->selectFilter( aBrepFilter );
106 if ( fd->exec() == QDialog::Accepted ) {
107 filename = fd->selectedFile();
108 format = filterMap[fd->selectedFilter()];
109 lastUsedFilter = fd->selectedFilter();
113 qApp->processEvents();
117 //=======================================================================
118 // function : getFileNames
119 // purpose : Select list of files for Import operation. Returns also
120 // the selected file type code through <format> argument.
121 //=======================================================================
122 static QStringList getFileNames( QWidget* parent,
123 const QString& initial,
124 const FilterMap& filterMap,
125 const QString& caption,
127 bool showCurrentDirInitially = false)
130 QStringList allFilters;
132 QRegExp re( "\\((.*)\\)" );
133 re.setMinimal( true );
134 for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
135 if ( it.value().contains( "BREP", Qt::CaseInsensitive ) && aBrepFilter.isEmpty() )
136 aBrepFilter = it.key();
137 filters.append( it.key() );
139 while ( re.indexIn( it.key(), pos ) >= 0 ) {
140 QString f = re.cap(1);
141 pos = re.pos() + f.length() + 2;
142 allFilters.append( f.simplified() );
145 filters.append( QObject::tr( "GEOM_ALL_IMPORT_FILES" ).arg( allFilters.join( " " ) ) );
147 SUIT_FileDlg fd( parent, true, true, true );
148 fd.setFileMode( SUIT_FileDlg::ExistingFiles );
149 if ( !caption.isEmpty() )
150 fd.setWindowTitle( caption );
151 if ( !initial.isEmpty() )
152 fd.selectFile( initial );
154 if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
155 fd.setDirectory( QDir::currentPath() );
157 fd.setFilters( filters );
159 if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
160 fd.selectFilter( lastUsedFilter );
161 else if ( !aBrepFilter.isEmpty() )
162 fd.selectFilter( aBrepFilter );
164 QStringList filenames;
166 filenames = fd.selectedFiles();
167 format = filterMap.contains( fd.selectedFilter() ) ? filterMap[ fd.selectedFilter() ] : QString();
168 lastUsedFilter = fd.selectedFilter();
170 qApp->processEvents();
174 //=======================================================================
175 // function : getParentComponent
176 // purpose : Get object's parent component entry
177 //=======================================================================
178 static QString getParentComponent( _PTR( SObject ) obj )
181 _PTR(SComponent) comp = obj->GetFatherComponent();
183 return QString( comp->GetID().c_str() );
188 //=====================================================================================
190 // purpose : check if the object(s) passed as the the second arguments are used
191 // by the other objects in the study
192 //=====================================================================================
193 static bool inUse( _PTR(Study) study, const QString& component, const QMap<QString,QString>& objects )
195 _PTR(SObject) comp = study->FindObjectID( component.toLatin1().data() );
199 // collect all GEOM objects being deleted
200 QMap<QString, GEOM::GEOM_Object_var> gobjects;
201 QMap<QString, QString>::ConstIterator oit;
202 std::list<_PTR(SObject)> aSelectedSO;
203 for ( oit = objects.begin(); oit != objects.end(); ++oit ) {
204 _PTR(SObject) so = study->FindObjectID( oit.key().toLatin1().data() );
207 aSelectedSO.push_back(so);
208 CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject( so );
209 GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
210 if( CORBA::is_nil( geomObj_rem ) )
212 gobjects.insert( oit.key(), geomObj_rem );
215 // Search References with other Modules
216 std::list< _PTR(SObject) >::iterator itSO = aSelectedSO.begin();
217 for ( ; itSO != aSelectedSO.end(); ++itSO ) {
218 std::vector<_PTR(SObject)> aReferences = study->FindDependances( *itSO );
219 int aRefLength = aReferences.size();
221 for (int i = 0; i < aRefLength; i++) {
222 _PTR(SObject) firstSO( aReferences[i] );
223 _PTR(SComponent) aComponent = firstSO->GetFatherComponent();
224 QString type = aComponent->ComponentDataType().c_str();
225 if ( type == "SMESH" )
231 // browse through all GEOM data tree
232 _PTR(ChildIterator) it ( study->NewChildIterator( comp ) );
233 for ( it->InitEx( true ); it->More(); it->Next() ) {
234 _PTR(SObject) child( it->Value() );
235 CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
236 GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
237 if( CORBA::is_nil( geomObj ) )
240 GEOM::ListOfGO_var list = geomObj->GetDependency();
241 if( list->length() == 0 )
244 for( int i = 0; i < list->length(); i++ ) {
245 bool depends = false;
246 bool deleted = false;
247 QMap<QString, GEOM::GEOM_Object_var>::Iterator git;
248 for ( git = gobjects.begin(); git != gobjects.end() && ( !depends || !deleted ); ++git ) {
249 depends = depends || list[i]->_is_equivalent( *git );
250 deleted = deleted || git.key() == child->GetID().c_str() ;//geomObj->_is_equivalent( *git );
252 if ( depends && !deleted )
259 //=======================================================================
260 // function : GEOMToolsGUI()
261 // purpose : Constructor
262 //=======================================================================
263 GEOMToolsGUI::GEOMToolsGUI( GeometryGUI* parent )
268 //=======================================================================
269 // function : ~GEOMToolsGUI()
270 // purpose : Destructor
271 //=======================================================================
272 GEOMToolsGUI::~GEOMToolsGUI()
276 //=======================================================================
277 // function : OnGUIEvent()
279 //=======================================================================
280 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
282 getGeometryGUI()->EmitSignalDeactivateDialog();
284 switch ( theCommandID ) {
285 case GEOMOp::OpDelete: // EDIT - DELETE
288 case GEOMOp::OpImport: // FILE - IMPORT
291 case GEOMOp::OpExport: // FILE - EXPORT
294 case GEOMOp::OpCheckGeom: // TOOLS - CHECK GEOMETRY
297 case GEOMOp::OpSelectVertex: // POPUP - SELECT ONLY - VERTEX
298 OnSelectOnly( GEOM_POINT );
300 case GEOMOp::OpSelectEdge: // POPUP - SELECT ONLY - EDGE
301 OnSelectOnly( GEOM_EDGE );
303 case GEOMOp::OpSelectWire: // POPUP - SELECT ONLY - WIRE
304 OnSelectOnly( GEOM_WIRE );
306 case GEOMOp::OpSelectFace: // POPUP - SELECT ONLY - FACE
307 OnSelectOnly( GEOM_FACE );
309 case GEOMOp::OpSelectShell: // POPUP - SELECT ONLY - SHELL
310 OnSelectOnly( GEOM_SHELL );
312 case GEOMOp::OpSelectSolid: // POPUP - SELECT ONLY - SOLID
313 OnSelectOnly( GEOM_SOLID );
315 case GEOMOp::OpSelectCompound: // POPUP - SELECT ONLY - COMPOUND
316 OnSelectOnly( GEOM_COMPOUND );
318 case GEOMOp::OpSelectAll: // POPUP - SELECT ONLY - SELECT ALL
319 OnSelectOnly( GEOM_ALLOBJECTS );
321 case GEOMOp::OpDeflection: // POPUP - DEFLECTION ANGLE
324 case GEOMOp::OpColor: // POPUP - COLOR
327 case GEOMOp::OpSetTexture: // POPUP - TEXTURE
330 case GEOMOp::OpTransparency: // POPUP - TRANSPARENCY
333 case GEOMOp::OpIncrTransparency: // SHORTCUT - INCREASE TRANSPARENCY
334 OnChangeTransparency( true );
336 case GEOMOp::OpDecrTransparency: // SHORTCUT - DECREASE TRANSPARENCY
337 OnChangeTransparency( false );
339 case GEOMOp::OpIsos: // POPUP - ISOS
342 case GEOMOp::OpIncrNbIsos: // SHORTCUT - INCREASE NB ISOLINES
345 case GEOMOp::OpDecrNbIsos: // SHORTCUT - DECREASE NB ISOLINES
348 case GEOMOp::OpMaterialProperties: // POPUP - MATERIAL PROPERTIES
349 OnMaterialProperties();
351 case GEOMOp::OpAutoColor: // POPUP - AUTO COLOR
354 case GEOMOp::OpNoAutoColor: // POPUP - DISABLE AUTO COLOR
355 OnDisableAutoColor();
357 case GEOMOp::OpShowChildren: // POPUP - SHOW CHILDREN
358 case GEOMOp::OpHideChildren: // POPUP - HIDE CHILDREN
359 OnShowHideChildren( theCommandID == GEOMOp::OpShowChildren );
361 case GEOMOp::OpPointMarker: // POPUP - POINT MARKER
364 case GEOMOp::OpUnpublishObject:// POPUP - UNPUBLISH
367 case GEOMOp::OpPublishObject:// GEOM ROOT OBJECT - POPUP - PUBLISH
370 case GEOMOp::OpEdgeWidth:
373 case GEOMOp::OpIsosWidth:
377 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
383 //===============================================================================
384 // function : OnEditDelete()
386 //===============================================================================
387 void GEOMToolsGUI::OnEditDelete()
389 SALOME_ListIO selected;
390 SalomeApp_Application* app =
391 dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
395 LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
396 SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
397 if ( !aSelMgr || !appStudy )
401 aSelMgr->selectedObjects( selected, "ObjectBrowser", false );
402 if ( selected.IsEmpty() )
405 _PTR(Study) aStudy = appStudy->studyDS();
407 // check if study is locked
408 if ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() )->IsLocked() ) {
409 SUIT_MessageBox::warning( app->desktop(),
411 tr("WRN_STUDY_LOCKED") );
412 return; // study is locked
415 // get GEOM component
416 CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
417 QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) );
419 // check each selected object: if belongs to GEOM, if not reference...
420 QMap<QString,QString> toBeDeleted;
421 QMap<QString,QString> allDeleted;
422 bool isComponentSelected = false;
424 for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
425 Handle(SALOME_InteractiveObject) anIObject = It.Value();
426 if ( !anIObject->hasEntry() )
427 continue; // invalid object
429 QString entry = anIObject->getEntry();
430 _PTR(SObject) obj = aStudy->FindObjectID( entry.toLatin1().data() );
431 // check parent component
432 QString parentComp = getParentComponent( obj );
433 if ( parentComp != geomComp ) {
434 SUIT_MessageBox::warning( app->desktop(),
435 QObject::tr("ERR_ERROR"),
436 QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ) );
437 return; // not GEOM object selected
440 ///////////////////////////////////////////////////////
441 // if GEOM component is selected, so skip other checks
442 if ( isComponentSelected ) continue;
443 ///////////////////////////////////////////////////////
445 // check if object is reference
446 _PTR(SObject) refobj;
447 if ( obj && obj->ReferencedObject( refobj ) ) {
448 // get the main object by reference IPAL 21354
450 entry = obj->GetID().c_str();
453 QString aName = obj->GetName().c_str();
454 if ( entry == geomComp ) {
455 // GEOM component is selected, skip other checks
456 isComponentSelected = true;
459 toBeDeleted.insert( entry, aName );
460 allDeleted.insert( entry, aName ); // skip GEOM component
461 // browse through all children recursively
462 _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) );
463 for ( it->InitEx( true ); it->More(); it->Next() ) {
464 _PTR(SObject) child( it->Value() );
465 if ( child && child->ReferencedObject( refobj ) )
466 continue; // skip references
467 aName = child->GetName().c_str();
468 if ( !aName.isEmpty() )
469 allDeleted.insert( child->GetID().c_str(), aName );
473 // is there is anything to delete?
474 if ( !isComponentSelected && allDeleted.count() <= 0 )
475 return; // nothing to delete
477 // show confirmation dialog box
478 GEOMToolsGUI_DeleteDlg dlg( app->desktop(), allDeleted, isComponentSelected );
480 return; // operation is cancelled by user
482 // get currently opened views
483 QList<SALOME_View*> views;
485 ViewManagerList vmans = app->viewManagers();
486 SUIT_ViewManager* vman;
487 foreach ( vman, vmans ) {
488 SUIT_ViewModel* vmod = vman->getViewModel();
489 view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
491 views.append( view );
494 _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
495 GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
497 if ( isComponentSelected ) {
498 // GEOM component is selected: delete all objects recursively
499 _PTR(SObject) comp = aStudy->FindObjectID( geomComp.toLatin1().data() );
502 _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
503 // remove top-level objects only
504 for ( it->InitEx( false ); it->More(); it->Next() ) {
505 _PTR(SObject) child( it->Value() );
506 // remove object from GEOM engine
507 removeObjectWithChildren( child, aStudy, views, disp );
508 // remove object from study
509 aStudyBuilder->RemoveObjectWithChildren( child );
513 // GEOM component is not selected: check if selected objects are in use
514 if ( inUse( aStudy, geomComp, allDeleted ) ) {
515 SUIT_MessageBox::warning( app->desktop(),
516 QObject::tr("WRN_WARNING"),
517 QObject::tr("DEP_OBJECT") );
518 return; // object(s) in use
520 // ... and then delete all objects
521 QMap<QString, QString>::Iterator it;
522 for ( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
523 _PTR(SObject) obj ( aStudy->FindObjectID( it.key().toLatin1().data() ) );
524 // remove object from GEOM engine
525 removeObjectWithChildren( obj, aStudy, views, disp );
526 // remove objects from study
527 aStudyBuilder->RemoveObjectWithChildren( obj );
532 aSelMgr->setSelectedObjects( selected );
533 getGeometryGUI()->updateObjBrowser();
534 app->updateActions(); //SRN: To update a Save button in the toolbar
537 //=====================================================================================
539 // purpose : BRep, Iges, Step, ...
540 //=====================================================================================
541 bool GEOMToolsGUI::Import()
543 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
544 if ( !app ) return false;
546 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
548 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
551 _PTR(Study) aStudy = stud->studyDS();
553 // check if study is locked
554 bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
556 SUIT_MessageBox::warning( app->desktop(),
557 QObject::tr("WRN_WARNING"),
558 QObject::tr("WRN_STUDY_LOCKED") );
562 // check if GEOM engine is available
563 GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
564 if ( CORBA::is_nil( eng ) ) {
565 SUIT_MessageBox::critical( app->desktop(),
566 QObject::tr("WRN_WARNING"),
567 QObject::tr( "GEOM Engine is not started" ) );
571 GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
572 if ( aInsOp->_is_nil() )
575 // obtain a list of available import formats
577 GEOM::string_array_var aFormats, aPatterns;
578 aInsOp->ImportTranslators( aFormats, aPatterns );
580 for ( int i = 0, n = aFormats->length(); i < n; i++ )
581 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
583 // select files to be imported
585 QStringList fileNames = getFileNames( app->desktop(), "", aMap,
586 tr( "GEOM_MEN_IMPORT" ), fileType, true );
589 SUIT_OverrideCursor wc;
591 if ( fileNames.count() == 0 )
592 return false; // nothing selected, return
596 QList< GEOM::GEOM_Object_var > objsForDisplay;
598 QStringList anEntryList;
600 // iterate through all selected files
602 SUIT_MessageBox::StandardButton igesAnswer = SUIT_MessageBox::NoButton;
603 SUIT_MessageBox::StandardButton acisAnswer = SUIT_MessageBox::NoButton;
605 for ( int i = 0; i < fileNames.count(); i++ ) {
606 QString fileName = fileNames[i];
608 if ( fileName.isEmpty() )
611 QString aCurrentType;
612 if ( fileType.isEmpty() ) {
613 // file type is not defined, try to detect
614 QString ext = QFileInfo( fileName ).suffix().toUpper();
615 QRegExp re( "\\*\\.(\\w+)" );
616 for ( FilterMap::const_iterator it = aMap.begin();
617 it != aMap.end() && aCurrentType.isEmpty(); ++it ) {
619 while ( re.indexIn( it.key(), pos ) >= 0 ) {
620 QString f = re.cap(1).trimmed().toUpper();
621 if ( ext == f ) { aCurrentType = it.value(); break; }
622 pos = re.pos() + re.cap(1).length() + 2;
627 aCurrentType = fileType;
630 if ( aCurrentType.isEmpty() ) {
631 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNSUPPORTED_TYPE" ) ) );
635 GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
637 app->putInfo( tr( "GEOM_PRP_LOADING" ).arg( SUIT_Tools::file( fileName, /*withExten=*/true ) ) );
640 CORBA::String_var fileN = fileName.toLatin1().constData();
641 CORBA::String_var fileT = aCurrentType.toLatin1().constData();
644 if ( aCurrentType == "IGES" ) {
645 GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, "IGES_UNIT" );
646 bool needConvert = false;
647 TCollection_AsciiString aUnitName = aInsOp->GetErrorCode();
648 if ( aUnitName.SubString( 1, 4 ) == "UNIT" )
649 needConvert = aUnitName.SubString( 6, aUnitName.Length() ) != "M";
652 if ( igesAnswer == SUIT_MessageBox::NoToAll ) {
653 // converting for all files is already approved
654 fileT = "IGES_SCALE";
656 else if ( igesAnswer != SUIT_MessageBox::YesToAll ) {
657 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
658 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
659 igesAnswer = SUIT_MessageBox::question( app->desktop(),
660 "Question",//tr("WRN_WARNING"),
661 tr("GEOM_SCALE_DIMENSIONS"),
662 btns | SUIT_MessageBox::Cancel,
663 SUIT_MessageBox::No );
664 switch ( igesAnswer ) {
665 case SUIT_MessageBox::Cancel:
666 return false; // cancel (break) import operation
667 case SUIT_MessageBox::Yes:
668 case SUIT_MessageBox::YesToAll:
669 break; // scaling is confirmed
670 case SUIT_MessageBox::No:
671 case SUIT_MessageBox::NoAll:
672 fileT = "IGES_SCALE";
674 break; // scaling is rejected
675 } // switch ( igesAnswer )
676 } // if ( igeAnswer != NoToAll )
677 } // if ( needConvert )
678 } // if ( aCurrentType == "IGES" )
679 else if ( aCurrentType == "ACIS" ) {
680 if ( acisAnswer != SUIT_MessageBox::YesToAll && acisAnswer != SUIT_MessageBox::NoToAll ) {
681 SUIT_MessageBox::StandardButtons btns = SUIT_MessageBox::Yes | SUIT_MessageBox::No;
682 if ( i < fileNames.count()-1 ) btns = btns | SUIT_MessageBox::YesToAll | SUIT_MessageBox::NoToAll;
683 acisAnswer = SUIT_MessageBox::question( app->desktop(),
684 "Question",//tr("WRN_WARNING"),
685 tr("GEOM_PUBLISH_NAMED_SHAPES"),
686 btns | SUIT_MessageBox::Cancel,
687 SUIT_MessageBox::No );
688 if ( acisAnswer == SUIT_MessageBox::Cancel )
689 return false; // cancel (break) import operation
690 } // if ( acisAnswer != YesToAll && acisAnswer != NoToAll )
691 } // else if ( aCurrentType == "ACIS" )
693 GEOM::GEOM_Object_var anObj = aInsOp->ImportFile( fileN, fileT );
695 if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
696 QString aPublishObjName =
697 GEOMBase::GetDefaultName( SUIT_Tools::file( fileName, /*withExten=*/true ) );
699 SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy( aStudy );
700 SALOMEDS::SObject_var aSO =
701 GeometryGUI::GetGeomGen()->PublishInStudy( aDSStudy,
702 SALOMEDS::SObject::_nil(),
704 aPublishObjName.toLatin1().constData() );
705 if ( ( !aSO->_is_nil() ) )
706 anEntryList.append( aSO->GetID() );
708 objsForDisplay.append( anObj );
710 if ( aCurrentType == "ACIS" ) {
711 if ( acisAnswer == SUIT_MessageBox::Yes || acisAnswer == SUIT_MessageBox::YesToAll )
712 GeometryGUI::GetGeomGen()->PublishNamedShapesInStudy( aDSStudy, anObj );
719 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( aInsOp->GetErrorCode() ) );
722 catch( const SALOME::SALOME_Exception& S_ex ) {
724 errors.append( QString( "%1 : %2" ).arg( fileName ).arg( tr( "GEOM_UNKNOWN_IMPORT_ERROR" ) ) );
728 // update object browser
729 getGeometryGUI()->updateObjBrowser( true );
731 // browse published objects
732 app->browseObjects( anEntryList );
734 // display imported model (if only one file is selected)
735 if ( objsForDisplay.count() == 1 )
736 GEOM_Displayer( stud ).Display( objsForDisplay[0].in() );
738 if ( errors.count() > 0 ) {
739 SUIT_MessageBox::critical( app->desktop(),
740 QObject::tr( "GEOM_ERROR" ),
741 QObject::tr( "GEOM_IMPORT_ERRORS" ) + "\n" + errors.join( "\n" ) );
744 app->updateActions(); //SRN: To update a Save button in the toolbar
746 return objsForDisplay.count() > 0;
749 //=====================================================================================
751 // purpose : BRep, Iges, Step
752 //=====================================================================================
753 bool GEOMToolsGUI::Export()
755 SalomeApp_Application* app = getGeometryGUI()->getApp();
756 if (!app) return false;
758 SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
760 MESSAGE ( "FAILED to cast active study to SalomeApp_Study" );
763 _PTR(Study) aStudy = stud->studyDS();
765 GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
766 if ( CORBA::is_nil( eng ) ) {
767 SUIT_MessageBox::critical( app->desktop(),
768 QObject::tr("WRN_WARNING"),
769 QObject::tr( "GEOM Engine is not started" ) );
773 GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
774 if ( aInsOp->_is_nil() )
777 // Obtain a list of available export formats
780 GEOM::string_array_var aFormats, aPatterns;
781 aInsOp->ExportTranslators( aFormats, aPatterns );
782 for ( int i = 0, n = aFormats->length(); i < n; i++ ) {
783 aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
784 filters.push_back( (char*)aPatterns[i] );
787 // Get selected objects
788 LightApp_SelectionMgr* sm = app->selectionMgr();
792 SALOME_ListIO selectedObjects;
793 sm->selectedObjects( selectedObjects );
794 bool appropriateObj = false;
796 SALOME_ListIteratorOfListIO It( selectedObjects );
797 for (; It.More(); It.Next()) {
798 Handle(SALOME_InteractiveObject) IObject = It.Value();
799 GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject( IObject );
801 if ( anObj->_is_nil() )
805 QString file = getFileName(app->desktop(), QString( IObject->getName() ), aMap, filters,
806 tr("GEOM_MEN_EXPORT"), false, fileType, true);
808 // User has pressed "Cancel" --> stop the operation
809 if ( file.isEmpty() || fileType.isEmpty() )
812 GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
814 SUIT_OverrideCursor wc;
816 app->putInfo( tr("GEOM_PRP_EXPORT").arg(SUIT_Tools::file( file, /*withExten=*/true )) );
820 aInsOp->Export( anObj, file.toStdString().c_str(), fileType.toLatin1().constData() );
822 if (aInsOp->IsDone())
827 SUIT_MessageBox::critical(app->desktop(),
828 QObject::tr("GEOM_ERROR"),
829 QObject::tr("GEOM_PRP_ABORT") + "\n" + QObject::tr(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 );