From: gdd Date: Tue, 28 Jun 2011 12:48:30 +0000 (+0000) Subject: rnc: In the frame of the feature EDF 1900, made possible to define a point by clickin... X-Git-Tag: Before_opencv_branch_20110913~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=66a0b44a07cd9e3b626dcfa1297a4612e8465a42;p=modules%2Fgeom.git 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 --- diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index b46892c12..a6b0bdf23 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -29,14 +29,23 @@ #include #include "GeometryGUI_Operations.h" +#include #include #include #include #include +#include +#include #include #include #include +#include +#include +#include +#include + +#include #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; diff --git a/src/EntityGUI/EntityGUI.h b/src/EntityGUI/EntityGUI.h index 988f5af85..cfc0addef 100644 --- a/src/EntityGUI/EntityGUI.h +++ b/src/EntityGUI/EntityGUI.h @@ -32,9 +32,11 @@ #include #include +#include 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 diff --git a/src/EntityGUI/EntityGUI_SketcherDlg.cxx b/src/EntityGUI/EntityGUI_SketcherDlg.cxx index b2b9a06ad..92e9edfc2 100644 --- a/src/EntityGUI/EntityGUI_SketcherDlg.cxx +++ b/src/EntityGUI/EntityGUI_SketcherDlg.cxx @@ -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 = "<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,17 +1572,25 @@ 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; + LastDecimal = aPrecision; else // 'g' format in the Qstring - LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); + LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place if ( Abs(vz) < minRad){ - if (vz < 0.0) - Group3Spin->SpinBox_DZ->setValue( - minRad ); - else - Group3Spin->SpinBox_DZ->setValue( minRad ); + if (vz < 0.0) + Group3Spin->SpinBox_DZ->setValue( - minRad ); + else + Group3Spin->SpinBox_DZ->setValue( minRad ); } } vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text(); @@ -1554,18 +1599,26 @@ void EntityGUI_SketcherDlg::ValueChangedInSpinBox( double newValue ) vx = Group3Spin->SpinBox_DX->value(); vxStr = Group3Spin->SpinBox_DX->text(); 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_REL_RADIUS || mySketchType == PT_ABS_RADIUS) && (vx != 0 || vy != 0)){ + 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; + LastDecimal = aPrecision; else // 'g' format in the QString - LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); - minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place + LastDecimal = qAbs( aPrecision ) - ceil( log10(minRad) ); + minRad = ceil(pow(10,LastDecimal) * minRad) / pow(10,LastDecimal); // Rounded up at the last allowed decimal place if ( Abs(vz) < minRad){ - if (vz < 0.0) - Group3Spin->SpinBox_DZ->setValue( - minRad ); - else - Group3Spin->SpinBox_DZ->setValue( minRad ); + if (vz < 0.0) + Group3Spin->SpinBox_DZ->setValue( - minRad ); + else + Group3Spin->SpinBox_DZ->setValue( minRad ); } } vz = Group3Spin->SpinBox_DZ->value(); vzStr = Group3Spin->SpinBox_DZ->text(); @@ -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 = "<ButtonGroup->checkedId(); + MESSAGE("buttonId = "< myLCSList; - int myCheckFlag; + int myCheckFlag; + + TopAbs_ShapeEnum myNeedType; private: enum SketchState { FIRST_POINT, NEXT_POINT };