1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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
24 // File : BasicGUI.cxx
25 // Author : Damien COQUERET
30 #include "GeometryGUI.h"
32 #include "SUIT_Session.h"
33 #include "SUIT_Desktop.h"
34 #include "SUIT_ViewWindow.h"
35 #include "OCCViewer_ViewWindow.h"
36 #include "OCCViewer_ViewModel.h"
37 #include "OCCViewer_ViewManager.h"
38 #include "OCCViewer_ViewPort3d.h"
39 #include "utilities.h"
41 #include <Precision.hxx>
42 #include <BRep_Tool.hxx>
43 #include <ProjLib.hxx>
47 #include "BasicGUI_PointDlg.h" // Method POINT
48 #include "BasicGUI_LineDlg.h" // Method LINE
49 #include "BasicGUI_CircleDlg.h" // Method CIRCLE
50 #include "BasicGUI_EllipseDlg.h" // Method ELLIPSE
51 #include "BasicGUI_ArcDlg.h" // Method ARC
52 #include "BasicGUI_CurveDlg.h" // Method CURVE
53 #include "BasicGUI_VectorDlg.h" // Method VECTOR
54 #include "BasicGUI_PlaneDlg.h" // Method PLANE
55 #include "BasicGUI_WorkingPlaneDlg.h" // Method WORKING PLANE
56 #include "BasicGUI_MarkerDlg.h" // Method REPAIR
60 //=======================================================================
61 // function : BasicGUI()
62 // purpose : Constructor
63 //=======================================================================
64 BasicGUI::BasicGUI( GeometryGUI* parent ) :
69 //=======================================================================
70 // function : ~BasicGUI()
71 // purpose : Destructor
72 //=======================================================================
78 //=======================================================================
79 // function : OnGUIEvent()
81 //=======================================================================
82 bool BasicGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
84 getGeometryGUI()->EmitSignalDeactivateDialog();
87 switch ( theCommandID )
90 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent, "" );
93 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent, "" );
96 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent, "");
99 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent, "" );
102 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent, "" );
105 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent, "" );
108 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent, "");
110 case 4018: // WORKING PLANE
111 aDlg = new BasicGUI_WorkingPlaneDlg( getGeometryGUI(), parent, "" );
114 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent, "" );
117 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
120 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
131 //=================================================================================
132 // function : 0nMousePress()
133 // purpose : [static] manage mouse events
134 //=================================================================================
135 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
137 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
139 // Create Point dialog, OCC viewer
140 if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) &&
141 theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
142 pe->state() != Qt::ControlButton )
144 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
145 if ( aPntDlg->acceptMouseEvent() )
147 OCCViewer_Viewer* anOCCViewer =
148 ((OCCViewer_ViewManager*)(theViewWindow->getViewManager()))->getOCCViewer();
149 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
154 if ( pe->state() == Qt::ShiftButton )
155 ic->ShiftSelect(); // Append selection
157 ic->Select(); // New selection
160 if ( ic->MoreSelected() )
162 TopoDS_Shape aShape = ic->SelectedShape();
163 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
164 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
168 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
169 aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
172 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
173 } // acceptMouseEvent()
179 //=======================================================================
180 // function : ConvertClickToPoint()
181 // purpose : Returns the point clicked in 3D view
182 //=======================================================================
183 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView)
185 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
186 aView->Eye(XEye, YEye, ZEye);
188 aView->At(XAt, YAt, ZAt);
189 gp_Pnt EyePoint(XEye, YEye, ZEye);
190 gp_Pnt AtPoint(XAt, YAt, ZAt);
192 gp_Vec EyeVector(EyePoint, AtPoint);
193 gp_Dir EyeDir(EyeVector);
195 gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
196 Standard_Real X, Y, Z;
197 aView->Convert(x, y, X, Y, Z);
198 gp_Pnt ConvertedPoint(X, Y, Z);
200 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
201 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
205 //=====================================================================================
207 //=====================================================================================
211 GEOMGUI* GetLibGUI( GeometryGUI* parent )
213 return new BasicGUI( parent );