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