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"
15 #include "VISU_Mesh_i.hh"
16 #include "VISU_Gen_i.hh"
17 #include "VISU_StreamLines_i.hh"
18 #include "VISU_StreamLinesPL.hxx"
19 #include "VISU_Actor.h"
21 #include "SalomeApp_Application.h"
22 #include "SalomeApp_SelectionMgr.h"
24 #include "SUIT_Desktop.h"
25 #include "SUIT_ResourceMgr.h"
26 #include "SUIT_MessageBox.h"
28 #include "SALOME_ListIO.hxx"
30 #include "SVTK_ViewWindow.h"
34 #include <qgroupbox.h>
35 #include <qcolordialog.h>
36 #include <qtabwidget.h>
38 #include <SALOMEDSClient_SObject.hxx>
39 #include <SALOMEDS_SObject.hxx>
43 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
44 : QDialog(parent, "VisuGUI_StreamLinesDlg", false,
45 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 setCaption(tr("DLG_TITLE"));
49 setSizeGripEnabled(TRUE);
51 QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
52 aBoxLayout->setSpacing( 6 );
53 aBoxLayout->setMargin( 11 );
55 QTabWidget* aTabBox = new QTabWidget(this);
57 QFrame* aTopBox = new QFrame(this);
58 aTopBox->setMargin( 11 );
59 QGridLayout* TopLayout = new QGridLayout( aTopBox );
60 TopLayout->setAlignment( Qt::AlignTop );
61 TopLayout->setSpacing( 8 );
62 TopLayout->setMargin( 11 );
65 QGroupBox* aSourceBox = new QGroupBox (tr("SOURCE_GRP"), aTopBox);
66 aSourceBox->setColumnLayout(0, Qt::Vertical);
67 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox->layout() );
68 aSrcLayout->setSpacing( 6 );
69 aSrcLayout->setMargin( 0 );
71 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
72 aSrcLayout->addWidget(aTypeLbl, 0, 0);
74 myUseSrcCombo = new QComboBox(aSourceBox);
75 const char* aChoise[] = { "None", "Entity", "Family", "Group", "Presentation", 0 };
76 myUseSrcCombo->insertStrList(aChoise);
77 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
79 mySrcCombo = new QComboBox(aSourceBox);
80 mySrcCombo->setEnabled((myUseSrcCombo->currentItem() == 0));
82 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
86 SUIT_Study* aActiveStudy = VisuGUI::GetActiveStudy();
87 SalomeApp_SelectionMgr* aSel = VisuGUI::application()->selectionMgr();
88 SALOME_ListIO selected; aSel->selectedObjects( selected );
89 if( selected.Extent() > 0 ) {
90 Handle(SALOME_InteractiveObject) aIO = selected.First();
92 SALOMEDSClient_SObject* aSObject = VisuGUI::GetStudyDocument()->FindObjectID(aIO->getEntry());
93 aSObject = aSObject->GetFather();
94 aSObject = aSObject->GetFather();
95 aSObject = aSObject->GetFather();
96 aSObject = aSObject->GetFather();
97 mySelectionObj = aSObject;
98 CORBA::Object_var anObject = VISU::ClientSObjectToObject( mySelectionObj );
99 VISU::Result_var aResult;
100 if (CORBA::is_nil(anObject)) {
101 mySelectionObj = mySelectionObj->GetFather();
103 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
105 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
106 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
107 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject( aChildSObj );
109 if(!CORBA::is_nil( aChildObject ) ) {
110 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
111 if( !CORBA::is_nil( aPrsObj ) ) { // if this is a Prs object
112 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
113 (aPrsObj->GetType() != VISU::TMESH)) {
114 SALOMEDSClient_GenericAttribute* anAttr;
115 if ( aChildSObj->FindAttribute(anAttr, "AttributeName") ) {
116 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>( anAttr );
117 myPrsLst += QString(aName->Value());
118 myPrsList.append(aPrsObj);
124 // else { // This is not a Prs object
125 SALOMEDSClient_GenericAttribute* anAttr;
126 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
127 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
128 string aComm = aComment->Value();
129 QString strIn(aComm.c_str());
130 VISU::Storable::TRestoringMap aMap;
131 VISU::Storable::StrToMap(strIn,aMap);
133 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
135 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
136 SALOMEDSClient_GenericAttribute* aNameAttr;
137 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
138 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>( aNameAttr );
139 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
142 myFamilisLst += QString(aName->Value());
143 myFamilyList.append(aPrsObj);
146 myGroupsLst += QString(aName->Value());
147 myGroupList.append(aPrsObj);
150 myEntitiesLst += QString(aName->Value());
151 myEntityList.append(aPrsObj);
162 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
163 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
165 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
166 aSrcLayout->addWidget(aPercentLbl, 2, 0);
168 myPntPercent = new QtxDblSpinBox( 0, 1, 0.1, aSourceBox );
169 aSrcLayout->addWidget(myPntPercent, 2, 1);
171 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
173 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
174 TopLayout->addWidget(aStepLenLbl, 1, 0);
175 myStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
176 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
177 TopLayout->addWidget(myStepLen, 1, 1);
178 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
180 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
181 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
182 myIntegStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
183 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
184 TopLayout->addWidget(myIntegStepLen, 2, 1);
185 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
187 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
188 TopLayout->addWidget(aPropagationLbl, 3, 0);
189 myPropTime = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 1, aTopBox );
190 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
191 TopLayout->addWidget(myPropTime, 3, 1);
192 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
194 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
195 TopLayout->addWidget(aDirLbl, 4, 0);
196 myDirCombo = new QComboBox(aTopBox);
197 myDirCombo->insertItem("Forward");
198 myDirCombo->insertItem("Backward");
199 myDirCombo->insertItem("Both");
200 TopLayout->addWidget(myDirCombo, 4, 1);
202 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox, "UseMagn");
203 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
204 TopLayout->addWidget(myUseScalar, 5, 0);
206 SelColor = new QPushButton (tr("USE_COLOR_BTN"), aTopBox, "SelColor");
207 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
208 TopLayout->addWidget( SelColor, 5, 1);
210 aTabBox->addTab(aTopBox, "Stream Lines");
211 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
212 myScalarPane->setMargin( 5 );
213 aTabBox->addTab(myScalarPane, "Scalar Bar");
215 aBoxLayout->addWidget(aTabBox);
217 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
218 aGroupButtons->setColumnLayout(0, Qt::Vertical );
219 aGroupButtons->layout()->setSpacing( 0 );
220 aGroupButtons->layout()->setMargin( 0 );
222 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
223 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
224 aGroupButtonsLayout->setSpacing( 6 );
225 aGroupButtonsLayout->setMargin( 11 );
227 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
228 aOkBtn->setAutoDefault( TRUE );
229 aOkBtn->setDefault( TRUE );
230 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
231 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
233 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
234 aCancelBtn->setAutoDefault( TRUE );
235 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
236 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
237 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
239 aBoxLayout->addWidget(aGroupButtons);
246 void VisuGUI_StreamLinesDlg::initFromPrsObject (VISU::StreamLines_i* thePrs)
248 myScalarPane->initFromPrsObject(thePrs);
251 static int aNbOfSteps = 30;
252 VISU_StreamLinesPL* aStreamLinesPL = thePrs->GetStreamLinesPL();
254 aMin = aStreamLinesPL->GetMinPropagationTime();
255 aMax = aStreamLinesPL->GetMaxPropagationTime();
256 myPropTime->setRange(aMin,aMax);
257 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
258 myPropTime->setLineStep((aMax-aMin)/aNbOfSteps);
260 aMin = aStreamLinesPL->GetMinStepLength();
261 aMax = aStreamLinesPL->GetMaxStepLength();
262 myStepLen->setRange(aMin,aMax);
263 myStepLen->setValue(aStreamLinesPL->GetStepLength());
264 myStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
266 aMin = aStreamLinesPL->GetMinIntegrationStep();
267 aMax = aStreamLinesPL->GetMaxIntegrationStep();
268 myIntegStepLen->setRange(aMin,aMax);
269 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
270 myIntegStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
272 switch (thePrs->GetDirection()) {
273 case VISU::StreamLines::FORWARD:
274 myDirCombo->setCurrentItem(0);
276 case VISU::StreamLines::BACKWARD:
277 myDirCombo->setCurrentItem(1);
279 case VISU::StreamLines::BOTH:
280 myDirCombo->setCurrentItem(2);
282 myUseScalar->setChecked(thePrs->IsColored());
283 myPntPercent->setValue(thePrs->GetUsedPoints());
285 mySrcCombo->setEnabled(false);
286 QString aSrcEntry = thePrs->GetSourceEntry();
288 SALOMEDS::Color anOldColor = thePrs->GetColor();
289 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
293 #define INITPRS(PRSLIST, PRSNUM) \
294 for (int i = 0; i < PRSLIST.count(); i++) { \
295 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
296 if (aPrs == NULL) continue; \
297 if (aSrcEntry == aPrs->GetEntry()) { \
298 onSourceTypeChange(PRSNUM); \
299 myUseSrcCombo->setCurrentItem(PRSNUM); \
300 mySrcCombo->setEnabled(true); \
301 mySrcCombo->setCurrentItem(i); \
306 if (!aSrcEntry.isEmpty()) {
307 INITPRS(myEntityList, 1);
308 INITPRS(myFamilyList, 2);
309 INITPRS(myGroupList, 3);
310 INITPRS(myPrsList, 4);
315 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::StreamLines_i* thePrs)
317 bool isAccepted = myScalarPane->storeToPrsObject(thePrs);
319 thePrs->ShowColored(myUseScalar->isChecked());
320 if (!thePrs->IsColored()) {
321 SALOMEDS::Color aColor;
322 aColor.R = myColor.red()/255.;
323 aColor.G = myColor.green()/255.;
324 aColor.B = myColor.blue()/255.;
325 thePrs->SetColor(aColor);
328 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
329 switch (myDirCombo->currentItem()) {
331 aDirection = VISU::StreamLines::FORWARD;
334 aDirection = VISU::StreamLines::BACKWARD;
337 aDirection = VISU::StreamLines::BOTH;
340 VISU::Prs3d_var aPrs;
341 int aSrcSelection = myUseSrcCombo->currentItem();
342 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
343 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
344 VISU::VISUType aType;
346 switch (aSrcSelection) {
348 aPrs = myEntityList[aSrcItem];
349 aType = VISU::TENTITY;
350 aName = myEntitiesLst[aSrcItem];
353 aPrs = myFamilyList[aSrcItem];
354 aType = VISU::TFAMILY;
355 aName = myFamilisLst[aSrcItem];
358 aPrs = myGroupList[aSrcItem];
359 aType = VISU::TGROUP;
360 aName = myGroupsLst[aSrcItem];
362 case 4: // Presentation
363 aPrs = myPrsList[aSrcItem];
366 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
367 aPrs = createMesh(aType, aName);
370 isAccepted = thePrs->SetParams(myIntegStepLen->value(),
374 myPntPercent->value(),
378 // SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("WRN_VISU"),
379 // tr("ERR_CANT_BUILD_PRESENTATION"),
387 void VisuGUI_StreamLinesDlg::setColor( QColor color )
390 SelColor->setPaletteBackgroundColor(myColor);
395 Called when "Select Color" buttonx clicked
397 void VisuGUI_StreamLinesDlg::setVColor()
399 QColor cnew = QColorDialog::getColor( myColor, this );
400 if ( cnew.isValid() )
406 Enbled/disables magnitude coloring
408 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
410 myUseScalar->setEnabled( enable );
415 Called when "Magnitude Coloring" check box clicked
417 void VisuGUI_StreamLinesDlg::enableSetColor()
419 SelColor->setEnabled(!myUseScalar->isChecked() );
422 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
425 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
428 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
429 myStepLen->setMaxValue(theValue);
432 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
435 mySrcCombo->setEnabled(false);
438 mySrcCombo->setEnabled(true);
442 mySrcCombo->insertStringList(myEntitiesLst);
445 mySrcCombo->insertStringList(myFamilisLst);
448 mySrcCombo->insertStringList(myGroupsLst);
450 case 4: // Presentation
451 mySrcCombo->insertStringList(myPrsLst);
457 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
459 return VISU::Mesh::_nil();
461 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
462 VISU::Result_var aResult;
463 if (!CORBA::is_nil(anObject)) {
464 aResult = VISU::Result::_narrow(anObject);
466 if (CORBA::is_nil(aResult)) {
467 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
468 tr("WRN_NO_AVAILABLE_DATA"),
470 return VISU::Mesh::_nil();
472 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
473 VISU::Storable::TRestoringMap aMap;
475 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
476 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
477 SALOMEDSClient_GenericAttribute* anAttr;
478 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
479 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
480 CORBA::String_var aComm = aComment->Value().c_str();
481 QString strIn(aComm.in());
483 VISU::Storable::StrToMap(strIn,aMap);
485 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
487 if (aType != theType) continue;
489 SALOMEDSClient_GenericAttribute* aNameAttr;
490 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
491 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>(aNameAttr);
492 if (QString(aName->Value()) == theName) break; //use current map
497 VISU::Mesh_var aMesh;
498 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
502 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
503 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
508 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
513 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
514 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
518 if(!CORBA::is_nil(aMesh)){ // Create Actor
519 VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
520 if(SVTK_ViewWindow* vf = VISU::GetViewWindow()){
522 pPresent->SetPresentationType(VISU::POINT);
523 VISU_Actor *anActor = pPresent->CreateActor();
524 vf->AddActor(anActor);
526 SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr("VISU_WARNING"),
527 tr("ERR_CANT_CREATE_ACTOR"),
532 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
533 tr("ERR_CANT_BUILD_PRESENTATION"),
536 return aMesh._retn();
540 void VisuGUI_StreamLinesDlg::accept() {
541 if (myScalarPane->check())