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 // VISU VISUGUI : GUI of VISU component
24 // File : VisuGUI_MagnitudeDlg.cxx
25 // Author : Laurent CORNABE & Hubert ROLLAND
29 #include "VisuGUI_DeformedShapeDlg.h"
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_InputPane.h"
34 #include "VisuGUI_Prs3dTools.h"
36 #include "VISU_ColoredPrs3dFactory.hh"
37 #include "VISU_DeformedShape_i.hh"
38 #include "VisuGUI_ViewTools.h"
39 #include "VISU_Gen_i.hh"
40 #include "VISU_Result_i.hh"
42 #include "SVTK_ViewWindow.h"
43 #include "SalomeApp_Module.h"
44 #include <SalomeApp_DoubleSpinBox.h>
45 #include "LightApp_Application.h"
46 #include "SUIT_Desktop.h"
47 #include "SUIT_Session.h"
48 #include "SUIT_MessageBox.h"
49 #include "SUIT_ResourceMgr.h"
55 #include <QPushButton>
67 VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule)
68 : VisuGUI_ScalarBarBaseDlg(theModule)
70 setWindowTitle(tr("DLG_TITLE"));
71 setSizeGripEnabled(TRUE);
75 QVBoxLayout* TopLayout = new QVBoxLayout (this);
76 TopLayout->setSpacing(6);
77 TopLayout->setMargin(11);
79 myTabBox = new QTabWidget (this);
81 // Deformed shape pane
82 QWidget* aBox = new QWidget (this);
83 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
84 aVBLay->setMargin(11);
85 QFrame* TopGroup = new QFrame ( aBox );
86 aVBLay->addWidget( TopGroup );
87 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
88 TopGroup->setLineWidth(1);
89 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
90 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
91 TopGroupLayout->setSpacing(6);
92 TopGroupLayout->setMargin(11);
95 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup );
96 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
98 ScalFact = new SalomeApp_DoubleSpinBox (TopGroup);
99 VISU::initSpinBox( ScalFact, 0., 1.0E+38, .1, "visual_data_precision" );
100 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
101 ScalFact->setValue(0.1);
102 TopGroupLayout->addWidget(ScalFact, 0, 1);
104 // Magnitude coloring
105 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING"), TopGroup);
106 UseMagn->setChecked(true);
107 TopGroupLayout->addWidget(UseMagn, 1, 0, 1, 2);
109 myTabBox->addTab(aBox, tr("DEFORMED_SHAPE_TAB"));
112 myInputPane = new VisuGUI_InputPane(VISU::TDEFORMEDSHAPE, theModule, this);
114 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
115 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
118 QGroupBox* GroupButtons = new QGroupBox (this);
119 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
120 //oupButtons->setColumnLayout(0, Qt::Vertical);
121 //GroupButtons->layout()->setSpacing(0);
122 //GroupButtons->layout()->setMargin(0);
123 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons);
124 GroupButtonsLayout->setAlignment(Qt::AlignTop);
125 GroupButtonsLayout->setSpacing(6);
126 GroupButtonsLayout->setMargin(11);
128 QPushButton* buttonOk = new QPushButton (tr("A&pply and Close"), GroupButtons);
129 buttonOk->setAutoDefault(TRUE);
130 buttonOk->setDefault(TRUE);
131 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
133 QPushButton* buttonApply = new QPushButton (tr("&Apply"), GroupButtons);
134 buttonApply->setAutoDefault(TRUE);
135 buttonApply->setDefault(TRUE);
136 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
138 QPushButton* buttonCancel = new QPushButton (tr("BUT_CANCEL") , GroupButtons);
139 buttonCancel->setAutoDefault(TRUE);
140 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
142 QPushButton* buttonHelp = new QPushButton (tr("BUT_HELP") , GroupButtons);
143 buttonHelp->setAutoDefault(TRUE);
144 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
146 // Add Tab box and Buttons to the top layout
147 TopLayout->addWidget(myTabBox);
148 TopLayout->addWidget(GroupButtons);
150 // signals and slots connections
151 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
152 connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply()));
153 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
154 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
157 VisuGUI_DeformedShapeDlg::~VisuGUI_DeformedShapeDlg()
160 void VisuGUI_DeformedShapeDlg::initFromPrsObject (VISU::ColoredPrs3d_i* thePrs,
164 myPrsCopy = VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
166 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
167 setFactor(myPrsCopy->GetScale());
168 UseMagn->setChecked(myPrsCopy->IsColored());
173 myInputPane->initFromPrsObject(myPrsCopy);
174 myTabBox->setCurrentIndex(0);
177 void VisuGUI_DeformedShapeDlg::setFactor(double theFactor)
180 if (fabs(theFactor) > numeric_limits<double>::epsilon()) {
181 int degree = int(log10(fabs(theFactor))) - 1;
182 if (fabs(theFactor) < 1) {
183 // as logarithm value is negative in this case
184 // and it is truncated to the bigger integer
187 step = pow(10., double(degree));
190 ScalFact->setSingleStep(step);
191 ScalFact->setValue(theFactor);
194 int VisuGUI_DeformedShapeDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
199 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
200 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
202 myPrsCopy->SetScale(getFactor());
203 myPrsCopy->ShowColored(isColored());
205 VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Copy(myPrsCopy, thePrs);
210 void VisuGUI_DeformedShapeDlg::updatePrsCopy( VISU::Prs3d_i* thePrs )
212 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
213 VisuGUI* aVisuGUI = dynamic_cast <VisuGUI*>(myModule);
214 if ( myPrsCopy->GetNumberOfActors() == 0 ) {
215 PublishInView(aVisuGUI, myPrsCopy, aViewWindow);
219 if( SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>( myModule ) ) {
220 VISU_Actor* anActorSource = VISU::FindActor( aViewWindow, thePrs );
221 VISU_Actor* anActorCopy = VISU::FindActor( aViewWindow, myPrsCopy );
222 if( anActorSource && anActorCopy )
223 anActorCopy->DeepCopy( anActorSource );
227 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false))
228 aViewWindow->onFitAll();
229 int aPos = VISU::GetFreePositionOfDefaultScalarBar(aVisuGUI, aViewWindow);
230 VISU::AddScalarBarPosition(aVisuGUI, aViewWindow, myPrsCopy, aPos);
233 myPrsCopy->UpdateActors();
234 } catch (std::runtime_error& exc) {
235 myPrsCopy->RemoveActors();
238 SUIT_MessageBox::warning(VISU::GetDesktop(myModule),
240 tr("ERR_CANT_BUILD_PRESENTATION") + ": " + exc.what());
242 aViewWindow->Repaint();
246 void VisuGUI_DeformedShapeDlg::accept()
248 VisuGUI_ScalarBarBaseDlg::done( isValid() );
251 void VisuGUI_DeformedShapeDlg::reject()
254 VisuGUI_ScalarBarBaseDlg::done( 1 );
256 VisuGUI_ScalarBarBaseDlg::reject();
259 QString VisuGUI_DeformedShapeDlg::GetContextHelpFilePath()
261 return "deformed_shape_page.html";
264 bool VisuGUI_DeformedShapeDlg::onApply()
266 if ( storeToPrsObject( myPrsCopy ) )
268 updatePrsCopy( myPrsCopy );
275 ////////////////////////////////////////////////////////////////////////////////
277 ////////////////////////////////////////////////////////////////////////////////
279 VISU::Prs3d_i* VisuGUI_DeformedShapeDlg::CreatePrs3d(VisuGUI* theModule)
281 VISU::DeformedShape_i* aPrs3d = NULL;
282 _PTR(SObject) aTimeStamp;
283 Handle(SALOME_InteractiveObject) anIO;
284 VISU::ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
286 if (VISU::CheckTimeStamp(theModule, aTimeStamp, anIO, aPublishInStudyMode))
288 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aTimeStamp);
289 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
290 if ( aType == VISU::TTIMESTAMP )
293 QString aMeshName = aRestoringMap["myMeshName"];
294 QString anEntity = aRestoringMap["myEntityId"];
295 QString aFieldName = aRestoringMap["myFieldName"];
296 QString aTimeStampId = aRestoringMap["myTimeStampId"];
298 //typedef VISU::DeformedShape_i TPrs3d_i;
301 VISU::CreatePrs3dFromFactory<VISU::DeformedShape_i>(theModule,
303 aMeshName.toLatin1().data(),
304 (VISU::Entity)anEntity.toInt(),
305 aFieldName.toLatin1().data(),
306 aTimeStampId.toInt(),
307 aPublishInStudyMode);
310 VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule);
311 aDlg->initFromPrsObject(aPrs3d, true);
312 aDlg->UseMagn->setChecked(true);
313 VisuGUI_DialogRunner r(aDlg);
314 int dlgResult = r.run( false );
316 if ( dlgResult == 0 )
317 DeletePrs3d(theModule,aPrs3d);
319 aDlg->storeToPrsObject( aPrs3d );
320 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
321 PublishInView(theModule, aPrs3d, aViewWindow);
322 if(VISU::GetResourceMgr()->booleanValue("VISU","automatic_fit_all",false))
323 aViewWindow->onFitAll();
324 int aPos = VISU::GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
325 VISU::AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
328 VISU::UpdateObjBrowser(theModule, true, aTimeStamp);
336 ////////////////////////////////////////////////////////////////////////////////
338 void VisuGUI_DeformedShapeDlg::EditPrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs3d, Handle(SALOME_InteractiveObject)& theIO)
340 typedef VISU::DeformedShape_i TPrs3d_i;
342 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
343 VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule);
344 aDlg->initFromPrsObject(aPrs3d, true);
345 aDlg->updatePrsCopy(thePrs3d);
347 //Hide thePrs3d from Viewer
348 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule);
350 if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
351 if (anActor->GetVisibility())
352 anActor->VisibilityOff();
354 VisuGUI_DialogRunner r(aDlg);
355 int dlgResult = r.run( true );
357 if ( dlgResult != 0 )
358 aDlg->storeToPrsObject( aPrs3d );
361 thePrs3d->UpdateActors();
363 catch (std::runtime_error& exc) {
364 thePrs3d->RemoveActors();
367 SUIT_MessageBox::warning
368 (VISU::GetDesktop(theModule), QObject::tr("WRN_VISU"),
369 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()));
373 if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
374 if (!anActor->GetVisibility())
375 anActor->VisibilityOn();
381 ///////////////////////////////////////////////////////////////////////////////////
382 int VisuGUI_DeformedShapeDlg::isValid()
384 if(myInputPane->check() && GetScalarPane()->check())