-using namespace std;
-// File : VisuGUI_CutPlanesDlg.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_CutPlanesDlg.cxx
+// Author : Laurent CORNABE & Hubert ROLLAND
+// Module : VISU
// $Header$
#include "VisuGUI_CutPlanesDlg.h"
-#include <qlayout.h>
+#include "VISU_CutPlanes_i.hh"
+
#include "QAD_Application.h"
#include "QAD_Desktop.h"
+#include <qlayout.h>
+#include <qcheckbox.h>
+#include <qstyle.h>
+#include <qstring.h>
+#include <qvalidator.h>
+#include <qlineedit.h>
+
+using namespace std;
+
/*!
Constructor
*/
QGridLayout* TopLayout = new QGridLayout( this );
TopLayout->setSpacing( 6 );
TopLayout->setMargin( 11 );
- /*
- QGridLayout* CommentLayout = new QGridLayout;
- CommentLayout->setMargin( 0 );
- CommentLayout->setSpacing( 6 );
-
- QLabel* Comment1 = new QLabel( tr( "Enter plane position between" ), this, "Comment1" );
- Comment1->setText( tr( "Enter plane position between" ) );
- Comment1->setAlignment( AlignCenter );
-
- Comment2_1 = new QLabel( tr( "v1" ), this, "Comment2_1" );
- Comment2_1->setMinimumSize( QSize( 70, 0 ) );
- Comment2_1->setAlignment( AlignCenter);
-
- QLabel* Comment2 = new QLabel( tr( " and " ), this, "Comment2" );
- Comment2->setAlignment( AlignCenter );
-
- Comment2_2 = new QLabel( tr( "v2" ), this, "Comment2_2" );
- Comment2_2->setMinimumSize( QSize( 70, 0 ) );
- Comment2_2->setAlignment( AlignCenter );
-
- QLabel* Comment3 = new QLabel( tr( "or in fraction between" ), this, "Comment3" );
- Comment3->setAlignment( AlignCenter );
-
- QLabel* Commento4 = new QLabel( tr( " and " ), this, "Comment4" );
- Comment4->setAlignment( AlignCenter );
-
- QLabel* Comment4_1 = new QLabel( tr( "0" ), this, "Comment4_1" );
- Comment4_1->setMinimumSize( QSize( 70, 0 ) );
- Comment4_1->setAlignment( AlignCenter );
-
- QLabel* Comment4_2 = new QLabel( tr( "100" ), this, "Comment4_2" );
- Comment4_2->setMinimumSize( QSize( 70, 0 ) );
- Comment4_2->setAlignment( AlignCenter );
- QFont font = Comment3->font(); font.setBold( true );
- Comment2_1->setFont( font );
- Comment2_2->setFont( font );
- Comment4_1->setFont( font );
- Comment4_2->setFont( font );
-
- CommentLayout->addMultiCellWidget( Comment1, 0, 0, 0, 2 );
- CommentLayout->addWidget( Comment2_1, 1, 0 );
- CommentLayout->addWidget( Comment2, 1, 1 );
- CommentLayout->addWidget( Comment2_2, 1, 2 );
- CommentLayout->addMultiCellWidget( Comment3, 2, 2, 0, 2 );
- CommentLayout->addWidget( Comment4_1, 3, 0 );
- CommentLayout->addWidget( Comment4, 3, 1 );
- CommentLayout->addWidget( Comment4_2, 3, 2 );
- CommentLayout->setColStretch( 0 , 5 );
- CommentLayout->setColStretch( 2 , 5 );
- */
+
QButtonGroup* SelPlane = new QButtonGroup( tr( "Orientation" ), this, "SelPlane" );
SelPlane->setTitle( tr( "Orientation" ) );
SelPlane->setColumnLayout(0, Qt::Vertical );
nbPlan = new QSpinBox( 1, 100, 1, this, "nbPlan" );
nbPlan->setValue( 1 );
nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
- /*
- GBplan1 = new QGroupBox( tr( "First plane" ), this, "GBplan1" );
- GBplan1->setColumnLayout(0, Qt::Vertical );
- GBplan1->layout()->setSpacing( 0 );
- GBplan1->layout()->setMargin( 0 );
- QGridLayout* GBplan1Layout = new QGridLayout( GBplan1->layout() );
- GBplan1Layout->setAlignment( Qt::AlignTop );
- GBplan1Layout->setSpacing( 6 );
- GBplan1Layout->setMargin( 11 );
-
- QLabel* LabelPos = new QLabel( tr( "Plane position (value):" ), GBplan1, "LabelPos" );
- GBplan1Layout->addWidget( LabelPos, 0, 0 );
-
- PosPlan1 = new QAD_SpinBoxDbl( GBplan1, -999.999, 999.999, 0.1 );
- PosPlan1->setValue( 0 );
- PosPlan1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
- GBplan1Layout->addWidget( PosPlan1, 0, 1 );
-
- QLabel* LabelPosi = new QLabel( tr( "Plane position (fraction):" ), GBplan1, "LabelPosi" );
- GBplan1Layout->addWidget( LabelPosi, 1, 0 );
-
- PosFrac1 = new QAD_SpinBoxDbl( GBplan1, 0, 100, 0.1 );
- PosFrac1->setValue( 0 );
- PosFrac1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
- GBplan1Layout->addWidget( PosFrac1, 1, 1 );
-
- GBplan2 = new QGroupBox( tr( "Second plane" ), this, "GBplan2" );
- GBplan2->setColumnLayout(0, Qt::Vertical );
- GBplan2->layout()->setSpacing( 0 );
- GBplan2->layout()->setMargin( 0 );
- QGridLayout* GBplan2Layout = new QGridLayout( GBplan2->layout() );
- GBplan2Layout->setAlignment( Qt::AlignTop );
- GBplan2Layout->setSpacing( 6 );
- GBplan2Layout->setMargin( 11 );
-
- QLabel* LabelPos_5 = new QLabel( tr( "Plane position (value):" ), GBplan2, "LabelPos_5" );
- GBplan2Layout->addWidget( LabelPos_5, 0, 0);
-
- PosPlan2 = new QAD_SpinBoxDbl( GBplan2, -999.999, 999.999, 0.1 );
- PosPlan2->setValue( 0 );
- PosPlan2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
- GBplan2Layout->addWidget( PosPlan2, 0, 1 );
-
- QLabel* LabelPosi_6 = new QLabel( tr( "Plane position (fraction):" ), GBplan2, "LabelPosi_6" );
- GBplan2Layout->addWidget( LabelPosi_6, 1, 0);
+
+ myPosTable = new QTable(this, "Positions of planes" );
+ myPosTable->setMaximumHeight( 227 );
+ myPosTable->setMinimumWidth( 294 );
+ //myPosTable->setGeometry( QRect( 11, 98, 289, 325 ) );
+ myPosTable->setNumCols(2);
+ myPosTable->setNumRows(0);
- PosFrac2 = new QAD_SpinBoxDbl( GBplan2, 0, 100, 0.1 );
- PosFrac2->setValue( 100 );
- PosFrac2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
- GBplan2Layout->addWidget( PosFrac2, 1, 1 );
- */
+ QHeader *th = myPosTable->horizontalHeader();
+ th->setLabel( 0, "Position" );
+ th->setLabel( 1, "Set default" );
+
QGroupBox* GBrot = new QGroupBox( tr( "Rotations" ), this, "GBrot" );
GBrot->setColumnLayout(0, Qt::Vertical );
GBrot->layout()->setSpacing( 0 );
buttonCancel->setAutoDefault( TRUE );
GroupButtonsLayout->addWidget( buttonCancel, 0, 2 );
+ QLabel* aPosLbl = new QLabel(tr( "LBL_POS" ), this);
+ myPosSpn = new QAD_SpinBoxDbl( this, 0, 1, 0.1 );
+
+ th->setStyle("QStyle::CE_PushButton");
+
// layouting
TopLayout->addMultiCellWidget( SelPlane, 0, 0, 0, 1 );
- // TopLayout->addLayout( CommentLayout, 0, 1 );
- TopLayout->addWidget( LabelPosi_3, 1, 0 );
- TopLayout->addWidget( nbPlan, 1, 1 );
- //TopLayout->addMultiCellWidget( GBplan1, 2, 2, 0, 1 );
- //TopLayout->addMultiCellWidget( GBplan2, 3, 3, 0, 1 );
- TopLayout->addMultiCellWidget( GBrot, 2, 2, 0, 1 );
- TopLayout->addMultiCellWidget( GroupButtons, 3, 3, 0, 1 );
+ TopLayout->addMultiCellWidget( GBrot, 1, 1, 0, 1 );
+ TopLayout->addWidget( LabelPosi_3, 2, 0 );
+ TopLayout->addWidget( nbPlan, 2, 1 );
+ TopLayout->addMultiCellWidget( myPosTable, 3, 3, 0, 1 );
+ TopLayout->setRowStretch ( 3, 3 );
+ TopLayout->addWidget(aPosLbl, 4, 0 );
+ TopLayout->addWidget(myPosSpn, 4, 1 );
+ TopLayout->addMultiCellWidget( GroupButtons, 5, 5, 0, 1 );
// signals and slots connections
- connect( SelPlane, SIGNAL( clicked( int ) ), this, SLOT( orientationChanged( int ) ) );
- //connect( PosPlan1, SIGNAL( valueChanged( double ) ), this, SLOT( posChanged( double ) ) );
- //connect( PosPlan2, SIGNAL( valueChanged( double ) ), this, SLOT( posChanged( double ) ) );
- //connect( PosFrac1, SIGNAL( valueChanged( double ) ), this, SLOT( fracChanged( double ) ) );
- //connect( PosFrac2, SIGNAL( valueChanged( double ) ), this, SLOT( fracChanged( double ) ) );
- //connect( nbPlan, SIGNAL( valueChanged( int ) ), this, SLOT( nbPlanChanged( int ) ) );
-
+ connect( SelPlane, SIGNAL( clicked( int )), this, SLOT( orientationChanged( int ) ) );
+ connect( nbPlan, SIGNAL( valueChanged( int )), this, SLOT( DrawTable( ) ) );
+ connect( myPosSpn, SIGNAL( valueChanged( double )), this, SLOT( DrawTable( ) ) );
+ connect( RBzx, SIGNAL( toggled(bool)), this, SLOT( DrawTable( ) ) );
+ connect( RByz, SIGNAL( toggled(bool)), this, SLOT( DrawTable( ) ) );
+ connect( RBxy, SIGNAL( toggled(bool)), this, SLOT( DrawTable( ) ) );
+ connect( th, SIGNAL( clicked(int)), this, SLOT( setDefault(int) ) );
+
connect( buttonOk, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
+ myCutPlanes = NULL;
+
// default values
+ hasInit = false;
X1 = 0; X2 = 0;
Y1 = 0; Y2 = 0;
Z1 = 0; Z2 = 0;
- //nbPold = 0;
- RBxy->setChecked( true );
+ RByz->setChecked( true );
orientationChanged( 0 );
- //nbPlanChanged( 1 );
}
/*!
*/
VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
{
+ if(myCutPlanes) delete myCutPlanes;
}
setNbPlanes(thePrs->GetNbPlanes());
setRotation(thePrs->GetRotateX()*180./PI, thePrs->GetRotateY()*180./PI);
setPlanePos(thePrs->GetOrientationType());
+ myPosSpn->setValue(thePrs->GetDisplacement());
+ hasInit = true;
+ // init table
+ myCutPlanes = new VISU::CutPlanes_i(thePrs->GetResult(),false);
+ myCutPlanes->SameAs(thePrs);
+ DrawTable();
}
void VisuGUI_CutPlanesDlg::storeToPrsObject(VISU::CutPlanes_i* thePrs) {
thePrs->SetRotateX(getRotation1()*PI/180.);
thePrs->SetRotateY(getRotation2()*PI/180.);
thePrs->SetOrientationType(getOrientaion());
- thePrs->Update();
+ thePrs->SetDisplacement(myPosSpn->value());
+ for (int i = 0; i < getNbPlanes(); ++i)
+ {
+ if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
+ thePrs->SetPlanePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
+ else thePrs->SetDefault(i);
+ }
}
/*!
if ( RBxy->isChecked() ) {
LabelRot1->setText( tr( "Rotation around X (Y to Z):" ) );
LabelRot2->setText( tr( "Rotation around Y (Z to X):" ) );
- //Comment2_1->setText( QString::number( Z1 ) );
- //Comment2_2->setText( QString::number( Z2 ) );
- //PosPlan1->setMinValue( Z1 );
- //PosPlan1->setMaxValue( Z2 );
- //PosPlan2->setMinValue( Z1 );
- //PosPlan2->setMaxValue( Z2 );
- /*
- if( nbPlan->value() == 1 ) {
-// PosFrac1->setValue( 50 );
- PosPlan1->setValue( ( Z1 + Z2 ) / 2 );
-// PosFrac2->setValue( 50 );
- PosPlan2->setValue( ( Z1 + Z2 ) / 2 );
- }
- else {
-// PosFrac1->setValue( 0 );
- //PosPlan1->setValue( Z1 );
-// PosFrac2->setValue(100);
- PosPlan2->setValue( Z2 );
- }*/
- }
- else if ( RByz->isChecked() ) {
+ } else if ( RByz->isChecked() ) {
LabelRot1->setText( tr( "Rotation around Y (Z to X):" ) );
LabelRot2->setText( tr( "Rotation around Z (X to Y):" ) );
- //Comment2_1->setText( QString::number( X1 ) );
- //Comment2_2->setText( QString::number( X2 ) );
- //PosPlan1->setMinValue( X1 );
- //PosPlan1->setMaxValue( X2 );
- //PosPlan2->setMinValue( X1 );
- //PosPlan2->setMaxValue( X2 );
- /*
- if( nbPlan->value() == 1 ) {
-// PosFrac1->setValue( 50 );
- PosPlan1->setValue( ( X1 + X2 ) / 2 );
-// PosFrac2->setValue( 50 );
- PosPlan2->setValue( ( X1 + X2 ) / 2 );
- }
- else {
-// PosFrac1->setValue( 0 );
- PosPlan1->setValue( X1 );
-// PosFrac2->setValue( 100 );
- PosPlan2->setValue( X2 );
- }*/
- }
- else { // RBzx->isChecked()
- //Comment2_1->setText( QString::number( Y1 ) );
- //Comment2_2->setText( QString::number( Y2 ) );
- //PosPlan1->setMinValue( Y1 );
- //PosPlan1->setMaxValue( Y2 );
- //PosPlan2->setMinValue( Y1 );
- //PosPlan2->setMaxValue( Y2 );
+ } else {
LabelRot1->setText( tr( "Rotation around Z (X to Y):" ) );
LabelRot2->setText( tr( "Rotation around X (Y to Z):" ) );
- /*
- if( (nbPlan->value()) == 1 ) {
-// PosFrac1->setValue( 50 );
- PosPlan1->setValue( ( Y1 + Y2 ) / 2 );
-// PosFrac2->setValue( 50 );
- PosPlan2->setValue( ( Y1 + Y2 ) / 2 );
- }
- else {
-// PosFrac1->setValue( 0 );
- PosPlan1->setValue( Y1 );
-// PosFrac2->setValue( 100 );
- PosPlan2->setValue( Y2 );
- }*/
}
}
-/*!
- Called when nb of planes is changed
-*/
-/*void VisuGUI_CutPlanesDlg::nbPlanChanged( int nb )
-{
- int nold = ( nbPold == 0 ? 0 : ( nbPold > 1 ? 2 : 1 ) );
- int nnew = ( nb == 0 ? 0 : ( nb > 1 ? 2 : 1 ) );
-
- if( nold != nnew )
- orientationChanged( 0 );
- //GBplan1->setEnabled( nnew != 0 );
- //GBplan2->setEnabled( nnew > 1 && nnew != 0 );
- nbPold = nb;
- }*/
-/*!
- Called when position ( fraction ) is changed
-*/
-/*void VisuGUI_CutPlanesDlg::fracChanged( double value )
-{
- if ( signalsBlocked() )
- return;
- QAD_SpinBoxDbl* spin = 0;
- double V1, V2;
- if ( sender() == PosFrac1 )
- spin = PosPlan1;
- if ( sender() == PosFrac2 )
- spin = PosPlan2;
- if( RBxy->isChecked() ) {
- V1 = Z1; V2 = Z2;
- }
- else if( RByz->isChecked() ) {
- V1 = X1; V2 = X2;
- }
- else {
- V1 = Y1; V2 = Y2;
- }
- if ( spin ) {
- blockSignals( true );
- spin->setValue( V1 + ( V2 - V1 ) * value / 100 );
- blockSignals( false );
- }
- }*/
-
-/*!
- Called when position ( value ) is changed
-*/
-/*void VisuGUI_CutPlanesDlg::posChanged( double value )
-{
- if ( signalsBlocked() )
- return;
- QAD_SpinBoxDbl* spin = 0;
- double V;
- if ( sender() == PosPlan1 )
- spin = PosFrac1;
- if ( sender() == PosPlan2 )
- spin = PosFrac2;
- if( RBxy->isChecked() ) {
- if ( value <= Z1 )
- V = 0;
- else if ( value >= Z2 )
- V = 100;
- else
- V = ( value - Z1 ) / ( Z2 - Z1 ) * 100;
- }
- else if( RByz->isChecked() )
- if ( value <= X1 )
- V = 0;
- else if ( value >= X2 )
- V = 100;
- else
- V = ( value - X1 ) / ( X2 - X1 ) * 100;
- else
- if ( value <= Y1 )
- V = 0;
- else if ( value >= Y2 )
- V = 100;
- else
- V = ( value - Y1 ) / ( Y2 - Y1 ) * 100;
- if ( spin ) {
- blockSignals( true );
- spin->setValue( V );
- blockSignals( false );
- }
- }*/
/*!
Sets bounds ( must be called first )
else // zx
RBzx->setChecked( true );
orientationChanged( 0 );
- //PosPlan1->setValue( pos1 );
- //PosPlan2->setValue( pos2 );
}
-/*!
- Sets planes orientation and position ( fraction )
-*/
-/*void VisuGUI_CutPlanesDlg::setPlanePosFrac( const int orient, const double frac1, const double frac2 )
-{
- if ( orient == 1 ) // xy
- RBxy->setChecked( true );
- else if ( orient == 2) // yz
- RByz->setChecked( true );
- else // zx
- RBzx->setChecked( true );
- orientationChanged( 0 );
- PosFrac1->setValue( frac1 );
- PosFrac2->setValue( frac2 );
- }*/
/*!
Gets planes orientation
return orient;
}
-/*!
- Gets planes position 1
-*/
-/*double VisuGUI_CutPlanesDlg::getPlanePos1()
-{
- return PosPlan1->value();
- }*/
-
-/*!
- Gets planes position 2
-*/
-/*double VisuGUI_CutPlanesDlg::getPlanePos2()
-{
- return PosPlan2->value();
- }*/
/*!
Sets planes rotation
{
return Rot2->value();
}
+
+/*!
+ Draw the table of planes positions
+*/
+
+void VisuGUI_CutPlanesDlg::DrawTable()
+{
+ if (!hasInit) return;
+
+ int aNbRows = myPosTable->numRows();
+ int aNbPlanes = getNbPlanes();
+
+ if (aNbRows>0)
+ for (int i = 0; i < aNbRows; ++i)
+ {
+ if (!((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked())
+ myCutPlanes->SetPlanePosition( i, ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->text().toDouble() );
+ }
+
+ myCutPlanes->SetNbPlanes(aNbPlanes);
+ myCutPlanes->SetDisplacement(myPosSpn->value());
+ myCutPlanes->SetOrientationType(getOrientaion());
+
+ if (aNbRows < aNbPlanes)
+ {
+ if (aNbRows == 0) myPosTable->setNumRows(aNbPlanes);
+ else myPosTable->insertRows(aNbRows, aNbPlanes - aNbRows );
+
+ QHeader *vh = myPosTable->verticalHeader();
+ QString str;
+
+ QDoubleValidator *dvalidator = new QDoubleValidator(myPosTable);
+ dvalidator->setDecimals(32);
+
+ for (int i = aNbRows; i < myPosTable->numRows(); ++i)
+ {
+ QLineEdit *editline = new QLineEdit( myPosTable );
+ editline->setValidator(dvalidator);
+ myPosTable->setCellWidget( i, 0, editline );
+
+ QCheckBox *checkbox = new QCheckBox( myPosTable );
+ myPosTable->setCellWidget(i, 1, checkbox );
+ connect(checkbox , SIGNAL( clicked() ), this , SLOT( setDefault() ) );
+
+ str = str.setNum(i+1);
+ str.prepend ("Plane# ");
+ vh->setLabel( i, str );
+ }
+ }
+ else if (aNbRows > aNbPlanes)
+ for (int i = aNbRows-1; myPosTable->numRows() != aNbPlanes; --i )
+ myPosTable->removeRow(i);
+
+ for (int i = 0; i < myPosTable->numRows(); ++i)
+ {
+ ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutPlanes->GetPlanePosition(i)) );
+
+ if (myCutPlanes->IsDefault(i))
+ {
+ ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
+ ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
+ }
+ }
+}
+
+void VisuGUI_CutPlanesDlg::setDefault(int all)
+{
+ if (all == 0) return;
+
+ if (all == 1)
+ for (int i = 0; i < getNbPlanes(); ++i)
+ ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->setChecked(true);
+
+ for (int i = 0; i < getNbPlanes(); ++i)
+ {
+ if ( ((QCheckBox*)myPosTable->cellWidget( i, 1 ))->isChecked() )
+ {
+ myCutPlanes->SetDefault(i);
+ ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setText( QString::number(myCutPlanes->GetPlanePosition(i)) );
+ ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(false);
+ }
+ else ((QLineEdit*)myPosTable->cellWidget( i, 0 ))->setEnabled(true);
+ }
+}