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_AngleDlg.h"
#include "MeasureGUI_Widgets.h" #include "MeasureGUI_Widgets.h"
#include <GEOMBase.h>
#include <DlgRef.h> #include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h> #include <GeometryGUI.h>
#include <SUIT_Desktop.h>
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ResourceMgr.h> #include <SUIT_ResourceMgr.h>
#include <SalomeApp_Tools.h>
#include <SUIT_MessageBox.h> #include <SUIT_MessageBox.h>
#include <SUIT_ViewWindow.h> #include <SUIT_ViewWindow.h>
#include <SUIT_ViewManager.h> #include <SUIT_ViewManager.h>
#include <SOCC_Prs.h> #include <SOCC_Prs.h>
#include <SOCC_ViewModel.h> #include <SOCC_ViewModel.h>
#include <SalomeApp_Tools.h>
#include <SalomeApp_Application.h> #include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
@ -79,33 +78,34 @@
// The dialog will by default be modeless, unless you set 'modal' to // The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog. // TRUE to construct a modal dialog.
//================================================================================= //=================================================================================
MeasureGUI_AngleDlg::MeasureGUI_AngleDlg( GeometryGUI* GUI, QWidget* parent ) MeasureGUI_AngleDlg::MeasureGUI_AngleDlg (GeometryGUI* GUI, QWidget* parent)
: MeasureGUI_Skeleton( GUI, parent ) : MeasureGUI_Skeleton(GUI, parent)
{ {
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_ANGLE" ) ) ); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_ANGLE")));
QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
setWindowTitle( tr( "GEOM_MEASURE_ANGLE_TITLE" ) ); setWindowTitle(tr("GEOM_MEASURE_ANGLE_TITLE"));
// Widgets /***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_MEASURE_ANGLE_ANGLE"));
mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_MEASURE_ANGLE_ANGLE" ) ); myGrp = new MeasureGUI_2Sel1LineEdit(centralWidget());
mainFrame()->RadioButton1->setIcon( image0 ); 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);
myGrp = new MeasureGUI_2Sel1LineEdit( centralWidget() ); QVBoxLayout* layout = new QVBoxLayout(centralWidget());
myGrp->GroupBox1->setTitle( tr( "GEOM_MEASURE_ANGLE_OBJ" ) ); layout->setMargin(0); layout->setSpacing(6);
myGrp->TextLabel1->setText( tr( "GEOM_OBJECT_I" ).arg( "1" ) ); layout->addWidget(myGrp);
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 // Help page reference
myHelpFileName = "using_measurement_tools_page.html#angle_anchor"; myHelpFileName = "using_measurement_tools_page.html#angle_anchor";
@ -128,6 +128,11 @@ MeasureGUI_AngleDlg::~MeasureGUI_AngleDlg()
//================================================================================= //=================================================================================
void MeasureGUI_AngleDlg::Init() void MeasureGUI_AngleDlg::Init()
{ {
// init variables
myGrp->LineEdit1->setText("");
myGrp->LineEdit2->setText("");
myObj = myObj2 = GEOM::GEOM_Object::_nil();
mySelBtn = myGrp->PushButton1; mySelBtn = myGrp->PushButton1;
mySelEdit = myGrp->LineEdit1; mySelEdit = myGrp->LineEdit1;
mySelBtn2 = myGrp->PushButton2; mySelBtn2 = myGrp->PushButton2;
@ -135,14 +140,14 @@ void MeasureGUI_AngleDlg::Init()
myEditCurrentArgument = mySelEdit; myEditCurrentArgument = mySelEdit;
connect( mySelEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); // signals and slots connections
connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect(mySelEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
connect(mySelBtn2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
globalSelection( GEOM_LINE ); globalSelection(GEOM_LINE);
MeasureGUI_Skeleton::Init(); MeasureGUI_Skeleton::Init();
} }
//================================================================================= //=================================================================================
// function : SelectionIntoArgument() // function : SelectionIntoArgument()
// purpose : Called when selection has changed // purpose : Called when selection has changed
@ -162,10 +167,22 @@ void MeasureGUI_AngleDlg::SelectionIntoArgument()
aSelectedObject = GEOM::GEOM_Object::_nil(); 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; myObj = aSelectedObject;
else if (!myObj->_is_nil() && myObj2->_is_nil())
myGrp->PushButton2->click();
}
else {
myObj2 = aSelectedObject; myObj2 = aSelectedObject;
if (!myObj2->_is_nil() && myObj->_is_nil())
myGrp->PushButton1->click();
}
processObject(); processObject();
} }
@ -176,16 +193,16 @@ void MeasureGUI_AngleDlg::SelectionIntoArgument()
//================================================================================= //=================================================================================
void MeasureGUI_AngleDlg::processObject() void MeasureGUI_AngleDlg::processObject()
{ {
myGrp->LineEdit1->setText( !myObj->_is_nil() ? GEOMBase::GetName( myObj ) : "" ); myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : "");
myGrp->LineEdit2->setText( !myObj2->_is_nil() ? GEOMBase::GetName( myObj2 ) : "" ); myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
double anAngle = 0.; double anAngle = 0.;
if ( getParameters( anAngle ) ) { if (getParameters(anAngle)) {
myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( anAngle ) ); myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(anAngle));
redisplayPreview(); redisplayPreview();
} }
else { else {
myGrp->LineEdit3->setText( "" ); myGrp->LineEdit3->setText("");
erasePreview(); erasePreview();
} }
} }
@ -194,24 +211,24 @@ void MeasureGUI_AngleDlg::processObject()
// function : getParameters() // function : getParameters()
// purpose : Get angle between objects // purpose : Get angle between objects
//================================================================================= //=================================================================================
bool MeasureGUI_AngleDlg::getParameters( double& theAngle ) bool MeasureGUI_AngleDlg::getParameters (double& theAngle)
{ {
QString msg; QString msg;
if ( isValid( msg ) ) { if (isValid(msg)) {
try { 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 ) { catch(const SALOME::SALOME_Exception& e) {
SalomeApp_Tools::QtCatchCorbaException( e ); SalomeApp_Tools::QtCatchCorbaException(e);
return false; return false;
} }
bool isDone = getOperation()->IsDone(); bool isDone = getOperation()->IsDone();
if ( !isDone ) { if (!isDone) {
CORBA::String_var aMsg = getOperation()->GetErrorCode(); CORBA::String_var aMsg = getOperation()->GetErrorCode();
SUIT_MessageBox::warning( this, SUIT_MessageBox::warning(this,
QObject::tr( "WRN_WARNING" ), QObject::tr("WRN_WARNING"),
QObject::tr( aMsg.in() ) ); QObject::tr(aMsg.in()));
} }
return isDone; return isDone;
} }
@ -227,17 +244,32 @@ void MeasureGUI_AngleDlg::SetEditCurrentArgument()
{ {
QPushButton* send = (QPushButton*)sender(); QPushButton* send = (QPushButton*)sender();
if ( send == mySelBtn ) { if (send == myGrp->PushButton1) {
mySelEdit->setFocus(); myEditCurrentArgument = myGrp->LineEdit1;
myEditCurrentArgument = mySelEdit;
myGrp->PushButton2->setDown(false);
myGrp->LineEdit2->setEnabled(false);
} }
else { else {
mySelEdit2->setFocus(); myEditCurrentArgument = myGrp->LineEdit2;
myEditCurrentArgument = mySelEdit2;
myGrp->PushButton1->setDown(false);
myGrp->LineEdit1->setEnabled(false);
} }
globalSelection( GEOM_LINE ); disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
SelectionIntoArgument(); 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(); SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
if ( myObj->_is_nil() || myObj2->_is_nil() || !getParameters( anAngle ) || if (myObj->_is_nil() || myObj2->_is_nil() || !getParameters(anAngle) ||
vw->getViewManager()->getType() != OCCViewer_Viewer::Type() ) vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
return 0; return 0;
if ( anAngle > Precision::Angular() ) { if (anAngle > Precision::Angular()) {
try { try {
#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
OCC_CATCH_SIGNALS; OCC_CATCH_SIGNALS;
#endif #endif
TopoDS_Shape S1, S2; TopoDS_Shape S1, S2;
if ( GEOMBase::GetShape( myObj , S1, TopAbs_EDGE ) && if (GEOMBase::GetShape(myObj , S1, TopAbs_EDGE) &&
GEOMBase::GetShape( myObj2, S2, TopAbs_EDGE ) ) { GEOMBase::GetShape(myObj2, S2, TopAbs_EDGE)) {
TopoDS_Edge anEdge1 = TopoDS::Edge( S1 ); TopoDS_Edge anEdge1 = TopoDS::Edge(S1);
TopoDS_Edge anEdge2 = TopoDS::Edge( S2 ); TopoDS_Edge anEdge2 = TopoDS::Edge(S2);
// Build a plane for angle dimension presentation {P11, P12, P3} // Build a plane for angle dimension presentation {P11, P12, P3}
TopoDS_Vertex V11, V12, V21, V22; TopoDS_Vertex V11, V12, V21, V22;
TopExp::Vertices( anEdge1, V11, V12 ); TopExp::Vertices(anEdge1, V11, V12);
TopExp::Vertices( anEdge2, V21, V22 ); 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 aP11 = BRep_Tool::Pnt(TopExp::FirstVertex(anEdge1));
gp_Pnt aP22 = BRep_Tool::Pnt( TopExp::LastVertex ( anEdge2 ) ); 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));
// *P3 // *P3
// \ // \
@ -308,54 +340,54 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
// \ / // \ /
// \ / // \ /
// *P21 // *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 ); gce_MakePln gce_MP(aP11, aP12, aP3);
Handle(Geom_Plane) aPlane = new Geom_Plane( gce_MP.Value() ); Handle(Geom_Plane) aPlane = new Geom_Plane(gce_MP.Value());
// Build the angle dimension presentation // Build the angle dimension presentation
QString aLabel; QString aLabel;
aLabel.sprintf( "%.1f", anAngle ); aLabel.sprintf("%.1f", anAngle);
Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension Handle(AIS_AngleDimension) anIO = new AIS_AngleDimension
( anEdge1, anEdge2, aPlane, anAngle * PI180, (anEdge1, anEdge2, aPlane, anAngle * PI180,
TCollection_ExtendedString( (Standard_CString)aLabel.toLatin1().data() ) ); TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().data()));
Handle(Geom_Line) geom_lin1,geom_lin2; Handle(Geom_Line) geom_lin1,geom_lin2;
gp_Pnt ptat11,ptat12,ptat21,ptat22; gp_Pnt ptat11,ptat12,ptat21,ptat22;
Standard_Boolean isInfinite1,isInfinite2; Standard_Boolean isInfinite1,isInfinite2;
Handle(Geom_Curve) extCurv; Handle(Geom_Curve) extCurv;
Standard_Integer extShape; Standard_Integer extShape;
if ( AIS::ComputeGeometry(anEdge1, if (AIS::ComputeGeometry(anEdge1,
anEdge2, anEdge2,
extShape, extShape,
geom_lin1, geom_lin1,
geom_lin2, geom_lin2,
ptat11, ptat11,
ptat12, ptat12,
ptat21, ptat21,
ptat22, ptat22,
extCurv, extCurv,
isInfinite1, isInfinite1,
isInfinite2, isInfinite2,
aPlane)) { aPlane)) {
Standard_Real arrSize1 = anIO->ArrowSize(); Standard_Real arrSize1 = anIO->ArrowSize();
Standard_Real arrSize2 = anIO->ArrowSize(); Standard_Real arrSize2 = anIO->ArrowSize();
if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.; if (!isInfinite1) arrSize1 = ptat11.Distance(ptat12)/10.;
if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.; if (!isInfinite2) arrSize2 = ptat21.Distance(ptat22)/10.;
Standard_Real arrowSize = Max(arrSize1,arrSize2); Standard_Real arrowSize = Max(arrSize1,arrSize2);
anIO->SetArrowSize(arrowSize); anIO->SetArrowSize(arrowSize);
} }
SOCC_Prs* aPrs = SOCC_Prs* aPrs =
dynamic_cast<SOCC_Prs*>( ( (SOCC_Viewer*)( vw->getViewManager()->getViewModel() ) )->CreatePrs( 0 ) ); dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
if ( aPrs ) if (aPrs)
aPrs->AddObject( anIO ); aPrs->AddObject(anIO);
return aPrs; return aPrs;
} }
} }
catch( Standard_Failure ) { catch(Standard_Failure) {
} }
} }
@ -366,7 +398,7 @@ SALOME_Prs* MeasureGUI_AngleDlg::buildPrs()
// function : isValid() // function : isValid()
// purpose : // 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();
} }

View File

@ -26,9 +26,8 @@
#include "MeasureGUI_DistanceDlg.h" #include "MeasureGUI_DistanceDlg.h"
#include "MeasureGUI_Widgets.h" #include "MeasureGUI_Widgets.h"
#include <GEOMBase.h>
#include <DlgRef.h> #include <DlgRef.h>
#include <GEOMBase.h>
#include <GeometryGUI.h> #include <GeometryGUI.h>
#include <SUIT_Session.h> #include <SUIT_Session.h>
@ -42,6 +41,7 @@
#include <SalomeApp_Application.h> #include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
// OCCT Includes
#include <Geom_Plane.hxx> #include <Geom_Plane.hxx>
#include <AIS_LengthDimension.hxx> #include <AIS_LengthDimension.hxx>
#include <BRepBuilderAPI_MakeEdge.hxx> #include <BRepBuilderAPI_MakeEdge.hxx>
@ -56,51 +56,47 @@
// The dialog will by default be modeless, unless you set 'modal' to // The dialog will by default be modeless, unless you set 'modal' to
// true to construct a modal dialog. // true to construct a modal dialog.
//================================================================================= //=================================================================================
MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg( GeometryGUI* GUI, QWidget* parent ) MeasureGUI_DistanceDlg::MeasureGUI_DistanceDlg (GeometryGUI* GUI, QWidget* parent)
: MeasureGUI_Skeleton( GUI, parent ) : MeasureGUI_Skeleton(GUI, parent)
{ {
QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
"GEOM", tr( "ICON_DLG_MINDIST" ) ) ); QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_MINDIST")));
QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
"GEOM", tr( "ICON_SELECT" ) ) );
setWindowTitle( tr( "GEOM_MINDIST_TITLE" ) ); setWindowTitle(tr("GEOM_MINDIST_TITLE"));
/***************************************************************/ /***************************************************************/
mainFrame()->GroupConstructors->setTitle(tr("GEOM_DISTANCE"));
mainFrame()->GroupConstructors->setTitle( tr( "GEOM_DISTANCE" ) ); mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->RadioButton1->setIcon( image0 );
myGrp = new MeasureGUI_2Sel4LineEdit( centralWidget() ); myGrp = new MeasureGUI_2Sel4LineEdit(centralWidget());
myGrp->GroupBox1->setTitle( tr( "GEOM_MINDIST_OBJ" ) ); myGrp->GroupBox1->setTitle(tr("GEOM_MINDIST_OBJ"));
myGrp->TextLabel1->setText( tr( "GEOM_OBJECT_I" ).arg( "1" ) ); myGrp->TextLabel1->setText(tr("GEOM_OBJECT_I").arg("1"));
myGrp->TextLabel2->setText( tr( "GEOM_OBJECT_I" ).arg( "2" ) ); myGrp->TextLabel2->setText(tr("GEOM_OBJECT_I").arg("2"));
myGrp->TextLabel3->setText( tr( "GEOM_LENGTH" ) ); myGrp->TextLabel3->setText(tr("GEOM_LENGTH"));
myGrp->TextLabel4->setText( tr( "GEOM_DX" ) ); myGrp->TextLabel4->setText(tr("GEOM_DX"));
myGrp->TextLabel5->setText( tr( "GEOM_DY" ) ); myGrp->TextLabel5->setText(tr("GEOM_DY"));
myGrp->TextLabel6->setText( tr( "GEOM_DZ" ) ); myGrp->TextLabel6->setText(tr("GEOM_DZ"));
myGrp->LineEdit3->setReadOnly( true ); myGrp->LineEdit3->setReadOnly(true);
myGrp->PushButton1->setIcon( image1 ); myGrp->PushButton1->setIcon(image1);
myGrp->PushButton2->setIcon( image1 ); myGrp->PushButton2->setIcon(image1);
myGrp->LineEdit1->setReadOnly( true ); myGrp->LineEdit1->setReadOnly(true);
myGrp->LineEdit2->setReadOnly( true ); myGrp->LineEdit2->setReadOnly(true);
myGrp->LineEdit4->setReadOnly( true ); myGrp->LineEdit4->setReadOnly(true);
myGrp->LineEdit5->setReadOnly( true ); myGrp->LineEdit5->setReadOnly(true);
myGrp->LineEdit6->setReadOnly( true ); myGrp->LineEdit6->setReadOnly(true);
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( myGrp );
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(myGrp);
/***************************************************************/ /***************************************************************/
myHelpFileName = "using_measurement_tools_page.html#min_distance_anchor"; myHelpFileName = "using_measurement_tools_page.html#min_distance_anchor";
/* Initialisation */ // Initialisation
Init(); Init();
} }
//================================================================================= //=================================================================================
// function : ~MeasureGUI_DistanceDlg() // function : ~MeasureGUI_DistanceDlg()
// purpose : Destroys the object and frees any allocated resources // purpose : Destroys the object and frees any allocated resources
@ -109,27 +105,29 @@ MeasureGUI_DistanceDlg::~MeasureGUI_DistanceDlg()
{ {
} }
//================================================================================= //=================================================================================
// function : Init() // function : Init()
// purpose : // purpose :
//================================================================================= //=================================================================================
void MeasureGUI_DistanceDlg::Init() void MeasureGUI_DistanceDlg::Init()
{ {
// init variables
myGrp->LineEdit1->setText("");
myGrp->LineEdit2->setText("");
myObj = myObj2 = GEOM::GEOM_Object::_nil();
mySelBtn = myGrp->PushButton1; mySelBtn = myGrp->PushButton1;
mySelEdit = myGrp->LineEdit1; mySelEdit = myGrp->LineEdit1;
mySelBtn2 = myGrp->PushButton2;
mySelEdit2 = myGrp->LineEdit2;
myEditCurrentArgument = mySelEdit;
connect( mySelEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) ); myEditCurrentArgument = myGrp->LineEdit1;
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(); MeasureGUI_Skeleton::Init();
} }
//================================================================================= //=================================================================================
// function : SelectionIntoArgument() // function : SelectionIntoArgument()
// purpose : Called when selection has changed // purpose : Called when selection has changed
@ -149,10 +147,22 @@ void MeasureGUI_DistanceDlg::SelectionIntoArgument()
aSelectedObject = GEOM::GEOM_Object::_nil(); 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; myObj = aSelectedObject;
else if (!myObj->_is_nil() && myObj2->_is_nil())
myGrp->PushButton2->click();
}
else {
myObj2 = aSelectedObject; myObj2 = aSelectedObject;
if (!myObj2->_is_nil() && myObj->_is_nil())
myGrp->PushButton1->click();
}
processObject(); processObject();
} }
@ -163,26 +173,26 @@ void MeasureGUI_DistanceDlg::SelectionIntoArgument()
//================================================================================= //=================================================================================
void MeasureGUI_DistanceDlg::processObject() void MeasureGUI_DistanceDlg::processObject()
{ {
myGrp->LineEdit1->setText( !myObj->_is_nil() ? GEOMBase::GetName( myObj ) : "" ); myGrp->LineEdit1->setText(!myObj->_is_nil() ? GEOMBase::GetName(myObj ) : "");
myGrp->LineEdit2->setText( !myObj2->_is_nil() ? GEOMBase::GetName( myObj2 ) : "" ); myGrp->LineEdit2->setText(!myObj2->_is_nil() ? GEOMBase::GetName(myObj2) : "");
gp_Pnt aPnt1, aPnt2; gp_Pnt aPnt1, aPnt2;
double aDist = 0.; double aDist = 0.;
if ( getParameters( aDist, aPnt1, aPnt2 ) ) { if (getParameters(aDist, aPnt1, aPnt2)) {
myGrp->LineEdit3->setText( DlgRef::PrintDoubleValue( aDist ) ); myGrp->LineEdit3->setText(DlgRef::PrintDoubleValue(aDist));
gp_XYZ aVec = aPnt2.XYZ() - aPnt1.XYZ(); gp_XYZ aVec = aPnt2.XYZ() - aPnt1.XYZ();
myGrp->LineEdit4->setText( DlgRef::PrintDoubleValue( aVec.X() ) ); myGrp->LineEdit4->setText(DlgRef::PrintDoubleValue(aVec.X()));
myGrp->LineEdit5->setText( DlgRef::PrintDoubleValue( aVec.Y() ) ); myGrp->LineEdit5->setText(DlgRef::PrintDoubleValue(aVec.Y()));
myGrp->LineEdit6->setText( DlgRef::PrintDoubleValue( aVec.Z() ) ); myGrp->LineEdit6->setText(DlgRef::PrintDoubleValue(aVec.Z()));
redisplayPreview(); redisplayPreview();
} }
else { else {
myGrp->LineEdit3->setText( "" ); myGrp->LineEdit3->setText("");
myGrp->LineEdit4->setText( "" ); myGrp->LineEdit4->setText("");
myGrp->LineEdit5->setText( "" ); myGrp->LineEdit5->setText("");
myGrp->LineEdit6->setText( "" ); myGrp->LineEdit6->setText("");
erasePreview(); erasePreview();
} }
} }
@ -191,31 +201,30 @@ void MeasureGUI_DistanceDlg::processObject()
// function : getParameters() // function : getParameters()
// purpose : Get distance between objects // purpose : Get distance between objects
//================================================================================= //=================================================================================
bool MeasureGUI_DistanceDlg::getParameters( double& theDistance, bool MeasureGUI_DistanceDlg::getParameters (double& theDistance,
gp_Pnt& thePnt1, gp_Pnt& thePnt1,
gp_Pnt& thePnt2 ) gp_Pnt& thePnt2)
{ {
QString msg; QString msg;
if ( !isValid( msg ) ) if (isValid(msg)) {
return false;
else {
try { try {
double x1, y1, z1, x2, y2, z2; double x1, y1, z1, x2, y2, z2;
theDistance = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetMinDistance( theDistance = GEOM::GEOM_IMeasureOperations::_narrow(getOperation())->
myObj, myObj2, x1, y1, z1, x2, y2, z2 ); GetMinDistance(myObj, myObj2, x1, y1, z1, x2, y2, z2);
thePnt1.SetCoord( x1, y1, z1 ); thePnt1.SetCoord(x1, y1, z1);
thePnt2.SetCoord( x2, y2, z2 ); thePnt2.SetCoord(x2, y2, z2);
} }
catch( const SALOME::SALOME_Exception& e ) { catch(const SALOME::SALOME_Exception& e) {
SalomeApp_Tools::QtCatchCorbaException( e ); SalomeApp_Tools::QtCatchCorbaException(e);
return false; return false;
} }
return getOperation()->IsDone(); return getOperation()->IsDone();
} }
}
return false;
}
//================================================================================= //=================================================================================
// function : SetEditCurrentArgument() // function : SetEditCurrentArgument()
@ -223,20 +232,30 @@ bool MeasureGUI_DistanceDlg::getParameters( double& theDistance,
//================================================================================= //=================================================================================
void MeasureGUI_DistanceDlg::SetEditCurrentArgument() void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
{ {
QPushButton* send = ( QPushButton* )sender(); QPushButton* send = (QPushButton*)sender();
if ( send == mySelBtn ) { if (send == myGrp->PushButton1) {
mySelEdit->setFocus(); myEditCurrentArgument = myGrp->LineEdit1;
myEditCurrentArgument = mySelEdit;
myGrp->PushButton2->setDown(false);
myGrp->LineEdit2->setEnabled(false);
} }
else { else {
mySelEdit2->setFocus(); myEditCurrentArgument = myGrp->LineEdit2;
myEditCurrentArgument = mySelEdit2;
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() // function : LineEditReturnPressed()
@ -244,22 +263,20 @@ void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
//================================================================================= //=================================================================================
void MeasureGUI_DistanceDlg::LineEditReturnPressed() void MeasureGUI_DistanceDlg::LineEditReturnPressed()
{ {
QLineEdit* send = ( QLineEdit* )sender(); QLineEdit* send = (QLineEdit*)sender();
if ( send == mySelEdit ) if (send == myGrp->LineEdit1 || send == myGrp->LineEdit2) {
myEditCurrentArgument = mySelEdit; myEditCurrentArgument = send;
else
myEditCurrentArgument = mySelEdit2;
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList; SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList); aSelMgr->selectedObjects(aSelList);
if (GEOMBase::SelectionByNameInDialogs(this, mySelEdit->text(), aSelList)) if (GEOMBase::SelectionByNameInDialogs(this, myGrp->LineEdit1->text(), aSelList))
mySelEdit->setText(mySelEdit->text()); myGrp->LineEdit1->setText(myGrp->LineEdit1->text());
}
} }
//================================================================================= //=================================================================================
// function : buildPrs() // function : buildPrs()
// purpose : // purpose :
@ -267,58 +284,57 @@ void MeasureGUI_DistanceDlg::LineEditReturnPressed()
SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs() SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs()
{ {
double aDist = 0.; 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(); SUIT_ViewWindow* vw = SUIT_Session::session()->activeApplication()->desktop()->activeWindow();
if ( myObj->_is_nil() || myObj2->_is_nil() || if (myObj->_is_nil() || myObj2->_is_nil() ||
!getParameters( aDist, aPnt1, aPnt2 ) || !getParameters(aDist, aPnt1, aPnt2) ||
vw->getViewManager()->getType() != OCCViewer_Viewer::Type() ) vw->getViewManager()->getType() != OCCViewer_Viewer::Type())
return 0; return 0;
try try
{ {
if ( aDist <= 1.e-9 ) { if (aDist <= 1.e-9) {
BRepBuilderAPI_MakeVertex aMaker( aPnt1 ); BRepBuilderAPI_MakeVertex aMaker(aPnt1);
return getDisplayer()->BuildPrs( aMaker.Vertex() ); return getDisplayer()->BuildPrs(aMaker.Vertex());
} }
else { else {
BRepBuilderAPI_MakeEdge MakeEdge( aPnt1, aPnt2 ); BRepBuilderAPI_MakeEdge MakeEdge(aPnt1, aPnt2);
TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex( aPnt1 ); TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex(aPnt1);
TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex( aPnt2 ); TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex(aPnt2);
QString aLabel; QString aLabel;
aLabel.sprintf( "%.1f", aDist ); aLabel.sprintf("%.1f", aDist);
gp_Pnt aPnt3( ( aPnt1.X() + aPnt2.X() ) / 2, gp_Pnt aPnt3((aPnt1.X() + aPnt2.X()) / 2,
( aPnt1.Y() + aPnt2.Y() ) / 2, (aPnt1.Y() + aPnt2.Y()) / 2,
( aPnt1.Z() + aPnt2.Z() ) / 2 + 100 ); (aPnt1.Z() + aPnt2.Z()) / 2 + 100);
gp_Vec va( aPnt3, aPnt1 ); gp_Vec va(aPnt3, aPnt1);
gp_Vec vb( aPnt3, aPnt2 ); gp_Vec vb(aPnt3, aPnt2);
if ( va.IsParallel( vb, Precision::Angular() ) ) { if (va.IsParallel(vb, Precision::Angular())) {
aPnt3.SetY( ( aPnt1.Y() + aPnt2.Y() ) / 2 + 100 ); aPnt3.SetY((aPnt1.Y() + aPnt2.Y()) / 2 + 100);
aPnt3.SetZ( ( aPnt1.Z() + aPnt2.Z() ) / 2 ); 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( gce_MakePln gce_MP(aPnt1, aPnt2, aPnt3);
aVert1, aVert2, P, aDist, TCollection_ExtendedString( (Standard_CString)aLabel.toLatin1().constData() ) ); Handle(Geom_Plane) P = new Geom_Plane(gce_MP.Value());
anIO->SetArrowSize( aDist/20 );
SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>( ((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs( 0 ) ); Handle(AIS_LengthDimension) anIO = new AIS_LengthDimension(
aVert1, aVert2, P, aDist, TCollection_ExtendedString((Standard_CString)aLabel.toLatin1().constData()));
anIO->SetArrowSize(aDist/20);
if ( aPrs ) SOCC_Prs* aPrs = dynamic_cast<SOCC_Prs*>(((SOCC_Viewer*)(vw->getViewManager()->getViewModel()))->CreatePrs(0));
aPrs->AddObject( anIO );
if (aPrs)
aPrs->AddObject(anIO);
return aPrs; return aPrs;
} }
} }
catch( Standard_Failure ) { catch(Standard_Failure) {
return 0; return 0;
} }
} }
@ -327,7 +343,7 @@ SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs()
// function : isValid() // function : isValid()
// purpose : // 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();
} }

View File

@ -34,14 +34,15 @@
#include <SalomeApp_Application.h> #include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
#include <GEOMImpl_Types.hxx> // OCCT Includes
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
#include <TopExp.hxx> #include <TopExp.hxx>
#include <TColStd_IndexedMapOfInteger.hxx> #include <TColStd_IndexedMapOfInteger.hxx>
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
#include <GEOMImpl_Types.hxx>
//================================================================================= //=================================================================================
// class : MeasureGUI_NormaleDlg() // class : MeasureGUI_NormaleDlg()
// purpose : Constructs a MeasureGUI_NormaleDlg which is a child of 'parent', with the // 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 // The dialog will by default be modeless, unless you set 'modal' to
// TRUE to construct a modal dialog. // TRUE to construct a modal dialog.
//================================================================================= //=================================================================================
MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg( GeometryGUI* theGeometryGUI, QWidget* parent ) MeasureGUI_NormaleDlg::MeasureGUI_NormaleDlg (GeometryGUI* theGeometryGUI, QWidget* parent)
: GEOMBase_Skeleton( theGeometryGUI, parent, false ) : GEOMBase_Skeleton(theGeometryGUI, parent, false)
{ {
SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
QPixmap image0( aResMgr->loadPixmap( "GEOM", tr( "ICON_DLG_NORMALE" ) ) ); QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_NORMALE")));
QPixmap image1( aResMgr->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) ); 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()->GroupConstructors->setTitle(tr("GEOM_NORMALE"));
mainFrame()->RadioButton1->setIcon( image0 ); mainFrame()->RadioButton1->setIcon(image0);
mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose ); mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton2->close(); mainFrame()->RadioButton2->close();
mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose);
mainFrame()->RadioButton3->close(); mainFrame()->RadioButton3->close();
GroupArgs = new DlgRef_2Sel ( centralWidget() ); GroupArgs = new DlgRef_2Sel (centralWidget());
GroupArgs->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) ); GroupArgs->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
GroupArgs->TextLabel1->setText( tr( "GEOM_FACE" ) ); GroupArgs->TextLabel1->setText(tr("GEOM_FACE"));
GroupArgs->TextLabel2->setText( tr( "GEOM_POINT" ) ); GroupArgs->TextLabel2->setText(tr("GEOM_POINT"));
GroupArgs->PushButton1->setIcon( image1 ); GroupArgs->PushButton1->setIcon(image1);
GroupArgs->PushButton2->setIcon( image1 ); GroupArgs->PushButton2->setIcon(image1);
QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
layout->setMargin( 0 ); layout->setSpacing( 6 );
layout->addWidget( GroupArgs );
QVBoxLayout* layout = new QVBoxLayout(centralWidget());
layout->setMargin(0); layout->setSpacing(6);
layout->addWidget(GroupArgs);
/***************************************************************/ /***************************************************************/
setHelpFileName("using_measurement_tools_page.html#normale_anchor"); setHelpFileName("using_measurement_tools_page.html#normale_anchor");
@ -100,32 +100,27 @@ MeasureGUI_NormaleDlg::~MeasureGUI_NormaleDlg()
//================================================================================= //=================================================================================
void MeasureGUI_NormaleDlg::Init() void MeasureGUI_NormaleDlg::Init()
{ {
/* init variables */ // init variables
GroupArgs->LineEdit1->setReadOnly( true ); GroupArgs->LineEdit1->setReadOnly(true);
GroupArgs->LineEdit2->setReadOnly( true ); GroupArgs->LineEdit2->setReadOnly(true);
myFace = GEOM::GEOM_Object::_nil(); GroupArgs->LineEdit1->setText("");
myPoint = GEOM::GEOM_Object::_nil(); GroupArgs->LineEdit2->setText("");
myFace = myPoint = GEOM::GEOM_Object::_nil();
myEditCurrentArgument = GroupArgs->LineEdit1; // signals and slots connections
globalSelection( GEOM_FACE ); // to close previous local selection connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE ); connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
/* signals and slots connections */ connect(GroupArgs->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); connect(GroupArgs->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
connect( GroupArgs->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect(GroupArgs->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
connect( GroupArgs->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); connect(GroupArgs->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
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")); initName(tr("GEOM_VECTOR_NORMALE"));
GroupArgs->PushButton1->click();
SelectionIntoArgument(); SelectionIntoArgument();
} }
@ -135,7 +130,7 @@ void MeasureGUI_NormaleDlg::Init()
//================================================================================= //=================================================================================
void MeasureGUI_NormaleDlg::ClickOnOk() void MeasureGUI_NormaleDlg::ClickOnOk()
{ {
if ( ClickOnApply() ) if (ClickOnApply())
ClickOnCancel(); ClickOnCancel();
} }
@ -145,29 +140,31 @@ void MeasureGUI_NormaleDlg::ClickOnOk()
//================================================================================= //=================================================================================
bool MeasureGUI_NormaleDlg::ClickOnApply() bool MeasureGUI_NormaleDlg::ClickOnApply()
{ {
if ( !onAccept() ) if (!onAccept())
return false; return false;
initName(); initName();
// activate first line edit
GroupArgs->PushButton1->click();
return true; return true;
} }
//================================================================================= //=================================================================================
// function : SelectionIntoArgument() // 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() void MeasureGUI_NormaleDlg::SelectionIntoArgument()
{ {
erasePreview(); erasePreview();
myEditCurrentArgument->setText( "" ); myEditCurrentArgument->setText("");
if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) { if (myEditCurrentArgument == GroupArgs->LineEdit1) {
myFace = GEOM::GEOM_Object::_nil(); myFace = GEOM::GEOM_Object::_nil();
} }
else if ( myEditCurrentArgument == GroupArgs->LineEdit2 ) { else if (myEditCurrentArgument == GroupArgs->LineEdit2) {
myPoint = GEOM::GEOM_Object::_nil(); myPoint = GEOM::GEOM_Object::_nil();
} }
LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
SALOME_ListIO aSelList; SALOME_ListIO aSelList;
aSelMgr->selectedObjects(aSelList); aSelMgr->selectedObjects(aSelList);
@ -180,60 +177,118 @@ void MeasureGUI_NormaleDlg::SelectionIntoArgument()
GEOM::GEOM_Object_var aSelectedObject = GEOM::GEOM_Object_var aSelectedObject =
GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult); GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
if ( !testResult ) if (!testResult || CORBA::is_nil(aSelectedObject))
return; return;
QString aName = GEOMBase::GetName( aSelectedObject ); QString aName = GEOMBase::GetName(aSelectedObject);
if ( myEditCurrentArgument == GroupArgs->LineEdit1 ) { if (myEditCurrentArgument == GroupArgs->LineEdit1) {
TopoDS_Shape aShape; TopoDS_Shape aShape;
if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
{ {
TColStd_IndexedMapOfInteger aMap; TColStd_IndexedMapOfInteger aMap;
aSelMgr->GetIndexes(aSelList.First(), 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() ); GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
int anIndex = aMap( 1 ); int anIndex = aMap(1);
aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
aName += QString( ":face_%1" ).arg( anIndex ); aName += QString(":face_%1").arg(anIndex);
} }
else // Global Selection else // Global Selection
{ {
if ( aShape.ShapeType() != TopAbs_FACE ) { if (aShape.ShapeType() != TopAbs_FACE) {
aSelectedObject = GEOM::GEOM_Object::_nil(); aSelectedObject = GEOM::GEOM_Object::_nil();
aName = ""; aName = "";
} }
} }
} }
myFace = aSelectedObject; 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; TopoDS_Shape aShape;
if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() ) if (GEOMBase::GetShape(aSelectedObject, aShape, TopAbs_SHAPE) && !aShape.IsNull())
{ {
TColStd_IndexedMapOfInteger aMap; TColStd_IndexedMapOfInteger aMap;
aSelMgr->GetIndexes(aSelList.First(), 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() ); GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations(getStudyId());
int anIndex = aMap( 1 ); int anIndex = aMap(1);
aSelectedObject = aShapesOp->GetSubShape( aSelectedObject, anIndex ); aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
aName += QString( ":vertex_%1" ).arg( anIndex ); aName += QString(":vertex_%1").arg(anIndex);
} }
else // Global Selection else // Global Selection
{ {
if ( aShape.ShapeType() != TopAbs_VERTEX ) { if (aShape.ShapeType() != TopAbs_VERTEX) {
aSelectedObject = GEOM::GEOM_Object::_nil(); aSelectedObject = GEOM::GEOM_Object::_nil();
aName = ""; aName = "";
} }
} }
} }
myPoint = aSelectedObject; 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();
} }
myEditCurrentArgument->setText( aName ); 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(); displayPreview();
} }
@ -244,35 +299,13 @@ void MeasureGUI_NormaleDlg::SelectionIntoArgument()
void MeasureGUI_NormaleDlg::LineEditReturnPressed() void MeasureGUI_NormaleDlg::LineEditReturnPressed()
{ {
QLineEdit* send = (QLineEdit*)sender(); QLineEdit* send = (QLineEdit*)sender();
if ( send == GroupArgs->LineEdit1 || if (send == GroupArgs->LineEdit1 ||
send == GroupArgs->LineEdit2 ) { send == GroupArgs->LineEdit2) {
myEditCurrentArgument = send; myEditCurrentArgument = send;
GEOMBase_Skeleton::LineEditReturnPressed(); GEOMBase_Skeleton::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() // function : ActivateThisDialog()
// purpose : // purpose :
@ -281,16 +314,17 @@ void MeasureGUI_NormaleDlg::ActivateThisDialog()
{ {
GEOMBase_Skeleton::ActivateThisDialog(); GEOMBase_Skeleton::ActivateThisDialog();
SelectionIntoArgument(); // reinit, because some selected objects could be removed
Init();
} }
//================================================================================= //=================================================================================
// function : enterEvent() // function : enterEvent()
// purpose : // purpose :
//================================================================================= //=================================================================================
void MeasureGUI_NormaleDlg::enterEvent( QEvent* e ) void MeasureGUI_NormaleDlg::enterEvent (QEvent*)
{ {
if ( !mainFrame()->GroupConstructors->isEnabled() ) if (!mainFrame()->GroupConstructors->isEnabled())
ActivateThisDialog(); ActivateThisDialog();
} }
@ -300,30 +334,30 @@ void MeasureGUI_NormaleDlg::enterEvent( QEvent* e )
//================================================================================= //=================================================================================
GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation() GEOM::GEOM_IOperations_ptr MeasureGUI_NormaleDlg::createOperation()
{ {
return getGeomEngine()->GetIMeasureOperations( getStudyId() ); return getGeomEngine()->GetIMeasureOperations(getStudyId());
} }
//================================================================================= //=================================================================================
// function : isValid // function : isValid
// purpose : // 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) && !CORBA::is_nil(myPoint);
return !CORBA::is_nil( myFace ); return !CORBA::is_nil(myFace);
} }
//================================================================================= //=================================================================================
// function : execute // function : execute
// purpose : // purpose :
//================================================================================= //=================================================================================
bool MeasureGUI_NormaleDlg::execute( ObjectList& objects ) bool MeasureGUI_NormaleDlg::execute (ObjectList& objects)
{ {
GEOM::GEOM_Object_var anObj = 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() ) if (!anObj->_is_nil())
objects.push_back( anObj._retn() ); objects.push_back(anObj._retn());
return true; return true;
} }