X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FEntityGUI%2FEntityGUI.cxx;h=5fa025aa7b946203d8d8ac3bc33f788e0659a035;hb=f91bad6fb6e89c189a2e6a146f1d6419eeb8ea77;hp=ccb9f8e9693341fb440d02cd833089fd891ec5cf;hpb=004197ec827d52331f0d529202eb4e52a1c4388f;p=modules%2Fgeom.git diff --git a/src/EntityGUI/EntityGUI.cxx b/src/EntityGUI/EntityGUI.cxx index ccb9f8e96..5fa025aa7 100644 --- a/src/EntityGUI/EntityGUI.cxx +++ b/src/EntityGUI/EntityGUI.cxx @@ -1,23 +1,23 @@ -// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE // -// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, -// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // // GEOM GEOMGUI : GUI for Geometry component @@ -29,18 +29,30 @@ #include #include "GeometryGUI_Operations.h" +#include #include #include #include #include +#include +#include #include #include #include +#include +#include +#include +#include -#include "EntityGUI_SketcherDlg.h" // Sketcher -#include "EntityGUI_3DSketcherDlg.h" // Sketcher -#include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE +#include +#include + +#include "EntityGUI_SketcherDlg.h" // Sketcher +#include "EntityGUI_3DSketcherDlg.h" // Sketcher +#include "EntityGUI_SubShapeDlg.h" // Method SUBSHAPE +#include "EntityGUI_FeatureDetectorDlg.h" // Feature Detection +#include "EntityGUI_PictureImportDlg.h" // Import Picture in viewer //======================================================================= // function : EntityGUI() @@ -84,6 +96,14 @@ bool EntityGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) case GEOMOp::OpExplode: // EXPLODE aDlg = new EntityGUI_SubShapeDlg( getGeometryGUI(), parent ); break; +#ifdef WITH_OPENCV + case GEOMOp::OpFeatureDetect: // FEATURE DETECTION + aDlg = new EntityGUI_FeatureDetectorDlg( getGeometryGUI(), parent ); + break; +#endif + case GEOMOp::OpPictureImport: // IMPORT PICTURE IN VIEWER + aDlg = new EntityGUI_PictureImportDlg( getGeometryGUI(), parent ); + break; default: app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); break; @@ -94,6 +114,143 @@ 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 && + theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && + pe->modifiers() != Qt::ControlModifier ) { + + gp_Pnt aPnt; + + if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_SketcherDlg" ) == 0 ) + { + EntityGUI_SketcherDlg* aSketcherDlg = (EntityGUI_SketcherDlg*) aDlg; + if ( aSketcherDlg->acceptMouseEvent() ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + 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(); + aSketcherDlg->OnPointSelected( modifiers, aPnt ); // "feed" the point to point construction dialog + } // acceptMouseEvent() + } +#ifdef WITH_OPENCV + if ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) + { + EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg; + if ( aCornerDlg->acceptMouseEvent() ) { + OCCViewer_Viewer* anOCCViewer = + ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer(); + Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext(); + + ic->InitSelected(); + ic->Select(); // New selection + + ic->InitSelected(); + TopoDS_Shape aShape; + if ( ic->MoreSelected() ) + 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() ); + } + +// aCornerDlg->OnPointSelected( aPnt ); // "feed" the point to corner detection dialog + +// QPoint start = QPoint(pe->x(),pe->y()); + aCornerDlg->setStartPnt( aPnt ); + } // acceptMouseEvent() + + } +#endif + } + + return false; +} + +//================================================================================= +// function : 0nMouseRelease() +// purpose : [static] manage mouse events +//================================================================================= +bool EntityGUI::OnMouseRelease( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow ) +{ + MESSAGE("EntityGUI::OnMouseRelease") + QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox(); +#ifdef WITH_OPENCV + if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "EntityGUI_FeatureDetectorDlg" ) == 0 ) && + theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && + pe->modifiers() != Qt::ControlModifier ) + { + EntityGUI_FeatureDetectorDlg* aCornerDlg = (EntityGUI_FeatureDetectorDlg*) aDlg; + + gp_Pnt aPnt; + + if ( aCornerDlg->acceptMouseEvent() ) + { +// QPoint end = QPoint(pe->x(),pe->y()); + OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort(); + aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() ); + aCornerDlg->setEndPnt( aPnt ); + } + } +#endif + 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 +258,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 +307,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;