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 : GetBasicGUI()
62 // purpose : Get the only BasicGUI object [ static ]
63 //=======================================================================
64 BasicGUI* BasicGUI::GetBasicGUI( GeometryGUI* parent )
66 return new BasicGUI( parent );
69 //=======================================================================
70 // function : BasicGUI()
71 // purpose : Constructor
72 //=======================================================================
73 BasicGUI::BasicGUI( GeometryGUI* parent ) :
78 //=======================================================================
79 // function : ~BasicGUI()
80 // purpose : Destructor
81 //=======================================================================
87 //=======================================================================
88 // function : OnGUIEvent()
90 //=======================================================================
91 bool BasicGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
93 getGeometryGUI()->EmitSignalDeactivateDialog();
96 switch ( theCommandID )
99 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent, "" );
102 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent, "" );
105 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent, "");
107 case 4014: // ELLIPSE
108 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent, "" );
111 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent, "" );
114 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent, "" );
117 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent, "");
119 case 4018: // WORKING PLANE
120 aDlg = new BasicGUI_WorkingPlaneDlg( getGeometryGUI(), parent, "" );
123 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent, "" );
126 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
129 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
140 //=================================================================================
141 // function : 0nMousePress()
142 // purpose : [static] manage mouse events
143 //=================================================================================
144 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
146 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
148 // Create Point dialog, OCC viewer
149 if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && pe->state() != Qt::ControlButton )
151 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
152 if ( aPntDlg->acceptMouseEvent() )
154 OCCViewer_Viewer* anOCCViewer = ((OCCViewer_ViewManager*)(theViewWindow->getViewManager()))->getOCCViewer();
155 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
160 if( pe->state() == Qt::ShiftButton )
161 ic->ShiftSelect(); // Append selection
163 ic->Select(); // New selection
166 if( ic->MoreSelected() )
168 TopoDS_Shape aShape = ic->SelectedShape();
169 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
170 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
174 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
175 aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
178 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
179 } // acceptMouseEvent()
185 //=======================================================================
186 // function : ConvertClickToPoint()
187 // purpose : Returns the point clicked in 3D view
188 //=======================================================================
189 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView)
191 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
192 aView->Eye(XEye, YEye, ZEye);
194 aView->At(XAt, YAt, ZAt);
195 gp_Pnt EyePoint(XEye, YEye, ZEye);
196 gp_Pnt AtPoint(XAt, YAt, ZAt);
198 gp_Vec EyeVector(EyePoint, AtPoint);
199 gp_Dir EyeDir(EyeVector);
201 gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
202 Standard_Real X, Y, Z;
203 aView->Convert(x, y, X, Y, Z);
204 gp_Pnt ConvertedPoint(X, Y, Z);
206 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
207 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
211 //=====================================================================================
213 //=====================================================================================
217 __declspec( dllexport )
219 GEOMGUI* GetLibGUI( GeometryGUI* parent )
221 return BasicGUI::GetBasicGUI( parent );