Salome HOME
Join modifications from branch OCC_debug_for_3_2_0b1
[modules/visu.git] / src / VISUGUI / VisuGUI_VectorsDlg.cxx
index 9771df6f050e44dd197179529d0a6f7090f30f92..e16e94bc2aa9dff6477fb6a3cca0b557db986750 100644 (file)
@@ -1,44 +1,85 @@
-using namespace std;
-//  File      : VisuGUI_VectorsDlg.cxx
-//  Created   : Wed Aug 01 10:23:06 2001
-//  Author    : Laurent CORNABE & Hubert ROLLAND 
-//  Project   : SALOME
-//  Module    : VISUGUI
-//  Copyright : PRINCIPIA
+//  VISU VISUGUI : GUI of VISU component
+//
+//  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 
+//
+//
+//
+//  File   : VisuGUI_VectorsDlg.cxx
+//  Author : Laurent CORNABE & Hubert ROLLAND 
+//  Module : VISU
 //  $Header$
 
 #include "VisuGUI_VectorsDlg.h"
+
+#include "VisuGUI.h"
+//#include "VisuGUI_Selection.h"
+#include "VisuGUI_Tools.h"
+
+#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 <qlayout.h>
 #include <qcolordialog.h>
-#include "QAD_Application.h"
-#include "QAD_Desktop.h"
+#include <qtabwidget.h>
+
+using namespace std;
 
 /*!
   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)
+    : QDialog(VISU::GetDesktop(theModule), "VisuGUI_VectorsDlg", true,
+      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
 {
-  setCaption( tr( "Vector Field Representation" ) );
-  setSizeGripEnabled( TRUE );
+  setCaption(tr("DLG_TITLE"));
+  setSizeGripEnabled(TRUE);
 
   QVBoxLayout* TopLayout = new QVBoxLayout( this ); 
   TopLayout->setSpacing( 6 );
   TopLayout->setMargin( 11 );
 
-  TopGroup = new QButtonGroup( this, "TopGroup" );
+  QTabWidget* aTabBox = new QTabWidget(this);
+
+  QVBox* aBox = new QVBox(this);
+  aBox->setMargin( 11 );
+
+  TopGroup = new QButtonGroup( aBox, "TopGroup" );
   TopGroup->setColumnLayout(0, Qt::Vertical );
   TopGroup->layout()->setSpacing( 0 );
-  TopGroup->layout()->setMargin( 0 );
+  TopGroup->layout()->setMargin( 5 );
   QGridLayout* TopGroupLayout = new QGridLayout( TopGroup->layout() );
   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, "ScaleLabel");
 
-  ScalFact = new QAD_SpinBoxDbl( TopGroup, 1e-20, 1.0E+38, 0.1, 5);
+  ScalFact = new QtxDblSpinBox( 1e-20, 1.0E+38, 0.1, TopGroup );
+  ScalFact->setPrecision( 5 );
   ScalFact->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
   ScalFact->setValue( 0.1 );
 
@@ -46,7 +87,7 @@ 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, "LineWidLabel");
 
   LinWid = new QSpinBox( 1, 10, 1, TopGroup, "LinWid" );
   LinWid->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
@@ -56,22 +97,22 @@ 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");
+  //UseMagn->setText(tr("MAGNITUDE_COLORING_CHK"));
+  SelColor = new QPushButton (tr("SEL_COLOR_BTN"), TopGroup, "SelColor");
 
   /*  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, "UseGlyph");
   
-  TypeGlyph = new QButtonGroup( tr( "Glyph type" ), TopGroup, "TypeGlyph" );
+  TypeGlyph = new QButtonGroup (tr("GLYPH_TYPE_GRP"), TopGroup, "TypeGlyph");
   TypeGlyph->setColumnLayout(0, Qt::Vertical );
   TypeGlyph->layout()->setSpacing( 0 );
   TypeGlyph->layout()->setMargin( 0 );
@@ -80,14 +121,14 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   TypeGlyphLayout->setSpacing( 6 );
   TypeGlyphLayout->setMargin( 11 );
 
-  RBArrows = new QRadioButton( tr( "Arrows" ), TypeGlyph, "RBArrows" );
+  RBArrows = new QRadioButton (tr("ARROWS_BTN") , TypeGlyph, "RBArrows");
   TypeGlyphLayout->addWidget( RBArrows, 0, 0 );
-  RBCones2 = new QRadioButton( tr( "Cones (2)" ), TypeGlyph, "RBCones2" );
+  RBCones2 = new QRadioButton (tr("CONES2_BTN"), TypeGlyph, "RBCones2");
   TypeGlyphLayout->addWidget( RBCones2, 1, 0 );
-  RBCones6 = new QRadioButton( tr( "Cones (6)" ), TypeGlyph, "RBCones6" );
+  RBCones6 = new QRadioButton (tr("CONES6_BTN"), TypeGlyph, "RBCones6");
   TypeGlyphLayout->addWidget( RBCones6, 2, 0 );
 
-  PosGlyph = new QButtonGroup( tr( "Glyph position" ), TopGroup, "PosGlyph" );
+  PosGlyph = new QButtonGroup (tr("GLYPH_POSITION_GRP"), TopGroup, "PosGlyph");
   PosGlyph->setColumnLayout(0, Qt::Vertical );
   PosGlyph->layout()->setSpacing( 0 );
   PosGlyph->layout()->setMargin( 0 );
@@ -96,11 +137,11 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   PosGlyphLayout->setSpacing( 6 );
   PosGlyphLayout->setMargin( 11 );
   
-  RBTail = new QRadioButton( tr( "Tail" ), PosGlyph, "RBTail" );
+  RBTail = new QRadioButton (tr("TAIL_BTN"  ), PosGlyph, "RBTail");
   PosGlyphLayout->addWidget( RBTail, 0, 0 );
-  RBCent = new QRadioButton( tr( "Center" ), PosGlyph, "RBCent" );
+  RBCent = new QRadioButton (tr("CENTER_BTN"), PosGlyph, "RBCent");
   PosGlyphLayout->addWidget( RBCent, 1, 0 );
-  RBHead = new QRadioButton( tr( "Head" ), PosGlyph, "RBHead" );
+  RBHead = new QRadioButton (tr("HEAD_BTN"  ), PosGlyph, "RBHead");
   PosGlyphLayout->addWidget( RBHead, 2, 0 );
 
   TopGroupLayout->addMultiCellWidget( UseGlyph, 3, 3, 0, 2 );
@@ -125,9 +166,17 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   buttonCancel = new QPushButton( tr( "&Cancel" ) , GroupButtons, "buttonCancel" );
   buttonCancel->setAutoDefault( TRUE );
   GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
+  buttonHelp = new QPushButton( tr( "&Help" ) , GroupButtons, "buttonHelp" );
+  buttonHelp->setAutoDefault( TRUE );
+  GroupButtonsLayout->addWidget( buttonHelp, 0, 3 );
 
   // top layout
-  TopLayout->addWidget( TopGroup );
+  aTabBox->addTab(aBox, "Vectors");
+  myScalarPane = new VisuGUI_ScalarBarPane(this, false);
+  myScalarPane->setMargin( 5 );
+  aTabBox->addTab(myScalarPane, "Scalar Bar");  
+
+  TopLayout->addWidget( aTabBox );
   TopLayout->addWidget( GroupButtons );
   
   // signals and slots connections
@@ -136,6 +185,7 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   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 );
@@ -147,21 +197,16 @@ VisuGUI_VectorsDlg::VisuGUI_VectorsDlg()
   enableSetColor();
 }
 
-/*!
-  Destructor
-*/
-VisuGUI_VectorsDlg::~VisuGUI_VectorsDlg()
-{
-}
 
 
 void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
+  myScalarPane->initFromPrsObject(thePrs);
   setScaleFactor(thePrs->GetScale());
-  setLineWidth(thePrs->GetLineWidth());
-  setUseMagnColor(thePrs->isColored());
-  setColor(QColor(thePrs->GetColor()[0]*255,
-                 thePrs->GetColor()[1]*255,
-                 thePrs->GetColor()[2]*255));
+  setLineWidth((int)thePrs->GetLineWidth());
+  setUseMagnColor(thePrs->IsColored());
+  SALOMEDS::Color anOldColor = thePrs->GetColor();
+  QColor aColor = QColor(int(255*anOldColor.R),int(255*anOldColor.G),int(255*anOldColor.B));
+  setColor(aColor);
   
   if (thePrs->GetGlyphType() != VISU::Vectors::NONE) {
     setUseGlyphs(true);
@@ -174,23 +219,24 @@ void VisuGUI_VectorsDlg::initFromPrsObject(VISU::Vectors_i* thePrs) {
 }
 
 
-void VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
+int VisuGUI_VectorsDlg::storeToPrsObject(VISU::Vectors_i* thePrs) {
+  myScalarPane->storeToPrsObject(thePrs);
   thePrs->SetScale(getScaleFactor());
   thePrs->SetLineWidth(getLineWidth());
-  thePrs->setColored(getUseMagnColor());
-  
-  float aColor[3];
-  aColor[0] = myColor.red()/255.;
-  aColor[1] = myColor.green()/255.;
-  aColor[2] = myColor.blue()/255.;
-
-  thePrs->SetColor(aColor);
-  
+  thePrs->ShowColored(getUseMagnColor());
+  if(!thePrs->IsColored()){
+    SALOMEDS::Color aColor;
+    aColor.R = myColor.red()/255.;
+    aColor.G = myColor.green()/255.;
+    aColor.B = myColor.blue()/255.;
+    thePrs->SetColor(aColor);
+  }
   if (getUseGlyphs()) {
     thePrs->SetGlyphPos(getGlyphPos());
     thePrs->SetGlyphType(getGlyphType());
   } else 
     thePrs->SetGlyphType(VISU::Vectors::NONE);
+  return 1;
 }
 
 
@@ -369,4 +415,32 @@ void VisuGUI_VectorsDlg::enableMagnColor( bool enable )
 }
 
 
+void VisuGUI_VectorsDlg::accept() {
+  if (myScalarPane->check()) 
+    {
+      myScalarPane->deletePreview();
+      QDialog::accept();
+    }
+}
 
+void VisuGUI_VectorsDlg::reject()
+{
+  myScalarPane->deletePreview();
+  QDialog::reject();
+}
+
+void VisuGUI_VectorsDlg::onHelp()
+{
+  QString aHelpFileName = "/files/vectors_presentation.htm";
+  LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
+  if (app) {
+    VisuGUI* aVisuGUI = dynamic_cast<VisuGUI*>( app->activeModule() );
+    app->onHelpContextModule(aVisuGUI ? app->moduleName(aVisuGUI->moduleName()) : QString(""), aHelpFileName);
+  }
+  else {
+    SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
+                          QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
+                          arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(aHelpFileName),
+                          QObject::tr("BUT_OK"));
+  }
+}