]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI.cxx
Salome HOME
Improve actions management
[modules/geom.git] / src / BasicGUI / BasicGUI.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BasicGUI.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
25 //
26 #include "BasicGUI.h"
27
28 #include "BasicGUI_PointDlg.h"        // Method POINT
29 #include "BasicGUI_LineDlg.h"         // Method LINE
30 #include "BasicGUI_CircleDlg.h"       // Method CIRCLE
31 #include "BasicGUI_EllipseDlg.h"      // Method ELLIPSE
32 #include "BasicGUI_ArcDlg.h"          // Method ARC
33 #include "BasicGUI_CurveDlg.h"        // Method CURVE
34 #include "BasicGUI_VectorDlg.h"       // Method VECTOR
35 #include "BasicGUI_PlaneDlg.h"        // Method PLANE
36 #include "BasicGUI_MarkerDlg.h"       // Method LOCAL COORDINATE SYSTEM
37
38 #include <GeometryGUI.h>
39 #include "GeometryGUI_Operations.h"
40
41 #include <SUIT_Session.h>
42 #include <SUIT_Desktop.h>
43 #include <SUIT_ViewWindow.h>
44 #include <OCCViewer_ViewWindow.h>
45 #include <OCCViewer_ViewModel.h>
46 #include <OCCViewer_ViewManager.h>
47 #include <OCCViewer_ViewPort3d.h>
48
49 #include <BRep_Tool.hxx>
50 #include <ProjLib.hxx>
51 #include <ElSLib.hxx>
52 #include <TopoDS.hxx>
53
54 #include <QMouseEvent>
55
56 //=======================================================================
57 // function : BasicGUI()
58 // purpose  : Constructor
59 //=======================================================================
60 BasicGUI::BasicGUI( GeometryGUI* parent )
61   : GEOMGUI( parent )
62 {
63 }
64
65 //=======================================================================
66 // function : ~BasicGUI()
67 // purpose  : Destructor
68 //=======================================================================
69 BasicGUI::~BasicGUI()
70 {
71 }
72
73
74 //=======================================================================
75 // function : OnGUIEvent()
76 // purpose  : 
77 //=======================================================================
78 bool BasicGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
79 {
80   getGeometryGUI()->EmitSignalDeactivateDialog();
81   QDialog* aDlg = NULL;
82
83   switch ( theCommandID ) {
84   case GEOMOp::OpPoint:    // POINT
85     aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent ); 
86     break;
87   case GEOMOp::OpLine:     // LINE
88     aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
89     break;
90   case GEOMOp::OpCircle:   // CIRCLE
91     aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
92     break;
93   case GEOMOp::OpEllipse:  // ELLIPSE
94     aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
95     break;
96   case GEOMOp::OpArc:      // ARC
97     aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
98     break ;
99   case GEOMOp::OpVector:   // VECTOR
100     aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
101     break;
102   case GEOMOp::OpPlane:    // PLANE
103     aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
104     break;
105   case GEOMOp::OpCurve:    // CURVE
106     aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
107     break;
108   case GEOMOp::OpLCS:      // LOCAL COORDINATE SYSTEM
109     aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
110     break;      
111   default:
112     SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
113     break;
114   }
115   
116   if ( aDlg != NULL )
117     aDlg->show();
118   
119   return true;
120 }
121
122
123 //=================================================================================
124 // function : 0nMousePress()
125 // purpose  : [static] manage mouse events
126 //=================================================================================
127 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
128 {
129   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
130
131   // Create Point dialog, OCC viewer 
132   if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "BasicGUI_PointDlg" ) == 0 ) &&
133        theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
134        pe->modifiers() != Qt::ControlModifier ) {
135     BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
136     if ( aPntDlg->acceptMouseEvent() ) {
137       OCCViewer_Viewer* anOCCViewer =
138         ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
139       Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
140
141       gp_Pnt aPnt;    
142
143       ic->InitSelected();
144       if ( pe->modifiers() == Qt::ShiftModifier )
145         ic->ShiftSelect();  // Append selection
146       else
147         ic->Select();       // New selection
148
149       ic->InitSelected();
150       if ( ic->MoreSelected() ) {
151         TopoDS_Shape aShape = ic->SelectedShape();
152         if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
153           aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
154       }
155       else {
156         OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
157         aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
158       }
159
160       aPntDlg->OnPointSelected( aPnt );  // "feed" the point to point construction dialog
161     } // acceptMouseEvent()
162   }
163   return false;
164 }
165
166
167 //=======================================================================
168 // function : ConvertClickToPoint()
169 // purpose  : Returns the point clicked in 3D view
170 //=======================================================================
171 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
172 {
173   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
174   aView->Eye( XEye, YEye, ZEye );
175
176   aView->At( XAt, YAt, ZAt );
177   gp_Pnt EyePoint( XEye, YEye, ZEye );
178   gp_Pnt AtPoint( XAt, YAt, ZAt );
179
180   gp_Vec EyeVector( EyePoint, AtPoint );
181   gp_Dir EyeDir( EyeVector );
182
183   gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
184   Standard_Real X, Y, Z;
185   aView->Convert( x, y, X, Y, Z );
186   gp_Pnt ConvertedPoint( X, Y, Z );
187
188   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
189   gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
190   return ResultPoint;
191 }
192
193 //=====================================================================================
194 // EXPORTED METHODS
195 //=====================================================================================
196 extern "C"
197 {
198 #ifdef WIN32
199   __declspec( dllexport )
200 #endif
201   GEOMGUI* GetLibGUI( GeometryGUI* parent )
202   {
203     return new BasicGUI( parent );
204   }
205 }