From: jfa Date: Mon, 29 Sep 2008 13:36:48 +0000 (+0000) Subject: Bugs 16640, 19050: Improve selection mechanism in GEOM dialog boxes. X-Git-Tag: V5_1_0a2~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b77eef91b668848973deb46b6bf68c2d684313f0;p=modules%2Fgeom.git Bugs 16640, 19050: Improve selection mechanism in GEOM dialog boxes. --- diff --git a/src/MeasureGUI/MeasureGUI_AngleDlg.cxx b/src/MeasureGUI/MeasureGUI_AngleDlg.cxx index 31f5a69e6..191e9f153 100644 --- a/src/MeasureGUI/MeasureGUI_AngleDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_AngleDlg.cxx @@ -26,20 +26,19 @@ #include "MeasureGUI_AngleDlg.h" #include "MeasureGUI_Widgets.h" -#include #include - +#include #include -#include #include +#include #include -#include #include #include #include #include #include +#include #include #include @@ -79,33 +78,34 @@ // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -MeasureGUI_AngleDlg::MeasureGUI_AngleDlg( GeometryGUI* GUI, QWidget* parent ) - : MeasureGUI_Skeleton( GUI, parent ) +MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent) + : MeasureGUI_Skeleton(GUI, parent) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ANGLE" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); - - setWindowTitle( tr( "GEOM_MEASURE_ANGLE_TITLE" ) ); - - // Widgets - - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MEASURE_ANGLE_ANGLE" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - - myGrp = new MeasureGUI_2Sel1LineEdit( centralWidget() ); - myGrp->GroupBox1->setTitle( tr( "GEOM_MEASURE_ANGLE_OBJ" ) ); - myGrp->TextLabel1->setText( tr( "GEOM_OBJECT_I" ).arg( "1" ) ); - myGrp->TextLabel2->setText( tr( "GEOM_OBJECT_I" ).arg( "2" ) ); - myGrp->TextLabel3->setText( tr( "GEOM_MEASURE_ANGLE_IS" ) ); - myGrp->LineEdit3->setReadOnly( true ); - myGrp->PushButton1->setIcon( image1 ); - myGrp->PushButton2->setIcon( image1 ); - myGrp->LineEdit1->setReadOnly( true ); - myGrp->LineEdit2->setReadOnly( true ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( myGrp ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ANGLE"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_MEASURE_ANGLE_TITLE")); + + /***************************************************************/ + mainFrame()->GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE")); + mainFrame()->RadioButton1->setIcon(image0); + + myGrp = new MeasureGUI_2Sel1LineEdit(centralWidget()); + myGrp->GroupBox1->setTitle(tr("GEOM_MEASURE_ANGLE_OBJ")); + myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1")); + myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2")); + myGrp->TextLabel3->setText(tr("GEOM_MEASURE_ANGLE_IS")); + myGrp->LineEdit3->setReadOnly(true); + myGrp->PushButton1->setIcon(image1); + myGrp->PushButton2->setIcon(image1); + myGrp->LineEdit1->setReadOnly(true); + myGrp->LineEdit2->setReadOnly(true); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(myGrp); + /***************************************************************/ // Help page reference myHelpFileName = "using_measurement_tools_page.html#angle_anchor"; @@ -128,6 +128,11 @@ MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg() //================================================================================= void MeasureGUI_AngleDlg::Init() { + // init variables + myGrp->LineEdit1->setText(""); + myGrp->LineEdit2->setText(""); + myObj = myObj2 = GEOM::GEOM_Object::_nil(); + mySelBtn = myGrp->PushButton1; mySelEdit = myGrp->LineEdit1; mySelBtn2 = myGrp->PushButton2; @@ -135,14 +140,14 @@ void MeasureGUI_AngleDlg::Init() myEditCurrentArgument = mySelEdit; - connect( mySelEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + // signals and slots connections + connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - globalSelection( GEOM_LINE ); + globalSelection(GEOM_LINE); MeasureGUI_Skeleton::Init(); } - //================================================================================= // function : SelectionIntoArgument() // purpose : Called when selection has changed @@ -162,10 +167,22 @@ void MeasureGUI_AngleDlg::SelectionIntoArgument() aSelectedObject = GEOM::GEOM_Object::_nil(); } - if (myEditCurrentArgument == mySelEdit) + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == mySelEdit) { myObj = aSelectedObject; - else + if (!myObj->_is_nil() && myObj2->_is_nil()) + myGrp->PushButton2->click(); + } + else { myObj2 = aSelectedObject; + if (!myObj2->_is_nil() && myObj->_is_nil()) + myGrp->PushButton1->click(); + } processObject(); } @@ -176,16 +193,16 @@ void MeasureGUI_AngleDlg::SelectionIntoArgument() //================================================================================= void MeasureGUI_AngleDlg::processObject() { - myGrp->LineEdit1->setText( !myObj->_is_nil() ? GEOMBase::GetName( myObj ) : "" ); - myGrp->LineEdit2->setText( !myObj2->_is_nil() ? GEOMBase::GetName( myObj2 ) : "" ); + myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : ""); + myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : ""); double anAngle = 0.; - if ( getParameters( anAngle ) ) { - myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( anAngle ) ); + if (getParameters(anAngle)) { + myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle)); redisplayPreview(); } else { - myGrp->LineEdit3->setText( "" ); + myGrp->LineEdit3->setText(""); erasePreview(); } } @@ -194,24 +211,24 @@ void MeasureGUI_AngleDlg::processObject() // function : getParameters() // purpose : Get angle between objects //================================================================================= -bool MeasureGUI_AngleDlg::getParameters( double& theAngle ) +bool MeasureGUI_AngleDlg::getParameters (double& theAngle) { QString msg; - if ( isValid( msg ) ) { + if (isValid(msg)) { try { - theAngle = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetAngle( myObj, myObj2 ); + theAngle = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetAngle(myObj, myObj2); } - catch( const SALOME::SALOME_Exception& e ) { - SalomeApp_Tools::QtCatchCorbaException( e ); + catch(const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); return false; } - + bool isDone = getOperation()->IsDone(); - if ( !isDone ) { + if (!isDone) { CORBA::String_var aMsg = getOperation()->GetErrorCode(); - SUIT_MessageBox::warning( this, - QObject::tr( "WRN_WARNING" ), - QObject::tr( aMsg.in() ) ); + SUIT_MessageBox::warning(this, + QObject::tr("WRN_WARNING"), + QObject::tr(aMsg.in())); } return isDone; } @@ -227,17 +244,32 @@ void MeasureGUI_AngleDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - if ( send == mySelBtn ) { - mySelEdit->setFocus(); - myEditCurrentArgument = mySelEdit; + if (send == myGrp->PushButton1) { + myEditCurrentArgument = myGrp->LineEdit1; + + myGrp->PushButton2->setDown(false); + myGrp->LineEdit2->setEnabled(false); } else { - mySelEdit2->setFocus(); - myEditCurrentArgument = mySelEdit2; + myEditCurrentArgument = myGrp->LineEdit2; + + myGrp->PushButton1->setDown(false); + myGrp->LineEdit1->setEnabled(false); } - globalSelection( GEOM_LINE ); - SelectionIntoArgument(); + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + globalSelection(GEOM_LINE); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + // enable line edit + myEditCurrentArgument->setEnabled(true); + myEditCurrentArgument->setFocus(); + // after setFocus(), because it will be setDown(false) when loses focus + send->setDown(true); + + // seems we need it only to avoid preview disappearing, caused by selection mode change + redisplayPreview(); } //================================================================================= @@ -271,31 +303,31 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); - if ( myObj->_is_nil() || myObj2->_is_nil() || !getParameters( anAngle ) || - vw->getViewManager()->getType() != OCCViewer_Viewer::Type() ) + if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) || + vw->getViewManager()->getType() != OCCViewer_Viewer::Type()) return 0; - - if ( anAngle > Precision::Angular() ) { + + if (anAngle > Precision::Angular()) { try { #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 OCC_CATCH_SIGNALS; #endif TopoDS_Shape S1, S2; - if ( GEOMBase::GetShape( myObj , S1, TopAbs_EDGE ) && - GEOMBase::GetShape( myObj2, S2, TopAbs_EDGE ) ) { - TopoDS_Edge anEdge1 = TopoDS::Edge( S1 ); - TopoDS_Edge anEdge2 = TopoDS::Edge( S2 ); - + if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) && + GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE)) { + TopoDS_Edge anEdge1 = TopoDS::Edge(S1); + TopoDS_Edge anEdge2 = TopoDS::Edge(S2); + // Build a plane for angle dimension presentation {P11, P12, P3} TopoDS_Vertex V11, V12, V21, V22; - TopExp::Vertices( anEdge1, V11, V12 ); - TopExp::Vertices( anEdge2, V21, V22 ); - - gp_Pnt aP11 = BRep_Tool::Pnt( TopExp::FirstVertex( anEdge1 ) ); - gp_Pnt aP12 = BRep_Tool::Pnt( TopExp::LastVertex ( anEdge1 ) ); + TopExp::Vertices(anEdge1, V11, V12); + TopExp::Vertices(anEdge2, V21, V22); + + gp_Pnt aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1)); + gp_Pnt aP12 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge1)); - gp_Pnt aP21 = BRep_Tool::Pnt( TopExp::FirstVertex( anEdge2 ) ); - gp_Pnt aP22 = BRep_Tool::Pnt( TopExp::LastVertex ( anEdge2 ) ); + gp_Pnt aP21 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge2)); + gp_Pnt aP22 = BRep_Tool::Pnt(TopExp::LastVertex (anEdge2)); // *P3 // \ @@ -308,54 +340,54 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() // \ / // \ / // *P21 - gp_Pnt aP3 ( aP22.XYZ() + aP11.XYZ() - aP21.XYZ() ); + gp_Pnt aP3 (aP22.XYZ() + aP11.XYZ() - aP21.XYZ()); - gce_MakePln gce_MP( aP11, aP12, aP3 ); - Handle(Geom_Plane) aPlane = new Geom_Plane( gce_MP.Value() ); + gce_MakePln gce_MP(aP11, aP12, aP3); + Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value()); // Build the angle dimension presentation QString aLabel; - aLabel.sprintf( "%.1f", anAngle ); + aLabel.sprintf("%.1f", anAngle); Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension - ( anEdge1, anEdge2, aPlane, anAngle * PI180, - TCollection_ExtendedString( (Standard_CString)aLabel.toLatin1().data() ) ); - Handle(Geom_Line) geom_lin1,geom_lin2; - gp_Pnt ptat11,ptat12,ptat21,ptat22; - Standard_Boolean isInfinite1,isInfinite2; - Handle(Geom_Curve) extCurv; - Standard_Integer extShape; - if ( AIS::ComputeGeometry(anEdge1, - anEdge2, - extShape, - geom_lin1, - geom_lin2, - ptat11, - ptat12, - ptat21, - ptat22, - extCurv, - isInfinite1, - isInfinite2, - aPlane)) { - Standard_Real arrSize1 = anIO->ArrowSize(); - Standard_Real arrSize2 = anIO->ArrowSize(); - if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.; - if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.; - Standard_Real arrowSize = Max(arrSize1,arrSize2); - anIO->SetArrowSize(arrowSize); - } + (anEdge1, anEdge2, aPlane, anAngle * PI180, + TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().data())); + Handle(Geom_Line) geom_lin1,geom_lin2; + gp_Pnt ptat11,ptat12,ptat21,ptat22; + Standard_Boolean isInfinite1,isInfinite2; + Handle(Geom_Curve) extCurv; + Standard_Integer extShape; + if (AIS::ComputeGeometry(anEdge1, + anEdge2, + extShape, + geom_lin1, + geom_lin2, + ptat11, + ptat12, + ptat21, + ptat22, + extCurv, + isInfinite1, + isInfinite2, + aPlane)) { + Standard_Real arrSize1 = anIO->ArrowSize(); + Standard_Real arrSize2 = anIO->ArrowSize(); + if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.; + if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.; + Standard_Real arrowSize = Max(arrSize1,arrSize2); + anIO->SetArrowSize(arrowSize); + } SOCC_Prs* aPrs = - dynamic_cast( ( (SOCC_Viewer*)( vw->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) ); + dynamic_cast(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0)); - if ( aPrs ) - aPrs->AddObject( anIO ); + if (aPrs) + aPrs->AddObject(anIO); return aPrs; } } - catch( Standard_Failure ) { + catch(Standard_Failure) { } } @@ -366,7 +398,7 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs() // function : isValid() // purpose : //================================================================================= -bool MeasureGUI_AngleDlg::isValid( QString& msg ) +bool MeasureGUI_AngleDlg::isValid (QString& msg) { - return MeasureGUI_Skeleton::isValid( msg ) && !myObj2->_is_nil(); + return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil(); } diff --git a/src/MeasureGUI/MeasureGUI_DistanceDlg.cxx b/src/MeasureGUI/MeasureGUI_DistanceDlg.cxx index f5423056d..04958ede0 100644 --- a/src/MeasureGUI/MeasureGUI_DistanceDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_DistanceDlg.cxx @@ -26,9 +26,8 @@ #include "MeasureGUI_DistanceDlg.h" #include "MeasureGUI_Widgets.h" -#include #include - +#include #include #include @@ -42,6 +41,7 @@ #include #include +// OCCT Includes #include #include #include @@ -56,51 +56,47 @@ // The dialog will by default be modeless, unless you set 'modal' to // true to construct a modal dialog. //================================================================================= -MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg( GeometryGUI* GUI, QWidget* parent ) - : MeasureGUI_Skeleton( GUI, parent ) +MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg (GeometryGUI* GUI, QWidget* parent) + : MeasureGUI_Skeleton(GUI, parent) { - QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( - "GEOM", tr( "ICON_DLG_MINDIST" ) ) ); - QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( - "GEOM", tr( "ICON_SELECT" ) ) ); + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MINDIST"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle( tr( "GEOM_MINDIST_TITLE" ) ); + setWindowTitle(tr("GEOM_MINDIST_TITLE")); /***************************************************************/ - - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_DISTANCE" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - - myGrp = new MeasureGUI_2Sel4LineEdit( centralWidget() ); - myGrp->GroupBox1->setTitle( tr( "GEOM_MINDIST_OBJ" ) ); - myGrp->TextLabel1->setText( tr( "GEOM_OBJECT_I" ).arg( "1" ) ); - myGrp->TextLabel2->setText( tr( "GEOM_OBJECT_I" ).arg( "2" ) ); - myGrp->TextLabel3->setText( tr( "GEOM_LENGTH" ) ); - myGrp->TextLabel4->setText( tr( "GEOM_DX" ) ); - myGrp->TextLabel5->setText( tr( "GEOM_DY" ) ); - myGrp->TextLabel6->setText( tr( "GEOM_DZ" ) ); - myGrp->LineEdit3->setReadOnly( true ); - myGrp->PushButton1->setIcon( image1 ); - myGrp->PushButton2->setIcon( image1 ); - myGrp->LineEdit1->setReadOnly( true ); - myGrp->LineEdit2->setReadOnly( true ); - myGrp->LineEdit4->setReadOnly( true ); - myGrp->LineEdit5->setReadOnly( true ); - myGrp->LineEdit6->setReadOnly( true ); - - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( myGrp ); - + mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISTANCE")); + mainFrame()->RadioButton1->setIcon(image0); + + myGrp = new MeasureGUI_2Sel4LineEdit(centralWidget()); + myGrp->GroupBox1->setTitle(tr("GEOM_MINDIST_OBJ")); + myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1")); + myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2")); + myGrp->TextLabel3->setText(tr("GEOM_LENGTH")); + myGrp->TextLabel4->setText(tr("GEOM_DX")); + myGrp->TextLabel5->setText(tr("GEOM_DY")); + myGrp->TextLabel6->setText(tr("GEOM_DZ")); + myGrp->LineEdit3->setReadOnly(true); + myGrp->PushButton1->setIcon(image1); + myGrp->PushButton2->setIcon(image1); + myGrp->LineEdit1->setReadOnly(true); + myGrp->LineEdit2->setReadOnly(true); + myGrp->LineEdit4->setReadOnly(true); + myGrp->LineEdit5->setReadOnly(true); + myGrp->LineEdit6->setReadOnly(true); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(myGrp); /***************************************************************/ myHelpFileName = "using_measurement_tools_page.html#min_distance_anchor"; - /* Initialisation */ + // Initialisation Init(); } - //================================================================================= // function : ~MeasureGUI_DistanceDlg() // purpose : Destroys the object and frees any allocated resources @@ -109,27 +105,29 @@ MeasureGUI_DistanceDlg::~MeasureGUI_DistanceDlg() { } - //================================================================================= // function : Init() // purpose : //================================================================================= void MeasureGUI_DistanceDlg::Init() { + // init variables + myGrp->LineEdit1->setText(""); + myGrp->LineEdit2->setText(""); + myObj = myObj2 = GEOM::GEOM_Object::_nil(); + mySelBtn = myGrp->PushButton1; mySelEdit = myGrp->LineEdit1; - mySelBtn2 = myGrp->PushButton2; - mySelEdit2 = myGrp->LineEdit2; - - myEditCurrentArgument = mySelEdit; - connect( mySelEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + myEditCurrentArgument = myGrp->LineEdit1; + + // signals and slots connections + connect(myGrp->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(myGrp->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); MeasureGUI_Skeleton::Init(); } - //================================================================================= // function : SelectionIntoArgument() // purpose : Called when selection has changed @@ -149,10 +147,22 @@ void MeasureGUI_DistanceDlg::SelectionIntoArgument() aSelectedObject = GEOM::GEOM_Object::_nil(); } - if ( myEditCurrentArgument == mySelEdit ) + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (myEditCurrentArgument == myGrp->LineEdit1) { myObj = aSelectedObject; - else + if (!myObj->_is_nil() && myObj2->_is_nil()) + myGrp->PushButton2->click(); + } + else { myObj2 = aSelectedObject; + if (!myObj2->_is_nil() && myObj->_is_nil()) + myGrp->PushButton1->click(); + } processObject(); } @@ -163,26 +173,26 @@ void MeasureGUI_DistanceDlg::SelectionIntoArgument() //================================================================================= void MeasureGUI_DistanceDlg::processObject() { - myGrp->LineEdit1->setText( !myObj->_is_nil() ? GEOMBase::GetName( myObj ) : "" ); - myGrp->LineEdit2->setText( !myObj2->_is_nil() ? GEOMBase::GetName( myObj2 ) : "" ); + myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : ""); + myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : ""); gp_Pnt aPnt1, aPnt2; double aDist = 0.; - if ( getParameters( aDist, aPnt1, aPnt2 ) ) { - myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( aDist ) ); + if (getParameters(aDist, aPnt1, aPnt2)) { + myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(aDist)); gp_XYZ aVec = aPnt2.XYZ() - aPnt1.XYZ(); - myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aVec.X() ) ); - myGrp->LineEdit5->setText( DlgRef::PrintDoubleValue( aVec.Y() ) ); - myGrp->LineEdit6->setText( DlgRef::PrintDoubleValue( aVec.Z() ) ); + myGrp->LineEdit4->setText(DlgRef::PrintDoubleValue(aVec.X())); + myGrp->LineEdit5->setText(DlgRef::PrintDoubleValue(aVec.Y())); + myGrp->LineEdit6->setText(DlgRef::PrintDoubleValue(aVec.Z())); redisplayPreview(); } else { - myGrp->LineEdit3->setText( "" ); - myGrp->LineEdit4->setText( "" ); - myGrp->LineEdit5->setText( "" ); - myGrp->LineEdit6->setText( "" ); + myGrp->LineEdit3->setText(""); + myGrp->LineEdit4->setText(""); + myGrp->LineEdit5->setText(""); + myGrp->LineEdit6->setText(""); erasePreview(); } } @@ -191,31 +201,30 @@ void MeasureGUI_DistanceDlg::processObject() // function : getParameters() // purpose : Get distance between objects //================================================================================= -bool MeasureGUI_DistanceDlg::getParameters( double& theDistance, +bool MeasureGUI_DistanceDlg::getParameters (double& theDistance, gp_Pnt& thePnt1, - gp_Pnt& thePnt2 ) + gp_Pnt& thePnt2) { QString msg; - if ( !isValid( msg ) ) - return false; - else { + if (isValid(msg)) { try { double x1, y1, z1, x2, y2, z2; - theDistance = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetMinDistance( - myObj, myObj2, x1, y1, z1, x2, y2, z2 ); + theDistance = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())-> + GetMinDistance(myObj, myObj2, x1, y1, z1, x2, y2, z2); - thePnt1.SetCoord( x1, y1, z1 ); - thePnt2.SetCoord( x2, y2, z2 ); + thePnt1.SetCoord(x1, y1, z1); + thePnt2.SetCoord(x2, y2, z2); } - catch( const SALOME::SALOME_Exception& e ) { - SalomeApp_Tools::QtCatchCorbaException( e ); + catch(const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); return false; } return getOperation()->IsDone(); } -} + return false; +} //================================================================================= // function : SetEditCurrentArgument() @@ -223,20 +232,30 @@ bool MeasureGUI_DistanceDlg::getParameters( double& theDistance, //================================================================================= void MeasureGUI_DistanceDlg::SetEditCurrentArgument() { - QPushButton* send = ( QPushButton* )sender(); + QPushButton* send = (QPushButton*)sender(); - if ( send == mySelBtn ) { - mySelEdit->setFocus(); - myEditCurrentArgument = mySelEdit; + if (send == myGrp->PushButton1) { + myEditCurrentArgument = myGrp->LineEdit1; + + myGrp->PushButton2->setDown(false); + myGrp->LineEdit2->setEnabled(false); } else { - mySelEdit2->setFocus(); - myEditCurrentArgument = mySelEdit2; + myEditCurrentArgument = myGrp->LineEdit2; + + myGrp->PushButton1->setDown(false); + myGrp->LineEdit1->setEnabled(false); } - SelectionIntoArgument(); -} + // enable line edit + myEditCurrentArgument->setEnabled(true); + myEditCurrentArgument->setFocus(); + // after setFocus(), because it will be setDown(false) when loses focus + send->setDown(true); + // seems we need it only to avoid preview disappearing, caused by selection mode change + redisplayPreview(); +} //================================================================================= // function : LineEditReturnPressed() @@ -244,22 +263,20 @@ void MeasureGUI_DistanceDlg::SetEditCurrentArgument() //================================================================================= void MeasureGUI_DistanceDlg::LineEditReturnPressed() { - QLineEdit* send = ( QLineEdit* )sender(); + QLineEdit* send = (QLineEdit*)sender(); - if ( send == mySelEdit ) - myEditCurrentArgument = mySelEdit; - else - myEditCurrentArgument = mySelEdit2; + if (send == myGrp->LineEdit1 || send == myGrp->LineEdit2) { + myEditCurrentArgument = send; - LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); - SALOME_ListIO aSelList; - aSelMgr->selectedObjects(aSelList); + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); - if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), aSelList)) - mySelEdit->setText(mySelEdit->text()); + if (GEOMBase::SelectionByNameInDialogs(this, myGrp->LineEdit1->text(), aSelList)) + myGrp->LineEdit1->setText(myGrp->LineEdit1->text()); + } } - //================================================================================= // function : buildPrs() // purpose : @@ -267,58 +284,57 @@ void MeasureGUI_DistanceDlg::LineEditReturnPressed() SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs() { double aDist = 0.; - gp_Pnt aPnt1( 0, 0, 0 ), aPnt2( 0, 0, 0 ); - + gp_Pnt aPnt1(0, 0, 0), aPnt2(0, 0, 0); SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow(); - if ( myObj->_is_nil() || myObj2->_is_nil() || - !getParameters( aDist, aPnt1, aPnt2 ) || - vw->getViewManager()->getType() != OCCViewer_Viewer::Type() ) + if (myObj->_is_nil() || myObj2->_is_nil() || + !getParameters(aDist, aPnt1, aPnt2) || + vw->getViewManager()->getType() != OCCViewer_Viewer::Type()) return 0; - + try { - if ( aDist <= 1.e-9 ) { - BRepBuilderAPI_MakeVertex aMaker( aPnt1 ); - return getDisplayer()->BuildPrs( aMaker.Vertex() ); + if (aDist <= 1.e-9) { + BRepBuilderAPI_MakeVertex aMaker(aPnt1); + return getDisplayer()->BuildPrs(aMaker.Vertex()); } else { - BRepBuilderAPI_MakeEdge MakeEdge( aPnt1, aPnt2 ); - TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex( aPnt1 ); - TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex( aPnt2 ); + BRepBuilderAPI_MakeEdge MakeEdge(aPnt1, aPnt2); + TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(aPnt1); + TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(aPnt2); QString aLabel; - aLabel.sprintf( "%.1f", aDist ); + aLabel.sprintf("%.1f", aDist); - gp_Pnt aPnt3( ( aPnt1.X() + aPnt2.X() ) / 2, - ( aPnt1.Y() + aPnt2.Y() ) / 2, - ( aPnt1.Z() + aPnt2.Z() ) / 2 + 100 ); + gp_Pnt aPnt3((aPnt1.X() + aPnt2.X()) / 2, + (aPnt1.Y() + aPnt2.Y()) / 2, + (aPnt1.Z() + aPnt2.Z()) / 2 + 100); - gp_Vec va( aPnt3, aPnt1 ); - gp_Vec vb( aPnt3, aPnt2 ); + gp_Vec va(aPnt3, aPnt1); + gp_Vec vb(aPnt3, aPnt2); - if ( va.IsParallel( vb, Precision::Angular() ) ) { - aPnt3.SetY( ( aPnt1.Y() + aPnt2.Y() ) / 2 + 100 ); - aPnt3.SetZ( ( aPnt1.Z() + aPnt2.Z() ) / 2 ); + if (va.IsParallel(vb, Precision::Angular())) { + aPnt3.SetY((aPnt1.Y() + aPnt2.Y()) / 2 + 100); + aPnt3.SetZ((aPnt1.Z() + aPnt2.Z()) / 2); } - - gce_MakePln gce_MP( aPnt1, aPnt2, aPnt3 ); - Handle( Geom_Plane ) P = new Geom_Plane( gce_MP.Value() ); - Handle( AIS_LengthDimension ) anIO = new AIS_LengthDimension( - aVert1, aVert2, P, aDist, TCollection_ExtendedString( (Standard_CString)aLabel.toLatin1().constData() ) ); - anIO->SetArrowSize( aDist/20 ); + gce_MakePln gce_MP(aPnt1, aPnt2, aPnt3); + Handle(Geom_Plane) P = new Geom_Plane(gce_MP.Value()); + + Handle(AIS_LengthDimension) anIO = new AIS_LengthDimension( + aVert1, aVert2, P, aDist, TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().constData())); + anIO->SetArrowSize(aDist/20); - SOCC_Prs* aPrs = dynamic_cast( ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs( 0 ) ); + SOCC_Prs* aPrs = dynamic_cast(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0)); - if ( aPrs ) - aPrs->AddObject( anIO ); + if (aPrs) + aPrs->AddObject(anIO); return aPrs; } } - catch( Standard_Failure ) { + catch(Standard_Failure) { return 0; } } @@ -327,7 +343,7 @@ SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs() // function : isValid() // purpose : //================================================================================= -bool MeasureGUI_DistanceDlg::isValid( QString& msg ) +bool MeasureGUI_DistanceDlg::isValid (QString& msg) { - return MeasureGUI_Skeleton::isValid( msg ) && !myObj2->_is_nil(); + return MeasureGUI_Skeleton::isValid(msg) && !myObj2->_is_nil(); } diff --git a/src/MeasureGUI/MeasureGUI_NormaleDlg.cxx b/src/MeasureGUI/MeasureGUI_NormaleDlg.cxx index 071661fce..033beb9bd 100644 --- a/src/MeasureGUI/MeasureGUI_NormaleDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_NormaleDlg.cxx @@ -34,14 +34,15 @@ #include #include -#include - +// OCCT Includes #include #include #include #include #include +#include + //================================================================================= // class : MeasureGUI_NormaleDlg() // purpose : Constructs a MeasureGUI_NormaleDlg which is a child of 'parent', with the @@ -49,36 +50,35 @@ // The dialog will by default be modeless, unless you set 'modal' to // TRUE to construct a modal dialog. //================================================================================= -MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent ) - : GEOMBase_Skeleton( theGeometryGUI, parent, false ) +MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent) + : GEOMBase_Skeleton(theGeometryGUI, parent, false) { SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_NORMALE" ) ) ); - QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); + QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE"))); + QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT"))); - setWindowTitle( tr( "GEOM_NORMALE_TITLE" ) ); + setWindowTitle(tr("GEOM_NORMALE_TITLE")); /***************************************************************/ - mainFrame()->GroupConstructors->setTitle( tr( "GEOM_NORMALE" ) ); - mainFrame()->RadioButton1->setIcon( image0 ); - mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->GroupConstructors->setTitle(tr("GEOM_NORMALE")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton2->close(); - mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); mainFrame()->RadioButton3->close(); - GroupArgs = new DlgRef_2Sel ( centralWidget() ); - GroupArgs->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); - - GroupArgs->TextLabel1->setText( tr( "GEOM_FACE" ) ); - GroupArgs->TextLabel2->setText( tr( "GEOM_POINT" ) ); + GroupArgs = new DlgRef_2Sel (centralWidget()); + GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); - GroupArgs->PushButton1->setIcon( image1 ); - GroupArgs->PushButton2->setIcon( image1 ); + GroupArgs->TextLabel1->setText(tr("GEOM_FACE")); + GroupArgs->TextLabel2->setText(tr("GEOM_POINT")); - QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); - layout->setMargin( 0 ); layout->setSpacing( 6 ); - layout->addWidget( GroupArgs ); + GroupArgs->PushButton1->setIcon(image1); + GroupArgs->PushButton2->setIcon(image1); + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupArgs); /***************************************************************/ setHelpFileName("using_measurement_tools_page.html#normale_anchor"); @@ -100,32 +100,27 @@ MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg() //================================================================================= void MeasureGUI_NormaleDlg::Init() { - /* init variables */ - GroupArgs->LineEdit1->setReadOnly( true ); - GroupArgs->LineEdit2->setReadOnly( true ); - - myFace = GEOM::GEOM_Object::_nil(); - myPoint = GEOM::GEOM_Object::_nil(); + // init variables + GroupArgs->LineEdit1->setReadOnly(true); + GroupArgs->LineEdit2->setReadOnly(true); - myEditCurrentArgument = GroupArgs->LineEdit1; - globalSelection( GEOM_FACE ); // to close previous local selection - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE ); + GroupArgs->LineEdit1->setText(""); + GroupArgs->LineEdit2->setText(""); + myFace = myPoint = GEOM::GEOM_Object::_nil(); - /* signals and slots connections */ - connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); - connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + // signals and slots connections + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); - connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); - connect( GroupArgs->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); - connect( GroupArgs->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - connect( GroupArgs->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); - - connect( myGeomGUI->getApp()->selectionMgr(), - SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); initName(tr("GEOM_VECTOR_NORMALE")); + GroupArgs->PushButton1->click(); SelectionIntoArgument(); } @@ -135,7 +130,7 @@ void MeasureGUI_NormaleDlg::Init() //================================================================================= void MeasureGUI_NormaleDlg::ClickOnOk() { - if ( ClickOnApply() ) + if (ClickOnApply()) ClickOnCancel(); } @@ -145,29 +140,31 @@ void MeasureGUI_NormaleDlg::ClickOnOk() //================================================================================= bool MeasureGUI_NormaleDlg::ClickOnApply() { - if ( !onAccept() ) + if (!onAccept()) return false; initName(); + // activate first line edit + GroupArgs->PushButton1->click(); return true; } //================================================================================= // function : SelectionIntoArgument() -// purpose : Called when selection as changed or other case +// purpose : Called when selection is changed or on dialog initialization or activation //================================================================================= void MeasureGUI_NormaleDlg::SelectionIntoArgument() { erasePreview(); - myEditCurrentArgument->setText( "" ); + myEditCurrentArgument->setText(""); - if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) { + if (myEditCurrentArgument == GroupArgs->LineEdit1) { myFace = GEOM::GEOM_Object::_nil(); } - else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) { + else if (myEditCurrentArgument == GroupArgs->LineEdit2) { myPoint = GEOM::GEOM_Object::_nil(); } - + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); SALOME_ListIO aSelList; aSelMgr->selectedObjects(aSelList); @@ -180,75 +177,79 @@ void MeasureGUI_NormaleDlg::SelectionIntoArgument() GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); - if ( !testResult ) + if (!testResult || CORBA::is_nil(aSelectedObject)) return; - QString aName = GEOMBase::GetName( aSelectedObject ); + QString aName = GEOMBase::GetName(aSelectedObject); - if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) { + if (myEditCurrentArgument == GroupArgs->LineEdit1) { TopoDS_Shape aShape; - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) { TColStd_IndexedMapOfInteger aMap; aSelMgr->GetIndexes(aSelList.First(), aMap); - if ( aMap.Extent() == 1 ) // Local Selection + if (aMap.Extent() == 1) // Local Selection { - GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() ); - int anIndex = aMap( 1 ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); - aName += QString( ":face_%1" ).arg( anIndex ); + GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); + int anIndex = aMap(1); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); + aName += QString(":face_%1").arg(anIndex); } else // Global Selection { - if ( aShape.ShapeType() != TopAbs_FACE ) { + if (aShape.ShapeType() != TopAbs_FACE) { aSelectedObject = GEOM::GEOM_Object::_nil(); aName = ""; - } + } } } myFace = aSelectedObject; + myEditCurrentArgument->setText(aName); + + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + if (!myFace->_is_nil() && myPoint->_is_nil()) + GroupArgs->PushButton2->click(); } - else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) { + else if (myEditCurrentArgument == GroupArgs->LineEdit2) { TopoDS_Shape aShape; - if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) + if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull()) { TColStd_IndexedMapOfInteger aMap; aSelMgr->GetIndexes(aSelList.First(), aMap); - if ( aMap.Extent() == 1 ) // Local Selection + if (aMap.Extent() == 1) // Local Selection { - GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() ); - int anIndex = aMap( 1 ); - aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); - aName += QString( ":vertex_%1" ).arg( anIndex ); + GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId()); + int anIndex = aMap(1); + aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex); + aName += QString(":vertex_%1").arg(anIndex); } else // Global Selection { - if ( aShape.ShapeType() != TopAbs_VERTEX ) { + if (aShape.ShapeType() != TopAbs_VERTEX) { aSelectedObject = GEOM::GEOM_Object::_nil(); aName = ""; - } + } } } myPoint = aSelectedObject; - } - - myEditCurrentArgument->setText( aName ); + myEditCurrentArgument->setText(aName); - displayPreview(); -} + // clear selection + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + myGeomGUI->getApp()->selectionMgr()->clearSelected(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); -//================================================================================= -// function : LineEditReturnPressed() -// purpose : -//================================================================================= -void MeasureGUI_NormaleDlg::LineEditReturnPressed() -{ - QLineEdit* send = (QLineEdit*)sender(); - if ( send == GroupArgs->LineEdit1 || - send == GroupArgs->LineEdit2 ) { - myEditCurrentArgument = send; - GEOMBase_Skeleton::LineEditReturnPressed(); + if (!myPoint->_is_nil() && myFace->_is_nil()) + GroupArgs->PushButton1->click(); } + + displayPreview(); } //================================================================================= @@ -258,19 +259,51 @@ void MeasureGUI_NormaleDlg::LineEditReturnPressed() void MeasureGUI_NormaleDlg::SetEditCurrentArgument() { QPushButton* send = (QPushButton*)sender(); - globalSelection( GEOM_FACE ); - if ( send == GroupArgs->PushButton1 ) { + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + globalSelection(GEOM_FACE); + + if (send == GroupArgs->PushButton1) { myEditCurrentArgument = GroupArgs->LineEdit1; - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE ); + + GroupArgs->PushButton2->setDown(false); + GroupArgs->LineEdit2->setEnabled(false); + + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); } - else if ( send == GroupArgs->PushButton2 ) { + else if (send == GroupArgs->PushButton2) { myEditCurrentArgument = GroupArgs->LineEdit2; - localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); + + GroupArgs->PushButton1->setDown(false); + GroupArgs->LineEdit1->setEnabled(false); + + localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX); } + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + // enable line edit + myEditCurrentArgument->setEnabled(true); myEditCurrentArgument->setFocus(); - SelectionIntoArgument(); + // after setFocus(), because it will be setDown(false) when loses focus + send->setDown(true); + + // seems we need it only to avoid preview disappearing, caused by selection mode change + displayPreview(); +} + +//================================================================================= +// function : LineEditReturnPressed() +// purpose : +//================================================================================= +void MeasureGUI_NormaleDlg::LineEditReturnPressed() +{ + QLineEdit* send = (QLineEdit*)sender(); + if (send == GroupArgs->LineEdit1 || + send == GroupArgs->LineEdit2) { + myEditCurrentArgument = send; + GEOMBase_Skeleton::LineEditReturnPressed(); + } } //================================================================================= @@ -281,16 +314,17 @@ void MeasureGUI_NormaleDlg::ActivateThisDialog() { GEOMBase_Skeleton::ActivateThisDialog(); - SelectionIntoArgument(); + // reinit, because some selected objects could be removed + Init(); } //================================================================================= // function : enterEvent() // purpose : //================================================================================= -void MeasureGUI_NormaleDlg::enterEvent( QEvent* e ) +void MeasureGUI_NormaleDlg::enterEvent (QEvent*) { - if ( !mainFrame()->GroupConstructors->isEnabled() ) + if (!mainFrame()->GroupConstructors->isEnabled()) ActivateThisDialog(); } @@ -300,30 +334,30 @@ void MeasureGUI_NormaleDlg::enterEvent( QEvent* e ) //================================================================================= GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation() { - return getGeomEngine()->GetIMeasureOperations( getStudyId() ); + return getGeomEngine()->GetIMeasureOperations(getStudyId()); } //================================================================================= // function : isValid // purpose : //================================================================================= -bool MeasureGUI_NormaleDlg::isValid( QString& ) +bool MeasureGUI_NormaleDlg::isValid (QString&) { //return !CORBA::is_nil(myFace) && !CORBA::is_nil(myPoint); - return !CORBA::is_nil( myFace ); + return !CORBA::is_nil(myFace); } //================================================================================= // function : execute // purpose : //================================================================================= -bool MeasureGUI_NormaleDlg::execute( ObjectList& objects ) +bool MeasureGUI_NormaleDlg::execute (ObjectList& objects) { GEOM::GEOM_Object_var anObj = - GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetNormal( myFace, myPoint ); + GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->GetNormal(myFace, myPoint); - if ( !anObj->_is_nil() ) - objects.push_back( anObj._retn() ); + if (!anObj->_is_nil()) + objects.push_back(anObj._retn()); return true; }