Salome HOME
Initial version of interface 'CurveCreator_ISection' was created for the curve sections.
[modules/geom.git] / src / BasicGUI / BasicGUI_VectorDlg.cxx
index 23a1a8492bf73ab79c6e4ad6330939ee18aebf55..8b915423bb37e7e3be161d34bbbed9862cd98ba3 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2015  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, or (at your option) any later version.
 //
-//  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   : BasicGUI_VectorDlg.cxx
 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
@@ -50,7 +51,7 @@
 //            TRUE to construct a modal dialog.
 //=================================================================================
 BasicGUI_VectorDlg::BasicGUI_VectorDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
-                                       bool modal, Qt::WindowFlags fl )
+                                        bool modal, Qt::WindowFlags fl )
   : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
 {
   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_VECTOR_2P" ) ) );
@@ -118,17 +119,17 @@ 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();
   double step = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100 );
 
   /* min, max, step and decimals for spin boxes */
-  initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
-  initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
-  initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 6 ); // VSR:TODO : DBL_DIGITS_DISPLAY
+  initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, "length_precision" );
+  initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, "length_precision" );
+  initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, "length_precision" );
 
   double dx( 0. ), dy( 0. ), dz( 200. );
   GroupDimensions->SpinBox_DX->setValue( dx );
@@ -149,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 ) ) );
@@ -161,7 +159,7 @@ void BasicGUI_VectorDlg::Init()
   connect( GroupDimensions->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( ReverseVector( int ) ) );
 
   connect( myGeomGUI->getApp()->selectionMgr(),
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+           SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 
   initName( tr("GEOM_VECTOR") );
 
@@ -188,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:
@@ -208,7 +206,7 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
       globalSelection(); // close local contexts, if any
       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
       connect( myGeomGUI->getApp()->selectionMgr(),
-              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+               SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
       break;
     }
   case 1:
@@ -230,8 +228,9 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
   qApp->processEvents();
   updateGeometry();
   resize( minimumSizeHint() );
+  SelectionIntoArgument();
 
-  displayPreview();
+  displayPreview(true);
 }
 
 
@@ -241,6 +240,7 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
 //=================================================================================
 void BasicGUI_VectorDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
@@ -270,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())
-       GroupPoints->PushButton2->click();
+      if (myPoint1 && !myPoint2)
+        GroupPoints->PushButton2->click();
     }
     else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
       myPoint2 = aSelectedObject;
-      if (!myPoint2->_is_nil() && myPoint1->_is_nil())
-       GroupPoints->PushButton1->click();
+      if (myPoint2 && !myPoint1)
+        GroupPoints->PushButton1->click();
     }
   }
 
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -362,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);
 }
 
 
@@ -389,7 +340,7 @@ void BasicGUI_VectorDlg::ActivateThisDialog()
   GEOMBase_Skeleton::ActivateThisDialog();
   connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
            this, SLOT( SelectionIntoArgument() ) );
-       
+        
   ConstructorsClicked( getConstructorId() );
 }
 
@@ -418,7 +369,7 @@ void BasicGUI_VectorDlg::enterEvent( QEvent* )
 //=================================================================================
 void BasicGUI_VectorDlg::ValueChangedInSpinBox( double newValue )
 {
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -435,7 +386,7 @@ void BasicGUI_VectorDlg::ReverseVector( int state )
   GroupDimensions->SpinBox_DY->setValue( dy );
   GroupDimensions->SpinBox_DZ->setValue( dz );
 
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -453,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;
 }
 
 //=================================================================================
@@ -476,10 +426,12 @@ bool BasicGUI_VectorDlg::execute( ObjectList& objects )
 
   GEOM::GEOM_Object_var anObj;
 
+  GEOM::GEOM_IBasicOperations_var anOper = GEOM::GEOM_IBasicOperations::_narrow( getOperation() );
+
   switch ( getConstructorId() ) {
   case 0 :
     {
-      anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorTwoPnt( myPoint1, myPoint2 );
+      anObj = anOper->MakeVectorTwoPnt( myPoint1.get(), myPoint2.get() );
       res = true;
       break;
     }
@@ -493,10 +445,10 @@ bool BasicGUI_VectorDlg::execute( ObjectList& objects )
       aParameters << GroupDimensions->SpinBox_DX->text();
       aParameters << GroupDimensions->SpinBox_DY->text();
       aParameters << GroupDimensions->SpinBox_DZ->text();
-      anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeVectorDXDYDZ( dx, dy, dz );
+      anObj = anOper->MakeVectorDXDYDZ( dx, dy, dz );
 
       if ( !anObj->_is_nil() && !IsPreview() )
-        anObj->SetParameters(GeometryGUI::JoinObjectParameters(aParameters));
+        anObj->SetParameters(aParameters.join(":").toLatin1().constData());
       
       res = true;
       break;
@@ -515,15 +467,19 @@ 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 );
+}
+
+//=================================================================================
+// function : getSourceObjects
+// purpose  : virtual method to get source objects
+//=================================================================================
+QList<GEOM::GeomObjPtr> BasicGUI_VectorDlg::getSourceObjects()
+{
+  QList<GEOM::GeomObjPtr> res;
+  res << myPoint1 << myPoint2;
+  return res;
 }