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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : BasicGUI.cxx
25 // Author : Damien COQUERET
31 #include "GeometryGUI.h"
33 #include "SUIT_Session.h"
34 #include "SUIT_Desktop.h"
35 #include "SUIT_ViewWindow.h"
36 #include "OCCViewer_ViewWindow.h"
37 #include "OCCViewer_ViewModel.h"
38 #include "OCCViewer_ViewManager.h"
39 #include "OCCViewer_ViewPort3d.h"
40 #include "utilities.h"
42 #include <Precision.hxx>
43 #include <BRep_Tool.hxx>
44 #include <ProjLib.hxx>
48 #include "BasicGUI_PointDlg.h" // Method POINT
49 #include "BasicGUI_LineDlg.h" // Method LINE
50 #include "BasicGUI_CircleDlg.h" // Method CIRCLE
51 #include "BasicGUI_EllipseDlg.h" // Method ELLIPSE
52 #include "BasicGUI_ArcDlg.h" // Method ARC
53 #include "BasicGUI_CurveDlg.h" // Method CURVE
54 #include "BasicGUI_VectorDlg.h" // Method VECTOR
55 #include "BasicGUI_PlaneDlg.h" // Method PLANE
56 #include "BasicGUI_WorkingPlaneDlg.h" // Method WORKING PLANE
57 #include "BasicGUI_MarkerDlg.h" // Method REPAIR
59 BasicGUI* BasicGUI::myGUIObject = 0;
61 //=======================================================================
62 // function : GetBasicGUI()
63 // purpose : Get the only BasicGUI object [ static ]
64 //=======================================================================
65 BasicGUI* BasicGUI::GetBasicGUI( GeometryGUI* parent )
67 if ( myGUIObject == 0 ) {
68 myGUIObject = new BasicGUI( parent );
73 //=======================================================================
74 // function : BasicGUI()
75 // purpose : Constructor
76 //=======================================================================
77 BasicGUI::BasicGUI( GeometryGUI* parent ) :
83 //=======================================================================
84 // function : ~BasicGUI()
85 // purpose : Destructor
86 //=======================================================================
92 //=======================================================================
93 // function : OnGUIEvent()
95 //=======================================================================
96 bool BasicGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
98 getGeometryGUI()->EmitSignalDeactivateDialog();
101 switch ( theCommandID )
104 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent, "" );
107 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent, "" );
110 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent, "");
112 case 4014: // ELLIPSE
113 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent, "" );
116 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent, "" );
119 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent, "" );
122 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent, "");
124 case 4018: // WORKING PLANE
125 aDlg = new BasicGUI_WorkingPlaneDlg( getGeometryGUI(), parent, "" );
128 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent, "" );
131 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
134 SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
145 //=================================================================================
146 // function : 0nMousePress()
147 // purpose : [static] manage mouse events
148 //=================================================================================
149 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
151 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
153 // Create Point dialog, OCC viewer
154 if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && pe->state() != Qt::ControlButton )
156 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
157 if ( aPntDlg->acceptMouseEvent() )
159 OCCViewer_Viewer* anOCCViewer = ((OCCViewer_ViewManager*)(theViewWindow->getViewManager()))->getOCCViewer();
160 Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
165 if( pe->state() == Qt::ShiftButton )
166 ic->ShiftSelect(); // Append selection
168 ic->Select(); // New selection
171 if( ic->MoreSelected() )
173 TopoDS_Shape aShape = ic->SelectedShape();
174 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
175 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
179 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
180 aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
183 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
184 } // acceptMouseEvent()
190 //=======================================================================
191 // function : ConvertClickToPoint()
192 // purpose : Returns the point clicked in 3D view
193 //=======================================================================
194 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView)
196 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
197 aView->Eye(XEye, YEye, ZEye);
199 aView->At(XAt, YAt, ZAt);
200 gp_Pnt EyePoint(XEye, YEye, ZEye);
201 gp_Pnt AtPoint(XAt, YAt, ZAt);
203 gp_Vec EyeVector(EyePoint, AtPoint);
204 gp_Dir EyeDir(EyeVector);
206 gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
207 Standard_Real X, Y, Z;
208 aView->Convert(x, y, X, Y, Z);
209 gp_Pnt ConvertedPoint(X, Y, Z);
211 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
212 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
216 //=====================================================================================
218 //=====================================================================================
221 GEOMGUI* GetLibGUI( GeometryGUI* parent )
223 return BasicGUI::GetBasicGUI( parent );