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)));
86 //SUIT_Study* aActiveStudy = VISU::(myVisuGUI);
87 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
88 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
89 SALOME_ListIO selected;
90 aSel->selectedObjects(selected);
91 if (selected.Extent() > 0) {
92 Handle(SALOME_InteractiveObject) aIO = selected.First();
93 if (aIO->hasEntry()) {
94 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
95 aSObject = aSObject->GetFather();
96 aSObject = aSObject->GetFather();
97 aSObject = aSObject->GetFather();
98 aSObject = aSObject->GetFather();
99 mySelectionObj = aSObject;
100 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
101 VISU::Result_var aResult;
102 if (CORBA::is_nil(anObject)) {
103 mySelectionObj = mySelectionObj->GetFather();
105 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
107 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
108 _PTR(SObject) aChildSObj = aIter->Value();
109 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
111 if (!CORBA::is_nil(aChildObject)) {
112 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
113 if (!CORBA::is_nil(aPrsObj)) { // if this is a Prs object
114 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
115 (aPrsObj->GetType() != VISU::TMESH)) {
116 _PTR(GenericAttribute) anAttr;
117 if (aChildSObj->FindAttribute(anAttr, "AttributeName")) {
118 _PTR(AttributeName) aName (anAttr);
119 myPrsLst += QString(aName->Value().c_str());
120 myPrsList.append(aPrsObj);
126 // else { // This is not a Prs object
127 _PTR(GenericAttribute) anAttr;
128 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
129 _PTR(AttributeComment) aComment (anAttr);
130 string aComm = aComment->Value();
131 QString strIn (aComm.c_str());
132 VISU::Storable::TRestoringMap aMap;
133 VISU::Storable::StrToMap(strIn,aMap);
135 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
137 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
138 _PTR(GenericAttribute) aNameAttr;
139 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
140 _PTR(AttributeName) aName (aNameAttr);
141 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
144 myFamilisLst += QString(aName->Value().c_str());
145 myFamilyList.append(aPrsObj);
148 myGroupsLst += QString(aName->Value().c_str());
149 myGroupList.append(aPrsObj);
152 myEntitiesLst += QString(aName->Value().c_str());
153 myEntityList.append(aPrsObj);
164 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
165 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
167 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
168 aSrcLayout->addWidget(aPercentLbl, 2, 0);
170 myPntPercent = new QtxDblSpinBox( 0, 1, 0.1, aSourceBox );
171 aSrcLayout->addWidget(myPntPercent, 2, 1);
173 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
175 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
176 TopLayout->addWidget(aStepLenLbl, 1, 0);
177 myStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
178 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
179 TopLayout->addWidget(myStepLen, 1, 1);
180 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
182 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
183 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
184 myIntegStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
185 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
186 TopLayout->addWidget(myIntegStepLen, 2, 1);
187 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
189 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
190 TopLayout->addWidget(aPropagationLbl, 3, 0);
191 myPropTime = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 1, aTopBox );
192 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
193 TopLayout->addWidget(myPropTime, 3, 1);
194 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
196 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
197 TopLayout->addWidget(aDirLbl, 4, 0);
198 myDirCombo = new QComboBox(aTopBox);
199 myDirCombo->insertItem("Forward");
200 myDirCombo->insertItem("Backward");
201 myDirCombo->insertItem("Both");
202 TopLayout->addWidget(myDirCombo, 4, 1);
204 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox, "UseMagn");
205 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
206 TopLayout->addWidget(myUseScalar, 5, 0);
208 SelColor = new QPushButton (tr("USE_COLOR_BTN"), aTopBox, "SelColor");
209 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
210 TopLayout->addWidget( SelColor, 5, 1);
212 aTabBox->addTab(aTopBox, "Stream Lines");
213 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
214 myScalarPane->setMargin( 5 );
215 aTabBox->addTab(myScalarPane, "Scalar Bar");
217 aBoxLayout->addWidget(aTabBox);
219 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
220 aGroupButtons->setColumnLayout(0, Qt::Vertical );
221 aGroupButtons->layout()->setSpacing( 0 );
222 aGroupButtons->layout()->setMargin( 0 );
224 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
225 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
226 aGroupButtonsLayout->setSpacing( 6 );
227 aGroupButtonsLayout->setMargin( 11 );
229 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
230 aOkBtn->setAutoDefault( TRUE );
231 aOkBtn->setDefault( TRUE );
232 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
233 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
235 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
236 aCancelBtn->setAutoDefault( TRUE );
237 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
238 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
239 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
241 aBoxLayout->addWidget(aGroupButtons);
248 void VisuGUI_StreamLinesDlg::initFromPrsObject (VISU::StreamLines_i* thePrs)
250 myScalarPane->initFromPrsObject(thePrs);
253 static int aNbOfSteps = 30;
254 VISU_StreamLinesPL* aStreamLinesPL = thePrs->GetStreamLinesPL();
256 aMin = aStreamLinesPL->GetMinPropagationTime();
257 aMax = aStreamLinesPL->GetMaxPropagationTime();
258 myPropTime->setRange(aMin,aMax);
259 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
260 myPropTime->setLineStep((aMax-aMin)/aNbOfSteps);
262 aMin = aStreamLinesPL->GetMinStepLength();
263 aMax = aStreamLinesPL->GetMaxStepLength();
264 myStepLen->setRange(aMin,aMax);
265 myStepLen->setValue(aStreamLinesPL->GetStepLength());
266 myStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
268 aMin = aStreamLinesPL->GetMinIntegrationStep();
269 aMax = aStreamLinesPL->GetMaxIntegrationStep();
270 myIntegStepLen->setRange(aMin,aMax);
271 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
272 myIntegStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
274 switch (thePrs->GetDirection()) {
275 case VISU::StreamLines::FORWARD:
276 myDirCombo->setCurrentItem(0);
278 case VISU::StreamLines::BACKWARD:
279 myDirCombo->setCurrentItem(1);
281 case VISU::StreamLines::BOTH:
282 myDirCombo->setCurrentItem(2);
284 myUseScalar->setChecked(thePrs->IsColored());
285 myPntPercent->setValue(thePrs->GetUsedPoints());
287 mySrcCombo->setEnabled(false);
288 QString aSrcEntry = thePrs->GetSourceEntry();
290 SALOMEDS::Color anOldColor = thePrs->GetColor();
291 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
295 #define INITPRS(PRSLIST, PRSNUM) \
296 for (int i = 0; i < PRSLIST.count(); i++) { \
297 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
298 if (aPrs == NULL) continue; \
299 if (aSrcEntry == aPrs->GetEntry()) { \
300 onSourceTypeChange(PRSNUM); \
301 myUseSrcCombo->setCurrentItem(PRSNUM); \
302 mySrcCombo->setEnabled(true); \
303 mySrcCombo->setCurrentItem(i); \
308 if (!aSrcEntry.isEmpty()) {
309 INITPRS(myEntityList, 1);
310 INITPRS(myFamilyList, 2);
311 INITPRS(myGroupList, 3);
312 INITPRS(myPrsList, 4);
317 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::StreamLines_i* thePrs)
319 bool isAccepted = myScalarPane->storeToPrsObject(thePrs);
321 thePrs->ShowColored(myUseScalar->isChecked());
322 if (!thePrs->IsColored()) {
323 SALOMEDS::Color aColor;
324 aColor.R = myColor.red()/255.;
325 aColor.G = myColor.green()/255.;
326 aColor.B = myColor.blue()/255.;
327 thePrs->SetColor(aColor);
330 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
331 switch (myDirCombo->currentItem()) {
333 aDirection = VISU::StreamLines::FORWARD;
336 aDirection = VISU::StreamLines::BACKWARD;
339 aDirection = VISU::StreamLines::BOTH;
342 VISU::Prs3d_var aPrs;
343 int aSrcSelection = myUseSrcCombo->currentItem();
344 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
345 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
346 VISU::VISUType aType;
348 switch (aSrcSelection) {
350 aPrs = myEntityList[aSrcItem];
351 aType = VISU::TENTITY;
352 aName = myEntitiesLst[aSrcItem];
355 aPrs = myFamilyList[aSrcItem];
356 aType = VISU::TFAMILY;
357 aName = myFamilisLst[aSrcItem];
360 aPrs = myGroupList[aSrcItem];
361 aType = VISU::TGROUP;
362 aName = myGroupsLst[aSrcItem];
364 case 4: // Presentation
365 aPrs = myPrsList[aSrcItem];
368 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
369 aPrs = createMesh(aType, aName);
372 isAccepted = thePrs->SetParams(myIntegStepLen->value(),
376 myPntPercent->value(),
380 // SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("WRN_VISU"),
381 // tr("ERR_CANT_BUILD_PRESENTATION"),
389 void VisuGUI_StreamLinesDlg::setColor( QColor color )
392 SelColor->setPaletteBackgroundColor(myColor);
397 Called when "Select Color" buttonx clicked
399 void VisuGUI_StreamLinesDlg::setVColor()
401 QColor cnew = QColorDialog::getColor( myColor, this );
402 if ( cnew.isValid() )
408 Enbled/disables magnitude coloring
410 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
412 myUseScalar->setEnabled( enable );
417 Called when "Magnitude Coloring" check box clicked
419 void VisuGUI_StreamLinesDlg::enableSetColor()
421 SelColor->setEnabled(!myUseScalar->isChecked() );
424 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
427 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
430 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
431 myStepLen->setMaxValue(theValue);
434 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
437 mySrcCombo->setEnabled(false);
440 mySrcCombo->setEnabled(true);
444 mySrcCombo->insertStringList(myEntitiesLst);
447 mySrcCombo->insertStringList(myFamilisLst);
450 mySrcCombo->insertStringList(myGroupsLst);
452 case 4: // Presentation
453 mySrcCombo->insertStringList(myPrsLst);
459 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
461 return VISU::Mesh::_nil();
463 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
464 VISU::Result_var aResult;
465 if (!CORBA::is_nil(anObject)) {
466 aResult = VISU::Result::_narrow(anObject);
468 if (CORBA::is_nil(aResult)) {
469 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
470 tr("WRN_NO_AVAILABLE_DATA"),
472 return VISU::Mesh::_nil();
474 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
475 VISU::Storable::TRestoringMap aMap;
477 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
478 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
479 SALOMEDSClient_GenericAttribute* anAttr;
480 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
481 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
482 CORBA::String_var aComm = aComment->Value().c_str();
483 QString strIn(aComm.in());
485 VISU::Storable::StrToMap(strIn,aMap);
487 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
489 if (aType != theType) continue;
491 SALOMEDSClient_GenericAttribute* aNameAttr;
492 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
493 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>(aNameAttr);
494 if (QString(aName->Value()) == theName) break; //use current map
499 VISU::Mesh_var aMesh;
500 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
504 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
505 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
510 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
515 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
516 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
520 if(!CORBA::is_nil(aMesh)){ // Create Actor
521 VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
522 if(SVTK_ViewWindow* vf = VISU::GetViewWindow()){
524 pPresent->SetPresentationType(VISU::POINT);
525 VISU_Actor *anActor = pPresent->CreateActor();
526 vf->AddActor(anActor);
528 SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr("VISU_WARNING"),
529 tr("ERR_CANT_CREATE_ACTOR"),
534 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
535 tr("ERR_CANT_BUILD_PRESENTATION"),
538 return aMesh._retn();
542 void VisuGUI_StreamLinesDlg::accept() {
543 if (myScalarPane->check())