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_Selection.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 "SUIT_Desktop.h"
26 #include "SUIT_ResourceMgr.h"
27 #include "SUIT_MessageBox.h"
29 #include "SALOME_ListIO.hxx"
31 #include "SVTK_ViewWindow.h"
35 #include <qgroupbox.h>
36 #include <qcolordialog.h>
37 #include <qtabwidget.h>
39 #include <SALOMEDSClient_SObject.hxx>
40 #include <SALOMEDS_SObject.hxx>
44 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (QWidget* parent)
45 : QDialog(parent, "VisuGUI_StreamLinesDlg", false,
46 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)));
87 SUIT_Study* aActiveStudy = VisuGUI::GetActiveStudy();
88 SalomeApp_SelectionMgr* aSel = VisuGUI::application()->selectionMgr();
89 SALOME_ListIO selected; aSel->selectedObjects( selected );
90 if( selected.Extent() > 0 ) {
91 Handle(SALOME_InteractiveObject) aIO = selected.First();
93 SALOMEDSClient_SObject* aSObject = VisuGUI::GetStudyDocument()->FindObjectID(aIO->getEntry());
94 aSObject = aSObject->GetFather();
95 aSObject = aSObject->GetFather();
96 aSObject = aSObject->GetFather();
97 aSObject = aSObject->GetFather();
98 mySelectionObj = aSObject;
99 CORBA::Object_var anObject = VISU::ClientSObjectToObject( mySelectionObj );
100 VISU::Result_var aResult;
101 if (CORBA::is_nil(anObject)) {
102 mySelectionObj = mySelectionObj->GetFather();
104 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
106 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
107 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
108 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject( aChildSObj );
110 if(!CORBA::is_nil( aChildObject ) ) {
111 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
112 if( !CORBA::is_nil( aPrsObj ) ) { // if this is a Prs object
113 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
114 (aPrsObj->GetType() != VISU::TMESH)) {
115 SALOMEDSClient_GenericAttribute* anAttr;
116 if ( aChildSObj->FindAttribute(anAttr, "AttributeName") ) {
117 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>( anAttr );
118 myPrsLst += QString(aName->Value());
119 myPrsList.append(aPrsObj);
125 // else { // This is not a Prs object
126 SALOMEDSClient_GenericAttribute* anAttr;
127 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
128 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
129 string aComm = aComment->Value();
130 QString strIn(aComm.c_str());
131 VISU::Storable::TRestoringMap aMap;
132 VISU::Storable::StrToMap(strIn,aMap);
134 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
136 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
137 SALOMEDSClient_GenericAttribute* aNameAttr;
138 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
139 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>( aNameAttr );
140 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow( aChildObject );
143 myFamilisLst += QString(aName->Value());
144 myFamilyList.append(aPrsObj);
147 myGroupsLst += QString(aName->Value());
148 myGroupList.append(aPrsObj);
151 myEntitiesLst += QString(aName->Value());
152 myEntityList.append(aPrsObj);
163 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
164 aSrcLayout->addMultiCellWidget(mySrcCombo, 1, 1, 0, 1);
166 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
167 aSrcLayout->addWidget(aPercentLbl, 2, 0);
169 myPntPercent = new QtxDblSpinBox( 0, 1, 0.1, aSourceBox );
170 aSrcLayout->addWidget(myPntPercent, 2, 1);
172 TopLayout->addMultiCellWidget(aSourceBox, 0, 0, 0, 1);
174 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
175 TopLayout->addWidget(aStepLenLbl, 1, 0);
176 myStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
177 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
178 TopLayout->addWidget(myStepLen, 1, 1);
179 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
181 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
182 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
183 myIntegStepLen = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 0.1, aTopBox );
184 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
185 TopLayout->addWidget(myIntegStepLen, 2, 1);
186 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
188 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
189 TopLayout->addWidget(aPropagationLbl, 3, 0);
190 myPropTime = new QtxDblSpinBox( DBL_MIN, DBL_MAX, 1, aTopBox );
191 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
192 TopLayout->addWidget(myPropTime, 3, 1);
193 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
195 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
196 TopLayout->addWidget(aDirLbl, 4, 0);
197 myDirCombo = new QComboBox(aTopBox);
198 myDirCombo->insertItem("Forward");
199 myDirCombo->insertItem("Backward");
200 myDirCombo->insertItem("Both");
201 TopLayout->addWidget(myDirCombo, 4, 1);
203 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox, "UseMagn");
204 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
205 TopLayout->addWidget(myUseScalar, 5, 0);
207 SelColor = new QPushButton (tr("USE_COLOR_BTN"), aTopBox, "SelColor");
208 connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
209 TopLayout->addWidget( SelColor, 5, 1);
211 aTabBox->addTab(aTopBox, "Stream Lines");
212 myScalarPane = new VisuGUI_ScalarBarPane(this, false);
213 myScalarPane->setMargin( 5 );
214 aTabBox->addTab(myScalarPane, "Scalar Bar");
216 aBoxLayout->addWidget(aTabBox);
218 QGroupBox* aGroupButtons = new QGroupBox( this, "GroupButtons" );
219 aGroupButtons->setColumnLayout(0, Qt::Vertical );
220 aGroupButtons->layout()->setSpacing( 0 );
221 aGroupButtons->layout()->setMargin( 0 );
223 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons->layout() );
224 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
225 aGroupButtonsLayout->setSpacing( 6 );
226 aGroupButtonsLayout->setMargin( 11 );
228 QPushButton* aOkBtn = new QPushButton( tr( "&OK" ), aGroupButtons, "buttonOk" );
229 aOkBtn->setAutoDefault( TRUE );
230 aOkBtn->setDefault( TRUE );
231 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
232 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
234 QPushButton* aCancelBtn = new QPushButton( tr( "&Cancel" ) , aGroupButtons, "buttonCancel" );
235 aCancelBtn->setAutoDefault( TRUE );
236 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
237 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
238 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
240 aBoxLayout->addWidget(aGroupButtons);
247 void VisuGUI_StreamLinesDlg::initFromPrsObject (VISU::StreamLines_i* thePrs)
249 myScalarPane->initFromPrsObject(thePrs);
252 static int aNbOfSteps = 30;
253 VISU_StreamLinesPL* aStreamLinesPL = thePrs->GetStreamLinesPL();
255 aMin = aStreamLinesPL->GetMinPropagationTime();
256 aMax = aStreamLinesPL->GetMaxPropagationTime();
257 myPropTime->setRange(aMin,aMax);
258 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
259 myPropTime->setLineStep((aMax-aMin)/aNbOfSteps);
261 aMin = aStreamLinesPL->GetMinStepLength();
262 aMax = aStreamLinesPL->GetMaxStepLength();
263 myStepLen->setRange(aMin,aMax);
264 myStepLen->setValue(aStreamLinesPL->GetStepLength());
265 myStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
267 aMin = aStreamLinesPL->GetMinIntegrationStep();
268 aMax = aStreamLinesPL->GetMaxIntegrationStep();
269 myIntegStepLen->setRange(aMin,aMax);
270 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
271 myIntegStepLen->setLineStep((aMax-aMin)/aNbOfSteps);
273 switch (thePrs->GetDirection()) {
274 case VISU::StreamLines::FORWARD:
275 myDirCombo->setCurrentItem(0);
277 case VISU::StreamLines::BACKWARD:
278 myDirCombo->setCurrentItem(1);
280 case VISU::StreamLines::BOTH:
281 myDirCombo->setCurrentItem(2);
283 myUseScalar->setChecked(thePrs->IsColored());
284 myPntPercent->setValue(thePrs->GetUsedPoints());
286 mySrcCombo->setEnabled(false);
287 QString aSrcEntry = thePrs->GetSourceEntry();
289 SALOMEDS::Color anOldColor = thePrs->GetColor();
290 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
294 #define INITPRS(PRSLIST, PRSNUM) \
295 for (int i = 0; i < PRSLIST.count(); i++) { \
296 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
297 if (aPrs == NULL) continue; \
298 if (aSrcEntry == aPrs->GetEntry()) { \
299 onSourceTypeChange(PRSNUM); \
300 myUseSrcCombo->setCurrentItem(PRSNUM); \
301 mySrcCombo->setEnabled(true); \
302 mySrcCombo->setCurrentItem(i); \
307 if (!aSrcEntry.isEmpty()) {
308 INITPRS(myEntityList, 1);
309 INITPRS(myFamilyList, 2);
310 INITPRS(myGroupList, 3);
311 INITPRS(myPrsList, 4);
316 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::StreamLines_i* thePrs)
318 bool isAccepted = myScalarPane->storeToPrsObject(thePrs);
320 thePrs->ShowColored(myUseScalar->isChecked());
321 if (!thePrs->IsColored()) {
322 SALOMEDS::Color aColor;
323 aColor.R = myColor.red()/255.;
324 aColor.G = myColor.green()/255.;
325 aColor.B = myColor.blue()/255.;
326 thePrs->SetColor(aColor);
329 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
330 switch (myDirCombo->currentItem()) {
332 aDirection = VISU::StreamLines::FORWARD;
335 aDirection = VISU::StreamLines::BACKWARD;
338 aDirection = VISU::StreamLines::BOTH;
341 VISU::Prs3d_var aPrs;
342 int aSrcSelection = myUseSrcCombo->currentItem();
343 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentItem() : -1;
344 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
345 VISU::VISUType aType;
347 switch (aSrcSelection) {
349 aPrs = myEntityList[aSrcItem];
350 aType = VISU::TENTITY;
351 aName = myEntitiesLst[aSrcItem];
354 aPrs = myFamilyList[aSrcItem];
355 aType = VISU::TFAMILY;
356 aName = myFamilisLst[aSrcItem];
359 aPrs = myGroupList[aSrcItem];
360 aType = VISU::TGROUP;
361 aName = myGroupsLst[aSrcItem];
363 case 4: // Presentation
364 aPrs = myPrsList[aSrcItem];
367 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
368 aPrs = createMesh(aType, aName);
371 isAccepted = thePrs->SetParams(myIntegStepLen->value(),
375 myPntPercent->value(),
379 // SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("WRN_VISU"),
380 // tr("ERR_CANT_BUILD_PRESENTATION"),
388 void VisuGUI_StreamLinesDlg::setColor( QColor color )
391 SelColor->setPaletteBackgroundColor(myColor);
396 Called when "Select Color" buttonx clicked
398 void VisuGUI_StreamLinesDlg::setVColor()
400 QColor cnew = QColorDialog::getColor( myColor, this );
401 if ( cnew.isValid() )
407 Enbled/disables magnitude coloring
409 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
411 myUseScalar->setEnabled( enable );
416 Called when "Magnitude Coloring" check box clicked
418 void VisuGUI_StreamLinesDlg::enableSetColor()
420 SelColor->setEnabled(!myUseScalar->isChecked() );
423 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
426 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
429 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
430 myStepLen->setMaxValue(theValue);
433 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
436 mySrcCombo->setEnabled(false);
439 mySrcCombo->setEnabled(true);
443 mySrcCombo->insertStringList(myEntitiesLst);
446 mySrcCombo->insertStringList(myFamilisLst);
449 mySrcCombo->insertStringList(myGroupsLst);
451 case 4: // Presentation
452 mySrcCombo->insertStringList(myPrsLst);
458 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
460 return VISU::Mesh::_nil();
462 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
463 VISU::Result_var aResult;
464 if (!CORBA::is_nil(anObject)) {
465 aResult = VISU::Result::_narrow(anObject);
467 if (CORBA::is_nil(aResult)) {
468 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
469 tr("WRN_NO_AVAILABLE_DATA"),
471 return VISU::Mesh::_nil();
473 SALOMEDSClient_ChildIterator* aIter = VisuGUI::GetStudyDocument()->NewChildIterator( mySelectionObj );
474 VISU::Storable::TRestoringMap aMap;
476 for (aIter->InitEx(true); aIter->More(); aIter->Next() ) {
477 SALOMEDSClient_SObject* aChildSObj = aIter->Value();
478 SALOMEDSClient_GenericAttribute* anAttr;
479 if (aChildSObj->FindAttribute(anAttr, "AttributeComment")) {
480 SALOMEDSClient_AttributeComment* aComment = dynamic_cast<SALOMEDSClient_AttributeComment*>( anAttr );
481 CORBA::String_var aComm = aComment->Value().c_str();
482 QString strIn(aComm.in());
484 VISU::Storable::StrToMap(strIn,aMap);
486 VISU::VISUType aType = (VISU::VISUType)VISU::Storable::FindValue(aMap,"myType",&isExist).toInt();
488 if (aType != theType) continue;
490 SALOMEDSClient_GenericAttribute* aNameAttr;
491 if ( aChildSObj->FindAttribute(aNameAttr, "AttributeName") ) {
492 SALOMEDSClient_AttributeName* aName = dynamic_cast<SALOMEDSClient_AttributeName*>(aNameAttr);
493 if (QString(aName->Value()) == theName) break; //use current map
498 VISU::Mesh_var aMesh;
499 QString aMeshName = VISU::Storable::FindValue(aMap,"myMeshName");
503 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myEntityId").toInt();
504 aMesh = VisuGUI::GetVisuGen()->FamilyMeshOnEntity(aResult,aMeshName.latin1(),anEntity,theName.latin1());
509 aMesh = VisuGUI::GetVisuGen()->GroupMesh(aResult,aMeshName.latin1(), theName.latin1());
514 VISU::Entity anEntity = (VISU::Entity)VISU::Storable::FindValue(aMap,"myId").toInt();
515 aMesh = VisuGUI::GetVisuGen()->MeshOnEntity(aResult,aMeshName.latin1(),anEntity);
519 if(!CORBA::is_nil(aMesh)){ // Create Actor
520 VISU::Mesh_i* pPresent = dynamic_cast<VISU::Mesh_i*>(VISU::GetServant(aMesh).in());
521 if(SVTK_ViewWindow* vf = VISU::GetViewWindow()){
523 pPresent->SetPresentationType(VISU::POINT);
524 VISU_Actor *anActor = pPresent->CreateActor();
525 vf->AddActor(anActor);
527 SUIT_MessageBox::warn1 ( VisuGUI::application()->desktop(), tr("VISU_WARNING"),
528 tr("ERR_CANT_CREATE_ACTOR"),
533 SUIT_MessageBox::warn1(VisuGUI::application()->desktop(), tr("VISU_WARNING"),
534 tr("ERR_CANT_BUILD_PRESENTATION"),
537 return aMesh._retn();
541 void VisuGUI_StreamLinesDlg::accept() {
542 if (myScalarPane->check())