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>
33 extern VisuGUI *visuGUI;
35 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg()
36 : QDialog( QAD_Application::getDesktop(), "VisuGUI_StreamLinesDlg", false, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
38 setCaption("Stream lines Preferences");
39 setSizeGripEnabled( TRUE );
41 QGridLayout* TopLayout = new QGridLayout( this );
42 TopLayout->setSpacing( 6 );
43 TopLayout->setMargin( 11 );
46 QGroupBox* aSourceBox = new QGroupBox(tr("Source"), this);
47 aSourceBox->setColumnLayout(0, Qt::Vertical);
48 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox->layout() );
49 aSrcLayout->setSpacing( 6 );
50 aSrcLayout->setMargin( 0 );
52 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
53 aSrcLayout->addWidget(aTypeLbl, 0, 0);
55 myUseSrcCombo = new QComboBox(aSourceBox);
56 const char* aChoise[] = { "None", "Entity", "Family", "Group", "Presentation", 0 };
57 myUseSrcCombo->insertStrList(aChoise);
58 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
60 mySrcCombo = new QComboBox(aSourceBox);
61 mySrcCombo->setEnabled((myUseSrcCombo->currentItem() == 0));
63 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
66 QAD_Study* aActiveStudy = VisuGUI::GetActiveStudy();
67 SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
68 if( aSel->IObjectCount() > 0 ) {
69 Handle(SALOME_InteractiveObject) aIO = aSel->firstIObject();
71 SALOMEDS::SObject_var aSObject = VisuGUI::GetStudyDocument()->FindObjectID(aIO->getEntry());
72 aSObject = aSObject->GetFather();
73 aSObject = aSObject->GetFather();
74 aSObject = aSObject->GetFather();
75 aSObject = aSObject->GetFather();
76 mySelectionObj = aSObject;
77 CORBA::Object_var anObject = VISU::SObjectToObject(mySelectionObj);
78 VISU::Result_var aResult;
79 if (CORBA::is_nil(anObject)) {
80 mySelectionObj = mySelectionObj->GetFather();
82 SALOMEDS::ChildIterator_var aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
84 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
85 SALOMEDS::SObject_var aChildSObj = aIter->Value();
86 CORBA::Object_var aChildObject = VISU::SObjectToObject( aChildSObj );
88 if(!CORBA::is_nil( aChildObject ) ) {
89 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
90 if( !CORBA::is_nil( aPrsObj ) ) { // if this is a Prs object
91 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
92 (aPrsObj->GetType() != VISU::TMESH)) {
93 SALOMEDS::GenericAttribute_var anAttr;
94 if ( aChildSObj->FindAttribute(anAttr, "AttributeName") ) {
95 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
96 myPrsLst += QString(aName->Value());
97 myPrsList.append(aPrsObj);
103 // else { // This is not a Prs object
104 SALOMEDS::GenericAttribute_var anAttr;
105 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
106 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
107 string aComm = aComment->Value();
108 QString strIn(aComm.c_str());
109 VISU::Storable::TRestoringMap aMap;
110 VISU::Storable::StrToMap(strIn,aMap);
112 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
114 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
115 SALOMEDS::GenericAttribute_var aNameAttr;
116 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
117 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(aNameAttr);
118 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
121 myFamilisLst += QString(aName->Value());
122 myFamilyList.append(aPrsObj);
125 myGroupsLst += QString(aName->Value());
126 myGroupList.append(aPrsObj);
129 myEntitiesLst += QString(aName->Value());
130 myEntityList.append(aPrsObj);
140 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
141 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
143 QLabel* aPercentLbl = new QLabel( tr( "Used points (0..1)" ), aSourceBox);
144 aSrcLayout->addWidget(aPercentLbl, 2, 0);
146 myPntPercent = new QAD_SpinBoxDbl( aSourceBox, 0, 1, 0.1);
147 aSrcLayout->addWidget(myPntPercent, 2, 1);
149 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
152 QLabel* aStepLenLbl = new QLabel( tr( "Step Length" ), this);
153 TopLayout->addWidget(aStepLenLbl, 1, 0);
154 myStepLen = new QAD_SpinBoxDbl( this, DBL_MIN, DBL_MAX, 0.1);
155 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
156 TopLayout->addWidget(myStepLen, 1, 1);
157 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
159 QLabel* aIntegStepLenLbl = new QLabel( tr( "Integration Step" ), this);
160 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
161 myIntegStepLen = new QAD_SpinBoxDbl( this, DBL_MIN, DBL_MAX, 0.1);
162 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
163 TopLayout->addWidget(myIntegStepLen, 2, 1);
164 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
166 QLabel* aPropagationLbl = new QLabel( tr( "Propagation Time" ), this);
167 TopLayout->addWidget(aPropagationLbl, 3, 0);
168 myPropTime = new QAD_SpinBoxDbl( this, DBL_MIN, DBL_MAX, 1);
169 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
170 TopLayout->addWidget(myPropTime, 3, 1);
171 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
173 QLabel* aDirLbl = new QLabel( tr( "Direction" ), this);
174 TopLayout->addWidget(aDirLbl, 4, 0);
175 myDirCombo = new QComboBox(this);
176 myDirCombo->insertItem("Forward");
177 myDirCombo->insertItem("Backward");
178 myDirCombo->insertItem("Both");
179 TopLayout->addWidget(myDirCombo, 4, 1);
181 myUseScalar = new QCheckBox( tr( "Magnitude coloring" ), this, "UseMagn" );
182 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
183 TopLayout->addWidget(myUseScalar, 5, 0);
185 SelColor = new QPushButton( tr( "Use Color" ), this, "SelColor" );
186 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
187 TopLayout->addWidget( SelColor, 5, 1);
189 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
190 aGroupButtons->setColumnLayout(0, Qt::Vertical );
191 aGroupButtons->layout()->setSpacing( 0 );
192 aGroupButtons->layout()->setMargin( 0 );
194 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
195 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
196 aGroupButtonsLayout->setSpacing( 6 );
197 aGroupButtonsLayout->setMargin( 11 );
199 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
200 aOkBtn->setAutoDefault( TRUE );
201 aOkBtn->setDefault( TRUE );
202 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
203 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
205 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
206 aCancelBtn->setAutoDefault( TRUE );
207 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
208 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
209 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
210 TopLayout->addMultiCellWidget( aGroupButtons, 6, 6, 0, 1 );
216 void VisuGUI_StreamLinesDlg::initFromPrsObject(VISU::StreamLines_i* thePrs) {
217 myPropTime->setValue(thePrs->GetPropagationTime());
219 myStepLen->setRange(VISU_StreamLinesPL::GetMinStepLength(thePrs->GetIntegrationStep()),
220 VISU_StreamLinesPL::GetMaxStepLength(thePrs->GetPropagationTime()));
221 myStepLen->setValue(thePrs->GetStepLength());
223 myIntegStepLen->setRange(thePrs->GetMinIntegrationStep(),thePrs->GetMaxIntegrationStep());
224 myIntegStepLen->setValue(thePrs->GetIntegrationStep());
226 switch (thePrs->GetDirection()) {
227 case VISU::StreamLines::FORWARD:
228 myDirCombo->setCurrentItem(0);
230 case VISU::StreamLines::BACKWARD:
231 myDirCombo->setCurrentItem(1);
233 case VISU::StreamLines::BOTH:
234 myDirCombo->setCurrentItem(2);
236 myUseScalar->setChecked(thePrs->IsColored());
237 myPntPercent->setValue(thePrs->GetUsedPoints());
239 mySrcCombo->setEnabled(false);
240 QString aSrcEntry = thePrs->GetSourceEntry();
242 SALOMEDS::Color anOldColor = thePrs->GetColor();
243 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
247 #define INITPRS(PRSLIST, PRSNUM) \
248 for (int i = 0; i < PRSLIST.count(); i++) { \
249 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i])); \
250 if (aPrs == NULL) continue; \
251 if (aSrcEntry == aPrs->GetEntry()) { \
252 onSourceTypeChange(PRSNUM); \
253 myUseSrcCombo->setCurrentItem(PRSNUM); \
254 mySrcCombo->setEnabled(true); \
255 mySrcCombo->setCurrentItem(i); \
260 if (!aSrcEntry.isEmpty()) {
261 INITPRS(myEntityList, 1);
262 INITPRS(myFamilyList, 2);
263 INITPRS(myGroupList, 3);
264 INITPRS(myPrsList, 4);
273 void VisuGUI_StreamLinesDlg::storeToPrsObject(VISU::StreamLines_i* thePrs) {
274 //Order of setting of the values are important
275 thePrs->SetIntegrationStep(myIntegStepLen->value());
276 thePrs->SetPropagationTime(myPropTime->value());
277 thePrs->SetStepLength(myStepLen->value());
278 switch (myDirCombo->currentItem()) {
280 thePrs->SetDirection(VISU::StreamLines::FORWARD);
283 thePrs->SetDirection(VISU::StreamLines::BACKWARD);
286 thePrs->SetDirection(VISU::StreamLines::BOTH);
288 thePrs->ShowColored(myUseScalar->isChecked());
289 if(!thePrs->IsColored()){
290 SALOMEDS::Color aColor;
291 aColor.R = myColor.red()/255.;
292 aColor.G = myColor.green()/255.;
293 aColor.B = myColor.blue()/255.;
294 thePrs->SetColor(aColor);
296 thePrs->SetUsedPoints(myPntPercent->value());
298 int aSrcSelection = myUseSrcCombo->currentItem();
299 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
300 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
301 VISU::Prs3d_var aPrs;
302 VISU::VISUType aType;
304 switch (aSrcSelection){
306 aPrs = myEntityList[aSrcItem];
307 aType = VISU::TENTITY;
308 aName = myEntitiesLst[aSrcItem];
311 aPrs = myFamilyList[aSrcItem];
312 aType = VISU::TFAMILY;
313 aName = myFamilisLst[aSrcItem];
316 aPrs = myGroupList[aSrcItem];
317 aType = VISU::TGROUP;
318 aName = myGroupsLst[aSrcItem];
320 case 4: // Presentation
321 aPrs = myPrsList[aSrcItem];
324 if (!CORBA::is_nil( aPrs )) {
325 thePrs->SetSource(aPrs);
326 } else if (aSrcSelection == 4) {
327 thePrs->SetSource(VISU::Prs3d::_nil());
328 } else { // Create Mesh presentation
329 thePrs->SetSource(createMesh(aType, aName));
332 thePrs->SetSource(VISU::Prs3d::_nil());
338 void VisuGUI_StreamLinesDlg::setColor( QColor color )
341 SelColor->setPaletteBackgroundColor(myColor);
346 Called when "Select Color" buttonx clicked
348 void VisuGUI_StreamLinesDlg::setVColor()
350 QColor cnew = QColorDialog::getColor( myColor, this );
351 if ( cnew.isValid() )
357 Enbled/disables magnitude coloring
359 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
361 myUseScalar->setEnabled( enable );
366 Called when "Magnitude Coloring" check box clicked
368 void VisuGUI_StreamLinesDlg::enableSetColor()
370 SelColor->setEnabled(!myUseScalar->isChecked() );
373 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
376 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
377 PropagationTimeChanged(myPropTime->value());
380 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
381 myStepLen->setMinValue(VISU_StreamLinesPL::GetMinStepLength(myIntegStepLen->value()));
382 myStepLen->setMaxValue(VISU_StreamLinesPL::GetMaxStepLength(myPropTime->value()));
385 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
388 mySrcCombo->setEnabled(false);
391 mySrcCombo->setEnabled(true);
395 mySrcCombo->insertStringList(myEntitiesLst);
398 mySrcCombo->insertStringList(myFamilisLst);
401 mySrcCombo->insertStringList(myGroupsLst);
403 case 4: // Presentation
404 mySrcCombo->insertStringList(myPrsLst);
410 VISU::Mesh_var VisuGUI_StreamLinesDlg::createMesh(VISU::VISUType theType, QString theName) {
411 CORBA::Object_var anObject = VISU::SObjectToObject(mySelectionObj);
412 VISU::Result_var aResult;
413 if (!CORBA::is_nil(anObject)) {
414 aResult = VISU::Result::_narrow(anObject);
416 if(CORBA::is_nil(aResult)) {
417 QAD_MessageBox::warn1(QAD_Application::getDesktop(), tr ("VISU_WARNING"),
418 tr ("WRN_NO_AVAILABLE_DATA"),
420 return VISU::Mesh::_nil();
422 SALOMEDS::ChildIterator_var aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
423 VISU::Storable::TRestoringMap aMap;
425 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
426 SALOMEDS::SObject_var aChildSObj = aIter->Value();
427 SALOMEDS::GenericAttribute_var anAttr;
428 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
429 SALOMEDS::AttributeComment_var aComment = SALOMEDS::AttributeComment::_narrow(anAttr);
430 CORBA::String_var aComm = aComment->Value();
431 QString strIn(aComm.in());
433 VISU::Storable::StrToMap(strIn,aMap);
435 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
437 if (aType != theType) continue;
439 SALOMEDS::GenericAttribute_var aNameAttr;
440 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
441 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(aNameAttr);
442 if (QString(aName->Value()) == theName) break; //use current map
447 CORBA::Object_var aMesh;
448 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
452 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
453 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
458 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
463 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
464 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
468 VISU::Mesh_i* pPresent = NULL;
469 if(!CORBA::is_nil(aMesh))
470 pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh));
471 if (pPresent == NULL) {
472 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
473 tr ("ERR_CANT_BUILD_PRESENTATION"),
474 tr ("VISU_BUT_OK") );
475 return VISU::Mesh::_nil();
478 if(VTKViewer_ViewFrame* vf = visuGUI->GetVtkViewFrame()){
480 pPresent->SetPresentationType(VISU::POINT);
481 VISU_Actor *anActor = pPresent->CreateActor();
482 vf->AddActor(anActor);
483 }catch(std::runtime_error& exc){
484 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("VISU_WARNING"),
485 tr ("ERR_CANT_CREATE_ACTOR"),
486 tr ("VISU_BUT_OK") );
489 return pPresent->_this();