X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FVISUGUI%2FVisuGUI_OffsetDlg.cxx;h=9dc2aa0a2b4fd0e8b5a0957ea1f385ce6cdeed5d;hb=c25714a9012243bcabcf495e35255a0d01a913a8;hp=5ef2cbfbe334d8ad8ff876df70b76ceedddc4e0a;hpb=716894d52739e56d77c5085e02b4cdfdbef60136;p=modules%2Fvisu.git diff --git a/src/VISUGUI/VisuGUI_OffsetDlg.cxx b/src/VISUGUI/VisuGUI_OffsetDlg.cxx index 5ef2cbfb..9dc2aa0a 100644 --- a/src/VISUGUI/VisuGUI_OffsetDlg.cxx +++ b/src/VISUGUI/VisuGUI_OffsetDlg.cxx @@ -1,21 +1,23 @@ -// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. -// -// This library is distributed in the hope that it will be useful -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // #include "VisuGUI_OffsetDlg.h" @@ -27,62 +29,66 @@ #include "VISU_Actor.h" #include "LightApp_Application.h" +#include "LightApp_SelectionMgr.h" +#include "SALOME_ListIteratorOfListIO.hxx" #include "SalomeApp_Application.h" +#include #include "SVTK_ViewWindow.h" #include "SVTK_ViewModel.h" +#include "SUIT_ViewManager.h" #include "SUIT_Desktop.h" #include "SUIT_Session.h" #include "SUIT_MessageBox.h" #include "SUIT_ResourceMgr.h" -#include "QtxDblSpinBox.h" - // VTK Includes #include "vtkRenderer.h" // QT Includes -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #define MAXVAL 1e10 VisuGUI_OffsetDlg::VisuGUI_OffsetDlg (VisuGUI* theModule) -: QDialog(VISU::GetDesktop(theModule), 0, false, WStyle_Customize | - WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose), -myModule(theModule) +: QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ), + myModule(theModule), + mySelectionMgr(VISU::GetSelectionMgr(theModule)) { - myPrsList.setAutoDelete(false); + //myPrsList.setAutoDelete(false); + //myPointMapList.setAutoDelete(false); - setName("VisuGUI_OffsetDlg"); - setCaption(tr("TIT_OFFSETDLG")); + setWindowTitle(tr("TIT_OFFSETDLG")); setSizeGripEnabled(TRUE); QVBoxLayout* TopLayout = new QVBoxLayout (this); TopLayout->setSpacing(6); TopLayout->setMargin(11); - QHBox* anOffsetsPane = new QHBox (this); - anOffsetsPane->setSpacing(6); + QWidget* anOffsetsPane = new QWidget (this); + QHBoxLayout* aHBLay = new QHBoxLayout( anOffsetsPane ); + aHBLay->setSpacing(6); - new QLabel ("dX:", anOffsetsPane); - myDxEdt = new QtxDblSpinBox (anOffsetsPane, "myDxEdt"); - myDxEdt->setRange(-MAXVAL, MAXVAL); + aHBLay->addWidget( new QLabel ("dX:", anOffsetsPane) ); + aHBLay->addWidget( myDxEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) ); + VISU::initSpinBox( myDxEdt, -MAXVAL, MAXVAL, 1., "length_precision" ); - new QLabel("dY:", anOffsetsPane); - myDyEdt = new QtxDblSpinBox (anOffsetsPane, "myDyEdt"); - myDyEdt->setRange(-MAXVAL, MAXVAL); + aHBLay->addWidget( new QLabel("dY:", anOffsetsPane) );; + aHBLay->addWidget( myDyEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) ); + VISU::initSpinBox( myDyEdt, -MAXVAL, MAXVAL, 1., "length_precision" ); - new QLabel("dZ:", anOffsetsPane); - myDzEdt = new QtxDblSpinBox (anOffsetsPane, "myDzEdt"); - myDzEdt->setRange(-MAXVAL, MAXVAL); + aHBLay->addWidget( new QLabel("dZ:", anOffsetsPane) ); + aHBLay->addWidget( myDzEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) ); + VISU::initSpinBox( myDzEdt, -MAXVAL, MAXVAL, 1., "length_precision" ); QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), anOffsetsPane); + aHBLay->addWidget( aResetBtn ); connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset())); TopLayout->addWidget(anOffsetsPane); @@ -96,32 +102,32 @@ myModule(theModule) } // Common buttons =========================================================== - QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons"); - GroupButtons->setColumnLayout(0, Qt::Vertical); - GroupButtons->layout()->setSpacing(0); - GroupButtons->layout()->setMargin(0); - QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout()); + QGroupBox* GroupButtons = new QGroupBox(this); + //GroupButtons->setColumnLayout(0, Qt::Vertical); + //GroupButtons->layout()->setSpacing(0); + //GroupButtons->layout()->setMargin(0); + QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons); GroupButtonsLayout->setAlignment(Qt::AlignTop); GroupButtonsLayout->setSpacing(6); GroupButtonsLayout->setMargin(11); - QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk"); + QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons); buttonOk->setAutoDefault(TRUE); buttonOk->setDefault(TRUE); GroupButtonsLayout->addWidget(buttonOk, 0, 0); GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1); - QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons, "buttonApply"); + QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons); buttonOk->setAutoDefault(TRUE); GroupButtonsLayout->addWidget(buttonApply, 0, 2); GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3); - QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel"); + QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons); buttonCancel->setAutoDefault(TRUE); GroupButtonsLayout->addWidget(buttonCancel, 0, 4); GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 5); - QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp"); + QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons ); buttonHelp->setAutoDefault(TRUE); GroupButtonsLayout->addWidget(buttonHelp, 0, 6); @@ -131,6 +137,50 @@ myModule(theModule) connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply())); connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject())); connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp())); + connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged())); + + onSelectionChanged(); + show(); +} + +void VisuGUI_OffsetDlg::setVisible(bool show){ + if ( show && getPrsCount() > 0 ) + QDialog::setVisible( show ); + else + QDialog::setVisible( show ); +} + +void VisuGUI_OffsetDlg::onSelectionChanged(){ + if(!mySelectionMgr) + return; + + //Clear old selection + clearPresentations(); + + SALOME_ListIO aListIO; + mySelectionMgr->selectedObjects(aListIO); + + SalomeApp_Study* aStudy = VISU::GetAppStudy(myModule); + SALOME_ListIteratorOfListIO anIter(aListIO); + for (; anIter.More(); anIter.Next()) { + Handle(SALOME_InteractiveObject) anIO = anIter.Value(); + if (anIO->hasEntry()) { + QString anEntry(anIO->getEntry()); + VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, anEntry.toLatin1().constData()); + if(VISU::Prs3d_i* aPrsObject = VISU::GetPrs3dFromBase(anObjectInfo.myBase)) + addPresentation(aPrsObject); + else if (VISU::PointMap3d_i* aPrs = dynamic_cast(anObjectInfo.myBase)) { + addPointMapPresentation(aPrs); + } + } + } +} + +void VisuGUI_OffsetDlg::clearPresentations(){ + myPrsList.clear(); + myPointMapList.clear(); + myOldOffsets.clear(); + myOldPointMapOffsets.clear(); } void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs) @@ -148,6 +198,22 @@ void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs) } } +void VisuGUI_OffsetDlg::addPointMapPresentation (VISU::PointMap3d_i* thePrs) +{ + myPointMapList.append(thePrs); + + CORBA::Float anOffset[3]; + thePrs->GetOffset(anOffset[0],anOffset[1],anOffset[2]); + OffsetStruct anOffs(anOffset[0],anOffset[1],anOffset[2]); + myOldPointMapOffsets.append(anOffs); + if (myPointMapList.count() == 1) { + setOffset(anOffs.myOffset); + } else if (myPointMapList.count() == 2) { + OffsetStruct anOffs; + setOffset(anOffs.myOffset); + } +} + void VisuGUI_OffsetDlg::setOffset (const vtkFloatingPointType* theOffset) { myDxEdt->setValue(theOffset[0]); @@ -182,24 +248,55 @@ void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, vtkFloatingPointTyp if (myPrsList.count() == 0) return; - if (isToSave()) + if (isToSave()) { + thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]); + thePrs->UpdateActors(); + return; + } + + ViewManagerList aViewManagerList; + SalomeApp_Application* anApp = myModule->getApp(); + anApp->viewManagers(aViewManagerList); + QList::Iterator anVMIter = aViewManagerList.begin(); + for (; anVMIter != aViewManagerList.end(); anVMIter++ ) { + QVector aViews = (*anVMIter)->getViews(); + for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) { + if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) { + if (SVTK_ViewWindow* vw = dynamic_cast(aViewWindow)) { + if (VISU_Actor* anActor = VISU::FindActor(vw, thePrs)) { + anActor->SetPosition(theOffset); + vw->onAdjustTrihedron(); + vw->getRenderer()->ResetCameraClippingRange(); + vw->Repaint(); + } + } + } + } + } +} + +void VisuGUI_OffsetDlg::updatePointMapOffset (VISU::PointMap3d_i* thePrs, vtkFloatingPointType* theOffset) +{ + if (myPointMapList.count() == 0) + return; + + if (isToSave()) thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]); ViewManagerList aViewManagerList; SalomeApp_Application* anApp = myModule->getApp(); anApp->viewManagers(aViewManagerList); - QPtrListIterator anVMIter (aViewManagerList); - for (; anVMIter.current(); ++anVMIter) { - SUIT_ViewManager* aViewManager = anVMIter.current(); - QPtrVector aViews = aViewManager->getViews(); + SUIT_ViewManager* aViewManager; + foreach( aViewManager, aViewManagerList ) { + QVector aViews = aViewManager->getViews(); for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) { if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) { if (SVTK_ViewWindow* vw = dynamic_cast(aViewWindow)) { - vw->onAdjustTrihedron(); + vw->onAdjustTrihedron(); - if (VISU_Actor* anActor = VISU::FindActor(vw, thePrs)) { + if (VISU_ActorBase* anActor = VISU::FindActorBase(vw, thePrs)) { anActor->SetPosition(theOffset); - vw->highlight(thePrs->GetIO(), 1); + vw->highlight(thePrs->GetIO(), 1); vw->getRenderer()->ResetCameraClippingRange(); vw->Repaint(); } @@ -216,6 +313,9 @@ void VisuGUI_OffsetDlg::accept() for (int i = 0; i < myPrsList.count(); i++) { updateOffset(myPrsList.at(i), anOffset); } + for (int i = 0; i < myPointMapList.count(); i++) { + updatePointMapOffset(myPointMapList.at(i), anOffset); + } QDialog::accept(); } @@ -224,6 +324,9 @@ void VisuGUI_OffsetDlg::reject() for (int i = 0; i < myPrsList.count(); i++) { updateOffset(myPrsList.at(i), myOldOffsets[i].myOffset); } + for (int i = 0; i < myPointMapList.count(); i++) { + updatePointMapOffset(myPointMapList.at(i), myOldPointMapOffsets[i].myOffset); + } QDialog::reject(); } @@ -231,9 +334,13 @@ void VisuGUI_OffsetDlg::onApply() { vtkFloatingPointType anOffset[3]; getOffset(anOffset); + for (int i = 0; i < myPrsList.count(); i++) { updateOffset(myPrsList.at(i), anOffset); } + for (int i = 0; i < myPointMapList.count(); i++) { + updatePointMapOffset(myPointMapList.at(i), anOffset); + } } void VisuGUI_OffsetDlg::onHelp() @@ -249,10 +356,10 @@ void VisuGUI_OffsetDlg::onHelp() #else platform = "application"; #endif - SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"), - QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). - arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName), - QObject::tr("BUT_OK")); + SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"), + QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE"). + arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName), + QObject::tr("BUT_OK")); } } @@ -262,7 +369,7 @@ void VisuGUI_OffsetDlg::keyPressEvent( QKeyEvent* e ) if ( e->isAccepted() ) return; - if ( e->key() == Key_F1 ) + if ( e->key() == Qt::Key_F1 ) { e->accept(); onHelp();