]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI.cxx
Salome HOME
*** empty log message ***
[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 804: // ADD IN STUDY - POPUP VIEWER
204       {
205         // SAN -- TO BE REMOVED !!!!
206         break;
207       }
208     case 901: // RENAME
209       {
210         OnRename();
211         break;
212       }
213     case 5103: // CHECK GEOMETRY
214       {
215         OnCheckGeometry();
216         break;
217       }
218     case 8032: // COLOR - POPUP VIEWER
219       {
220         OnColor();
221         break;
222       }
223     case 8033: // TRANSPARENCY - POPUP VIEWER
224       {
225         OnTransparency();
226         break;
227       }
228     case 8034: // ISOS - POPUP VIEWER
229       {
230         OnNbIsos();
231         break;
232       }
233     case 9024 : // OPEN - OBJBROSER POPUP
234       {
235         OnOpen();
236         break;
237       }
238     default:
239       {
240         SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
241         break;
242       }
243     }
244   return true;
245 }
246
247
248
249 //===============================================================================
250 // function : OnEditDelete()
251 // purpose  :
252 //===============================================================================
253 void GEOMToolsGUI::OnEditDelete()
254 {
255   SALOME_ListIO selected;
256   SalomeApp_Application* app =
257     dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
258   if ( app ) {
259     LightApp_SelectionMgr* aSelMgr = app->selectionMgr();
260     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
261     if ( aSelMgr && appStudy ) {
262       aSelMgr->selectedObjects( selected, QString::null, false );
263       if ( !selected.IsEmpty() ) {
264         _PTR(Study) aStudy = appStudy->studyDS();
265
266         bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
267         if ( aLocked ) {
268           SUIT_MessageBox::warning ( app->desktop(),
269                                      QObject::tr("WRN_WARNING"),
270                                      QObject::tr("WRN_STUDY_LOCKED"),
271                                      QObject::tr("BUT_OK") );
272           return;
273         }
274
275         // VSR 17/11/04: check if all objects selected belong to GEOM component --> start
276         // modifications of ASV 01.06.05
277         QString parentComp = getParentComponent( aStudy, selected );
278   CORBA::String_var geomIOR = app->orb()->object_to_string( GeometryGUI::GetGeomGen() );
279         QString geomComp = getParentComponent( aStudy->FindObjectIOR( geomIOR.in() ) );
280
281         if ( parentComp != geomComp )  {
282           SUIT_MessageBox::warning ( app->desktop(),
283                                      QObject::tr("ERR_ERROR"),
284                                      QObject::tr("NON_GEOM_OBJECTS_SELECTED").arg( getGeometryGUI()->moduleName() ),
285                                      QObject::tr("BUT_OK") );
286           return;
287         }
288         // VSR 17/11/04: check if all objects selected belong to GEOM component <-- finish
289
290         if ( SUIT_MessageBox::warning( app->desktop(),
291                                        QObject::tr( "GEOM_WRN_WARNING" ),
292                                        QObject::tr( "GEOM_REALLY_DELETE" ),
293                                        QObject::tr( "GEOM_BUT_YES" ),
294                                        QObject::tr( "GEOM_BUT_NO" ), 1 ) != 0 )
295           return;
296
297         //      QAD_Operation* op = new SALOMEGUI_ImportOperation(.....);
298         //      op->start();
299
300         // prepare list of SALOME_Views
301         QList<SALOME_View*> views;
302         SALOME_View* view;
303         // fill the list
304         ViewManagerList vmans = app->viewManagers();
305         SUIT_ViewManager* vman;
306         QListIterator<SUIT_ViewManager*> it( vmans );
307         while ( it.hasNext() && (vman = it.next()) ) {
308           SUIT_ViewModel* vmod = vman->getViewModel();
309           view = dynamic_cast<SALOME_View*> ( vmod ); // must work for OCC and VTK views
310           if ( view )
311             views.append( view );
312         }
313
314         _PTR(StudyBuilder) aStudyBuilder (aStudy->NewBuilder());
315         _PTR(GenericAttribute) anAttr;
316         GEOM_Displayer* disp = new GEOM_Displayer( appStudy );
317
318         _PTR(SComponent) aGeom ( aStudy->FindComponent("GEOM") );
319           if ( !aGeom )
320             return;     
321
322         // MAIN LOOP OF SELECTED OBJECTS
323         for ( SALOME_ListIteratorOfListIO It( selected ); It.More(); It.Next() ) {
324
325           Handle(SALOME_InteractiveObject) io = It.Value();
326           if ( !io->hasEntry() )
327             continue;
328
329           _PTR(SObject) obj ( aStudy->FindObjectID( io->getEntry() ) );
330
331           // disable removal of "Geometry" component object
332           if ( !strcmp( obj->GetIOR().c_str(), geomIOR ) )
333             continue;
334
335           //If the object has been used to create another one,then it can't be deleted 
336           _PTR(ChildIterator) it (aStudy->NewChildIterator(aGeom));
337           for ( it->InitEx( true ); it->More(); it->Next() ) {
338              _PTR(SObject) chobj (it->Value());
339              if(CheckSubObjectInUse(chobj, obj, aStudy)) return;
340              //check subobjects
341              for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
342                _PTR(SObject) child (it->Value());
343                if(CheckSubObjectInUse( chobj, child, aStudy)) return;
344              }
345            }
346
347           RemoveObjectWithChildren(obj, aStudy, views, disp);
348
349           // Remove objects from Study
350           aStudyBuilder->RemoveObject( obj );
351
352           //deleted = true;
353         } // MAIN LOOP of selected
354
355         selected.Clear();
356         aSelMgr->setSelectedObjects( selected );
357         getGeometryGUI()->updateObjBrowser();
358       } // if ( selected not empty )
359     } // if ( selMgr && appStudy )
360
361     app->updateActions(); //SRN: To update a Save button in the toolbar
362
363   } // if ( app )
364
365
366   //  if ( deleted )
367   //    op->finish();
368   //  else
369   //    op->abort();
370 }
371
372
373 //==============================================================================
374 // function : OnEditCopy()
375 // purpose  :
376 //==============================================================================
377 void GEOMToolsGUI::OnEditCopy()
378 {
379 /*
380  SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
381   GEOM::string_array_var listIOR = new GEOM::string_array;
382
383   const SALOME_ListIO& List = Sel->StoredIObjects();
384
385   myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
386
387   Sel->ClearIObjects();
388
389   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
390   int aStudyID = aStudy->StudyId();
391
392   for (unsigned int ind = 0; ind < listIOR->length();ind++) {
393     GEOM::GEOM_Object_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
394     try {
395       GEOM::GEOM_IInsertOperations_var IOp =  myGeom->GetIInsertOperations(aStudyID);
396       GEOM::GEOM_Object_var result = IOp->MakeCopy(aShapeInit);
397       myGeomBase->Display(result);
398     }
399     catch  (const SALOME::SALOME_Exception& S_ex) {
400       QtCatchCorbaException(S_ex);
401     }
402   }
403
404   QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
405 */
406 }
407
408
409 //=====================================================================================
410 // function : Import
411 // purpose  : BRep, Iges, Step
412 //=====================================================================================
413 bool GEOMToolsGUI::Import()
414 {
415   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( getGeometryGUI()->getApp() );
416   //SUIT_Application* app = getGeometryGUI()->getApp();
417   if (! app) return false;
418
419   SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
420   if ( !stud ) {
421     cout << "FAILED to cast active study to SalomeApp_Study" << endl;
422     return false;
423   }
424   _PTR(Study) aStudy = stud->studyDS();
425
426   bool aLocked = (_PTR(AttributeStudyProperties)(aStudy->GetProperties()))->IsLocked();
427   if ( aLocked ) {
428     SUIT_MessageBox::warning ( app->desktop(),
429                                QObject::tr("WRN_WARNING"),
430                                QObject::tr("WRN_STUDY_LOCKED"),
431                                QObject::tr("BUT_OK") );
432     return false;
433   }
434
435   GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
436   if ( CORBA::is_nil( eng ) ) {
437     SUIT_MessageBox::critical( app->desktop(),
438                                QObject::tr("WRN_WARNING"),
439                                QObject::tr( "GEOM Engine is not started" ),
440                                QObject::tr("BUT_OK") );
441       return false;
442     }
443
444   GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
445   if ( aInsOp->_is_nil() )
446     return false;
447
448   GEOM::GEOM_Object_var anObj;
449
450   // Obtain a list of available import formats
451   FilterMap aMap;
452   GEOM::string_array_var aFormats, aPatterns;
453   aInsOp->ImportTranslators( aFormats, aPatterns );
454
455   for ( int i = 0, n = aFormats->length(); i < n; i++ )
456     aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
457
458   QString fileType;
459
460   QString fileName = getFileName(app->desktop(), "", aMap,
461                                  tr("GEOM_MEN_IMPORT"), true, fileType);
462
463   if (fileType.isEmpty() )
464     {
465       // Trying to detect file type
466       QFileInfo aFileInfo( fileName );
467       QString aPossibleType = (aFileInfo.suffix()).toUpper() ;
468
469       if ( (aMap.values()).contains(aPossibleType) )
470         fileType = aPossibleType;
471     }
472
473   if (fileName.isEmpty() || fileType.isEmpty())
474     return false;
475
476   GEOM_Operation* anOp = new GEOM_Operation (app, aInsOp.in());
477   try {
478     SUIT_OverrideCursor wc;
479
480     app->putInfo(tr("GEOM_PRP_LOADING").arg(SUIT_Tools::file(fileName, /*withExten=*/true)));
481
482     anOp->start();
483
484     CORBA::String_var fileN = fileName.toLatin1().data();
485     CORBA::String_var fileT = fileType.toLatin1().data();
486     anObj = aInsOp->Import(fileN, fileT);
487
488     if ( !anObj->_is_nil() && aInsOp->IsDone() ) {
489       QString aPublishObjName =
490         GEOMBase::GetDefaultName(SUIT_Tools::file(fileName, /*withExten=*/true));
491
492       SALOMEDS::Study_var aDSStudy = GeometryGUI::ClientStudyToStudy(aStudy);
493       GeometryGUI::GetGeomGen()->PublishInStudy(aDSStudy,
494                                                 SALOMEDS::SObject::_nil(),
495                                                 anObj,
496                                                 aPublishObjName.toStdString().c_str());
497
498       GEOM_Displayer( stud ).Display( anObj.in() );
499
500       // update data model and object browser
501       getGeometryGUI()->updateObjBrowser( true );
502
503       anOp->commit();
504     }
505     else {
506       anOp->abort();
507       wc.suspend();
508       SUIT_MessageBox::critical( app->desktop(),
509                                  QObject::tr( "GEOM_ERROR" ),
510                                  QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
511                                  QObject::tr("BUT_OK") );
512     }
513   }
514   catch( const SALOME::SALOME_Exception& S_ex ) {
515     //QtCatchCorbaException(S_ex);
516     anOp->abort();
517     return false;
518   }
519
520   app->updateActions(); //SRN: To update a Save button in the toolbar
521
522   return true;
523 }
524
525
526 //=====================================================================================
527 // function : Export
528 // purpose  : BRep, Iges, Step
529 //=====================================================================================
530 bool GEOMToolsGUI::Export()
531 {
532   SalomeApp_Application* app = getGeometryGUI()->getApp();
533   if (!app) return false;
534
535   SalomeApp_Study* stud = dynamic_cast<SalomeApp_Study*> ( app->activeStudy() );
536   if ( !stud ) {
537     cout << "FAILED to cast active study to SalomeApp_Study" << endl;
538     return false;
539   }
540   _PTR(Study) aStudy = stud->studyDS();
541
542   GEOM::GEOM_Gen_var eng = GeometryGUI::GetGeomGen();
543   if ( CORBA::is_nil( eng ) ) {
544     SUIT_MessageBox::critical( app->desktop(),
545                                QObject::tr("WRN_WARNING"),
546                                QObject::tr( "GEOM Engine is not started" ),
547                                QObject::tr("BUT_OK") );
548     return false;
549   }
550
551   GEOM::GEOM_IInsertOperations_var aInsOp = eng->GetIInsertOperations( aStudy->StudyId() );
552   if ( aInsOp->_is_nil() )
553     return false;
554
555   // Obtain a list of available export formats
556   FilterMap aMap;
557   GEOM::string_array_var aFormats, aPatterns;
558   aInsOp->ExportTranslators( aFormats, aPatterns );
559   for ( int i = 0, n = aFormats->length(); i < n; i++ )
560     aMap.insert( (char*)aPatterns[i], (char*)aFormats[i] );
561
562   // Get selected objects
563   LightApp_SelectionMgr* sm = app->selectionMgr();
564   if ( !sm )
565     return false;
566
567   SALOME_ListIO selectedObjects;
568   sm->selectedObjects( selectedObjects );
569
570   SALOME_ListIteratorOfListIO It( selectedObjects );
571   for(;It.More();It.Next()) {
572     Handle(SALOME_InteractiveObject) IObject = It.Value();
573     Standard_Boolean found;
574     GEOM::GEOM_Object_var anObj = GEOMBase::ConvertIOinGEOMObject(IObject, found);
575
576     if ( !found || anObj->_is_nil() )
577       continue;
578
579     QString fileType;
580     QString file = getFileName(app->desktop(), QString( IObject->getName() ), aMap,
581                                tr("GEOM_MEN_EXPORT"), false, fileType);
582
583     // User has pressed "Cancel" --> stop the operation
584     if ( file.isEmpty() || fileType.isEmpty() )
585       return false;
586
587     GEOM_Operation* anOp = new GEOM_Operation( app, aInsOp.in() );
588     try {
589       SUIT_OverrideCursor wc;
590
591       app->putInfo( tr("GEOM_PRP_EXPORT").arg(SUIT_Tools::file( file, /*withExten=*/true )) );
592
593       anOp->start();
594
595
596       aInsOp->Export( anObj, file.toStdString().c_str(), fileType.toLatin1().constData() );
597
598       if ( aInsOp->IsDone() )
599         anOp->commit();
600       else
601         {
602           anOp->abort();
603           wc.suspend();
604           SUIT_MessageBox::critical( app->desktop(),
605                                      QObject::tr( "GEOM_ERROR" ),
606                                      QObject::tr("GEOM_PRP_ABORT") + "\n" + QString( aInsOp->GetErrorCode() ),
607                                      QObject::tr("BUT_OK") );
608           return false;
609         }
610     }
611     catch (const SALOME::SALOME_Exception& S_ex) {
612       //QtCatchCorbaException(S_ex);
613       anOp->abort();
614       return false;
615     }
616   }
617
618   return true;
619 }
620
621
622 QString GEOMToolsGUI::getParentComponent( _PTR( Study ) study, const SALOME_ListIO& iobjs )
623 {
624   QString parentComp;
625
626   for ( SALOME_ListIteratorOfListIO it( iobjs ); it.More(); it.Next() ) {
627
628     Handle(SALOME_InteractiveObject) io = it.Value();
629     if ( !io->hasEntry() )
630       continue;
631
632     QString compName = getParentComponent( study->FindObjectID( io->getEntry() ) );
633
634     if ( parentComp.isNull() )
635       parentComp = compName;
636     else if ( parentComp.compare( compName) != 0 ) { // objects belonging to different components are selected
637       parentComp = QString::null;
638       break;
639     }
640   }
641
642   return parentComp;
643 }
644
645 QString GEOMToolsGUI::getParentComponent( _PTR( SObject ) obj )
646 {
647   if ( obj ) {
648     _PTR(SComponent) comp = obj->GetFatherComponent();
649     if ( comp ) {
650       _PTR(GenericAttribute) anAttr;
651       if ( comp->FindAttribute( anAttr, "AttributeName") ) {
652         _PTR(AttributeName) aName( anAttr );
653         return QString( aName->Value().c_str() );
654       }
655     }
656   }
657   return QString();
658 }
659
660 //=====================================================================================
661 // function : RemoveObjectWithChildren
662 // purpose  : to be used by OnEditDelete() method
663 //=====================================================================================
664 void GEOMToolsGUI::RemoveObjectWithChildren(_PTR(SObject) obj,
665                                             _PTR(Study) aStudy,
666                                             QList<SALOME_View*> views,
667                                             GEOM_Displayer* disp)
668 {
669   // iterate through all children of obj
670   for (_PTR(ChildIterator) it (aStudy->NewChildIterator(obj)); it->More(); it->Next()) {
671     _PTR(SObject) child (it->Value());
672     RemoveObjectWithChildren(child, aStudy, views, disp);
673   }
674
675   // erase object and remove it from engine
676   _PTR(GenericAttribute) anAttr;
677   if (obj->FindAttribute(anAttr, "AttributeIOR")) {
678     _PTR(AttributeIOR) anIOR (anAttr);
679
680     // Delete shape in Client
681     const TCollection_AsciiString ASCIor ((char*)anIOR->Value().c_str());
682     getGeometryGUI()->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
683
684     CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(obj);
685     GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
686     if (!CORBA::is_nil(geomObj)) {
687       // Erase graphical object
688       QListIterator<SALOME_View*> it( views );
689       while ( it.hasNext() )
690         if ( SALOME_View* view = it.next() )
691           disp->Erase(geomObj, true, view);
692       
693       // Remove object from Engine
694       GeometryGUI::GetGeomGen()->RemoveObject( geomObj );
695     }
696   }
697 }
698
699 //=====================================================================================
700 // function : CheckSubObjectInUse
701 // purpose  : to be used by OnEditDelete() method
702 //=====================================================================================
703 bool GEOMToolsGUI::CheckSubObjectInUse(_PTR(SObject) checkobj,
704                                        _PTR(SObject) remobj,
705                                        _PTR(Study) aStudy)
706 {
707   CORBA::Object_var corbaObj = GeometryGUI::ClientSObjectToObject(checkobj);
708   GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( corbaObj );
709   if( CORBA::is_nil(geomObj) ) 
710     return false;
711
712   GEOM::ListOfGO_var list = geomObj->GetDependency();
713   if( list->length() > 1 )
714     for(int i = 0; i < list->length(); i++ ){
715       CORBA::Object_var corbaObj_rem = GeometryGUI::ClientSObjectToObject(remobj);
716       GEOM::GEOM_Object_var geomObj_rem = GEOM::GEOM_Object::_narrow( corbaObj_rem );
717       if( list[i]->_is_equivalent( geomObj_rem ) ){
718         SalomeApp_Application* app =
719           dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
720
721         SUIT_MessageBox::warning ( app->desktop(),
722                                    QObject::tr("WRN_WARNING"),
723                                    QObject::tr("DEP_OBJECT"),
724                                    QObject::tr("BUT_OK") );
725         return true;
726       }
727     }
728
729   return false;
730 }
731
732 //=================================================================================
733 // function : deactivate()
734 // purpose  : Called when GEOM component is deactivated
735 //=================================================================================
736 void GEOMToolsGUI::deactivate()
737 {
738   SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
739   if ( app ) {
740     SalomeApp_Study* appStudy = dynamic_cast<SalomeApp_Study*>( app->activeStudy() );
741     GEOM_Displayer aDisp (appStudy);
742     aDisp.GlobalSelection();
743     getGeometryGUI()->setLocalSelectionMode(GEOM_ALLOBJECTS);
744   }
745 }
746
747 //=====================================================================================
748 // EXPORTED METHODS
749 //=====================================================================================
750 extern "C"
751 {
752 #ifdef WIN32
753   __declspec( dllexport )
754 #endif
755   GEOMGUI* GetLibGUI( GeometryGUI* parent )
756   {
757     return new GEOMToolsGUI( parent );
758   }
759 }