1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : GEOMBase_Tools.cxx
25 // Author : Damien COQUERET
30 #include "GEOMToolsGUI.h"
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"
38 #include "OCCViewer_Viewer3d.h"
39 #include "VTKViewer_ViewFrame.h"
41 #include "SALOME_ListIteratorOfListIO.hxx"
42 #include "SALOMEGUI_NameDlg.h"
43 #include "SALOMEGUI_ImportOperation.h"
44 #include "SALOMEGUI_QtCatchCorbaException.hxx"
46 #include <AIS_Drawer.hxx>
47 #include <AIS_ListIteratorOfListOfInteractive.hxx>
48 #include <Prs3d_IsoAspect.hxx>
50 #include <vtkBMPReader.h>
51 #include <vtkTexture.h>
52 #include <vtkTextureMapToPlane.h>
53 #include <vtkTransformTextureCoords.h>
54 #include <vtkDataSetMapper.h>
56 #include <qfileinfo.h>
57 #include <qcolordialog.h>
60 #include "GEOMToolsGUI_NbIsosDlg.h" // Method ISOS adjustement
61 #include "GEOMToolsGUI_TransparencyDlg.h" // Method TRANSPARENCY adjustement
63 //=======================================================================
64 // function : GEOMToolsGUI()
65 // purpose : Constructor
66 //=======================================================================
67 GEOMToolsGUI::GEOMToolsGUI() :
70 myGeomBase = new GEOMBase();
71 myGeomGUI = GEOMContext::GetGeomGUI();
72 myGeom = myGeomGUI->myComponentGeom;
76 //=======================================================================
77 // function : ~GEOMToolsGUI()
78 // purpose : Destructor
79 //=======================================================================
80 GEOMToolsGUI::~GEOMToolsGUI()
85 //=======================================================================
86 // function : OnGUIEvent()
88 //=======================================================================
89 bool GEOMToolsGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
91 GEOMToolsGUI* myGEOMToolsGUI = new GEOMToolsGUI();
92 myGEOMToolsGUI->myGeomGUI->EmitSignalDeactivateDialog();
93 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
95 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
100 myGEOMToolsGUI->OnEditCopy();
105 myGEOMToolsGUI->OnEditDelete();
108 case 111: // IMPORT BREP
110 myGEOMToolsGUI->Import(theCommandID);
113 case 112: // IMPORT IGES
115 myGEOMToolsGUI->Import(theCommandID);
118 case 113: // IMPORT STEP
120 myGEOMToolsGUI->Import(theCommandID);
123 case 121: // EXPORT BREP
125 myGEOMToolsGUI->Export(theCommandID);
128 case 122: // EXPORT IGES
130 myGEOMToolsGUI->Export(theCommandID);
133 case 123: // EXPORT STEP
135 myGEOMToolsGUI->Export(theCommandID);
138 case 411: // SETTINGS - ADD IN STUDY
140 QMenuBar* Mb = QAD_Application::getDesktop()->getMainMenuBar();
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);
149 case 412: // SETTINGS - SHADING COLOR
151 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
154 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
155 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
157 QString SCr = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorRed");
158 QString SCg = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorGreen");
159 QString SCb = QAD_CONFIG->getSetting("Geometry:SettingsShadingColorBlue");
161 if(!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty()) {
162 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
165 Quantity_Color Default = Quantity_Color();
166 color = QColor ((int)Default.Red() * 255.0, (int)Default.Green()* 255.0, (int)Default.Blue() * 255.0);
169 QColor c = QColorDialog::getColor(color, QAD_Application::getDesktop());
171 //myGEOMToolsGUI->myGeomGUI->GetShadingColor() = Quantity_Color(c.red() / 255.0, c.green() / 255.0, c.blue() / 255.0, Quantity_TOC_RGB);
173 AIS_ListOfInteractive List;
174 ic->DisplayedObjects(List);
175 AIS_ListOfInteractive List1;
176 ic->ObjectsInCollector(List1);
179 AIS_ListIteratorOfListOfInteractive ite(List);
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);
189 ic->UpdateCurrentViewer();
191 QAD_CONFIG->addSetting("Geometry:SettingsShadingColorRed", c.red());
192 QAD_CONFIG->addSetting("Geometry:SettingsShadingColorGreen", c.green());
193 QAD_CONFIG->addSetting("Geometry:SettingsShadingColorBlue", c.blue());
197 case 413: // SETTINGS - ISOS
199 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
202 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
203 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
205 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
206 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
208 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
212 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
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();
220 NbIsosDlg->SpinBoxU->setValue(UIso);
221 NbIsosDlg->SpinBoxV->setValue(VIso);
223 if(NbIsosDlg->exec()) {
224 UIso = NbIsosDlg->SpinBoxU->text().toInt();
225 VIso = NbIsosDlg->SpinBoxV->text().toInt();
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 */
233 AIS_ListOfInteractive List;
234 ic->DisplayedObjects(List);
235 AIS_ListOfInteractive List1;
236 ic->ObjectsInCollector(List1);
239 AIS_ListIteratorOfListOfInteractive ite(List);
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);
254 ic->UpdateCurrentViewer();
257 case 414: // SETTINGS : STEP VALUE FOR SPIN BOXES
259 QString step = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
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);
266 QAD_CONFIG->addSetting("Geometry:SettingsGeomStep", QString("%1").arg(dd));
268 /* Emit signal to GeometryGUI_SpinBoxes */
269 myGEOMToolsGUI->myGeomGUI->EmitSignalDefaultStepValueChanged(dd);
272 parent->putInfo(tr("GEOM_PRP_ABORT"));
275 case 804: // ADD IN STUDY - POPUP VIEWER
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);
283 /* Is set on the dialog box */
284 QApplication::restoreOverrideCursor();
289 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
290 for(; It.More(); It.Next()) {
291 Handle(SALOME_InteractiveObject) IObject = It.Value();
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);
300 QString nm = QString(aName->Value());
301 nm = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), nm);
303 QApplication::setOverrideCursor(Qt::waitCursor);
304 QAD_Application::getDesktop()->getActiveStudy()->renameIObject(IObject, nm);
305 QApplication::restoreOverrideCursor();
312 case 5103: // CHECK GEOMETRY
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();
320 case 5104: // LOAD SCRIPT
322 QStringList filtersList;
323 filtersList.append(tr("GEOM_MEN_LOAD_SCRIPT"));
324 filtersList.append(tr("GEOM_MEN_ALL_FILES"));
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();
332 PyEditor->setText("import geompy\n");
333 PyEditor->handleReturn();
335 QStringList aTextList = QStringList::split(".", file.fileName());
336 PyEditor->setText("geompy.Path('" + file.dirPath() + "')\n");
337 PyEditor->handleReturn();
339 PyEditor->setText("from " + aTextList.first() + " import *\n");
340 PyEditor->handleReturn();
342 QApplication::restoreOverrideCursor();
345 case 8032: // COLOR - POPUP VIEWER
347 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
349 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
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());
358 QApplication::setOverrideCursor(Qt::waitCursor);
359 for(;It.More();It.Next()) {
360 Handle(SALOME_InteractiveObject) IOS = It.Value();
361 myRenderInter->SetColor(IOS,c);
364 QApplication::restoreOverrideCursor();
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);
372 Quantity_Color CSFColor;
373 Shape->Color(CSFColor);
375 QColor c = QColorDialog::getColor(QColor(CSFColor.Red() * 255.0, CSFColor.Green()* 255.0, CSFColor.Blue() * 255.0), QAD_Application::getDesktop());
378 CSFColor = Quantity_Color (c.red()/255., c.green()/255., c.blue()/255., Quantity_TOC_RGB);
379 QApplication::setOverrideCursor( Qt::waitCursor );
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);
387 Shape->SetColor(CSFColor);
388 Shape->SetShadingColor(CSFColor);
394 QApplication::restoreOverrideCursor();
397 case 8033: // TRANSPARENCY - POPUP VIEWER
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();
405 GEOMBase_TransparencyDlg *aDlg = new GEOMBase_TransparencyDlg(parent, "", Sel, ic);
408 case 8034: // ISOS - POPUP VIEWER
410 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
413 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
414 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
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");
423 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
427 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
431 GEOMBase_NbIsosDlg * NbIsosDlg =
432 new GEOMBase_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE);
434 NbIsosDlg->SpinBoxU->setValue(IsoU.toInt());
435 NbIsosDlg->SpinBoxV->setValue(IsoV.toInt());
437 if(NbIsosDlg->exec()) {
438 QApplication::setOverrideCursor(Qt::waitCursor);
439 for(; ic->MoreCurrent(); ic->NextCurrent()) {
440 Handle(AIS_Drawer) CurDrawer;
442 CurDrawer = ic->Current()->Attributes();
443 CurDrawer->UIsoAspect()->SetNumber(NbIsosDlg->SpinBoxU->text().toInt());
444 CurDrawer->VIsoAspect()->SetNumber(NbIsosDlg->SpinBoxV->text().toInt());
446 ic->SetLocalAttributes(CurObject, CurDrawer);
447 ic->Redisplay(CurObject);
451 QApplication::restoreOverrideCursor();
454 case 9024 : // OPEN - OBJBROSER POPUP
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")) {
477 obj->FindAttribute(anAttr, "AttributePersistentRef");
479 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
480 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
481 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
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);
490 MESSAGE("Component is null");
495 obj = anIter->Value();
498 anAttr = SALOMEDS::GenericAttribute::_nil();
506 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
514 //===============================================================================
515 // function : OnEditDelete()
517 //===============================================================================
518 void GEOMToolsGUI::OnEditDelete()
520 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
521 if(Sel->IObjectCount() == 0)
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)
527 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
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;
535 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
536 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
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());
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);
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);
562 myContext->Erase(Result, true, false);
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);
569 //Renderer->RemoveActor(ac);
571 myRenderInter->Remove(ac->getIO());
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 );
586 myContext->Erase(Result, true, false);
588 else if(sf->getTypeView() == VIEW_VTK) {
589 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
590 myRenderInter->Remove( IObject );
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);
601 /* Erase objects in Study */
602 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
603 if(!obj->_is_nil()) {
604 aStudyBuilder->RemoveObject(obj);
608 } /* IObject->hasEntry() */
611 if (deleted) op->finish();
614 /* Clear any previous selection */
615 Sel->ClearIObjects();
616 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
620 //==============================================================================
621 // function : OnEditCopy()
623 //==============================================================================
624 void GEOMToolsGUI::OnEditCopy()
626 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
627 GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
629 const SALOME_ListIO& List = Sel->StoredIObjects();
631 myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
633 Sel->ClearIObjects();
635 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
636 GEOM::GEOM_Shape_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
638 GEOM::GEOM_Shape_var result = myGeom->MakeCopy(aShapeInit) ;
639 result->NameType( aShapeInit->NameType() );
640 myGeomBase->Display(result);
642 catch (const SALOME::SALOME_Exception& S_ex) {
643 QtCatchCorbaException(S_ex);
647 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
651 //=====================================================================================
653 // purpose : BRep, Iges, Step
654 //=====================================================================================
655 bool GEOMToolsGUI::Import(int aState)
657 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
658 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
660 GEOM::GEOM_Shape_var aShape;
662 QStringList filtersList;
666 case 111 : // Import BREP
668 filtersList.append(tr("GEOM_MEN_IMPORT_BREP"));
669 filtersList.append(tr("GEOM_MEN_ALL_FILES"));
671 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
672 if(!file.isEmpty()) {
673 QApplication::setOverrideCursor(Qt::waitCursor);
675 aShape = myGeom->ImportBREP(file.latin1());
677 catch(const SALOME::SALOME_Exception& S_ex) {
678 QtCatchCorbaException(S_ex);
683 case 112 : // Import IGES
685 filtersList.append( tr("GEOM_MEN_IMPORT_IGES") ) ;
686 filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
688 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
691 tr("GEOM_MEN_IMPORT"),
693 if ( !file.isEmpty() ) {
694 QApplication::setOverrideCursor( Qt::waitCursor );
696 aShape = myGeom->ImportIGES( file.latin1() );
698 catch (const SALOME::SALOME_Exception& S_ex) {
699 QtCatchCorbaException(S_ex);
704 case 113 : // Import STEP
706 filtersList.append( tr("GEOM_MEN_IMPORT_STEP") ) ;
707 filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
709 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
712 tr("GEOM_MEN_IMPORT"),
714 if ( !file.isEmpty() ) {
715 QApplication::setOverrideCursor( Qt::waitCursor );
717 aShape = myGeom->ImportSTEP( file.latin1() );
719 catch (const SALOME::SALOME_Exception& S_ex) {
720 QtCatchCorbaException(S_ex);
727 if ( !file.isEmpty() ) {
728 QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
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;
736 if (father->_is_nil()) {
737 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy() );
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);
753 // if (aLocked) return false;
754 father->ComponentIOR(myGeomGUI->GetFatherior());
756 QString nameShape = QAD_Tools::getFileNameFromPath(file,false) + QString("_%1").arg(myGeomGUI->GetNbGeom()++);
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"));
763 QApplication::restoreOverrideCursor();
768 //=====================================================================================
770 // purpose : BRep, Iges, Step
771 //=====================================================================================
772 bool GEOMToolsGUI::Export(int aState)
774 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
775 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
777 GEOM::GEOM_Shape_var aShape;
779 static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"),
780 tr("GEOM_MEN_IMPORT_IGES"),
781 tr("GEOM_MEN_IMPORT_STEP") };
783 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
784 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
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);
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"),
802 if ( !file.isEmpty() && !aShape->_is_nil() ) {
803 QApplication::setOverrideCursor( Qt::waitCursor );
804 // Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
806 myGeom->ExportBREP(strdup( file.latin1()), aShape);
808 catch (const SALOME::SALOME_Exception& S_ex) {
809 QtCatchCorbaException(S_ex);
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);
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"),
830 if ( !file.isEmpty() && !aShape->_is_nil() ) {
831 QApplication::setOverrideCursor( Qt::waitCursor );
833 myGeom->ExportIGES(strdup( file.latin1()), aShape);
835 catch (const SALOME::SALOME_Exception& S_ex) {
836 QtCatchCorbaException(S_ex);
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
844 // ICW.AddShape (Shape->Shape());
845 // ICW.ComputeModel();
846 // Standard_Boolean result = ICW.Write( strdup(file.latin1()) );
855 // bool test = false ;
856 // IFSelect_ReturnStatus status ;
857 // //VRV: OCC 4.0 migration
858 // STEPControl_Writer aWriter;
859 // //VRV: OCC 4.0 migration
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);
870 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
871 QString( IObject->getName() ) + ".stp",
872 tr("GEOM_MEN_IMPORT_STEP"),
873 tr("GEOM_MEN_EXPORT"),
875 if ( !file.isEmpty() && !aShape->_is_nil() ) {
877 QApplication::setOverrideCursor( Qt::waitCursor ) ;
879 myGeom->ExportSTEP(strdup( file.latin1()), aShape);
881 catch (const SALOME::SALOME_Exception& S_ex) {
882 QtCatchCorbaException(S_ex);
884 // //VRV: OCC 4.0 migration
885 // status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ;
886 // //VRV: OCC 4.0 migration
888 // if ( status != IFSelect_RetDone ) {
889 // QApplication::restoreOverrideCursor() ;
896 // status = aWriter.Write( strdup(file.latin1()) ) ;
897 // QApplication::restoreOverrideCursor() ;
904 QApplication::restoreOverrideCursor() ;
908 //=====================================================================================
910 //=====================================================================================
913 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
914 {return GEOMToolsGUI::OnGUIEvent(theCommandID, parent);}