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 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_MagnitudeDlg.cxx
24 // Author : Laurent CORNABE & Hubert ROLLAND
28 #include "VisuGUI_DeformedShapeDlg.h"
30 #include "VisuGUI_Tools.h"
31 #include "VisuGUI_InputPane.h"
33 #include "VISU_ColoredPrs3dFactory.hh"
34 #include "VISU_DeformedShape_i.hh"
35 #include "VisuGUI_ViewTools.h"
36 #include "VISU_Gen_i.hh"
37 #include "VISU_Result_i.hh"
38 #include "VisuGUI_Prs3dTools.h"
39 #include "SVTK_ViewWindow.h"
40 #include "SalomeApp_Module.h"
41 #include "LightApp_Application.h"
42 #include "SUIT_Desktop.h"
43 #include "SUIT_Session.h"
44 #include "SUIT_MessageBox.h"
45 #include "SUIT_ResourceMgr.h"
51 #include <QPushButton>
63 VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule)
64 : VisuGUI_ScalarBarBaseDlg(theModule)
66 setWindowTitle(tr("DLG_TITLE"));
67 setSizeGripEnabled(TRUE);
71 QVBoxLayout* TopLayout = new QVBoxLayout (this);
72 TopLayout->setSpacing(6);
73 TopLayout->setMargin(11);
75 myTabBox = new QTabWidget (this);
77 // Deformed shape pane
78 QWidget* aBox = new QWidget (this);
79 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
80 aVBLay->setMargin(11);
81 QFrame* TopGroup = new QFrame ( aBox );
82 aVBLay->addWidget( TopGroup );
83 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
84 TopGroup->setLineWidth(1);
85 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
86 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
87 TopGroupLayout->setSpacing(6);
88 TopGroupLayout->setMargin(11);
91 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup );
92 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
94 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
95 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
97 ScalFact = new QtxDoubleSpinBox (0, 1.0E+38, 0.1, aPrecision*(-1), 38, TopGroup);
98 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
99 ScalFact->setValue(0.1);
100 TopGroupLayout->addWidget(ScalFact, 0, 1);
102 // Magnitude coloring
103 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING"), TopGroup);
104 UseMagn->setChecked(true);
105 TopGroupLayout->addWidget(UseMagn, 1, 0, 1, 2);
107 myTabBox->addTab(aBox, tr("DEFORMED_SHAPE_TAB"));
110 myInputPane = new VisuGUI_InputPane(VISU::TDEFORMEDSHAPE, theModule, this);
112 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
113 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
116 QGroupBox* GroupButtons = new QGroupBox (this);
117 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
118 //oupButtons->setColumnLayout(0, Qt::Vertical);
119 //GroupButtons->layout()->setSpacing(0);
120 //GroupButtons->layout()->setMargin(0);
121 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
122 GroupButtonsLayout->setAlignment(Qt::AlignTop);
123 GroupButtonsLayout->setSpacing(6);
124 GroupButtonsLayout->setMargin(11);
126 QPushButton* buttonOk = new QPushButton (tr("A&pply and Close"), GroupButtons);
127 buttonOk->setAutoDefault(TRUE);
128 buttonOk->setDefault(TRUE);
129 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
131 QPushButton* buttonApply = new QPushButton (tr("&Apply"), GroupButtons);
132 buttonApply->setAutoDefault(TRUE);
133 buttonApply->setDefault(TRUE);
134 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
136 QPushButton* buttonCancel = new QPushButton (tr("BUT_CANCEL") , GroupButtons);
137 buttonCancel->setAutoDefault(TRUE);
138 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
140 QPushButton* buttonHelp = new QPushButton (tr("BUT_HELP") , GroupButtons);
141 buttonHelp->setAutoDefault(TRUE);
142 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
144 // Add Tab box and Buttons to the top layout
145 TopLayout->addWidget(myTabBox);
146 TopLayout->addWidget(GroupButtons);
148 // signals and slots connections
149 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
150 connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply()));
151 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
152 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
155 VisuGUI_DeformedShapeDlg::~VisuGUI_DeformedShapeDlg()
158 void VisuGUI_DeformedShapeDlg::initFromPrsObject (VISU::ColoredPrs3d_i* thePrs,
162 myPrsCopy = VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
164 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
165 setFactor(myPrsCopy->GetScale());
166 UseMagn->setChecked(myPrsCopy->IsColored());
171 myInputPane->initFromPrsObject(myPrsCopy);
172 myTabBox->setCurrentIndex(0);
175 void VisuGUI_DeformedShapeDlg::setFactor(double theFactor)
178 if (fabs(theFactor) > numeric_limits<double>::epsilon()) {
179 int degree = int(log10(fabs(theFactor))) - 1;
180 if (fabs(theFactor) < 1) {
181 // as logarithm value is negative in this case
182 // and it is truncated to the bigger integer
185 step = pow(10., double(degree));
188 ScalFact->setSingleStep(step);
189 ScalFact->setValue(theFactor);
192 int VisuGUI_DeformedShapeDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
197 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
198 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
200 myPrsCopy->SetScale(getFactor());
201 myPrsCopy->ShowColored(isColored());
203 VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Copy(myPrsCopy, thePrs);
208 void VisuGUI_DeformedShapeDlg::updatePrsCopy()
210 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
211 VisuGUI* aVisuGUI = dynamic_cast <VisuGUI*>(myModule);
212 if ( myPrsCopy->GetNumberOfActors() == 0 ) {
213 PublishInView(aVisuGUI, myPrsCopy, aViewWindow);
214 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false))
215 aViewWindow->onFitAll();
216 int aPos = VISU::GetFreePositionOfDefaultScalarBar(aVisuGUI, aViewWindow);
217 VISU::AddScalarBarPosition(aVisuGUI, aViewWindow, myPrsCopy, aPos);
220 myPrsCopy->UpdateActors();
221 } catch (std::runtime_error& exc) {
222 myPrsCopy->RemoveActors();
225 SUIT_MessageBox::warning(VISU::GetDesktop(myModule),
227 tr("ERR_CANT_BUILD_PRESENTATION") + ": " + exc.what());
229 aViewWindow->Repaint();
233 void VisuGUI_DeformedShapeDlg::accept()
235 VisuGUI_ScalarBarBaseDlg::done( isValid() );
238 void VisuGUI_DeformedShapeDlg::reject()
241 VisuGUI_ScalarBarBaseDlg::done( 1 );
243 VisuGUI_ScalarBarBaseDlg::reject();
246 QString VisuGUI_DeformedShapeDlg::GetContextHelpFilePath()
248 return "deformed_shape_page.html";
251 bool VisuGUI_DeformedShapeDlg::onApply()
253 if ( storeToPrsObject( myPrsCopy ) )
262 ////////////////////////////////////////////////////////////////////////////////
264 ////////////////////////////////////////////////////////////////////////////////
266 VISU::Prs3d_i* VisuGUI_DeformedShapeDlg::CreatePrs3d(VisuGUI* theModule)
268 VISU::DeformedShape_i* aPrs3d = NULL;
269 _PTR(SObject) aTimeStamp;
270 Handle(SALOME_InteractiveObject) anIO;
271 VISU::ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
273 if (VISU::CheckTimeStamp(theModule, aTimeStamp, anIO, aPublishInStudyMode))
275 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aTimeStamp);
276 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
277 if ( aType == VISU::TTIMESTAMP )
280 QString aMeshName = aRestoringMap["myMeshName"];
281 QString anEntity = aRestoringMap["myEntityId"];
282 QString aFieldName = aRestoringMap["myFieldName"];
283 QString aTimeStampId = aRestoringMap["myTimeStampId"];
285 //typedef VISU::DeformedShape_i TPrs3d_i;
288 VISU::CreatePrs3dFromFactory<VISU::DeformedShape_i>(theModule,
290 aMeshName.toLatin1().data(),
291 (VISU::Entity)anEntity.toInt(),
292 aFieldName.toLatin1().data(),
293 aTimeStampId.toInt(),
294 aPublishInStudyMode);
297 VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule);
298 aDlg->initFromPrsObject(aPrs3d, true);
299 aDlg->UseMagn->setChecked(true);
300 VisuGUI_DialogRunner r(aDlg);
301 int dlgResult = r.run( false );
303 if ( dlgResult == 0 )
304 DeletePrs3d(theModule,aPrs3d);
306 aDlg->storeToPrsObject( aPrs3d );
307 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
308 PublishInView(theModule, aPrs3d, aViewWindow);
309 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false))
310 aViewWindow->onFitAll();
311 int aPos = VISU::GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
312 VISU::AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
315 VISU::UpdateObjBrowser(theModule, true, aTimeStamp);
323 ////////////////////////////////////////////////////////////////////////////////
325 void VisuGUI_DeformedShapeDlg::EditPrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs3d, Handle(SALOME_InteractiveObject)& theIO)
327 typedef VISU::DeformedShape_i TPrs3d_i;
329 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
330 VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule);
331 aDlg->initFromPrsObject(aPrs3d, true);
332 aDlg->updatePrsCopy();
334 //Hide thePrs3d from Viewer
335 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule);
337 if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
338 if (anActor->GetVisibility())
339 anActor->VisibilityOff();
341 VisuGUI_DialogRunner r(aDlg);
342 int dlgResult = r.run( false );
344 if ( dlgResult != 0 )
345 aDlg->storeToPrsObject( aPrs3d );
348 thePrs3d->UpdateActors();
350 catch (std::runtime_error& exc) {
351 thePrs3d->RemoveActors();
354 SUIT_MessageBox::warning
355 (VISU::GetDesktop(theModule), QObject::tr("WRN_VISU"),
356 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()));
360 if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
361 if (!anActor->GetVisibility())
362 anActor->VisibilityOn();
368 ///////////////////////////////////////////////////////////////////////////////////
369 int VisuGUI_DeformedShapeDlg::isValid()
371 if(myInputPane->check() && GetScalarPane()->check())