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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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_SelectionMgr.h"
42 #include "SUIT_Desktop.h"
44 #include "SALOME_ListIO.hxx"
46 #include "SALOMEDSClient_AttributeComment.hxx"
47 #include "SALOMEDSClient_AttributeName.hxx"
50 #include <qtabwidget.h>
59 VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule)
60 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_ScalarMapOnDeformedShapeDlg", false,
61 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
66 setCaption(tr("DLG_TITLE"));
67 setSizeGripEnabled(TRUE);
69 QVBoxLayout* TopLayout = new QVBoxLayout (this);
70 TopLayout->setSpacing(6);
71 TopLayout->setMargin(11);
73 QTabWidget* aTabBox = new QTabWidget (this);
75 // Scalar Map on Deformed shape pane
76 QVBox* aBox = new QVBox (this);
78 QFrame* TopGroup = new QFrame (aBox, "TopGroup");
79 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
80 TopGroup->setLineWidth(1);
81 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
82 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
83 TopGroupLayout->setSpacing(6);
84 TopGroupLayout->setMargin(11);
87 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel");
88 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
90 ScalFact = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, TopGroup);
91 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
92 ScalFact->setPrecision(5);
93 ScalFact->setValue(0.1);
94 TopGroupLayout->addWidget(ScalFact, 0, 1);
97 QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup, "FieldLabel");
98 myFieldsCombo = new QComboBox (TopGroup,"Fields");
100 TopGroupLayout->addWidget(FieldLabel, 1, 0);
101 TopGroupLayout->addWidget(myFieldsCombo,1,1);
103 // TimeStamps combo box
104 QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup, "TimeStampLabel");
105 myTimeStampsCombo = new QComboBox (TopGroup,"TimeStamp");
107 TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
108 TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
111 aTabBox->addTab(aBox, tr("SCALAR_MAP_ON_DEFORMED_SHAPE_TAB"));
114 myScalarPane = new VisuGUI_ScalarBarPane (this, false);
115 myScalarPane->setMargin(5);
117 aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
120 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
121 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
122 GroupButtons->setColumnLayout(0, Qt::Vertical);
123 GroupButtons->layout()->setSpacing(0);
124 GroupButtons->layout()->setMargin(0);
125 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
126 GroupButtonsLayout->setAlignment(Qt::AlignTop);
127 GroupButtonsLayout->setSpacing(6);
128 GroupButtonsLayout->setMargin(11);
130 QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk");
131 buttonOk->setAutoDefault(TRUE);
132 buttonOk->setDefault(TRUE);
133 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
135 GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding,
136 QSizePolicy::Minimum), 0, 1);
138 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel");
139 buttonCancel->setAutoDefault(TRUE);
140 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
142 // Add Tab box and Buttons to the top layout
143 TopLayout->addWidget(aTabBox);
144 TopLayout->addWidget(GroupButtons);
146 // signals and slots connections
147 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
148 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
149 connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
150 connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
153 void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject
154 (VISU::ScalarMapOnDeformedShape_i* thePrs, bool isAnim)
156 myIsAnimation = isAnim;
159 setFactor(myPrs->GetScale());
160 myTimeStampsCombo->setDisabled(isAnim);
162 QString aFieldName(myPrs->GetScalarFieldName());
163 float aIterFloat = GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
164 myPrs->GetScalarFieldName().c_str(),
165 myPrs->GetScalarIteration(),
166 myPrs->GetScalarEntity());
167 QString aIteration(QString("%1").arg(aIterFloat));
169 if (myMeshFieldsTimes.size() == 0)
171 // find all fields and time stamps on it
172 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
173 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
174 SALOME_ListIO selected;
175 aSel->selectedObjects(selected);
176 if (selected.Extent() > 0) {
177 Handle(SALOME_InteractiveObject) aIO = selected.First();
178 if (aIO->hasEntry()) {
179 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
181 _PTR(GenericAttribute) anTmpAttr;
182 if (aSObject->FindAttribute(anTmpAttr, "AttributeComment")) {
183 _PTR(AttributeComment) aTmpComment (anTmpAttr);
184 string aTmpComm = aTmpComment->Value();
185 QString aTmpstrIn (aTmpComm.c_str());
186 VISU::Storable::TRestoringMap aTmpaMap;
187 VISU::Storable::StrToMap(aTmpstrIn,aTmpaMap);
189 VISU::VISUType aTmpType =
190 (VISU::VISUType)VISU::Storable::FindValue(aTmpaMap,"myType",&aTmpisExist).toInt();
192 case VISU::TTIMESTAMP:
194 aSObject = aSObject->GetFather();
195 aSObject = aSObject->GetFather();
200 _PTR(SObject) newSObject;
201 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
202 aSObject = aSObject->GetFather();
205 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();
222 aSObject = aSObject->GetFather();
223 aSObject = aSObject->GetFather();
225 mySelectionObj = aSObject;
226 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
227 if (CORBA::is_nil(anObject)) {
228 mySelectionObj = mySelectionObj->GetFather();
233 if (mySelectionObj) {
234 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
236 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
237 _PTR(SObject) aChildSObj = aIter->Value();
238 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
240 _PTR(GenericAttribute) anAttr;
241 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
242 _PTR(AttributeComment) aComment (anAttr);
243 string aComm = aComment->Value();
244 QString strIn (aComm.c_str());
245 VISU::Storable::TRestoringMap aMap;
246 VISU::Storable::StrToMap(strIn,aMap);
248 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
250 if ((aType == VISU::TTIMESTAMP)) {
251 _PTR(GenericAttribute) aNameAttr;
252 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
253 _PTR(AttributeName) aName (aNameAttr);
254 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
255 QString aMeshName = VISU::getValue(aChildSObj, "myMeshName");
256 if (QString(myPrs->GetMeshName().c_str()) != aMeshName) continue;
257 myCurrMeshName = aMeshName;
258 QString aFieldName = VISU::getValue(aChildSObj, "myFieldName");
259 QString aTimeIter = VISU::getValue(aChildSObj, "myTimeStampId");
260 QString aEntity = VISU::getValue(aChildSObj, "myEntityId");
261 VISU::TEntity anEntity;
262 switch (aEntity.toInt()) {
263 case 0: anEntity = VISU::NODE_ENTITY; break;
264 case 1: anEntity = VISU::EDGE_ENTITY; break;
265 case 2: anEntity = VISU::FACE_ENTITY; break;
266 case 3: anEntity = VISU::CELL_ENTITY; break;
268 TFT &aFieldsMap = myMeshFieldsTimes[aMeshName.latin1()];
269 TFE aKey (aFieldName.latin1(), anEntity);
270 aFieldsMap[aKey][aTimeIter.toInt()] =
271 GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
284 myFieldsCombo->setCurrentText(aFieldName);
285 AddAllTimes(myFieldsCombo->currentText());
286 myTimeStampsCombo->setCurrentText(aIteration);
289 myScalarPane->initFromPrsObject(myPrs);
292 int VisuGUI_ScalarMapOnDeformedShapeDlg::storeToPrsObject
293 (VISU::ScalarMapOnDeformedShape_i* thePrs, bool theUpdateScalars, int theIter)
295 thePrs->SetScale(getFactor());
298 thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
299 getCurrentScalarFieldName().latin1(),
301 myPrs->GetScalarEntity());
303 thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
304 getCurrentScalarFieldName().latin1(),
305 myTimeStampsCombo->currentItem() + 1,
306 myPrs->GetScalarEntity());
308 if (theUpdateScalars) SetScalarField();
310 thePrs->ShowColored(true);
312 myScalarPane->storeToPrsObject(thePrs);
319 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldNamePos(){
320 return myFieldsCombo->currentItem();
323 QString VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldName(){
324 return myFieldsCombo->currentText();
327 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarNbIterations(){
328 return myTimeStampsCombo->count();
331 VISU::TEntity VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarEntity(){
332 VISU::TEntity anEntity;
333 TFT::const_iterator aIterField = myMeshFieldsTimes[myCurrMeshName].begin();
334 for(;aIterField != myMeshFieldsTimes[myCurrMeshName].end();aIterField++){
335 if (aIterField->first.first == myFieldsCombo->currentText()){
336 anEntity = aIterField->first.second;
343 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(){
344 SetScalarField(myTimeStampsCombo->currentItem()+1);
347 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(int theIter,QString theFieldName){
351 if(theFieldName.isEmpty())
352 aFieldName = myFieldsCombo->currentText();
354 aFieldName = theFieldName;
356 VISU::TEntity anEntity = getCurrentScalarEntity();
358 myPrs->SetScalarField(myCurrMeshName.latin1(),
363 myScalarPane->storeToPrsObject(myPrs);
368 void VisuGUI_ScalarMapOnDeformedShapeDlg::accept()
370 if (myScalarPane->check()){
371 myScalarPane->deletePreview();
376 void VisuGUI_ScalarMapOnDeformedShapeDlg::reject()
378 myScalarPane->deletePreview();
382 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllFieldNames(){
383 TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin();
384 for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){
385 QString aMeshName = aIterMesh->first;
386 TFT::const_iterator aIterField = (aIterMesh->second).begin();
387 for(;aIterField != (aIterMesh->second).end(); aIterField++){
388 QString aFieldName = aIterField->first.first;
389 myFieldsCombo->insertItem(aFieldName);
394 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllTimes(const QString& theFieldName){
395 TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin();
396 for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){
397 QString aMeshName = aIterMesh->first;
398 TFT::const_iterator aIterField = (aIterMesh->second).begin();
399 for(;aIterField != (aIterMesh->second).end(); aIterField++){
400 QString aFieldName = aIterField->first.first;
401 if(theFieldName != aFieldName) continue;
402 myTimeStampsCombo->clear();
403 TTL::const_iterator aTimeIter = (aIterField->second).begin();
404 for(;aTimeIter != (aIterField->second).end(); aTimeIter++)
405 myTimeStampsCombo->insertItem(QString("%1").arg(aTimeIter->second));
411 void VisuGUI_ScalarMapOnDeformedShapeDlg::onFieldChanged(int){
412 AddAllTimes(myFieldsCombo->currentText());
417 void VisuGUI_ScalarMapOnDeformedShapeDlg::onTimeStampChanged(int){
422 void VisuGUI_ScalarMapOnDeformedShapeDlg::UpdateScalarField(){
423 myPrs->SetScale(getFactor());
425 myPrs->GetScalarMapOnDeformedShapePL()->Build();
426 myPrs->GetScalarMapOnDeformedShapePL()->Update();
427 myPrs->GetScalarMapOnDeformedShapePL()->GetSourceRange(aRange);
428 double aDoubleRange[2];
429 aDoubleRange[0] = double(aRange[0]);
430 aDoubleRange[1] = double(aRange[1]);
431 myScalarPane->initFromPrsObject(myPrs);
432 myScalarPane->setRange(aDoubleRange[0],aDoubleRange[1],myScalarPane->isIRange());
435 float VisuGUI_ScalarMapOnDeformedShapeDlg::GetFloatValueOfTimeStamp(const char* theMeshName,
436 const char* theFieldName,
438 const VISU::TEntity theEntity){
440 VISU::Result_i* theResult = myPrs->GetResult();
441 VISU::PField aField = theResult->GetInput()->GetField(theMeshName,theEntity,theFieldName);
442 if(!aField) return ret;
443 VISU::TValField& aValField = aField->myValField;
444 VISU::TValField::const_iterator aIter = aValField.find(theIter);
445 if(aIter != aValField.end()){
446 VISU::PValForTime aValForTime = aIter->second;
447 ret = float(aValForTime->myTime.first);
450 cout << "Where are no aValForTime with iteration:"<<theIter<<endl;
451 cout << "\tThe possible interations is aValField.keys():";
452 VISU::TValField::const_iterator aTmp = aValField.begin();
453 for(;aTmp != aValField.end(); aTmp++)
454 cout << aTmp->first << ",";