1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #include "VisuGUI_FilterScalarsDlg.h"
23 #include "VISU_ColoredPrs3d_i.hh"
24 #include "VISU_ColoredPrs3dHolder_i.hh"
27 #include "VisuGUI_Tools.h"
29 #include <SalomeApp_Application.h>
30 #include <LightApp_SelectionMgr.h>
32 #include <SUIT_Desktop.h>
33 #include <SUIT_MessageBox.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <QPushButton>
38 #include <QVBoxLayout>
39 #include <QHBoxLayout>
43 #include <QDoubleValidator>
46 VisuGUI_FilterScalarsDlg::VisuGUI_FilterScalarsDlg( VisuGUI* theModule )
47 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
48 myVisuGUI( theModule )
51 setWindowTitle(tr("TITLE"));
52 setSizeGripEnabled(true);
53 setAttribute( Qt::WA_DeleteOnClose, true );
55 QVBoxLayout* aMainLayout = new QVBoxLayout(this);
57 myRangeBox = new QGroupBox(this);
58 myRangeBox->setTitle(tr("BOXTITLE"));
59 myRangeBox->setCheckable(true);
60 aMainLayout->addWidget(myRangeBox);
62 QHBoxLayout* aBoxLayout = new QHBoxLayout(myRangeBox);
63 aBoxLayout->addWidget(new QLabel(tr("MINLBL"), myRangeBox));
64 myMinEdit = new QLineEdit( myRangeBox );
65 myMinEdit->setValidator( new QDoubleValidator(myMinEdit) );
66 aBoxLayout->addWidget(myMinEdit);
68 aBoxLayout->addWidget(new QLabel(tr("MAXLBL"), myRangeBox));
69 myMaxEdit = new QLineEdit( myRangeBox );
70 myMaxEdit->setValidator( new QDoubleValidator(myMaxEdit) );
71 aBoxLayout->addWidget(myMaxEdit);
73 QGroupBox* aGroupButtons = new QGroupBox(this);
74 QHBoxLayout* aButtonsLayout = new QHBoxLayout(aGroupButtons);
76 QPushButton* aBtnOk = new QPushButton(tr("BUT_OK"), aGroupButtons);
77 aBtnOk->setAutoDefault(true);
78 aBtnOk->setDefault(true);
79 aButtonsLayout->addWidget(aBtnOk);
81 QPushButton* aBtnCancel = new QPushButton(tr("BUT_CANCEL"), aGroupButtons);
82 aBtnCancel->setAutoDefault(true);
83 aButtonsLayout->addWidget(aBtnCancel);
85 aButtonsLayout->addStretch();
87 QPushButton* aBtnHelp = new QPushButton(tr("BUT_HELP"), aGroupButtons);
88 aBtnHelp->setAutoDefault(true);
89 aButtonsLayout->addWidget(aBtnHelp);
91 aMainLayout->addWidget(aGroupButtons);
93 connect(aBtnOk, SIGNAL(clicked()), this, SLOT(accept()));
94 connect(aBtnCancel, SIGNAL(clicked()), this, SLOT(reject()));
95 connect(aBtnHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
97 SalomeApp_Application* anApp = theModule->getApp();
98 LightApp_SelectionMgr* aSelectionMgr = anApp->selectionMgr();
99 connect( aSelectionMgr, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionEvent() ) );
105 VisuGUI_FilterScalarsDlg::~VisuGUI_FilterScalarsDlg()
108 void VisuGUI_FilterScalarsDlg::onSelectionEvent()
110 typedef SALOME::GenericObjPtr< VISU::ColoredPrs3d_i > TColoredPrs3dPtr;
111 VISU::TSelectionInfo aSelectionInfo = VISU::GetSelectedObjects( myVisuGUI );
112 myColoredPrs3d = TColoredPrs3dPtr();
113 if ( !aSelectionInfo.empty() ) {
114 VISU::TSelectionItem aSelectionItem = aSelectionInfo.front();
115 if ( VISU::Base_i* aBase = aSelectionItem.myObjectInfo.myBase ) {
116 if ( VISU::ColoredPrs3d_i* aColoredPrs3d = dynamic_cast< VISU::ColoredPrs3d_i* >( aBase ) ) {
117 myColoredPrs3d = aColoredPrs3d;
118 } else if (VISU::ColoredPrs3dHolder_i* aHolder =
119 dynamic_cast< VISU::ColoredPrs3dHolder_i* >( aBase )) {
120 myColoredPrs3d = aHolder->GetPrs3dDevice();
122 if (myColoredPrs3d.get() != NULL) {
123 myRangeBox->setChecked( myColoredPrs3d->IsScalarFilterUsed() );
124 myMinEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMin() ) );
125 myMaxEdit->setText( QString::number( myColoredPrs3d->GetScalarFilterMax() ) );
135 void VisuGUI_FilterScalarsDlg::accept()
137 myColoredPrs3d->SetScalarFilterRange( myMinEdit->text().toDouble(), myMaxEdit->text().toDouble() );
138 myColoredPrs3d->UseScalarFiltering( myRangeBox->isChecked() );
139 myColoredPrs3d->UpdateActors();
143 void VisuGUI_FilterScalarsDlg::reject()
148 void VisuGUI_FilterScalarsDlg::onHelp()
150 QString aHelpFileName = "viewing_3d_presentations_page.html#filter_by_scalars_anchor";
151 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
153 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
157 platform = "winapplication";
159 platform = "application";
161 SUIT_MessageBox::warning(0, tr("WRN_WARNING"),
162 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
163 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),