Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / OperationGUI / OperationGUI_ArchimedeDlg.cxx
index 7e272e91db9d02ee50b0ab36c24e3acf99dd9894..26a867ae2eb011f96f2859f52d3bab4b9757af4c 100644 (file)
 //  Module : GEOM
 //  $Header$
 
-using namespace std;
 #include "OperationGUI_ArchimedeDlg.h"
+#include "DlgRef_1Sel3Spin.h"
 
 #include "QAD_Config.h"
+#include "QAD_Desktop.h"
 
 //=================================================================================
 // class    : OperationGUI_ArchimedeDlg()
@@ -38,9 +39,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( QWidget* parent, SALOME_Selection* Sel )
+: GEOMBase_Skeleton( parent, "ArchimedeDlg", Sel, false,
+    WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
 {
+  mySelection = Sel;
+
   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_ARCHIMEDE")));
   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
   
@@ -59,13 +63,13 @@ 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);
   /***************************************************************/
 
   /* Initialisations */
-  myOperationGUI = theOperationGUI;
-  Init();
+  Init( mySelection );
 }
 
 
@@ -83,54 +87,49 @@ OperationGUI_ArchimedeDlg::~OperationGUI_ArchimedeDlg()
 // function : Init()
 // purpose  :
 //=================================================================================
-void OperationGUI_ArchimedeDlg::Init()
+void OperationGUI_ArchimedeDlg::Init( SALOME_Selection* Sel )
 {
+  mySelection = Sel;
+
   /* 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 */
+  QString St = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
+  myStep = !St.isEmpty() ? St.toDouble() : 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);
+  /* min, max, myStep and decimals for spin boxes & initial values */
+  GroupPoints->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, myStep, 3);
   GroupPoints->SpinBox_DY->RangeStepAndValidator(0.001, 999.999, SpecificStep1, 3);
   GroupPoints->SpinBox_DZ->RangeStepAndValidator(0.001, 999.999, SpecificStep2, 3);
 
-  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())) ;
 
+  initName( tr( "GEOM_ARCHIMEDE" ) );
+
+  globalSelection( GEOM_ALLSHAPES );
+
+  SelectionIntoArgument();
+  
   /* displays Dialog */
   GroupPoints->show();
   this->show();
-
-  return;
 }
 
 
@@ -140,9 +139,8 @@ void OperationGUI_ArchimedeDlg::Init()
 //=================================================================================
 void OperationGUI_ArchimedeDlg::ClickOnOk()
 {
-  this->ClickOnApply();
-  ClickOnCancel();
-  return;
+  if ( ClickOnApply() )
+    ClickOnCancel();
 }
 
 
@@ -150,13 +148,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 +164,22 @@ void OperationGUI_ArchimedeDlg::ClickOnApply()
 //=================================================================================
 void OperationGUI_ArchimedeDlg::SelectionIntoArgument()
 {
-  myEditCurrentArgument->setText("");
-  QString aString = ""; /* name of selection */
+  myEditCurrentArgument->setText( "" );
+  myShape = GEOM::GEOM_Object::_nil();
+  
+  if ( mySelection->IObjectCount() != 1 )
+    return;
 
-  int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
-  if (nbSel != 1) {
-    myOkIO = false;
+  Standard_Boolean testResult = Standard_False;
+  myShape = GEOMBase::ConvertIOinGEOMObject( mySelection->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 +199,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,6 +206,7 @@ void OperationGUI_ArchimedeDlg::SetEditCurrentArgument()
 void OperationGUI_ArchimedeDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
+  globalSelection( GEOM_ALLSHAPES );
   connect(mySelection, 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;
 }