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, true),
73 myUpdateScalars(true),
74 myIsScalarFieldValid(true),
77 setWindowTitle(tr("DLG_TITLE"));
78 setSizeGripEnabled(true);
80 QVBoxLayout* TopLayout = new QVBoxLayout (this);
81 TopLayout->setSpacing(6);
82 TopLayout->setMargin(11);
84 myTabBox = new QTabWidget (this);
86 // Scalar Map on Deformed shape pane
87 QWidget* aBox = new QWidget (this);
88 QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
89 aVBLay->setMargin(11);
90 QFrame* TopGroup = new QFrame (aBox);
91 aVBLay->addWidget(TopGroup);
92 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
93 TopGroup->setLineWidth(1);
94 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
95 TopGroupLayout->setSpacing(6);
96 TopGroupLayout->setMargin(11);
99 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup);
100 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
102 SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
103 int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
105 ScalFact = new QtxDoubleSpinBox (0, 1.0E+38, 0.1, aPrecision*(-1), 32, TopGroup);
106 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
107 ScalFact->setValue(0.1);
108 TopGroupLayout->addWidget(ScalFact, 0, 1);
111 QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup);
112 myFieldsCombo = new QComboBox (TopGroup);
114 TopGroupLayout->addWidget(FieldLabel, 1, 0);
115 TopGroupLayout->addWidget(myFieldsCombo,1,1);
117 // TimeStamps combo box
118 QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup);
119 myTimeStampsCombo = new QComboBox (TopGroup);
121 TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
122 TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
123 TopGroupLayout->setRowStretch(3,5);
126 myTabBox->addTab(aBox, tr("DEFORMED_SHAPE_AND_SCALAR_MAP_TAB"));
129 myInputPane = new VisuGUI_InputPane(VISU::TDEFORMEDSHAPEANDSCALARMAP, theModule, this);
131 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
132 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
135 QGroupBox* GroupButtons = new QGroupBox (this);
136 QHBoxLayout* GroupButtonsLayout = new QHBoxLayout(GroupButtons);
137 GroupButtonsLayout->setSpacing(6);
138 GroupButtonsLayout->setMargin(11);
140 myButtonOk = new QPushButton (tr("&OK"), GroupButtons);
141 myButtonOk->setAutoDefault(true);
142 myButtonOk->setDefault(true);
143 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons);
144 buttonCancel->setAutoDefault(true);
145 QPushButton* buttonHelp = new QPushButton (tr("&Help") , GroupButtons);
146 buttonHelp->setAutoDefault(true);
148 GroupButtonsLayout->addWidget(myButtonOk);
149 GroupButtonsLayout->addSpacing(10);
150 GroupButtonsLayout->addStretch();
151 GroupButtonsLayout->addWidget(buttonCancel);
152 GroupButtonsLayout->addWidget(buttonHelp);
154 // Add Tab box and Buttons to the top layout
155 TopLayout->addWidget(myTabBox);
156 TopLayout->addWidget(GroupButtons);
158 // signals and slots connections
159 connect(myButtonOk, SIGNAL(clicked()), this, SLOT(accept()));
160 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
161 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
162 connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
163 connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
166 VisuGUI_DeformedShapeAndScalarMapDlg::~VisuGUI_DeformedShapeAndScalarMapDlg()
170 void VisuGUI_DeformedShapeAndScalarMapDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
174 myPrsCopy = VISU::TSameAsFactory<VISU::TDEFORMEDSHAPEANDSCALARMAP>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
175 setFactor(myPrsCopy->GetScale());
176 myTimeStampsCombo->setDisabled(myIsAnimation);
178 CORBA::String_var aFieldName(myPrsCopy->GetScalarFieldName());
179 QString aIteration = GetFloatValueOfTimeStamp(myPrsCopy->GetScalarEntity(),
181 myPrsCopy->GetScalarTimeStampNumber());
182 if (myEntity2Fields.size() == 0)
184 // find all fields and time stamps on it
185 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
186 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
187 SALOME_ListIO selected;
188 aSel->selectedObjects(selected);
189 if (selected.Extent() > 0) {
190 Handle(SALOME_InteractiveObject) aIO = selected.First();
191 if (aIO->hasEntry()) {
192 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
193 VISU::VISUType aType = VISU::Storable::SObject2Type( aSObject );
195 case VISU::TTIMESTAMP: {
196 aSObject = aSObject->GetFather();
197 aSObject = aSObject->GetFather();
201 _PTR(SObject) newSObject;
202 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
203 aSObject = aSObject->GetFather();
206 case VISU::TANIMATION: {
207 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
208 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
209 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
210 _PTR(SObject) newSObject;
211 if(aTmpChildSObj->ReferencedObject(newSObject)){
212 aSObject = newSObject;
213 aSObject->GetFather();
220 aSObject = aSObject->GetFather();
221 aSObject = aSObject->GetFather();
223 mySelectionObj = aSObject;
224 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
225 if (CORBA::is_nil(anObject)) {
226 mySelectionObj = mySelectionObj->GetFather();
231 if (mySelectionObj) {
232 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
234 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
235 _PTR(SObject) aChildSObj = aIter->Value();
236 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildSObj);
237 if (!aRestoringMap.empty()) {
238 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
239 if (aType == VISU::TTIMESTAMP) {
240 QString aMeshName = aRestoringMap["myMeshName"];
241 CORBA::String_var aName = myPrsCopy->GetMeshName();
242 if (aMeshName != aName.in())
244 QString aFieldName = aRestoringMap["myFieldName"];
245 QString aTimeIter = aRestoringMap["myTimeStampId"];
246 QString aEntity = aRestoringMap["myEntityId"];
247 VISU::Entity anEntity;
248 switch (aEntity.toInt()) {
249 case 0: anEntity = VISU::NODE; break;
250 case 1: anEntity = VISU::EDGE; break;
251 case 2: anEntity = VISU::FACE; break;
252 case 3: anEntity = VISU::CELL; break;
254 TFieldName2TimeStamps& aFieldName2TimeStamps = myEntity2Fields[anEntity];
255 TTimeStampNumber2Time& aTimeStampNumber2Time = aFieldName2TimeStamps[aFieldName];
256 aTimeStampNumber2Time[aTimeIter.toInt()] =
257 GetFloatValueOfTimeStamp(anEntity,
258 aFieldName.toLatin1().constData(),
266 int idx = myFieldsCombo->findText(aFieldName.in());
268 myFieldsCombo->setCurrentIndex(idx);
270 myFieldsCombo->addItem(aFieldName.in());
271 myFieldsCombo->setCurrentIndex(myFieldsCombo->count()-1);
273 AddAllTimes(myFieldsCombo->currentText());
274 idx = myTimeStampsCombo->findText(aIteration);
276 myTimeStampsCombo->setCurrentIndex(idx);
278 myTimeStampsCombo->addItem(aIteration);
279 myTimeStampsCombo->setCurrentIndex(myTimeStampsCombo->count()-1);
281 SetScalarField( false );
283 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
288 myInputPane->initFromPrsObject( myPrsCopy );
289 myTabBox->setCurrentIndex( 0 );
292 double VisuGUI_DeformedShapeAndScalarMapDlg::getFactor() const
294 return ScalFact->value();
297 void VisuGUI_DeformedShapeAndScalarMapDlg::setFactor(double theFactor)
300 if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
301 int degree = int(log10(fabs(theFactor))) - 1;
302 if (fabs(theFactor) < 1) {
303 // as logarithm value is negative in this case
304 // and it is truncated to the bigger integer
307 step = pow(10., double(degree));
310 ScalFact->setSingleStep(step);
311 ScalFact->setValue(theFactor);
315 VisuGUI_DeformedShapeAndScalarMapDlg
316 ::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
318 if(!myInputPane->check() || !GetScalarPane()->check())
321 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
322 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
324 myPrsCopy->SetScale(getFactor());
326 myPrsCopy->SetScalarField(myPrsCopy->GetScalarEntity(),
327 getCurrentScalarFieldName().toLatin1().constData(),
328 myTimeStampID[ myTimeStampsCombo->currentIndex() ]);
331 SetScalarField( false );
333 VISU::TSameAsFactory<VISU::TDEFORMEDSHAPEANDSCALARMAP>().Copy(myPrsCopy, thePrs);
338 int VisuGUI_DeformedShapeAndScalarMapDlg::getCurrentScalarFieldNamePos(){
339 return myFieldsCombo->currentIndex();
342 QString VisuGUI_DeformedShapeAndScalarMapDlg::getCurrentScalarFieldName(){
343 return myFieldsCombo->currentText();
346 int VisuGUI_DeformedShapeAndScalarMapDlg::getCurrentScalarNbIterations(){
347 return myTimeStampsCombo->count();
351 VisuGUI_DeformedShapeAndScalarMapDlg
352 ::getCurrentScalarEntity()
354 VISU::Entity anEntity = VISU::Entity(-1);
355 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
356 for(; anIter != myEntity2Fields.end(); anIter++){
357 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
358 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
359 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
360 const QString& aFieldName = aFieldIter->first;
361 if (aFieldName == myFieldsCombo->currentText()) {
362 anEntity = anIter->first;
370 void VisuGUI_DeformedShapeAndScalarMapDlg::SetScalarField( const bool save_scalar_pane ){
371 SetScalarField( myTimeStampID[ myTimeStampsCombo->currentIndex() ], "", save_scalar_pane );
375 VisuGUI_DeformedShapeAndScalarMapDlg
376 ::SetScalarField(int theIter,
377 QString theFieldName,
378 const bool save_scalar_pane )
380 QApplication::setOverrideCursor(Qt::WaitCursor);
382 if( save_scalar_pane && IsScalarFieldValid() )
383 GetScalarPane()->storeToPrsObject(myPrsCopy);
387 if(theFieldName.isEmpty())
388 aFieldName = myFieldsCombo->currentText();
390 aFieldName = theFieldName;
392 VISU::Entity anEntity = getCurrentScalarEntity();
395 myPrsCopy->SetScalarField(anEntity,
396 aFieldName.toLatin1().constData(),
398 if( save_scalar_pane )
400 myIsScalarFieldValid = true;
401 } catch( std::exception& exc ) {
403 SUIT_MessageBox::warning( this, tr( "WRN_WARNING" ), tr( "ERR_SCALAR_DATA_INCONSISTENT" ) );
404 myIsScalarFieldValid = false;
408 QApplication::restoreOverrideCursor();
411 void VisuGUI_DeformedShapeAndScalarMapDlg::accept()
413 VisuGUI_ScalarBarBaseDlg::accept();
416 void VisuGUI_DeformedShapeAndScalarMapDlg::reject()
418 VisuGUI_ScalarBarBaseDlg::reject();
421 QString VisuGUI_DeformedShapeAndScalarMapDlg::GetContextHelpFilePath()
423 return "scalar_map_on_deformed_shape_page.html";
426 void VisuGUI_DeformedShapeAndScalarMapDlg::AddAllFieldNames(){
427 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
428 for(; anIter != myEntity2Fields.end(); anIter++){
429 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
430 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
431 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
432 const QString& aFieldName = aFieldIter->first;
433 myFieldsCombo->addItem(aFieldName);
438 void VisuGUI_DeformedShapeAndScalarMapDlg::AddAllTimes(const QString& theFieldName){
439 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
440 int currentTimeStampId = (myTimeStampsCombo->count() > 0) ? myTimeStampsCombo->currentIndex() : 0;
441 for(; anIter != myEntity2Fields.end(); anIter++){
442 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
443 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
444 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
445 const QString& aFieldName = aFieldIter->first;
446 if(theFieldName != aFieldName)
449 myTimeStampID.clear();
450 myTimeStampsCombo->clear();
452 const TTimeStampNumber2Time& aTimeStampNumber2Time = aFieldIter->second;
453 TTimeStampNumber2Time::const_iterator aTimeStampIter = aTimeStampNumber2Time.begin();
454 for(; aTimeStampIter != aTimeStampNumber2Time.end(); aTimeStampIter++){
455 int aTimeStampNumber = aTimeStampIter->first;
456 myTimeStampID.push_back(aTimeStampNumber);
458 QString aTimeStampTime = aTimeStampIter->second;
459 myTimeStampsCombo->addItem(aTimeStampTime);
461 if(currentTimeStampId >= myTimeStampID.size())
462 currentTimeStampId = myTimeStampID.size()-1;
463 myTimeStampsCombo->setCurrentIndex(currentTimeStampId);
469 void VisuGUI_DeformedShapeAndScalarMapDlg::onFieldChanged(int){
470 AddAllTimes(myFieldsCombo->currentText());
472 //UpdateScalarField(); // it is called from SetScalarField() method
475 void VisuGUI_DeformedShapeAndScalarMapDlg::onTimeStampChanged(int){
477 //UpdateScalarField(); // it is called from SetScalarField() method
480 void VisuGUI_DeformedShapeAndScalarMapDlg::UpdateScalarField(){
481 GetScalarPane()->initFromPrsObject(myPrsCopy);
485 VisuGUI_DeformedShapeAndScalarMapDlg
486 ::GetFloatValueOfTimeStamp(VISU::Entity theEntity,
487 const std::string& theFieldName,
488 int theTimeStampNumber)
491 VISU::TEntity anEntity = VISU::TEntity(theEntity);
492 VISU::Result_i* theResult = myPrsCopy->GetCResult();
493 VISU::Result_i::PInput anInput = theResult->GetInput();
494 VISU::PField aField = anInput->GetField(myPrsCopy->GetCMeshName(),
500 VISU::TValField& aValField = aField->myValField;
501 VISU::TValField::const_iterator aIter = aValField.find(theTimeStampNumber);
502 if(aIter != aValField.end()){
503 VISU::PValForTime aValForTime = aIter->second;
504 aTime = VISU_Convertor::GenerateName(aValForTime->myTime).c_str();
509 void VisuGUI_DeformedShapeAndScalarMapDlg::updateControls()
511 bool isScalarFieldValid = IsScalarFieldValid();
512 myTabBox->setTabEnabled( 1, isScalarFieldValid ); // "Scalar Bar" tab
513 myTabBox->setTabEnabled( 2, isScalarFieldValid ); // "Input" tab
514 myTimeStampsCombo->setEnabled( isScalarFieldValid );
515 myButtonOk->setEnabled( isScalarFieldValid );