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