]> SALOME platform Git repositories - modules/visu.git/blob - src/VISUGUI/VisuGUI_DeformedShapeDlg.cxx
Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/visu.git] / src / VISUGUI / VisuGUI_DeformedShapeDlg.cxx
1 //  VISU VISUGUI : GUI of VISU component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : VisuGUI_MagnitudeDlg.cxx
25 //  Author : Laurent CORNABE & Hubert ROLLAND
26 //  Module : VISU
27 //  $Header$
28
29 #include "VisuGUI_DeformedShapeDlg.h"
30
31 #include "VisuGUI_Tools.h"
32 #include "VisuGUI_InputPane.h"
33 #include "VisuGUI.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"
47
48 #include <qlayout.h>
49 #include <qtabwidget.h>
50
51 using namespace std;
52
53 /*!
54  * Constructor
55  */
56 VisuGUI_DeformedShapeDlg::VisuGUI_DeformedShapeDlg (SalomeApp_Module* theModule)
57   : VisuGUI_ScalarBarBaseDlg(theModule, true)
58 {
59   setCaption(tr("DLG_TITLE"));
60   setSizeGripEnabled(TRUE);
61   myModule = theModule;
62   isApplyed = false;
63
64   QVBoxLayout* TopLayout = new QVBoxLayout (this);
65   TopLayout->setSpacing(6);
66   TopLayout->setMargin(11);
67
68   myTabBox = new QTabWidget (this);
69
70   // Deformed shape pane
71   QVBox* aBox = new QVBox (this);
72   aBox->setMargin(11);
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);
80
81   //   Scale factor
82   QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel");
83   TopGroupLayout->addWidget(ScaleLabel, 0, 0);
84
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);
90
91   //   Magnitude coloring
92   UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING"), TopGroup, "UseMagn");
93   UseMagn->setChecked(true);
94   TopGroupLayout->addMultiCellWidget(UseMagn, 1, 1, 0, 1);
95
96   myTabBox->addTab(aBox, tr("DEFORMED_SHAPE_TAB"));
97
98   // Scalar bar pane
99   myInputPane = new VisuGUI_InputPane(VISU::TDEFORMEDSHAPE, theModule, this);
100
101   myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
102   myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
103
104   // Buttons
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);
114
115   QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk");
116   buttonOk->setAutoDefault(TRUE);
117   buttonOk->setDefault(TRUE);
118   GroupButtonsLayout->addWidget(buttonOk, 0, 0);
119
120   QPushButton* buttonApply = new QPushButton (tr("&Apply"), GroupButtons, "buttonApply");
121   buttonApply->setAutoDefault(TRUE);
122   buttonApply->setDefault(TRUE);
123   GroupButtonsLayout->addWidget(buttonApply, 0, 1);
124
125   QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel");
126   buttonCancel->setAutoDefault(TRUE);
127   GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
128
129   QPushButton* buttonHelp = new QPushButton (tr("&Help") , GroupButtons, "buttonHelp");
130   buttonHelp->setAutoDefault(TRUE);
131   GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
132
133   // Add Tab box and Buttons to the top layout
134   TopLayout->addWidget(myTabBox);
135   TopLayout->addWidget(GroupButtons);
136
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()));
142 }
143
144 VisuGUI_DeformedShapeDlg::~VisuGUI_DeformedShapeDlg()
145 {}
146
147 void VisuGUI_DeformedShapeDlg::initFromPrsObject (VISU::ColoredPrs3d_i* thePrs,
148                                                   bool theInit)
149 {
150   if( theInit )
151     myPrsCopy = VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
152
153   VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
154
155   setFactor(myPrsCopy->GetScale());
156   UseMagn->setChecked(myPrsCopy->IsColored());
157
158   if (!theInit)
159     return;
160
161   myInputPane->initFromPrsObject(myPrsCopy);
162   myTabBox->setCurrentPage(0);
163 }
164
165 int VisuGUI_DeformedShapeDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
166 {
167   if( !isValid() )
168     return 0;
169
170   int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
171   anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
172
173   myPrsCopy->SetScale(getFactor());
174   myPrsCopy->ShowColored(isColored());
175
176   VISU::TSameAsFactory<VISU::TDEFORMEDSHAPE>().Copy(myPrsCopy, thePrs);
177
178   return anIsOk;
179 }
180
181 void VisuGUI_DeformedShapeDlg::updatePrsCopy()
182 {
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);
190     } else {
191     try {
192       myPrsCopy->UpdateActors();
193     } catch (std::runtime_error& exc) {
194       myPrsCopy->RemoveActors();
195       
196       INFOS(exc.what());
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"));
201     }
202     aViewWindow->Repaint();
203   }
204 }
205
206 void VisuGUI_DeformedShapeDlg::accept()
207 {
208    VisuGUI_ScalarBarBaseDlg::done( isValid() );
209 }
210
211 void VisuGUI_DeformedShapeDlg::reject()
212 {
213   if (isApplyed)
214     VisuGUI_ScalarBarBaseDlg::done( 1 );
215   else
216     VisuGUI_ScalarBarBaseDlg::reject();
217 }
218
219 QString VisuGUI_DeformedShapeDlg::GetContextHelpFilePath()
220 {
221   return "deformed_shape_page.html";
222 }
223
224 bool VisuGUI_DeformedShapeDlg::onApply()
225 {
226   if ( storeToPrsObject( myPrsCopy ) ) 
227   {
228     updatePrsCopy();
229     isApplyed = true;
230     return true;
231   }
232   return false;
233 }
234
235 ////////////////////////////////////////////////////////////////////////////////
236 //  Create and Edit
237 ////////////////////////////////////////////////////////////////////////////////
238
239 void VisuGUI_DeformedShapeDlg::CreatePrs3d(VisuGUI* theModule)
240 {
241   _PTR(SObject) aTimeStamp;
242   Handle(SALOME_InteractiveObject) anIO;
243   VISU::ColoredPrs3d_i::EPublishInStudyMode aPublishInStudyMode;
244
245   if (VISU::CheckTimeStamp(theModule, aTimeStamp, anIO, aPublishInStudyMode))
246     {
247       VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aTimeStamp);
248       VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
249       if ( aType == VISU::TTIMESTAMP )
250         {
251   
252           QString aMeshName = aRestoringMap["myMeshName"];
253           QString anEntity = aRestoringMap["myEntityId"];
254           QString aFieldName = aRestoringMap["myFieldName"];
255           QString aTimeStampId = aRestoringMap["myTimeStampId"];
256           
257           typedef VISU::DeformedShape_i TPrs3d_i; 
258           
259           TPrs3d_i* aPrs3d =
260             VISU::CreatePrs3dFromFactory<TPrs3d_i>(theModule,
261                                                    aTimeStamp,
262                                                    aMeshName.latin1(),
263                                                    (VISU::Entity)anEntity.toInt(),
264                                                    aFieldName.latin1(),
265                                                    aTimeStampId.toInt(),
266                                                    aPublishInStudyMode);
267           
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 );
273
274           if ( dlgResult == 0 )
275             aPrs3d->RemoveFromStudy();
276           else {
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);
283           }
284           
285           VISU::UpdateObjBrowser(theModule, true, aTimeStamp);
286           delete aDlg;
287         }
288     }
289 }
290
291 ////////////////////////////////////////////////////////////////////////////////
292
293 void VisuGUI_DeformedShapeDlg::EditPrs3d(VisuGUI* theModule, VISU::Prs3d_i* thePrs3d, Handle(SALOME_InteractiveObject)& theIO)
294 {
295   typedef VISU::DeformedShape_i TPrs3d_i;
296   
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();
301
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();
307
308     VisuGUI_DialogRunner r(aDlg);
309     int dlgResult = r.run( false );
310    
311     if ( dlgResult != 0 )
312       aDlg->storeToPrsObject( aPrs3d );
313       
314     try {
315       thePrs3d->UpdateActors();
316     }
317     catch (std::runtime_error& exc) {
318       thePrs3d->RemoveActors();
319       
320       INFOS(exc.what());
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"));
325     }
326
327     if (VISU_Actor* anActor = FindActor(aViewWindow, thePrs3d))
328       if (!anActor->GetVisibility())
329         anActor->VisibilityOn();
330     
331     delete aDlg;    
332   }
333 }
334
335 ///////////////////////////////////////////////////////////////////////////////////
336 int VisuGUI_DeformedShapeDlg::isValid()
337 {
338   if(myInputPane->check() && GetScalarPane()->check())
339     return 1; 
340   else
341     return 0;
342 }