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