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