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_WorkingPlaneDlg.h" // Method WORKING PLANE
37 #include "BasicGUI_MarkerDlg.h" // Method REPAIR
39 #include <GeometryGUI.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 ) {
85 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent );
88 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
91 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
94 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
97 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
100 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
103 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
105 /* case 4018: // WORKING PLANE
106 aDlg = new BasicGUI_WorkingPlaneDlg( getGeometryGUI(), parent );
107 break;*/ // DEPRECATED!
109 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
112 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
115 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
126 //=================================================================================
127 // function : 0nMousePress()
128 // purpose : [static] manage mouse events
129 //=================================================================================
130 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
132 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
134 // Create Point dialog, OCC viewer
135 if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "BasicGUI_PointDlg" ) == 0 ) &&
136 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
137 pe->modifiers() != Qt::ControlModifier ) {
138 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
139 if ( aPntDlg->acceptMouseEvent() ) {
140 OCCViewer_Viewer* anOCCViewer =
141 ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
142 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
147 if ( pe->modifiers() == Qt::ShiftModifier )
148 ic->ShiftSelect(); // Append selection
150 ic->Select(); // New selection
153 if ( ic->MoreSelected() ) {
154 TopoDS_Shape aShape = ic->SelectedShape();
155 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
156 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
159 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
160 aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
163 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
164 } // acceptMouseEvent()
170 //=======================================================================
171 // function : ConvertClickToPoint()
172 // purpose : Returns the point clicked in 3D view
173 //=======================================================================
174 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView )
176 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
177 aView->Eye( XEye, YEye, ZEye );
179 aView->At( XAt, YAt, ZAt );
180 gp_Pnt EyePoint( XEye, YEye, ZEye );
181 gp_Pnt AtPoint( XAt, YAt, ZAt );
183 gp_Vec EyeVector( EyePoint, AtPoint );
184 gp_Dir EyeDir( EyeVector );
186 gp_Pln PlaneOfTheView = gp_Pln( AtPoint, EyeDir );
187 Standard_Real X, Y, Z;
188 aView->Convert( x, y, X, Y, Z );
189 gp_Pnt ConvertedPoint( X, Y, Z );
191 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project( PlaneOfTheView, ConvertedPoint );
192 gp_Pnt ResultPoint = ElSLib::Value( ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView );
196 //=====================================================================================
198 //=====================================================================================
202 __declspec( dllexport )
204 GEOMGUI* GetLibGUI( GeometryGUI* parent )
206 return new BasicGUI( parent );