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 "SalomeApp_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>
34 #include <SALOMEDS_SObject.hxx>
38 #include <qgroupbox.h>
39 #include <qcolordialog.h>
40 #include <qtabwidget.h>
44 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (SalomeApp_Module* theModule)
45 : QDialog(VISU::GetDesktop(theModule), "VisuGUI_StreamLinesDlg", false,
46 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
50 setCaption(tr("DLG_TITLE"));
51 setSizeGripEnabled(TRUE);
53 QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
54 aBoxLayout->setSpacing( 6 );
55 aBoxLayout->setMargin( 11 );
57 QTabWidget* aTabBox = new QTabWidget(this);
59 QFrame* aTopBox = new QFrame(this);
60 aTopBox->setMargin( 11 );
61 QGridLayout* TopLayout = new QGridLayout( aTopBox );
62 TopLayout->setAlignment( Qt::AlignTop );
63 TopLayout->setSpacing( 8 );
64 TopLayout->setMargin( 11 );
67 QGroupBox* aSourceBox = new QGroupBox (tr("SOURCE_GRP"), aTopBox);
68 aSourceBox->setColumnLayout(0, Qt::Vertical);
69 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox->layout() );
70 aSrcLayout->setSpacing( 6 );
71 aSrcLayout->setMargin( 0 );
73 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
74 aSrcLayout->addWidget(aTypeLbl, 0, 0);
76 myUseSrcCombo = new QComboBox(aSourceBox);
77 const char* aChoise[] = { "None", "Entity", "Family", "Group", "Presentation", 0 };
78 myUseSrcCombo->insertStrList(aChoise);
79 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
81 mySrcCombo = new QComboBox(aSourceBox);
82 mySrcCombo->setEnabled((myUseSrcCombo->currentItem() == 0));
84 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
87 //SUIT_Study* aActiveStudy = VISU::(myVisuGUI);
88 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
89 SalomeApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
90 SALOME_ListIO selected;
91 aSel->selectedObjects(selected);
92 if (selected.Extent() > 0) {
93 Handle(SALOME_InteractiveObject) aIO = selected.First();
94 if (aIO->hasEntry()) {
95 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
96 aSObject = aSObject->GetFather();
97 aSObject = aSObject->GetFather();
98 aSObject = aSObject->GetFather();
99 aSObject = aSObject->GetFather();
100 mySelectionObj = aSObject;
101 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
102 VISU::Result_var aResult;
103 if (CORBA::is_nil(anObject)) {
104 mySelectionObj = mySelectionObj->GetFather();
106 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
108 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
109 _PTR(SObject) aChildSObj = aIter->Value();
110 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
112 if (!CORBA::is_nil(aChildObject)) {
113 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
114 if (!CORBA::is_nil(aPrsObj)) { // if this is a Prs object
115 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
116 (aPrsObj->GetType() != VISU::TMESH)) {
117 _PTR(GenericAttribute) anAttr;
118 if (aChildSObj->FindAttribute(anAttr, "AttributeName")) {
119 _PTR(AttributeName) aName (anAttr);
120 myPrsLst += QString(aName->Value().c_str());
121 myPrsList.append(aPrsObj);
127 // else { // This is not a Prs object
128 _PTR(GenericAttribute) anAttr;
129 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
130 _PTR(AttributeComment) aComment (anAttr);
131 string aComm = aComment->Value();
132 QString strIn (aComm.c_str());
133 VISU::Storable::TRestoringMap aMap;
134 VISU::Storable::StrToMap(strIn,aMap);
136 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
138 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
139 _PTR(GenericAttribute) aNameAttr;
140 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
141 _PTR(AttributeName) aName (aNameAttr);
142 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
145 myFamilisLst += QString(aName->Value().c_str());
146 myFamilyList.append(aPrsObj);
149 myGroupsLst += QString(aName->Value().c_str());
150 myGroupList.append(aPrsObj);
153 myEntitiesLst += QString(aName->Value().c_str());
154 myEntityList.append(aPrsObj);
165 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
166 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
168 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
169 aSrcLayout->addWidget(aPercentLbl, 2, 0);
171 myPntPercent = new QtxDblSpinBox( 0, 1, 0.1, aSourceBox );
172 aSrcLayout->addWidget(myPntPercent, 2, 1);
174 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
176 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
177 TopLayout->addWidget(aStepLenLbl, 1, 0);
178 myStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
179 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180 TopLayout->addWidget(myStepLen, 1, 1);
181 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
183 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
184 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
185 myIntegStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
186 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
187 TopLayout->addWidget(myIntegStepLen, 2, 1);
188 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
190 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
191 TopLayout->addWidget(aPropagationLbl, 3, 0);
192 myPropTime = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 1, aTopBox );
193 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
194 TopLayout->addWidget(myPropTime, 3, 1);
195 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
197 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
198 TopLayout->addWidget(aDirLbl, 4, 0);
199 myDirCombo = new QComboBox(aTopBox);
200 myDirCombo->insertItem("Forward");
201 myDirCombo->insertItem("Backward");
202 myDirCombo->insertItem("Both");
203 TopLayout->addWidget(myDirCombo, 4, 1);
205 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox, "UseMagn");
206 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
207 TopLayout->addWidget(myUseScalar, 5, 0);
209 SelColor = new QPushButton (tr("USE_COLOR_BTN"), aTopBox, "SelColor");
210 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
211 TopLayout->addWidget( SelColor, 5, 1);
213 aTabBox->addTab(aTopBox, "Stream Lines");
214 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
215 myScalarPane->setMargin( 5 );
216 aTabBox->addTab(myScalarPane, "Scalar Bar");
218 aBoxLayout->addWidget(aTabBox);
220 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
221 aGroupButtons->setColumnLayout(0, Qt::Vertical );
222 aGroupButtons->layout()->setSpacing( 0 );
223 aGroupButtons->layout()->setMargin( 0 );
225 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
226 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
227 aGroupButtonsLayout->setSpacing( 6 );
228 aGroupButtonsLayout->setMargin( 11 );
230 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
231 aOkBtn->setAutoDefault( TRUE );
232 aOkBtn->setDefault( TRUE );
233 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
234 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
236 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
237 aCancelBtn->setAutoDefault( TRUE );
238 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
239 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
240 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
242 aBoxLayout->addWidget(aGroupButtons);
249 void VisuGUI_StreamLinesDlg::initFromPrsObject (VISU::StreamLines_i* thePrs)
251 myScalarPane->initFromPrsObject(thePrs);
254 static int aNbOfSteps = 30;
255 VISU_StreamLinesPL* aStreamLinesPL = thePrs->GetStreamLinesPL();
257 aMin = aStreamLinesPL->GetMinPropagationTime();
258 aMax = aStreamLinesPL->GetMaxPropagationTime();
259 myPropTime->setRange(aMin,aMax);
260 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
261 myPropTime->setLineStep((aMax-aMin)/aNbOfSteps);
263 aMin = aStreamLinesPL->GetMinStepLength();
264 aMax = aStreamLinesPL->GetMaxStepLength();
265 myStepLen->setRange(aMin,aMax);
266 myStepLen->setValue(aStreamLinesPL->GetStepLength());
267 myStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
269 aMin = aStreamLinesPL->GetMinIntegrationStep();
270 aMax = aStreamLinesPL->GetMaxIntegrationStep();
271 myIntegStepLen->setRange(aMin,aMax);
272 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
273 myIntegStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
275 switch (thePrs->GetDirection()) {
276 case VISU::StreamLines::FORWARD:
277 myDirCombo->setCurrentItem(0);
279 case VISU::StreamLines::BACKWARD:
280 myDirCombo->setCurrentItem(1);
282 case VISU::StreamLines::BOTH:
283 myDirCombo->setCurrentItem(2);
285 myUseScalar->setChecked(thePrs->IsColored());
286 myPntPercent->setValue(thePrs->GetUsedPoints());
288 mySrcCombo->setEnabled(false);
289 QString aSrcEntry = thePrs->GetSourceEntry();
291 SALOMEDS::Color anOldColor = thePrs->GetColor();
292 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
296 #define INITPRS(PRSLIST, PRSNUM) \
297 for (int i = 0; i < PRSLIST.count(); i++) { \
298 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
299 if (aPrs == NULL) continue; \
300 if (aSrcEntry == aPrs->GetEntry()) { \
301 onSourceTypeChange(PRSNUM); \
302 myUseSrcCombo->setCurrentItem(PRSNUM); \
303 mySrcCombo->setEnabled(true); \
304 mySrcCombo->setCurrentItem(i); \
309 if (!aSrcEntry.isEmpty()) {
310 INITPRS(myEntityList, 1);
311 INITPRS(myFamilyList, 2);
312 INITPRS(myGroupList, 3);
313 INITPRS(myPrsList, 4);
318 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::StreamLines_i* thePrs)
320 bool isAccepted = myScalarPane->storeToPrsObject(thePrs);
322 thePrs->ShowColored(myUseScalar->isChecked());
323 if (!thePrs->IsColored()) {
324 SALOMEDS::Color aColor;
325 aColor.R = myColor.red()/255.;
326 aColor.G = myColor.green()/255.;
327 aColor.B = myColor.blue()/255.;
328 thePrs->SetColor(aColor);
331 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
332 switch (myDirCombo->currentItem()) {
334 aDirection = VISU::StreamLines::FORWARD;
337 aDirection = VISU::StreamLines::BACKWARD;
340 aDirection = VISU::StreamLines::BOTH;
343 VISU::Prs3d_var aPrs;
344 int aSrcSelection = myUseSrcCombo->currentItem();
345 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
346 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
347 VISU::VISUType aType;
349 switch (aSrcSelection) {
351 aPrs = myEntityList[aSrcItem];
352 aType = VISU::TENTITY;
353 aName = myEntitiesLst[aSrcItem];
356 aPrs = myFamilyList[aSrcItem];
357 aType = VISU::TFAMILY;
358 aName = myFamilisLst[aSrcItem];
361 aPrs = myGroupList[aSrcItem];
362 aType = VISU::TGROUP;
363 aName = myGroupsLst[aSrcItem];
365 case 4: // Presentation
366 aPrs = myPrsList[aSrcItem];
369 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
370 aPrs = createMesh(aType, aName);
373 isAccepted = thePrs->SetParams(myIntegStepLen->value(),
377 myPntPercent->value(),
381 // SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("WRN_VISU"),
382 // tr("ERR_CANT_BUILD_PRESENTATION"),
390 void VisuGUI_StreamLinesDlg::setColor( QColor color )
393 SelColor->setPaletteBackgroundColor(myColor);
398 Called when "Select Color" buttonx clicked
400 void VisuGUI_StreamLinesDlg::setVColor()
402 QColor cnew = QColorDialog::getColor( myColor, this );
403 if ( cnew.isValid() )
409 Enbled/disables magnitude coloring
411 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
413 myUseScalar->setEnabled( enable );
418 Called when "Magnitude Coloring" check box clicked
420 void VisuGUI_StreamLinesDlg::enableSetColor()
422 SelColor->setEnabled(!myUseScalar->isChecked() );
425 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
428 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
431 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
432 myStepLen->setMaxValue(theValue);
435 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
438 mySrcCombo->setEnabled(false);
441 mySrcCombo->setEnabled(true);
445 mySrcCombo->insertStringList(myEntitiesLst);
448 mySrcCombo->insertStringList(myFamilisLst);
451 mySrcCombo->insertStringList(myGroupsLst);
453 case 4: // Presentation
454 mySrcCombo->insertStringList(myPrsLst);
460 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
462 return VISU::Mesh::_nil();
464 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
465 VISU::Result_var aResult;
466 if (!CORBA::is_nil(anObject)) {
467 aResult = VISU::Result::_narrow(anObject);
469 if (CORBA::is_nil(aResult)) {
470 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
471 tr("WRN_NO_AVAILABLE_DATA"),
473 return VISU::Mesh::_nil();
475 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
476 VISU::Storable::TRestoringMap aMap;
478 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
479 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
480 SALOMEDSClient_GenericAttribute* anAttr;
481 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
482 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
483 CORBA::String_var aComm = aComment->Value().c_str();
484 QString strIn(aComm.in());
486 VISU::Storable::StrToMap(strIn,aMap);
488 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
490 if (aType != theType) continue;
492 SALOMEDSClient_GenericAttribute* aNameAttr;
493 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
494 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>(aNameAttr);
495 if (QString(aName->Value()) == theName) break; //use current map
500 VISU::Mesh_var aMesh;
501 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
505 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
506 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
511 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
516 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
517 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
521 if(!CORBA::is_nil(aMesh)){ // Create Actor
522 VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
523 if(SVTK_ViewWindow* vf = VISU::GetViewWindow()){
525 pPresent->SetPresentationType(VISU::POINT);
526 VISU_Actor *anActor = pPresent->CreateActor();
527 vf->AddActor(anActor);
529 SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr("VISU_WARNING"),
530 tr("ERR_CANT_CREATE_ACTOR"),
535 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
536 tr("ERR_CANT_BUILD_PRESENTATION"),
539 return aMesh._retn();
543 void VisuGUI_StreamLinesDlg::accept() {
544 if (myScalarPane->check())