Salome HOME
sources v1.2c
[modules/visu.git] / src / VISUGUI / VisuGUI_CutPlanesDlg.cxx
index 0e87bf97cab33215f6b11438fd5810ff2c822977..5b55f9cd2c0d9381bc544a61ca8eaa39f9b27308 100644 (file)
 //  Module : VISU
 //  $Header$
 
-using namespace std;
 #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
 */
@@ -68,6 +77,17 @@ VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg()
   nbPlan->setValue( 1 );
   nbPlan->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
 
+  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);
+  
+  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 );
@@ -117,26 +137,39 @@ VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg()
   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->addWidget( LabelPosi_3,   1, 0 );
-  TopLayout->addWidget( nbPlan,        1, 1 );
-  TopLayout->addMultiCellWidget( GBrot,        2, 2, 0, 1 );
-  TopLayout->addWidget(aPosLbl, 3, 0 );
-  TopLayout->addWidget(myPosSpn, 3, 1 );
-  TopLayout->addMultiCellWidget( GroupButtons, 4, 4, 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( 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;
-  RBxy->setChecked( true );
+  RByz->setChecked( true );
   orientationChanged( 0 );
 }
 
@@ -145,6 +178,7 @@ VisuGUI_CutPlanesDlg::VisuGUI_CutPlanesDlg()
 */
 VisuGUI_CutPlanesDlg::~VisuGUI_CutPlanesDlg()
 {
+  if(myCutPlanes) delete myCutPlanes; 
 }
 
 
@@ -153,6 +187,11 @@ void VisuGUI_CutPlanesDlg::initFromPrsObject(VISU::CutPlanes_i* thePrs) {
   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) {
@@ -161,7 +200,12 @@ void VisuGUI_CutPlanesDlg::storeToPrsObject(VISU::CutPlanes_i* thePrs) {
   thePrs->SetRotateY(getRotation2()*PI/180.);
   thePrs->SetOrientationType(getOrientaion());
   thePrs->SetDisplacement(myPosSpn->value());
-  thePrs->Update();
+  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);
+    }
 }
 
 /*!
@@ -267,3 +311,87 @@ double VisuGUI_CutPlanesDlg::getRotation2()
 {
   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); 
+    }
+}