Salome HOME
IPAL19834: Incorrect result after make Partition of 2 objects. A fix by PKV.
[modules/geom.git] / src / BasicGUI / BasicGUI_VectorDlg.cxx
index 2d91ba4ef61629b75d7e4ed0af9d116f1c583fe4..9408a0a3971f0e8bca95b1e0ebcd7e68f2b93dea 100644 (file)
@@ -25,7 +25,7 @@
 
 #include "BasicGUI_VectorDlg.h"
 
-#include <GEOM_DlgRef.h>
+#include <DlgRef.h>
 #include <GeometryGUI.h>
 #include <GEOMBase.h>
 
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 
+#include <TopoDS_Shape.hxx>
+#include <TopoDS.hxx>
+#include <TopExp.hxx>
+#include <TColStd_IndexedMapOfInteger.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+
 #include <GEOMImpl_Types.hxx>
 
 //=================================================================================
 // class    : BasicGUI_VectorDlg()
-// purpose  : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the 
+// purpose  : Constructs a BasicGUI_VectorDlg which is a child of 'parent', with the
 //            name 'name' and widget flags set to 'f'.
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
@@ -84,8 +90,8 @@ BasicGUI_VectorDlg::BasicGUI_VectorDlg( GeometryGUI* theGeometryGUI, QWidget* pa
   layout->addWidget( GroupDimensions );
   /***************************************************************/
 
-  setHelpFileName( "vector.htm" );
-  
+  setHelpFileName( "create_vector_page.html" );
+
   /* Initialisations */
   Init();
 }
@@ -96,7 +102,7 @@ BasicGUI_VectorDlg::BasicGUI_VectorDlg( GeometryGUI* theGeometryGUI, QWidget* pa
 // purpose  : Destroys the object and frees any allocated resources
 //=================================================================================
 BasicGUI_VectorDlg::~BasicGUI_VectorDlg()
-{  
+{
 }
 
 
@@ -115,11 +121,11 @@ void BasicGUI_VectorDlg::Init()
   /* 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, 3 );
-  initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 );
-  initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 );
+  initSpinBox( GroupDimensions->SpinBox_DX, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
+  initSpinBox( GroupDimensions->SpinBox_DY, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
+  initSpinBox( GroupDimensions->SpinBox_DZ, COORD_MIN, COORD_MAX, step, 3 ); // VSR:TODO : DBL_DIGITS_DISPLAY
 
   double dx( 0. ), dy( 0. ), dz( 200. );
   GroupDimensions->SpinBox_DX->setValue( dx );
@@ -131,7 +137,7 @@ void BasicGUI_VectorDlg::Init()
   /* signals and slots connections */
   connect( myGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( DeactivateActiveDialog() ) );
   connect( myGeomGUI, SIGNAL( SignalCloseAllDialogs() ),        this, SLOT( ClickOnCancel() ) );
-  
+
   connect( buttonOk(),     SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
   connect( buttonApply(),  SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
 
@@ -147,20 +153,28 @@ void BasicGUI_VectorDlg::Init()
   connect( GroupDimensions->SpinBox_DY, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
   connect( GroupDimensions->SpinBox_DZ, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox( double ) ) );
 
-  // VSR: TODO ->>
-  connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DX, SLOT( SetStep( double ) ) );
-  connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DY, SLOT( SetStep( double ) ) );
-  connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), GroupDimensions->SpinBox_DZ, SLOT( SetStep( double ) ) );
-  // <<-
+  connect( myGeomGUI, SIGNAL( SignalDefaultStepValueChanged( double ) ), this, SLOT( SetDoubleSpinBoxStep( double ) ) );
 
   connect( GroupDimensions->CheckButton1, SIGNAL( stateChanged( int ) ), this, SLOT( ReverseVector( int ) ) );
 
-  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
+  connect( myGeomGUI->getApp()->selectionMgr(),
+          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
 
   initName( tr("GEOM_VECTOR") );
 
-  ConstructorsClicked( 0 );
+  setConstructorId( 1 ); // simplest constructor
+  ConstructorsClicked( 1 );
+}
+
+//=================================================================================
+// function : SetDoubleSpinBoxStep()
+// purpose  : Double spin box management
+//=================================================================================
+void BasicGUI_VectorDlg::SetDoubleSpinBoxStep( double step )
+{
+  GroupDimensions->SpinBox_DX->setSingleStep(step);
+  GroupDimensions->SpinBox_DY->setSingleStep(step);
+  GroupDimensions->SpinBox_DZ->setSingleStep(step);
 }
 
 
@@ -170,7 +184,7 @@ void BasicGUI_VectorDlg::Init()
 //=================================================================================
 void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
 {
-  disconnect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 0, this, 0 );
+  disconnect( myGeomGUI->getApp()->selectionMgr(), 0, this, 0 );
   myPoint1 = GEOM::GEOM_Object::_nil();
   myPoint2 = GEOM::GEOM_Object::_nil();
 
@@ -179,26 +193,28 @@ void BasicGUI_VectorDlg::ConstructorsClicked( int constructorId )
     {
       GroupDimensions->hide();
       GroupPoints->show();
-      
+
       myEditCurrentArgument = GroupPoints->LineEdit1;
       GroupPoints->LineEdit1->setText( "" );
       GroupPoints->LineEdit2->setText( "" );
-      
-      globalSelection( GEOM_POINT );
-      connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
-              SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
+
+      globalSelection(); // close local contexts, if any
+      localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
+      connect( myGeomGUI->getApp()->selectionMgr(),
+              SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
       break;
     }
   case 1:
     {
       GroupPoints->hide();
       GroupDimensions->show();
-      
-      double dx( 0. ), dy( 0. ), dz( 0. ); 
+      globalSelection(); // close local contexts, if any
+
+      double dx( 0. ), dy( 0. ), dz( 0. );
       GroupDimensions->SpinBox_DX->setValue( dx );
       GroupDimensions->SpinBox_DY->setValue( dy );
       GroupDimensions->SpinBox_DZ->setValue( dz );
-      
+
       GroupDimensions->CheckButton1->setChecked( false );
       break;
     }
@@ -256,11 +272,42 @@ void BasicGUI_VectorDlg::SelectionIntoArgument()
     return;
   }
 
-  // nbSel == 1 
+  // nbSel == 1
   Standard_Boolean aRes = Standard_False;
   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
   if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
-    myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
+    QString aName = GEOMBase::GetName(aSelectedObject);
+
+    TopoDS_Shape aShape;
+    if ( GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) {
+      LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+      TColStd_IndexedMapOfInteger aMap;
+      aSelMgr->GetIndexes( firstIObject(), 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 = "";
+        }
+      }
+    }
+
+    myEditCurrentArgument->setText(aName);
+
     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
   }
@@ -288,7 +335,7 @@ void BasicGUI_VectorDlg::SetEditCurrentArgument()
 // purpose  :
 //=================================================================================
 void BasicGUI_VectorDlg::LineEditReturnPressed()
-{ 
+{
   QLineEdit* send = (QLineEdit*)sender();
   if      ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
   else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
@@ -304,8 +351,8 @@ void BasicGUI_VectorDlg::LineEditReturnPressed()
 void BasicGUI_VectorDlg::ActivateThisDialog()
 {
   GEOMBase_Skeleton::ActivateThisDialog();
-  connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
-          SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
+  connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
+           this, SLOT( SelectionIntoArgument() ) );
        
   ConstructorsClicked( getConstructorId() );
 }
@@ -316,7 +363,6 @@ void BasicGUI_VectorDlg::ActivateThisDialog()
 //=================================================================================
 void BasicGUI_VectorDlg::DeactivateActiveDialog()
 {
-  // myGeomGUI->SetState( -1 );
   GEOMBase_Skeleton::DeactivateActiveDialog();
 }
 
@@ -352,7 +398,7 @@ void BasicGUI_VectorDlg::ReverseVector( int state )
   GroupDimensions->SpinBox_DX->setValue( dx );
   GroupDimensions->SpinBox_DY->setValue( dy );
   GroupDimensions->SpinBox_DZ->setValue( dz );
-  
+
   displayPreview();
 }
 
@@ -381,7 +427,7 @@ bool BasicGUI_VectorDlg::isValid( QString& msg )
 bool BasicGUI_VectorDlg::execute( ObjectList& objects )
 {
   bool res = false;
-  
+
   GEOM::GEOM_Object_var anObj;
 
   switch ( getConstructorId() ) {
@@ -408,3 +454,21 @@ bool BasicGUI_VectorDlg::execute( ObjectList& objects )
   return res;
 }
 
+//=================================================================================
+// function : addSubshapeToStudy
+// purpose  : virtual method to add new SubObjects if local selection
+//=================================================================================
+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;
+  }
+  addSubshapesToFather( objMap );
+}