-// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 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
+// 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
+//
+// 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
+// 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/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "VisuGUI_OffsetDlg.h"
#include "VISU_ViewManager_i.hh"
#include "VISU_Actor.h"
+#include "LightApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+#include "SALOME_ListIteratorOfListIO.hxx"
#include "SalomeApp_Application.h"
+#include <SalomeApp_DoubleSpinBox.h>
#include "SVTK_ViewWindow.h"
#include "SVTK_ViewModel.h"
+#include "SUIT_ViewManager.h"
#include "SUIT_Desktop.h"
-
-#include "QtxDblSpinBox.h"
+#include "SUIT_Session.h"
+#include "SUIT_MessageBox.h"
+#include "SUIT_ResourceMgr.h"
// VTK Includes
#include "vtkRenderer.h"
// QT Includes
-#include <qhbox.h>
-#include <qlabel.h>
-#include <qlayout.h>
-#include <qcheckbox.h>
-#include <qgroupbox.h>
-#include <qpushbutton.h>
+#include <QLabel>
+#include <QLayout>
+#include <QCheckBox>
+#include <QGroupBox>
+#include <QPushButton>
+#include <QKeyEvent>
#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* aOffsetsPane = new QHBox (this);
- aOffsetsPane->setSpacing(6);
+ QWidget* anOffsetsPane = new QWidget (this);
+ QHBoxLayout* aHBLay = new QHBoxLayout( anOffsetsPane );
+ aHBLay->setSpacing(6);
- new QLabel ("dX:", aOffsetsPane);
- myDxEdt = new QtxDblSpinBox (aOffsetsPane, "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:", aOffsetsPane);
- myDyEdt = new QtxDblSpinBox (aOffsetsPane, "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:", aOffsetsPane);
- myDzEdt = new QtxDblSpinBox (aOffsetsPane, "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"), aOffsetsPane);
+ QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), anOffsetsPane);
+ aHBLay->addWidget( aResetBtn );
connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset()));
- TopLayout->addWidget(aOffsetsPane);
+ TopLayout->addWidget(anOffsetsPane);
if (!VISU::GetCStudy(VISU::GetAppStudy(theModule))->GetProperties()->IsLocked()) {
mySaveChk = new QCheckBox ("Save to presentation", this);
}
// 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->setAutoDefault(TRUE);
+ GroupButtonsLayout->addWidget(buttonHelp, 0, 6);
TopLayout->addWidget(GroupButtons);
connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
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<VISU::PointMap3d_i*>(anObjectInfo.myBase)) {
+ addPointMapPresentation(aPrs);
+ }
+ }
+ }
+}
+
+void VisuGUI_OffsetDlg::clearPresentations(){
+ myPrsList.clear();
+ myPointMapList.clear();
+ myOldOffsets.clear();
+ myOldPointMapOffsets.clear();
}
void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
{
myPrsList.append(thePrs);
- OffsetStruct aOffs;
- thePrs->GetOffset(aOffs.myOffset);
- myOldOffsets.append(aOffs);
+ CORBA::Float anOffset[3];
+ thePrs->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
+ OffsetStruct anOffs(anOffset[0],anOffset[1],anOffset[2]);
+ myOldOffsets.append(anOffs);
if (myPrsList.count() == 1) {
- setOffset(aOffs.myOffset);
+ setOffset(anOffs.myOffset);
} else if (myPrsList.count() == 2) {
- float aOffset[3];
- aOffset[0] = aOffset[1] = aOffset[2] = 0;
- setOffset(aOffset);
+ OffsetStruct anOffs;
+ setOffset(anOffs.myOffset);
}
}
-void VisuGUI_OffsetDlg::setOffset (const float* theOffset)
+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 double* theOffset)
{
myDxEdt->setValue(theOffset[0]);
myDyEdt->setValue(theOffset[1]);
myDzEdt->setValue(theOffset[2]);
}
-void VisuGUI_OffsetDlg::getOffset (float* theOffset) const
+void VisuGUI_OffsetDlg::getOffset (double* theOffset) const
{
theOffset[0] = myDxEdt->value();
theOffset[1] = myDyEdt->value();
return false;
}
-void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, float* theOffset)
+void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, double* theOffset)
{
- if (myPrsList.count() == 0) return;
+ if (myPrsList.count() == 0)
+ return;
- if (isToSave()) thePrs->SetOffset(theOffset);
+ if (isToSave()) {
+ thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
+ thePrs->UpdateActors();
+ return;
+ }
ViewManagerList aViewManagerList;
SalomeApp_Application* anApp = myModule->getApp();
anApp->viewManagers(aViewManagerList);
- QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
- for (; anVMIter.current(); ++anVMIter) {
- SUIT_ViewManager* aViewManager = anVMIter.current();
- QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
+ QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
+ for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
+ QVector<SUIT_ViewWindow*> 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<SVTK_ViewWindow*>(aViewWindow)) {
- vw->onAdjustTrihedron();
+ 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, double* theOffset)
+{
+ if (myPointMapList.count() == 0)
+ return;
- if (VISU_Actor* anActor = VISU::GetActor(thePrs, vw)) {
+ if (isToSave())
+ thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
+
+ ViewManagerList aViewManagerList;
+ SalomeApp_Application* anApp = myModule->getApp();
+ anApp->viewManagers(aViewManagerList);
+ SUIT_ViewManager* aViewManager;
+ foreach( aViewManager, aViewManagerList ) {
+ QVector<SUIT_ViewWindow*> 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<SVTK_ViewWindow*>(aViewWindow)) {
+ vw->onAdjustTrihedron();
+
+ if (VISU_ActorBase* anActor = VISU::FindActorBase(vw, thePrs)) {
anActor->SetPosition(theOffset);
+ vw->highlight(thePrs->GetIO(), 1);
vw->getRenderer()->ResetCameraClippingRange();
vw->Repaint();
-
- Handle(SALOME_InteractiveObject) anIO;
- CORBA::Object_var anObject = VISU::GetSelectedObj(myModule, &anIO);
- if (!CORBA::is_nil(anObject))
- vw->highlight(anIO, 1);
}
}
}
void VisuGUI_OffsetDlg::accept()
{
- float aOffset[3];
- getOffset(aOffset);
+ double anOffset[3];
+ getOffset(anOffset);
for (int i = 0; i < myPrsList.count(); i++) {
- updateOffset(myPrsList.at(i), aOffset);
+ updateOffset(myPrsList.at(i), anOffset);
+ }
+ for (int i = 0; i < myPointMapList.count(); i++) {
+ updatePointMapOffset(myPointMapList.at(i), anOffset);
}
QDialog::accept();
}
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();
}
void VisuGUI_OffsetDlg::onApply()
{
- float aOffset[3];
- getOffset(aOffset);
+ double anOffset[3];
+ getOffset(anOffset);
+
for (int i = 0; i < myPrsList.count(); i++) {
- updateOffset(myPrsList.at(i), aOffset);
+ updateOffset(myPrsList.at(i), anOffset);
+ }
+ for (int i = 0; i < myPointMapList.count(); i++) {
+ updatePointMapOffset(myPointMapList.at(i), anOffset);
+ }
+}
+
+void VisuGUI_OffsetDlg::onHelp()
+{
+ QString aHelpFileName = "translate_presentation_page.html";
+ LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+ if (app)
+ app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
+ else {
+ QString platform;
+#ifdef WIN32
+ platform = "winapplication";
+#else
+ platform = "application";
+#endif
+ 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"));
}
}
+
+void VisuGUI_OffsetDlg::keyPressEvent( QKeyEvent* e )
+{
+ QDialog::keyPressEvent( e );
+ if ( e->isAccepted() )
+ return;
+
+ if ( e->key() == Qt::Key_F1 )
+ {
+ e->accept();
+ onHelp();
+ }
+}