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