rnc: In the frame of the feature EDF 1900, made possible to define a point by clicking in the 3D view when using the Sketcher

This commit is contained in:
gdd 2011-06-28 12:48:30 +00:00
parent 07682aac19
commit 66a0b44a07
4 changed files with 193 additions and 22 deletions

View File

@ -29,14 +29,23 @@
#include <GeometryGUI.h>
#include "GeometryGUI_Operations.h"
#include <SUIT_Session.h>
#include <SUIT_Desktop.h>
#include <SUIT_ViewWindow.h>
#include <OCCViewer_ViewModel.h>
#include <OCCViewer_ViewManager.h>
#include <OCCViewer_ViewWindow.h>
#include <OCCViewer_ViewPort3d.h>
#include <SalomeApp_Study.h>
#include <SalomeApp_Application.h>
#include <TopoDS_Shape.hxx>
#include <TopoDS.hxx>
#include <BRep_Tool.hxx>
#include <ProjLib.hxx>
#include <ElSLib.hxx>
#include <QMouseEvent>
#include "EntityGUI_SketcherDlg.h" // Sketcher
#include "EntityGUI_3DSketcherDlg.h" // Sketcher
@ -94,6 +103,77 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
return true;
}
//=================================================================================
// function : 0nMousePress()
// purpose : [static] manage mouse events
//=================================================================================
bool EntityGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
{
MESSAGE("EntityGUI::OnMousePress")
QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
// Create Point dialog, OCC viewer
if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 ) &&
theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
pe->modifiers() != Qt::ControlModifier ) {
MESSAGE("Premier if ok!")
EntityGUI_SketcherDlg* aPntDlg = (EntityGUI_SketcherDlg*) aDlg;
if ( aPntDlg->acceptMouseEvent() ) {
OCCViewer_Viewer* anOCCViewer =
( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
gp_Pnt aPnt;
ic->InitSelected();
if ( pe->modifiers() == Qt::ShiftModifier )
ic->ShiftSelect(); // Append selection
else
ic->Select(); // New selection
ic->InitSelected();
if ( ic->MoreSelected() ) {
TopoDS_Shape aShape = ic->SelectedShape();
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
}
else {
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
}
Qt::KeyboardModifiers modifiers = pe->modifiers();
aPntDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog
} // acceptMouseEvent()
}
return false;
}
//=======================================================================
// function : ConvertClickToPoint()
// purpose : Returns the point clicked in 3D view
//=======================================================================
gp_Pnt EntityGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
{
V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
aView->Eye( XEye, YEye, ZEye );
aView->At( XAt, YAt, ZAt );
gp_Pnt EyePoint( XEye, YEye, ZEye );
gp_Pnt AtPoint( XAt, YAt, ZAt );
gp_Vec EyeVector( EyePoint, AtPoint );
gp_Dir EyeDir( EyeVector );
gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
Standard_Real X, Y, Z;
aView->Convert( x, y, X, Y, Z );
gp_Pnt ConvertedPoint( X, Y, Z );
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
return ResultPoint;
}
//=====================================================================================
// function : DisplaySimulationShape()
@ -101,6 +181,7 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
//=====================================================================================
void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Shape& S2 )
{
MESSAGE("EntityGUI::DisplaySimulationShape")
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return;
@ -149,6 +230,7 @@ void EntityGUI::DisplaySimulationShape( const TopoDS_Shape& S1, const TopoDS_Sha
//==================================================================================
void EntityGUI::EraseSimulationShape()
{
MESSAGE("EntityGUI::EraseSimulationShape")
SalomeApp_Application* app = getGeometryGUI()->getApp();
if ( !app ) return;

View File

@ -32,9 +32,11 @@
#include <SALOMEDSClient.hxx>
#include <AIS_Shape.hxx>
#include <V3d_View.hxx>
class TopoDS_Shape;
//=================================================================================
// class : EntityGUI
// purpose :
@ -46,6 +48,9 @@ public :
~EntityGUI();
bool OnGUIEvent( int, SUIT_Desktop* );
bool OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow );
gp_Pnt ConvertClickToPoint( int x, int y, Handle(V3d_View) aView );
void DisplaySimulationShape( const TopoDS_Shape&, const TopoDS_Shape& );
void EraseSimulationShape();
@ -57,6 +62,7 @@ public:
// AIS shape used only during topo/geom simulations
Handle(AIS_Shape) mySimulationShape1;
Handle(AIS_Shape) mySimulationShape2;
};
#endif // ENTITYGUI_H

View File

@ -1154,6 +1154,7 @@ void EntityGUI_SketcherDlg::setEnabledRedo( bool value )
//=================================================================================
void EntityGUI_SketcherDlg::SelectionIntoArgument()
{
MESSAGE("EntityGUI_SketcherDlg::SelectionIntoArgument")
myEditCurrentArgument->setText( "" );
double tmpX = myX;
double tmpY = myY;
@ -1171,6 +1172,11 @@ void EntityGUI_SketcherDlg::SelectionIntoArgument()
aSelMgr->selectedObjects(aSelList);
int nbSel = aSelList.Extent();
MESSAGE("NbSel = "<<nbSel)
if (nbSel == 0){
myX=tmpX;
myY=tmpY;
}
if (nbSel == 1 && myEditCurrentArgument == Group1Sel->LineEdit1) {
GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
if ( !CORBA::is_nil(aSelectedObject) ) {
@ -1489,12 +1495,42 @@ void EntityGUI_SketcherDlg::enterEvent( QEvent* )
//=================================================================================
void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
{
MESSAGE("EntityGUI_SketcherDlg::closeEvent")
//myGeometryGUI->SetState( -1 );
disconnect( myGeometryGUI->getApp()->selectionMgr(), 0, this, 0 );
myGeometryGUI->getApp()->updateActions();
QDialog::closeEvent( e );
}
//rnc TODO
//=================================================================================
// function : OnPointSelected
// purpose :
//=================================================================================
void EntityGUI_SketcherDlg::OnPointSelected(Qt::KeyboardModifiers modifiers, const gp_Pnt& thePnt)
{
MESSAGE("EntityGUI_SketcherDlg::OnPointSelected")
switch (getPnt2ConstructorId()){
case 1:
Group2Spin->SpinBox_DX->setValue( thePnt.X() );
Group2Spin->SpinBox_DY->setValue( thePnt.Y() );
break;
case 0:
Group3Spin->SpinBox_DX->setValue( thePnt.X() );
Group3Spin->SpinBox_DY->setValue( thePnt.Y() );
break;
case 2:
if (modifiers == Qt::MetaModifier){ // Select center with Meta key
Group4Spin->SpinBox_DX->setValue( thePnt.X() );
Group4Spin->SpinBox_DY->setValue( thePnt.Y() );
}
else{ // The select end point
Group4Spin->SpinBox_DZ->setValue( thePnt.X() );
Group4Spin->SpinBox_DS->setValue( thePnt.Y() );
}
break;
}
}
//=================================================================================
// function : ValueChangedInSpinBox()
@ -1502,9 +1538,10 @@ void EntityGUI_SketcherDlg::closeEvent( QCloseEvent* e )
//=================================================================================
void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
{
MESSAGE("EntityGUI_SketcherDlg::ValueChangedInSpinBox")
QObject* send = (QObject*)sender();
Standard_Real vx, vy, vz, vs, minRad;
vx = vy = vz = vs = minRad =0.0;
Standard_Real vx, vy, vz, vs, minRad, dx, dy;
vx = vy = vz = vs = minRad = dx = dy = 0.0;
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
@ -1535,7 +1572,15 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
vy = Group3Spin->SpinBox_DY->value(); vyStr = Group3Spin->SpinBox_DY->text();
vz = Group3Spin->SpinBox_DZ->value();
if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0) ) {
minRad = 0.5 * Sqrt(vx * vx + vy * vy); //Computation of the minimum acceptable radius for the arc calculation
if (mySketchType == PT_ABS_RADIUS){
dx = vx - myLastX1;
dy = vy - myLastY1;
}
else{
dx = vx;
dy = vy;
}
minRad = 0.5 * Sqrt(dx * dx + dy * dy); //Computation of the minimum acceptable radius for the arc calculation
if (aPrecision >= 0) // 'f' format in the QString
LastDecimal = aPrecision;
else // 'g' format in the Qstring
@ -1555,7 +1600,15 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue )
vy = newValue; vyStr = newValueStr;
vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text();
if ( (mySketchType == PT_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){
minRad = 0.5 * Sqrt(vx * vx + vy * vy); //Computation of the minimum acceptable radius for the arc calculation
if (mySketchType == PT_ABS_RADIUS){
dx = vx - myLastX1;
dy = vy - myLastY1;
}
else{
dx = vx;
dy = vy;
}
minRad = 0.5 * Sqrt(dx * dx + dy * dy); //Computation of the minimum acceptable radius for the arc calculation
if (aPrecision >= 0) // 'f' format in the QString
LastDecimal = aPrecision;
else // 'g' format in the QString
@ -2366,6 +2419,29 @@ void EntityGUI_SketcherDlg::FindLocalCS()
}
}
//rnc TODO
//=================================================================================
// function : getPnt1ConstructorId()
// purpose :
//=================================================================================
int EntityGUI_SketcherDlg::getPnt1ConstructorId() const
{
int buttonId = GroupPt->ButtonGroup->checkedId();
MESSAGE("buttonId = "<<buttonId)
return buttonId;
}
//=================================================================================
// function : getPnt2ConstructorId()
// purpose :
//=================================================================================
int EntityGUI_SketcherDlg::getPnt2ConstructorId() const
{
int buttonId = GroupPt2->ButtonGroup->checkedId();
MESSAGE("buttonId = "<<buttonId)
return buttonId;
}
//=================================================================================
// function : GetActiveLocalCS()
// purpose : Get Working plane

View File

@ -73,6 +73,9 @@ public:
bool eventFilter (QObject* object, QEvent* event);
bool acceptMouseEvent() const { return ( getPnt1ConstructorId() == 1 ); } //accept mouse event only on absolute selection mode
void OnPointSelected( Qt::KeyboardModifiers, const gp_Pnt& ); // called by EntityGUI::OnMousePress()
protected:
void initSpinBox( SalomeApp_DoubleSpinBox*,
double, double, double = 0.1,
@ -106,6 +109,8 @@ private:
bool createShapes( GEOM::GEOM_Object_ptr,
TopoDS_Shape&,
TopoDS_Shape& );
int getPnt1ConstructorId() const;
int getPnt2ConstructorId() const;
private:
int myConstructorId;
@ -168,6 +173,8 @@ private:
int myCheckFlag;
TopAbs_ShapeEnum myNeedType;
private:
enum SketchState { FIRST_POINT, NEXT_POINT };