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"
29 #include "VisuGUI_Tools.h"
30 #include "VISU_Result_i.hh"
31 #include "VISU_ScalarMapOnDeformedShape_i.hh"
32 #include "VISU_ScalarMapOnDeformedShapePL.hxx"
33 #include "SalomeApp_Module.h"
34 #include "LightApp_SelectionMgr.h"
35 #include "SUIT_Desktop.h"
36 #include "VISU_ScalarMapPL.hxx"
38 #include "SALOME_ListIO.hxx"
40 #include "VISU_Convertor.hxx"
42 #include "SALOMEDSClient_AttributeComment.hxx"
43 #include "SALOMEDSClient_AttributeName.hxx"
46 #include <qtabwidget.h>
55 VisuGUI_ScalarMapOnDeformedShapeDlg::VisuGUI_ScalarMapOnDeformedShapeDlg (SalomeApp_Module* theModule)
56 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_ScalarMapOnDeformedShapeDlg", false,
57 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
61 setCaption(tr("DLG_TITLE"));
62 setSizeGripEnabled(TRUE);
64 QVBoxLayout* TopLayout = new QVBoxLayout (this);
65 TopLayout->setSpacing(6);
66 TopLayout->setMargin(11);
68 QTabWidget* aTabBox = new QTabWidget (this);
70 // Scalar Map on Deformed shape pane
71 QVBox* aBox = new QVBox (this);
73 QFrame* TopGroup = new QFrame (aBox, "TopGroup");
74 TopGroup->setFrameStyle(QFrame::Box | QFrame::Sunken);
75 TopGroup->setLineWidth(1);
76 QGridLayout* TopGroupLayout = new QGridLayout (TopGroup);
77 TopGroupLayout->setAlignment(Qt::AlignTop | Qt::AlignCenter);
78 TopGroupLayout->setSpacing(6);
79 TopGroupLayout->setMargin(11);
82 QLabel* ScaleLabel = new QLabel (tr("SCALE_FACTOR"), TopGroup, "ScaleLabel");
83 TopGroupLayout->addWidget(ScaleLabel, 0, 0);
85 ScalFact = new QtxDblSpinBox (0.0, 1.0E+38, 0.1, TopGroup);
86 ScalFact->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
87 ScalFact->setPrecision(5);
88 ScalFact->setValue(0.1);
89 TopGroupLayout->addWidget(ScalFact, 0, 1);
92 QLabel* FieldLabel = new QLabel (tr("FIELD_ITEM"), TopGroup, "FieldLabel");
93 myFieldsCombo = new QComboBox (TopGroup,"Fields");
95 TopGroupLayout->addWidget(FieldLabel, 1, 0);
96 TopGroupLayout->addWidget(myFieldsCombo,1,1);
98 // TimeStamps combo box
99 QLabel* TimeStampLabel = new QLabel (tr("TIMESTAMP_ITEM"), TopGroup, "TimeStampLabel");
100 myTimeStampsCombo = new QComboBox (TopGroup,"TimeStamp");
102 TopGroupLayout->addWidget(TimeStampLabel, 2, 0);
103 TopGroupLayout->addWidget(myTimeStampsCombo,2,1);
106 aTabBox->addTab(aBox, tr("SCALAR_MAP_ON_DEFORMED_SHAPE_TAB"));
109 myScalarPane = new VisuGUI_ScalarBarPane (this, false);
110 myScalarPane->setMargin(5);
112 aTabBox->addTab(myScalarPane, tr("SCALAR_BAR_TAB"));
115 QGroupBox* GroupButtons = new QGroupBox (this, "GroupButtons");
116 GroupButtons->setGeometry(QRect(10, 10, 281, 48));
117 GroupButtons->setColumnLayout(0, Qt::Vertical);
118 GroupButtons->layout()->setSpacing(0);
119 GroupButtons->layout()->setMargin(0);
120 QGridLayout* GroupButtonsLayout = new QGridLayout (GroupButtons->layout());
121 GroupButtonsLayout->setAlignment(Qt::AlignTop);
122 GroupButtonsLayout->setSpacing(6);
123 GroupButtonsLayout->setMargin(11);
125 QPushButton* buttonOk = new QPushButton (tr("&OK"), GroupButtons, "buttonOk");
126 buttonOk->setAutoDefault(TRUE);
127 buttonOk->setDefault(TRUE);
128 GroupButtonsLayout->addWidget(buttonOk, 0, 0);
130 GroupButtonsLayout->addItem(new QSpacerItem (5, 5, QSizePolicy::Expanding,
131 QSizePolicy::Minimum), 0, 1);
133 QPushButton* buttonCancel = new QPushButton (tr("&Cancel") , GroupButtons, "buttonCancel");
134 buttonCancel->setAutoDefault(TRUE);
135 GroupButtonsLayout->addWidget(buttonCancel, 0, 2);
137 // Add Tab box and Buttons to the top layout
138 TopLayout->addWidget(aTabBox);
139 TopLayout->addWidget(GroupButtons);
141 // signals and slots connections
142 connect(buttonOk, SIGNAL(clicked()), this, SLOT(accept()));
143 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(reject()));
144 connect(myFieldsCombo, SIGNAL(activated(int)), this, SLOT(onFieldChanged(int)));
145 connect(myTimeStampsCombo, SIGNAL(activated(int)), this, SLOT(onTimeStampChanged(int)));
149 void VisuGUI_ScalarMapOnDeformedShapeDlg::initFromPrsObject (VISU::ScalarMapOnDeformedShape_i* thePrs,bool isAnim)
153 setFactor(thePrs->GetScale());
154 myTimeStampsCombo->setDisabled(isAnim);
156 QString aFieldName(thePrs->GetScalarFieldName());
157 float aIterFloat = GetFloatValueOfTimeStamp(thePrs->GetMeshName().c_str(),
158 thePrs->GetScalarFieldName().c_str(),
159 thePrs->GetScalarIteration(),
160 thePrs->GetScalarEntity());
161 QString aIteration(QString("%1").arg(aIterFloat));
163 if (myMeshFieldsTimes.size() == 0)
165 // find all fields and time stamps on it
166 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
167 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
168 SALOME_ListIO selected;
169 aSel->selectedObjects(selected);
170 if (selected.Extent() > 0) {
171 Handle(SALOME_InteractiveObject) aIO = selected.First();
172 if (aIO->hasEntry()) {
173 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
174 aSObject = aSObject->GetFather();
175 aSObject = aSObject->GetFather();
176 aSObject = aSObject->GetFather();
177 aSObject = aSObject->GetFather();
178 mySelectionObj = aSObject;
179 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
180 VISU::Result_var aResult;
181 if (CORBA::is_nil(anObject)) {
182 mySelectionObj = mySelectionObj->GetFather();
184 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
186 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
187 _PTR(SObject) aChildSObj = aIter->Value();
188 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
190 _PTR(GenericAttribute) anAttr;
191 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
192 _PTR(AttributeComment) aComment (anAttr);
193 string aComm = aComment->Value();
194 QString strIn (aComm.c_str());
195 VISU::Storable::TRestoringMap aMap;
196 VISU::Storable::StrToMap(strIn,aMap);
198 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
200 if ((aType == VISU::TTIMESTAMP)) {
201 _PTR(GenericAttribute) aNameAttr;
202 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
203 _PTR(AttributeName) aName (aNameAttr);
204 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
205 QString aMeshName = VISU::getValue(aChildSObj,"myMeshName");
206 if(QString(thePrs->GetMeshName().c_str()) != aMeshName) continue;
207 myCurrMeshName = aMeshName;
208 QString aFieldName = VISU::getValue(aChildSObj,"myFieldName");
209 QString aTimeIter = VISU::getValue(aChildSObj,"myTimeStampId");
210 QString aEntity = VISU::getValue(aChildSObj,"myEntityId");
211 VISU::TEntity anEntity;
212 switch(aEntity.toInt()){
213 case 0: anEntity = VISU::NODE_ENTITY; break;
214 case 1: anEntity = VISU::EDGE_ENTITY; break;
215 case 2: anEntity = VISU::FACE_ENTITY; break;
216 case 3: anEntity = VISU::CELL_ENTITY; break;
218 TFT &aFieldsMap = myMeshFieldsTimes[aMeshName.latin1()];
219 TFE aKey(aFieldName.latin1(),anEntity);
220 aFieldsMap[aKey][aTimeIter.toInt()] =
221 GetFloatValueOfTimeStamp(myPrs->GetMeshName().c_str(),
236 myFieldsCombo->setCurrentText(aFieldName);
237 AddAllTimes(myFieldsCombo->currentText());
238 myTimeStampsCombo->setCurrentText(aIteration);
241 myScalarPane->initFromPrsObject(myPrs);
244 int VisuGUI_ScalarMapOnDeformedShapeDlg::storeToPrsObject(VISU::ScalarMapOnDeformedShape_i* thePrs, bool theUpdateScalar) {
246 thePrs->SetScale(getFactor());
248 thePrs->SetScalarField(myPrs->GetScalarMeshName().c_str(),
249 myPrs->GetScalarFieldName().c_str(),
250 myPrs->GetScalarIteration(),
251 myPrs->GetScalarEntity());
253 if (theUpdateScalar) SetScalarField();
255 thePrs->ShowColored(true);
257 myScalarPane->storeToPrsObject(thePrs);
264 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldNamePos(){
265 return myFieldsCombo->currentItem();
268 QString VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarFieldName(){
269 return myFieldsCombo->currentText();
272 int VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarNbIterations(){
273 return myTimeStampsCombo->count();
276 VISU::TEntity VisuGUI_ScalarMapOnDeformedShapeDlg::getCurrentScalarEntity(){
277 VISU::TEntity anEntity;
278 TFT::const_iterator aIterField = myMeshFieldsTimes[myCurrMeshName].begin();
279 for(;aIterField != myMeshFieldsTimes[myCurrMeshName].end();aIterField++){
280 if (aIterField->first.first == myFieldsCombo->currentText()){
281 anEntity = aIterField->first.second;
288 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(){
289 SetScalarField(myTimeStampsCombo->currentItem()+1);
292 void VisuGUI_ScalarMapOnDeformedShapeDlg::SetScalarField(int theIter,QString theFieldName){
296 if(theFieldName.isEmpty())
297 aFieldName = myFieldsCombo->currentText();
299 aFieldName = theFieldName;
301 VISU::TEntity anEntity = getCurrentScalarEntity();
303 myPrs->SetScalarField(myCurrMeshName.latin1(),
308 myScalarPane->storeToPrsObject(myPrs);
313 void VisuGUI_ScalarMapOnDeformedShapeDlg::accept()
315 if (myScalarPane->check()){
316 myScalarPane->deletePreview();
321 void VisuGUI_ScalarMapOnDeformedShapeDlg::reject()
323 myScalarPane->deletePreview();
327 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllFieldNames(){
328 TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin();
329 for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){
330 QString aMeshName = aIterMesh->first;
331 TFT::const_iterator aIterField = (aIterMesh->second).begin();
332 for(;aIterField != (aIterMesh->second).end(); aIterField++){
333 QString aFieldName = aIterField->first.first;
334 myFieldsCombo->insertItem(aFieldName);
339 void VisuGUI_ScalarMapOnDeformedShapeDlg::AddAllTimes(const QString& theFieldName){
340 TMF::const_iterator aIterMesh = myMeshFieldsTimes.begin();
341 for(;aIterMesh != myMeshFieldsTimes.end();aIterMesh++){
342 QString aMeshName = aIterMesh->first;
343 TFT::const_iterator aIterField = (aIterMesh->second).begin();
344 for(;aIterField != (aIterMesh->second).end(); aIterField++){
345 QString aFieldName = aIterField->first.first;
346 if(theFieldName != aFieldName) continue;
347 myTimeStampsCombo->clear();
348 TTL::const_iterator aTimeIter = (aIterField->second).begin();
349 for(;aTimeIter != (aIterField->second).end(); aTimeIter++)
350 myTimeStampsCombo->insertItem(QString("%1").arg(aTimeIter->second));
356 void VisuGUI_ScalarMapOnDeformedShapeDlg::onFieldChanged(int){
357 AddAllTimes(myFieldsCombo->currentText());
362 void VisuGUI_ScalarMapOnDeformedShapeDlg::onTimeStampChanged(int){
367 void VisuGUI_ScalarMapOnDeformedShapeDlg::UpdateScalarField(){
368 myPrs->SetScale(getFactor());
370 myPrs->GetScalarMapOnDeformedShapePL()->Build();
371 myPrs->GetScalarMapOnDeformedShapePL()->Update();
372 myPrs->GetScalarMapOnDeformedShapePL()->GetSourceRange(aRange);
373 double aDoubleRange[2];
374 aDoubleRange[0] = double(aRange[0]);
375 aDoubleRange[1] = double(aRange[1]);
376 myScalarPane->initFromPrsObject(myPrs);
377 myScalarPane->setRange(aDoubleRange[0],aDoubleRange[1],myScalarPane->isIRange());
380 float VisuGUI_ScalarMapOnDeformedShapeDlg::GetFloatValueOfTimeStamp(const char* theMeshName,
381 const char* theFieldName,
383 const VISU::TEntity theEntity){
385 VISU::Result_i* theResult = myPrs->GetResult();
386 VISU::PField aField = theResult->GetInput()->GetField(theMeshName,theEntity,theFieldName);
387 if(!aField) return ret;
388 VISU::TValField& aValField = aField->myValField;
389 VISU::TValField::const_iterator aIter = aValField.find(theIter);
390 if(aIter != aValField.end()){
391 VISU::PValForTime aValForTime = aIter->second;
392 ret = float(aValForTime->myTime.first);
395 cout << "Where are no aValForTime with iteration:"<<theIter<<endl;
396 cout << "\tThe possible interations is aValField.keys():";
397 VISU::TValField::const_iterator aTmp = aValField.begin();
398 for(;aTmp != aValField.end(); aTmp++)
399 cout << aTmp->first << ",";