1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
29 #include "BasicGUI_PointDlg.h" // Method POINT
30 #include "BasicGUI_LineDlg.h" // Method LINE
31 #include "BasicGUI_CircleDlg.h" // Method CIRCLE
32 #include "BasicGUI_EllipseDlg.h" // Method ELLIPSE
33 #include "BasicGUI_ArcDlg.h" // Method ARC
34 #include "BasicGUI_CurveDlg.h" // Method CURVE
35 #include "BasicGUI_VectorDlg.h" // Method VECTOR
36 #include "BasicGUI_PlaneDlg.h" // Method PLANE
37 #include "BasicGUI_MarkerDlg.h" // Method LOCAL COORDINATE SYSTEM
39 #include <GeometryGUI.h>
40 #include "GeometryGUI_Operations.h"
42 #include <SUIT_Session.h>
43 #include <SUIT_Desktop.h>
44 #include <SUIT_ViewWindow.h>
45 #include <OCCViewer_ViewWindow.h>
46 #include <OCCViewer_ViewModel.h>
47 #include <OCCViewer_ViewManager.h>
48 #include <OCCViewer_ViewPort3d.h>
50 #include <BRep_Tool.hxx>
51 #include <ProjLib.hxx>
55 #include <QMouseEvent>
57 //=======================================================================
58 // function : BasicGUI()
59 // purpose : Constructor
60 //=======================================================================
61 BasicGUI::BasicGUI( GeometryGUI* parent )
66 //=======================================================================
67 // function : ~BasicGUI()
68 // purpose : Destructor
69 //=======================================================================
75 //=======================================================================
76 // function : OnGUIEvent()
78 //=======================================================================
79 bool BasicGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
81 getGeometryGUI()->EmitSignalDeactivateDialog();
84 switch ( theCommandID ) {
85 case GEOMOp::OpPoint: // POINT
86 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent );
88 case GEOMOp::OpLine: // LINE
89 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
91 case GEOMOp::OpCircle: // CIRCLE
92 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
94 case GEOMOp::OpEllipse: // ELLIPSE
95 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
97 case GEOMOp::OpArc: // ARC
98 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
100 case GEOMOp::OpVector: // VECTOR
101 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
103 case GEOMOp::OpPlane: // PLANE
104 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
106 case GEOMOp::OpCurve: // CURVE
107 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
109 case GEOMOp::OpLCS: // LOCAL COORDINATE SYSTEM
110 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
113 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
124 //=================================================================================
125 // function : 0nMousePress()
126 // purpose : [static] manage mouse events
127 //=================================================================================
128 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
130 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
132 // Create Point dialog, OCC viewer
133 if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "BasicGUI_PointDlg" ) == 0 ) &&
134 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
135 pe->modifiers() != Qt::ControlModifier ) {
136 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
137 if ( aPntDlg->acceptMouseEvent() ) {
138 OCCViewer_Viewer* anOCCViewer =
139 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
140 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
145 if ( pe->modifiers() == Qt::ShiftModifier )
146 ic->ShiftSelect(); // Append selection
148 ic->Select(); // New selection
151 if ( ic->MoreSelected() ) {
152 TopoDS_Shape aShape = ic->SelectedShape();
153 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
154 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
157 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
158 aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
161 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
162 } // acceptMouseEvent()
168 //=======================================================================
169 // function : ConvertClickToPoint()
170 // purpose : Returns the point clicked in 3D view
171 //=======================================================================
172 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
174 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
175 aView->Eye( XEye, YEye, ZEye );
177 aView->At( XAt, YAt, ZAt );
178 gp_Pnt EyePoint( XEye, YEye, ZEye );
179 gp_Pnt AtPoint( XAt, YAt, ZAt );
181 gp_Vec EyeVector( EyePoint, AtPoint );
182 gp_Dir EyeDir( EyeVector );
184 gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
185 Standard_Real X, Y, Z;
186 aView->Convert( x, y, X, Y, Z );
187 gp_Pnt ConvertedPoint( X, Y, Z );
189 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
190 gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
194 //=====================================================================================
196 //=====================================================================================
200 __declspec( dllexport )
202 GEOMGUI* GetLibGUI( GeometryGUI* parent )
204 return new BasicGUI( parent );