1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : BasicGUI.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
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
38 #include <GeometryGUI.h>
39 #include "GeometryGUI_Operations.h"
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>
49 #include <BRep_Tool.hxx>
50 #include <ProjLib.hxx>
54 #include <QMouseEvent>
56 //=======================================================================
57 // function : BasicGUI()
58 // purpose : Constructor
59 //=======================================================================
60 BasicGUI::BasicGUI( GeometryGUI* parent )
65 //=======================================================================
66 // function : ~BasicGUI()
67 // purpose : Destructor
68 //=======================================================================
74 //=======================================================================
75 // function : OnGUIEvent()
77 //=======================================================================
78 bool BasicGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
80 getGeometryGUI()->EmitSignalDeactivateDialog();
83 switch ( theCommandID ) {
84 case GEOMOp::OpPoint: // POINT
85 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent );
87 case GEOMOp::OpLine: // LINE
88 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
90 case GEOMOp::OpCircle: // CIRCLE
91 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
93 case GEOMOp::OpEllipse: // ELLIPSE
94 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
96 case GEOMOp::OpArc: // ARC
97 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
99 case GEOMOp::OpVector: // VECTOR
100 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
102 case GEOMOp::OpPlane: // PLANE
103 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
105 case GEOMOp::OpCurve: // CURVE
106 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
108 case GEOMOp::OpLCS: // LOCAL COORDINATE SYSTEM
109 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
112 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
123 //=================================================================================
124 // function : 0nMousePress()
125 // purpose : [static] manage mouse events
126 //=================================================================================
127 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
129 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
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();
144 if ( pe->modifiers() == Qt::ShiftModifier )
145 ic->ShiftSelect(); // Append selection
147 ic->Select(); // New selection
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() ) );
156 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
157 aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
160 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
161 } // acceptMouseEvent()
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 )
173 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
174 aView->Eye( XEye, YEye, ZEye );
176 aView->At( XAt, YAt, ZAt );
177 gp_Pnt EyePoint( XEye, YEye, ZEye );
178 gp_Pnt AtPoint( XAt, YAt, ZAt );
180 gp_Vec EyeVector( EyePoint, AtPoint );
181 gp_Dir EyeDir( EyeVector );
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 );
188 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
189 gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
193 //=====================================================================================
195 //=====================================================================================
199 __declspec( dllexport )
201 GEOMGUI* GetLibGUI( GeometryGUI* parent )
203 return new BasicGUI( parent );