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 Handle(AIS_InteractiveContext) ic;
400 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
401 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
402 ic = v3d->getAISContext();
404 GEOMBase_TransparencyDlg *aDlg = new GEOMBase_TransparencyDlg(parent, "", Sel, ic);
407 case 8034: // ISOS - POPUP VIEWER
409 if(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() > VIEW_OCC)
412 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
413 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
416 if(ic->MoreCurrent()) {
417 Handle(GEOM_AISShape) CurObject = Handle(GEOM_AISShape)::DownCast(ic->Current());
418 QString IsoU = QAD_CONFIG->getSetting("Geometry:SettingsIsoU");
419 QString IsoV = QAD_CONFIG->getSetting("Geometry:SettingsIsoV");
422 ic->DefaultDrawer()->UIsoAspect()->SetNumber(IsoU.toInt());
426 ic->DefaultDrawer()->VIsoAspect()->SetNumber(IsoV.toInt());
430 GEOMBase_NbIsosDlg * NbIsosDlg =
431 new GEOMBase_NbIsosDlg(QAD_Application::getDesktop(), tr("GEOM_MEN_ISOS"), TRUE);
433 NbIsosDlg->SpinBoxU->setValue(IsoU.toInt());
434 NbIsosDlg->SpinBoxV->setValue(IsoV.toInt());
436 if(NbIsosDlg->exec()) {
437 QApplication::setOverrideCursor(Qt::waitCursor);
438 for(; ic->MoreCurrent(); ic->NextCurrent()) {
439 Handle(AIS_Drawer) CurDrawer;
441 CurDrawer = ic->Current()->Attributes();
442 CurDrawer->UIsoAspect()->SetNumber(NbIsosDlg->SpinBoxU->text().toInt());
443 CurDrawer->VIsoAspect()->SetNumber(NbIsosDlg->SpinBoxV->text().toInt());
445 ic->SetLocalAttributes(CurObject, CurDrawer);
446 ic->Redisplay(CurObject);
450 QApplication::restoreOverrideCursor();
453 case 9024 : // OPEN - OBJBROSER POPUP
455 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
456 Handle(SALOME_InteractiveObject) anIObject;
457 for(;It.More();It.Next()) {
458 anIObject = It.Value();
459 SALOMEDS::SObject_var obj = aStudy->FindObjectID(anIObject->getEntry());
460 SALOMEDS::AttributePersistentRef_var aPersist;
461 SALOMEDS::AttributeIOR_var anIOR;
462 if(!obj->_is_nil()) {
463 // this SObject may be GEOM module root SObject
464 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(obj);
465 SALOMEDS::GenericAttribute_var anAttr;
466 bool useSubItems = false;
467 while (anIter->More() && !useSubItems) {
468 SALOMEDS::SObject_var subobj = anIter->Value();
469 if (subobj->FindAttribute(anAttr, "AttributePersistentRef")) {
476 obj->FindAttribute(anAttr, "AttributePersistentRef");
478 while(useSubItems?anIter->More():!anAttr->_is_nil()) {
479 if(!obj->FindAttribute(anAttr, "AttributeIOR") &&
480 obj->FindAttribute(anAttr, "AttributePersistentRef")) {
482 Engines::Component_var comp = QAD_Application::getDesktop()->getEngine("FactoryServer","GEOM");
483 if (!CORBA::is_nil(comp)) {
484 SALOMEDS::Driver_var driver = SALOMEDS::Driver::_narrow(comp);
485 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
486 aStudyBuilder->LoadWith(aStudy->FindComponent("GEOM"),driver);
489 MESSAGE("Component is null");
494 obj = anIter->Value();
497 anAttr = SALOMEDS::GenericAttribute::_nil();
505 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
513 //===============================================================================
514 // function : OnEditDelete()
516 //===============================================================================
517 void GEOMToolsGUI::OnEditDelete()
519 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
520 if(Sel->IObjectCount() == 0)
523 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)
526 int nbSf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFramesCount();
528 Standard_Boolean found;
529 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
530 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
531 SALOMEDS::GenericAttribute_var anAttr;
532 SALOMEDS::AttributeIOR_var anIOR;
534 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
535 QAD_Operation* op = new SALOMEGUI_ImportOperation( QAD_Application::getDesktop()->getActiveStudy() );
537 Standard_Boolean deleted = false;
538 for(;It.More();It.Next()) {
539 Handle(SALOME_InteractiveObject) IObject = It.Value();
540 if(IObject->hasEntry()) {
541 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
542 SALOMEDS::SObject_var SO = aStudy->FindObjectID(IObject->getEntry());
544 /* Erase child graphical objects */
545 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
546 for(; it->More();it->Next()) {
547 SALOMEDS::SObject_var CSO= it->Value();
548 if(CSO->FindAttribute(anAttr, "AttributeIOR") ) {
549 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
550 /* Delete child(s) shape in Client : */
551 const TCollection_AsciiString ASCior(anIOR->Value()) ;
552 myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(ASCior);
554 for(int i = 0; i < nbSf; i++) {
555 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
556 if(sf->getTypeView() == VIEW_OCC) {
557 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
558 Handle (AIS_InteractiveContext) myContext = v3d->getAISContext();
559 Handle(GEOM_AISShape) Result = myGeomBase->ConvertIORinGEOMAISShape(anIOR->Value(), found);
561 myContext->Erase(Result, true, false);
563 else if(sf->getTypeView() == VIEW_VTK) {
564 //vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
565 VTKViewer_RenderWindowInteractor* myRenderInter = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
566 GEOM_Actor* ac = myGeomBase->ConvertIORinGEOMActor(anIOR->Value(), found);
568 //Renderer->RemoveActor(ac);
570 myRenderInter->Remove(ac->getIO());
577 /* Erase main graphical object */
578 for(int i = 0; i < nbSf; i++) {
579 QAD_StudyFrame* sf = QAD_Application::getDesktop()->getActiveStudy()->getStudyFrame(i);
580 if(sf->getTypeView() == VIEW_OCC) {
581 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getViewer();
582 Handle(AIS_InteractiveContext) myContext = v3d->getAISContext();
583 Handle(GEOM_AISShape) Result = myGeomBase->ConvertIOinGEOMAISShape(IObject, found );
585 myContext->Erase(Result, true, false);
587 else if(sf->getTypeView() == VIEW_VTK) {
588 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
589 myRenderInter->Remove( IObject );
593 /* Delete main shape in Client : */
594 if(SO->FindAttribute(anAttr, "AttributeIOR")) {
595 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
596 const TCollection_AsciiString ASCIor(anIOR->Value()) ;
597 myGeomGUI->GetShapeReader().RemoveShapeFromBuffer(ASCIor);
600 /* Erase objects in Study */
601 SALOMEDS::SObject_var obj = aStudy->FindObjectID(IObject->getEntry());
602 if(!obj->_is_nil()) {
603 aStudyBuilder->RemoveObject(obj);
607 } /* IObject->hasEntry() */
610 if (deleted) op->finish();
613 /* Clear any previous selection */
614 Sel->ClearIObjects();
615 QAD_Application::getDesktop()->getActiveStudy()->updateObjBrowser();
619 //==============================================================================
620 // function : OnEditCopy()
622 //==============================================================================
623 void GEOMToolsGUI::OnEditCopy()
625 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection() );
626 GEOM::GEOM_Gen::ListOfIOR_var listIOR = new GEOM::GEOM_Gen::ListOfIOR;
628 const SALOME_ListIO& List = Sel->StoredIObjects();
630 myGeomBase->ConvertListOfIOInListOfIOR(List, listIOR);
632 Sel->ClearIObjects();
634 for (unsigned int ind = 0; ind < listIOR->length();ind++) {
635 GEOM::GEOM_Shape_var aShapeInit = myGeom->GetIORFromString(listIOR[ind]);
637 GEOM::GEOM_Shape_var result = myGeom->MakeCopy(aShapeInit) ;
638 result->NameType( aShapeInit->NameType() );
639 myGeomBase->Display(result);
641 catch (const SALOME::SALOME_Exception& S_ex) {
642 QtCatchCorbaException(S_ex);
646 QAD_Application::getDesktop()->putInfo(tr("GEOM_PRP_READY"));
650 //=====================================================================================
652 // purpose : BRep, Iges, Step
653 //=====================================================================================
654 bool GEOMToolsGUI::Import(int aState)
656 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
657 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
659 GEOM::GEOM_Shape_var aShape;
661 QStringList filtersList;
665 case 111 : // Import BREP
667 filtersList.append(tr("GEOM_MEN_IMPORT_BREP"));
668 filtersList.append(tr("GEOM_MEN_ALL_FILES"));
670 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(), "", filtersList, tr("GEOM_MEN_IMPORT"), true);
671 if(!file.isEmpty()) {
672 QApplication::setOverrideCursor(Qt::waitCursor);
674 aShape = myGeom->ImportBREP(file.latin1());
676 catch(const SALOME::SALOME_Exception& S_ex) {
677 QtCatchCorbaException(S_ex);
682 case 112 : // Import IGES
684 filtersList.append( tr("GEOM_MEN_IMPORT_IGES") ) ;
685 filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
687 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
690 tr("GEOM_MEN_IMPORT"),
692 if ( !file.isEmpty() ) {
693 QApplication::setOverrideCursor( Qt::waitCursor );
695 aShape = myGeom->ImportIGES( file.latin1() );
697 catch (const SALOME::SALOME_Exception& S_ex) {
698 QtCatchCorbaException(S_ex);
703 case 113 : // Import STEP
705 filtersList.append( tr("GEOM_MEN_IMPORT_STEP") ) ;
706 filtersList.append( tr("GEOM_MEN_ALL_FILES") ) ;
708 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
711 tr("GEOM_MEN_IMPORT"),
713 if ( !file.isEmpty() ) {
714 QApplication::setOverrideCursor( Qt::waitCursor );
716 aShape = myGeom->ImportSTEP( file.latin1() );
718 catch (const SALOME::SALOME_Exception& S_ex) {
719 QtCatchCorbaException(S_ex);
726 if ( !file.isEmpty() ) {
727 QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_LOADING").arg(QAD_Tools::getFileNameFromPath( file )) );
729 SALOMEDS::SComponent_var father = aStudy->FindComponent("GEOM");
730 SALOMEDS::SObject_var fatherSF = aStudy->FindObjectID(QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->entry());
731 SALOMEDS::GenericAttribute_var anAttr;
732 SALOMEDS::AttributeName_var aName;
733 SALOMEDS::AttributePixMap_var aPixmap;
735 if (father->_is_nil()) {
736 QAD_Operation* op = new SALOMEGUI_ImportOperation(QAD_Application::getDesktop()->getActiveStudy() );
738 aLocked = aStudy->GetProperties()->IsLocked();
739 if (aLocked) aStudy->GetProperties()->SetLocked(false);
740 father = aStudyBuilder->NewComponent("GEOM");
741 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributeName");
742 aName = SALOMEDS::AttributeName::_narrow(anAttr);
743 // aName->SetValue( tr("GEOM_MEN_COMPONENT") );
744 aName->SetValue(QAD_Application::getDesktop()->getComponentUserName( "GEOM" ) );
745 anAttr = aStudyBuilder->FindOrCreateAttribute(father, "AttributePixMap");
746 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
747 aPixmap->SetPixMap( "ICON_OBJBROWSER_Geometry" );
748 aStudyBuilder->DefineComponentInstance( father, myGeom );
749 if (aLocked) aStudy->GetProperties()->SetLocked(true);
752 // if (aLocked) return false;
753 father->ComponentIOR(myGeomGUI->GetFatherior());
755 QString nameShape = QAD_Tools::getFileNameFromPath(file,false) + QString("_%1").arg(myGeomGUI->GetNbGeom()++);
757 if(myGeomBase->Display(aShape, strdup(nameShape.latin1()))) {
758 QAD_Application::getDesktop()->getActiveStudy()->setMessage( tr("GEOM_INF_LOADED").arg(QAD_Tools::getFileNameFromPath( file )) );
759 QAD_Application::getDesktop()->putInfo( tr("GEOM_PRP_READY"));
762 QApplication::restoreOverrideCursor();
767 //=====================================================================================
769 // purpose : BRep, Iges, Step
770 //=====================================================================================
771 bool GEOMToolsGUI::Export(int aState)
773 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
774 SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
776 GEOM::GEOM_Shape_var aShape;
778 static QString filters[] = { tr("GEOM_MEN_IMPORT_BREP"),
779 tr("GEOM_MEN_IMPORT_IGES"),
780 tr("GEOM_MEN_IMPORT_STEP") };
782 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
783 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
789 for(;It.More();It.Next()) {
790 QApplication::restoreOverrideCursor();
791 Handle(SALOME_InteractiveObject) IObject = It.Value();
792 Standard_Boolean found;
793 GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
794 // Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
796 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
797 QString( IObject->getName() ) + ".brep",
798 tr("GEOM_MEN_IMPORT_BREP"),
799 tr("GEOM_MEN_EXPORT"),
801 if ( !file.isEmpty() && !aShape->_is_nil() ) {
802 QApplication::setOverrideCursor( Qt::waitCursor );
803 // Standard_Boolean result = BRepTools::Write(Shape->Shape(), strdup(file.latin1()) );
805 myGeom->ExportBREP(strdup( file.latin1()), aShape);
807 catch (const SALOME::SALOME_Exception& S_ex) {
808 QtCatchCorbaException(S_ex);
817 for(;It.More();It.Next()) {
818 QApplication::restoreOverrideCursor();
819 Handle(SALOME_InteractiveObject) IObject = It.Value();
820 Standard_Boolean found;
821 GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
822 // Handle(GEOM_AISShape) Shape = myGeomGUI->ConvertIOinGEOMAISShape(IObject, found, true);
824 QString file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
825 QString( IObject->getName() ) + ".igs",
826 tr("GEOM_MEN_IMPORT_IGES"),
827 tr("GEOM_MEN_EXPORT"),
829 if ( !file.isEmpty() && !aShape->_is_nil() ) {
830 QApplication::setOverrideCursor( Qt::waitCursor );
832 myGeom->ExportIGES(strdup( file.latin1()), aShape);
834 catch (const SALOME::SALOME_Exception& S_ex) {
835 QtCatchCorbaException(S_ex);
837 // //VRV: OCC 4.0 migration
838 // IGESControl_Controller::Init();
839 // IGESControl_Writer ICW (Interface_Static::CVal("XSTEP.iges.unit"),
840 // Interface_Static::IVal("XSTEP.iges.writebrep.mode"));
841 // //VRV: OCC 4.0 migration
843 // ICW.AddShape (Shape->Shape());
844 // ICW.ComputeModel();
845 // Standard_Boolean result = ICW.Write( strdup(file.latin1()) );
854 // bool test = false ;
855 // IFSelect_ReturnStatus status ;
856 // //VRV: OCC 4.0 migration
857 // STEPControl_Writer aWriter;
858 // //VRV: OCC 4.0 migration
861 for( ; It.More(); It.Next() ) {
862 // GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
863 QApplication::restoreOverrideCursor();
864 Handle(SALOME_InteractiveObject) IObject = It.Value();
865 Standard_Boolean found;
866 GEOM::GEOM_Shape_var aShape = myGeomBase->ConvertIOinGEOMShape(IObject, found);
867 // Handle(GEOM_AISShape) Shape = myGeomBase->ConvertIOinGEOMAISShape(IObject, found, true);
869 file = QAD_FileDlg::getFileName(QAD_Application::getDesktop(),
870 QString( IObject->getName() ) + ".stp",
871 tr("GEOM_MEN_IMPORT_STEP"),
872 tr("GEOM_MEN_EXPORT"),
874 if ( !file.isEmpty() && !aShape->_is_nil() ) {
876 QApplication::setOverrideCursor( Qt::waitCursor ) ;
878 myGeom->ExportSTEP(strdup( file.latin1()), aShape);
880 catch (const SALOME::SALOME_Exception& S_ex) {
881 QtCatchCorbaException(S_ex);
883 // //VRV: OCC 4.0 migration
884 // status = aWriter.Transfer( Shape->Shape(), STEPControl_ManifoldSolidBrep ) ;
885 // //VRV: OCC 4.0 migration
887 // if ( status != IFSelect_RetDone ) {
888 // QApplication::restoreOverrideCursor() ;
895 // status = aWriter.Write( strdup(file.latin1()) ) ;
896 // QApplication::restoreOverrideCursor() ;
903 QApplication::restoreOverrideCursor() ;
907 //=====================================================================================
909 //=====================================================================================
912 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
913 {return GEOMToolsGUI::OnGUIEvent(theCommandID, parent);}