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