Back to index

salome-geom  6.5.0
BasicGUI.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : BasicGUI.cxx
00025 // Author : Damien COQUERET, Open CASCADE S.A.S.
00026 //
00027 #include "BasicGUI.h"
00028 
00029 #include "BasicGUI_PointDlg.h"        // Method POINT
00030 #include "BasicGUI_LineDlg.h"         // Method LINE
00031 #include "BasicGUI_CircleDlg.h"       // Method CIRCLE
00032 #include "BasicGUI_EllipseDlg.h"      // Method ELLIPSE
00033 #include "BasicGUI_ArcDlg.h"          // Method ARC
00034 #include "BasicGUI_CurveDlg.h"        // Method CURVE
00035 #include "BasicGUI_VectorDlg.h"       // Method VECTOR
00036 #include "BasicGUI_PlaneDlg.h"        // Method PLANE
00037 #include "BasicGUI_MarkerDlg.h"       // Method LOCAL COORDINATE SYSTEM
00038 
00039 #include <GeometryGUI.h>
00040 #include "GeometryGUI_Operations.h"
00041 
00042 #include <SUIT_Session.h>
00043 #include <SUIT_Desktop.h>
00044 #include <SUIT_ViewWindow.h>
00045 #include <OCCViewer_ViewWindow.h>
00046 #include <OCCViewer_ViewModel.h>
00047 #include <OCCViewer_ViewManager.h>
00048 #include <OCCViewer_ViewPort3d.h>
00049 
00050 #include <BRep_Tool.hxx>
00051 #include <ProjLib.hxx>
00052 #include <ElSLib.hxx>
00053 #include <TopoDS.hxx>
00054 
00055 #include <QMouseEvent>
00056 
00057 //=======================================================================
00058 // function : BasicGUI()
00059 // purpose  : Constructor
00060 //=======================================================================
00061 BasicGUI::BasicGUI( GeometryGUI* parent )
00062   : GEOMGUI( parent )
00063 {
00064 }
00065 
00066 //=======================================================================
00067 // function : ~BasicGUI()
00068 // purpose  : Destructor
00069 //=======================================================================
00070 BasicGUI::~BasicGUI()
00071 {
00072 }
00073 
00074 
00075 //=======================================================================
00076 // function : OnGUIEvent()
00077 // purpose  : 
00078 //=======================================================================
00079 bool BasicGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
00080 {
00081   getGeometryGUI()->EmitSignalDeactivateDialog();
00082   QDialog* aDlg = NULL;
00083 
00084   switch ( theCommandID ) {
00085   case GEOMOp::OpPoint:    // POINT
00086     aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent ); 
00087     break;
00088   case GEOMOp::OpLine:     // LINE
00089     aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
00090     break;
00091   case GEOMOp::OpCircle:   // CIRCLE
00092     aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
00093     break;
00094   case GEOMOp::OpEllipse:  // ELLIPSE
00095     aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
00096     break;
00097   case GEOMOp::OpArc:      // ARC
00098     aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
00099     break ;
00100   case GEOMOp::OpVector:   // VECTOR
00101     aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
00102     break;
00103   case GEOMOp::OpPlane:    // PLANE
00104     aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
00105     break;
00106   case GEOMOp::OpCurve:    // CURVE
00107     aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
00108     break;
00109   case GEOMOp::OpLCS:      // LOCAL COORDINATE SYSTEM
00110     aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
00111     break;      
00112   default:
00113     SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
00114     break;
00115   }
00116   
00117   if ( aDlg != NULL )
00118     aDlg->show();
00119   
00120   return true;
00121 }
00122 
00123 
00124 //=================================================================================
00125 // function : 0nMousePress()
00126 // purpose  : [static] manage mouse events
00127 //=================================================================================
00128 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
00129 {
00130   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
00131 
00132   // Create Point dialog, OCC viewer 
00133   if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "BasicGUI_PointDlg" ) == 0 ) &&
00134        theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
00135        pe->modifiers() != Qt::ControlModifier ) {
00136     BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
00137     if ( aPntDlg->acceptMouseEvent() ) {
00138       OCCViewer_Viewer* anOCCViewer =
00139         ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
00140       Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
00141 
00142       gp_Pnt aPnt;    
00143 
00144       ic->InitSelected();
00145       if ( pe->modifiers() == Qt::ShiftModifier )
00146         ic->ShiftSelect();  // Append selection
00147       else
00148         ic->Select();       // New selection
00149 
00150       ic->InitSelected();
00151       if ( ic->MoreSelected() ) {
00152         TopoDS_Shape aShape = ic->SelectedShape();
00153         if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
00154           aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
00155       }
00156       else {
00157         OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
00158         aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
00159       }
00160 
00161       aPntDlg->OnPointSelected( aPnt );  // "feed" the point to point construction dialog
00162     } // acceptMouseEvent()
00163   }
00164   return false;
00165 }
00166 
00167 
00168 //=======================================================================
00169 // function : ConvertClickToPoint()
00170 // purpose  : Returns the point clicked in 3D view
00171 //=======================================================================
00172 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
00173 {
00174   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
00175   aView->Eye( XEye, YEye, ZEye );
00176 
00177   aView->At( XAt, YAt, ZAt );
00178   gp_Pnt EyePoint( XEye, YEye, ZEye );
00179   gp_Pnt AtPoint( XAt, YAt, ZAt );
00180 
00181   gp_Vec EyeVector( EyePoint, AtPoint );
00182   gp_Dir EyeDir( EyeVector );
00183 
00184   gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
00185   Standard_Real X, Y, Z;
00186   aView->Convert( x, y, X, Y, Z );
00187   gp_Pnt ConvertedPoint( X, Y, Z );
00188 
00189   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
00190   gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
00191   return ResultPoint;
00192 }
00193 
00194 //=====================================================================================
00195 // EXPORTED METHODS
00196 //=====================================================================================
00197 extern "C"
00198 {
00199 #ifdef WIN32
00200   __declspec( dllexport )
00201 #endif
00202   GEOMGUI* GetLibGUI( GeometryGUI* parent )
00203   {
00204     return new BasicGUI( parent );
00205   }
00206 }