Salome HOME
NPAL18111: Bad shape build by partition.
[modules/geom.git] / src / BasicGUI / BasicGUI_CircleDlg.cxx
index 503489d1bc0504815c56b49736dca749200a946e..fe5ba5a809269273b0554718b6230072ccd9da67 100644 (file)
@@ -17,7 +17,7 @@
 //  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //
 //
 #include "SUIT_Desktop.h"
 #include "SUIT_Session.h"
 #include "SalomeApp_Application.h"
-#include "SalomeApp_SelectionMgr.h"
+#include "LightApp_SelectionMgr.h"
 
+#include <TColStd_IndexedMapOfInteger.hxx>
+#include <TopTools_IndexedMapOfShape.hxx>
 #include <qlabel.h>
 
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TopExp.hxx>
+
+#include <GEOMImpl_ILocalOperations.hxx>
+
 #include "GEOMImpl_Types.hxx"
+#include "GEOM_Object.hxx"
+#include "GEOM_Engine.hxx"
 
 #include "utilities.h"
 
 //            The dialog will by default be modeless, unless you set 'modal' to
 //            TRUE to construct a modal dialog.
 //=================================================================================
-BasicGUI_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* parent, const char* name, bool modal, WFlags fl)
-  :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
-   myGeometryGUI(theGeometryGUI)
+BasicGUI_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
+                                       const char* name, bool modal, WFlags fl)
+  :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
+                     WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
 {
   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PV")));
   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_PNTS")));
+  QPixmap image3(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_CIRCLE_C2P")));
   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
 
   setCaption(tr("GEOM_CIRCLE_TITLE"));
@@ -60,7 +73,7 @@ BasicGUI_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* par
   GroupConstructors->setTitle(tr("GEOM_CIRCLE"));
   RadioButton1->setPixmap(image0);
   RadioButton2->setPixmap(image2);
-  RadioButton3->close(TRUE);
+  RadioButton3->setPixmap(image3);
 
   GroupPntVecR = new DlgRef_2Sel1Spin(this, "GroupPntVecR");
   GroupPntVecR->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
@@ -87,10 +100,26 @@ BasicGUI_CircleDlg::BasicGUI_CircleDlg(GeometryGUI* theGeometryGUI, QWidget* par
   Group3Pnts->LineEdit2->setReadOnly( true );
   Group3Pnts->LineEdit3->setReadOnly( true );
 
+  GroupCenter2Pnts = new DlgRef_3Sel_QTD(this, "GroupCenter2Pnts");
+  GroupCenter2Pnts->GroupBox1->setTitle(tr("GEOM_CENTER_2POINTS"));
+  GroupCenter2Pnts->TextLabel1->setText(tr("GEOM_CENTER_POINT"));
+  GroupCenter2Pnts->TextLabel2->setText(tr("GEOM_POINT1"));
+  GroupCenter2Pnts->TextLabel3->setText(tr("GEOM_POINT2"));
+  GroupCenter2Pnts->PushButton1->setPixmap(image1);
+  GroupCenter2Pnts->PushButton2->setPixmap(image1);
+  GroupCenter2Pnts->PushButton3->setPixmap(image1);
+
+  GroupCenter2Pnts->LineEdit1->setReadOnly( true );
+  GroupCenter2Pnts->LineEdit2->setReadOnly( true );
+  GroupCenter2Pnts->LineEdit3->setReadOnly( true );
+
   Layout1->addWidget( GroupPntVecR, 2, 0 );
   Layout1->addWidget( Group3Pnts, 2, 0 );
+  Layout1->addWidget( GroupCenter2Pnts, 2, 0 );
   /***************************************************************/
 
+  setHelpFileName("circle.htm");
+
   Init();
 }
 
@@ -115,20 +144,20 @@ void BasicGUI_CircleDlg::Init()
 
   myPoint = myDir = myPoint1 = myPoint2 = myPoint3 = GEOM::GEOM_Object::_nil();
 
-  // myGeometryGUI->SetState( 0 );
+  // myGeomGUI->SetState( 0 );
 
   /* Get setting of step value from file configuration */
   SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
   double aStep = resMgr->doubleValue( "Geometry", "SettingsGeomStep", 100);
 
   /* min, max, step and decimals for spin boxes & initial values */
-  GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, 999.999, aStep, 3);
+  GroupPntVecR->SpinBox_DX->RangeStepAndValidator(0.001, COORD_MAX, aStep, DBL_DIGITS_DISPLAY);
   GroupPntVecR->SpinBox_DX->SetValue( 100 );
 
   /* signals and slots connections */
   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
-  connect(myGeometryGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
-  connect(myGeometryGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
+  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()));
@@ -140,11 +169,15 @@ void BasicGUI_CircleDlg::Init()
   connect(Group3Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
   connect(Group3Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
 
+  connect(GroupCenter2Pnts->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+  connect(GroupCenter2Pnts->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+  connect(GroupCenter2Pnts->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
+
   connect(GroupPntVecR->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
   connect(GroupPntVecR->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
 
   connect(GroupPntVecR->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
-  connect(myGeometryGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
+  connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPntVecR->SpinBox_DX, SLOT(SetStep(double)));
   
   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
          SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
@@ -152,6 +185,7 @@ void BasicGUI_CircleDlg::Init()
   initName( tr( "GEOM_CIRCLE" ) );
 
   Group3Pnts->hide();
+  GroupCenter2Pnts->hide();
   ConstructorsClicked( 0 );
 }
 
@@ -169,6 +203,7 @@ void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
     case 0:
       {
        Group3Pnts->hide();
+       GroupCenter2Pnts->hide();
        resize(0, 0);
        GroupPntVecR->show();
        
@@ -180,6 +215,7 @@ void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
   case 1:
     {
       GroupPntVecR->hide();
+      GroupCenter2Pnts->hide();
       resize( 0, 0 );
       Group3Pnts->show();
       
@@ -189,10 +225,25 @@ void BasicGUI_CircleDlg::ConstructorsClicked( int constructorId )
       Group3Pnts->LineEdit3->setText("");
       break;
       }
+   case 2:
+      {
+       GroupPntVecR->hide();
+        Group3Pnts->hide();            
+        resize( 0, 0 );
+        GroupCenter2Pnts->show();
+
+       myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
+       GroupCenter2Pnts->LineEdit1->setText("");
+        GroupCenter2Pnts->LineEdit2->setText("");
+        GroupCenter2Pnts->LineEdit3->setText("");
+        break;
+      }
   }
   
   myEditCurrentArgument->setFocus();
-  globalSelection( GEOM_POINT );
+  //  globalSelection( GEOM_POINT );
+  GEOM::GEOM_Object_var anObj;
+  localSelection( anObj, TopAbs_VERTEX );
   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
          SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
 }
@@ -245,22 +296,47 @@ void BasicGUI_CircleDlg::SelectionIntoArgument()
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = GEOM::GEOM_Object::_nil();
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = GEOM::GEOM_Object::_nil();
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = GEOM::GEOM_Object::_nil();
+    else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4  = GEOM::GEOM_Object::_nil();
+    else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5  = GEOM::GEOM_Object::_nil();
+    else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6  = GEOM::GEOM_Object::_nil();
     return;
   }
 
   // nbSel == 1
   Standard_Boolean aRes = Standard_False;
-  GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
+  Handle(SALOME_InteractiveObject) anIO = firstIObject();
+  GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
-  {  
+  { 
     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
+    // If selected Vertex or Edge on the some Shape Get selection Subshape
+    TopoDS_Shape aShape;
+    if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
+      {
+       LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
+       TColStd_IndexedMapOfInteger aMap;
+       aSelMgr->GetIndexes( anIO, aMap );
+       if ( aMap.Extent() == 1 )
+         {
+           GEOM::GEOM_IShapesOperations_var aShapesOp =
+             getGeomEngine()->GetIShapesOperations( getStudyId() );
+           int anIndex = aMap( 1 );
+           TopTools_IndexedMapOfShape aShapes;
+           TopExp::MapShapes( aShape, aShapes );
+           aShape = aShapes.FindKey( anIndex );
+           aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
+           aSelMgr->clearSelected();
+         }
+      }
     if      ( myEditCurrentArgument == GroupPntVecR->LineEdit1 ) myPoint  = aSelectedObject;
-    else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir    = aSelectedObject;
+    else if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) myDir = aSelectedObject;
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit1 )   myPoint1 = aSelectedObject;
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit2 )   myPoint2 = aSelectedObject;
     else if ( myEditCurrentArgument == Group3Pnts->LineEdit3 )   myPoint3 = aSelectedObject;
+    else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit1 ) myPoint4 = aSelectedObject;
+    else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit2 ) myPoint5 = aSelectedObject;
+    else if ( myEditCurrentArgument == GroupCenter2Pnts->LineEdit3 ) myPoint6 = aSelectedObject;
   }
-
   displayPreview();
 }
 
@@ -278,13 +354,21 @@ void BasicGUI_CircleDlg::SetEditCurrentArgument()
   else if ( send == Group3Pnts->PushButton1 )   myEditCurrentArgument = Group3Pnts->LineEdit1;
   else if ( send == Group3Pnts->PushButton2 )   myEditCurrentArgument = Group3Pnts->LineEdit2;
   else if ( send == Group3Pnts->PushButton3 )   myEditCurrentArgument = Group3Pnts->LineEdit3;
+  else if ( send == GroupCenter2Pnts->PushButton1 )   myEditCurrentArgument = GroupCenter2Pnts->LineEdit1;
+  else if ( send == GroupCenter2Pnts->PushButton2 )   myEditCurrentArgument = GroupCenter2Pnts->LineEdit2;
+  else if ( send == GroupCenter2Pnts->PushButton3 )   myEditCurrentArgument = GroupCenter2Pnts->LineEdit3;
   
   myEditCurrentArgument->setFocus();
   
-  if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 ) 
-    globalSelection( GEOM_LINE );
-  else
-    globalSelection( GEOM_POINT );
+  if ( myEditCurrentArgument == GroupPntVecR->LineEdit2 )
+    {
+      GEOM::GEOM_Object_var anObj;
+      localSelection( anObj, TopAbs_EDGE );
+    }
+  else {
+    GEOM::GEOM_Object_var anObj;
+    localSelection( anObj, TopAbs_EDGE );
+  }
   SelectionIntoArgument();
 }
 
@@ -299,7 +383,10 @@ void BasicGUI_CircleDlg::LineEditReturnPressed()
        send == GroupPntVecR->LineEdit2 ||
        send == Group3Pnts->LineEdit1 ||
        send == Group3Pnts->LineEdit2 ||
-       send == Group3Pnts->LineEdit3 )
+       send == Group3Pnts->LineEdit3 ||
+       send == GroupCenter2Pnts->LineEdit1 ||
+       send == GroupCenter2Pnts->LineEdit2 ||
+       send == GroupCenter2Pnts->LineEdit3 )
   {
     myEditCurrentArgument = send;
     GEOMBase_Skeleton::LineEditReturnPressed();
@@ -318,7 +405,7 @@ void BasicGUI_CircleDlg::ActivateThisDialog()
   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
          SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
 
-  // myGeometryGUI->SetState( 0 );
+  // myGeomGUI->SetState( 0 );
 
   ConstructorsClicked( getConstructorId() );
 }
@@ -340,7 +427,7 @@ void BasicGUI_CircleDlg::enterEvent(QEvent* e)
 //=================================================================================
 void BasicGUI_CircleDlg::DeactivateActiveDialog()
 {
-  // myGeometryGUI->SetState( -1 );
+  // myGeomGUI->SetState( -1 );
   GEOMBase_Skeleton::DeactivateActiveDialog();
 }
 
@@ -359,7 +446,11 @@ void BasicGUI_CircleDlg::ValueChangedInSpinBox()
 //=================================================================================
 double BasicGUI_CircleDlg::getRadius() const
 {
-  return GroupPntVecR->SpinBox_DX->GetValue();
+  switch ( getConstructorId() )
+    {
+    case 0 :
+      return GroupPntVecR->SpinBox_DX->GetValue();
+    }
 }
 
 //=================================================================================
@@ -368,7 +459,7 @@ double BasicGUI_CircleDlg::getRadius() const
 //=================================================================================
 GEOM::GEOM_IOperations_ptr BasicGUI_CircleDlg::createOperation()
 {
-  return myGeometryGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
+  return myGeomGUI->GetGeomGen()->GetICurvesOperations( getStudyId() );
 }
 
 //=================================================================================
@@ -392,6 +483,9 @@ bool BasicGUI_CircleDlg::isValid( QString& msg )
   else if ( id == 1 )
     return !myPoint1->_is_nil() && !myPoint2->_is_nil() && !myPoint3->_is_nil() &&
       !isEqual( myPoint1, myPoint2 ) && !isEqual( myPoint1, myPoint3 ) && !isEqual( myPoint2, myPoint3 );
+  else if ( id == 2 )
+      return !myPoint4->_is_nil() && !myPoint5->_is_nil() && !myPoint6->_is_nil() &&
+      !isEqual( myPoint4, myPoint5 ) && !isEqual( myPoint5, myPoint6 ) && !isEqual( myPoint4, myPoint6 );
   return false;
 }
 
@@ -407,6 +501,7 @@ bool BasicGUI_CircleDlg::execute( ObjectList& objects )
   
   switch ( getConstructorId() )
   {
+    cout << "constructior ID = " << getConstructorId() << endl;
   case 0 :
     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCirclePntVecR( myPoint, myDir, getRadius() );
     res = true;
@@ -415,10 +510,15 @@ bool BasicGUI_CircleDlg::execute( ObjectList& objects )
     anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleThreePnt( myPoint1, myPoint2, myPoint3 );
     res = true;
     break;
+  case 2 :
+    anObj = GEOM::GEOM_ICurvesOperations::_narrow( getOperation() )->MakeCircleCenter2Pnt( myPoint4, myPoint5, myPoint6 );
+    res = true;
+    break;
   }
   
   if ( !anObj->_is_nil() )
     objects.push_back( anObj._retn() );
+  else cout << "Execute Object is NULL!" << endl;
   
   return res;
 }
@@ -429,7 +529,6 @@ bool BasicGUI_CircleDlg::execute( ObjectList& objects )
 //=================================================================================
 void BasicGUI_CircleDlg::closeEvent( QCloseEvent* e )
 {
-  // myGeometryGUI->SetState( -1 );
   GEOMBase_Skeleton::closeEvent( e );
 }