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 "QAD_RightFrame.h"
34 #include "QAD_Desktop.h"
35 #include "OCCViewer_Viewer3d.h"
36 #include "OCCViewer_ViewPort3d.h"
37 #include "SALOMEGUI_QtCatchCorbaException.hxx"
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
58 BasicGUI* BasicGUI::myGUIObject = 0;
60 //=======================================================================
61 // function : GetBasicGUI()
62 // purpose : Get the only BasicGUI object [ static ]
63 //=======================================================================
64 BasicGUI* BasicGUI::GetBasicGUI()
66 if ( myGUIObject == 0 ) {
67 myGUIObject = new BasicGUI();
72 //=======================================================================
73 // function : BasicGUI()
74 // purpose : Constructor
75 //=======================================================================
76 BasicGUI::BasicGUI() :
82 //=======================================================================
83 // function : ~BasicGUI()
84 // purpose : Destructor
85 //=======================================================================
91 //=======================================================================
92 // function : OnGUIEvent()
94 //=======================================================================
95 bool BasicGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
97 GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
98 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
101 switch ( theCommandID )
105 Handle(AIS_InteractiveContext) ic;
106 QAD_StudyFrame* aFrame = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
107 if ( aFrame->getTypeView() == VIEW_OCC)
109 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)aFrame->getRightFrame()->getViewFrame())->getViewer();
110 ic = v3d->getAISContext();
112 aDlg = new BasicGUI_PointDlg( parent, "", Sel );
116 aDlg = new BasicGUI_LineDlg(parent, "", Sel);
119 aDlg = new BasicGUI_CircleDlg(parent, "", Sel);
121 case 4014: // ELLIPSE
122 aDlg = new BasicGUI_EllipseDlg(parent, "", Sel);
125 aDlg = new BasicGUI_ArcDlg(parent, "", Sel);
128 aDlg = new BasicGUI_VectorDlg(parent, "", Sel);
131 aDlg = new BasicGUI_PlaneDlg(parent, "", Sel);
133 case 4018: // WORKING PLANE
134 aDlg = new BasicGUI_WorkingPlaneDlg(parent, "", Sel);
137 aDlg = new BasicGUI_CurveDlg( parent, "", Sel );
140 aDlg = new BasicGUI_MarkerDlg( parent, Sel );
143 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
154 //=================================================================================
155 // function : 0nMousePress()
156 // purpose : [static] manage mouse events
157 //=================================================================================
158 bool BasicGUI::OnMousePress( QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* theFrame )
160 QDialog* aDlg = GeometryGUI::GetGeomGUI()->GetActiveDialogBox();
162 // Create Point dialog, OCC viewer
163 if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theFrame->getTypeView() == VIEW_OCC )
165 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
166 if ( aPntDlg->acceptMouseEvent() )
168 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)theFrame->getRightFrame()->getViewFrame())->getViewer();
169 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
174 if( pe->state() == Qt::ShiftButton )
175 v3d->getAISSelector()->shiftSelect(); // Append selection
177 v3d->getAISSelector()->select(); // New selection
180 if( ic->MoreSelected() )
182 TopoDS_Shape aShape = ic->SelectedShape();
183 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
184 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
188 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)theFrame->getRightFrame()->getViewFrame())->getViewPort();
189 aPnt = ConvertClickToPoint( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() );
192 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
193 } // acceptMouseEvent()
199 //=======================================================================
200 // function : ConvertClickToPoint()
201 // purpose : Returns the point clicked in 3D view
202 //=======================================================================
203 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView)
205 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
206 aView->Eye(XEye, YEye, ZEye);
208 aView->At(XAt, YAt, ZAt);
209 gp_Pnt EyePoint(XEye, YEye, ZEye);
210 gp_Pnt AtPoint(XAt, YAt, ZAt);
212 gp_Vec EyeVector(EyePoint, AtPoint);
213 gp_Dir EyeDir(EyeVector);
215 gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
216 Standard_Real X, Y, Z;
217 aView->Convert(x, y, X, Y, Z);
218 gp_Pnt ConvertedPoint(X, Y, Z);
220 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
221 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
225 //=====================================================================================
227 //=====================================================================================
232 return BasicGUI::GetBasicGUI();