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_DeformedShapeAndScalarMapDlg.cxx
24 // Author : Eugeny Nikolaev
27 #include "VisuGUI_DeformedShapeAndScalarMapDlg.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_InputPane.h"
32 #include "VISU_Result_i.hh"
33 #include "VISU_DeformedShapeAndScalarMap_i.hh"
34 #include "VISU_ColoredPrs3dFactory.hh"
36 #include "VISU_ScalarMapPL.hxx"
37 #include "VISU_DeformedShapeAndScalarMapPL.hxx"
39 #include "VISU_Convertor.hxx"
41 #include <QtxDoubleSpinBox.h>
42 #include <SalomeApp_Module.h>
43 #include <LightApp_Application.h>
44 #include <LightApp_SelectionMgr.h>
45 #include <SUIT_Desktop.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SUIT_Session.h>
48 #include <SUIT_MessageBox.h>
50 #include <SALOME_ListIO.hxx>
52 #include <SALOMEDSClient_AttributeString.hxx>
53 #include <SALOMEDSClient_AttributeName.hxx>
55 #include <QVBoxLayout>
56 #include <QHBoxLayout>
57 #include <QGridLayout>
60 #include <QPushButton>
70 VisuGUI_DeformedShapeAndScalarMapDlg::VisuGUI_DeformedShapeAndScalarMapDlg (SalomeApp_Module* theModule)
71 : VisuGUI_ScalarBarBaseDlg(theModule),
73 myUpdateScalars(true),
76 setWindowTitle(tr("DLG_TITLE"));
77 setSizeGripEnabled(true);
79 QVBoxLayout* TopLayout = new QVBoxLayout (this);
80 TopLayout->setSpacing(6);
81 TopLayout->setMargin(11);
83 myTabBox = new QTabWidget (this);
85 // Scalar Map on Deformed shape pane
86 QWidget* aBox = new QWidget (this);
87 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
88 aVBLay->setMargin(11);
89 QFrame* TopGroup = new QFrame (aBox);
90 aVBLay->addWidget(TopGroup);
91 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
92 TopGroup->setLineWidth(1);
93 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
94 TopGroupLayout->setSpacing(6);
95 TopGroupLayout->setMargin(11);
98 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup);
99 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
101 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
102 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
104 ScalFact = new QtxDoubleSpinBox (0, 1.0E+38, 0.1, aPrecision*(-1), 32, TopGroup);
105 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
106 ScalFact->setValue(0.1);
107 TopGroupLayout->addWidget(ScalFact, 0, 1);
110 QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup);
111 myFieldsCombo = new QComboBox (TopGroup);
113 TopGroupLayout->addWidget(FieldLabel, 1, 0);
114 TopGroupLayout->addWidget(myFieldsCombo,1,1);
116 // TimeStamps combo box
117 QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup);
118 myTimeStampsCombo = new QComboBox (TopGroup);
120 TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
121 TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
122 TopGroupLayout->setRowStretch(3,5);
125 myTabBox->addTab(aBox, tr("DEFORMED_SHAPE_AND_SCALAR_MAP_TAB"));
128 myInputPane = new VisuGUI_InputPane(VISU::TDEFORMEDSHAPEANDSCALARMAP, theModule, this);
130 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
131 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
134 QGroupBox* GroupButtons = new QGroupBox (this);
135 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
136 GroupButtonsLayout->setSpacing(6);
137 GroupButtonsLayout->setMargin(11);
139 QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons);
140 buttonOk->setAutoDefault(true);
141 buttonOk->setDefault(true);
142 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons);
143 buttonCancel->setAutoDefault(true);
144 QPushButton* buttonHelp = new QPushButton (tr("&Help") , GroupButtons);
145 buttonHelp->setAutoDefault(true);
147 GroupButtonsLayout->addWidget(buttonOk);
148 GroupButtonsLayout->addSpacing(10);
149 GroupButtonsLayout->addStretch();
150 GroupButtonsLayout->addWidget(buttonCancel);
151 GroupButtonsLayout->addWidget(buttonHelp);
153 // Add Tab box and Buttons to the top layout
154 TopLayout->addWidget(myTabBox);
155 TopLayout->addWidget(GroupButtons);
157 // signals and slots connections
158 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
159 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
160 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
161 connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
162 connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
165 VisuGUI_DeformedShapeAndScalarMapDlg::~VisuGUI_DeformedShapeAndScalarMapDlg()
169 void VisuGUI_DeformedShapeAndScalarMapDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
173 myPrsCopy = VISU::TSameAsFactory<VISU::TDEFORMEDSHAPEANDSCALARMAP>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
174 setFactor(myPrsCopy->GetScale());
175 myTimeStampsCombo->setDisabled(myIsAnimation);
177 CORBA::String_var aFieldName(myPrsCopy->GetScalarFieldName());
178 QString aIteration = GetFloatValueOfTimeStamp(myPrsCopy->GetScalarEntity(),
180 myPrsCopy->GetScalarTimeStampNumber());
181 if (myEntity2Fields.size() == 0)
183 // find all fields and time stamps on it
184 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
185 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
186 SALOME_ListIO selected;
187 aSel->selectedObjects(selected);
188 if (selected.Extent() > 0) {
189 Handle(SALOME_InteractiveObject) aIO = selected.First();
190 if (aIO->hasEntry()) {
191 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
192 VISU::VISUType aType = VISU::Storable::SObject2Type( aSObject );
194 case VISU::TTIMESTAMP: {
195 aSObject = aSObject->GetFather();
196 aSObject = aSObject->GetFather();
200 _PTR(SObject) newSObject;
201 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
202 aSObject = aSObject->GetFather();
205 case VISU::TANIMATION: {
206 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
207 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
208 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
209 _PTR(SObject) newSObject;
210 if(aTmpChildSObj->ReferencedObject(newSObject)){
211 aSObject = newSObject;
212 aSObject->GetFather();
219 aSObject = aSObject->GetFather();
220 aSObject = aSObject->GetFather();
222 mySelectionObj = aSObject;
223 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
224 if (CORBA::is_nil(anObject)) {
225 mySelectionObj = mySelectionObj->GetFather();
230 if (mySelectionObj) {
231 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
233 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
234 _PTR(SObject) aChildSObj = aIter->Value();
235 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildSObj);
236 if (!aRestoringMap.empty()) {
237 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
238 if (aType == VISU::TTIMESTAMP) {
239 QString aMeshName = aRestoringMap["myMeshName"];
240 CORBA::String_var aName = myPrsCopy->GetMeshName();
241 if (aMeshName != aName.in())
243 QString aFieldName = aRestoringMap["myFieldName"];
244 QString aTimeIter = aRestoringMap["myTimeStampId"];
245 QString aEntity = aRestoringMap["myEntityId"];
246 VISU::Entity anEntity;
247 switch (aEntity.toInt()) {
248 case 0: anEntity = VISU::NODE; break;
249 case 1: anEntity = VISU::EDGE; break;
250 case 2: anEntity = VISU::FACE; break;
251 case 3: anEntity = VISU::CELL; break;
253 TFieldName2TimeStamps& aFieldName2TimeStamps = myEntity2Fields[anEntity];
254 TTimeStampNumber2Time& aTimeStampNumber2Time = aFieldName2TimeStamps[aFieldName];
255 aTimeStampNumber2Time[aTimeIter.toInt()] =
256 GetFloatValueOfTimeStamp(anEntity,
257 aFieldName.toLatin1().constData(),
265 int idx = myFieldsCombo->findText(aFieldName.in());
267 myFieldsCombo->setCurrentIndex(idx);
269 myFieldsCombo->addItem(aFieldName.in());
270 myFieldsCombo->setCurrentIndex(myFieldsCombo->count()-1);
272 AddAllTimes(myFieldsCombo->currentText());
273 idx = myTimeStampsCombo->findText(aIteration);
275 myTimeStampsCombo->setCurrentIndex(idx);
277 myTimeStampsCombo->addItem(aIteration);
278 myTimeStampsCombo->setCurrentIndex(myTimeStampsCombo->count()-1);
280 SetScalarField( false );
282 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
287 myInputPane->initFromPrsObject( myPrsCopy );
288 myTabBox->setCurrentIndex( 0 );
291 double VisuGUI_DeformedShapeAndScalarMapDlg::getFactor() const
293 return ScalFact->value();
296 void VisuGUI_DeformedShapeAndScalarMapDlg::setFactor(double theFactor)
299 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
300 int degree = int(log10(fabs(theFactor))) - 1;
301 if (fabs(theFactor) < 1) {
302 // as logarithm value is negative in this case
303 // and it is truncated to the bigger integer
306 step = pow(10., double(degree));
309 ScalFact->setSingleStep(step);
310 ScalFact->setValue(theFactor);
314 VisuGUI_DeformedShapeAndScalarMapDlg
315 ::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
317 if(!myInputPane->check() || !GetScalarPane()->check())
320 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
321 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
323 myPrsCopy->SetScale(getFactor());
325 myPrsCopy->SetScalarField(myPrsCopy->GetScalarEntity(),
326 getCurrentScalarFieldName().toLatin1().constData(),
327 myTimeStampID[ myTimeStampsCombo->currentIndex() ]);
330 SetScalarField( false );
332 VISU::TSameAsFactory<VISU::TDEFORMEDSHAPEANDSCALARMAP>().Copy(myPrsCopy, thePrs);
337 int VisuGUI_DeformedShapeAndScalarMapDlg::getCurrentScalarFieldNamePos(){
338 return myFieldsCombo->currentIndex();
341 QString VisuGUI_DeformedShapeAndScalarMapDlg::getCurrentScalarFieldName(){
342 return myFieldsCombo->currentText();
345 int VisuGUI_DeformedShapeAndScalarMapDlg::getCurrentScalarNbIterations(){
346 return myTimeStampsCombo->count();
350 VisuGUI_DeformedShapeAndScalarMapDlg
351 ::getCurrentScalarEntity()
353 VISU::Entity anEntity = VISU::Entity(-1);
354 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
355 for(; anIter != myEntity2Fields.end(); anIter++){
356 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
357 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
358 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
359 const QString& aFieldName = aFieldIter->first;
360 if (aFieldName == myFieldsCombo->currentText()) {
361 anEntity = anIter->first;
369 void VisuGUI_DeformedShapeAndScalarMapDlg::SetScalarField( const bool save_scalar_pane ){
370 SetScalarField( myTimeStampID[ myTimeStampsCombo->currentIndex() ], "", save_scalar_pane );
374 VisuGUI_DeformedShapeAndScalarMapDlg
375 ::SetScalarField(int theIter,
376 QString theFieldName,
377 const bool save_scalar_pane )
379 QApplication::setOverrideCursor(Qt::WaitCursor);
381 if( save_scalar_pane )
382 GetScalarPane()->storeToPrsObject(myPrsCopy);
386 if(theFieldName.isEmpty())
387 aFieldName = myFieldsCombo->currentText();
389 aFieldName = theFieldName;
391 VISU::Entity anEntity = getCurrentScalarEntity();
393 myPrsCopy->SetScalarField(anEntity,
394 aFieldName.toLatin1().constData(),
397 if( save_scalar_pane )
400 QApplication::restoreOverrideCursor();
403 void VisuGUI_DeformedShapeAndScalarMapDlg::accept()
405 VisuGUI_ScalarBarBaseDlg::accept();
408 void VisuGUI_DeformedShapeAndScalarMapDlg::reject()
410 VisuGUI_ScalarBarBaseDlg::reject();
413 QString VisuGUI_DeformedShapeAndScalarMapDlg::GetContextHelpFilePath()
415 return "scalar_map_on_deformed_shape_page.html";
418 void VisuGUI_DeformedShapeAndScalarMapDlg::AddAllFieldNames(){
419 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
420 for(; anIter != myEntity2Fields.end(); anIter++){
421 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
422 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
423 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
424 const QString& aFieldName = aFieldIter->first;
425 myFieldsCombo->addItem(aFieldName);
430 void VisuGUI_DeformedShapeAndScalarMapDlg::AddAllTimes(const QString& theFieldName){
431 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
432 int currentTimeStampId = (myTimeStampsCombo->count() > 0) ? myTimeStampsCombo->currentIndex() : 0;
433 for(; anIter != myEntity2Fields.end(); anIter++){
434 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
435 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
436 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
437 const QString& aFieldName = aFieldIter->first;
438 if(theFieldName != aFieldName)
441 myTimeStampID.clear();
442 myTimeStampsCombo->clear();
444 const TTimeStampNumber2Time& aTimeStampNumber2Time = aFieldIter->second;
445 TTimeStampNumber2Time::const_iterator aTimeStampIter = aTimeStampNumber2Time.begin();
446 for(; aTimeStampIter != aTimeStampNumber2Time.end(); aTimeStampIter++){
447 int aTimeStampNumber = aTimeStampIter->first;
448 myTimeStampID.push_back(aTimeStampNumber);
450 QString aTimeStampTime = aTimeStampIter->second;
451 myTimeStampsCombo->addItem(aTimeStampTime);
453 if(currentTimeStampId >= myTimeStampID.size())
454 currentTimeStampId = myTimeStampID.size()-1;
455 myTimeStampsCombo->setCurrentIndex(currentTimeStampId);
461 void VisuGUI_DeformedShapeAndScalarMapDlg::onFieldChanged(int){
462 AddAllTimes(myFieldsCombo->currentText());
467 void VisuGUI_DeformedShapeAndScalarMapDlg::onTimeStampChanged(int){
472 void VisuGUI_DeformedShapeAndScalarMapDlg::UpdateScalarField(){
473 GetScalarPane()->initFromPrsObject(myPrsCopy);
477 VisuGUI_DeformedShapeAndScalarMapDlg
478 ::GetFloatValueOfTimeStamp(VISU::Entity theEntity,
479 const std::string& theFieldName,
480 int theTimeStampNumber)
483 VISU::TEntity anEntity = VISU::TEntity(theEntity);
484 VISU::Result_i* theResult = myPrsCopy->GetCResult();
485 VISU::Result_i::PInput anInput = theResult->GetInput();
486 VISU::PField aField = anInput->GetField(myPrsCopy->GetCMeshName(),
492 VISU::TValField& aValField = aField->myValField;
493 VISU::TValField::const_iterator aIter = aValField.find(theTimeStampNumber);
494 if(aIter != aValField.end()){
495 VISU::PValForTime aValForTime = aIter->second;
496 aTime = VISU_Convertor::GenerateName(aValForTime->myTime).c_str();