]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMToolsGUI/GEOMToolsGUI.cxx
Salome HOME
5eddb4047d8af460211c6d5ca6c0c8fad3fd99e6
[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   QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
537   op->start();
538   Standard_Boolean deleted = false;
539   for(;It.More();It.Next()) {
540     Handle(SALOME_InteractiveObject) IObject = It.Value();
541     if(IObject->hasEntry()) {
542       SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
543       SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
544       
545       /* Erase child graphical objects */
546       SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
547       for(; it->More();it->Next()) {
548         SALOMEDS::SObject_var CSO= it->Value();
549         if(CSO->FindAttribute(anAttr, "AttributeIOR") ) {
550           anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
551           /* Delete child(s) shape in Client : */
552           const TCollection_AsciiString ASCior(anIOR->Value()) ;
553           myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(ASCior);
554
555           for(int i = 0; i < nbSf; i++) {
556             QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
557             if(sf->getTypeView() == VIEW_OCC) {
558               OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
559               Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
560               Handle(GEOM_AISShape) Result = myGeomBase->ConvertIORinGEOMAISShape(anIOR->Value(), found);
561               if(found)
562                 myContext->Erase(Result, true, false);
563             }
564             else if(sf->getTypeView() == VIEW_VTK) {
565               //vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
566               VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
567               GEOM_Actor* ac = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), found);
568               if(found) {
569                 //Renderer->RemoveActor(ac);
570                 if(ac->hasIO()) 
571                   myRenderInter->Remove(ac->getIO());
572               }
573             }
574           }
575         }
576       }
577       
578       /* Erase main graphical object */
579       for(int i = 0; i < nbSf; i++) {
580         QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
581         if(sf->getTypeView() == VIEW_OCC) {
582           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
583           Handle(AIS_InteractiveContext) myContext = v3d->getAISContext();
584           Handle(GEOM_AISShape) Result = myGeomBase->ConvertIOinGEOMAISShape(IObject, found );
585           if(found)
586             myContext->Erase(Result, true, false);
587         }
588         else if(sf->getTypeView() == VIEW_VTK) {
589           VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
590           myRenderInter->Remove( IObject );
591         }
592       }
593       
594       /* Delete main shape in Client : */
595       if(SO->FindAttribute(anAttr, "AttributeIOR")) {
596         anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
597         const TCollection_AsciiString ASCIor(anIOR->Value()) ;
598         myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
599       }
600
601       /* Erase objects in Study */
602       SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
603       if(!obj->_is_nil()) {
604         aStudyBuilder->RemoveObject(obj);
605         deleted = true;
606       }
607
608     } /* IObject->hasEntry() */
609   }   /* more/next           */
610
611   if (deleted) op->finish();
612   else op->abort();
613
614   /* Clear any previous selection */
615   Sel->ClearIObjects(); 
616   QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
617 }
618
619
620 //==============================================================================
621 // function : OnEditCopy()
622 // purpose  :
623 //==============================================================================
624 void GEOMToolsGUI::OnEditCopy()
625 {
626   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
627   GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
628
629   const SALOME_ListIO& List = Sel->StoredIObjects();
630
631   myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
632
633   Sel->ClearIObjects();
634
635   for (unsigned int ind = 0; ind < listIOR->length();ind++) {
636     GEOM::GEOM_Shape_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
637     try {
638       GEOM::GEOM_Shape_var result = myGeom->MakeCopy(aShapeInit) ;
639       result->NameType( aShapeInit->NameType() );
640       myGeomBase->Display(result);
641     }
642     catch  (const SALOME::SALOME_Exception& S_ex) {
643       QtCatchCorbaException(S_ex);
644     }
645   }
646   
647   QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
648 }
649
650
651 //=====================================================================================
652 // function : Import
653 // purpose  : BRep, Iges, Step
654 //=====================================================================================
655 bool GEOMToolsGUI::Import(int aState)
656 {
657   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
658   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
659   
660   GEOM::GEOM_Shape_var aShape;
661   QString file;
662   QStringList filtersList;
663   
664   switch(aState)
665     {
666     case 111 :  // Import BREP
667       {
668         filtersList.append(tr("GEOM_MEN_IMPORT_BREP"));
669         filtersList.append(tr("GEOM_MEN_ALL_FILES"));
670
671         file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
672         if(!file.isEmpty()) {
673           QApplication::setOverrideCursor(Qt::waitCursor);
674           try {
675             aShape = myGeom->ImportBREP(file.latin1());
676           }
677           catch(const SALOME::SALOME_Exception& S_ex) {
678             QtCatchCorbaException(S_ex);
679           }
680         }
681         break;
682       }
683     case 112 :  // Import IGES
684       {
685         filtersList.append( tr("GEOM_MEN_IMPORT_IGES") ) ;
686         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
687
688         file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
689                                         "",
690                                         filtersList,
691                                         tr("GEOM_MEN_IMPORT"),
692                                         true);
693         if ( !file.isEmpty() ) {
694           QApplication::setOverrideCursor( Qt::waitCursor );
695           try {
696             aShape = myGeom->ImportIGES( file.latin1() );
697           }
698           catch (const SALOME::SALOME_Exception& S_ex) {
699             QtCatchCorbaException(S_ex);
700           }
701         }
702         break;
703       }
704     case 113 : // Import STEP
705       {
706         filtersList.append( tr("GEOM_MEN_IMPORT_STEP") ) ;
707         filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
708
709         file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
710                                         "",
711                                         filtersList,
712                                         tr("GEOM_MEN_IMPORT"),
713                                         true);
714         if ( !file.isEmpty() ) {
715           QApplication::setOverrideCursor( Qt::waitCursor );
716           try {
717             aShape = myGeom->ImportSTEP( file.latin1() );
718           }
719           catch  (const SALOME::SALOME_Exception& S_ex) {
720             QtCatchCorbaException(S_ex);
721           }
722         }
723         break;
724       }
725     }
726   
727   if ( !file.isEmpty() ) {
728     QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
729
730     SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
731     SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
732     SALOMEDS::GenericAttribute_var anAttr;
733     SALOMEDS::AttributeName_var    aName;
734     SALOMEDS::AttributePixMap_var  aPixmap;
735     int aLocked = false;
736     if (father->_is_nil()) {
737       QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy() );
738       op->start();
739       aLocked = aStudy->GetProperties()->IsLocked();
740       if (aLocked) aStudy->GetProperties()->SetLocked(false);
741       father = aStudyBuilder->NewComponent("GEOM");
742       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
743       aName = SALOMEDS::AttributeName::_narrow(anAttr);
744       //      aName->SetValue( tr("GEOM_MEN_COMPONENT") );
745       aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) );
746       anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
747       aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
748       aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
749       aStudyBuilder->DefineComponentInstance( father, myGeom );
750       if (aLocked) aStudy->GetProperties()->SetLocked(true);
751       op->finish();
752     }
753 //      if (aLocked) return false;
754     father->ComponentIOR(myGeomGUI->GetFatherior());
755
756     QString nameShape = QAD_Tools::getFileNameFromPath(file,false) +  QString("_%1").arg(myGeomGUI->GetNbGeom()++);
757
758     if(myGeomBase->Display(aShape, strdup(nameShape.latin1()))) {
759       QAD_Application::getDesktop()->getActiveStudy()->setMessage( tr("GEOM_INF_LOADED").arg(QAD_Tools::getFileNameFromPath( file )) );
760       QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_READY"));
761     }
762   }
763   QApplication::restoreOverrideCursor();
764   return true;
765 }
766
767
768 //=====================================================================================
769 // function : Export
770 // purpose  : BRep, Iges, Step
771 //=====================================================================================
772 bool GEOMToolsGUI::Export(int aState)
773 {
774   SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
775   SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
776
777   GEOM::GEOM_Shape_var aShape;
778
779   static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"),
780                                tr("GEOM_MEN_IMPORT_IGES"),
781                                tr("GEOM_MEN_IMPORT_STEP") };
782   
783   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
784   SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
785
786   switch (aState)
787     {
788     case 121 :
789       {
790         for(;It.More();It.Next()) {
791           QApplication::restoreOverrideCursor();
792           Handle(SALOME_InteractiveObject) IObject = It.Value();
793           Standard_Boolean found;
794           GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
795           //      Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
796           if ( found ) {
797             QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), 
798                                                     QString( IObject->getName() ) + ".brep",
799                                                     tr("GEOM_MEN_IMPORT_BREP"),
800                                                     tr("GEOM_MEN_EXPORT"),
801                                                     false);
802             if ( !file.isEmpty() && !aShape->_is_nil() ) {
803               QApplication::setOverrideCursor( Qt::waitCursor );
804               //      Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
805               try {
806                 myGeom->ExportBREP(strdup( file.latin1()), aShape);
807               }  
808               catch (const SALOME::SALOME_Exception& S_ex) {
809                 QtCatchCorbaException(S_ex);
810               }
811             }
812           }
813         }
814         break;
815       }
816     case 122 :
817       {
818         for(;It.More();It.Next()) {
819           QApplication::restoreOverrideCursor();
820           Handle(SALOME_InteractiveObject) IObject = It.Value();
821           Standard_Boolean found;
822           GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
823           //      Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
824           if ( found ) {
825             QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), 
826                                                     QString( IObject->getName() ) + ".igs",
827                                                     tr("GEOM_MEN_IMPORT_IGES"),
828                                                     tr("GEOM_MEN_EXPORT"),
829                                                     false);
830             if ( !file.isEmpty() && !aShape->_is_nil() ) {
831               QApplication::setOverrideCursor( Qt::waitCursor );
832               try {
833                 myGeom->ExportIGES(strdup( file.latin1()), aShape);
834               }  
835               catch (const SALOME::SALOME_Exception& S_ex) {
836                 QtCatchCorbaException(S_ex);
837               }
838 //            //VRV: OCC 4.0 migration
839 //            IGESControl_Controller::Init();
840 //            IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
841 //                                       Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
842 //            //VRV: OCC 4.0 migration
843
844 //            ICW.AddShape (Shape->Shape());
845 //            ICW.ComputeModel();
846 //            Standard_Boolean result = ICW.Write( strdup(file.latin1()) );
847             }
848           }
849         }
850         break;
851       }
852
853     case 123 :
854       {
855 //      bool test = false ;
856 //      IFSelect_ReturnStatus status ;
857 //      //VRV: OCC 4.0 migration
858 //      STEPControl_Writer aWriter;
859 //      //VRV: OCC 4.0 migration
860         QString file;
861
862         for( ; It.More(); It.Next() ) {
863 //        GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
864           QApplication::restoreOverrideCursor();
865           Handle(SALOME_InteractiveObject) IObject = It.Value();
866           Standard_Boolean found;
867           GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
868           //      Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
869           if ( found ) {
870             file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), 
871                                             QString( IObject->getName() ) + ".stp",
872                                             tr("GEOM_MEN_IMPORT_STEP"),
873                                             tr("GEOM_MEN_EXPORT"),
874                                             false);
875             if ( !file.isEmpty() && !aShape->_is_nil() ) {
876
877               QApplication::setOverrideCursor( Qt::waitCursor ) ;       
878               try {   
879                 myGeom->ExportSTEP(strdup( file.latin1()), aShape);   
880               }  
881               catch (const SALOME::SALOME_Exception& S_ex) {
882                 QtCatchCorbaException(S_ex);
883               }
884 //            //VRV: OCC 4.0 migration
885 //            status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ;
886 //            //VRV: OCC 4.0 migration
887 //            test = true ;
888 //            if ( status != IFSelect_RetDone ) {
889 //              QApplication::restoreOverrideCursor() ;
890 //              return false ;
891 //            }
892             }
893           }
894         }
895 //      if(test) {
896 //        status = aWriter.Write( strdup(file.latin1()) ) ;
897 //        QApplication::restoreOverrideCursor() ;
898 //        return status ;
899 //      }
900         break;
901       }
902
903     }
904   QApplication::restoreOverrideCursor() ;
905 }
906
907
908 //=====================================================================================
909 // EXPORTED METHODS
910 //=====================================================================================
911 extern "C"
912 {
913   bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
914   {return GEOMToolsGUI::OnGUIEvent(theCommandID, parent);}
915 }