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