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