Salome HOME
Update translations for Chamfer and Fillet 3D operations.
[modules/geom.git] / src / BasicGUI / BasicGUI_VectorDlg.cxx
index 3ec36f1a23fd1065787cf774aedbcbfa915765e4..847e06c16b3659d31fa3a82237085592253344c2 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  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
@@ -119,8 +119,8 @@ void BasicGUI_VectorDlg::Init()
     /* init variables */
   myEditCurrentArgument = GroupPoints->LineEdit1;
 
-  myPoint1 = GEOM::GEOM_Object::_nil();
-  myPoint2 = GEOM::GEOM_Object::_nil();
+  myPoint1.nullify();
+  myPoint2.nullify();
 
   /* Get setting of step value from file configuration */
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
@@ -150,9 +150,6 @@ void BasicGUI_VectorDlg::Init()
   connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
   connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
 
-  connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
-  connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
-
   connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
   connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
   connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
@@ -189,8 +186,8 @@ void BasicGUI_VectorDlg::SetDoubleSpinBoxStep( double step )
 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
 {
   disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
-  myPoint1 = GEOM::GEOM_Object::_nil();
-  myPoint2 = GEOM::GEOM_Object::_nil();
+  myPoint1.nullify();
+  myPoint2.nullify();
 
   switch ( constructorId ) {
   case 0:
@@ -231,8 +228,9 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
   qApp->processEvents();
   updateGeometry();
   resize( minimumSizeHint() );
+  SelectionIntoArgument();
 
-  displayPreview();
+  displayPreview(true);
 }
 
 
@@ -242,6 +240,7 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
 //=================================================================================
 void BasicGUI_VectorDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
@@ -271,72 +270,37 @@ bool BasicGUI_VectorDlg::ClickOnApply()
 void BasicGUI_VectorDlg::SelectionIntoArgument()
 {
   myEditCurrentArgument->setText( "" );
-
+  
   LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
   SALOME_ListIO aSelList;
   aSelMgr->selectedObjects(aSelList);
 
   if (aSelList.Extent() != 1) {
     if (myEditCurrentArgument == GroupPoints->LineEdit1)
-      myPoint1 = GEOM::GEOM_Object::_nil();
+      myPoint1.nullify();
     else if (myEditCurrentArgument == GroupPoints->LineEdit2)
-      myPoint2 = GEOM::GEOM_Object::_nil();
+      myPoint2.nullify();
     return;
   }
 
-  // nbSel == 1
-  Standard_Boolean aRes = Standard_False;
-  GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), aRes);
-  if (!CORBA::is_nil(aSelectedObject) && aRes) {
-    QString 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) { // Local Selection
-        int anIndex = aMap(1);
-        aName += QString(":vertex_%1").arg(anIndex);
-
-        //Find SubShape Object in Father
-        GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::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 = "";
-        }
-      }
-    }
-
+  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);
-
-    if (!aSelectedObject->_is_nil()) { // clear selection if something selected
-      globalSelection();
-      localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
-    }
-
-    if      (myEditCurrentArgument == GroupPoints->LineEdit1) {
+    if (myEditCurrentArgument == GroupPoints->LineEdit1) {
       myPoint1 = aSelectedObject;
-      if (!myPoint1->_is_nil() && myPoint2->_is_nil())
+      if (myPoint1 && !myPoint2)
         GroupPoints->PushButton2->click();
     }
     else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
       myPoint2 = aSelectedObject;
-      if (!myPoint2->_is_nil() && myPoint1->_is_nil())
+      if (myPoint2 && !myPoint1)
         GroupPoints->PushButton1->click();
     }
   }
 
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -363,21 +327,7 @@ void BasicGUI_VectorDlg::SetEditCurrentArgument()
   globalSelection(); // close local selection to clear it
   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
   send->setDown(true);
-  displayPreview();
-}
-
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose  :
-//=================================================================================
-void BasicGUI_VectorDlg::LineEditReturnPressed()
-{
-  QLineEdit* send = (QLineEdit*)sender();
-  if      ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
-  else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
-  else return;
-  GEOMBase_Skeleton::LineEditReturnPressed();
+  displayPreview(true);
 }
 
 
@@ -419,7 +369,7 @@ void BasicGUI_VectorDlg::enterEvent( QEvent* )
 //=================================================================================
 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
 {
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -436,7 +386,7 @@ void BasicGUI_VectorDlg::ReverseVector( int state )
   GroupDimensions->SpinBox_DY->setValue( dy );
   GroupDimensions->SpinBox_DZ->setValue( dz );
 
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -454,17 +404,16 @@ GEOM::GEOM_IOperations_ptr BasicGUI_VectorDlg::createOperation()
 //=================================================================================
 bool BasicGUI_VectorDlg::isValid( QString& msg )
 {
+  bool ok = false;
   if(getConstructorId() == 0) 
-    return !myPoint1->_is_nil() && !myPoint2->_is_nil();
+    ok = myPoint1 && myPoint2;
   else if(getConstructorId() == 1)
   {
-    bool ok = true;
-    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
-    ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
-    ok = GroupDimensions->SpinBox_DZ->isValid( msg, !IsPreview() ) && ok;
-    return ok;
+    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) &&
+         GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) &&
+         GroupDimensions->SpinBox_DZ->isValid( msg, !IsPreview() );
   }
-  return false;
+  return ok;
 }
 
 //=================================================================================
@@ -482,7 +431,7 @@ bool BasicGUI_VectorDlg::execute( ObjectList& objects )
   switch ( getConstructorId() ) {
   case 0 :
     {
-      anObj = anOper->MakeVectorTwoPnt( myPoint1, myPoint2 );
+      anObj = anOper->MakeVectorTwoPnt( myPoint1.get(), myPoint2.get() );
       res = true;
       break;
     }
@@ -518,15 +467,8 @@ bool BasicGUI_VectorDlg::execute( ObjectList& objects )
 //=================================================================================
 void BasicGUI_VectorDlg::addSubshapesToStudy()
 {
-  QMap<QString, GEOM::GEOM_Object_var> objMap;
-
-  switch ( getConstructorId() ) {
-  case 0:
-    objMap[GroupPoints->LineEdit1->text()] = myPoint1;
-    objMap[GroupPoints->LineEdit2->text()] = myPoint2;
-    break;
-  case 1:
-    return;
+  if ( getConstructorId() == 0 ) {
+    GEOMBase::PublishSubObject( myPoint1.get() );
+    GEOMBase::PublishSubObject( myPoint2.get() );
   }
-  addSubshapesToFather( objMap );
 }