1 // Copyright (C) 2007-2010 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
23 #include "VisuGUI_OffsetDlg.h"
26 #include "VisuGUI_Tools.h"
28 #include "VISU_ViewManager_i.hh"
29 #include "VISU_Actor.h"
31 #include "LightApp_Application.h"
32 #include "LightApp_SelectionMgr.h"
33 #include "SALOME_ListIteratorOfListIO.hxx"
34 #include "SalomeApp_Application.h"
35 #include <SalomeApp_DoubleSpinBox.h>
36 #include "SVTK_ViewWindow.h"
37 #include "SVTK_ViewModel.h"
38 #include "SUIT_ViewManager.h"
39 #include "SUIT_Desktop.h"
40 #include "SUIT_Session.h"
41 #include "SUIT_MessageBox.h"
42 #include "SUIT_ResourceMgr.h"
45 #include "vtkRenderer.h"
52 #include <QPushButton>
59 VisuGUI_OffsetDlg::VisuGUI_OffsetDlg (VisuGUI* theModule)
60 : QDialog(VISU::GetDesktop(theModule), Qt::WindowTitleHint | Qt::WindowSystemMenuHint ),
62 mySelectionMgr(VISU::GetSelectionMgr(theModule))
64 //myPrsList.setAutoDelete(false);
65 //myPointMapList.setAutoDelete(false);
67 setWindowTitle(tr("TIT_OFFSETDLG"));
68 setSizeGripEnabled(TRUE);
70 QVBoxLayout* TopLayout = new QVBoxLayout (this);
71 TopLayout->setSpacing(6);
72 TopLayout->setMargin(11);
74 QWidget* anOffsetsPane = new QWidget (this);
75 QHBoxLayout* aHBLay = new QHBoxLayout( anOffsetsPane );
76 aHBLay->setSpacing(6);
78 aHBLay->addWidget( new QLabel ("dX:", anOffsetsPane) );
79 aHBLay->addWidget( myDxEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) );
80 VISU::initSpinBox( myDxEdt, -MAXVAL, MAXVAL, 1., "length_precision" );
82 aHBLay->addWidget( new QLabel("dY:", anOffsetsPane) );;
83 aHBLay->addWidget( myDyEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) );
84 VISU::initSpinBox( myDyEdt, -MAXVAL, MAXVAL, 1., "length_precision" );
86 aHBLay->addWidget( new QLabel("dZ:", anOffsetsPane) );
87 aHBLay->addWidget( myDzEdt = new SalomeApp_DoubleSpinBox (anOffsetsPane) );
88 VISU::initSpinBox( myDzEdt, -MAXVAL, MAXVAL, 1., "length_precision" );
90 QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), anOffsetsPane);
91 aHBLay->addWidget( aResetBtn );
92 connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset()));
94 TopLayout->addWidget(anOffsetsPane);
96 if (!VISU::GetCStudy(VISU::GetAppStudy(theModule))->GetProperties()->IsLocked()) {
97 mySaveChk = new QCheckBox ("Save to presentation", this);
98 TopLayout->addWidget(mySaveChk);
99 mySaveChk->setChecked(true);
104 // Common buttons ===========================================================
105 QGroupBox* GroupButtons = new QGroupBox(this);
106 //GroupButtons->setColumnLayout(0, Qt::Vertical);
107 //GroupButtons->layout()->setSpacing(0);
108 //GroupButtons->layout()->setMargin(0);
109 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons);
110 GroupButtonsLayout->setAlignment(Qt::AlignTop);
111 GroupButtonsLayout->setSpacing(6);
112 GroupButtonsLayout->setMargin(11);
114 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons);
115 buttonOk->setAutoDefault(TRUE);
116 buttonOk->setDefault(TRUE);
117 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
118 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
120 QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons);
121 buttonOk->setAutoDefault(TRUE);
122 GroupButtonsLayout->addWidget(buttonApply, 0, 2);
123 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3);
125 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons);
126 buttonCancel->setAutoDefault(TRUE);
127 GroupButtonsLayout->addWidget(buttonCancel, 0, 4);
128 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 5);
130 QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons );
131 buttonHelp->setAutoDefault(TRUE);
132 GroupButtonsLayout->addWidget(buttonHelp, 0, 6);
134 TopLayout->addWidget(GroupButtons);
136 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
137 connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply()));
138 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
139 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
140 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionChanged()));
142 onSelectionChanged();
146 void VisuGUI_OffsetDlg::setVisible(bool show){
147 if ( show && getPrsCount() > 0 )
148 QDialog::setVisible( show );
150 QDialog::setVisible( show );
153 void VisuGUI_OffsetDlg::onSelectionChanged(){
157 //Clear old selection
158 clearPresentations();
160 SALOME_ListIO aListIO;
161 mySelectionMgr->selectedObjects(aListIO);
163 SalomeApp_Study* aStudy = VISU::GetAppStudy(myModule);
164 SALOME_ListIteratorOfListIO anIter(aListIO);
165 for (; anIter.More(); anIter.Next()) {
166 Handle(SALOME_InteractiveObject) anIO = anIter.Value();
167 if (anIO->hasEntry()) {
168 QString anEntry(anIO->getEntry());
169 VISU::TObjectInfo anObjectInfo = VISU::GetObjectByEntry(aStudy, anEntry.toLatin1().constData());
170 if(VISU::Prs3d_i* aPrsObject = VISU::GetPrs3dFromBase(anObjectInfo.myBase))
171 addPresentation(aPrsObject);
172 else if (VISU::PointMap3d_i* aPrs = dynamic_cast<VISU::PointMap3d_i*>(anObjectInfo.myBase)) {
173 addPointMapPresentation(aPrs);
179 void VisuGUI_OffsetDlg::clearPresentations(){
181 myPointMapList.clear();
182 myOldOffsets.clear();
183 myOldPointMapOffsets.clear();
186 void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
188 myPrsList.append(thePrs);
189 CORBA::Float anOffset[3];
190 thePrs->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
191 OffsetStruct anOffs(anOffset[0],anOffset[1],anOffset[2]);
192 myOldOffsets.append(anOffs);
193 if (myPrsList.count() == 1) {
194 setOffset(anOffs.myOffset);
195 } else if (myPrsList.count() == 2) {
197 setOffset(anOffs.myOffset);
201 void VisuGUI_OffsetDlg::addPointMapPresentation (VISU::PointMap3d_i* thePrs)
203 myPointMapList.append(thePrs);
205 CORBA::Float anOffset[3];
206 thePrs->GetOffset(anOffset[0],anOffset[1],anOffset[2]);
207 OffsetStruct anOffs(anOffset[0],anOffset[1],anOffset[2]);
208 myOldPointMapOffsets.append(anOffs);
209 if (myPointMapList.count() == 1) {
210 setOffset(anOffs.myOffset);
211 } else if (myPointMapList.count() == 2) {
213 setOffset(anOffs.myOffset);
217 void VisuGUI_OffsetDlg::setOffset (const vtkFloatingPointType* theOffset)
219 myDxEdt->setValue(theOffset[0]);
220 myDyEdt->setValue(theOffset[1]);
221 myDzEdt->setValue(theOffset[2]);
224 void VisuGUI_OffsetDlg::getOffset (vtkFloatingPointType* theOffset) const
226 theOffset[0] = myDxEdt->value();
227 theOffset[1] = myDyEdt->value();
228 theOffset[2] = myDzEdt->value();
231 void VisuGUI_OffsetDlg::onReset()
233 myDxEdt->setValue(0);
234 myDyEdt->setValue(0);
235 myDzEdt->setValue(0);
238 bool VisuGUI_OffsetDlg::isToSave() const
241 return mySaveChk->isChecked();
246 void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, vtkFloatingPointType* theOffset)
248 if (myPrsList.count() == 0)
252 thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
253 thePrs->UpdateActors();
257 ViewManagerList aViewManagerList;
258 SalomeApp_Application* anApp = myModule->getApp();
259 anApp->viewManagers(aViewManagerList);
260 QList<SUIT_ViewManager*>::Iterator anVMIter = aViewManagerList.begin();
261 for (; anVMIter != aViewManagerList.end(); anVMIter++ ) {
262 QVector<SUIT_ViewWindow*> aViews = (*anVMIter)->getViews();
263 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
264 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
265 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
266 if (VISU_Actor* anActor = VISU::FindActor(vw, thePrs)) {
267 anActor->SetPosition(theOffset);
268 vw->onAdjustTrihedron();
269 vw->getRenderer()->ResetCameraClippingRange();
278 void VisuGUI_OffsetDlg::updatePointMapOffset (VISU::PointMap3d_i* thePrs, vtkFloatingPointType* theOffset)
280 if (myPointMapList.count() == 0)
284 thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
286 ViewManagerList aViewManagerList;
287 SalomeApp_Application* anApp = myModule->getApp();
288 anApp->viewManagers(aViewManagerList);
289 SUIT_ViewManager* aViewManager;
290 foreach( aViewManager, aViewManagerList ) {
291 QVector<SUIT_ViewWindow*> aViews = aViewManager->getViews();
292 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
293 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
294 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
295 vw->onAdjustTrihedron();
297 if (VISU_ActorBase* anActor = VISU::FindActorBase(vw, thePrs)) {
298 anActor->SetPosition(theOffset);
299 vw->highlight(thePrs->GetIO(), 1);
300 vw->getRenderer()->ResetCameraClippingRange();
309 void VisuGUI_OffsetDlg::accept()
311 vtkFloatingPointType anOffset[3];
313 for (int i = 0; i < myPrsList.count(); i++) {
314 updateOffset(myPrsList.at(i), anOffset);
316 for (int i = 0; i < myPointMapList.count(); i++) {
317 updatePointMapOffset(myPointMapList.at(i), anOffset);
322 void VisuGUI_OffsetDlg::reject()
324 for (int i = 0; i < myPrsList.count(); i++) {
325 updateOffset(myPrsList.at(i), myOldOffsets[i].myOffset);
327 for (int i = 0; i < myPointMapList.count(); i++) {
328 updatePointMapOffset(myPointMapList.at(i), myOldPointMapOffsets[i].myOffset);
333 void VisuGUI_OffsetDlg::onApply()
335 vtkFloatingPointType anOffset[3];
338 for (int i = 0; i < myPrsList.count(); i++) {
339 updateOffset(myPrsList.at(i), anOffset);
341 for (int i = 0; i < myPointMapList.count(); i++) {
342 updatePointMapOffset(myPointMapList.at(i), anOffset);
346 void VisuGUI_OffsetDlg::onHelp()
348 QString aHelpFileName = "translate_presentation_page.html";
349 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
351 app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
355 platform = "winapplication";
357 platform = "application";
359 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
360 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
361 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(aHelpFileName),
362 QObject::tr("BUT_OK"));
366 void VisuGUI_OffsetDlg::keyPressEvent( QKeyEvent* e )
368 QDialog::keyPressEvent( e );
369 if ( e->isAccepted() )
372 if ( e->key() == Qt::Key_F1 )