Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/geom.git] / src / TransformationGUI / TransformationGUI_RotationDlg.cxx
index c56fd9c9b935de0f116db7ae06fd9121793e570c..945ca796bd8ea15487311c5da2fe005b128baec5 100644 (file)
@@ -1,28 +1,29 @@
-//  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_RotationDlg.cxx
 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
-//
+
 #include "TransformationGUI_RotationDlg.h"
 
 #include <DlgRef.h>
@@ -98,7 +99,7 @@ TransformationGUI_RotationDlg::TransformationGUI_RotationDlg
 
   // Activate Create a Copy mode
   GroupPoints->CheckButton1->setChecked(true);
-  CreateCopyModeChanged(true);
+  CreateCopyModeChanged();
 
   Init();
 }
@@ -122,7 +123,7 @@ void TransformationGUI_RotationDlg::Init()
   double SpecificStep = 5;
 
   // min, max, step and decimals for spin boxes & initial values
-  initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, 3); // VSR: TODO: DBL_DIGITS_DISPLAY
+  initSpinBox(GroupPoints->SpinBox_DX, COORD_MIN, COORD_MAX, SpecificStep, "angle_precision" );
   GroupPoints->SpinBox_DX->setValue(anAngle);
 
   // init variables
@@ -131,7 +132,11 @@ void TransformationGUI_RotationDlg::Init()
   GroupPoints->LineEdit4->setText("");
   GroupPoints->LineEdit5->setText("");
 
-  myAxis = myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+  myObjects.clear();
+  myAxis.nullify();
+  myCentPoint.nullify();
+  myPoint1.nullify();
+  myPoint2.nullify();
 
   mainFrame()->GroupBoxPublish->show();
 
@@ -146,15 +151,12 @@ void TransformationGUI_RotationDlg::Init()
   connect(GroupPoints->PushButton4, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(GroupPoints->PushButton5, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
-  connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-  connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
-
   connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
 
   connect(GroupPoints->SpinBox_DX, SIGNAL(textChanged( const QString& )),
           this, SLOT(TextValueChangedInSpinBox( const QString&)));
 
-  connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
+  connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged()));
   connect(GroupPoints->CheckButton2, SIGNAL(toggled(bool)), this, SLOT(onReverse()));
 
   initName(tr("GEOM_ROTATION"));
@@ -178,7 +180,7 @@ void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
       GroupPoints->LineEdit2->clear();
       GroupPoints->ShowRows(4, 4, true);
 
-      myAxis = GEOM::GEOM_Object::_nil();
+      myAxis.nullify();
 
       GroupPoints->PushButton1->click();
     }
@@ -195,7 +197,9 @@ void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
       GroupPoints->LineEdit4->clear();
       GroupPoints->LineEdit5->clear();
 
-      myCentPoint = myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
+      myCentPoint.nullify();
+      myPoint1.nullify();
+      myPoint2.nullify();
 
       GroupPoints->PushButton1->click();
     }
@@ -211,7 +215,7 @@ void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
     SelectionIntoArgument();
   }
   else {
-    displayPreview();
+    processPreview();
   }
 }
 
@@ -221,6 +225,7 @@ void TransformationGUI_RotationDlg::ConstructorsClicked (int constructorId)
 //=================================================================================
 void TransformationGUI_RotationDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if (ClickOnApply())
     ClickOnCancel();
 }
@@ -235,8 +240,11 @@ bool TransformationGUI_RotationDlg::ClickOnApply()
     return false;
 
   initName();
+
   // activate selection and connect selection manager
   ConstructorsClicked(getConstructorId());
+  SelectionIntoArgument();
+
   return true;
 }
 
@@ -247,119 +255,78 @@ bool TransformationGUI_RotationDlg::ClickOnApply()
 void TransformationGUI_RotationDlg::SelectionIntoArgument()
 {
   erasePreview();
-  myEditCurrentArgument->setText("");
-
-  if (myEditCurrentArgument == GroupPoints->LineEdit1)
-    myObjects.length(0);
-  else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
-    myAxis = GEOM::GEOM_Object::_nil();
-  else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1)
-    myCentPoint = GEOM::GEOM_Object::_nil();
-  else if (myEditCurrentArgument == GroupPoints->LineEdit4)
-    myPoint1 = GEOM::GEOM_Object::_nil();
-  else if (myEditCurrentArgument == GroupPoints->LineEdit5)
-    myPoint2 = GEOM::GEOM_Object::_nil();
-
-  LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
-  SALOME_ListIO aSelList;
-  aSelMgr->selectedObjects(aSelList);
-
-  QString aName;
-
-  if (myEditCurrentArgument == GroupPoints->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 == GroupPoints->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 (aSelList.Extent() != 1)
-      return;
-
-    // nbSel == 1
-    Standard_Boolean testResult = Standard_False;
-    GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
-
-    if (!testResult || CORBA::is_nil(aSelectedObject))
-      return;
-
-    aName = GEOMBase::GetName(aSelectedObject);
-
-    // Get Selected object if selected subshape
+    TopAbs_ShapeEnum aNeedType = ( myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0 ) ?
+      TopAbs_EDGE : TopAbs_VERTEX;
+    GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
     TopoDS_Shape aShape;
-    if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
-    {
-      TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
-      if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0)
-        aNeedType = TopAbs_EDGE;
-
-      TColStd_IndexedMapOfInteger aMap;
-      aSelMgr->GetIndexes(aSelList.First(), aMap);
-      if (aMap.Extent() == 1)
-      {
-        int anIndex = aMap(1);
-        if (aNeedType == TopAbs_EDGE)
-          aName += QString(":edge_%1").arg(anIndex);
-        else
-          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
-        }
+    if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
+      QString aName = GEOMBase::GetName( aSelectedObject.get() );
+      myEditCurrentArgument->setText( aName );
+      if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
+       if ( getConstructorId() == 0 ) {
+         myAxis = aSelectedObject;
+         if ( myObjects.isEmpty() )
+           GroupPoints->PushButton1->click();
+       }
+       else if ( getConstructorId() == 1 ) {
+         myCentPoint = aSelectedObject;
+         if ( !myPoint1 )
+           GroupPoints->PushButton4->click();
+         else if ( !myPoint2 )
+           GroupPoints->PushButton5->click();
+         else if ( myObjects.isEmpty() )
+           GroupPoints->PushButton1->click();
+       }
       }
-      else // Global Selection
-      {
-        if (aShape.ShapeType() != aNeedType) {
-          aSelectedObject = GEOM::GEOM_Object::_nil();
-          aName = "";
-        }
+      else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
+       myPoint1 = aSelectedObject;
+       if ( !myPoint2 )
+         GroupPoints->PushButton5->click();
+       else if ( myObjects.isEmpty() )
+         GroupPoints->PushButton1->click();
+       else if ( !myCentPoint )
+         GroupPoints->PushButton2->click();
+      }
+      else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
+       myPoint2 = aSelectedObject;
+       if ( myObjects.isEmpty() )
+         GroupPoints->PushButton1->click();
+       else if ( !myCentPoint )
+         GroupPoints->PushButton2->click();
+       else if ( !myPoint1 )
+         GroupPoints->PushButton4->click();
       }
     }
-
-    myEditCurrentArgument->setText(aName);
-
-    if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 0) {
-      myAxis = aSelectedObject;
-      if (!myAxis->_is_nil() && !myObjects.length())
-        GroupPoints->PushButton1->click();
-    }
-    else if (myEditCurrentArgument == GroupPoints->LineEdit2 && getConstructorId() == 1) {
-      myCentPoint = aSelectedObject;
-      if (!myCentPoint->_is_nil() && myPoint1->_is_nil())
-        GroupPoints->PushButton4->click();
-    }
-    else if (myEditCurrentArgument == GroupPoints->LineEdit4) {
-      myPoint1 = aSelectedObject;
-      if (!myPoint1->_is_nil() && myPoint2->_is_nil())
-        GroupPoints->PushButton5->click();
-    }
-    else if (myEditCurrentArgument == GroupPoints->LineEdit5) {
-      myPoint2 = aSelectedObject;
-      if (!myPoint2->_is_nil() && !myObjects.length())
-        GroupPoints->PushButton1->click();
+    else {
+      if (myEditCurrentArgument == GroupPoints->LineEdit2 ) {
+       if ( getConstructorId() == 0 )
+         myAxis.nullify();
+       else if ( getConstructorId() == 1 )
+         myCentPoint.nullify();
+      }
+      else if ( myEditCurrentArgument == GroupPoints->LineEdit4 ) {
+       myPoint1.nullify();
+      }
+      else if ( myEditCurrentArgument == GroupPoints->LineEdit5 ) {
+       myPoint2.nullify();
+      }
+      myEditCurrentArgument->setText("");
     }
   }
 
-  // clear selection
-  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
-  myGeomGUI->getApp()->selectionMgr()->clearSelected();
-  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
-          this, SLOT(SelectionIntoArgument()));
-
-  displayPreview();
+  processPreview();
 }
 
 //=================================================================================
@@ -377,7 +344,11 @@ void TransformationGUI_RotationDlg::SetEditCurrentArgument()
     myEditCurrentArgument = GroupPoints->LineEdit1;
 
     GroupPoints->PushButton2->setDown(false);
+    GroupPoints->PushButton4->setDown(false);
+    GroupPoints->PushButton5->setDown(false);
     GroupPoints->LineEdit2->setEnabled(false);
+    GroupPoints->LineEdit4->setEnabled(false);
+    GroupPoints->LineEdit5->setEnabled(false);
   }
   else if (send == GroupPoints->PushButton2) {
     myEditCurrentArgument = GroupPoints->LineEdit2;
@@ -428,21 +399,7 @@ void TransformationGUI_RotationDlg::SetEditCurrentArgument()
   send->setDown(true);
 
   // seems we need it only to avoid preview disappearing, caused by selection mode change
-  displayPreview();
-}
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose  :
-//=================================================================================
-void TransformationGUI_RotationDlg::LineEditReturnPressed()
-{
-  QLineEdit* send = (QLineEdit*)sender();
-  if (send == GroupPoints->LineEdit1 ||
-      send == GroupPoints->LineEdit2) {
-    myEditCurrentArgument = send;
-    GEOMBase_Skeleton::LineEditReturnPressed();
-  }
+  processPreview();
 }
 
 //=================================================================================
@@ -453,7 +410,7 @@ void TransformationGUI_RotationDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
-          this, SLOT( SelectionIntoArgument() ) );
+           this, SLOT( SelectionIntoArgument() ) );
 
   ConstructorsClicked( getConstructorId() );
 }
@@ -484,7 +441,7 @@ void TransformationGUI_RotationDlg::TextValueChangedInSpinBox( const QString& s)
 //=================================================================================
 void TransformationGUI_RotationDlg::ValueChangedInSpinBox()
 {
-  displayPreview();
+  processPreview();
 }
 
 //=================================================================================
@@ -502,19 +459,18 @@ GEOM::GEOM_IOperations_ptr TransformationGUI_RotationDlg::createOperation()
 //=================================================================================
 bool TransformationGUI_RotationDlg::isValid (QString& msg)
 {
+  bool ok = false;
   switch (getConstructorId()) {
-  case 0: {
-    bool ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() );
-    return myObjects.length() > 0 && !(myAxis->_is_nil()) && ok;
+  case 0:
+    ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && !myObjects.isEmpty() && myAxis;
     break;
-  }
   case 1:
-    return myObjects.length() > 0 && !(myCentPoint->_is_nil() || myPoint1->_is_nil() || myPoint2->_is_nil());
+    ok = !myObjects.isEmpty() && myCentPoint && myPoint1 && myPoint2;
     break;
   default:
     break;
   }
-  return false;
+  return ok;
 }
 
 //=================================================================================
@@ -528,36 +484,36 @@ bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
 
   GEOM::GEOM_Object_var anObj;
 
+  GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
+
   switch (getConstructorId()) {
   case 0:
     {
       QStringList aParameters;
       aParameters<<GroupPoints->SpinBox_DX->text();
       if (toCreateCopy) {
-        for (int i = 0; i < myObjects.length(); i++) {
+        for (int i = 0; i < myObjects.count(); i++) {
           myCurrObject = myObjects[i];
-          anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
-            RotateCopy(myObjects[i], myAxis, GetAngle() * PI180);
+          anObj = anOper->RotateCopy(myObjects[i].get(), myAxis.get(), GetAngle() * M_PI / 180.);
           if (!anObj->_is_nil()) {
             if(!IsPreview()) {
-              anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
+              anObj->SetParameters(aParameters.join(":").toLatin1().constData());
             }
             objects.push_back(anObj._retn());
           }
         }
       }
       else {
-        for (int i = 0; i < myObjects.length(); i++) {
+        for (int i = 0; i < myObjects.count(); i++) {
           myCurrObject = myObjects[i];
-          anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
-            Rotate(myObjects[i], myAxis, GetAngle() * PI180);
+          anObj = anOper->Rotate(myObjects[i].get(), myAxis.get(), GetAngle() * M_PI / 180.);
           if (!anObj->_is_nil()) {
             if(!IsPreview()) {
-              anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
-             updateAttributes(anObj, aParameters);
-           }
+              anObj->SetParameters(aParameters.join(":").toLatin1().constData());
+              updateAttributes(anObj, aParameters);
+            }
             objects.push_back(anObj._retn());
-         }
+          }
         }
       }
       res = true;
@@ -566,19 +522,17 @@ bool TransformationGUI_RotationDlg::execute (ObjectList& objects)
   case 1:
     {
       if (toCreateCopy) {
-        for (int i = 0; i < myObjects.length(); i++) {
+        for (int i = 0; i < myObjects.count(); i++) {
           myCurrObject = myObjects[i];
-          anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
-            RotateThreePointsCopy(myObjects[i], myCentPoint, myPoint1, myPoint2);
+          anObj = anOper->RotateThreePointsCopy(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
           if (!anObj->_is_nil())
             objects.push_back(anObj._retn());
         }
       }
       else {
-        for (int i = 0; i < myObjects.length(); i++) {
+        for (int i = 0; i < myObjects.count(); i++) {
           myCurrObject = myObjects[i];
-          anObj = GEOM::GEOM_ITransformOperations::_narrow(getOperation())->
-            RotateThreePoints(myObjects[i], myCentPoint, myPoint1, myPoint2);
+          anObj = anOper->RotateThreePoints(myObjects[i].get(), myCentPoint.get(), myPoint1.get(), myPoint2.get());
           if (!anObj->_is_nil())
             objects.push_back(anObj._retn());
         }
@@ -604,10 +558,11 @@ void TransformationGUI_RotationDlg::restoreSubShapes (SALOMEDS::Study_ptr   theS
     // and we need to point the first argument directly
     GEOM::ListOfGO_var anArgs = new GEOM::ListOfGO;
     anArgs->length(1);
-    anArgs[0] = myCurrObject;
+    anArgs[0] = myCurrObject.copy();
     getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, anArgs,
                                         /*theFindMethod=*/GEOM::FSM_Transformed,
-                                        /*theInheritFirstArg=*/true);
+                                        /*theInheritFirstArg=*/true,
+                                        mainFrame()->CheckBoxAddPrefix->isChecked());
   }
 }
 
@@ -624,9 +579,9 @@ double TransformationGUI_RotationDlg::GetAngle() const
 // function :  CreateCopyModeChanged()
 // purpose  :
 //=================================================================================
-void TransformationGUI_RotationDlg::CreateCopyModeChanged (bool isCreateCopy)
+void TransformationGUI_RotationDlg::CreateCopyModeChanged()
 {
-  mainFrame()->GroupBoxName->setEnabled(isCreateCopy);
+  mainFrame()->GroupBoxName->setEnabled(GroupPoints->CheckButton1->isChecked());
 }
 
 //=================================================================================
@@ -647,17 +602,17 @@ void TransformationGUI_RotationDlg::addSubshapesToStudy()
 {
   bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
   if (toCreateCopy) {
-    QMap<QString, GEOM::GEOM_Object_var> objMap;
     switch (getConstructorId()) {
     case 0:
-      objMap[GroupPoints->LineEdit2->text()] = myAxis;
+      GEOMBase::PublishSubObject( myAxis.get() );
       break;
     case 1:
-      objMap[GroupPoints->LineEdit2->text()] = myCentPoint;
-      objMap[GroupPoints->LineEdit4->text()] = myPoint1;
-      objMap[GroupPoints->LineEdit5->text()] = myPoint2;
+      GEOMBase::PublishSubObject( myCentPoint.get() );
+      GEOMBase::PublishSubObject( myPoint1.get() );
+      GEOMBase::PublishSubObject( myPoint2.get() );
+      break;
+    default:
       break;
     }
-    addSubshapesToFather(objMap);
   }
 }