Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/geom.git] / src / BasicGUI / BasicGUI_PlaneDlg.cxx
index 22975fe585d9c86d16fa40ac300d61c9d0796eda..64936d546c3c3b0e6c5053c9f1b34aa716550b2f 100644 (file)
@@ -1,23 +1,23 @@
 //  GEOM GEOMGUI : GUI for Geometry component
 //
 //  Copyright (C) 2003  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 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 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  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 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
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 #include "SalomeApp_Application.h"
 #include "LightApp_SelectionMgr.h"
 
+#include <TColStd_MapOfInteger.hxx>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TopExp.hxx>
+#include <TColStd_IndexedMapOfInteger.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
+
 #include <qlabel.h>
 
 #include "GEOMImpl_Types.hxx"
@@ -41,7 +50,7 @@ using namespace std;
 
 //=================================================================================
 // class    : BasicGUI_PlaneDlg()
-// purpose  : Constructs a BasicGUI_PlaneDlg which is a child of 'parent', with the 
+// purpose  : Constructs a BasicGUI_PlaneDlg 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.
@@ -89,20 +98,20 @@ BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(GeometryGUI* theGeometryGUI, QWidget* paren
   Group3Pnts->LineEdit3->setReadOnly( true );
 
   GroupFace = new DlgRef_1Sel1Spin(this, "GroupFace");
-  GroupFace->GroupBox1->setTitle(tr("GEOM_FACE"));
+  GroupFace->GroupBox1->setTitle(tr("GEOM_FACE_OR_LCS"));
   GroupFace->TextLabel1->setText(tr("GEOM_SELECTION"));
   GroupFace->TextLabel2->setText(tr("GEOM_PLANE_SIZE"));
   GroupFace->PushButton1->setPixmap(image3);
 
   GroupFace->LineEdit1->setReadOnly( true );
-    
+
   Layout1->addWidget(GroupPntDir, 2, 0);
   Layout1->addWidget(Group3Pnts, 2, 0);
   Layout1->addWidget(GroupFace, 2, 0);
   /***************************************************************/
 
-  setHelpFileName("plane.htm");
-  
+  setHelpFileName("create_plane_page.html");
+
   Init();
 }
 
@@ -112,7 +121,7 @@ BasicGUI_PlaneDlg::BasicGUI_PlaneDlg(GeometryGUI* theGeometryGUI, QWidget* paren
 // purpose  : Destroys the object and frees any allocated resources
 //=================================================================================
 BasicGUI_PlaneDlg::~BasicGUI_PlaneDlg()
-{  
+{
 }
 
 
@@ -132,15 +141,15 @@ void BasicGUI_PlaneDlg::Init()
   /* Get setting of step value from file configuration */
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
-  
+
   double aTrimSize = 2000.0;
-  
+
   /* min, max, step and decimals for spin boxes */
-  GroupPntDir->SpinBox_DX->RangeStepAndValidator( 0.001, 10000000.0, aStep, 3 );
+  GroupPntDir->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
   GroupPntDir->SpinBox_DX->SetValue( aTrimSize );
-  Group3Pnts->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
+  Group3Pnts->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
   Group3Pnts->SpinBox_DX->SetValue( aTrimSize );
-  GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, 10000000.0, aStep, 3);
+  GroupFace->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
   GroupFace->SpinBox_DX->SetValue( aTrimSize );
 
   /* signals and slots connections */
@@ -174,7 +183,7 @@ void BasicGUI_PlaneDlg::Init()
   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), Group3Pnts->SpinBox_DX, SLOT(SetStep(double)));
   connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupFace->SpinBox_DX, SLOT(SetStep(double)));
 
-  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_PLANE" ) );
 
@@ -190,64 +199,69 @@ void BasicGUI_PlaneDlg::Init()
 //=================================================================================
 void BasicGUI_PlaneDlg::ConstructorsClicked(int constructorId)
 {
-  disconnect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 0, this, 0);
+  disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = myFace = GEOM::GEOM_Object::_nil();
 
-  switch ( constructorId )
+  switch (constructorId)
   {
-    case 0: /* plane from a point and a direction (vector, edge...) */
-      {        
-                               Group3Pnts->hide();
-                               GroupFace->hide();
-                               resize(0, 0);
-                               GroupPntDir->show();
-
-                               myEditCurrentArgument = GroupPntDir->LineEdit1;
-                               GroupPntDir->LineEdit1->setText(tr(""));
-                               GroupPntDir->LineEdit2->setText(tr(""));
-
-                               /* for the first argument */
-                               globalSelection( GEOM_POINT );
-                               break;
-      }
-    case 1: /* plane from 3 points */
-      {
-                               GroupPntDir->hide();
-                               GroupFace->hide();
-                               resize(0, 0);
-                               Group3Pnts->show();
-
-                               myEditCurrentArgument = Group3Pnts->LineEdit1;
-                               Group3Pnts->LineEdit1->setText("");
-                               Group3Pnts->LineEdit2->setText("");
-                               Group3Pnts->LineEdit3->setText("");
-
-                               /* for the first argument */
-                               globalSelection( GEOM_POINT );
-                               break;
-      } 
-    case 2: /* plane from a planar face selection */
-      {
-                               GroupPntDir->hide();
-                               Group3Pnts->hide();
-                               resize(0, 0);
-                               GroupFace->show();
-
-                               myEditCurrentArgument = GroupFace->LineEdit1;
-                               GroupFace->LineEdit1->setText(tr(""));
-
-                               /* for the first argument */
-                               globalSelection( GEOM_PLANE );
-                               break;
-      }
+  case 0: /* plane from a point and a direction (vector, edge...) */
+    {
+      Group3Pnts->hide();
+      GroupFace->hide();
+      resize(0, 0);
+      GroupPntDir->show();
+
+      myEditCurrentArgument = GroupPntDir->LineEdit1;
+      GroupPntDir->LineEdit1->setText(tr(""));
+      GroupPntDir->LineEdit2->setText(tr(""));
+
+      /* for the first argument */
+      globalSelection(); // close local contexts, if any
+      localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
+      break;
     }
+  case 1: /* plane from 3 points */
+    {
+      GroupPntDir->hide();
+      GroupFace->hide();
+      resize(0, 0);
+      Group3Pnts->show();
+
+      myEditCurrentArgument = Group3Pnts->LineEdit1;
+      Group3Pnts->LineEdit1->setText("");
+      Group3Pnts->LineEdit2->setText("");
+      Group3Pnts->LineEdit3->setText("");
+
+      /* for the first argument */
+      globalSelection(); // close local contexts, if any
+      localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
+      break;
+    }
+  case 2: /* plane from a planar face selection */
+    {
+      GroupPntDir->hide();
+      Group3Pnts->hide();
+      resize(0, 0);
+      GroupFace->show();
+
+      myEditCurrentArgument = GroupFace->LineEdit1;
+      GroupFace->LineEdit1->setText(tr(""));
+
+      /* for the first argument */
+      //globalSelection( GEOM_PLANE );
+      TColStd_MapOfInteger aMap;
+      aMap.Add( GEOM_PLANE );
+      aMap.Add( GEOM_MARKER );
+      globalSelection( aMap );
+      break;
+    }
+  }
 
   myEditCurrentArgument->setFocus();
-  connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
-         SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
+  connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
+          this, SLOT(SelectionIntoArgument()));
 }
 
-
 //=================================================================================
 // function : ClickOnOk()
 // purpose  :
@@ -258,7 +272,6 @@ void BasicGUI_PlaneDlg::ClickOnOk()
     ClickOnCancel();
 }
 
-
 //=================================================================================
 // function : ClickOnApply()
 // purpose  :
@@ -289,8 +302,8 @@ void BasicGUI_PlaneDlg::ClickOnCancel()
 void BasicGUI_PlaneDlg::SelectionIntoArgument()
 {
   myEditCurrentArgument->setText("");
-  
-  if ( IObjectCount() != 1 )  
+
+  if (IObjectCount() != 1)
   {
     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint  = GEOM::GEOM_Object::_nil();
     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir    = GEOM::GEOM_Object::_nil();
@@ -303,10 +316,55 @@ void BasicGUI_PlaneDlg::SelectionIntoArgument()
 
   // 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 ) );
+  GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), aRes);
+  if (!CORBA::is_nil(aSelectedObject) && aRes)
+  {
+    QString aName = GEOMBase::GetName(aSelectedObject);
+
+    TopoDS_Shape aShape;
+    if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
+    {
+      TopAbs_ShapeEnum aNeedType = TopAbs_VERTEX;
+      if (myEditCurrentArgument == GroupPntDir->LineEdit2)
+        aNeedType = TopAbs_EDGE;
+      else if (myEditCurrentArgument == GroupFace->LineEdit1)
+        aNeedType = TopAbs_FACE;
+
+      LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+      TColStd_IndexedMapOfInteger aMap;
+      aSelMgr->GetIndexes(firstIObject(), aMap);
+      if (aMap.Extent() == 1) // Local Selection
+      {
+
+        int anIndex = aMap(1);
+        if (aNeedType == TopAbs_EDGE)
+          aName += QString(":edge_%1").arg(anIndex);
+        else if (aNeedType == TopAbs_FACE)
+          aName += QString(":face_%1").arg(anIndex);
+        else
+          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() != aNeedType) {
+          aSelectedObject = GEOM::GEOM_Object::_nil();
+          aName = "";
+        }
+      }
+    }
+
+    myEditCurrentArgument->setText(aName);
+
     if      ( myEditCurrentArgument == GroupPntDir->LineEdit1 ) myPoint  = aSelectedObject;
     else if ( myEditCurrentArgument == GroupPntDir->LineEdit2 ) myDir    = aSelectedObject;
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )  myPoint1 = aSelectedObject;
@@ -325,7 +383,8 @@ void BasicGUI_PlaneDlg::SelectionIntoArgument()
 //=================================================================================
 void BasicGUI_PlaneDlg::SetEditCurrentArgument()
 {
-  QPushButton* send = (QPushButton*)sender();  
+  QPushButton* send = (QPushButton*)sender();
+  globalSelection( GEOM_POINT );
 
   if      ( send == GroupPntDir->PushButton1 ) myEditCurrentArgument = GroupPntDir->LineEdit1;
   else if ( send == GroupPntDir->PushButton2 ) myEditCurrentArgument = GroupPntDir->LineEdit2;
@@ -335,18 +394,25 @@ void BasicGUI_PlaneDlg::SetEditCurrentArgument()
   else if ( send == GroupFace->PushButton1 )   myEditCurrentArgument = GroupFace->LineEdit1;
 
   myEditCurrentArgument->setFocus();
-  
-  if ( myEditCurrentArgument == GroupPntDir->LineEdit2 )
-    globalSelection( GEOM_LINE );
-  else if ( myEditCurrentArgument == GroupFace->LineEdit1 )
-       globalSelection( GEOM_PLANE );
-  else
-       globalSelection( GEOM_POINT );
-   
+
+  if (myEditCurrentArgument == GroupPntDir->LineEdit2) {
+    globalSelection(); // close local contexts, if any
+    localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
+  }
+  else if (myEditCurrentArgument == GroupFace->LineEdit1) {
+    TColStd_MapOfInteger aMap;
+    aMap.Add( GEOM_PLANE );
+    aMap.Add( GEOM_MARKER );
+    globalSelection( aMap );
+  }
+  else { // 3 Pnts
+    globalSelection(); // close local contexts, if any
+    localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
+  }
+
   SelectionIntoArgument();
 }
 
-
 //=================================================================================
 // function : LineEditReturnPressed()
 // purpose  :
@@ -366,7 +432,6 @@ void BasicGUI_PlaneDlg::LineEditReturnPressed()
   }
 }
 
-
 //=================================================================================
 // function : ActivateThisDialog()
 // purpose  :
@@ -374,12 +439,10 @@ void BasicGUI_PlaneDlg::LineEditReturnPressed()
 void BasicGUI_PlaneDlg::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()));
 
-  // myGeomGUI->SetState( 0 );
-
-  ConstructorsClicked( getConstructorId() );
+  ConstructorsClicked(getConstructorId());
 }
 
 //=================================================================================
@@ -388,7 +451,6 @@ void BasicGUI_PlaneDlg::ActivateThisDialog()
 //=================================================================================
 void BasicGUI_PlaneDlg::DeactivateActiveDialog()
 {
-  // myGeomGUI->SetState( -1 );
   GEOMBase_Skeleton::DeactivateActiveDialog();
 }
 
@@ -508,3 +570,28 @@ void BasicGUI_PlaneDlg::closeEvent( QCloseEvent* e )
   GEOMBase_Skeleton::closeEvent( e );
 }
 
+//=================================================================================
+// function : addSubshapeToStudy
+// purpose  : virtual method to add new SubObjects if local selection
+//=================================================================================
+void BasicGUI_PlaneDlg::addSubshapesToStudy()
+{
+  QMap<QString, GEOM::GEOM_Object_var> objMap;
+
+switch (getConstructorId())
+  {
+  case 0:
+    objMap[GroupPntDir->LineEdit1->text()] = myPoint;
+    objMap[GroupPntDir->LineEdit2->text()] = myDir;
+    break;
+  case 1:
+    objMap[Group3Pnts->LineEdit1->text()] = myPoint1;
+    objMap[Group3Pnts->LineEdit2->text()] = myPoint2;
+    objMap[Group3Pnts->LineEdit3->text()] = myPoint3;
+    break;
+  case 2:
+    objMap[GroupFace->LineEdit1->text()] = myFace;
+    break;
+  }
+ addSubshapesToFather( objMap );
+}