1 // Copyright (C) 2007-2010 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),
78 setWindowTitle(tr("DLG_TITLE"));
79 setSizeGripEnabled(TRUE);
81 QVBoxLayout* aBoxLayout = new QVBoxLayout(this);
82 aBoxLayout->setSpacing( 6 );
83 aBoxLayout->setMargin( 11 );
85 myTabBox = new QTabWidget(this);
87 QFrame* aTopBox = new QFrame(this);
88 //aTopBox->setMargin( 11 );
89 QGridLayout* TopLayout = new QGridLayout( aTopBox );
90 TopLayout->setAlignment( Qt::AlignTop );
91 TopLayout->setSpacing( 8 );
92 TopLayout->setMargin( 11 );
95 QGroupBox* aSourceBox = new QGroupBox (tr("SOURCE_GRP"), aTopBox);
96 //aSourceBox->setColumnLayout(0, Qt::Vertical);
97 QGridLayout* aSrcLayout = new QGridLayout( aSourceBox );
98 aSrcLayout->setSpacing( 6 );
99 aSrcLayout->setMargin( 11 );
101 QLabel* aTypeLbl = new QLabel( tr( "LBL_SOURCE_TYPE" ), aSourceBox);
102 aSrcLayout->addWidget(aTypeLbl, 0, 0);
104 myUseSrcCombo = new QComboBox(aSourceBox);
106 aChoise.append( "None" );
107 aChoise.append( "Entity" );
108 aChoise.append( "Family" );
109 aChoise.append( "Group" );
110 aChoise.append( "Presentation" );
111 myUseSrcCombo->addItems(aChoise);
112 aSrcLayout->addWidget(myUseSrcCombo, 0, 1);
114 mySrcCombo = new QComboBox(aSourceBox);
115 mySrcCombo->setEnabled((myUseSrcCombo->currentIndex() == 0));
117 connect(myUseSrcCombo, SIGNAL(activated(int)), this, SLOT(onSourceTypeChange(int)));
119 // Find all fields and time stamps on it
120 _PTR(Study) aActiveStudy = VISU::GetCStudy(VISU::GetAppStudy(myVisuGUI));
121 LightApp_SelectionMgr* aSel = VISU::GetSelectionMgr(myVisuGUI);
122 SALOME_ListIO selected;
123 aSel->selectedObjects(selected);
124 if (selected.Extent() > 0) {
125 Handle(SALOME_InteractiveObject) aIO = selected.First();
126 if (aIO->hasEntry()) {
127 _PTR(SObject) aSObject = aActiveStudy->FindObjectID(aIO->getEntry());
128 VISU::VISUType aType = VISU::Storable::SObject2Type(aSObject);
130 case VISU::TTIMESTAMP: {
131 aSObject = aSObject->GetFather();
132 aSObject = aSObject->GetFather();
136 _PTR(SObject) newSObject;
137 if(aSObject->ReferencedObject(newSObject)) aSObject = newSObject;
138 aSObject = aSObject->GetFather();
141 case VISU::TANIMATION: {
142 _PTR(ChildIterator) aTmpIter = aActiveStudy->NewChildIterator(aSObject);
143 for (aTmpIter->InitEx(true); aTmpIter->More(); aTmpIter->Next()) {
144 _PTR(SObject) aTmpChildSObj = aTmpIter->Value();
145 _PTR(SObject) newSObject;
146 if(aTmpChildSObj->ReferencedObject(newSObject)){
147 aSObject = newSObject;
148 aSObject->GetFather();
155 aSObject = aSObject->GetFather();
156 aSObject = aSObject->GetFather();
158 mySelectionObj = aSObject;
159 CORBA::Object_var anObject = VISU::ClientSObjectToObject(mySelectionObj);
160 if (CORBA::is_nil(anObject)) {
161 mySelectionObj = mySelectionObj->GetFather();
166 if (mySelectionObj) {
167 _PTR(ChildIterator) aIter = aActiveStudy->NewChildIterator(mySelectionObj);
169 for (aIter->InitEx(true); aIter->More(); aIter->Next()) {
170 _PTR(SObject) aChildSObj = aIter->Value();
171 CORBA::Object_var aChildObject = VISU::ClientSObjectToObject(aChildSObj);
173 if (!CORBA::is_nil(aChildObject)) {
174 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
175 if (!CORBA::is_nil(aPrsObj)) { // if this is a Prs object
176 if ((aPrsObj->GetType() != VISU::TSTREAMLINES) &&
177 (aPrsObj->GetType() != VISU::TMESH)) {
178 _PTR(GenericAttribute) anAttr;
179 if (aChildSObj->FindAttribute(anAttr, "AttributeName")) {
180 _PTR(AttributeName) aName (anAttr);
181 myPrsLst += QString(aName->Value().c_str());
182 myPrsList.append(aPrsObj);
189 VISU::VISUType aType = VISU::Storable::SObject2Type(aChildSObj);
190 if ((aType == VISU::TFAMILY) || (aType == VISU::TGROUP) || (aType == VISU::TENTITY)) {
191 _PTR(GenericAttribute) aNameAttr;
192 if (aChildSObj->FindAttribute(aNameAttr, "AttributeName")) {
193 _PTR(AttributeName) aName (aNameAttr);
194 VISU::Prs3d_var aPrsObj = VISU::Prs3d::_narrow(aChildObject);
197 myFamilisLst += QString(aName->Value().c_str());
198 myFamilyList.append(aPrsObj);
201 myGroupsLst += QString(aName->Value().c_str());
202 myGroupList.append(aPrsObj);
205 myEntitiesLst += QString(aName->Value().c_str());
206 myEntityList.append(aPrsObj);
214 // connect(myUseSrcChk, SIGNAL(toggled(bool)), mySrcCombo, SLOT(setEnabled(bool)));
215 aSrcLayout->addWidget(mySrcCombo, 1, 0, 1, 2);
217 QLabel* aPercentLbl = new QLabel (tr("LBL_USED_POINTS"), aSourceBox);
218 aSrcLayout->addWidget(aPercentLbl, 2, 0);
220 myPntPercent = new SalomeApp_DoubleSpinBox( aSourceBox );
221 VISU::initSpinBox( myPntPercent, 0., 1., .1, "parametric_precision" );
222 aSrcLayout->addWidget(myPntPercent, 2, 1);
224 TopLayout->addWidget(aSourceBox, 0, 0, 1, 2);
226 QLabel* aStepLenLbl = new QLabel (tr("LBL_STEP_LENGTH"), aTopBox);
227 TopLayout->addWidget(aStepLenLbl, 1, 0);
228 myStepLen = new SalomeApp_DoubleSpinBox( aTopBox );
229 VISU::initSpinBox( myStepLen,
230 std::numeric_limits<double>::min(),
231 std::numeric_limits<double>::max(),
233 "parametrc_precision" );
234 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
235 TopLayout->addWidget(myStepLen, 1, 1);
236 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
238 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
239 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
240 myIntegStepLen = new SalomeApp_DoubleSpinBox( aTopBox );
241 VISU::initSpinBox( myIntegStepLen,
242 std::numeric_limits<double>::min(),
243 std::numeric_limits<double>::max(),
245 "parametrc_precision" );
246 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
247 TopLayout->addWidget(myIntegStepLen, 2, 1);
248 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
250 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
251 TopLayout->addWidget(aPropagationLbl, 3, 0);
252 myPropTime = new SalomeApp_DoubleSpinBox( aTopBox );
253 VISU::initSpinBox( myPropTime,
254 std::numeric_limits<double>::min(),
255 std::numeric_limits<double>::max(),
257 "parametrc_precision" );
258 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
259 TopLayout->addWidget(myPropTime, 3, 1);
260 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
262 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
263 TopLayout->addWidget(aDirLbl, 4, 0);
264 myDirCombo = new QComboBox(aTopBox);
265 myDirCombo->addItem("Forward");
266 myDirCombo->addItem("Backward");
267 myDirCombo->addItem("Both");
268 TopLayout->addWidget(myDirCombo, 4, 1);
270 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox);
271 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
272 TopLayout->addWidget(myUseScalar, 5, 0);
274 SelColor = new QtxColorButton( aTopBox );
275 SelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
276 //connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
277 TopLayout->addWidget( SelColor, 5, 1);
279 myTabBox->addTab(aTopBox, "Stream Lines");
280 myInputPane = new VisuGUI_InputPane(VISU::TSTREAMLINES, theModule, this);
281 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
282 myTabBox->addTab(myInputPane, "Input");
284 aBoxLayout->addWidget(myTabBox);
286 QGroupBox* aGroupButtons = new QGroupBox( this );
287 //aGroupButtons->setColumnLayout(0, Qt::Vertical );
288 //aGroupButtons->layout()->setSpacing( 0 );
289 //aGroupButtons->layout()->setMargin( 0 );
291 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons );
292 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
293 aGroupButtonsLayout->setSpacing( 6 );
294 aGroupButtonsLayout->setMargin( 11 );
296 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aGroupButtons );
297 aOkBtn->setAutoDefault( TRUE );
298 aOkBtn->setDefault( TRUE );
299 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
300 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
302 QPushButton* aCancelBtn = new QPushButton( tr( "BUT_CANCEL" ) , aGroupButtons );
303 aCancelBtn->setAutoDefault( TRUE );
304 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
306 QPushButton* aHelpBtn = new QPushButton( tr( "BUT_HELP" ) , aGroupButtons );
307 aHelpBtn->setAutoDefault( TRUE );
308 aGroupButtonsLayout->addWidget( aHelpBtn, 0, 3 );
310 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
311 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
312 connect( aHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
314 aBoxLayout->addWidget(aGroupButtons);
319 VisuGUI_StreamLinesDlg::~VisuGUI_StreamLinesDlg()
322 void VisuGUI_StreamLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
326 myPrsCopy = VISU::TSameAsFactory<VISU::TSTREAMLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
328 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
330 static int aNbOfSteps = 30;
331 VISU_StreamLinesPL* aStreamLinesPL = myPrsCopy->GetSpecificPL();
333 aMin = aStreamLinesPL->GetMinPropagationTime();
334 aMax = aStreamLinesPL->GetMaxPropagationTime();
335 myPropTime->setRange(aMin,aMax);
336 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
337 myPropTime->setSingleStep((aMax-aMin)/aNbOfSteps);
339 aMin = aStreamLinesPL->GetMinStepLength();
340 aMax = aStreamLinesPL->GetMaxStepLength();
341 myStepLen->setRange(aMin,aMax);
342 myStepLen->setValue(aStreamLinesPL->GetStepLength());
343 myStepLen->setSingleStep((aMax-aMin)/aNbOfSteps);
345 aMin = aStreamLinesPL->GetMinIntegrationStep();
346 aMax = aStreamLinesPL->GetMaxIntegrationStep();
347 myIntegStepLen->setRange(aMin,aMax);
348 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
349 myIntegStepLen->setSingleStep((aMax-aMin)/aNbOfSteps);
351 switch (myPrsCopy->GetDirection()) {
352 case VISU::StreamLines::FORWARD:
353 myDirCombo->setCurrentIndex(0);
355 case VISU::StreamLines::BACKWARD:
356 myDirCombo->setCurrentIndex(1);
358 case VISU::StreamLines::BOTH:
359 myDirCombo->setCurrentIndex(2);
361 myUseScalar->setChecked(myPrsCopy->IsColored());
362 myPntPercent->setValue(myPrsCopy->GetUsedPoints());
364 mySrcCombo->setEnabled(false);
365 QString aSrcEntry = myPrsCopy->GetSourceEntry();
367 SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
368 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
372 #define INITPRS(PRSLIST, PRSNUM) \
373 for (int i = 0; i < PRSLIST.count(); i++) { \
374 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
375 if (aPrs == NULL) continue; \
376 if (aSrcEntry == aPrs->GetEntry().c_str()) { \
377 onSourceTypeChange(PRSNUM); \
378 myUseSrcCombo->setCurrentIndex(PRSNUM); \
379 mySrcCombo->setEnabled(true); \
380 mySrcCombo->setCurrentIndex(i); \
385 if (!aSrcEntry.isEmpty()) {
386 INITPRS(myEntityList, 1);
387 INITPRS(myFamilyList, 2);
388 INITPRS(myGroupList, 3);
389 INITPRS(myPrsList, 4);
396 myInputPane->initFromPrsObject( myPrsCopy );
397 myTabBox->setCurrentIndex( 0 );
401 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
403 if(!myInputPane->check() || !GetScalarPane()->check())
406 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
407 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
410 myPrsCopy->ShowColored(myUseScalar->isChecked());
411 if (!myPrsCopy->IsColored()) {
412 SALOMEDS::Color aColor;
413 aColor.R = SelColor->color().red()/255.;
414 aColor.G = SelColor->color().green()/255.;
415 aColor.B = SelColor->color().blue()/255.;
416 myPrsCopy->SetColor(aColor);
419 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
420 switch (myDirCombo->currentIndex()) {
422 aDirection = VISU::StreamLines::FORWARD;
425 aDirection = VISU::StreamLines::BACKWARD;
428 aDirection = VISU::StreamLines::BOTH;
431 VISU::Prs3d_var aPrs;
432 int aSrcSelection = myUseSrcCombo->currentIndex();
433 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentIndex() : -1;
434 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
435 VISU::VISUType aType;
437 switch (aSrcSelection) {
439 aPrs = myEntityList[aSrcItem];
440 aType = VISU::TENTITY;
441 aName = myEntitiesLst[aSrcItem];
444 aPrs = myFamilyList[aSrcItem];
445 aType = VISU::TFAMILY;
446 aName = myFamilisLst[aSrcItem];
449 aPrs = myGroupList[aSrcItem];
450 aType = VISU::TGROUP;
451 aName = myGroupsLst[aSrcItem];
453 case 4: // Presentation
454 aPrs = myPrsList[aSrcItem];
457 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
458 aPrs = createMesh(aType, aName);
461 anIsOk &= myPrsCopy->SetParams(myIntegStepLen->value(),
465 myPntPercent->value(),
469 VISU::TSameAsFactory<VISU::TSTREAMLINES>().Copy(myPrsCopy, thePrs);
477 void VisuGUI_StreamLinesDlg::setColor( QColor color )
480 QPalette aPal = SelColor->palette();
481 aPal.setColor( SelColor->backgroundRole(), myColor );
482 SelColor->setPalette( aPal );*/
483 SelColor->setColor( color );
488 Called when "Select Color" buttonx clicked
490 /*void VisuGUI_StreamLinesDlg::setVColor()
492 QColor cnew = QColorDialog::getColor( myColor, this );
493 if ( cnew.isValid() )
499 Enbled/disables magnitude coloring
501 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
503 myUseScalar->setEnabled( enable );
508 Called when "Magnitude Coloring" check box clicked
510 void VisuGUI_StreamLinesDlg::enableSetColor()
512 SelColor->setEnabled(!myUseScalar->isChecked() );
515 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
518 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
521 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
522 myStepLen->setMaximum(theValue);
525 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
528 mySrcCombo->setEnabled(false);
531 mySrcCombo->setEnabled(true);
535 mySrcCombo->addItems(myEntitiesLst);
538 mySrcCombo->addItems(myFamilisLst);
541 mySrcCombo->addItems(myGroupsLst);
543 case 4: // Presentation
544 mySrcCombo->addItems(myPrsLst);
550 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
552 return VISU::Mesh::_nil();
555 void VisuGUI_StreamLinesDlg::accept()
557 VisuGUI_ScalarBarBaseDlg::accept();
560 void VisuGUI_StreamLinesDlg::reject()
562 VisuGUI_ScalarBarBaseDlg::reject();
565 QString VisuGUI_StreamLinesDlg::GetContextHelpFilePath()
567 return "stream_lines_page.html";