Salome HOME
Added a method to disable waiting cursor in the preview operation
[modules/geom.git] / src / PrimitiveGUI / PrimitiveGUI_FaceDlg.cxx
index 96d0f7d04bf683436c2b937035d017589ad1be4a..1e1004b016b2cc1f977e4d53940999ba5fe6953e 100755 (executable)
@@ -1,20 +1,20 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-//  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
@@ -124,8 +124,8 @@ void PrimitiveGUI_FaceDlg::Init()
   /* init variables */
   myEditCurrentArgument = GroupPlane->LineEdit1;
   GroupType->RadioButton1->setChecked(true);
-  myEdge = GEOM::GEOM_Object::_nil();
-  myFace = GEOM::GEOM_Object::_nil();
+  myEdge.nullify();
+  myFace.nullify();
   globalSelection(); // close local contexts, if any
   //  localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
 
@@ -159,7 +159,6 @@ void PrimitiveGUI_FaceDlg::Init()
   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
 
   connect( GroupPlane->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
-  connect( GroupPlane->LineEdit1,    SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
   connect( GroupPlane->SpinBox_DX, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
   connect( GroupPlane->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
 
@@ -199,7 +198,7 @@ void PrimitiveGUI_FaceDlg::SetDoubleSpinBoxStep( double step )
 //=================================================================================
 void PrimitiveGUI_FaceDlg::ValueChangedInSpinBox( double newValue )
 {
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -214,7 +213,7 @@ void PrimitiveGUI_FaceDlg::RadioButtonClicked()
     myOrientationType = 2;
   else if ( GroupOrientation->RadioButton3->isChecked() )
     myOrientationType = 3;
-  displayPreview();
+  displayPreview(true);
 }
 
 //=================================================================================
@@ -233,6 +232,10 @@ void PrimitiveGUI_FaceDlg::TypeButtonClicked()
     localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
     GroupPlane->TextLabel1->setText( tr( "GEOM_FACE" ) );
   }
+  myEditCurrentArgument = GroupPlane->LineEdit1;
+  myEditCurrentArgument->setText( "" );
+  myEdge.nullify();
+  myFace.nullify();
 }
 
 //=================================================================================
@@ -241,6 +244,7 @@ void PrimitiveGUI_FaceDlg::TypeButtonClicked()
 //=================================================================================
 void PrimitiveGUI_FaceDlg::ClickOnOk()
 {
+  setIsApplyAndClose( true );
   if ( ClickOnApply() )
     ClickOnCancel();
 }
@@ -287,8 +291,8 @@ void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
       myEditCurrentArgument = GroupPlane->LineEdit1;
       myEditCurrentArgument->setText("");
-      myEdge = GEOM::GEOM_Object::_nil();
-      myFace = GEOM::GEOM_Object::_nil();
+      myEdge.nullify();
+      myFace.nullify();
       GroupType->RadioButton1->setChecked( true );
       TypeButtonClicked();
       GroupDimensions->hide();
@@ -303,7 +307,7 @@ void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
   updateGeometry();
   resize( minimumSizeHint() );
   SelectionIntoArgument();
-  //displayPreview();
+  //displayPreview(true);
 }
 
 //=================================================================================
@@ -313,7 +317,7 @@ void PrimitiveGUI_FaceDlg::ConstructorsClicked( int constructorId )
 void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
 {
   if (getConstructorId() == 0) {
-    displayPreview();
+    displayPreview(true);
     return;
   }
 
@@ -324,56 +328,25 @@ void PrimitiveGUI_FaceDlg::SelectionIntoArgument()
   aSelMgr->selectedObjects(aSelList);
 
   if ( aSelList.Extent() != 1 ) {
-    if ( myEditCurrentArgument == GroupPlane->LineEdit1 )  myEdge = GEOM::GEOM_Object::_nil();
+    if ( myEditCurrentArgument == GroupPlane->LineEdit1 )  myEdge.nullify();
     return;
   }
 
-  // nbSel == 1 
-  Standard_Boolean aRes = Standard_False;
-  TopAbs_ShapeEnum aNeedType = TopAbs_EDGE;
-  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() ) {
-      if (GroupType->RadioButton2->isChecked())
-        aNeedType = TopAbs_FACE;
-
-      TColStd_IndexedMapOfInteger aMap;
-      aSelMgr->GetIndexes( aSelList.First(), aMap );
-      if ( aMap.Extent() == 1 ) { // Local Selection
-        int anIndex = aMap( 1 );
-        if ( aNeedType == TopAbs_EDGE )
-          aName += QString( ":edge_%1" ).arg( anIndex );
-        else
-          aName += QString( ":face_%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() != aNeedType ) {
-          aSelectedObject = GEOM::GEOM_Object::_nil();
-          aName = "";
-        }
-      }
-    }
+  TopAbs_ShapeEnum aNeedType = GroupType->RadioButton2->isChecked() ? TopAbs_FACE : TopAbs_EDGE;
+  GEOM::GeomObjPtr aSelectedObject = getSelected( aNeedType );
+  TopoDS_Shape aShape;
+  if ( aSelectedObject && GEOMBase::GetShape( aSelectedObject.get(), aShape ) && !aShape.IsNull() ) {
+    QString aName = GEOMBase::GetName( aSelectedObject.get() );
 
     myEditCurrentArgument->setText( aName );
+    
     if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_EDGE )
       myEdge = aSelectedObject;
     else if ( myEditCurrentArgument == GroupPlane->LineEdit1 && aNeedType == TopAbs_FACE )
       myFace = aSelectedObject;
   }
-  displayPreview();
+
+  displayPreview(true);
 }
 
 
@@ -398,20 +371,6 @@ void PrimitiveGUI_FaceDlg::SetEditCurrentArgument()
   SelectionIntoArgument();
 }
 
-
-//=================================================================================
-// function : LineEditReturnPressed()
-// purpose  :
-//=================================================================================
-void PrimitiveGUI_FaceDlg::LineEditReturnPressed()
-{
-  QLineEdit* send = (QLineEdit*)sender();
-  if ( send == GroupPlane->LineEdit1 )  myEditCurrentArgument = GroupPlane->LineEdit1;
-  else return;
-  GEOMBase_Skeleton::LineEditReturnPressed();
-}
-
-
 //=================================================================================
 // function : ActivateThisDialog()
 // purpose  :
@@ -459,28 +418,19 @@ GEOM::GEOM_IOperations_ptr PrimitiveGUI_FaceDlg::createOperation()
 //=================================================================================
 bool PrimitiveGUI_FaceDlg::isValid( QString& msg )
 {
-  bool ok = true;
+  bool ok = false;
   if( getConstructorId() == 0 )
   {
-    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
-    ok = GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
+    ok = GroupDimensions->SpinBox_DX->isValid( msg, !IsPreview() ) &&
+         GroupDimensions->SpinBox_DY->isValid( msg, !IsPreview() );
   }
   else if( getConstructorId() == 1 )
   {
-    ok = GroupPlane->SpinBox_DX->isValid( msg, !IsPreview() ) && ok;
-    ok = GroupPlane->SpinBox_DY->isValid( msg, !IsPreview() ) && ok;
+    ok = GroupPlane->SpinBox_DX->isValid( msg, !IsPreview() ) &&
+         GroupPlane->SpinBox_DY->isValid( msg, !IsPreview() ) &&
+         ( GroupType->RadioButton1->isChecked() ? myEdge : myFace );
   }
-
-  const int id = getConstructorId();
-  if ( id == 0 )
-    return ok;
-  else if ( id == 1 ) {
-    if (GroupType->RadioButton1->isChecked())
-      return !myEdge->_is_nil() && ok;
-    else if (GroupType->RadioButton2->isChecked())
-      return !myFace->_is_nil() && ok;
-  }
-  return false;
+  return ok;
 }
 
 //=================================================================================
@@ -509,8 +459,8 @@ bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
     break;
   case 1:
     anObj = GroupType->RadioButton1->isChecked() ? 
-      anOper->MakeFaceObjHW(myEdge, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) : 
-      anOper->MakeFaceObjHW(myFace, GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
+      anOper->MakeFaceObjHW(myEdge.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value()) : 
+      anOper->MakeFaceObjHW(myFace.get(), GroupPlane->SpinBox_DX->value(), GroupPlane->SpinBox_DY->value());
     if (!anObj->_is_nil() && !IsPreview())
     {
       aParameters << GroupPlane->SpinBox_DX->text();
@@ -533,14 +483,10 @@ bool PrimitiveGUI_FaceDlg::execute (ObjectList& objects)
 //=================================================================================
 void PrimitiveGUI_FaceDlg::addSubshapesToStudy()
 {
-  QMap<QString, GEOM::GEOM_Object_var> objMap;
-  switch ( getConstructorId() ) {
-  case 1 :
+  if ( getConstructorId() == 1 ) {
     if ( GroupType->RadioButton1->isChecked() )
-      objMap[GroupPlane->LineEdit1->text()] = myEdge;
+     GEOMBase::PublishSubObject( myEdge.get() );
     if ( GroupType->RadioButton2->isChecked() )
-      objMap[GroupPlane->LineEdit1->text()] = myFace;
-    break;
+     GEOMBase::PublishSubObject( myFace.get() );
   }
-  addSubshapesToFather( objMap );
 }