Salome HOME
0021209: Bug GetInPlace with faces. Integrate self-intersections checker.
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_SphereDlg.cxx
index 506e8b33d2290905a268e757b3a67c6736fc441d..ed06641200a1a1b95c758527a6721c49fe52516a 100644 (file)
@@ -1,24 +1,25 @@
-//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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   : PrimitiveGUI_SphereDlg.cxx
 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
@@ -108,15 +109,15 @@ void PrimitiveGUI_SphereDlg::Init()
   myEditCurrentArgument = GroupPoints->LineEdit1;
   GroupPoints->LineEdit1->setReadOnly( true );
   
-  myPoint = GEOM::GEOM_Object::_nil();
+  myPoint.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( GroupPoints->SpinBox_DX, 0.000001, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
-  initSpinBox( GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, 6 ); // VSR: TODO: DBL_DIGITS_DISPLAY
+  initSpinBox( GroupPoints->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" );
+  initSpinBox( GroupDimensions->SpinBox_DX, 0.000001, COORD_MAX, step, "length_precision" );
   GroupPoints->SpinBox_DX->setValue( 100.0 );
   GroupDimensions->SpinBox_DX->setValue( 100.0 );
   
@@ -127,7 +128,6 @@ void PrimitiveGUI_SphereDlg::Init()
   connect( this,          SIGNAL( constructorsClicked( int ) ), this, SLOT( ConstructorsClicked( int ) ) );
 
   connect( GroupPoints->PushButton1, SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
-  connect( GroupPoints->LineEdit1,   SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
 
   connect( GroupDimensions->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
   connect( GroupPoints->SpinBox_DX,     SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
@@ -172,7 +172,7 @@ void PrimitiveGUI_SphereDlg::ConstructorsClicked( int constructorId )
       
       myEditCurrentArgument = GroupPoints->LineEdit1;
       GroupPoints->LineEdit1->setText( "" );
-      myPoint = GEOM::GEOM_Object::_nil();
+      myPoint.nullify();
       
       connect( myGeomGUI->getApp()->selectionMgr(), 
                SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
@@ -192,8 +192,9 @@ void PrimitiveGUI_SphereDlg::ConstructorsClicked( int constructorId )
   qApp->processEvents();
   updateGeometry();
   resize( minimumSizeHint() );
+  SelectionIntoArgument();
 
-  displayPreview();
+  displayPreview(true);
 }
 
 
@@ -203,6 +204,7 @@ void PrimitiveGUI_SphereDlg::ConstructorsClicked( int constructorId )
 //=================================================================================
 void PrimitiveGUI_SphereDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
@@ -239,66 +241,21 @@ void PrimitiveGUI_SphereDlg::SelectionIntoArgument()
   aSelMgr->selectedObjects(aSelList);
 
   if (aSelList.Extent() != 1) {
-    myPoint = GEOM::GEOM_Object::_nil();
+    myPoint.nullify();
     return;
   }
 
-  /* nbSel == 1 ! */
-  Standard_Boolean testResult = Standard_False;
-  GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
-
-  if ( !testResult || CORBA::is_nil( aSelectedObject ) )
-    return;
-  QString aName = GEOMBase::GetName( aSelectedObject );
+  GEOM::GeomObjPtr aSelectedObject = getSelected( TopAbs_VERTEX );
   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.append( ":vertex_" + QString::number( 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 = "";
-      }
-    }
+  if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
+    QString aName = GEOMBase::GetName( aSelectedObject.get() );
+    myEditCurrentArgument->setText( aName );
+    myPoint = aSelectedObject;
   }
 
-  myEditCurrentArgument->setText( aName );
-  myPoint = aSelectedObject;
-
-  displayPreview();
-}
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose  :
-//=================================================================================
-void PrimitiveGUI_SphereDlg::LineEditReturnPressed()
-{
-  QLineEdit* send = (QLineEdit*)sender();
-  if ( send == GroupPoints->LineEdit1 ) {
-    myEditCurrentArgument = send;
-    GEOMBase_Skeleton::LineEditReturnPressed();
-  }
+  displayPreview(true);
 }
 
-
 //=================================================================================
 // function : SetEditCurrentArgument()
 // purpose  :
@@ -358,7 +315,7 @@ void PrimitiveGUI_SphereDlg::enterEvent( QEvent* )
 //=================================================================================
 void PrimitiveGUI_SphereDlg::ValueChangedInSpinBox()
 {
-  displayPreview();
+  displayPreview(true);
 }
 
 
@@ -378,12 +335,12 @@ GEOM::GEOM_IOperations_ptr PrimitiveGUI_SphereDlg::createOperation()
 //=================================================================================
 bool PrimitiveGUI_SphereDlg::isValid( QString& msg  )
 {
-  bool ok = true;
+  bool ok = false;
   if( getConstructorId() == 0 )
-    ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
+    ok = GroupPoints->SpinBox_DX->isValid( msg, !IsPreview() ) && myPoint;
   else if( getConstructorId() == 1 )
-    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
-  return getConstructorId() == 0 ? !myPoint->_is_nil() && ok : ok;
+    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() );
+  return ok;
 }
 
 //=================================================================================
@@ -401,8 +358,8 @@ bool PrimitiveGUI_SphereDlg::execute( ObjectList& objects )
   switch ( getConstructorId() ) {
   case 0 :
     {
-      if ( !CORBA::is_nil( myPoint ) ) {
-        anObj = anOper->MakeSpherePntR( myPoint, getRadius() );
+      if ( myPoint ) {
+        anObj = anOper->MakeSpherePntR( myPoint.get(), getRadius() );
         if (!anObj->_is_nil() && !IsPreview())
         {
           QStringList aParameters;
@@ -454,14 +411,7 @@ double PrimitiveGUI_SphereDlg::getRadius() const
 //=================================================================================
 void PrimitiveGUI_SphereDlg::addSubshapesToStudy()
 {
-  QMap<QString, GEOM::GEOM_Object_var> objMap;
-
-  switch ( getConstructorId() ) {
-  case 0:
-    objMap[GroupPoints->LineEdit1->text()] = myPoint;
-    break;
-  case 1:
-    return;
+  if ( getConstructorId() == 0 ) {
+    GEOMBase::PublishSubObject( myPoint.get() );
   }
-  addSubshapesToFather( objMap );
 }