]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_OffsetDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_OffsetDlg.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20
21 #include "VisuGUI_OffsetDlg.h"
22
23 #include "VisuGUI.h"
24 #include "VisuGUI_Tools.h"
25
26 #include "VISU_ViewManager_i.hh"
27 #include "VISU_Actor.h"
28
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"
37
38 #include "QtxDblSpinBox.h"
39
40 // VTK Includes
41 #include "vtkRenderer.h"
42
43 // QT Includes
44 #include <qhbox.h>
45 #include <qlabel.h>
46 #include <qlayout.h>
47 #include <qcheckbox.h>
48 #include <qgroupbox.h>
49 #include <qpushbutton.h>
50
51
52 #define  MAXVAL 1e10
53
54
55 VisuGUI_OffsetDlg::VisuGUI_OffsetDlg (VisuGUI* theModule)
56 : QDialog(VISU::GetDesktop(theModule), 0, false, WStyle_Customize |
57           WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu | WDestructiveClose),
58 myModule(theModule)
59 {
60   myPrsList.setAutoDelete(false);
61
62   setName("VisuGUI_OffsetDlg");
63   setCaption(tr("TIT_OFFSETDLG"));
64   setSizeGripEnabled(TRUE);
65
66   QVBoxLayout* TopLayout = new QVBoxLayout (this);
67   TopLayout->setSpacing(6);
68   TopLayout->setMargin(11);
69
70   QHBox* anOffsetsPane = new QHBox (this);
71   anOffsetsPane->setSpacing(6);
72
73   new QLabel ("dX:", anOffsetsPane);
74   myDxEdt = new QtxDblSpinBox (anOffsetsPane, "myDxEdt");
75   myDxEdt->setRange(-MAXVAL, MAXVAL);
76
77   new QLabel("dY:", anOffsetsPane);
78   myDyEdt = new QtxDblSpinBox (anOffsetsPane, "myDyEdt");
79   myDyEdt->setRange(-MAXVAL, MAXVAL);
80
81   new QLabel("dZ:", anOffsetsPane);
82   myDzEdt = new QtxDblSpinBox (anOffsetsPane, "myDzEdt");
83   myDzEdt->setRange(-MAXVAL, MAXVAL);
84
85   QPushButton* aResetBtn = new QPushButton(tr("BTN_RESET"), anOffsetsPane);
86   connect(aResetBtn, SIGNAL(clicked()), this, SLOT(onReset()));
87
88   TopLayout->addWidget(anOffsetsPane);
89
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);
94   } else {
95     mySaveChk = 0;
96   }
97
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);
107
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);
113
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);
118
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);  
123
124   QPushButton* buttonHelp = new QPushButton(tr("&Help") , GroupButtons, "buttonHelp");
125   buttonHelp->setAutoDefault(TRUE);
126   GroupButtonsLayout->addWidget(buttonHelp, 0, 6);
127
128   TopLayout->addWidget(GroupButtons);
129
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()));
134 }
135
136 void VisuGUI_OffsetDlg::addPresentation (VISU::Prs3d_i* thePrs)
137 {
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) {
146     OffsetStruct anOffs;
147     setOffset(anOffs.myOffset);
148   }
149 }
150
151 void VisuGUI_OffsetDlg::setOffset (const vtkFloatingPointType* theOffset)
152 {
153   myDxEdt->setValue(theOffset[0]);
154   myDyEdt->setValue(theOffset[1]);
155   myDzEdt->setValue(theOffset[2]);
156 }
157
158 void VisuGUI_OffsetDlg::getOffset (vtkFloatingPointType* theOffset) const
159 {
160   theOffset[0] = myDxEdt->value();
161   theOffset[1] = myDyEdt->value();
162   theOffset[2] = myDzEdt->value();
163 }
164
165 void VisuGUI_OffsetDlg::onReset()
166 {
167   myDxEdt->setValue(0);
168   myDyEdt->setValue(0);
169   myDzEdt->setValue(0);
170 }
171
172 bool VisuGUI_OffsetDlg::isToSave() const
173 {
174   if (mySaveChk)
175     return mySaveChk->isChecked();
176   else
177     return false;
178 }
179
180 void VisuGUI_OffsetDlg::updateOffset (VISU::Prs3d_i* thePrs, vtkFloatingPointType* theOffset)
181 {
182   if (myPrsList.count() == 0) 
183     return;
184
185   if (isToSave()) 
186     thePrs->SetOffset(theOffset[0],theOffset[1],theOffset[2]);
187
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();
199
200           if (VISU_Actor* anActor = VISU::FindActor(vw, thePrs)) {
201             anActor->SetPosition(theOffset);
202             vw->highlight(thePrs->GetIO(), 1);
203             vw->getRenderer()->ResetCameraClippingRange();
204             vw->Repaint();
205           }
206         }
207       }
208     }
209   }
210 }
211
212 void VisuGUI_OffsetDlg::accept()
213 {
214   vtkFloatingPointType anOffset[3];
215   getOffset(anOffset);
216   for (int i = 0; i < myPrsList.count(); i++) {
217     updateOffset(myPrsList.at(i), anOffset);
218   }
219   QDialog::accept();
220 }
221
222 void VisuGUI_OffsetDlg::reject()
223 {
224   for (int i = 0; i < myPrsList.count(); i++) {
225     updateOffset(myPrsList.at(i), myOldOffsets[i].myOffset);
226   }
227   QDialog::reject();
228 }
229
230 void VisuGUI_OffsetDlg::onApply()
231 {
232   vtkFloatingPointType anOffset[3];
233   getOffset(anOffset);
234   for (int i = 0; i < myPrsList.count(); i++) {
235     updateOffset(myPrsList.at(i), anOffset);
236   }
237 }
238
239 void VisuGUI_OffsetDlg::onHelp()
240 {
241   QString aHelpFileName = "translate_presentation_page.html";
242   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
243   if (app)
244     app->onHelpContextModule(myModule ? app->moduleName(myModule->moduleName()) : QString(""), aHelpFileName);
245   else {
246     QString platform;
247 #ifdef WIN32
248     platform = "winapplication";
249 #else
250     platform = "application";
251 #endif
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"));
256   }
257 }
258
259 void VisuGUI_OffsetDlg::keyPressEvent( QKeyEvent* e )
260 {
261   QDialog::keyPressEvent( e );
262   if ( e->isAccepted() )
263     return;
264
265   if ( e->key() == Key_F1 )
266     {
267       e->accept();
268       onHelp();
269     }
270 }