Salome HOME
Update for bug IPAL19949.
[modules/geom.git] / src / OperationGUI / OperationGUI_ArchimedeDlg.cxx
index 7e272e91db9d02ee50b0ab36c24e3acf99dd9894..9102c527377835877a9203f44a41d5b2616dfe60 100644 (file)
@@ -17,7 +17,7 @@
 //  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 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 //  Module : GEOM
 //  $Header$
 
-using namespace std;
 #include "OperationGUI_ArchimedeDlg.h"
+#include "DlgRef_1Sel3Spin.h"
 
-#include "QAD_Config.h"
+#include "SUIT_Desktop.h"
+#include "SUIT_Session.h"
+#include "SalomeApp_Application.h"
+#include "LightApp_SelectionMgr.h"
+
+#include <qlabel.h>
 
 //=================================================================================
 // class    : OperationGUI_ArchimedeDlg()
@@ -38,11 +43,12 @@ using namespace std;
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg(QWidget* parent,  const char* name, OperationGUI* theOperationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
-  :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
+OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
+  : GEOMBase_Skeleton(theGeometryGUI, parent, "ArchimedeDlg", false,
+                      WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
 {
-  QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ARCHIMEDE")));
-  QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
+  QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_ARCHIMEDE")));
+  QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
   
   setCaption(tr("GEOM_ARCHIMEDE_TITLE"));
 
@@ -59,12 +65,14 @@ OperationGUI_ArchimedeDlg::OperationGUI_ArchimedeDlg(QWidget* parent,  const cha
   GroupPoints->TextLabel3->setText(tr("GEOM_WATER_DENSITY"));
   GroupPoints->TextLabel4->setText(tr("GEOM_MESHING_DEFLECTION"));
   GroupPoints->PushButton1->setPixmap(image1);
+  GroupPoints->LineEdit1->setReadOnly( true );
 
-  Layout1->addWidget(GroupPoints, 1, 0);
+  Layout1->addWidget(GroupPoints, 2, 0);
   /***************************************************************/
 
+  setHelpFileName("archimede_page.html");
+
   /* Initialisations */
-  myOperationGUI = theOperationGUI;
   Init();
 }
 
@@ -88,49 +96,39 @@ void OperationGUI_ArchimedeDlg::Init()
   /* init variables */
   myEditCurrentArgument = GroupPoints->LineEdit1;
 
-  myWeight = 100.0;
-  myWaterDensity = 1.0;
-  myMeshingDeflection = 0.01;
-  myOkIO = false;
-
-  /* Get setting of step value from file configuration */
-  QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
-  step = St.toDouble();
-
+  /* Get setting of myStep value from file configuration */
+  SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
+  double myStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
 
   double SpecificStep1 = 0.1;
   double SpecificStep2 = 0.01;
-  /* min, max, step and decimals for spin boxes & initial values */
-  GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, step, 3);
-  GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep1, 3);
-  GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, 999.999, SpecificStep2, 3);
+  /* min, max, myStep and decimals for spin boxes & initial values */
+  GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, myStep, DBL_DIGITS_DISPLAY);
+  GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep1, DBL_DIGITS_DISPLAY);
+  GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, COORD_MAX, SpecificStep2, DBL_DIGITS_DISPLAY);
 
-  GroupPoints->SpinBox_DX->SetValue(myWeight);
-  GroupPoints->SpinBox_DY->SetValue(myWaterDensity);
-  GroupPoints->SpinBox_DZ->SetValue(myMeshingDeflection);
+  GroupPoints->SpinBox_DX->SetValue( 100.0 );
+  GroupPoints->SpinBox_DY->SetValue( 1.0 );
+  GroupPoints->SpinBox_DZ->SetValue( 0.01 );
 
   /* signals and slots connections */
   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
 
-  connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
 
-  connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
-  connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
-  connect(GroupPoints->SpinBox_DZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
-
   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DZ, SLOT(SetStep(double)));
   
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
-
-  /* displays Dialog */
-  GroupPoints->show();
-  this->show();
+  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+         this, SLOT(SelectionIntoArgument()));
+  
+  initName( tr( "GEOM_ARCHIMEDE" ) );
+  
+  globalSelection( GEOM_ALLSHAPES );
 
-  return;
+  SelectionIntoArgument();
 }
 
 
@@ -140,9 +138,8 @@ void OperationGUI_ArchimedeDlg::Init()
 //=================================================================================
 void OperationGUI_ArchimedeDlg::ClickOnOk()
 {
-  this->ClickOnApply();
-  ClickOnCancel();
-  return;
+  if ( ClickOnApply() )
+    ClickOnCancel();
 }
 
 
@@ -150,13 +147,13 @@ void OperationGUI_ArchimedeDlg::ClickOnOk()
 // function : ClickOnApply()
 // purpose  :
 //=================================================================================
-void OperationGUI_ArchimedeDlg::ClickOnApply()
+bool OperationGUI_ArchimedeDlg::ClickOnApply()
 {
-  buttonApply->setFocus();
-  QAD_Application::getDesktop()->putInfo(tr(""));
-  if(myOkIO)
-    myOperationGUI->Archimede(myIO, myWeight, myWaterDensity, myMeshingDeflection);
-  return;
+  if ( !onAccept() )
+    return false;
+
+  initName();
+  return true;
 }
 
 
@@ -166,20 +163,22 @@ void OperationGUI_ArchimedeDlg::ClickOnApply()
 //=================================================================================
 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
 {
-  myEditCurrentArgument->setText("");
-  QString aString = ""; /* name of selection */
+  myEditCurrentArgument->setText( "" );
+  myShape = GEOM::GEOM_Object::_nil();
+  
+  if ( IObjectCount() != 1 )
+    return;
 
-  int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
-  if (nbSel != 1) {
-    myOkIO = false;
+  Standard_Boolean testResult = Standard_False;
+  myShape = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
+
+  if ( !testResult || myShape->_is_nil() || !GEOMBase::IsShape( myShape ) )
+  {
+    myShape = GEOM::GEOM_Object::_nil();
     return;
   }
-  else {
-    myEditCurrentArgument->setText(aString);
-    myIO = mySelection->firstIObject();
-    myOkIO = true;
-  }
-  return; 
+
+  myEditCurrentArgument->setText( GEOMBase::GetName( myShape ) );
 }
 
 
@@ -199,25 +198,6 @@ void OperationGUI_ArchimedeDlg::LineEditReturnPressed()
   return;
 }
 
-
-//=================================================================================
-// function : SetEditCurrentArgument()
-// purpose  :
-//=================================================================================
-void OperationGUI_ArchimedeDlg::SetEditCurrentArgument()
-{    
-  QPushButton* send = (QPushButton*)sender();
-
-  if(send == GroupPoints->PushButton1) {
-    GroupPoints->LineEdit1->setFocus();
-    myEditCurrentArgument = GroupPoints->LineEdit1;
-    this->SelectionIntoArgument();
-  }
-
-  return;
-}
-
-
 //=================================================================================
 // function : ActivateThisDialog()
 // purpose  :
@@ -225,7 +205,9 @@ void OperationGUI_ArchimedeDlg::SetEditCurrentArgument()
 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
-  connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+  globalSelection( GEOM_ALLSHAPES );
+  connect(myGeomGUI->getApp()->selectionMgr(),
+         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
   return;
 }
 
@@ -244,19 +226,40 @@ void OperationGUI_ArchimedeDlg::enterEvent(QEvent* e)
 
 
 //=================================================================================
-// function : ValueChangedInSpinBox()
+// function : createOperation
+// purpose  :
+//=================================================================================
+GEOM::GEOM_IOperations_ptr OperationGUI_ArchimedeDlg::createOperation()
+{
+  return getGeomEngine()->GetILocalOperations( getStudyId() );
+}
+
+//=================================================================================
+// function : isValid
+// purpose  :
+//=================================================================================
+bool OperationGUI_ArchimedeDlg::isValid( QString& )
+{
+  return !myShape->_is_nil();
+}
+
+//=================================================================================
+// function : execute
 // purpose  :
 //=================================================================================
-void OperationGUI_ArchimedeDlg::ValueChangedInSpinBox(double newValue)
+bool OperationGUI_ArchimedeDlg::execute( ObjectList& objects )
 {
-  QObject* send = (QObject*)sender();
+  GEOM::GEOM_Object_var anObj;
 
-  if(send == GroupPoints->SpinBox_DX)
-    myWeight = newValue;
-  else if(send == GroupPoints->SpinBox_DY)
-    myWaterDensity = newValue;
-  else if(send == GroupPoints->SpinBox_DZ)
-    myMeshingDeflection = newValue;
+  double aWeight         = GroupPoints->SpinBox_DX->GetValue();
+  double aWaterDensity   = GroupPoints->SpinBox_DY->GetValue();
+  double aMeshDeflection = GroupPoints->SpinBox_DZ->GetValue();
+  
+  anObj = GEOM::GEOM_ILocalOperations::_narrow(
+    getOperation() )->MakeArchimede( myShape, aWeight, aWaterDensity, aMeshDeflection );
 
-  return;
+  if ( !anObj->_is_nil() )
+    objects.push_back( anObj._retn() );
+
+  return true;
 }