Salome HOME
Fix of the following issues:
[modules/visu.git] / src / VISUGUI / VisuGUI_VectorsDlg.cxx
index 174ee491e463230b8b5dd58989d72e3cf18089d1..e46f4498dd4dce86124b50e23ccfb22d079e5213 100644 (file)
-//  VISU VISUGUI : GUI of VISU component
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
 //
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  VISU VISUGUI : GUI of VISU component
 //  File   : VisuGUI_VectorsDlg.cxx
 //  Author : Laurent CORNABE & Hubert ROLLAND 
 //  Module : VISU
 //  $Header$
+//
+#include "VisuGUI_VectorsDlg.h"
+
+#include "VisuGUI.h"
+#include "VisuGUI_Tools.h"
+#include "VisuGUI_InputPane.h"
+
+#include "VISU_ColoredPrs3dFactory.hh"
+#include "VISU_Vectors_i.hh"
+#include "LightApp_Application.h"
+#include "SalomeApp_Module.h"
+
+#include "SUIT_Desktop.h"
+#include "SUIT_MessageBox.h"
+#include "SUIT_ResourceMgr.h"
+#include "SUIT_Session.h"
+
+#include <QtxColorButton.h>
+
+#include <QLayout>
+#include <QColorDialog>
+#include <QTabWidget>
+#include <QButtonGroup>
+#include <QGroupBox>
+#include <QRadioButton>
+#include <QCheckBox>
+#include <QLabel>
+#include <QSpinBox>
+#include <QPushButton>
+#include <QKeyEvent>
+
+#include <limits>
 
 using namespace std;
-#include "VisuGUI_VectorsDlg.h"
-#include <qlayout.h>
-#include <qcolordialog.h>
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
 
 /*!
   Constructor
 */
-VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
-    : QDialog( QAD_Application::getDesktop(), "VisuGUI_VectorsDlg", true, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
+VisuGUI_VectorsDlg::VisuGUI_VectorsDlg (SalomeApp_Module* theModule)
+  : VisuGUI_ScalarBarBaseDlg(theModule)
 {
-  setCaption( tr( "Vector Field Representation" ) );
-  setSizeGripEnabled( TRUE );
+  setWindowTitle(tr("DLG_TITLE"));
+  setSizeGripEnabled(TRUE);
 
   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
   TopLayout->setSpacing( 6 );
   TopLayout->setMargin( 11 );
 
-  TopGroup = new QButtonGroup( this, "TopGroup" );
-  TopGroup->setColumnLayout(0, Qt::Vertical );
-  TopGroup->layout()->setSpacing( 0 );
-  TopGroup->layout()->setMargin( 0 );
-  QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
+  myTabBox = new QTabWidget(this);
+
+  QWidget* aBox = new QWidget(this);
+  QVBoxLayout* aVBLay = new QVBoxLayout( aBox );
+  aVBLay->setMargin( 11 );
+
+  TopGroup = new QGroupBox( aBox );
+  aVBLay->addWidget( TopGroup );
+  //TopGroup->setColumnLayout(0, Qt::Vertical );
+  //TopGroup->layout()->setSpacing( 0 );
+  //TopGroup->layout()->setMargin( 5 );
+  QGridLayout* TopGroupLayout = new QGridLayout( TopGroup );
   TopGroupLayout->setAlignment( Qt::AlignTop );
   TopGroupLayout->setSpacing( 6 );
   TopGroupLayout->setMargin( 11 );
 
   // Scale factor
-  ScaleLabel = new QLabel( tr( "Scale factor:" ), TopGroup, "ScaleLabel" );
+  ScaleLabel = new QLabel (tr("LBL_SCALE_FACTOR"), TopGroup );
 
-  ScalFact = new QAD_SpinBoxDbl( TopGroup, 1e-20, 1.0E+38, 0.1, 5);
+  SUIT_ResourceMgr* aResourceMgr = VISU::GetResourceMgr();
+  int aPrecision = aResourceMgr->integerValue( "VISU", "floating_point_precision", 0 );
+
+  ScalFact = new QtxDoubleSpinBox( 0, 1.0E+38, 0.1, aPrecision*(-1), 32, TopGroup );
   ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   ScalFact->setValue( 0.1 );
 
@@ -66,9 +102,13 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   TopGroupLayout->addWidget( ScalFact, 0, 1 );
 
   // Line width
-  LineWidLabel = new QLabel( tr( "Line width:" ), TopGroup, "LineWidLabel" );
+  LineWidLabel = new QLabel (tr("LBL_LINE_WIDTH"), TopGroup );
 
-  LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
+  LinWid = new QSpinBox( TopGroup );
+  LinWid->setMinimum( 1 );
+  LinWid->setMaximum( 10 );
+  LinWid->setSingleStep( 1 );
+  
   LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   LinWid->setValue( 1 );
 
@@ -76,86 +116,107 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   TopGroupLayout->addWidget( LinWid, 1, 1 );
 
   // Color
-  UseMagn = new QCheckBox( tr( "Magnitude coloring" ), TopGroup, "UseMagn" );
-  UseMagn->setText( tr( "Magnitude coloring" ) );
-  SelColor = new QPushButton( tr( "Select Color" ), TopGroup, "SelColor" );
+  UseMagn = new QCheckBox (tr("MAGNITUDE_COLORING_CHK"), TopGroup);
+  //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
+  SelColor = new QtxColorButton (TopGroup);
+  SelColor->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
+  SelColor->setText( tr("SEL_COLOR_BTN") );
 
   /*  ColorLab = new QLabel( TopGroup, "ColorLab" );
   ColorLab->setFixedSize( SelColor->sizeHint().height(), SelColor->sizeHint().height() );
   ColorLab->setFrameStyle( QLabel::Plain | QLabel::Box );
-  */  
+  */
   TopGroupLayout->addWidget( UseMagn,  2, 0 );
   //TopGroupLayout->addWidget( ColorLab, 2, 1 );
   TopGroupLayout->addWidget( SelColor, 2, 1 );
 
   // Gliphs
-  UseGlyph = new QCheckBox( tr( "Use glyphs" ), TopGroup, "UseGlyph" );
+  UseGlyph = new QCheckBox (tr("USE_GLYPHS_CHK"), TopGroup);
   
-  TypeGlyph = new QButtonGroup( tr( "Glyph type" ), TopGroup, "TypeGlyph" );
-  TypeGlyph->setColumnLayout(0, Qt::Vertical );
-  TypeGlyph->layout()->setSpacing( 0 );
-  TypeGlyph->layout()->setMargin( 0 );
-  QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGlyph->layout() );
+  TypeGlyph = new QButtonGroup ( TopGroup);
+  TypeGB = new QGroupBox( tr("GLYPH_TYPE_GRP"), TopGroup );
+  //TypeGlyph->setColumnLayout(0, Qt::Vertical );
+  //TypeGlyph->layout()->setSpacing( 0 );
+  //TypeGlyph->layout()->setMargin( 0 );
+  QGridLayout* TypeGlyphLayout = new QGridLayout( TypeGB );
   TypeGlyphLayout->setAlignment( Qt::AlignTop );
   TypeGlyphLayout->setSpacing( 6 );
   TypeGlyphLayout->setMargin( 11 );
 
-  RBArrows = new QRadioButton( tr( "Arrows" ), TypeGlyph, "RBArrows" );
+  RBArrows = new QRadioButton (tr("ARROWS_BTN"), TypeGB );
   TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
-  RBCones2 = new QRadioButton( tr( "Cones (2)" ), TypeGlyph, "RBCones2" );
+  RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGB );
   TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
-  RBCones6 = new QRadioButton( tr( "Cones (6)" ), TypeGlyph, "RBCones6" );
+  RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGB );
   TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
 
-  PosGlyph = new QButtonGroup( tr( "Glyph position" ), TopGroup, "PosGlyph" );
-  PosGlyph->setColumnLayout(0, Qt::Vertical );
-  PosGlyph->layout()->setSpacing( 0 );
-  PosGlyph->layout()->setMargin( 0 );
-  QGridLayout* PosGlyphLayout = new QGridLayout( PosGlyph->layout() );
+  TypeGlyph->addButton( RBArrows );
+  TypeGlyph->addButton( RBCones2 );
+  TypeGlyph->addButton( RBCones6 );
+
+  PosGlyph = new QButtonGroup ( TopGroup );
+  PosGB = new QGroupBox( tr("GLYPH_POSITION_GRP"), TopGroup );
+  //PosGlyph->setColumnLayout(0, Qt::Vertical );
+  //PosGlyph->layout()->setSpacing( 0 );
+  //PosGlyph->layout()->setMargin( 0 );
+  QGridLayout* PosGlyphLayout = new QGridLayout( PosGB );
   PosGlyphLayout->setAlignment( Qt::AlignTop );
   PosGlyphLayout->setSpacing( 6 );
   PosGlyphLayout->setMargin( 11 );
   
-  RBTail = new QRadioButton( tr( "Tail" ), PosGlyph, "RBTail" );
+  RBTail = new QRadioButton (tr("TAIL_BTN"  ), PosGB );
   PosGlyphLayout->addWidget( RBTail, 0, 0 );
-  RBCent = new QRadioButton( tr( "Center" ), PosGlyph, "RBCent" );
+  RBCent = new QRadioButton (tr("CENTER_BTN"), PosGB );
   PosGlyphLayout->addWidget( RBCent, 1, 0 );
-  RBHead = new QRadioButton( tr( "Head" ), PosGlyph, "RBHead" );
+  RBHead = new QRadioButton (tr("HEAD_BTN"  ), PosGB );
   PosGlyphLayout->addWidget( RBHead, 2, 0 );
 
-  TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
-  TopGroupLayout->addWidget( TypeGlyph, 4, 0 );
-  TopGroupLayout->addMultiCellWidget( PosGlyph, 4, 4, 1, 2 );
+  PosGlyph->addButton( RBTail );
+  PosGlyph->addButton( RBCent );
+  PosGlyph->addButton( RBHead );
+
+  TopGroupLayout->addWidget( UseGlyph, 3, 0, 1, 3 );
+  TopGroupLayout->addWidget( TypeGB, 4, 0 );
+  TopGroupLayout->addWidget( PosGB, 4, 1, 1, 2 );
 
   // Common buttons ===========================================================
-  GroupButtons = new QGroupBox( this, "GroupButtons" );
-  GroupButtons->setColumnLayout(0, Qt::Vertical );
-  GroupButtons->layout()->setSpacing( 0 );
-  GroupButtons->layout()->setMargin( 0 );
-  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons->layout() );
+  GroupButtons = new QGroupBox( this );
+  //GroupButtons->setColumnLayout(0, Qt::Vertical );
+  //GroupButtons->layout()->setSpacing( 0 );
+  //GroupButtons->layout()->setMargin( 0 );
+  QGridLayout* GroupButtonsLayout = new QGridLayout( GroupButtons );
   GroupButtonsLayout->setAlignment( Qt::AlignTop );
   GroupButtonsLayout->setSpacing( 6 );
   GroupButtonsLayout->setMargin( 11 );
 
-  buttonOk = new QPushButton( tr( "&OK" ), GroupButtons, "buttonOk" );
+  buttonOk = new QPushButton( tr( "BUT_OK" ), GroupButtons );
   buttonOk->setAutoDefault( TRUE );
   buttonOk->setDefault( TRUE );
   GroupButtonsLayout->addWidget( buttonOk, 0, 0 );
   GroupButtonsLayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Expanding, QSizePolicy::Minimum ), 0, 1 );
-  buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
+  buttonCancel = new QPushButton( tr( "BUT_CANCEL" ) , GroupButtons );
   buttonCancel->setAutoDefault( TRUE );
   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
+  buttonHelp = new QPushButton( tr( "BUT_HELP" ) , GroupButtons );
+  buttonHelp->setAutoDefault( TRUE );
+  GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
 
   // top layout
-  TopLayout->addWidget( TopGroup );
+  myTabBox->addTab(aBox, "Vectors");
+  myInputPane = new VisuGUI_InputPane(VISU::TVECTORS, theModule, this);
+  myTabBox->addTab(GetScalarPane(), "Scalar Bar");
+  myTabBox->addTab(myInputPane, "Input");
+
+  TopLayout->addWidget( myTabBox );
   TopLayout->addWidget( GroupButtons );
   
   // signals and slots connections
   connect( UseGlyph,     SIGNAL( clicked() ), this, SLOT( enableGlyphType() ) );
-  connect( SelColor,     SIGNAL( clicked() ), this, SLOT( setVColor() ) );
+  //connect( SelColor,     SIGNAL( clicked() ), this, SLOT( setVColor() ) );
   connect( UseMagn,      SIGNAL( clicked() ), this, SLOT( enableSetColor() ) );
   connect( buttonOk,     SIGNAL( clicked() ), this, SLOT( accept() ) );
   connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
+  connect( buttonHelp,   SIGNAL( clicked() ), this, SLOT( onHelp() ) );
   
   // default values
   UseMagn->setChecked( TRUE );
@@ -167,49 +228,69 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   enableSetColor();
 }
 
-/*!
-  Destructor
-*/
 VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
+{}
+
+void VisuGUI_VectorsDlg::initFromPrsObject( VISU::ColoredPrs3d_i* thePrs,
+                                           bool theInit )
 {
-}
+  if ( theInit )
+    myPrsCopy = VISU::TSameAsFactory<VISU::TVECTORS>().Create(thePrs, VISU::ColoredPrs3d_i::EDoNotPublish);
 
+  VisuGUI_ScalarBarBaseDlg::initFromPrsObject(myPrsCopy, theInit);
 
-void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
-  setScaleFactor(thePrs->GetScale());
-  setLineWidth((int)thePrs->GetLineWidth());
-  setUseMagnColor(thePrs->isColored());
-  SALOMEDS::Color anOldColor = thePrs->GetColor();
+  setScaleFactor(myPrsCopy->GetScale());
+  setLineWidth((int)myPrsCopy->GetLineWidth());
+  setUseMagnColor(myPrsCopy->IsColored());
+  SALOMEDS::Color anOldColor = myPrsCopy->GetColor();
   QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
   setColor(aColor);
   
-  if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
+  if (myPrsCopy->GetGlyphType() != VISU::Vectors::NONE) {
     setUseGlyphs(true);
-    setGlyphType(thePrs->GetGlyphType());
-    setGlyphPos(thePrs->GetGlyphPos());
+    setGlyphType(myPrsCopy->GetGlyphType());
+    setGlyphPos(myPrsCopy->GetGlyphPos());
   } else 
     setUseGlyphs(false);
 
   enableSetColor();
+
+  if( !theInit )
+    return;
+
+  myInputPane->initFromPrsObject( myPrsCopy );
+  myTabBox->setCurrentIndex( 0 );
 }
 
 
-void VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
-  thePrs->SetScale(getScaleFactor());
-  thePrs->SetLineWidth(getLineWidth());
-  thePrs->setColored(getUseMagnColor());
-  if(!thePrs->isColored()){
+int VisuGUI_VectorsDlg::storeToPrsObject(VISU::ColoredPrs3d_i* thePrs)
+{
+  if(!myInputPane->check() || !GetScalarPane()->check())
+    return 0;
+  
+  int anIsOk = myInputPane->storeToPrsObject( myPrsCopy );
+  anIsOk &= GetScalarPane()->storeToPrsObject( myPrsCopy );
+  
+  myPrsCopy->SetScale(getScaleFactor());
+  myPrsCopy->SetLineWidth(getLineWidth());
+  myPrsCopy->ShowColored(getUseMagnColor());
+  if(!myPrsCopy->IsColored()){
+    QColor aSelectedColor = SelColor->color();
     SALOMEDS::Color aColor;
-    aColor.R = myColor.red()/255.;
-    aColor.G = myColor.green()/255.;
-    aColor.B = myColor.blue()/255.;
-    thePrs->SetColor(aColor);
+    aColor.R = aSelectedColor.red()/255.;
+    aColor.G = aSelectedColor.green()/255.;
+    aColor.B = aSelectedColor.blue()/255.;
+    myPrsCopy->SetColor(aColor);
   }
   if (getUseGlyphs()) {
-    thePrs->SetGlyphPos(getGlyphPos());
-    thePrs->SetGlyphType(getGlyphType());
+    myPrsCopy->SetGlyphPos(getGlyphPos());
+    myPrsCopy->SetGlyphType(getGlyphType());
   } else 
-    thePrs->SetGlyphType(VISU::Vectors::NONE);
+    myPrsCopy->SetGlyphType(VISU::Vectors::NONE);
+
+  VISU::TSameAsFactory<VISU::TVECTORS>().Copy(myPrsCopy, thePrs);
+
+  return anIsOk;
 }
 
 
@@ -219,8 +300,8 @@ void VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
 */
 void VisuGUI_VectorsDlg::enableGlyphType()
 {
-  TypeGlyph->setEnabled( UseGlyph->isChecked() );
-  PosGlyph->setEnabled( UseGlyph->isChecked() );
+  TypeGB->setEnabled( UseGlyph->isChecked() );
+  PosGB->setEnabled( UseGlyph->isChecked() );
 }
 
 /*!
@@ -235,19 +316,31 @@ void VisuGUI_VectorsDlg::enableSetColor()
 /*!
   Called when "Select Color" buttonx clicked
 */
-void VisuGUI_VectorsDlg::setVColor()
+/*void VisuGUI_VectorsDlg::setVColor()
 {
   QColor cnew = QColorDialog::getColor( myColor, this );
   if ( cnew.isValid() )
     setColor( cnew );
-}
+}*/
 
 /*!
   Sets Scale factor
 */
-void VisuGUI_VectorsDlg::setScaleFactor( double sf )
+void VisuGUI_VectorsDlg::setScaleFactor(double theFactor)
 {
-  ScalFact->setValue( sf );
+  double step = 0.1;
+  if (fabs(theFactor) > std::numeric_limits<double>::epsilon()) {
+    int degree = int(log10(fabs(theFactor))) - 1;
+    if (fabs(theFactor) < 1) {
+      // as logarithm value is negative in this case
+      // and it is truncated to the bigger integer
+      degree -= 1;
+    }
+    step = pow(10., double(degree));
+  }
+
+  ScalFact->setSingleStep(step);
+  ScalFact->setValue(theFactor);
 }
 
 /*!
@@ -313,13 +406,11 @@ bool VisuGUI_VectorsDlg::getUseGlyphs()
 */
 void VisuGUI_VectorsDlg::setColor( QColor color )
 {
-  myColor = color;
-  SelColor->setPaletteBackgroundColor(myColor);
-/*  QPalette pal = ColorLab->palette();
-  QColorGroup ca = pal.active();
-  ca.setColor( QColorGroup::Background, myColor );
-  pal.setActive( ca );
-  ColorLab->setPalette( pal );*/
+  //myColor = color;
+  //QPalette aPal = SelColor->palette();
+  //aPal.setColor( SelColor->backgroundRole(), myColor );
+  //SelColor->setPalette( aPal );
+  SelColor->setColor( color );
 }
 
 /*!
@@ -387,5 +478,7 @@ void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
   enableSetColor();
 }
 
-
-
+QString VisuGUI_VectorsDlg::GetContextHelpFilePath()
+{
+  return "vectors_page.html";
+}