1 // Copyright (C) 2007-2008 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
22 // File : VisuGUI_StreamLinesDlg.cxx
23 // Author : Vitaly SMETANNIKOV
26 #include "VisuGUI_StreamLinesDlg.h"
29 #include "VisuGUI_Tools.h"
30 #include "VisuGUI_InputPane.h"
32 #include "VISU_Mesh_i.hh"
33 #include "VISU_Gen_i.hh"
34 #include "VISU_StreamLines_i.hh"
35 #include "VISU_ColoredPrs3dFactory.hh"
36 #include "VISU_StreamLinesPL.hxx"
37 #include "VISU_Actor.h"
39 #include "SalomeApp_Application.h"
40 #include "LightApp_Application.h"
41 #include "LightApp_SelectionMgr.h"
43 #include "SVTK_ViewWindow.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_ResourceMgr.h"
48 #include "SUIT_MessageBox.h"
50 #include "SALOME_ListIO.hxx"
52 #include <SALOMEDSClient_SObject.hxx>
54 #include <QtxDoubleSpinBox.h>
55 #include <QtxColorButton.h>
64 #include <QColorDialog>
66 #include <QPushButton>
68 #include <QStringList>
75 VisuGUI_StreamLinesDlg::VisuGUI_StreamLinesDlg (SalomeApp_Module* theModule)
76 : 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 QtxDoubleSpinBox( aSourceBox );
222 VISU::initSpinBox(myPntPercent, 0, 1);
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 QtxDoubleSpinBox( aTopBox );
230 VISU::initSpinBox(myStepLen, DBL_MIN, DBL_MAX);
231 myStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
232 TopLayout->addWidget(myStepLen, 1, 1);
233 connect(myStepLen, SIGNAL(valueChanged(double)), this, SLOT(StepLengthChanged(double)));
235 QLabel* aIntegStepLenLbl = new QLabel (tr("LBL_INTEGRATION_STEP"), aTopBox);
236 TopLayout->addWidget(aIntegStepLenLbl, 2, 0);
237 myIntegStepLen = new QtxDoubleSpinBox( aTopBox );
238 VISU::initSpinBox(myIntegStepLen, DBL_MIN, DBL_MAX);
239 myIntegStepLen->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
240 TopLayout->addWidget(myIntegStepLen, 2, 1);
241 connect(myIntegStepLen, SIGNAL(valueChanged(double)), this, SLOT(IntegrationStepChanged(double)));
243 QLabel* aPropagationLbl = new QLabel (tr("LBL_PROPAGATION_TIME"), aTopBox);
244 TopLayout->addWidget(aPropagationLbl, 3, 0);
245 myPropTime = new QtxDoubleSpinBox( aTopBox );
246 VISU::initSpinBox(myPropTime, DBL_MIN, DBL_MAX);
247 myPropTime->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
248 TopLayout->addWidget(myPropTime, 3, 1);
249 connect(myPropTime, SIGNAL(valueChanged(double)), this, SLOT(PropagationTimeChanged(double)));
251 QLabel* aDirLbl = new QLabel (tr("LBL_DIRECTION"),aTopBox);
252 TopLayout->addWidget(aDirLbl, 4, 0);
253 myDirCombo = new QComboBox(aTopBox);
254 myDirCombo->addItem("Forward");
255 myDirCombo->addItem("Backward");
256 myDirCombo->addItem("Both");
257 TopLayout->addWidget(myDirCombo, 4, 1);
259 myUseScalar = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), aTopBox);
260 connect( myUseScalar, SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
261 TopLayout->addWidget(myUseScalar, 5, 0);
263 SelColor = new QtxColorButton( aTopBox );
264 SelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
265 //connect( SelColor, SIGNAL( clicked() ), this, SLOT( setVColor() ) );
266 TopLayout->addWidget( SelColor, 5, 1);
268 myTabBox->addTab(aTopBox, "Stream Lines");
269 myInputPane = new VisuGUI_InputPane(VISU::TSTREAMLINES, theModule, this);
270 myTabBox->addTab(GetScalarPane(), "Scalar Bar");
271 myTabBox->addTab(myInputPane, "Input");
273 aBoxLayout->addWidget(myTabBox);
275 QGroupBox* aGroupButtons = new QGroupBox( this );
276 //aGroupButtons->setColumnLayout(0, Qt::Vertical );
277 //aGroupButtons->layout()->setSpacing( 0 );
278 //aGroupButtons->layout()->setMargin( 0 );
280 QGridLayout* aGroupButtonsLayout = new QGridLayout( aGroupButtons );
281 aGroupButtonsLayout->setAlignment( Qt::AlignTop );
282 aGroupButtonsLayout->setSpacing( 6 );
283 aGroupButtonsLayout->setMargin( 11 );
285 QPushButton* aOkBtn = new QPushButton( tr( "BUT_OK" ), aGroupButtons );
286 aOkBtn->setAutoDefault( TRUE );
287 aOkBtn->setDefault( TRUE );
288 aGroupButtonsLayout->addWidget( aOkBtn, 0, 0 );
289 aGroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
291 QPushButton* aCancelBtn = new QPushButton( tr( "BUT_CANCEL" ) , aGroupButtons );
292 aCancelBtn->setAutoDefault( TRUE );
293 aGroupButtonsLayout->addWidget( aCancelBtn, 0, 2 );
295 QPushButton* aHelpBtn = new QPushButton( tr( "BUT_HELP" ) , aGroupButtons );
296 aHelpBtn->setAutoDefault( TRUE );
297 aGroupButtonsLayout->addWidget( aHelpBtn, 0, 3 );
299 connect( aOkBtn, SIGNAL( clicked() ), this, SLOT( accept() ) );
300 connect( aCancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
301 connect( aHelpBtn, SIGNAL( clicked() ), this, SLOT( onHelp() ) );
303 aBoxLayout->addWidget(aGroupButtons);
308 VisuGUI_StreamLinesDlg::~VisuGUI_StreamLinesDlg()
311 void VisuGUI_StreamLinesDlg::initFromPrsObject ( VISU::ColoredPrs3d_i* thePrs,
315 myPrsCopy = VISU::TSameAsFactory<VISU::TSTREAMLINES>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
317 VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
319 static int aNbOfSteps = 30;
320 VISU_StreamLinesPL* aStreamLinesPL = myPrsCopy->GetSpecificPL();
322 aMin = aStreamLinesPL->GetMinPropagationTime();
323 aMax = aStreamLinesPL->GetMaxPropagationTime();
324 myPropTime->setRange(aMin,aMax);
325 myPropTime->setValue(aStreamLinesPL->GetPropagationTime());
326 myPropTime->setSingleStep((aMax-aMin)/aNbOfSteps);
328 aMin = aStreamLinesPL->GetMinStepLength();
329 aMax = aStreamLinesPL->GetMaxStepLength();
330 myStepLen->setRange(aMin,aMax);
331 myStepLen->setValue(aStreamLinesPL->GetStepLength());
332 myStepLen->setSingleStep((aMax-aMin)/aNbOfSteps);
334 aMin = aStreamLinesPL->GetMinIntegrationStep();
335 aMax = aStreamLinesPL->GetMaxIntegrationStep();
336 myIntegStepLen->setRange(aMin,aMax);
337 myIntegStepLen->setValue(aStreamLinesPL->GetIntegrationStep());
338 myIntegStepLen->setSingleStep((aMax-aMin)/aNbOfSteps);
340 switch (myPrsCopy->GetDirection()) {
341 case VISU::StreamLines::FORWARD:
342 myDirCombo->setCurrentIndex(0);
344 case VISU::StreamLines::BACKWARD:
345 myDirCombo->setCurrentIndex(1);
347 case VISU::StreamLines::BOTH:
348 myDirCombo->setCurrentIndex(2);
350 myUseScalar->setChecked(myPrsCopy->IsColored());
351 myPntPercent->setValue(myPrsCopy->GetUsedPoints());
353 mySrcCombo->setEnabled(false);
354 QString aSrcEntry = myPrsCopy->GetSourceEntry();
356 SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
357 QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
361 #define INITPRS(PRSLIST, PRSNUM) \
362 for (int i = 0; i < PRSLIST.count(); i++) { \
363 VISU::Prs3d_i* aPrs = dynamic_cast<VISU::Prs3d_i*>(VISU::GetServant(PRSLIST[i]).in()); \
364 if (aPrs == NULL) continue; \
365 if (aSrcEntry == aPrs->GetEntry().c_str()) { \
366 onSourceTypeChange(PRSNUM); \
367 myUseSrcCombo->setCurrentIndex(PRSNUM); \
368 mySrcCombo->setEnabled(true); \
369 mySrcCombo->setCurrentIndex(i); \
374 if (!aSrcEntry.isEmpty()) {
375 INITPRS(myEntityList, 1);
376 INITPRS(myFamilyList, 2);
377 INITPRS(myGroupList, 3);
378 INITPRS(myPrsList, 4);
385 myInputPane->initFromPrsObject( myPrsCopy );
386 myTabBox->setCurrentIndex( 0 );
390 int VisuGUI_StreamLinesDlg::storeToPrsObject (VISU::ColoredPrs3d_i* thePrs)
392 if(!myInputPane->check() || !GetScalarPane()->check())
395 int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
396 anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
399 myPrsCopy->ShowColored(myUseScalar->isChecked());
400 if (!myPrsCopy->IsColored()) {
401 SALOMEDS::Color aColor;
402 aColor.R = SelColor->color().red()/255.;
403 aColor.G = SelColor->color().green()/255.;
404 aColor.B = SelColor->color().blue()/255.;
405 myPrsCopy->SetColor(aColor);
408 VISU::StreamLines::Direction aDirection = VISU::StreamLines::BOTH;
409 switch (myDirCombo->currentIndex()) {
411 aDirection = VISU::StreamLines::FORWARD;
414 aDirection = VISU::StreamLines::BACKWARD;
417 aDirection = VISU::StreamLines::BOTH;
420 VISU::Prs3d_var aPrs;
421 int aSrcSelection = myUseSrcCombo->currentIndex();
422 int aSrcItem = (mySrcCombo->count() > 0)? mySrcCombo->currentIndex() : -1;
423 if ((aSrcSelection > 0) && (aSrcItem > -1)) {
424 VISU::VISUType aType;
426 switch (aSrcSelection) {
428 aPrs = myEntityList[aSrcItem];
429 aType = VISU::TENTITY;
430 aName = myEntitiesLst[aSrcItem];
433 aPrs = myFamilyList[aSrcItem];
434 aType = VISU::TFAMILY;
435 aName = myFamilisLst[aSrcItem];
438 aPrs = myGroupList[aSrcItem];
439 aType = VISU::TGROUP;
440 aName = myGroupsLst[aSrcItem];
442 case 4: // Presentation
443 aPrs = myPrsList[aSrcItem];
446 if (CORBA::is_nil(aPrs) && aSrcSelection != 4) {
447 aPrs = createMesh(aType, aName);
450 anIsOk &= myPrsCopy->SetParams(myIntegStepLen->value(),
454 myPntPercent->value(),
458 VISU::TSameAsFactory<VISU::TSTREAMLINES>().Copy(myPrsCopy, thePrs);
466 void VisuGUI_StreamLinesDlg::setColor( QColor color )
469 QPalette aPal = SelColor->palette();
470 aPal.setColor( SelColor->backgroundRole(), myColor );
471 SelColor->setPalette( aPal );*/
472 SelColor->setColor( color );
477 Called when "Select Color" buttonx clicked
479 /*void VisuGUI_StreamLinesDlg::setVColor()
481 QColor cnew = QColorDialog::getColor( myColor, this );
482 if ( cnew.isValid() )
488 Enbled/disables magnitude coloring
490 void VisuGUI_StreamLinesDlg::enableMagnColor( bool enable )
492 myUseScalar->setEnabled( enable );
497 Called when "Magnitude Coloring" check box clicked
499 void VisuGUI_StreamLinesDlg::enableSetColor()
501 SelColor->setEnabled(!myUseScalar->isChecked() );
504 void VisuGUI_StreamLinesDlg::StepLengthChanged(double theValue){
507 void VisuGUI_StreamLinesDlg::IntegrationStepChanged(double theValue) {
510 void VisuGUI_StreamLinesDlg::PropagationTimeChanged(double theValue) {
511 myStepLen->setMaximum(theValue);
514 void VisuGUI_StreamLinesDlg::onSourceTypeChange(int theIndex) {
517 mySrcCombo->setEnabled(false);
520 mySrcCombo->setEnabled(true);
524 mySrcCombo->addItems(myEntitiesLst);
527 mySrcCombo->addItems(myFamilisLst);
530 mySrcCombo->addItems(myGroupsLst);
532 case 4: // Presentation
533 mySrcCombo->addItems(myPrsLst);
539 VISU::Mesh_ptr VisuGUI_StreamLinesDlg::createMesh (VISU::VISUType theType, QString theName)
541 return VISU::Mesh::_nil();
544 void VisuGUI_StreamLinesDlg::accept()
546 VisuGUI_ScalarBarBaseDlg::accept();
549 void VisuGUI_StreamLinesDlg::reject()
551 VisuGUI_ScalarBarBaseDlg::reject();
554 QString VisuGUI_StreamLinesDlg::GetContextHelpFilePath()
556 return "stream_lines_page.html";