]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI.cxx
Salome HOME
DCQ : New Architecture
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : GEOMBase_Tools.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header: 
28
29 using namespace std;
30 #include "GEOMToolsGUI.h"
31
32 #include "QAD_Config.h"
33 #include "QAD_FileDlg.h"
34 #include "QAD_Tools.h"
35 #include "QAD_MessageBox.h"
36 #include "QAD_RightFrame.h"
37
38 #include "OCCViewer_Viewer3d.h"
39 #include "VTKViewer_ViewFrame.h"
40
41 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "SALOMEGUI_NameDlg.h"
43 #include "SALOMEGUI_ImportOperation.h"
44 #include "SALOMEGUI_QtCatchCorbaException.hxx"
45
46 #include <AIS_Drawer.hxx>
47 #include <AIS_ListIteratorOfListOfInteractive.hxx>
48 #include <Prs3d_IsoAspect.hxx>
49
50 #include <vtkBMPReader.h>
51 #include <vtkTexture.h>
52 #include <vtkTextureMapToPlane.h>
53 #include <vtkTransformTextureCoords.h>
54 #include <vtkDataSetMapper.h>
55
56 #include <qfileinfo.h>
57 #include <qcolordialog.h>
58 #include <qspinbox.h>
59
60 #include "GEOMToolsGUI_NbIsosDlg.h"        // Method ISOS adjustement
61 #include "GEOMToolsGUI_TransparencyDlg.h"  // Method TRANSPARENCY adjustement
62
63 //=======================================================================
64 // function : GEOMToolsGUI()
65 // purpose  : Constructor
66 //=======================================================================
67 GEOMToolsGUI::GEOMToolsGUI() :
68   QObject()
69 {
70   myGeomBase = new GEOMBase();
71   myGeomGUI = GEOMContext::GetGeomGUI();
72   myGeom = myGeomGUI->myComponentGeom;
73 }
74
75
76 //=======================================================================
77 // function : ~GEOMToolsGUI()
78 // purpose  : Destructor
79 //=======================================================================
80 GEOMToolsGUI::~GEOMToolsGUI()
81 {
82 }
83
84
85 //=======================================================================
86 // function : OnGUIEvent()
87 // purpose  : 
88 //=======================================================================
89 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
90 {
91   GEOMToolsGUI* myGEOMToolsGUI = new GEOMToolsGUI();
92   myGEOMToolsGUI->myGeomGUI->EmitSignalDeactivateDialog();
93   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
94
95   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
96   switch (theCommandID)
97     {
98     case 31: // COPY
99       {
100         myGEOMToolsGUI->OnEditCopy();
101         break;
102       }
103     case 33: // DELETE
104       {
105         myGEOMToolsGUI->OnEditDelete();
106         break;
107       }
108     case 111: // IMPORT BREP
109       {
110         myGEOMToolsGUI->Import(theCommandID);
111         break;
112       }
113     case 112: // IMPORT IGES
114       {
115         myGEOMToolsGUI->Import(theCommandID);
116         break;
117       }
118     case 113: // IMPORT STEP
119       {
120         myGEOMToolsGUI->Import(theCommandID);
121         break;
122       }
123     case 121: // EXPORT BREP
124       {
125         myGEOMToolsGUI->Export(theCommandID);
126         break;
127       }
128     case 122: // EXPORT IGES
129       {
130         myGEOMToolsGUI->Export(theCommandID);
131         break;
132       }
133     case 123: // EXPORT STEP
134       {
135         myGEOMToolsGUI->Export(theCommandID);
136         break;
137       }
138     case 411: // SETTINGS - ADD IN STUDY
139       {
140         QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
141         QMenuData* pp;
142         QMenuItem* item = parent->menuBar()->findItem(411, &pp);
143         bool check = !pp->isItemChecked(411);
144         pp->setItemChecked(411,check);
145         //myGEOMToolsGUI->myGeomGUI->GetSettings_AddInStudy() = check;
146         QAD_CONFIG->addSetting("Geometry:SettingsAddInStudy", check);
147         break;
148       }
149     case 412: // SETTINGS - SHADING COLOR
150       {
151         if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
152           break;
153
154         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
155         Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
156
157         QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
158         QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
159         QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
160         QColor color;
161         if(!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty()) {          
162           color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
163         } 
164         else {
165           Quantity_Color Default = Quantity_Color();
166           color = QColor ((int)Default.Red()  * 255.0, (int)Default.Green()* 255.0, (int)Default.Blue() * 255.0);
167         }
168         
169         QColor c = QColorDialog::getColor(color, QAD_Application::getDesktop());
170         if(c.isValid()) {
171           //myGEOMToolsGUI->myGeomGUI->GetShadingColor() = Quantity_Color(c.red() / 255.0, c.green() / 255.0, c.blue() / 255.0, Quantity_TOC_RGB);
172           
173           AIS_ListOfInteractive List;
174           ic->DisplayedObjects(List);
175           AIS_ListOfInteractive List1;
176           ic->ObjectsInCollector(List1);
177           List.Append(List1);
178           
179           AIS_ListIteratorOfListOfInteractive ite(List);
180           while(ite.More()) {
181             if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
182               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
183               aSh->SetShadingColor(Quantity_Color(c.red() / 255.0, c.green() / 255.0, c.blue() / 255.0, Quantity_TOC_RGB));
184               ic->Redisplay(aSh, Standard_True, Standard_True);
185             }
186             ite.Next();
187           }
188           
189           ic->UpdateCurrentViewer();
190                 
191           QAD_CONFIG->addSetting("Geometry:SettingsShadingColorRed", c.red());
192           QAD_CONFIG->addSetting("Geometry:SettingsShadingColorGreen", c.green());
193           QAD_CONFIG->addSetting("Geometry:SettingsShadingColorBlue", c.blue());        
194         }
195         break;
196       }
197     case 413: // SETTINGS - ISOS
198       {
199         if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
200           break;
201
202         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
203         Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
204
205         QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
206         QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
207         if(!IsoU.isEmpty())
208           ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
209         else
210           IsoU = "1";
211         if (!IsoV.isEmpty())
212           ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
213         else
214           IsoV = "1";
215         
216         GEOMBase_NbIsosDlg* NbIsosDlg = new GEOMBase_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE);       
217         int UIso = IsoU.toInt();
218         int VIso = IsoV.toInt();
219         
220         NbIsosDlg->SpinBoxU->setValue(UIso);
221         NbIsosDlg->SpinBoxV->setValue(VIso);
222
223         if(NbIsosDlg->exec()) {
224           UIso = NbIsosDlg->SpinBoxU->text().toInt();
225           VIso = NbIsosDlg->SpinBoxV->text().toInt();
226           
227           ic->DefaultDrawer()->UIsoAspect()->SetNumber(UIso);
228           ic->DefaultDrawer()->VIsoAspect()->SetNumber(VIso);
229           QAD_CONFIG->addSetting("Geometry:SettingsIsoU", NbIsosDlg->SpinBoxU->text()); /* text format */
230           QAD_CONFIG->addSetting("Geometry:SettingsIsoV", NbIsosDlg->SpinBoxV->text()); /* text format */
231         }
232
233         AIS_ListOfInteractive List;
234         ic->DisplayedObjects(List);
235         AIS_ListOfInteractive List1;
236         ic->ObjectsInCollector(List1);
237         List.Append(List1);
238         
239         AIS_ListIteratorOfListOfInteractive ite(List);
240         ic->InitCurrent();
241         if(ic->NbCurrents())
242           while(ite.More()) {
243             if(ite.Value()->IsInstance(STANDARD_TYPE(GEOM_AISShape))) {
244               Handle(GEOM_AISShape) aSh = Handle(GEOM_AISShape)::DownCast(ite.Value());
245               Handle (AIS_Drawer) CurDrawer;
246               CurDrawer = aSh->Attributes();
247               CurDrawer->UIsoAspect()->SetNumber(UIso);
248               CurDrawer->VIsoAspect()->SetNumber(VIso);
249               ic->SetLocalAttributes(aSh, CurDrawer);
250               ic->Redisplay(aSh);       
251             }
252             ite.Next();
253           }
254         ic->UpdateCurrentViewer();
255         break;
256       }
257     case 414: // SETTINGS : STEP VALUE FOR SPIN BOXES
258       {
259         QString step = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
260         if(step.isEmpty())
261           step = "100.0";
262
263         Standard_Boolean res = false;
264         double dd = myGEOMToolsGUI->myGeomBase->Parameter(res, QString("%1").arg(step), tr("GEOM_MEN_STEP_LABEL"), tr("GEOM_STEP_TITLE"), 0.001, 10000.0, 3);
265         if(res) {
266           QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", QString("%1").arg(dd));
267
268           /* Emit signal to GeometryGUI_SpinBoxes */
269           myGEOMToolsGUI->myGeomGUI->EmitSignalDefaultStepValueChanged(dd);
270         }
271         else
272           parent->putInfo(tr("GEOM_PRP_ABORT"));
273         break;
274       }
275     case 804: // ADD IN STUDY - POPUP VIEWER
276       {
277         const SALOME_ListIO& ListSelected = Sel->StoredIObjects();
278         SALOME_ListIteratorOfListIO It(ListSelected);
279         for(; It.More(); It.Next()) {
280           Handle(SALOME_InteractiveObject) IObject = It.Value();
281           myGEOMToolsGUI->myGeomBase->AddInStudy(true, IObject);
282         }
283         /* Is set on the dialog box */
284         QApplication::restoreOverrideCursor();
285         break;
286       }
287     case 901: // RENAME
288       {
289         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
290         for(; It.More(); It.Next()) {
291           Handle(SALOME_InteractiveObject) IObject = It.Value();
292
293           SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
294           SALOMEDS::GenericAttribute_var anAttr;
295           SALOMEDS::AttributeName_var aName;
296           if(!obj->_is_nil()) {
297             if(obj->FindAttribute(anAttr, "AttributeName")) {
298               aName = SALOMEDS::AttributeName::_narrow(anAttr);
299
300               QString nm = QString(aName->Value());
301               nm = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), nm);
302               if(!nm.isEmpty()) {
303                 QApplication::setOverrideCursor(Qt::waitCursor);
304                 QAD_Application::getDesktop()->getActiveStudy()->renameIObject(IObject, nm);
305                 QApplication::restoreOverrideCursor();
306               }
307             }
308           }
309         }
310         break;
311       }
312     case 5103: // CHECK GEOMETRY
313       {
314         QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
315         PyEditor->setText("from GEOM_usinggeom import *\n");
316         PyEditor->setText(">>> ");
317         PyEditor->handleReturn();
318         break;
319       }
320     case 5104: // LOAD SCRIPT
321       {
322         QStringList filtersList;
323         filtersList.append(tr("GEOM_MEN_LOAD_SCRIPT"));
324         filtersList.append(tr("GEOM_MEN_ALL_FILES"));
325
326         QString aFile = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
327         if(!aFile.isEmpty()) {
328           QFileInfo file = aFile;
329           QApplication::setOverrideCursor(Qt::waitCursor);
330           QAD_PyEditor* PyEditor = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getPyEditor();
331
332           PyEditor->setText("import geompy\n");
333           PyEditor->handleReturn();
334
335           QStringList aTextList = QStringList::split(".", file.fileName());
336           PyEditor->setText("geompy.Path('" + file.dirPath() + "')\n");
337           PyEditor->handleReturn();
338
339           PyEditor->setText("from " + aTextList.first() + " import *\n");
340           PyEditor->handleReturn();
341         }
342         QApplication::restoreOverrideCursor();
343         break;
344       }
345     case 8032: // COLOR - POPUP VIEWER
346       {
347         if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
348           // VTK
349           VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
350           
351           SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
352           Handle(SALOME_InteractiveObject) FirstIOS =  Sel->firstIObject();
353           if(!FirstIOS.IsNull()) {
354             QColor initcolor = myRenderInter->GetColor(FirstIOS);
355             QColor c = QColorDialog::getColor( initcolor, QAD_Application::getDesktop());
356             
357             if(c.isValid()) {
358               QApplication::setOverrideCursor(Qt::waitCursor);
359               for(;It.More();It.Next()) {
360                 Handle(SALOME_InteractiveObject) IOS = It.Value();
361                 myRenderInter->SetColor(IOS,c);
362               }
363             }
364             QApplication::restoreOverrideCursor();
365           }
366         }
367         else if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
368           Handle(SALOME_InteractiveObject) IO = Sel->firstIObject();
369           Standard_Boolean found;
370           Handle(GEOM_AISShape) Shape = myGEOMToolsGUI->myGeomBase->ConvertIOinGEOMAISShape(IO, found, true);
371           if(found) {
372             Quantity_Color CSFColor;
373             Shape->Color(CSFColor);
374             
375             QColor c = QColorDialog::getColor(QColor(CSFColor.Red()  * 255.0, CSFColor.Green()* 255.0, CSFColor.Blue() * 255.0), QAD_Application::getDesktop());
376             
377             if(c.isValid()) {
378               CSFColor = Quantity_Color (c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB);
379               QApplication::setOverrideCursor( Qt::waitCursor );
380             
381               SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
382               for(;It.More();It.Next()) {
383                 Handle(SALOME_InteractiveObject) IObject = It.Value();
384                 Standard_Boolean found;
385                 Handle(GEOM_AISShape) Shape = myGEOMToolsGUI->myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
386                 if(found) {
387                   Shape->SetColor(CSFColor);
388                   Shape->SetShadingColor(CSFColor);
389                 }
390               }
391             }
392           }
393         }
394         QApplication::restoreOverrideCursor();
395         break;
396       }
397     case 8033: // TRANSPARENCY - POPUP VIEWER
398       {
399         OCCViewer_Viewer3d* v3d;
400         Handle(AIS_InteractiveContext) ic;
401         if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC) {
402           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
403           Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
404         }
405         GEOMBase_TransparencyDlg *aDlg = new GEOMBase_TransparencyDlg(parent, "", Sel, ic);
406         break;
407       }
408     case 8034: // ISOS - POPUP VIEWER
409       {
410         if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
411           break;
412
413         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
414         Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
415
416         ic->InitCurrent();
417         if(ic->MoreCurrent()) {
418           Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
419           QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
420           QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
421
422           if(!IsoU.isEmpty())
423             ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
424           else
425             IsoU = "1";
426           if (!IsoV.isEmpty())
427             ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
428           else
429             IsoV = "1";
430             
431           GEOMBase_NbIsosDlg * NbIsosDlg =
432             new GEOMBase_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE);
433     
434           NbIsosDlg->SpinBoxU->setValue(IsoU.toInt());
435           NbIsosDlg->SpinBoxV->setValue(IsoV.toInt());
436
437           if(NbIsosDlg->exec()) {
438             QApplication::setOverrideCursor(Qt::waitCursor);
439             for(; ic->MoreCurrent(); ic->NextCurrent()) {
440               Handle(AIS_Drawer) CurDrawer;
441               
442               CurDrawer = ic->Current()->Attributes();
443               CurDrawer->UIsoAspect()->SetNumber(NbIsosDlg->SpinBoxU->text().toInt());
444               CurDrawer->VIsoAspect()->SetNumber(NbIsosDlg->SpinBoxV->text().toInt());
445                 
446               ic->SetLocalAttributes(CurObject, CurDrawer);
447               ic->Redisplay(CurObject);
448             }
449           }
450         }
451         QApplication::restoreOverrideCursor();
452         break;
453       }
454     case 9024 : // OPEN - OBJBROSER POPUP
455       {
456         SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
457         Handle(SALOME_InteractiveObject) anIObject;
458         for(;It.More();It.Next()) {
459           anIObject = It.Value();
460           SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
461           SALOMEDS::AttributePersistentRef_var aPersist;
462           SALOMEDS::AttributeIOR_var anIOR;
463           if(!obj->_is_nil()) {
464             // this SObject may be GEOM module root SObject
465             SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(obj);
466             SALOMEDS::GenericAttribute_var anAttr;
467             bool useSubItems = false;
468             while (anIter->More() && !useSubItems) {
469               SALOMEDS::SObject_var subobj = anIter->Value();
470               if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
471                 useSubItems = true;
472                 obj = subobj;
473               }
474               else 
475                 anIter->Next();
476             }
477             obj->FindAttribute(anAttr, "AttributePersistentRef");
478               
479             while(useSubItems?anIter->More():!anAttr->_is_nil()) { 
480               if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
481                   obj->FindAttribute(anAttr, "AttributePersistentRef")) {
482                 // load
483                 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
484                 if (!CORBA::is_nil(comp)) {
485                   SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
486                   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
487                   aStudyBuilder->LoadWith(aStudy->FindComponent("GEOM"),driver);
488                 } 
489                 else {
490                   MESSAGE("Component is null");
491                 }
492               }
493               if(useSubItems) {
494                 anIter->Next();
495                 obj = anIter->Value();
496               } 
497               else 
498                 anAttr = SALOMEDS::GenericAttribute::_nil();
499             }
500           }
501         }
502         break;
503       }
504     default:
505       {
506         parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
507         break;
508       }
509     }
510   return true;
511 }
512
513
514 //===============================================================================
515 // function : OnEditDelete()
516 // purpose  :
517 //===============================================================================
518 void GEOMToolsGUI::OnEditDelete()
519 {
520   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
521   if(Sel->IObjectCount() == 0)
522     return;
523
524   if(QAD_MessageBox::warn2(QAD_Application::getDesktop(), tr("GEOM_WRN_WARNING"), tr("GEOM_REALLY_DELETE"), tr("GEOM_BUT_YES"), tr("GEOM_BUT_NO"), 1, 0, 0) != 1)
525     return;
526        
527   int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
528     
529   Standard_Boolean found;
530   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
531   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
532   SALOMEDS::GenericAttribute_var anAttr;
533   SALOMEDS::AttributeIOR_var anIOR;
534   
535   SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
536   for(;It.More();It.Next()) {
537     Handle(SALOME_InteractiveObject) IObject = It.Value();
538     if(IObject->hasEntry()) {
539       SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
540       SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
541       
542       /* Erase child graphical objects */
543       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
544       for(; it->More();it->Next()) {
545         SALOMEDS::SObject_var CSO= it->Value();
546         if(CSO->FindAttribute(anAttr, "AttributeIOR") ) {
547           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
548           /* Delete child(s) shape in Client : */
549           const TCollection_AsciiString ASCior(anIOR->Value()) ;
550           myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(ASCior);
551
552           for(int i = 0; i < nbSf; i++) {
553             QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
554             if(sf->getTypeView() == VIEW_OCC) {
555               OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
556               Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
557               Handle(GEOM_AISShape) Result = myGeomBase->ConvertIORinGEOMAISShape(anIOR->Value(), found);
558               if(found)
559                 myContext->Erase(Result, true, false);
560             }
561             else if(sf->getTypeView() == VIEW_VTK) {
562               //vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
563               VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
564               GEOM_Actor* ac = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), found);
565               if(found) {
566                 //Renderer->RemoveActor(ac);
567                 if(ac->hasIO()) 
568                   myRenderInter->Remove(ac->getIO());
569               }
570             }
571           }
572         }
573       }
574       
575       /* Erase main graphical object */
576       for(int i = 0; i < nbSf; i++) {
577         QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
578         if(sf->getTypeView() == VIEW_OCC) {
579           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
580           Handle(AIS_InteractiveContext) myContext = v3d->getAISContext();
581           Handle(GEOM_AISShape) Result = myGeomBase->ConvertIOinGEOMAISShape(IObject, found );
582           if(found)
583             myContext->Erase(Result, true, false);
584         }
585         else if(sf->getTypeView() == VIEW_VTK) {
586           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
587           myRenderInter->Remove( IObject );
588         }
589       }
590       
591       /* Delete main shape in Client : */
592       if(SO->FindAttribute(anAttr, "AttributeIOR")) {
593         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
594         const TCollection_AsciiString ASCIor(anIOR->Value()) ;
595         myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
596       }
597
598       /* Erase objects in Study */
599       SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
600       if(!obj->_is_nil()) {
601         QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy());
602         op->start();
603         aStudyBuilder->RemoveObject(obj);
604         op->finish();
605       }
606
607     } /* IObject->hasEntry() */
608   }   /* more/next           */
609
610   /* Clear any previous selection */
611   Sel->ClearIObjects(); 
612   QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
613 }
614
615
616 //==============================================================================
617 // function : OnEditCopy()
618 // purpose  :
619 //==============================================================================
620 void GEOMToolsGUI::OnEditCopy()
621 {
622   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
623   GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
624
625   const SALOME_ListIO& List = Sel->StoredIObjects();
626
627   myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
628
629   Sel->ClearIObjects();
630
631   for (unsigned int ind = 0; ind < listIOR->length();ind++) {
632     GEOM::GEOM_Shape_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
633     try {
634       GEOM::GEOM_Shape_var result = myGeom->MakeCopy(aShapeInit) ;
635       result->NameType( aShapeInit->NameType() );
636       myGeomBase->Display(result);
637     }
638     catch  (const SALOME::SALOME_Exception& S_ex) {
639       QtCatchCorbaException(S_ex);
640     }
641   }
642   
643   QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
644 }
645
646
647 //=====================================================================================
648 // function : Import
649 // purpose  : BRep, Iges, Step
650 //=====================================================================================
651 bool GEOMToolsGUI::Import(int aState)
652 {
653   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
654   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
655   
656   GEOM::GEOM_Shape_var aShape;
657   QString file;
658   QStringList filtersList;
659   
660   switch(aState)
661     {
662     case 111 :  // Import BREP
663       {
664         filtersList.append(tr("GEOM_MEN_IMPORT_BREP"));
665         filtersList.append(tr("GEOM_MEN_ALL_FILES"));
666
667         file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
668         if(!file.isEmpty()) {
669           QApplication::setOverrideCursor(Qt::waitCursor);
670           try {
671             aShape = myGeom->ImportBREP(file.latin1());
672           }
673           catch(const SALOME::SALOME_Exception& S_ex) {
674             QtCatchCorbaException(S_ex);
675           }
676         }
677         break;
678       }
679     case 112 :  // Import IGES
680       {
681         filtersList.append( tr("GEOM_MEN_IMPORT_IGES") ) ;
682         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
683
684         file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
685                                         "",
686                                         filtersList,
687                                         tr("GEOM_MEN_IMPORT"),
688                                         true);
689         if ( !file.isEmpty() ) {
690           QApplication::setOverrideCursor( Qt::waitCursor );
691           try {
692             aShape = myGeom->ImportIGES( file.latin1() );
693           }
694           catch (const SALOME::SALOME_Exception& S_ex) {
695             QtCatchCorbaException(S_ex);
696           }
697         }
698         break;
699       }
700     case 113 : // Import STEP
701       {
702         filtersList.append( tr("GEOM_MEN_IMPORT_STEP") ) ;
703         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
704
705         file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
706                                         "",
707                                         filtersList,
708                                         tr("GEOM_MEN_IMPORT"),
709                                         true);
710         if ( !file.isEmpty() ) {
711           QApplication::setOverrideCursor( Qt::waitCursor );
712           try {
713             aShape = myGeom->ImportSTEP( file.latin1() );
714           }
715           catch  (const SALOME::SALOME_Exception& S_ex) {
716             QtCatchCorbaException(S_ex);
717           }
718         }
719         break;
720       }
721     }
722   
723   if ( !file.isEmpty() ) {
724     QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
725
726     SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
727     SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
728     SALOMEDS::GenericAttribute_var anAttr;
729     SALOMEDS::AttributeName_var    aName;
730     SALOMEDS::AttributePixMap_var  aPixmap;
731     int aLocked = false;
732     if (father->_is_nil()) {
733       QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy() );
734       op->start();
735       aLocked = aStudy->GetProperties()->IsLocked();
736       if (aLocked) aStudy->GetProperties()->SetLocked(false);
737       father = aStudyBuilder->NewComponent("GEOM");
738       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
739       aName = SALOMEDS::AttributeName::_narrow(anAttr);
740       //      aName->SetValue( tr("GEOM_MEN_COMPONENT") );
741       aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) );
742       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
743       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
744       aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
745       if (aLocked) aStudy->GetProperties()->SetLocked(true);
746       op->finish();
747     }
748 //      if (aLocked) return false;
749     aStudyBuilder->DefineComponentInstance( father, myGeom );
750     father->ComponentIOR(myGeomGUI->GetFatherior());
751
752     QString nameShape = QAD_Tools::getFileNameFromPath(file,false) +  QString("_%1").arg(myGeomGUI->GetNbGeom()++);
753
754     if(myGeomBase->Display(aShape, strdup(nameShape.latin1()))) {
755       QAD_Application::getDesktop()->getActiveStudy()->setMessage( tr("GEOM_INF_LOADED").arg(QAD_Tools::getFileNameFromPath( file )) );
756       QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_READY"));
757     }
758   }
759   QApplication::restoreOverrideCursor();
760   return true;
761 }
762
763
764 //=====================================================================================
765 // function : Export
766 // purpose  : BRep, Iges, Step
767 //=====================================================================================
768 bool GEOMToolsGUI::Export(int aState)
769 {
770   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
771   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
772
773   GEOM::GEOM_Shape_var aShape;
774
775   static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"),
776                                tr("GEOM_MEN_IMPORT_IGES"),
777                                tr("GEOM_MEN_IMPORT_STEP") };
778   
779   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
780   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
781
782   switch (aState)
783     {
784     case 121 :
785       {
786         for(;It.More();It.Next()) {
787           QApplication::restoreOverrideCursor();
788           Handle(SALOME_InteractiveObject) IObject = It.Value();
789           Standard_Boolean found;
790           GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
791           //      Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
792           if ( found ) {
793             QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), 
794                                                     QString( IObject->getName() ) + ".brep",
795                                                     tr("GEOM_MEN_IMPORT_BREP"),
796                                                     tr("GEOM_MEN_EXPORT"),
797                                                     false);
798             if ( !file.isEmpty() && !aShape->_is_nil() ) {
799               QApplication::setOverrideCursor( Qt::waitCursor );
800               //      Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
801               try {
802                 myGeom->ExportBREP(strdup( file.latin1()), aShape);
803               }  
804               catch (const SALOME::SALOME_Exception& S_ex) {
805                 QtCatchCorbaException(S_ex);
806               }
807             }
808           }
809         }
810         break;
811       }
812     case 122 :
813       {
814         for(;It.More();It.Next()) {
815           QApplication::restoreOverrideCursor();
816           Handle(SALOME_InteractiveObject) IObject = It.Value();
817           Standard_Boolean found;
818           GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
819           //      Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
820           if ( found ) {
821             QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), 
822                                                     QString( IObject->getName() ) + ".igs",
823                                                     tr("GEOM_MEN_IMPORT_IGES"),
824                                                     tr("GEOM_MEN_EXPORT"),
825                                                     false);
826             if ( !file.isEmpty() && !aShape->_is_nil() ) {
827               QApplication::setOverrideCursor( Qt::waitCursor );
828               try {
829                 myGeom->ExportIGES(strdup( file.latin1()), aShape);
830               }  
831               catch (const SALOME::SALOME_Exception& S_ex) {
832                 QtCatchCorbaException(S_ex);
833               }
834 //            //VRV: OCC 4.0 migration
835 //            IGESControl_Controller::Init();
836 //            IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
837 //                                       Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
838 //            //VRV: OCC 4.0 migration
839
840 //            ICW.AddShape (Shape->Shape());
841 //            ICW.ComputeModel();
842 //            Standard_Boolean result = ICW.Write( strdup(file.latin1()) );
843             }
844           }
845         }
846         break;
847       }
848
849     case 123 :
850       {
851 //      bool test = false ;
852 //      IFSelect_ReturnStatus status ;
853 //      //VRV: OCC 4.0 migration
854 //      STEPControl_Writer aWriter;
855 //      //VRV: OCC 4.0 migration
856         QString file;
857
858         for( ; It.More(); It.Next() ) {
859 //        GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
860           QApplication::restoreOverrideCursor();
861           Handle(SALOME_InteractiveObject) IObject = It.Value();
862           Standard_Boolean found;
863           GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
864           //      Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
865           if ( found ) {
866             file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), 
867                                             QString( IObject->getName() ) + ".stp",
868                                             tr("GEOM_MEN_IMPORT_STEP"),
869                                             tr("GEOM_MEN_EXPORT"),
870                                             false);
871             if ( !file.isEmpty() && !aShape->_is_nil() ) {
872
873               QApplication::setOverrideCursor( Qt::waitCursor ) ;       
874               try {   
875                 myGeom->ExportSTEP(strdup( file.latin1()), aShape);   
876               }  
877               catch (const SALOME::SALOME_Exception& S_ex) {
878                 QtCatchCorbaException(S_ex);
879               }
880 //            //VRV: OCC 4.0 migration
881 //            status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ;
882 //            //VRV: OCC 4.0 migration
883 //            test = true ;
884 //            if ( status != IFSelect_RetDone ) {
885 //              QApplication::restoreOverrideCursor() ;
886 //              return false ;
887 //            }
888             }
889           }
890         }
891 //      if(test) {
892 //        status = aWriter.Write( strdup(file.latin1()) ) ;
893 //        QApplication::restoreOverrideCursor() ;
894 //        return status ;
895 //      }
896         break;
897       }
898
899     }
900   QApplication::restoreOverrideCursor() ;
901 }
902
903
904 //=====================================================================================
905 // EXPORTED METHODS
906 //=====================================================================================
907 extern "C"
908 {
909   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
910   {return GEOMToolsGUI::OnGUIEvent(theCommandID, parent);}
911 }