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"
32 #include "VISU_Result_i.hh"
33 #include "VISU_ScalarMapOnDeformedShape_i.hh"
35 #include "VISU_ScalarMapPL.hxx"
36 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
38 #include "VISU_Convertor.hxx"
40 #include "SalomeApp_Module.h"
41 #include "LightApp_Application.h"
42 #include "LightApp_SelectionMgr.h"
43 #include "SUIT_Desktop.h"
44 #include "SUIT_ResourceMgr.h"
45 #include "SUIT_Session.h"
46 #include "SUIT_MessageBox.h"
48 #include "SALOME_ListIO.hxx"
50 #include "SALOMEDSClient_AttributeComment.hxx"
51 #include "SALOMEDSClient_AttributeName.hxx"
54 #include <qtabwidget.h>
63 VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule)
64 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_ScalarMapOnDeformedShapeDlg", false,
65 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
70 setCaption(tr("DLG_TITLE"));
71 setSizeGripEnabled(TRUE);
73 QVBoxLayout* TopLayout = new QVBoxLayout (this);
74 TopLayout->setSpacing(6);
75 TopLayout->setMargin(11);
77 QTabWidget* aTabBox = new QTabWidget (this);
79 // Scalar Map on Deformed shape pane
80 QVBox* aBox = new QVBox (this);
82 QFrame* TopGroup = new QFrame (aBox, "TopGroup");
83 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
84 TopGroup->setLineWidth(1);
85 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
86 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
87 TopGroupLayout->setSpacing(6);
88 TopGroupLayout->setMargin(11);
91 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel");
92 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
94 ScalFact = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, TopGroup);
95 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
96 ScalFact->setPrecision(5);
97 ScalFact->setValue(0.1);
98 TopGroupLayout->addWidget(ScalFact, 0, 1);
101 QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup, "FieldLabel");
102 myFieldsCombo = new QComboBox (TopGroup,"Fields");
104 TopGroupLayout->addWidget(FieldLabel, 1, 0);
105 TopGroupLayout->addWidget(myFieldsCombo,1,1);
107 // TimeStamps combo box
108 QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup, "TimeStampLabel");
109 myTimeStampsCombo = new QComboBox (TopGroup,"TimeStamp");
111 TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
112 TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
115 aTabBox->addTab(aBox, tr("SCALAR_MAP_ON_DEFORMED_SHAPE_TAB"));
118 myScalarPane = new VisuGUI_ScalarBarPane (this, false);
119 myScalarPane->setMargin(5);
121 aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
124 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
125 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
126 GroupButtons->setColumnLayout(0, Qt::Vertical);
127 GroupButtons->layout()->setSpacing(0);
128 GroupButtons->layout()->setMargin(0);
129 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
130 GroupButtonsLayout->setAlignment(Qt::AlignTop);
131 GroupButtonsLayout->setSpacing(6);
132 GroupButtonsLayout->setMargin(11);
134 QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk");
135 buttonOk->setAutoDefault(TRUE);
136 buttonOk->setDefault(TRUE);
137 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
139 GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding,
140 QSizePolicy::Minimum), 0, 1);
142 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel");
143 buttonCancel->setAutoDefault(TRUE);
144 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
146 QPushButton* buttonHelp = new QPushButton (tr("&Help") , GroupButtons, "buttonHelp");
147 buttonHelp->setAutoDefault(TRUE);
148 GroupButtonsLayout->addWidget(buttonHelp, 0, 3);
150 // Add Tab box and Buttons to the top layout
151 TopLayout->addWidget(aTabBox);
152 TopLayout->addWidget(GroupButtons);
154 // signals and slots connections
155 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
156 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
157 connect(buttonHelp, SIGNAL(clicked()), this, SLOT(onHelp()));
158 connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
159 connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
162 void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject
163 (VISU::ScalarMapOnDeformedShape_i* thePrs, bool isAnim)
165 myIsAnimation = isAnim;
168 setFactor(myPrs->GetScale());
169 myTimeStampsCombo->setDisabled(isAnim);
171 QString aFieldName(myPrs->GetScalarFieldName().c_str());
172 float aIterFloat = GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
173 myPrs->GetScalarFieldName().c_str(),
174 myPrs->GetScalarIteration(),
175 myPrs->GetScalarEntity());
176 QString aIteration(QString("%1").arg(aIterFloat));
178 if (myMeshFieldsTimes.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());
190 _PTR(GenericAttribute) anTmpAttr;
191 if (aSObject->FindAttribute(anTmpAttr, "AttributeComment")) {
192 _PTR(AttributeComment) aTmpComment (anTmpAttr);
193 string aTmpComm = aTmpComment->Value();
194 QString aTmpstrIn (aTmpComm.c_str());
195 VISU::Storable::TRestoringMap aTmpaMap;
196 VISU::Storable::StrToMap(aTmpstrIn,aTmpaMap);
198 VISU::VISUType aTmpType =
199 (VISU::VISUType)VISU::Storable::FindValue(aTmpaMap,"myType",&aTmpisExist).toInt();
201 case VISU::TTIMESTAMP:
203 aSObject = aSObject->GetFather();
204 aSObject = aSObject->GetFather();
209 _PTR(SObject) newSObject;
210 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
211 aSObject = aSObject->GetFather();
214 case VISU::TANIMATION:
216 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
217 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
218 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
219 _PTR(SObject) newSObject;
220 if(aTmpChildSObj->ReferencedObject(newSObject)){
221 aSObject = newSObject;
222 aSObject->GetFather();
231 aSObject = aSObject->GetFather();
232 aSObject = aSObject->GetFather();
234 mySelectionObj = aSObject;
235 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
236 if (CORBA::is_nil(anObject)) {
237 mySelectionObj = mySelectionObj->GetFather();
242 if (mySelectionObj) {
243 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
245 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
246 _PTR(SObject) aChildSObj = aIter->Value();
247 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
249 _PTR(GenericAttribute) anAttr;
250 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
251 _PTR(AttributeComment) aComment (anAttr);
252 string aComm = aComment->Value();
253 QString strIn (aComm.c_str());
254 VISU::Storable::TRestoringMap aMap;
255 VISU::Storable::StrToMap(strIn,aMap);
257 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
259 if ((aType == VISU::TTIMESTAMP)) {
260 _PTR(GenericAttribute) aNameAttr;
261 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
262 _PTR(AttributeName) aName (aNameAttr);
263 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
264 QString aMeshName = VISU::getValue(aChildSObj, "myMeshName");
265 if (QString(myPrs->GetMeshName().c_str()) != aMeshName) continue;
266 myCurrMeshName = aMeshName;
267 QString aFieldName = VISU::getValue(aChildSObj, "myFieldName");
268 QString aTimeIter = VISU::getValue(aChildSObj, "myTimeStampId");
269 QString aEntity = VISU::getValue(aChildSObj, "myEntityId");
270 VISU::TEntity anEntity;
271 switch (aEntity.toInt()) {
272 case 0: anEntity = VISU::NODE_ENTITY; break;
273 case 1: anEntity = VISU::EDGE_ENTITY; break;
274 case 2: anEntity = VISU::FACE_ENTITY; break;
275 case 3: anEntity = VISU::CELL_ENTITY; break;
277 TFT &aFieldsMap = myMeshFieldsTimes[aMeshName.latin1()];
278 TFE aKey (aFieldName.latin1(), anEntity);
279 aFieldsMap[aKey][aTimeIter.toInt()] =
280 GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
293 myFieldsCombo->setCurrentText(aFieldName);
294 AddAllTimes(myFieldsCombo->currentText());
295 myTimeStampsCombo->setCurrentText(aIteration);
298 myScalarPane->initFromPrsObject(myPrs);
301 int VisuGUI_ScalarMapOnDeformedShapeDlg::storeToPrsObject
302 (VISU::ScalarMapOnDeformedShape_i* thePrs, bool theUpdateScalars, int theIter)
304 thePrs->SetScale(getFactor());
307 thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
308 getCurrentScalarFieldName().latin1(),
310 myPrs->GetScalarEntity());
312 thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
313 getCurrentScalarFieldName().latin1(),
314 myTimeStampsCombo->currentItem() + 1,
315 myPrs->GetScalarEntity());
317 if (theUpdateScalars) SetScalarField();
319 thePrs->ShowColored(true);
321 myScalarPane->storeToPrsObject(thePrs);
328 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldNamePos(){
329 return myFieldsCombo->currentItem();
332 QString VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldName(){
333 return myFieldsCombo->currentText();
336 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarNbIterations(){
337 return myTimeStampsCombo->count();
340 VISU::TEntity VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarEntity(){
341 VISU::TEntity anEntity;
342 TFT::const_iterator aIterField = myMeshFieldsTimes[myCurrMeshName].begin();
343 for(;aIterField != myMeshFieldsTimes[myCurrMeshName].end();aIterField++){
344 if (aIterField->first.first == myFieldsCombo->currentText()){
345 anEntity = aIterField->first.second;
352 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(){
353 SetScalarField(myTimeStampsCombo->currentItem()+1);
356 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(int theIter,QString theFieldName){
360 if(theFieldName.isEmpty())
361 aFieldName = myFieldsCombo->currentText();
363 aFieldName = theFieldName;
365 VISU::TEntity anEntity = getCurrentScalarEntity();
367 myPrs->SetScalarField(myCurrMeshName.latin1(),
372 myScalarPane->storeToPrsObject(myPrs);
377 void VisuGUI_ScalarMapOnDeformedShapeDlg::accept()
379 if (myScalarPane->check()){
380 myScalarPane->deletePreview();
385 void VisuGUI_ScalarMapOnDeformedShapeDlg::reject()
387 myScalarPane->deletePreview();
391 void VisuGUI_ScalarMapOnDeformedShapeDlg::onHelp()
393 QString aHelpFileName = "scalar_map_on_deformed_shape_presentation.htm";
394 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
396 app->onHelpContextModule(myVisuGUI ? app->moduleName(myVisuGUI->moduleName()) : QString(""), aHelpFileName);
398 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
399 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
400 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
401 QObject::tr("BUT_OK"));
405 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllFieldNames(){
406 TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin();
407 for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){
408 QString aMeshName = aIterMesh->first;
409 TFT::const_iterator aIterField = (aIterMesh->second).begin();
410 for(;aIterField != (aIterMesh->second).end(); aIterField++){
411 QString aFieldName = aIterField->first.first;
412 myFieldsCombo->insertItem(aFieldName);
417 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllTimes(const QString& theFieldName){
418 TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin();
419 for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){
420 QString aMeshName = aIterMesh->first;
421 TFT::const_iterator aIterField = (aIterMesh->second).begin();
422 for(;aIterField != (aIterMesh->second).end(); aIterField++){
423 QString aFieldName = aIterField->first.first;
424 if(theFieldName != aFieldName) continue;
425 myTimeStampsCombo->clear();
426 TTL::const_iterator aTimeIter = (aIterField->second).begin();
427 for(;aTimeIter != (aIterField->second).end(); aTimeIter++)
428 myTimeStampsCombo->insertItem(QString("%1").arg(aTimeIter->second));
434 void VisuGUI_ScalarMapOnDeformedShapeDlg::onFieldChanged(int){
435 AddAllTimes(myFieldsCombo->currentText());
440 void VisuGUI_ScalarMapOnDeformedShapeDlg::onTimeStampChanged(int){
445 void VisuGUI_ScalarMapOnDeformedShapeDlg::UpdateScalarField(){
446 myPrs->SetScale(getFactor());
447 vtkFloatingPointType aRange[2];
448 myPrs->GetScalarMapOnDeformedShapePL()->Build();
449 myPrs->GetScalarMapOnDeformedShapePL()->Update();
450 myPrs->GetScalarMapOnDeformedShapePL()->GetSourceRange(aRange);
451 double aDoubleRange[2];
452 aDoubleRange[0] = double(aRange[0]);
453 aDoubleRange[1] = double(aRange[1]);
454 myScalarPane->initFromPrsObject(myPrs);
455 myScalarPane->setRange(aDoubleRange[0],aDoubleRange[1],myScalarPane->isIRange());
458 float VisuGUI_ScalarMapOnDeformedShapeDlg::GetFloatValueOfTimeStamp(const char* theMeshName,
459 const char* theFieldName,
461 const VISU::TEntity theEntity){
463 VISU::Result_i* theResult = myPrs->GetResult();
464 VISU::PField aField = theResult->GetInput()->GetField(theMeshName,theEntity,theFieldName);
465 if(!aField) return ret;
466 VISU::TValField& aValField = aField->myValField;
467 VISU::TValField::const_iterator aIter = aValField.find(theIter);
468 if(aIter != aValField.end()){
469 VISU::PValForTime aValForTime = aIter->second;
470 ret = float(aValForTime->myTime.first);
473 cout << "Where are no aValForTime with iteration:"<<theIter<<endl;
474 cout << "\tThe possible interations is aValField.keys():";
475 VISU::TValField::const_iterator aTmp = aValField.begin();
476 for(;aTmp != aValField.end(); aTmp++)
477 cout << aTmp->first << ",";