Salome HOME
EDF 2281 : missing translations, doc and pictures
[modules/geom.git] / src / TransformationGUI / TransformationGUI_ScaleDlg.cxx
index 6ad61b4ec17d49a6dbd3db6a0bf5e6429e38ba87..ff31ede297451f818e7bbaf94592461fda1f54d1 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+// Copyright (C) 2003-2007  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 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.
+// 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
+// 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 // GEOM GEOMGUI : GUI for Geometry component
 // File   : TransformationGUI_ScaleDlg.cxx
 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
@@ -129,7 +130,7 @@ TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg (GeometryGUI* theGeometry
   CheckBoxCopy->hide();
 
   // Activate Create a Copy mode
-  CreateCopyModeChanged(true);
+  CreateCopyModeChanged();
 
   // Allowed inheritance of children and visual properties by the scaling result
   mainFrame()->GroupBoxPublish->show();
@@ -155,9 +156,9 @@ void TransformationGUI_ScaleDlg::Init()
   double aFactor = 2.0;
   double SpecificStep = 0.5;
 
-  initSpinBox(SpinBox_FX, COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
-  initSpinBox(SpinBox_FY, COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
-  initSpinBox(SpinBox_FZ, COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
+  initSpinBox(SpinBox_FX, COORD_MIN, COORD_MAX, SpecificStep, "parametric_precision" );
+  initSpinBox(SpinBox_FY, COORD_MIN, COORD_MAX, SpecificStep, "parametric_precision" );
+  initSpinBox(SpinBox_FZ, COORD_MIN, COORD_MAX, SpecificStep, "parametric_precision" );
   SpinBox_FX->setValue(aFactor);
   SpinBox_FY->setValue(aFactor);
   SpinBox_FZ->setValue(aFactor);
@@ -166,7 +167,8 @@ void TransformationGUI_ScaleDlg::Init()
   LineEdit1->setText("");
   LineEdit2->setText("");
 
-  myPoint = GEOM::GEOM_Object::_nil();
+  myObjects.clear();
+  myPoint.nullify();
 
   // Signals and slots connections
   connect(buttonOk(),        SIGNAL(clicked()), this, SLOT(ClickOnOk()));
@@ -176,16 +178,14 @@ void TransformationGUI_ScaleDlg::Init()
   connect(PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
-  connect(LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-  connect(LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-
   connect(SpinBox_FX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
   connect(SpinBox_FY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
   connect(SpinBox_FZ, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
+  
+  // san : Commented so as not to override specific step settings
+  //connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
 
-  connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), this, SLOT(SetDoubleSpinBoxStep(double)));
-
-  connect(CheckBoxCopy, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
+  connect(CheckBoxCopy, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged()));
 
   initName(tr("GEOM_SCALE"));
 
@@ -200,6 +200,9 @@ void TransformationGUI_ScaleDlg::ConstructorsClicked (int constructorId)
 {
   disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
 
+  myPoint.nullify();
+  LineEdit2->clear();
+  
   switch (constructorId) {
   case 0: // translation an object by dx, dy, dz
     TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
@@ -232,7 +235,7 @@ void TransformationGUI_ScaleDlg::ConstructorsClicked (int constructorId)
     SelectionIntoArgument();
   }
   else {
-    displayPreview();
+    processPreview();
   }
 }
 
@@ -242,6 +245,7 @@ void TransformationGUI_ScaleDlg::ConstructorsClicked (int constructorId)
 //=================================================================================
 void TransformationGUI_ScaleDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if (ClickOnApply())
     ClickOnCancel();
 }
@@ -256,8 +260,11 @@ bool TransformationGUI_ScaleDlg::ClickOnApply()
     return false;
 
   initName(tr("GEOM_SCALE"));
+
   // activate selection and connect selection manager
   ConstructorsClicked(getConstructorId());
+  SelectionIntoArgument();
+
   return true;
 }
 
@@ -268,89 +275,34 @@ bool TransformationGUI_ScaleDlg::ClickOnApply()
 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
 {
   erasePreview();
-  myEditCurrentArgument->setText("");
-
-  if (myEditCurrentArgument == LineEdit1)
-    myObjects.length(0);
-  else if (myEditCurrentArgument == LineEdit2)
-    myPoint = GEOM::GEOM_Object::_nil();
 
-  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
-  SALOME_ListIO aSelList;
-  aSelMgr->selectedObjects(aSelList);
-
-  QString aName;
-
-  if (myEditCurrentArgument == LineEdit1)
-  {
-    int aNbSel = GEOMBase::GetNameOfSelectedIObjects(aSelList, aName);
-    if (aNbSel < 1)
-      return;
-
-    GEOMBase::ConvertListOfIOInListOfGO(aSelList, myObjects);
-    if (!myObjects.length())
-      return;
-    else
-      myEditCurrentArgument->setText(aName);
+  if ( myEditCurrentArgument == LineEdit1 ) {
+    myObjects = getSelected( TopAbs_SHAPE, -1 );
+    if ( !myObjects.isEmpty() ) {
+      QString aName = myObjects.count() > 1 ? QString( "%1_objects").arg( myObjects.count() ) : GEOMBase::GetName( myObjects[0].get() );
+      myEditCurrentArgument->setText( aName );
+    }
+    else {
+      myEditCurrentArgument->setText("");
+    }
   }
-  else if (myEditCurrentArgument == LineEdit2)
-  {
-    GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object::_nil();
-    if (aSelList.Extent() == 1)
-    {
-      Standard_Boolean testResult = Standard_False;
-      aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
-      if (testResult)
-      {
-        aName = GEOMBase::GetName(aSelectedObject);
-
-        TopoDS_Shape aShape;
-        if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
-        {
-          TColStd_IndexedMapOfInteger aMap;
-          aSelMgr->GetIndexes(aSelList.First(), aMap);
-          if (aMap.Extent() == 1)
-          {
-            int anIndex = aMap(1);
-            aName += QString(":vertex_%1").arg(anIndex);
-
-            //Find SubShape Object in Father
-            GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
-
-            if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
-              GEOM::GEOM_IShapesOperations_var aShapesOp =
-                getGeomEngine()->GetIShapesOperations(getStudyId());
-              aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
-            }
-            else
-              aSelectedObject = aFindedObject; // get Object from study
-          }
-          else // Global Selection
-          {
-            if (aShape.ShapeType() != TopAbs_VERTEX) {
-              aSelectedObject = GEOM::GEOM_Object::_nil();
-              aName = "";
-            }
-          }
-        }
-      }
+  else {
+    GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX );
+    TopoDS_Shape aShape;
+    if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
+      QString aName = GEOMBase::GetName( aSelectedObject.get() );
+      myEditCurrentArgument->setText( aName );
+      myPoint = aSelectedObject;
+      if ( myObjects.isEmpty() )
+       PushButton1->click();
+    }
+    else {
+      myPoint.nullify();
+      myEditCurrentArgument->setText("");
     }
-
-    myPoint = aSelectedObject;
-    myEditCurrentArgument->setText(aName);
-
-    if (!myPoint->_is_nil() && !myObjects.length())
-      PushButton1->click();
   }
 
-  // clear selection
-  /*  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
-  myGeomGUI->getApp()->selectionMgr()->clearSelected();
-  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
-  this, SLOT(SelectionIntoArgument()));*/
-  // here commented, because multiple objects can be selected IPAL 21437
-
-  displayPreview();
+  processPreview();
 }
 
 //=================================================================================
@@ -388,21 +340,7 @@ void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
   send->setDown(true);
 
   // seems we need it only to avoid preview disappearing, caused by selection mode change
-  displayPreview();
-}
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose  :
-//=================================================================================
-void TransformationGUI_ScaleDlg::LineEditReturnPressed()
-{
-  QLineEdit* send = (QLineEdit*)sender();
-  if (send == LineEdit1 || send == LineEdit2)
-  {
-    myEditCurrentArgument = send;
-    GEOMBase_Skeleton::LineEditReturnPressed();
-  }
+  processPreview();
 }
 
 //=================================================================================
@@ -413,7 +351,7 @@ void TransformationGUI_ScaleDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   ConstructorsClicked( getConstructorId() );
 }
@@ -434,7 +372,7 @@ void TransformationGUI_ScaleDlg::enterEvent (QEvent*)
 //=================================================================================
 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
 {
-  displayPreview();
+  processPreview();
 }
 
 //=================================================================================
@@ -463,20 +401,22 @@ GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
 //=================================================================================
 bool TransformationGUI_ScaleDlg::isValid (QString& msg)
 {
-  // && !myPoint->_is_nil()
-  if (getConstructorId() == 0) {
-    bool ok = SpinBox_FX->isValid( msg, !IsPreview() );
-    return myObjects.length() > 0 && fabs(SpinBox_FX->value()) > 0.00001 && ok;
+  bool ok = false;
+  if ( getConstructorId() == 0 ) {
+    ok = SpinBox_FX->isValid( msg, !IsPreview() ) &&
+         !myObjects.isEmpty() &&
+         qAbs( SpinBox_FX->value() ) > 0.00001;
   }
-
-  bool ok = true;
-  ok = SpinBox_FX->isValid( msg, !IsPreview() ) && ok;
-  ok = SpinBox_FY->isValid( msg, !IsPreview() ) && ok;
-  ok = SpinBox_FZ->isValid( msg, !IsPreview() ) && ok;
-  return myObjects.length() > 0 &&
-    fabs(SpinBox_FX->value()) > 0.00001 &&
-    fabs(SpinBox_FY->value()) > 0.00001 &&
-    fabs(SpinBox_FZ->value()) > 0.00001 && ok;
+  else {
+    ok = SpinBox_FX->isValid( msg, !IsPreview() ) &&
+         SpinBox_FY->isValid( msg, !IsPreview() ) &&
+         SpinBox_FZ->isValid( msg, !IsPreview() ) &&
+         !myObjects.isEmpty() &&
+         qAbs( SpinBox_FX->value() ) > 0.00001 &&
+         qAbs( SpinBox_FY->value() ) > 0.00001 &&
+         qAbs( SpinBox_FZ->value() ) > 0.00001;
+  }
+  return ok;
 }
 
 //=================================================================================
@@ -497,9 +437,9 @@ bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
     {
       if (toCreateCopy)
       {
-        for (int i = 0; i < myObjects.length(); i++)
+        for (int i = 0; i < myObjects.count(); i++)
         {
-          anObj = anOper->ScaleShapeCopy(myObjects[i], myPoint, SpinBox_FX->value());
+          anObj = anOper->ScaleShapeCopy(myObjects[i].get(), myPoint.get(), SpinBox_FX->value());
           if (!anObj->_is_nil()) {
             if(!IsPreview()) 
               anObj->SetParameters(SpinBox_FX->text().toLatin1().constData());
@@ -509,9 +449,9 @@ bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
       }
       else
       {
-        for (int i = 0; i < myObjects.length(); i++)
+        for (int i = 0; i < myObjects.count(); i++)
         {
-          anObj = anOper->ScaleShape(myObjects[i], myPoint, SpinBox_FX->value());
+          anObj = anOper->ScaleShape(myObjects[i].get(), myPoint.get(), SpinBox_FX->value());
           if (!anObj->_is_nil())
             objects.push_back(anObj._retn());
         }
@@ -522,10 +462,10 @@ bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
     {
       if (toCreateCopy)
       {
-        for (int i = 0; i < myObjects.length(); i++)
+        for (int i = 0; i < myObjects.count(); i++)
         {
-          anObj = anOper->ScaleShapeAlongAxesCopy(myObjects[i], myPoint, SpinBox_FX->value(),
-                                                 SpinBox_FY->value(), SpinBox_FZ->value());
+          anObj = anOper->ScaleShapeAlongAxesCopy(myObjects[i].get(), myPoint.get(), SpinBox_FX->value(),
+                                                  SpinBox_FY->value(), SpinBox_FZ->value());
           if (!anObj->_is_nil())
             if(!IsPreview()) {
               QStringList aParameters;
@@ -539,10 +479,10 @@ bool TransformationGUI_ScaleDlg::execute (ObjectList& objects)
       }
       else
       {
-        for (int i = 0; i < myObjects.length(); i++)
+        for (int i = 0; i < myObjects.count(); i++)
         {
-          anObj = anOper->ScaleShapeAlongAxes(myObjects[i], myPoint, SpinBox_FX->value(),
-                                             SpinBox_FY->value(), SpinBox_FZ->value());
+          anObj = anOper->ScaleShapeAlongAxes(myObjects[i].get(), myPoint.get(), SpinBox_FX->value(),
+                                              SpinBox_FY->value(), SpinBox_FZ->value());
           if (!anObj->_is_nil())
             objects.push_back(anObj._retn());
         }
@@ -567,7 +507,8 @@ void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStud
     // empty list of arguments means that all arguments should be restored
     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(),
                                         /*theFindMethod=*/GEOM::FSM_Transformed,
-                                        /*theInheritFirstArg=*/true);
+                                        /*theInheritFirstArg=*/true,
+                                        mainFrame()->CheckBoxAddPrefix->isChecked());
   }
 }
 
@@ -575,9 +516,9 @@ void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr   theStud
 // function :  CreateCopyModeChanged()
 // purpose  :
 //=================================================================================
-void TransformationGUI_ScaleDlg::CreateCopyModeChanged (bool isCreateCopy)
+void TransformationGUI_ScaleDlg::CreateCopyModeChanged()
 {
-  mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
+  mainFrame()->GroupBoxName->setEnabled(CheckBoxCopy->isChecked());
 }
 
 //=================================================================================
@@ -589,11 +530,6 @@ void TransformationGUI_ScaleDlg::addSubshapesToStudy()
   bool toCreateCopy = IsPreview() || CheckBoxCopy->isChecked();
   if (toCreateCopy)
   {
-    if (!myPoint->_is_nil())
-    {
-      QMap<QString, GEOM::GEOM_Object_var> objMap;
-      objMap[LineEdit2->text()] = myPoint;
-      addSubshapesToFather(objMap);
-    }
+    GEOMBase::PublishSubObject( myPoint.get() );
   }
 }