1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 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
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 "VISU_ColoredPrs3dFactory.hh"
35 #include "VISU_DeformedShape_i.hh"
36 #include "VisuGUI_ViewTools.h"
37 #include "VISU_Gen_i.hh"
38 #include "VISU_Result_i.hh"
39 #include "VisuGUI_Prs3dTools.h"
40 #include "SVTK_ViewWindow.h"
41 #include "SalomeApp_Module.h"
42 #include "LightApp_Application.h"
43 #include "SUIT_Desktop.h"
44 #include "SUIT_Session.h"
45 #include "SUIT_MessageBox.h"
46 #include "SUIT_ResourceMgr.h"
49 #include <qtabwidget.h>
56 VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule)
57 : VisuGUI_ScalarBarBaseDlg(theModule, true)
59 setCaption(tr("DLG_TITLE"));
60 setSizeGripEnabled(TRUE);
64 QVBoxLayout* TopLayout = new QVBoxLayout (this);
65 TopLayout->setSpacing(6);
66 TopLayout->setMargin(11);
68 myTabBox = new QTabWidget (this);
70 // Deformed shape pane
71 QVBox* aBox = new QVBox (this);
73 QFrame* TopGroup = new QFrame (aBox, "TopGroup");
74 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
75 TopGroup->setLineWidth(1);
76 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
77 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
78 TopGroupLayout->setSpacing(6);
79 TopGroupLayout->setMargin(11);
82 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel");
83 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
85 ScalFact = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, TopGroup);
86 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
87 ScalFact->setPrecision(38);
88 ScalFact->setValue(0.1);
89 TopGroupLayout->addWidget(ScalFact, 0, 1);
92 UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING"), TopGroup, "UseMagn");
93 UseMagn->setChecked(true);
94 TopGroupLayout->addMultiCellWidget(UseMagn, 1, 1, 0, 1);
96 myTabBox->addTab(aBox, tr("DEFORMED_SHAPE_TAB"));
99 myInputPane = new VisuGUI_InputPane(VISU::TDEFORMEDSHAPE, theModule, this);
101 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
102 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
105 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
106 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
107 GroupButtons->setColumnLayout(0, Qt::Vertical);
108 GroupButtons->layout()->setSpacing(0);
109 GroupButtons->layout()->setMargin(0);
110 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
111 GroupButtonsLayout->setAlignment(Qt::AlignTop);
112 GroupButtonsLayout->setSpacing(6);
113 GroupButtonsLayout->setMargin(11);
115 QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk");
116 buttonOk->setAutoDefault(TRUE);
117 buttonOk->setDefault(TRUE);
118 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
120 QPushButton* buttonApply = new QPushButton (tr("&Apply"), GroupButtons, "buttonApply");
121 buttonApply->setAutoDefault(TRUE);
122 buttonApply->setDefault(TRUE);
123 GroupButtonsLayout->addWidget(buttonApply, 0, 1);
125 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel");
126 buttonCancel->setAutoDefault(TRUE);
127 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
129 QPushButton* buttonHelp = new QPushButton (tr("&Help") , GroupButtons, "buttonHelp");
130 buttonHelp->setAutoDefault(TRUE);
131 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
133 // Add Tab box and Buttons to the top layout
134 TopLayout->addWidget(myTabBox);
135 TopLayout->addWidget(GroupButtons);
137 // signals and slots connections
138 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
139 connect(buttonApply, SIGNAL(clicked()), this, SLOT(onApply()));
140 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
141 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
144 VisuGUI_DeformedShapeDlg::~VisuGUI_DeformedShapeDlg()
147 void VisuGUI_DeformedShapeDlg::initFromPrsObject (VISU::ColoredPrs3d_i* thePrs,
151 myPrsCopy = VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
153 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
155 setFactor(myPrsCopy->GetScale());
156 UseMagn->setChecked(myPrsCopy->IsColored());
161 myInputPane->initFromPrsObject(myPrsCopy);
162 myTabBox->setCurrentPage(0);
165 int VisuGUI_DeformedShapeDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
170 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
171 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
173 myPrsCopy->SetScale(getFactor());
174 myPrsCopy->ShowColored(isColored());
176 VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Copy(myPrsCopy, thePrs);
181 void VisuGUI_DeformedShapeDlg::updatePrsCopy()
183 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
184 VisuGUI* aVisuGUI = dynamic_cast <VisuGUI*>(myModule);
185 if ( myPrsCopy->GetNumberOfActors() == 0 ) {
186 PublishInView(aVisuGUI, myPrsCopy, aViewWindow);
187 aViewWindow->onFitAll();
188 int aPos = VISU::GetFreePositionOfDefaultScalarBar(aVisuGUI, aViewWindow);
189 VISU::AddScalarBarPosition(aVisuGUI, aViewWindow, myPrsCopy, aPos);
192 myPrsCopy->UpdateActors();
193 } catch (std::runtime_error& exc) {
194 myPrsCopy->RemoveActors();
197 SUIT_MessageBox::warn1
198 (VISU::GetDesktop(myModule), QObject::tr("WRN_VISU"),
199 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
200 QObject::tr("BUT_OK"));
202 aViewWindow->Repaint();
206 void VisuGUI_DeformedShapeDlg::accept()
208 VisuGUI_ScalarBarBaseDlg::done( isValid() );
211 void VisuGUI_DeformedShapeDlg::reject()
214 VisuGUI_ScalarBarBaseDlg::done( 1 );
216 VisuGUI_ScalarBarBaseDlg::reject();
219 QString VisuGUI_DeformedShapeDlg::GetContextHelpFilePath()
221 return "deformed_shape_page.html";
224 bool VisuGUI_DeformedShapeDlg::onApply()
226 if ( storeToPrsObject( myPrsCopy ) )
235 ////////////////////////////////////////////////////////////////////////////////
237 ////////////////////////////////////////////////////////////////////////////////
239 void VisuGUI_DeformedShapeDlg::CreatePrs3d(VisuGUI* theModule)
241 _PTR(SObject) aTimeStamp;
242 Handle(SALOME_InteractiveObject) anIO;
243 VISU::ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
245 if (VISU::CheckTimeStamp(theModule, aTimeStamp, anIO, aPublishInStudyMode))
247 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aTimeStamp);
248 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
249 if ( aType == VISU::TTIMESTAMP )
252 QString aMeshName = aRestoringMap["myMeshName"];
253 QString anEntity = aRestoringMap["myEntityId"];
254 QString aFieldName = aRestoringMap["myFieldName"];
255 QString aTimeStampId = aRestoringMap["myTimeStampId"];
257 typedef VISU::DeformedShape_i TPrs3d_i;
260 VISU::CreatePrs3dFromFactory<TPrs3d_i>(theModule,
263 (VISU::Entity)anEntity.toInt(),
265 aTimeStampId.toInt(),
266 aPublishInStudyMode);
268 VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule);
269 aDlg->initFromPrsObject(aPrs3d, true);
270 aDlg->UseMagn->setChecked(true);
271 VisuGUI_DialogRunner r(aDlg);
272 int dlgResult = r.run( false );
274 if ( dlgResult == 0 )
275 aPrs3d->RemoveFromStudy();
277 aDlg->storeToPrsObject( aPrs3d );
278 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>();
279 PublishInView(theModule, aPrs3d, aViewWindow);
280 aViewWindow->onFitAll();
281 int aPos = VISU::GetFreePositionOfDefaultScalarBar(theModule, aViewWindow);
282 VISU::AddScalarBarPosition(theModule, aViewWindow, aPrs3d, aPos);
285 VISU::UpdateObjBrowser(theModule, true, aTimeStamp);
291 ////////////////////////////////////////////////////////////////////////////////
293 void VisuGUI_DeformedShapeDlg::EditPrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs3d, Handle(SALOME_InteractiveObject)& theIO)
295 typedef VISU::DeformedShape_i TPrs3d_i;
297 if (TPrs3d_i* aPrs3d = dynamic_cast<TPrs3d_i*>(thePrs3d)) {
298 VisuGUI_DeformedShapeDlg* aDlg = new VisuGUI_DeformedShapeDlg (theModule);
299 aDlg->initFromPrsObject(aPrs3d, true);
300 aDlg->updatePrsCopy();
302 //Hide thePrs3d from Viewer
303 SVTK_ViewWindow* aViewWindow = VISU::GetActiveViewWindow<SVTK_ViewWindow>(theModule);
304 if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
305 if (anActor->GetVisibility())
306 anActor->VisibilityOff();
308 VisuGUI_DialogRunner r(aDlg);
309 int dlgResult = r.run( false );
311 if ( dlgResult != 0 )
312 aDlg->storeToPrsObject( aPrs3d );
315 thePrs3d->UpdateActors();
317 catch (std::runtime_error& exc) {
318 thePrs3d->RemoveActors();
321 SUIT_MessageBox::warn1
322 (VISU::GetDesktop(theModule), QObject::tr("WRN_VISU"),
323 QObject::tr("ERR_CANT_BUILD_PRESENTATION") + ": " + QObject::tr(exc.what()),
324 QObject::tr("BUT_OK"));
327 if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
328 if (!anActor->GetVisibility())
329 anActor->VisibilityOn();
335 ///////////////////////////////////////////////////////////////////////////////////
336 int VisuGUI_DeformedShapeDlg::isValid()
338 if(myInputPane->check() && GetScalarPane()->check())