1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : VisuGUI_StreamLinesDlg.cxx
24 // Author : Vitaly SMETANNIKOV
27 #include "VisuGUI_StreamLinesDlg.h"
30 #include "VisuGUI_Tools.h"
31 #include "VisuGUI_InputPane.h"
33 #include "VISU_Mesh_i.hh"
34 #include "VISU_Gen_i.hh"
35 #include "VISU_StreamLines_i.hh"
36 #include "VISU_ColoredPrs3dFactory.hh"
37 #include "VISU_StreamLinesPL.hxx"
38 #include "VISU_Actor.h"
40 #include <SalomeApp_DoubleSpinBox.h>
41 #include "SalomeApp_Application.h"
42 #include "LightApp_Application.h"
43 #include "LightApp_SelectionMgr.h"
45 #include "SVTK_ViewWindow.h"
47 #include "SUIT_Desktop.h"
48 #include "SUIT_Session.h"
49 #include "SUIT_ResourceMgr.h"
50 #include "SUIT_MessageBox.h"
52 #include "SALOME_ListIO.hxx"
54 #include <SALOMEDSClient_SObject.hxx>
56 #include <QtxColorButton.h>
65 #include <QColorDialog>
67 #include <QPushButton>
69 #include <QStringList>
74 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (SalomeApp_Module* theModule)
75 : VisuGUI_ScalarBarBaseDlg(theModule),
79 setWindowTitle(tr("DLG_TITLE"));
80 setSizeGripEnabled(TRUE);
82 QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
83 aBoxLayout->setSpacing( 6 );
84 aBoxLayout->setMargin( 11 );
86 myTabBox = new QTabWidget(this);
88 QFrame* aTopBox = new QFrame(this);
89 //aTopBox->setMargin( 11 );
90 QGridLayout* TopLayout = new QGridLayout( aTopBox );
91 TopLayout->setAlignment( Qt::AlignTop );
92 TopLayout->setSpacing( 8 );
93 TopLayout->setMargin( 11 );
96 QGroupBox* aSourceBox = new QGroupBox (tr("SOURCE_GRP"), aTopBox);
97 //aSourceBox->setColumnLayout(0, Qt::Vertical);
98 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox );
99 aSrcLayout->setSpacing( 6 );
100 aSrcLayout->setMargin( 11 );
102 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
103 aSrcLayout->addWidget(aTypeLbl, 0, 0);
105 myUseSrcCombo = new QComboBox(aSourceBox);
107 aChoise.append( "None" );
108 aChoise.append( "Entity" );
109 aChoise.append( "Family" );
110 aChoise.append( "Group" );
111 aChoise.append( "Presentation" );
112 myUseSrcCombo->addItems(aChoise);
113 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
115 mySrcCombo = new QComboBox(aSourceBox);
116 mySrcCombo->setEnabled((myUseSrcCombo->currentIndex() == 0));
118 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
120 // Find all fields and time stamps on it
121 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
122 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
123 SALOME_ListIO selected;
124 aSel->selectedObjects(selected);
125 if (selected.Extent() > 0) {
126 Handle(SALOME_InteractiveObject) aIO = selected.First();
127 if (aIO->hasEntry()) {
128 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
129 VISU::VISUType aType = VISU::Storable::SObject2Type(aSObject);
131 case VISU::TTIMESTAMP: {
132 aSObject = aSObject->GetFather();
133 aSObject = aSObject->GetFather();
137 _PTR(SObject) newSObject;
138 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
139 aSObject = aSObject->GetFather();
142 case VISU::TANIMATION: {
143 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
144 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
145 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
146 _PTR(SObject) newSObject;
147 if(aTmpChildSObj->ReferencedObject(newSObject)){
148 aSObject = newSObject;
149 aSObject->GetFather();
156 aSObject = aSObject->GetFather();
157 aSObject = aSObject->GetFather();
159 mySelectionObj = aSObject;
160 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
161 if (CORBA::is_nil(anObject)) {
162 mySelectionObj = mySelectionObj->GetFather();
167 if (mySelectionObj) {
168 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
170 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
171 _PTR(SObject) aChildSObj = aIter->Value();
172 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
174 if (!CORBA::is_nil(aChildObject)) {
175 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
176 if (!CORBA::is_nil(aPrsObj)) { // if this is a Prs object
177 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
178 (aPrsObj->GetType() != VISU::TMESH)) {
179 _PTR(GenericAttribute) anAttr;
180 if (aChildSObj->FindAttribute(anAttr, "AttributeName")) {
181 _PTR(AttributeName) aName (anAttr);
182 myPrsLst += QString(aName->Value().c_str());
183 myPrsList.append(aPrsObj);
190 VISU::VISUType aType = VISU::Storable::SObject2Type(aChildSObj);
191 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
192 _PTR(GenericAttribute) aNameAttr;
193 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
194 _PTR(AttributeName) aName (aNameAttr);
195 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
198 myFamilisLst += QString(aName->Value().c_str());
199 myFamilyList.append(aPrsObj);
202 myGroupsLst += QString(aName->Value().c_str());
203 myGroupList.append(aPrsObj);
206 myEntitiesLst += QString(aName->Value().c_str());
207 myEntityList.append(aPrsObj);
215 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
216 aSrcLayout->addWidget(mySrcCombo, 1, 0, 1, 2);
218 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
219 aSrcLayout->addWidget(aPercentLbl, 2, 0);
221 myPntPercent = new SalomeApp_DoubleSpinBox( aSourceBox );
222 VISU::initSpinBox( myPntPercent, 0., 1., .1, "parametric_precision" );
223 aSrcLayout->addWidget(myPntPercent, 2, 1);
225 TopLayout->addWidget(aSourceBox, 0, 0, 1, 2);
227 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
228 TopLayout->addWidget(aStepLenLbl, 1, 0);
229 myStepLen = new SalomeApp_DoubleSpinBox( aTopBox );
230 VISU::initSpinBox( myStepLen,
231 std::numeric_limits<double>::min(),
232 std::numeric_limits<double>::max(),
234 "parametric_precision" );
235 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
236 TopLayout->addWidget(myStepLen, 1, 1);
237 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
239 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
240 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
241 myIntegStepLen = new SalomeApp_DoubleSpinBox( aTopBox );
242 VISU::initSpinBox( myIntegStepLen,
243 std::numeric_limits<double>::min(),
244 std::numeric_limits<double>::max(),
246 "parametric_precision" );
247 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
248 TopLayout->addWidget(myIntegStepLen, 2, 1);
249 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
251 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
252 TopLayout->addWidget(aPropagationLbl, 3, 0);
253 myPropTime = new SalomeApp_DoubleSpinBox( aTopBox );
254 VISU::initSpinBox( myPropTime,
255 std::numeric_limits<double>::min(),
256 std::numeric_limits<double>::max(),
258 "parametric_precision" );
259 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
260 TopLayout->addWidget(myPropTime, 3, 1);
261 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
263 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
264 TopLayout->addWidget(aDirLbl, 4, 0);
265 myDirCombo = new QComboBox(aTopBox);
266 myDirCombo->addItem("Forward");
267 myDirCombo->addItem("Backward");
268 myDirCombo->addItem("Both");
269 TopLayout->addWidget(myDirCombo, 4, 1);
271 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox);
272 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
273 TopLayout->addWidget(myUseScalar, 5, 0);
275 SelColor = new QtxColorButton( aTopBox );
276 SelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
277 //connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
278 TopLayout->addWidget( SelColor, 5, 1);
280 myTabBox->addTab(aTopBox, "Stream Lines");
281 myInputPane = new VisuGUI_InputPane(VISU::TSTREAMLINES, theModule, this);
282 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
283 myTabBox->addTab(myInputPane, "Input");
285 aBoxLayout->addWidget(myTabBox);
287 QGroupBox* aGroupButtons = new QGroupBox( this );
288 //aGroupButtons->setColumnLayout(0, Qt::Vertical );
289 //aGroupButtons->layout()->setSpacing( 0 );
290 //aGroupButtons->layout()->setMargin( 0 );
292 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons );
293 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
294 aGroupButtonsLayout->setSpacing( 6 );
295 aGroupButtonsLayout->setMargin( 11 );
297 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aGroupButtons );
298 aOkBtn->setAutoDefault( TRUE );
299 aOkBtn->setDefault( TRUE );
300 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
301 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
303 QPushButton* aCancelBtn = new QPushButton( tr( "BUT_CANCEL" ) , aGroupButtons );
304 aCancelBtn->setAutoDefault( TRUE );
305 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
307 QPushButton* aHelpBtn = new QPushButton( tr( "BUT_HELP" ) , aGroupButtons );
308 aHelpBtn->setAutoDefault( TRUE );
309 aGroupButtonsLayout->addWidget( aHelpBtn, 0, 3 );
311 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
312 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
313 connect( aHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
315 aBoxLayout->addWidget(aGroupButtons);
320 VisuGUI_StreamLinesDlg::~VisuGUI_StreamLinesDlg()
323 void VisuGUI_StreamLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
327 myPrsCopy = VISU::TSameAsFactory<VISU::TSTREAMLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
329 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
331 static int aNbOfSteps = 30;
332 VISU_StreamLinesPL* aStreamLinesPL = myPrsCopy->GetSpecificPL();
334 aMin = aStreamLinesPL->GetMinPropagationTime();
335 aMax = aStreamLinesPL->GetMaxPropagationTime();
336 myPropTime->setRange(aMin,aMax);
337 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
338 myPropTime->setSingleStep((aMax-aMin)/aNbOfSteps);
340 aMin = aStreamLinesPL->GetMinStepLength();
341 aMax = aStreamLinesPL->GetMaxStepLength();
342 myStepLen->setRange(aMin,aMax);
343 myStepLen->setValue(aStreamLinesPL->GetStepLength());
344 myStepLen->setSingleStep((aMax-aMin)/aNbOfSteps);
346 aMin = aStreamLinesPL->GetMinIntegrationStep();
347 aMax = aStreamLinesPL->GetMaxIntegrationStep();
348 myIntegStepLen->setRange(aMin,aMax);
349 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
350 myIntegStepLen->setSingleStep((aMax-aMin)/aNbOfSteps);
352 switch (myPrsCopy->GetDirection()) {
353 case VISU::StreamLines::FORWARD:
354 myDirCombo->setCurrentIndex(0);
356 case VISU::StreamLines::BACKWARD:
357 myDirCombo->setCurrentIndex(1);
359 case VISU::StreamLines::BOTH:
360 myDirCombo->setCurrentIndex(2);
362 myUseScalar->setChecked(myPrsCopy->IsColored());
363 myPntPercent->setValue(myPrsCopy->GetUsedPoints());
365 mySrcCombo->setEnabled(false);
366 QString aSrcEntry = myPrsCopy->GetSourceEntry();
368 SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
369 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
373 #define INITPRS(PRSLIST, PRSNUM) \
374 for (int i = 0; i < PRSLIST.count(); i++) { \
375 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
376 if (aPrs == NULL) continue; \
377 if (aSrcEntry == aPrs->GetEntry().c_str()) { \
378 onSourceTypeChange(PRSNUM); \
379 myUseSrcCombo->setCurrentIndex(PRSNUM); \
380 mySrcCombo->setEnabled(true); \
381 mySrcCombo->setCurrentIndex(i); \
386 if (!aSrcEntry.isEmpty()) {
387 INITPRS(myEntityList, 1);
388 INITPRS(myFamilyList, 2);
389 INITPRS(myGroupList, 3);
390 INITPRS(myPrsList, 4);
397 myInputPane->initFromPrsObject( myPrsCopy );
398 myTabBox->setCurrentIndex( 0 );
402 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
404 VISU::TSameAsFactory<VISU::TSTREAMLINES>().Copy(myPrsCopy, thePrs);
411 void VisuGUI_StreamLinesDlg::setColor( QColor color )
414 QPalette aPal = SelColor->palette();
415 aPal.setColor( SelColor->backgroundRole(), myColor );
416 SelColor->setPalette( aPal );*/
417 SelColor->setColor( color );
422 Called when "Select Color" buttonx clicked
424 /*void VisuGUI_StreamLinesDlg::setVColor()
426 QColor cnew = QColorDialog::getColor( myColor, this );
427 if ( cnew.isValid() )
433 Enbled/disables magnitude coloring
435 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
437 myUseScalar->setEnabled( enable );
442 Called when "Magnitude Coloring" check box clicked
444 void VisuGUI_StreamLinesDlg::enableSetColor()
446 SelColor->setEnabled(!myUseScalar->isChecked() );
449 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
452 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
455 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
456 myStepLen->setMaximum(theValue);
459 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
462 mySrcCombo->setEnabled(false);
465 mySrcCombo->setEnabled(true);
469 mySrcCombo->addItems(myEntitiesLst);
472 mySrcCombo->addItems(myFamilisLst);
475 mySrcCombo->addItems(myGroupsLst);
477 case 4: // Presentation
478 mySrcCombo->addItems(myPrsLst);
484 void VisuGUI_StreamLinesDlg::storeToPrsCopy() {
486 if(!myInputPane->check() || !GetScalarPane()->check()) {
491 myStatus = myInputPane->storeToPrsObject( myPrsCopy );
492 myStatus &= GetScalarPane()->storeToPrsObject( myPrsCopy );
495 myPrsCopy->ShowColored(myUseScalar->isChecked());
496 if (!myPrsCopy->IsColored()) {
497 SALOMEDS::Color aColor;
498 aColor.R = SelColor->color().red()/255.;
499 aColor.G = SelColor->color().green()/255.;
500 aColor.B = SelColor->color().blue()/255.;
501 myPrsCopy->SetColor(aColor);
504 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
505 switch (myDirCombo->currentIndex()) {
507 aDirection = VISU::StreamLines::FORWARD;
510 aDirection = VISU::StreamLines::BACKWARD;
513 aDirection = VISU::StreamLines::BOTH;
516 VISU::Prs3d_var aPrs;
517 int aSrcSelection = myUseSrcCombo->currentIndex();
518 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentIndex() : -1;
519 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
520 VISU::VISUType aType;
522 switch (aSrcSelection) {
524 aPrs = myEntityList[aSrcItem];
525 aType = VISU::TENTITY;
526 aName = myEntitiesLst[aSrcItem];
529 aPrs = myFamilyList[aSrcItem];
530 aType = VISU::TFAMILY;
531 aName = myFamilisLst[aSrcItem];
534 aPrs = myGroupList[aSrcItem];
535 aType = VISU::TGROUP;
536 aName = myGroupsLst[aSrcItem];
538 case 4: // Presentation
539 aPrs = myPrsList[aSrcItem];
542 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
543 aPrs = createMesh(aType, aName);
546 myStatus &= myPrsCopy->SetParams(myIntegStepLen->value(),
550 myPntPercent->value(),
556 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
558 return VISU::Mesh::_nil();
561 void VisuGUI_StreamLinesDlg::accept()
564 //rnv: To fix the IPAL21920: WinTC5.1.4: parameters of StreamLines are not taken in account.
565 //rnv: Show confirmation message in case if 'Used points' and 'Step length' were re-calculated.
566 //1. Store parameters to the myPrsCopy
569 //2. Check 'Used points' and 'Step length' parameters
570 if( myStepLen->value() > myPrsCopy->GetStepLength() ||
571 myPntPercent->value() > myPrsCopy->GetUsedPoints() ) {
572 QString aWarning = tr("STREAM_MEMORY_ALERT");
573 if( SUIT_MessageBox::warning( this, tr( "WRN_VISU_WARNING" ), aWarning, tr( "BUT_OK" ), tr( "CANCEL" ) ) == 1 ) {
574 // Set re-calculated values
575 myStepLen->setValue(myPrsCopy->GetStepLength());
576 myPntPercent->setValue(myPrsCopy->GetUsedPoints());
581 VisuGUI_ScalarBarBaseDlg::accept();
584 void VisuGUI_StreamLinesDlg::reject()
586 VisuGUI_ScalarBarBaseDlg::reject();
589 QString VisuGUI_StreamLinesDlg::GetContextHelpFilePath()
591 return "stream_lines_page.html";