Bugs 16640, 19050: Improve selection mechanism in GEOM dialog boxes.

This commit is contained in:
jfa 2008-09-29 13:36:48 +00:00
parent 0dd54298d5
commit b77eef91b6
3 changed files with 410 additions and 328 deletions

View File

@ -26,20 +26,19 @@
#include "MeasureGUI_AngleDlg.h"
#include "MeasureGUI_Widgets.h"
#include <GEOMBase.h>
#include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h>
#include <SalomeApp_Tools.h>
#include <SUIT_MessageBox.h>
#include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h>
#include <SOCC_Prs.h>
#include <SOCC_ViewModel.h>
#include <SalomeApp_Tools.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
@ -82,13 +81,13 @@
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" ) ) );
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"));
// Widgets
/***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE"));
mainFrame()->RadioButton1->setIcon(image0);
@ -106,6 +105,7 @@ MeasureGUI_AngleDlg::MeasureGUI_AngleDlg( GeometryGUI* GUI, QWidget* parent )
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,6 +140,7 @@ void MeasureGUI_AngleDlg::Init()
myEditCurrentArgument = mySelEdit;
// signals and slots connections
connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
@ -142,7 +148,6 @@ void MeasureGUI_AngleDlg::Init()
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();
}
@ -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);
}
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
globalSelection(GEOM_LINE);
SelectionIntoArgument();
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();
}
//=================================================================================

View File

@ -26,9 +26,8 @@
#include "MeasureGUI_DistanceDlg.h"
#include "MeasureGUI_Widgets.h"
#include <GEOMBase.h>
#include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h>
#include <SUIT_Session.h>
@ -42,6 +41,7 @@
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
// OCCT Includes
#include <Geom_Plane.hxx>
#include <AIS_LengthDimension.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx>
@ -59,15 +59,13 @@
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"));
/***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISTANCE"));
mainFrame()->RadioButton1->setIcon(image0);
@ -91,16 +89,14 @@ MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg( GeometryGUI* GUI, QWidget* paren
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;
myEditCurrentArgument = myGrp->LineEdit1;
connect( mySelEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
// 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();
}
@ -196,13 +206,11 @@ bool MeasureGUI_DistanceDlg::getParameters( double& theDistance,
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);
@ -214,8 +222,9 @@ bool MeasureGUI_DistanceDlg::getParameters( double& theDistance,
return getOperation()->IsDone();
}
}
return false;
}
//=================================================================================
// function : SetEditCurrentArgument()
@ -225,18 +234,28 @@ void MeasureGUI_DistanceDlg::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);
}
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()
@ -246,19 +265,17 @@ void MeasureGUI_DistanceDlg::LineEditReturnPressed()
{
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);
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()
@ -269,7 +286,6 @@ SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs()
double aDist = 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() ||

View File

@ -34,14 +34,15 @@
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <GEOMImpl_Types.hxx>
// OCCT Includes
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <TopExp.hxx>
#include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx>
#include <GEOMImpl_Types.hxx>
//=================================================================================
// class : MeasureGUI_NormaleDlg()
// purpose : Constructs a MeasureGUI_NormaleDlg which is a child of 'parent', with the
@ -78,7 +79,6 @@ MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg( GeometryGUI* theGeometryGUI, QWidg
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(GroupArgs);
/***************************************************************/
setHelpFileName("using_measurement_tools_page.html#normale_anchor");
@ -100,18 +100,15 @@ MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
//=================================================================================
void MeasureGUI_NormaleDlg::Init()
{
/* init variables */
// init variables
GroupArgs->LineEdit1->setReadOnly(true);
GroupArgs->LineEdit2->setReadOnly(true);
myFace = GEOM::GEOM_Object::_nil();
myPoint = GEOM::GEOM_Object::_nil();
GroupArgs->LineEdit1->setText("");
GroupArgs->LineEdit2->setText("");
myFace = myPoint = GEOM::GEOM_Object::_nil();
myEditCurrentArgument = GroupArgs->LineEdit1;
globalSelection( GEOM_FACE ); // to close previous local selection
localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
/* signals and slots connections */
// signals and slots connections
connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
@ -121,11 +118,9 @@ void MeasureGUI_NormaleDlg::Init()
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() ) );
initName(tr("GEOM_VECTOR_NORMALE"));
GroupArgs->PushButton1->click();
SelectionIntoArgument();
}
@ -149,12 +144,14 @@ bool MeasureGUI_NormaleDlg::ClickOnApply()
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()
{
@ -180,7 +177,7 @@ 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);
@ -207,6 +204,16 @@ void MeasureGUI_NormaleDlg::SelectionIntoArgument()
}
}
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) {
TopoDS_Shape aShape;
@ -230,10 +237,58 @@ void MeasureGUI_NormaleDlg::SelectionIntoArgument()
}
}
myPoint = 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 (!myPoint->_is_nil() && myFace->_is_nil())
GroupArgs->PushButton1->click();
}
displayPreview();
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
globalSelection(GEOM_FACE);
if (send == GroupArgs->PushButton1) {
myEditCurrentArgument = GroupArgs->LineEdit1;
GroupArgs->PushButton2->setDown(false);
GroupArgs->LineEdit2->setEnabled(false);
localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE);
}
else if (send == GroupArgs->PushButton2) {
myEditCurrentArgument = GroupArgs->LineEdit2;
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();
// 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();
}
@ -251,28 +306,6 @@ void MeasureGUI_NormaleDlg::LineEditReturnPressed()
}
}
//=================================================================================
// function : SetEditCurrentArgument()
// purpose :
//=================================================================================
void MeasureGUI_NormaleDlg::SetEditCurrentArgument()
{
QPushButton* send = (QPushButton*)sender();
globalSelection( GEOM_FACE );
if ( send == GroupArgs->PushButton1 ) {
myEditCurrentArgument = GroupArgs->LineEdit1;
localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
}
else if ( send == GroupArgs->PushButton2 ) {
myEditCurrentArgument = GroupArgs->LineEdit2;
localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
}
myEditCurrentArgument->setFocus();
SelectionIntoArgument();
}
//=================================================================================
// function : ActivateThisDialog()
// purpose :
@ -281,14 +314,15 @@ 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())
ActivateThisDialog();