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