]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI.cxx
Salome HOME
0019882: EDF 453 GEOM: Impossible to change the iso values in the VTK window
[modules/geom.git] / src / GEOMToolsGUI / GEOMToolsGUI.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : GEOMBase_Tools.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "GEOMToolsGUI.h"
30 #include "GEOMToolsGUI_DeleteDlg.h"
31
32 #include "GeometryGUI.h"
33 #include "GEOM_Actor.h"
34 #include "GEOMBase.h"
35
36 #include "GEOM_Operation.h"
37 #include "GEOM_Displayer.h"
38
39 #include <SUIT_Session.h>
40 #include <SUIT_Application.h>
41 #include <SUIT_OverrideCursor.h>
42 #include <SUIT_MessageBox.h>
43 #include <SUIT_Tools.h>
44 #include <SUIT_FileDlg.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ViewModel.h>
47
48 #include <SalomeApp_Application.h>
49 #include <SalomeApp_Study.h>
50 #include <LightApp_SelectionMgr.h>
51 #include <GEOMImpl_Types.hxx>
52
53 #include <SALOME_ListIteratorOfListIO.hxx>
54 #include <SALOME_Prs.h>
55
56 #include "utilities.h"
57
58 // QT Includes
59 #include <qapplication.h>
60 #include <qmap.h>
61
62 // OCCT Includes
63 #include <TCollection_AsciiString.hxx>
64
65 using namespace std;
66
67 typedef QMap<QString, QString> FilterMap;
68
69 //=======================================================================
70 // function : getFileName
71 // purpose  : Selection of a file name for Import/Export. Returns also
72 //            the selected file type code through <filter> argument.
73 //=======================================================================
74 static QString getFileName( QWidget*           parent,
75                             const QString&     initial,
76                             const FilterMap&   filterMap,
77                             const QStringList  filters,
78                             const QString&     caption,
79                             bool               open,
80                             QString&           format,
81                             bool               showCurrentDirInitially = false)
82 {
83   static QString lastUsedFilter;
84   //QStringList filters;
85   QString aBrepFilter;
86   for ( FilterMap::const_iterator it = filterMap.begin(); it != filterMap.end(); ++it ) {
87     //filters.push_back( it.key() );
88
89     if (it.key().contains("BREP", false)) {
90       aBrepFilter = it.key();
91     }
92   }
93
94   SUIT_FileDlg* fd = new SUIT_FileDlg( parent, open, true, true );
95   if ( !caption.isEmpty() )
96     fd->setCaption( caption );
97
98   if ( !initial.isEmpty() )
99     fd->setSelection( initial );
100   
101   if ( showCurrentDirInitially && SUIT_FileDlg::getLastVisitedPath().isEmpty() )
102     fd->setDir( QDir::currentDirPath() );
103
104   fd->setFilters( filters );
105
106   if ( !lastUsedFilter.isEmpty() && filterMap.contains( lastUsedFilter ) )
107     fd->setSelectedFilter( lastUsedFilter );
108   else {
109     if (!aBrepFilter.isEmpty()) {
110       fd->setSelectedFilter(aBrepFilter);
111     }
112   }
113
114   fd->exec();
115   QString filename = fd->selectedFile();
116   format = filterMap[fd->selectedFilter()];
117   lastUsedFilter = fd->selectedFilter();
118   delete fd;
119   qApp->processEvents();
120   return filename;
121 }
122
123 //=======================================================================
124 // function : getParentComponent
125 // purpose  : Get object's parent component entry
126 //=======================================================================
127 static QString getParentComponent( _PTR( SObject ) obj )
128 {
129   if ( obj ) {
130     _PTR(SComponent) comp = obj->GetFatherComponent();
131     if ( comp )
132       return QString( comp->GetID().c_str() );
133   }
134   return QString();
135 }
136
137 //=====================================================================================
138 // function : inUse
139 // purpose  : check if the object(s) passed as the the second arguments are used
140 //            by the other objects in the study
141 //=====================================================================================
142 static bool inUse( _PTR(Study) study, const QString& component, const QMap<QString,QString>& objects )
143 {
144   _PTR(SObject) comp = study->FindObjectID( component.latin1() );
145   if ( !comp )
146     return false;
147
148   // collect all GEOM objects being deleted
149   QMap<QString, GEOM::GEOM_Object_var> gobjects;
150   QMap<QString, QString>::ConstIterator oit;
151   for ( oit = objects.begin(); oit != objects.end(); ++oit ) {
152     _PTR(SObject) so = study->FindObjectID( oit.key().latin1() );
153     if ( !so )
154       continue;
155     CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject( so );
156     GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
157     if( CORBA::is_nil( geomObj_rem ) ) 
158       continue;
159     gobjects.insert( oit.key(), geomObj_rem );
160   }
161   
162   // browse through all GEOM data tree
163   _PTR(ChildIterator) it ( study->NewChildIterator( comp ) );
164   for ( it->InitEx( true ); it->More(); it->Next() ) {
165     _PTR(SObject) child( it->Value() );
166     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject( child );
167     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
168     if( CORBA::is_nil( geomObj ) ) 
169       continue;
170
171     GEOM::ListOfGO_var list = geomObj->GetDependency();
172     if( list->length() <= 1 ) 
173       continue; // ??? why 1?
174
175     for( int i = 0; i < list->length(); i++ ) {
176       bool depends = false;
177       bool deleted = false;
178       QMap<QString, GEOM::GEOM_Object_var>::Iterator git;
179       for ( git = gobjects.begin(); git != gobjects.end() && ( !depends || !deleted ); ++git ) {
180         depends = depends || list[i]->_is_equivalent( *git );
181         deleted = deleted || git.key() == child->GetID().c_str() ;//geomObj->_is_equivalent( *git );
182       }
183       if ( depends && !deleted )
184         return true;
185     }
186   }
187   return false;
188 }
189
190
191 //=======================================================================
192 // function : GEOMToolsGUI()
193 // purpose  : Constructor
194 //=======================================================================
195 GEOMToolsGUI::GEOMToolsGUI( GeometryGUI* parent )
196 : GEOMGUI( parent )
197 {
198 }
199
200
201 //=======================================================================
202 // function : ~GEOMToolsGUI()
203 // purpose  : Destructor
204 //=======================================================================
205 GEOMToolsGUI::~GEOMToolsGUI()
206 {
207 }
208
209
210 //=======================================================================
211 // function : OnGUIEvent()
212 // purpose  :
213 //=======================================================================
214 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
215 {
216   getGeometryGUI()->EmitSignalDeactivateDialog();
217
218   switch (theCommandID)
219     {
220     case 31: // COPY
221       {
222         OnEditCopy();
223         break;
224       }
225     case 33: // DELETE
226       {
227         OnEditDelete();
228         break;
229       }
230     case 111: // IMPORT BREP
231     case 112: // IMPORT IGES
232     case 113: // IMPORT STEP
233       {
234         Import();
235         break;
236       }
237     case 121: // EXPORT BREP
238     case 122: // EXPORT IGES
239     case 123: // EXPORT STEP
240       {
241         Export();
242         break;
243       }
244     case 2171: // POPUP VIEWER - SELECT ONLY - VERTEX
245       {
246         OnSelectOnly( GEOM_POINT );
247         break;
248       }
249     case 2172: // POPUP VIEWER - SELECT ONLY - EDGE
250       {
251         OnSelectOnly( GEOM_EDGE );
252         break;
253       }
254     case 2173: // POPUP VIEWER - SELECT ONLY - WIRE
255       {
256         OnSelectOnly( GEOM_WIRE );
257         break;
258       }
259     case 2174: // POPUP VIEWER - SELECT ONLY - FACE
260       {
261         OnSelectOnly( GEOM_FACE );
262         break;
263       }
264     case 2175: // POPUP VIEWER - SELECT ONLY - SHELL
265       {
266         OnSelectOnly( GEOM_SHELL );
267         break;
268       }
269     case 2176: // POPUP VIEWER - SELECT ONLY - SOLID
270       {
271         OnSelectOnly( GEOM_SOLID );
272         break;
273       }
274     case 2177: // POPUP VIEWER - SELECT ONLY - COMPOUND
275       {
276         OnSelectOnly( GEOM_COMPOUND );
277         break;
278       }
279     case 2178: // POPUP VIEWER - SELECT ONLY - SELECT ALL
280       {
281         OnSelectOnly( GEOM_ALLOBJECTS );
282         break;
283       }    
284     case 411: // SETTINGS - ADD IN STUDY
285       {
286         // SAN -- TO BE REMOVED !!!
287         break;
288       }
289     case 412: // SETTINGS - SHADING COLOR
290       {
291         OnSettingsColor();
292         break;
293       }
294     case 804: // ADD IN STUDY - POPUP VIEWER
295       {
296         // SAN -- TO BE REMOVED !!!!
297         break;
298       }
299     case 901: // RENAME
300       {
301         OnRename();
302         break;
303       }
304     case 5103: // CHECK GEOMETRY
305       {
306         OnCheckGeometry();
307         break;
308       }
309     case 8032: // COLOR - POPUP VIEWER
310       {
311         OnColor();
312         break;
313       }
314     case 8033: // TRANSPARENCY - POPUP VIEWER
315       {
316         OnTransparency();
317         break;
318       }
319     case 8034: // ISOS - POPUP VIEWER
320       {
321         OnNbIsos();
322         break;
323       }
324     case 8035: // AUTO COLOR - POPUP VIEWER
325       {
326         OnAutoColor();
327         break;
328       }
329     case 8036: // DISABLE AUTO COLOR - POPUP VIEWER
330       {
331         OnDisableAutoColor();
332         break;
333       }
334     case 9024 : // OPEN - OBJBROSER POPUP
335       {
336         OnOpen();
337         break;
338       }
339     default:
340       {
341         SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
342         break;
343       }
344     }
345   return true;
346 }
347
348
349 //===============================================================================
350 // function : OnEditDelete()
351 // purpose  :
352 //===============================================================================
353 void GEOMToolsGUI::OnEditDelete()
354 {
355   SALOME_ListIO selected;
356   SalomeApp_Application* app =
357     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
358   if ( !app )
359     return;
360
361   LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
362   SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
363   if ( !aSelMgr || !appStudy )
364     return;
365
366   // get selection
367   aSelMgr->selectedObjects( selected, "ObjectBrowser", false );
368   if ( selected.IsEmpty() )
369     return;
370
371   _PTR(Study) aStudy = appStudy->studyDS();
372   
373   // check if study is locked
374   if ( _PTR(AttributeStudyProperties)( aStudy->GetProperties() )->IsLocked() ) {
375     SUIT_MessageBox::warn1( app->desktop(),
376                             tr("WRN_WARNING"),
377                             tr("WRN_STUDY_LOCKED"),
378                             tr("BUT_OK") );
379     return; // study is locked
380   }
381   
382   // get GEOM component
383   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
384   QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) );
385
386   // check each selected object: if belongs to GEOM, if not reference...
387   QMap<QString,QString> toBeDeleted;
388   QMap<QString,QString> allDeleted;
389   bool isComponentSelected = false;
390   for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
391     Handle(SALOME_InteractiveObject) anIObject = It.Value();
392     if ( !anIObject->hasEntry() )
393       continue; // invalid object
394     // ...
395     QString entry = anIObject->getEntry();
396     _PTR(SObject) obj = aStudy->FindObjectID( entry.latin1() );
397     // check parent component
398     QString parentComp = getParentComponent( obj );
399     if ( parentComp != geomComp )  {
400       SUIT_MessageBox::warn1( app->desktop(),
401                               QObject::tr("ERR_ERROR"),
402                               QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ),
403                               QObject::tr("BUT_OK") );
404       return; // not GEOM object selected
405     }
406
407     ///////////////////////////////////////////////////////
408     // if GEOM component is selected, so skip other checks
409     if ( isComponentSelected ) continue; 
410     ///////////////////////////////////////////////////////
411         
412     // check if object is reference
413     _PTR(SObject) refobj;
414     if ( obj && obj->ReferencedObject( refobj ) )
415       continue; // skip references
416     // ...
417     QString aName = obj->GetName().c_str();
418     if ( entry == geomComp ) {
419       // GEOM component is selected, skip other checks
420       isComponentSelected = true;
421       continue;
422     }
423     toBeDeleted.insert( entry, aName );
424     allDeleted.insert( entry, aName ); // skip GEOM component
425     // browse through all children recursively
426     _PTR(ChildIterator) it ( aStudy->NewChildIterator( obj ) );
427     for ( it->InitEx( true ); it->More(); it->Next() ) {
428       _PTR(SObject) child( it->Value() );
429       if ( child && child->ReferencedObject( refobj ) )
430         continue; // skip references
431       aName = child->GetName().c_str();
432       if ( !aName.isEmpty() )
433         allDeleted.insert( child->GetID().c_str(), aName );
434     }
435   }
436   
437   // is there is anything to delete?
438   if ( !isComponentSelected && allDeleted.count() <= 0 )
439     return; // nothing to delete
440
441   // show confirmation dialog box
442   GEOMToolsGUI_DeleteDlg dlg( app->desktop(), allDeleted, isComponentSelected );
443   if ( !dlg.exec() )
444     return; // operation is cancelled by user
445   
446   // get currently opened views
447   QPtrList<SALOME_View> views;
448   SALOME_View* view;
449   ViewManagerList vmans = app->viewManagers();
450   SUIT_ViewManager* vman;
451   for ( vman = vmans.first(); vman; vman = vmans.next() ) {
452     SUIT_ViewModel* vmod = vman->getViewModel();
453     view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
454     if ( view )
455       views.append( view );
456   }
457   
458   _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
459   GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
460   
461   if ( isComponentSelected ) {
462     // GEOM component is selected: delete all objects recursively
463     _PTR(SObject) comp = aStudy->FindObjectID( geomComp.latin1() );
464     if ( !comp )
465       return;
466     _PTR(ChildIterator) it ( aStudy->NewChildIterator( comp ) );
467     // remove top-level objects only
468     for ( it->InitEx( false ); it->More(); it->Next() ) {
469       _PTR(SObject) child( it->Value() );
470       // remove object from GEOM engine
471       removeObjectWithChildren( child, aStudy, views, disp );
472       // remove object from study
473       aStudyBuilder->RemoveObjectWithChildren( child );
474     }
475   }
476   else {
477     // GEOM component is not selected: check if selected objects are in use
478     if ( inUse( aStudy, geomComp, allDeleted ) ) {
479       SUIT_MessageBox::warn1( app->desktop(),
480                               QObject::tr("WRN_WARNING"),
481                               QObject::tr("DEP_OBJECT"),
482                               QObject::tr("BUT_OK") );
483       return; // object(s) in use
484     }
485     // ... and then delete all objects
486     QMap<QString, QString>::Iterator it;
487     for ( it = toBeDeleted.begin(); it != toBeDeleted.end(); ++it ) {
488       _PTR(SObject) obj ( aStudy->FindObjectID( it.key().latin1() ) );
489       // remove object from GEOM engine
490       removeObjectWithChildren( obj, aStudy, views, disp );
491       // remove objects from study
492       aStudyBuilder->RemoveObjectWithChildren( obj );
493     }
494   }
495   
496   selected.Clear();
497   aSelMgr->setSelectedObjects( selected );
498   getGeometryGUI()->updateObjBrowser();
499   app->updateActions(); //SRN: To update a Save button in the toolbar
500 }
501
502
503 //==============================================================================
504 // function : OnEditCopy()
505 // purpose  :
506 //==============================================================================
507 void GEOMToolsGUI::OnEditCopy()
508 {
509 /*
510  SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
511   GEOM::string_array_var listIOR = new GEOM::string_array;
512
513   const SALOME_ListIO& List = Sel->StoredIObjects();
514
515   myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
516
517   Sel->ClearIObjects();
518
519   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
520   int aStudyID = aStudy->StudyId();
521
522   for (unsigned int ind = 0; ind < listIOR->length();ind++) {
523     GEOM::GEOM_Object_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
524     try {
525       GEOM::GEOM_IInsertOperations_var IOp =  myGeom->GetIInsertOperations(aStudyID);
526       GEOM::GEOM_Object_var result = IOp->MakeCopy(aShapeInit);
527       myGeomBase->Display(result);
528     }
529     catch  (const SALOME::SALOME_Exception& S_ex) {
530       QtCatchCorbaException(S_ex);
531     }
532   }
533
534   QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
535 */
536 }
537
538
539 //=====================================================================================
540 // function : Import
541 // purpose  : BRep, Iges, Step
542 //=====================================================================================
543 bool GEOMToolsGUI::Import()
544 {
545   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
546   //SUIT_Application* app = getGeometryGUI()->getApp();
547   if (! app) return false;
548
549   SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
550   if ( !stud ) {
551     cout << "FAILED to cast active study to SalomeApp_Study" << endl;
552     return false;
553   }
554   _PTR(Study) aStudy = stud->studyDS();
555
556   bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
557   if ( aLocked ) {
558     SUIT_MessageBox::warn1 ( app->desktop(),
559                             QObject::tr("WRN_WARNING"),
560                             QObject::tr("WRN_STUDY_LOCKED"),
561                             QObject::tr("BUT_OK") );
562     return false;
563   }
564
565   GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
566   if ( CORBA::is_nil( eng ) ) {
567     SUIT_MessageBox::error1( app->desktop(),
568                             QObject::tr("WRN_WARNING"),
569                             QObject::tr( "GEOM Engine is not started" ),
570                             QObject::tr("BUT_OK") );
571       return false;
572     }
573
574   GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
575   if ( aInsOp->_is_nil() )
576     return false;
577
578   GEOM::GEOM_Object_var anObj;
579
580   // Obtain a list of available import formats
581   FilterMap aMap;
582   QStringList filters;
583   GEOM::string_array_var aFormats, aPatterns;
584   aInsOp->ImportTranslators( aFormats, aPatterns );
585
586   for ( int i = 0, n = aFormats->length(); i < n; i++ ) {
587     aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
588     filters.push_back( (char*)aPatterns[i] );
589   }
590
591   QString fileType;
592   
593   QString fileName = getFileName(app->desktop(), "", aMap, filters,
594                                  tr("GEOM_MEN_IMPORT"), true, fileType, true);
595
596   if (fileType.isEmpty() )
597     {
598       // Trying to detect file type
599       QFileInfo aFileInfo( fileName );
600       QString aPossibleType = (aFileInfo.extension(false)).upper() ;
601
602       if ( (aMap.values()).contains(aPossibleType) )
603         fileType = aPossibleType;
604     }
605
606   if (fileName.isEmpty() || fileType.isEmpty())
607     return false;
608
609   GEOM_Operation* anOp = new GEOM_Operation (app, aInsOp.in());
610   try {
611     SUIT_OverrideCursor wc;
612
613     app->putInfo(tr("GEOM_PRP_LOADING").arg(SUIT_Tools::file(fileName, /*withExten=*/true)));
614
615     anOp->start();
616
617     CORBA::String_var fileN = fileName.latin1();
618     CORBA::String_var fileT = fileType.latin1();
619     anObj = aInsOp->Import(fileN, fileT);
620
621     if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
622       QString aPublishObjName =
623         GEOMBase::GetDefaultName(SUIT_Tools::file(fileName, /*withExten=*/true));
624
625       SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy(aStudy);
626       GeometryGUI::GetGeomGen()->PublishInStudy(aDSStudy,
627                                                 SALOMEDS::SObject::_nil(),
628                                                 anObj,
629                                                 aPublishObjName);
630
631       GEOM_Displayer( stud ).Display( anObj.in() );
632
633       // update data model and object browser
634       getGeometryGUI()->updateObjBrowser( true );
635
636       anOp->commit();
637     }
638     else {
639       anOp->abort();
640       wc.suspend();
641       SUIT_MessageBox::error1( app->desktop(),
642                               QObject::tr( "GEOM_ERROR" ),
643                               QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
644                               QObject::tr("BUT_OK") );
645     }
646   }
647   catch( const SALOME::SALOME_Exception& S_ex ) {
648     //QtCatchCorbaException(S_ex);
649     anOp->abort();
650     return false;
651   }
652
653   app->updateActions(); //SRN: To update a Save button in the toolbar
654
655   return true;
656 }
657
658
659 //=====================================================================================
660 // function : Export
661 // purpose  : BRep, Iges, Step
662 //=====================================================================================
663 bool GEOMToolsGUI::Export()
664 {
665   SalomeApp_Application* app = getGeometryGUI()->getApp();
666   if (!app) return false;
667
668   SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
669   if ( !stud ) {
670     cout << "FAILED to cast active study to SalomeApp_Study" << endl;
671     return false;
672   }
673   _PTR(Study) aStudy = stud->studyDS();
674
675   GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
676   if ( CORBA::is_nil( eng ) ) {
677     SUIT_MessageBox::error1( app->desktop(),
678                              QObject::tr("WRN_WARNING"),
679                              QObject::tr( "GEOM Engine is not started" ),
680                              QObject::tr("BUT_OK") );
681     return false;
682   }
683
684   GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
685   if ( aInsOp->_is_nil() )
686     return false;
687
688   // Obtain a list of available export formats
689   FilterMap aMap;
690   QStringList filters;
691   GEOM::string_array_var aFormats, aPatterns;
692   aInsOp->ExportTranslators( aFormats, aPatterns );
693   for ( int i = 0, n = aFormats->length(); i < n; i++ ) {
694     aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
695     filters.push_back( (char*)aPatterns[i] );
696   }
697
698   // Get selected objects
699   LightApp_SelectionMgr* sm = app->selectionMgr();
700   if ( !sm )
701     return false;
702
703   SALOME_ListIO selectedObjects;
704   sm->selectedObjects( selectedObjects );
705
706   SALOME_ListIteratorOfListIO It( selectedObjects );
707   for(;It.More();It.Next()) {
708     Handle(SALOME_InteractiveObject) IObject = It.Value();
709     Standard_Boolean found;
710     GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(IObject, found);
711
712     if ( !found || anObj->_is_nil() )
713       continue;
714
715     QString fileType;
716     QString file = getFileName(app->desktop(), QString( IObject->getName() ), aMap, filters,
717                                tr("GEOM_MEN_EXPORT"), false, fileType, true);
718
719     // User has pressed "Cancel" --> stop the operation
720     if ( file.isEmpty() || fileType.isEmpty() )
721       return false;
722
723     GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
724     try {
725       SUIT_OverrideCursor wc;
726
727       app->putInfo( tr("GEOM_PRP_EXPORT").arg(SUIT_Tools::file( file, /*withExten=*/true )) );
728
729       anOp->start();
730
731
732       aInsOp->Export( anObj, file, fileType.latin1() );
733
734       if ( aInsOp->IsDone() )
735         anOp->commit();
736       else
737         {
738           anOp->abort();
739           wc.suspend();
740           SUIT_MessageBox::error1( app->desktop(),
741                                    QObject::tr( "GEOM_ERROR" ),
742                                    QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
743                                    QObject::tr("BUT_OK") );
744           return false;
745         }
746     }
747     catch (const SALOME::SALOME_Exception& S_ex) {
748       //QtCatchCorbaException(S_ex);
749       anOp->abort();
750       return false;
751     }
752   }
753
754   return true;
755 }
756
757 //=====================================================================================
758 // function : RemoveObjectWithChildren
759 // purpose  : to be used by OnEditDelete() method
760 //=====================================================================================
761 void GEOMToolsGUI::removeObjectWithChildren(_PTR(SObject) obj,
762                                             _PTR(Study) aStudy,
763                                             QPtrList<SALOME_View> views,
764                                             GEOM_Displayer* disp)
765 {
766   // iterate through all children of obj
767   for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
768     _PTR(SObject) child (it->Value());
769     removeObjectWithChildren(child, aStudy, views, disp);
770   }
771
772   // erase object and remove it from engine
773   _PTR(GenericAttribute) anAttr;
774   if (obj->FindAttribute(anAttr, "AttributeIOR")) {
775     _PTR(AttributeIOR) anIOR (anAttr);
776
777     // Delete shape in Client
778     const TCollection_AsciiString ASCIor ((char*)anIOR->Value().c_str());
779     getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
780
781     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj);
782     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
783     if (!CORBA::is_nil(geomObj)) {
784       // Erase graphical object
785       SALOME_View* view = views.first();
786       for (; view; view = views.next()) {
787         disp->Erase(geomObj, true, view);
788       }
789
790       // Remove object from Engine
791       GeometryGUI::GetGeomGen()->RemoveObject( geomObj );
792     }
793   }
794 }
795
796 //=================================================================================
797 // function : deactivate()
798 // purpose  : Called when GEOM component is deactivated
799 //=================================================================================
800 void GEOMToolsGUI::deactivate()
801 {
802   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
803   if ( app ) {
804     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
805     GEOM_Displayer aDisp (appStudy);
806     aDisp.GlobalSelection();
807     getGeometryGUI()->setLocalSelectionMode(GEOM_ALLOBJECTS);
808   }
809 }
810
811 //=====================================================================================
812 // EXPORTED METHODS
813 //=====================================================================================
814 extern "C"
815 {
816 GEOMTOOLSGUI_EXPORT
817   GEOMGUI* GetLibGUI( GeometryGUI* parent )
818   {
819     return new GEOMToolsGUI( parent );
820   }
821 }