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/
21 #include "VisuGUI_OffsetDlg.h"
24 #include "VisuGUI_Tools.h"
26 #include "VISU_ViewManager_i.hh"
27 #include "VISU_Actor.h"
29 #include "SalomeApp_Application.h"
30 #include "SVTK_ViewWindow.h"
31 #include "SVTK_ViewModel.h"
32 #include "SUIT_Desktop.h"
34 #include "QtxDblSpinBox.h"
37 #include "vtkRenderer.h"
43 #include <qcheckbox.h>
44 #include <qgroupbox.h>
45 #include <qpushbutton.h>
51 VisuGUI_OffsetDlg::VisuGUI_OffsetDlg (VisuGUI* theModule)
52 : QDialog(VISU::GetDesktop(theModule), 0, false, WStyle_Customize |
53 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
56 myPrsList.setAutoDelete(false);
58 setName("VisuGUI_OffsetDlg");
59 setCaption(tr("TIT_OFFSETDLG"));
60 setSizeGripEnabled(TRUE);
62 QVBoxLayout* TopLayout = new QVBoxLayout (this);
63 TopLayout->setSpacing(6);
64 TopLayout->setMargin(11);
66 QHBox* aOffsetsPane = new QHBox (this);
67 aOffsetsPane->setSpacing(6);
69 new QLabel ("dX:", aOffsetsPane);
70 myDxEdt = new QtxDblSpinBox (aOffsetsPane, "myDxEdt");
71 myDxEdt->setRange(-MAXVAL, MAXVAL);
73 new QLabel("dY:", aOffsetsPane);
74 myDyEdt = new QtxDblSpinBox (aOffsetsPane, "myDyEdt");
75 myDyEdt->setRange(-MAXVAL, MAXVAL);
77 new QLabel("dZ:", aOffsetsPane);
78 myDzEdt = new QtxDblSpinBox (aOffsetsPane, "myDzEdt");
79 myDzEdt->setRange(-MAXVAL, MAXVAL);
81 QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), aOffsetsPane);
82 connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset()));
84 TopLayout->addWidget(aOffsetsPane);
86 if (!VISU::GetCStudy(VISU::GetAppStudy(theModule))->GetProperties()->IsLocked()) {
87 mySaveChk = new QCheckBox ("Save to presentation", this);
88 TopLayout->addWidget(mySaveChk);
89 mySaveChk->setChecked(true);
94 // Common buttons ===========================================================
95 QGroupBox* GroupButtons = new QGroupBox(this, "GroupButtons");
96 GroupButtons->setColumnLayout(0, Qt::Vertical);
97 GroupButtons->layout()->setSpacing(0);
98 GroupButtons->layout()->setMargin(0);
99 QGridLayout* GroupButtonsLayout = new QGridLayout(GroupButtons->layout());
100 GroupButtonsLayout->setAlignment(Qt::AlignTop);
101 GroupButtonsLayout->setSpacing(6);
102 GroupButtonsLayout->setMargin(11);
104 QPushButton* buttonOk = new QPushButton(tr("&OK"), GroupButtons, "buttonOk");
105 buttonOk->setAutoDefault(TRUE);
106 buttonOk->setDefault(TRUE);
107 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
108 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 1);
110 QPushButton* buttonApply = new QPushButton(tr("&Apply"), GroupButtons, "buttonApply");
111 buttonOk->setAutoDefault(TRUE);
112 GroupButtonsLayout->addWidget(buttonApply, 0, 2);
113 GroupButtonsLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3);
115 QPushButton* buttonCancel = new QPushButton(tr("&Cancel") , GroupButtons, "buttonCancel");
116 buttonCancel->setAutoDefault(TRUE);
117 GroupButtonsLayout->addWidget(buttonCancel, 0, 4);
119 TopLayout->addWidget(GroupButtons);
121 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
122 connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply()));
123 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
126 void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
128 myPrsList.append(thePrs);
130 thePrs->GetOffset(aOffs.myOffset);
131 myOldOffsets.append(aOffs);
132 if (myPrsList.count() == 1) {
133 setOffset(aOffs.myOffset);
134 } else if (myPrsList.count() == 2) {
136 aOffset[0] = aOffset[1] = aOffset[2] = 0;
141 void VisuGUI_OffsetDlg::setOffset (const float* theOffset)
143 myDxEdt->setValue(theOffset[0]);
144 myDyEdt->setValue(theOffset[1]);
145 myDzEdt->setValue(theOffset[2]);
148 void VisuGUI_OffsetDlg::getOffset (float* theOffset) const
150 theOffset[0] = myDxEdt->value();
151 theOffset[1] = myDyEdt->value();
152 theOffset[2] = myDzEdt->value();
155 void VisuGUI_OffsetDlg::onReset()
157 myDxEdt->setValue(0);
158 myDyEdt->setValue(0);
159 myDzEdt->setValue(0);
162 bool VisuGUI_OffsetDlg::isToSave() const
165 return mySaveChk->isChecked();
170 void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, float* theOffset)
172 if (myPrsList.count() == 0) return;
174 if (isToSave()) thePrs->SetOffset(theOffset);
176 ViewManagerList aViewManagerList;
177 SalomeApp_Application* anApp = myModule->getApp();
178 anApp->viewManagers(aViewManagerList);
179 QPtrListIterator<SUIT_ViewManager> anVMIter (aViewManagerList);
180 for (; anVMIter.current(); ++anVMIter) {
181 SUIT_ViewManager* aViewManager = anVMIter.current();
182 QPtrVector<SUIT_ViewWindow> aViews = aViewManager->getViews();
183 for (int i = 0, iEnd = aViews.size(); i < iEnd; i++) {
184 if (SUIT_ViewWindow* aViewWindow = aViews.at(i)) {
185 if (SVTK_ViewWindow* vw = dynamic_cast<SVTK_ViewWindow*>(aViewWindow)) {
186 vw->onAdjustTrihedron();
188 if (VISU_Actor* anActor = VISU::GetActor(thePrs, vw)) {
189 anActor->SetPosition(theOffset);
190 vw->getRenderer()->ResetCameraClippingRange();
193 Handle(SALOME_InteractiveObject) anIO;
194 CORBA::Object_var anObject = VISU::GetSelectedObj(myModule, &anIO);
195 if (!CORBA::is_nil(anObject))
196 vw->highlight(anIO, 1);
204 void VisuGUI_OffsetDlg::accept()
208 for (int i = 0; i < myPrsList.count(); i++) {
209 updateOffset(myPrsList.at(i), aOffset);
214 void VisuGUI_OffsetDlg::reject()
216 for (int i = 0; i < myPrsList.count(); i++) {
217 updateOffset(myPrsList.at(i), myOldOffsets[i].myOffset);
222 void VisuGUI_OffsetDlg::onApply()
226 for (int i = 0; i < myPrsList.count(); i++) {
227 updateOffset(myPrsList.at(i), aOffset);