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_ViewFrame.h"
37 #include "OCCViewer_AISSelector.h"
38 #include "OCCViewer_ViewPort3d.h"
39 #include "SALOMEGUI_QtCatchCorbaException.hxx"
41 #include "utilities.h"
43 #include <Precision.hxx>
44 #include <BRep_Tool.hxx>
45 #include <ProjLib.hxx>
49 #include "BasicGUI_PointDlg.h" // Method POINT
50 #include "BasicGUI_LineDlg.h" // Method LINE
51 #include "BasicGUI_CircleDlg.h" // Method CIRCLE
52 #include "BasicGUI_EllipseDlg.h" // Method ELLIPSE
53 #include "BasicGUI_ArcDlg.h" // Method ARC
54 #include "BasicGUI_CurveDlg.h" // Method CURVE
55 #include "BasicGUI_VectorDlg.h" // Method VECTOR
56 #include "BasicGUI_PlaneDlg.h" // Method PLANE
57 #include "BasicGUI_WorkingPlaneDlg.h" // Method WORKING PLANE
58 #include "BasicGUI_MarkerDlg.h" // Method REPAIR
60 BasicGUI* BasicGUI::myGUIObject = 0;
62 //=======================================================================
63 // function : GetBasicGUI()
64 // purpose : Get the only BasicGUI object [ static ]
65 //=======================================================================
66 BasicGUI* BasicGUI::GetBasicGUI()
68 if ( myGUIObject == 0 ) {
69 myGUIObject = new BasicGUI();
74 //=======================================================================
75 // function : BasicGUI()
76 // purpose : Constructor
77 //=======================================================================
78 BasicGUI::BasicGUI() :
84 //=======================================================================
85 // function : ~BasicGUI()
86 // purpose : Destructor
87 //=======================================================================
93 //=======================================================================
94 // function : OnGUIEvent()
96 //=======================================================================
97 bool BasicGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
99 GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
100 SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
101 QDialog* aDlg = NULL;
103 switch ( theCommandID )
107 Handle(AIS_InteractiveContext) ic;
108 QAD_StudyFrame* aFrame = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
109 if ( aFrame->getTypeView() == VIEW_OCC)
111 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)aFrame->getRightFrame()->getViewFrame())->getViewer();
112 ic = v3d->getAISContext();
114 aDlg = new BasicGUI_PointDlg( parent, "", Sel );
118 aDlg = new BasicGUI_LineDlg(parent, "", Sel);
121 aDlg = new BasicGUI_CircleDlg(parent, "", Sel);
123 case 4014: // ELLIPSE
124 aDlg = new BasicGUI_EllipseDlg(parent, "", Sel);
127 aDlg = new BasicGUI_ArcDlg(parent, "", Sel);
130 aDlg = new BasicGUI_VectorDlg(parent, "", Sel);
133 aDlg = new BasicGUI_PlaneDlg(parent, "", Sel);
135 case 4018: // WORKING PLANE
136 aDlg = new BasicGUI_WorkingPlaneDlg(parent, "", Sel);
139 aDlg = new BasicGUI_CurveDlg( parent, "", Sel );
142 aDlg = new BasicGUI_MarkerDlg( parent, Sel );
145 parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
156 //=================================================================================
157 // function : 0nMousePress()
158 // purpose : [static] manage mouse events
159 //=================================================================================
160 bool BasicGUI::OnMousePress( QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* theFrame )
162 QDialog* aDlg = GeometryGUI::GetGeomGUI()->GetActiveDialogBox();
164 // Create Point dialog, OCC viewer
165 if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theFrame->getTypeView() == VIEW_OCC && pe->state() != Qt::ControlButton )
167 BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
168 if ( aPntDlg->acceptMouseEvent() )
170 OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)theFrame->getRightFrame()->getViewFrame())->getViewer();
171 Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
176 if( pe->state() == Qt::ShiftButton )
177 v3d->getAISSelector()->shiftSelect(); // Append selection
179 v3d->getAISSelector()->select(); // New selection
182 if( ic->MoreSelected() )
184 TopoDS_Shape aShape = ic->SelectedShape();
185 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
186 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
190 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)theFrame->getRightFrame()->getViewFrame())->getViewPort();
191 aPnt = ConvertClickToPoint( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() );
194 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
195 } // acceptMouseEvent()
201 //=======================================================================
202 // function : ConvertClickToPoint()
203 // purpose : Returns the point clicked in 3D view
204 //=======================================================================
205 gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView)
207 V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
208 aView->Eye(XEye, YEye, ZEye);
210 aView->At(XAt, YAt, ZAt);
211 gp_Pnt EyePoint(XEye, YEye, ZEye);
212 gp_Pnt AtPoint(XAt, YAt, ZAt);
214 gp_Vec EyeVector(EyePoint, AtPoint);
215 gp_Dir EyeDir(EyeVector);
217 gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
218 Standard_Real X, Y, Z;
219 aView->Convert(x, y, X, Y, Z);
220 gp_Pnt ConvertedPoint(X, Y, Z);
222 gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
223 gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
227 //=====================================================================================
229 //=====================================================================================
234 return BasicGUI::GetBasicGUI();