1 // VISU VISUGUI : GUI of VISU component
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : VisuGUI_StreamLinesDlg.cxx
8 // Author : Vitaly SMETANNIKOV
11 #include "VisuGUI_StreamLinesDlg.h"
14 #include "VisuGUI_Tools.h"
16 #include "VISU_Mesh_i.hh"
17 #include "VISU_Gen_i.hh"
18 #include "VISU_StreamLines_i.hh"
19 #include "VISU_StreamLinesPL.hxx"
20 #include "VISU_Actor.h"
22 #include "SalomeApp_Application.h"
23 #include "LightApp_SelectionMgr.h"
25 #include "SVTK_ViewWindow.h"
27 #include "SUIT_Desktop.h"
28 #include "SUIT_ResourceMgr.h"
29 #include "SUIT_MessageBox.h"
31 #include "SALOME_ListIO.hxx"
33 #include <SALOMEDSClient_SObject.hxx>
37 #include <qgroupbox.h>
38 #include <qcolordialog.h>
39 #include <qtabwidget.h>
43 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (SalomeApp_Module* theModule)
44 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_StreamLinesDlg", false,
45 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
49 setCaption(tr("DLG_TITLE"));
50 setSizeGripEnabled(TRUE);
52 QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
53 aBoxLayout->setSpacing( 6 );
54 aBoxLayout->setMargin( 11 );
56 QTabWidget* aTabBox = new QTabWidget(this);
58 QFrame* aTopBox = new QFrame(this);
59 aTopBox->setMargin( 11 );
60 QGridLayout* TopLayout = new QGridLayout( aTopBox );
61 TopLayout->setAlignment( Qt::AlignTop );
62 TopLayout->setSpacing( 8 );
63 TopLayout->setMargin( 11 );
66 QGroupBox* aSourceBox = new QGroupBox (tr("SOURCE_GRP"), aTopBox);
67 aSourceBox->setColumnLayout(0, Qt::Vertical);
68 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox->layout() );
69 aSrcLayout->setSpacing( 6 );
70 aSrcLayout->setMargin( 0 );
72 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
73 aSrcLayout->addWidget(aTypeLbl, 0, 0);
75 myUseSrcCombo = new QComboBox(aSourceBox);
76 const char* aChoise[] = { "None", "Entity", "Family", "Group", "Presentation", 0 };
77 myUseSrcCombo->insertStrList(aChoise);
78 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
80 mySrcCombo = new QComboBox(aSourceBox);
81 mySrcCombo->setEnabled((myUseSrcCombo->currentItem() == 0));
83 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
85 // Find all fields and time stamps on it
86 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
87 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
88 SALOME_ListIO selected;
89 aSel->selectedObjects(selected);
90 if (selected.Extent() > 0) {
91 Handle(SALOME_InteractiveObject) aIO = selected.First();
92 if (aIO->hasEntry()) {
93 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
95 _PTR(GenericAttribute) anTmpAttr;
96 if (aSObject->FindAttribute(anTmpAttr, "AttributeComment")) {
97 _PTR(AttributeComment) aTmpComment (anTmpAttr);
98 string aTmpComm = aTmpComment->Value();
99 QString aTmpstrIn (aTmpComm.c_str());
100 VISU::Storable::TRestoringMap aTmpaMap;
101 VISU::Storable::StrToMap(aTmpstrIn,aTmpaMap);
103 VISU::VISUType aTmpType =
104 (VISU::VISUType)VISU::Storable::FindValue(aTmpaMap,"myType",&aTmpisExist).toInt();
106 case VISU::TTIMESTAMP:
108 aSObject = aSObject->GetFather();
109 aSObject = aSObject->GetFather();
114 _PTR(SObject) newSObject;
115 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
116 aSObject = aSObject->GetFather();
119 case VISU::TANIMATION:
121 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
122 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
123 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
124 _PTR(SObject) newSObject;
125 if(aTmpChildSObj->ReferencedObject(newSObject)){
126 aSObject = newSObject;
127 aSObject->GetFather();
136 aSObject = aSObject->GetFather();
137 aSObject = aSObject->GetFather();
139 mySelectionObj = aSObject;
140 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
141 if (CORBA::is_nil(anObject)) {
142 mySelectionObj = mySelectionObj->GetFather();
147 if (mySelectionObj) {
148 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
150 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
151 _PTR(SObject) aChildSObj = aIter->Value();
152 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
154 if (!CORBA::is_nil(aChildObject)) {
155 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
156 if (!CORBA::is_nil(aPrsObj)) { // if this is a Prs object
157 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
158 (aPrsObj->GetType() != VISU::TMESH)) {
159 _PTR(GenericAttribute) anAttr;
160 if (aChildSObj->FindAttribute(anAttr, "AttributeName")) {
161 _PTR(AttributeName) aName (anAttr);
162 myPrsLst += QString(aName->Value().c_str());
163 myPrsList.append(aPrsObj);
170 _PTR(GenericAttribute) anAttr;
171 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
172 _PTR(AttributeComment) aComment (anAttr);
173 string aComm = aComment->Value();
174 QString strIn (aComm.c_str());
175 VISU::Storable::TRestoringMap aMap;
176 VISU::Storable::StrToMap(strIn,aMap);
178 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
180 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
181 _PTR(GenericAttribute) aNameAttr;
182 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
183 _PTR(AttributeName) aName (aNameAttr);
184 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
187 myFamilisLst += QString(aName->Value().c_str());
188 myFamilyList.append(aPrsObj);
191 myGroupsLst += QString(aName->Value().c_str());
192 myGroupList.append(aPrsObj);
195 myEntitiesLst += QString(aName->Value().c_str());
196 myEntityList.append(aPrsObj);
206 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
207 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
209 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
210 aSrcLayout->addWidget(aPercentLbl, 2, 0);
212 myPntPercent = new QtxDblSpinBox( 0, 1, 0.1, aSourceBox );
213 aSrcLayout->addWidget(myPntPercent, 2, 1);
215 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
217 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
218 TopLayout->addWidget(aStepLenLbl, 1, 0);
219 myStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
220 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
221 TopLayout->addWidget(myStepLen, 1, 1);
222 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
224 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
225 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
226 myIntegStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
227 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
228 TopLayout->addWidget(myIntegStepLen, 2, 1);
229 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
231 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
232 TopLayout->addWidget(aPropagationLbl, 3, 0);
233 myPropTime = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 1, aTopBox );
234 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
235 TopLayout->addWidget(myPropTime, 3, 1);
236 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
238 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
239 TopLayout->addWidget(aDirLbl, 4, 0);
240 myDirCombo = new QComboBox(aTopBox);
241 myDirCombo->insertItem("Forward");
242 myDirCombo->insertItem("Backward");
243 myDirCombo->insertItem("Both");
244 TopLayout->addWidget(myDirCombo, 4, 1);
246 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox, "UseMagn");
247 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
248 TopLayout->addWidget(myUseScalar, 5, 0);
250 SelColor = new QPushButton (tr("USE_COLOR_BTN"), aTopBox, "SelColor");
251 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
252 TopLayout->addWidget( SelColor, 5, 1);
254 aTabBox->addTab(aTopBox, "Stream Lines");
255 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
256 myScalarPane->setMargin( 5 );
257 aTabBox->addTab(myScalarPane, "Scalar Bar");
259 aBoxLayout->addWidget(aTabBox);
261 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
262 aGroupButtons->setColumnLayout(0, Qt::Vertical );
263 aGroupButtons->layout()->setSpacing( 0 );
264 aGroupButtons->layout()->setMargin( 0 );
266 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
267 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
268 aGroupButtonsLayout->setSpacing( 6 );
269 aGroupButtonsLayout->setMargin( 11 );
271 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
272 aOkBtn->setAutoDefault( TRUE );
273 aOkBtn->setDefault( TRUE );
274 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
275 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
277 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
278 aCancelBtn->setAutoDefault( TRUE );
279 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
280 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
281 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
283 aBoxLayout->addWidget(aGroupButtons);
289 void VisuGUI_StreamLinesDlg::initFromPrsObject (VISU::StreamLines_i* thePrs)
291 myScalarPane->initFromPrsObject(thePrs);
294 static int aNbOfSteps = 30;
295 VISU_StreamLinesPL* aStreamLinesPL = thePrs->GetStreamLinesPL();
297 aMin = aStreamLinesPL->GetMinPropagationTime();
298 aMax = aStreamLinesPL->GetMaxPropagationTime();
299 myPropTime->setRange(aMin,aMax);
300 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
301 myPropTime->setLineStep((aMax-aMin)/aNbOfSteps);
303 aMin = aStreamLinesPL->GetMinStepLength();
304 aMax = aStreamLinesPL->GetMaxStepLength();
305 myStepLen->setRange(aMin,aMax);
306 myStepLen->setValue(aStreamLinesPL->GetStepLength());
307 myStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
309 aMin = aStreamLinesPL->GetMinIntegrationStep();
310 aMax = aStreamLinesPL->GetMaxIntegrationStep();
311 myIntegStepLen->setRange(aMin,aMax);
312 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
313 myIntegStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
315 switch (thePrs->GetDirection()) {
316 case VISU::StreamLines::FORWARD:
317 myDirCombo->setCurrentItem(0);
319 case VISU::StreamLines::BACKWARD:
320 myDirCombo->setCurrentItem(1);
322 case VISU::StreamLines::BOTH:
323 myDirCombo->setCurrentItem(2);
325 myUseScalar->setChecked(thePrs->IsColored());
326 myPntPercent->setValue(thePrs->GetUsedPoints());
328 mySrcCombo->setEnabled(false);
329 QString aSrcEntry = thePrs->GetSourceEntry();
331 SALOMEDS::Color anOldColor = thePrs->GetColor();
332 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
336 #define INITPRS(PRSLIST, PRSNUM) \
337 for (int i = 0; i < PRSLIST.count(); i++) { \
338 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
339 if (aPrs == NULL) continue; \
340 if (aSrcEntry == aPrs->GetEntry()) { \
341 onSourceTypeChange(PRSNUM); \
342 myUseSrcCombo->setCurrentItem(PRSNUM); \
343 mySrcCombo->setEnabled(true); \
344 mySrcCombo->setCurrentItem(i); \
349 if (!aSrcEntry.isEmpty()) {
350 INITPRS(myEntityList, 1);
351 INITPRS(myFamilyList, 2);
352 INITPRS(myGroupList, 3);
353 INITPRS(myPrsList, 4);
358 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::StreamLines_i* thePrs)
360 bool isAccepted = myScalarPane->storeToPrsObject(thePrs);
362 thePrs->ShowColored(myUseScalar->isChecked());
363 if (!thePrs->IsColored()) {
364 SALOMEDS::Color aColor;
365 aColor.R = myColor.red()/255.;
366 aColor.G = myColor.green()/255.;
367 aColor.B = myColor.blue()/255.;
368 thePrs->SetColor(aColor);
371 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
372 switch (myDirCombo->currentItem()) {
374 aDirection = VISU::StreamLines::FORWARD;
377 aDirection = VISU::StreamLines::BACKWARD;
380 aDirection = VISU::StreamLines::BOTH;
383 VISU::Prs3d_var aPrs;
384 int aSrcSelection = myUseSrcCombo->currentItem();
385 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
386 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
387 VISU::VISUType aType;
389 switch (aSrcSelection) {
391 aPrs = myEntityList[aSrcItem];
392 aType = VISU::TENTITY;
393 aName = myEntitiesLst[aSrcItem];
396 aPrs = myFamilyList[aSrcItem];
397 aType = VISU::TFAMILY;
398 aName = myFamilisLst[aSrcItem];
401 aPrs = myGroupList[aSrcItem];
402 aType = VISU::TGROUP;
403 aName = myGroupsLst[aSrcItem];
405 case 4: // Presentation
406 aPrs = myPrsList[aSrcItem];
409 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
410 aPrs = createMesh(aType, aName);
413 isAccepted = thePrs->SetParams(myIntegStepLen->value(),
417 myPntPercent->value(),
421 // SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("WRN_VISU"),
422 // tr("ERR_CANT_BUILD_PRESENTATION"),
430 void VisuGUI_StreamLinesDlg::setColor( QColor color )
433 SelColor->setPaletteBackgroundColor(myColor);
438 Called when "Select Color" buttonx clicked
440 void VisuGUI_StreamLinesDlg::setVColor()
442 QColor cnew = QColorDialog::getColor( myColor, this );
443 if ( cnew.isValid() )
449 Enbled/disables magnitude coloring
451 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
453 myUseScalar->setEnabled( enable );
458 Called when "Magnitude Coloring" check box clicked
460 void VisuGUI_StreamLinesDlg::enableSetColor()
462 SelColor->setEnabled(!myUseScalar->isChecked() );
465 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
468 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
471 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
472 myStepLen->setMaxValue(theValue);
475 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
478 mySrcCombo->setEnabled(false);
481 mySrcCombo->setEnabled(true);
485 mySrcCombo->insertStringList(myEntitiesLst);
488 mySrcCombo->insertStringList(myFamilisLst);
491 mySrcCombo->insertStringList(myGroupsLst);
493 case 4: // Presentation
494 mySrcCombo->insertStringList(myPrsLst);
500 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
502 return VISU::Mesh::_nil();
504 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
505 VISU::Result_var aResult;
506 if (!CORBA::is_nil(anObject)) {
507 aResult = VISU::Result::_narrow(anObject);
509 if (CORBA::is_nil(aResult)) {
510 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
511 tr("WRN_NO_AVAILABLE_DATA"),
513 return VISU::Mesh::_nil();
515 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
516 VISU::Storable::TRestoringMap aMap;
518 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
519 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
520 SALOMEDSClient_GenericAttribute* anAttr;
521 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
522 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
523 CORBA::String_var aComm = aComment->Value().c_str();
524 QString strIn(aComm.in());
526 VISU::Storable::StrToMap(strIn,aMap);
528 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
530 if (aType != theType) continue;
532 SALOMEDSClient_GenericAttribute* aNameAttr;
533 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
534 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>(aNameAttr);
535 if (QString(aName->Value()) == theName) break; //use current map
540 VISU::Mesh_var aMesh;
541 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
545 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
546 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
551 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
556 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
557 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
561 if(!CORBA::is_nil(aMesh)){ // Create Actor
562 VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
563 if(SVTK_ViewWindow* vf = VISU::GetViewWindow()){
565 pPresent->SetPresentationType(VISU::POINT);
566 VISU_Actor *anActor = pPresent->CreateActor();
567 vf->AddActor(anActor);
569 SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr("VISU_WARNING"),
570 tr("ERR_CANT_CREATE_ACTOR"),
575 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
576 tr("ERR_CANT_BUILD_PRESENTATION"),
579 return aMesh._retn();
583 void VisuGUI_StreamLinesDlg::accept() {
584 if (myScalarPane->check())
586 myScalarPane->deletePreview();
591 void VisuGUI_StreamLinesDlg::reject()
593 myScalarPane->deletePreview();