1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 #include "VisuGUI_OffsetDlg.h"
24 #include "VisuGUI_Tools.h"
26 #include "VISU_ViewManager_i.hh"
27 #include "VISU_Actor.h"
29 #include "LightApp_Application.h"
30 #include "SalomeApp_Application.h"
31 #include "SVTK_ViewWindow.h"
32 #include "SVTK_ViewModel.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_Session.h"
35 #include "SUIT_MessageBox.h"
36 #include "SUIT_ResourceMgr.h"
38 #include "QtxDblSpinBox.h"
41 #include "vtkRenderer.h"
47 #include <qcheckbox.h>
48 #include <qgroupbox.h>
49 #include <qpushbutton.h>
55 VisuGUI_OffsetDlg::VisuGUI_OffsetDlg (VisuGUI* theModule)
56 : QDialog(VISU::GetDesktop(theModule), 0, false, WStyle_Customize |
57 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
60 myPrsList.setAutoDelete(false);
62 setName("VisuGUI_OffsetDlg");
63 setCaption(tr("TIT_OFFSETDLG"));
64 setSizeGripEnabled(TRUE);
66 QVBoxLayout* TopLayout = new QVBoxLayout (this);
67 TopLayout->setSpacing(6);
68 TopLayout->setMargin(11);
70 QHBox* anOffsetsPane = new QHBox (this);
71 anOffsetsPane->setSpacing(6);
73 new QLabel ("dX:", anOffsetsPane);
74 myDxEdt = new QtxDblSpinBox (anOffsetsPane, "myDxEdt");
75 myDxEdt->setRange(-MAXVAL, MAXVAL);
77 new QLabel("dY:", anOffsetsPane);
78 myDyEdt = new QtxDblSpinBox (anOffsetsPane, "myDyEdt");
79 myDyEdt->setRange(-MAXVAL, MAXVAL);
81 new QLabel("dZ:", anOffsetsPane);
82 myDzEdt = new QtxDblSpinBox (anOffsetsPane, "myDzEdt");
83 myDzEdt->setRange(-MAXVAL, MAXVAL);
85 QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), anOffsetsPane);
86 connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset()));
88 TopLayout->addWidget(anOffsetsPane);
90 if (!VISU::GetCStudy(VISU::GetAppStudy(theModule))->GetProperties()->IsLocked()) {
91 mySaveChk = new QCheckBox ("Save to presentation", this);
92 TopLayout->addWidget(mySaveChk);
93 mySaveChk->setChecked(true);
98 // Common buttons ===========================================================
99 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
100 GroupButtons->setColumnLayout(0, Qt::Vertical);
101 GroupButtons->layout()->setSpacing(0);
102 GroupButtons->layout()->setMargin(0);
103 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
104 GroupButtonsLayout->setAlignment(Qt::AlignTop);
105 GroupButtonsLayout->setSpacing(6);
106 GroupButtonsLayout->setMargin(11);
108 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
109 buttonOk->setAutoDefault(TRUE);
110 buttonOk->setDefault(TRUE);
111 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
112 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
114 QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons, "buttonApply");
115 buttonOk->setAutoDefault(TRUE);
116 GroupButtonsLayout->addWidget(buttonApply, 0, 2);
117 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3);
119 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
120 buttonCancel->setAutoDefault(TRUE);
121 GroupButtonsLayout->addWidget(buttonCancel, 0, 4);
122 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 5);
124 QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
125 buttonHelp->setAutoDefault(TRUE);
126 GroupButtonsLayout->addWidget(buttonHelp, 0, 6);
128 TopLayout->addWidget(GroupButtons);
130 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
131 connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply()));
132 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
133 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
136 void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
138 myPrsList.append(thePrs);
139 CORBA::Float anOffset[3];
140 thePrs->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
141 OffsetStruct anOffs(anOffset[0],anOffset[1],anOffset[2]);
142 myOldOffsets.append(anOffs);
143 if (myPrsList.count() == 1) {
144 setOffset(anOffs.myOffset);
145 } else if (myPrsList.count() == 2) {
147 setOffset(anOffs.myOffset);
151 void VisuGUI_OffsetDlg::setOffset (const vtkFloatingPointType* theOffset)
153 myDxEdt->setValue(theOffset[0]);
154 myDyEdt->setValue(theOffset[1]);
155 myDzEdt->setValue(theOffset[2]);
158 void VisuGUI_OffsetDlg::getOffset (vtkFloatingPointType* theOffset) const
160 theOffset[0] = myDxEdt->value();
161 theOffset[1] = myDyEdt->value();
162 theOffset[2] = myDzEdt->value();
165 void VisuGUI_OffsetDlg::onReset()
167 myDxEdt->setValue(0);
168 myDyEdt->setValue(0);
169 myDzEdt->setValue(0);
172 bool VisuGUI_OffsetDlg::isToSave() const
175 return mySaveChk->isChecked();
180 void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, vtkFloatingPointType* theOffset)
182 if (myPrsList.count() == 0)
186 thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
188 ViewManagerList aViewManagerList;
189 SalomeApp_Application* anApp = myModule->getApp();
190 anApp->viewManagers(aViewManagerList);
191 QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
192 for (; anVMIter.current(); ++anVMIter) {
193 SUIT_ViewManager* aViewManager = anVMIter.current();
194 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
195 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
196 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
197 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
198 vw->onAdjustTrihedron();
200 if (VISU_Actor* anActor = VISU::FindActor(vw, thePrs)) {
201 anActor->SetPosition(theOffset);
202 vw->highlight(thePrs->GetIO(), 1);
203 vw->getRenderer()->ResetCameraClippingRange();
212 void VisuGUI_OffsetDlg::accept()
214 vtkFloatingPointType anOffset[3];
216 for (int i = 0; i < myPrsList.count(); i++) {
217 updateOffset(myPrsList.at(i), anOffset);
222 void VisuGUI_OffsetDlg::reject()
224 for (int i = 0; i < myPrsList.count(); i++) {
225 updateOffset(myPrsList.at(i), myOldOffsets[i].myOffset);
230 void VisuGUI_OffsetDlg::onApply()
232 vtkFloatingPointType anOffset[3];
234 for (int i = 0; i < myPrsList.count(); i++) {
235 updateOffset(myPrsList.at(i), anOffset);
239 void VisuGUI_OffsetDlg::onHelp()
241 QString aHelpFileName = "translate_presentation_page.html";
242 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
244 app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
248 platform = "winapplication";
250 platform = "application";
252 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
253 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
254 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
255 QObject::tr("BUT_OK"));
259 void VisuGUI_OffsetDlg::keyPressEvent( QKeyEvent* e )
261 QDialog::keyPressEvent( e );
262 if ( e->isAccepted() )
265 if ( e->key() == Key_F1 )