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"
12 #include "VISU_StreamLines_i.hh"
13 #include "VISU_Mesh_i.hh"
14 #include "VISU_Gen_i.hh"
15 #include "VISU_StreamLinesPL.hxx"
16 #include "VISU_Actor.h"
18 #include "QAD_Application.h"
19 #include "QAD_Desktop.h"
20 #include "QAD_Config.h"
21 #include "QAD_MessageBox.h"
23 #include "SALOME_Selection.h"
24 #include "VTKViewer_ViewFrame.h"
28 #include <qgroupbox.h>
29 #include <qcolordialog.h>
30 #include <qtabwidget.h>
35 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg()
36 : QDialog( QAD_Application::getDesktop(), "VisuGUI_StreamLinesDlg", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
39 setCaption("Stream lines Preferences");
40 setSizeGripEnabled( TRUE );
42 QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
43 aBoxLayout->setSpacing( 6 );
44 aBoxLayout->setMargin( 11 );
46 QTabWidget* aTabBox = new QTabWidget(this);
48 QFrame* aTopBox = new QFrame(this);
49 aTopBox->setMargin( 11 );
50 QGridLayout* TopLayout = new QGridLayout( aTopBox );
51 TopLayout->setAlignment( Qt::AlignTop );
52 TopLayout->setSpacing( 8 );
53 TopLayout->setMargin( 11 );
56 QGroupBox* aSourceBox = new QGroupBox(tr("Source"), aTopBox);
57 aSourceBox->setColumnLayout(0, Qt::Vertical);
58 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox->layout() );
59 aSrcLayout->setSpacing( 6 );
60 aSrcLayout->setMargin( 0 );
62 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
63 aSrcLayout->addWidget(aTypeLbl, 0, 0);
65 myUseSrcCombo = new QComboBox(aSourceBox);
66 const char* aChoise[] = { "None", "Entity", "Family", "Group", "Presentation", 0 };
67 myUseSrcCombo->insertStrList(aChoise);
68 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
70 mySrcCombo = new QComboBox(aSourceBox);
71 mySrcCombo->setEnabled((myUseSrcCombo->currentItem() == 0));
73 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
76 QAD_Study* aActiveStudy = VisuGUI::GetActiveStudy();
77 SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
78 if( aSel->IObjectCount() > 0 ) {
79 Handle(SALOME_InteractiveObject) aIO = aSel->firstIObject();
81 SALOMEDS::SObject_var aSObject = VisuGUI::GetStudyDocument()->FindObjectID(aIO->getEntry());
82 aSObject = aSObject->GetFather();
83 aSObject = aSObject->GetFather();
84 aSObject = aSObject->GetFather();
85 aSObject = aSObject->GetFather();
86 mySelectionObj = aSObject;
87 CORBA::Object_var anObject = VISU::SObjectToObject(mySelectionObj);
88 VISU::Result_var aResult;
89 if (CORBA::is_nil(anObject)) {
90 mySelectionObj = mySelectionObj->GetFather();
92 SALOMEDS::ChildIterator_var aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
94 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
95 SALOMEDS::SObject_var aChildSObj = aIter->Value();
96 CORBA::Object_var aChildObject = VISU::SObjectToObject( aChildSObj );
98 if(!CORBA::is_nil( aChildObject ) ) {
99 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
100 if( !CORBA::is_nil( aPrsObj ) ) { // if this is a Prs object
101 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
102 (aPrsObj->GetType() != VISU::TMESH)) {
103 SALOMEDS::GenericAttribute_var anAttr;
104 if ( aChildSObj->FindAttribute(anAttr, "AttributeName") ) {
105 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
106 myPrsLst += QString(aName->Value());
107 myPrsList.append(aPrsObj);
113 // else { // This is not a Prs object
114 SALOMEDS::GenericAttribute_var anAttr;
115 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
116 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
117 string aComm = aComment->Value();
118 QString strIn(aComm.c_str());
119 VISU::Storable::TRestoringMap aMap;
120 VISU::Storable::StrToMap(strIn,aMap);
122 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
124 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
125 SALOMEDS::GenericAttribute_var aNameAttr;
126 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
127 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(aNameAttr);
128 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
131 myFamilisLst += QString(aName->Value());
132 myFamilyList.append(aPrsObj);
135 myGroupsLst += QString(aName->Value());
136 myGroupList.append(aPrsObj);
139 myEntitiesLst += QString(aName->Value());
140 myEntityList.append(aPrsObj);
150 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
151 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
153 QLabel* aPercentLbl = new QLabel( tr( "Used points (0..1)" ), aSourceBox);
154 aSrcLayout->addWidget(aPercentLbl, 2, 0);
156 myPntPercent = new QAD_SpinBoxDbl( aSourceBox, 0, 1, 0.1);
157 aSrcLayout->addWidget(myPntPercent, 2, 1);
159 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
162 QLabel* aStepLenLbl = new QLabel( tr( "Step Length" ), aTopBox);
163 TopLayout->addWidget(aStepLenLbl, 1, 0);
164 myStepLen = new QAD_SpinBoxDbl( aTopBox, DBL_MIN, DBL_MAX, 0.1);
165 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
166 TopLayout->addWidget(myStepLen, 1, 1);
167 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
169 QLabel* aIntegStepLenLbl = new QLabel( tr( "Integration Step" ), aTopBox);
170 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
171 myIntegStepLen = new QAD_SpinBoxDbl( aTopBox, DBL_MIN, DBL_MAX, 0.1);
172 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
173 TopLayout->addWidget(myIntegStepLen, 2, 1);
174 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
176 QLabel* aPropagationLbl = new QLabel( tr( "Propagation Time" ), aTopBox);
177 TopLayout->addWidget(aPropagationLbl, 3, 0);
178 myPropTime = new QAD_SpinBoxDbl(aTopBox, DBL_MIN, DBL_MAX, 1);
179 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180 TopLayout->addWidget(myPropTime, 3, 1);
181 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
183 QLabel* aDirLbl = new QLabel( tr( "Direction" ),aTopBox);
184 TopLayout->addWidget(aDirLbl, 4, 0);
185 myDirCombo = new QComboBox(aTopBox);
186 myDirCombo->insertItem("Forward");
187 myDirCombo->insertItem("Backward");
188 myDirCombo->insertItem("Both");
189 TopLayout->addWidget(myDirCombo, 4, 1);
191 myUseScalar = new QCheckBox( tr( "Magnitude coloring" ), aTopBox, "UseMagn" );
192 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
193 TopLayout->addWidget(myUseScalar, 5, 0);
195 SelColor = new QPushButton( tr( "Use Color" ), aTopBox, "SelColor" );
196 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
197 TopLayout->addWidget( SelColor, 5, 1);
199 aTabBox->addTab(aTopBox, "Stream Lines");
200 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
201 myScalarPane->setMargin( 5 );
202 aTabBox->addTab(myScalarPane, "Scalar Bar");
204 aBoxLayout->addWidget(aTabBox);
206 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
207 aGroupButtons->setColumnLayout(0, Qt::Vertical );
208 aGroupButtons->layout()->setSpacing( 0 );
209 aGroupButtons->layout()->setMargin( 0 );
211 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
212 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
213 aGroupButtonsLayout->setSpacing( 6 );
214 aGroupButtonsLayout->setMargin( 11 );
216 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
217 aOkBtn->setAutoDefault( TRUE );
218 aOkBtn->setDefault( TRUE );
219 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
220 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
222 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
223 aCancelBtn->setAutoDefault( TRUE );
224 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
225 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
226 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
228 aBoxLayout->addWidget(aGroupButtons);
235 void VisuGUI_StreamLinesDlg::initFromPrsObject(VISU::StreamLines_i* thePrs) {
236 myScalarPane->initFromPrsObject(thePrs);
239 static int aNbOfSteps = 30;
240 VISU_StreamLinesPL* aStreamLinesPL = thePrs->GetStreamLinesPL();
242 aMin = aStreamLinesPL->GetMinPropagationTime();
243 aMax = aStreamLinesPL->GetMaxPropagationTime();
244 myPropTime->setRange(aMin,aMax);
245 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
246 myPropTime->setLineStep((aMax-aMin)/aNbOfSteps);
248 aMin = aStreamLinesPL->GetMinStepLength();
249 aMax = aStreamLinesPL->GetMaxStepLength();
250 myStepLen->setRange(aMin,aMax);
251 myStepLen->setValue(aStreamLinesPL->GetStepLength());
252 myStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
254 aMin = aStreamLinesPL->GetMinIntegrationStep();
255 aMax = aStreamLinesPL->GetMaxIntegrationStep();
256 myIntegStepLen->setRange(aMin,aMax);
257 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
258 myIntegStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
260 switch (thePrs->GetDirection()) {
261 case VISU::StreamLines::FORWARD:
262 myDirCombo->setCurrentItem(0);
264 case VISU::StreamLines::BACKWARD:
265 myDirCombo->setCurrentItem(1);
267 case VISU::StreamLines::BOTH:
268 myDirCombo->setCurrentItem(2);
270 myUseScalar->setChecked(thePrs->IsColored());
271 myPntPercent->setValue(thePrs->GetUsedPoints());
273 mySrcCombo->setEnabled(false);
274 QString aSrcEntry = thePrs->GetSourceEntry();
276 SALOMEDS::Color anOldColor = thePrs->GetColor();
277 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
281 #define INITPRS(PRSLIST, PRSNUM) \
282 for (int i = 0; i < PRSLIST.count(); i++) { \
283 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
284 if (aPrs == NULL) continue; \
285 if (aSrcEntry == aPrs->GetEntry()) { \
286 onSourceTypeChange(PRSNUM); \
287 myUseSrcCombo->setCurrentItem(PRSNUM); \
288 mySrcCombo->setEnabled(true); \
289 mySrcCombo->setCurrentItem(i); \
294 if (!aSrcEntry.isEmpty()) {
295 INITPRS(myEntityList, 1);
296 INITPRS(myFamilyList, 2);
297 INITPRS(myGroupList, 3);
298 INITPRS(myPrsList, 4);
306 int VisuGUI_StreamLinesDlg::storeToPrsObject(VISU::StreamLines_i* thePrs) {
307 bool isAccepted = myScalarPane->storeToPrsObject(thePrs);
309 thePrs->ShowColored(myUseScalar->isChecked());
310 if(!thePrs->IsColored()){
311 SALOMEDS::Color aColor;
312 aColor.R = myColor.red()/255.;
313 aColor.G = myColor.green()/255.;
314 aColor.B = myColor.blue()/255.;
315 thePrs->SetColor(aColor);
318 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
319 switch (myDirCombo->currentItem()) {
321 aDirection = VISU::StreamLines::FORWARD;
324 aDirection = VISU::StreamLines::BACKWARD;
327 aDirection = VISU::StreamLines::BOTH;
330 VISU::Prs3d_var aPrs;
331 int aSrcSelection = myUseSrcCombo->currentItem();
332 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
333 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
334 VISU::VISUType aType;
336 switch (aSrcSelection){
338 aPrs = myEntityList[aSrcItem];
339 aType = VISU::TENTITY;
340 aName = myEntitiesLst[aSrcItem];
343 aPrs = myFamilyList[aSrcItem];
344 aType = VISU::TFAMILY;
345 aName = myFamilisLst[aSrcItem];
348 aPrs = myGroupList[aSrcItem];
349 aType = VISU::TGROUP;
350 aName = myGroupsLst[aSrcItem];
352 case 4: // Presentation
353 aPrs = myPrsList[aSrcItem];
356 if(CORBA::is_nil(aPrs) && aSrcSelection != 4){
357 aPrs = createMesh(aType, aName);
360 isAccepted = thePrs->SetParams(myIntegStepLen->value(),
364 myPntPercent->value(),
368 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
369 tr ("ERR_CANT_BUILD_PRESENTATION"),
370 tr ("VISU_BUT_OK") );
377 void VisuGUI_StreamLinesDlg::setColor( QColor color )
380 SelColor->setPaletteBackgroundColor(myColor);
385 Called when "Select Color" buttonx clicked
387 void VisuGUI_StreamLinesDlg::setVColor()
389 QColor cnew = QColorDialog::getColor( myColor, this );
390 if ( cnew.isValid() )
396 Enbled/disables magnitude coloring
398 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
400 myUseScalar->setEnabled( enable );
405 Called when "Magnitude Coloring" check box clicked
407 void VisuGUI_StreamLinesDlg::enableSetColor()
409 SelColor->setEnabled(!myUseScalar->isChecked() );
412 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
415 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
418 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
419 myStepLen->setMaxValue(theValue);
422 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
425 mySrcCombo->setEnabled(false);
428 mySrcCombo->setEnabled(true);
432 mySrcCombo->insertStringList(myEntitiesLst);
435 mySrcCombo->insertStringList(myFamilisLst);
438 mySrcCombo->insertStringList(myGroupsLst);
440 case 4: // Presentation
441 mySrcCombo->insertStringList(myPrsLst);
447 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh(VISU::VISUType theType, QString theName) {
448 CORBA::Object_var anObject = VISU::SObjectToObject(mySelectionObj);
449 VISU::Result_var aResult;
450 if (!CORBA::is_nil(anObject)) {
451 aResult = VISU::Result::_narrow(anObject);
453 if(CORBA::is_nil(aResult)) {
454 QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
455 tr ("WRN_NO_AVAILABLE_DATA"),
457 return VISU::Mesh::_nil();
459 SALOMEDS::ChildIterator_var aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
460 VISU::Storable::TRestoringMap aMap;
462 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
463 SALOMEDS::SObject_var aChildSObj = aIter->Value();
464 SALOMEDS::GenericAttribute_var anAttr;
465 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
466 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
467 CORBA::String_var aComm = aComment->Value();
468 QString strIn(aComm.in());
470 VISU::Storable::StrToMap(strIn,aMap);
472 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
474 if (aType != theType) continue;
476 SALOMEDS::GenericAttribute_var aNameAttr;
477 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
478 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(aNameAttr);
479 if (QString(aName->Value()) == theName) break; //use current map
484 VISU::Mesh_var aMesh;
485 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
489 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
490 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
495 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
500 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
501 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
505 if(!CORBA::is_nil(aMesh)){ // Create Actor
506 VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
507 if(VTKViewer_ViewFrame* vf = VisuGUI::GetVtkViewFrame()){
509 pPresent->SetPresentationType(VISU::POINT);
510 VISU_Actor *anActor = pPresent->CreateActor();
511 vf->AddActor(anActor);
513 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
514 tr ("ERR_CANT_CREATE_ACTOR"),
515 tr ("VISU_BUT_OK") );
519 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
520 tr ("ERR_CANT_BUILD_PRESENTATION"),
521 tr ("VISU_BUT_OK") );
523 return aMesh._retn();
526 void VisuGUI_StreamLinesDlg::accept() {
527 if (myScalarPane->check()) QDialog::accept();