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_ScalarMapOnDeformedShapeDlg.cxx
25 // Author : Eugeny Nikolaev
28 #include "VisuGUI_ScalarMapOnDeformedShapeDlg.h"
30 #include "VisuGUI_Tools.h"
31 #include "VisuGUI_InputPane.h"
33 #include "VISU_Result_i.hh"
34 #include "VISU_ScalarMapOnDeformedShape_i.hh"
35 #include "VISU_ColoredPrs3dFactory.hh"
37 #include "VISU_ScalarMapPL.hxx"
38 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
40 #include "VISU_Convertor.hxx"
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"
56 #include <qtabwidget.h>
65 VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule)
66 : VisuGUI_ScalarBarBaseDlg(theModule),
68 myUpdateScalars(true),
71 setCaption(tr("DLG_TITLE"));
72 setSizeGripEnabled(TRUE);
74 QVBoxLayout* TopLayout = new QVBoxLayout (this);
75 TopLayout->setSpacing(6);
76 TopLayout->setMargin(11);
78 myTabBox = new QTabWidget (this);
80 // Scalar Map on Deformed shape pane
81 QVBox* aBox = new QVBox (this);
83 QFrame* TopGroup = new QFrame (aBox, "TopGroup");
84 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
85 TopGroup->setLineWidth(1);
86 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
87 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
88 TopGroupLayout->setSpacing(6);
89 TopGroupLayout->setMargin(11);
92 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel");
93 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
95 ScalFact = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, TopGroup);
96 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
97 ScalFact->setPrecision(38);
98 ScalFact->setValue(0.1);
99 TopGroupLayout->addWidget(ScalFact, 0, 1);
102 QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup, "FieldLabel");
103 myFieldsCombo = new QComboBox (TopGroup,"Fields");
105 TopGroupLayout->addWidget(FieldLabel, 1, 0);
106 TopGroupLayout->addWidget(myFieldsCombo,1,1);
108 // TimeStamps combo box
109 QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup, "TimeStampLabel");
110 myTimeStampsCombo = new QComboBox (TopGroup,"TimeStamp");
112 TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
113 TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
116 myTabBox->addTab(aBox, tr("SCALAR_MAP_ON_DEFORMED_SHAPE_TAB"));
119 myInputPane = new VisuGUI_InputPane(VISU::TSCALARMAPONDEFORMEDSHAPE, theModule, this);
121 myTabBox->addTab(GetScalarPane(), tr("SCALAR_BAR_TAB"));
122 myTabBox->addTab(myInputPane, tr("INPUT_TAB"));
125 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
126 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
127 GroupButtons->setColumnLayout(0, Qt::Vertical);
128 GroupButtons->layout()->setSpacing(0);
129 GroupButtons->layout()->setMargin(0);
130 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
131 GroupButtonsLayout->setAlignment(Qt::AlignTop);
132 GroupButtonsLayout->setSpacing(6);
133 GroupButtonsLayout->setMargin(11);
135 QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk");
136 buttonOk->setAutoDefault(TRUE);
137 buttonOk->setDefault(TRUE);
138 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
140 GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding,
141 QSizePolicy::Minimum), 0, 1);
143 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel");
144 buttonCancel->setAutoDefault(TRUE);
145 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
147 QPushButton* buttonHelp = new QPushButton (tr("&Help") , GroupButtons, "buttonHelp");
148 buttonHelp->setAutoDefault(TRUE);
149 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
151 // Add Tab box and Buttons to the top layout
152 TopLayout->addWidget(myTabBox);
153 TopLayout->addWidget(GroupButtons);
155 // signals and slots connections
156 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
157 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
158 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
159 connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
160 connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
163 VisuGUI_ScalarMapOnDeformedShapeDlg::~VisuGUI_ScalarMapOnDeformedShapeDlg()
166 void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
170 myPrsCopy = VISU::TSameAsFactory<VISU::TSCALARMAPONDEFORMEDSHAPE>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
171 setFactor(myPrsCopy->GetScale());
172 myTimeStampsCombo->setDisabled(myIsAnimation);
174 CORBA::String_var aFieldName(myPrsCopy->GetScalarFieldName());
175 QString aIteration = GetFloatValueOfTimeStamp(myPrsCopy->GetScalarEntity(),
177 myPrsCopy->GetScalarTimeStampNumber());
178 if (myEntity2Fields.size() == 0)
180 // find all fields and time stamps on it
181 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
182 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
183 SALOME_ListIO selected;
184 aSel->selectedObjects(selected);
185 if (selected.Extent() > 0) {
186 Handle(SALOME_InteractiveObject) aIO = selected.First();
187 if (aIO->hasEntry()) {
188 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
189 VISU::VISUType aType = VISU::Storable::SObject2Type( aSObject );
191 case VISU::TTIMESTAMP: {
192 aSObject = aSObject->GetFather();
193 aSObject = aSObject->GetFather();
197 _PTR(SObject) newSObject;
198 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
199 aSObject = aSObject->GetFather();
202 case VISU::TANIMATION: {
203 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
204 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
205 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
206 _PTR(SObject) newSObject;
207 if(aTmpChildSObj->ReferencedObject(newSObject)){
208 aSObject = newSObject;
209 aSObject->GetFather();
216 aSObject = aSObject->GetFather();
217 aSObject = aSObject->GetFather();
219 mySelectionObj = aSObject;
220 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
221 if (CORBA::is_nil(anObject)) {
222 mySelectionObj = mySelectionObj->GetFather();
227 if (mySelectionObj) {
228 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
230 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
231 _PTR(SObject) aChildSObj = aIter->Value();
232 VISU::Storable::TRestoringMap aRestoringMap = VISU::Storable::GetStorableMap(aChildSObj);
233 if (!aRestoringMap.empty()) {
234 VISU::VISUType aType = VISU::Storable::RestoringMap2Type(aRestoringMap);
235 if (aType == VISU::TTIMESTAMP) {
236 QString aMeshName = aRestoringMap["myMeshName"];
237 CORBA::String_var aName = myPrsCopy->GetMeshName();
238 if (aMeshName != aName.in())
240 QString aFieldName = aRestoringMap["myFieldName"];
241 QString aTimeIter = aRestoringMap["myTimeStampId"];
242 QString aEntity = aRestoringMap["myEntityId"];
243 VISU::Entity anEntity;
244 switch (aEntity.toInt()) {
245 case 0: anEntity = VISU::NODE; break;
246 case 1: anEntity = VISU::EDGE; break;
247 case 2: anEntity = VISU::FACE; break;
248 case 3: anEntity = VISU::CELL; break;
250 TFieldName2TimeStamps& aFieldName2TimeStamps = myEntity2Fields[anEntity];
251 TTimeStampNumber2Time& aTimeStampNumber2Time = aFieldName2TimeStamps[aFieldName];
252 aTimeStampNumber2Time[aTimeIter.toInt()] =
253 GetFloatValueOfTimeStamp(anEntity,
262 myFieldsCombo->setCurrentText(aFieldName.in());
263 AddAllTimes(myFieldsCombo->currentText());
264 myTimeStampsCombo->setCurrentText(aIteration);
265 SetScalarField( false );
267 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
272 myInputPane->initFromPrsObject( myPrsCopy );
273 myTabBox->setCurrentPage( 0 );
277 VisuGUI_ScalarMapOnDeformedShapeDlg
278 ::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
280 if(!myInputPane->check() || !GetScalarPane()->check())
283 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
284 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
286 myPrsCopy->SetScale(getFactor());
288 myPrsCopy->SetScalarField(myPrsCopy->GetScalarEntity(),
289 getCurrentScalarFieldName().latin1(),
290 myTimeStampID[ myTimeStampsCombo->currentItem() ]);
293 SetScalarField( false );
295 VISU::TSameAsFactory<VISU::TSCALARMAPONDEFORMEDSHAPE>().Copy(myPrsCopy, thePrs);
300 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldNamePos(){
301 return myFieldsCombo->currentItem();
304 QString VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldName(){
305 return myFieldsCombo->currentText();
308 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarNbIterations(){
309 return myTimeStampsCombo->count();
313 VisuGUI_ScalarMapOnDeformedShapeDlg
314 ::getCurrentScalarEntity()
316 VISU::Entity anEntity = VISU::Entity(-1);
317 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
318 for(; anIter != myEntity2Fields.end(); anIter++){
319 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
320 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
321 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
322 const QString& aFieldName = aFieldIter->first;
323 if (aFieldName == myFieldsCombo->currentText()) {
324 anEntity = anIter->first;
332 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField( const bool save_scalar_pane ){
333 SetScalarField( myTimeStampID[ myTimeStampsCombo->currentItem() ], "", save_scalar_pane );
337 VisuGUI_ScalarMapOnDeformedShapeDlg
338 ::SetScalarField(int theIter,
339 QString theFieldName,
340 const bool save_scalar_pane )
342 QApplication::setOverrideCursor(Qt::waitCursor);
344 if( save_scalar_pane )
345 GetScalarPane()->storeToPrsObject(myPrsCopy);
349 if(theFieldName.isEmpty())
350 aFieldName = myFieldsCombo->currentText();
352 aFieldName = theFieldName;
354 VISU::Entity anEntity = getCurrentScalarEntity();
356 myPrsCopy->SetScalarField(anEntity,
360 if( save_scalar_pane )
363 QApplication::restoreOverrideCursor();
366 void VisuGUI_ScalarMapOnDeformedShapeDlg::accept()
368 VisuGUI_ScalarBarBaseDlg::accept();
371 void VisuGUI_ScalarMapOnDeformedShapeDlg::reject()
373 VisuGUI_ScalarBarBaseDlg::reject();
376 QString VisuGUI_ScalarMapOnDeformedShapeDlg::GetContextHelpFilePath()
378 return "scalar_map_on_deformed_shape_page.html";
381 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllFieldNames(){
382 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
383 for(; anIter != myEntity2Fields.end(); anIter++){
384 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
385 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
386 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
387 const QString& aFieldName = aFieldIter->first;
388 myFieldsCombo->insertItem(aFieldName);
393 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllTimes(const QString& theFieldName){
394 TEntity2Fields::const_iterator anIter = myEntity2Fields.begin();
395 for(; anIter != myEntity2Fields.end(); anIter++){
396 const TFieldName2TimeStamps& aFieldName2TimeStamps = anIter->second;
397 TFieldName2TimeStamps::const_iterator aFieldIter = aFieldName2TimeStamps.begin();
398 for(; aFieldIter != aFieldName2TimeStamps.end(); aFieldIter++){
399 const QString& aFieldName = aFieldIter->first;
400 if(theFieldName != aFieldName)
403 myTimeStampID.clear();
404 myTimeStampsCombo->clear();
406 const TTimeStampNumber2Time& aTimeStampNumber2Time = aFieldIter->second;
407 TTimeStampNumber2Time::const_iterator aTimeStampIter = aTimeStampNumber2Time.begin();
408 for(; aTimeStampIter != aTimeStampNumber2Time.end(); aTimeStampIter++){
409 int aTimeStampNumber = aTimeStampIter->first;
410 myTimeStampID.push_back(aTimeStampNumber);
412 QString aTimeStampTime = aTimeStampIter->second;
413 myTimeStampsCombo->insertItem(aTimeStampTime);
420 void VisuGUI_ScalarMapOnDeformedShapeDlg::onFieldChanged(int){
421 AddAllTimes(myFieldsCombo->currentText());
426 void VisuGUI_ScalarMapOnDeformedShapeDlg::onTimeStampChanged(int){
431 void VisuGUI_ScalarMapOnDeformedShapeDlg::UpdateScalarField(){
432 GetScalarPane()->initFromPrsObject(myPrsCopy);
436 VisuGUI_ScalarMapOnDeformedShapeDlg
437 ::GetFloatValueOfTimeStamp(VISU::Entity theEntity,
438 const std::string& theFieldName,
439 int theTimeStampNumber)
442 VISU::TEntity anEntity = VISU::TEntity(theEntity);
443 VISU::Result_i* theResult = myPrsCopy->GetCResult();
444 VISU::Result_i::PInput anInput = theResult->GetInput();
445 VISU::PField aField = anInput->GetField(myPrsCopy->GetCMeshName(),
451 VISU::TValField& aValField = aField->myValField;
452 VISU::TValField::const_iterator aIter = aValField.find(theTimeStampNumber);
453 if(aIter != aValField.end()){
454 VISU::PValForTime aValForTime = aIter->second;
455 aTime = VISU_Convertor::GenerateName(aValForTime->myTime).c_str();