]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI.cxx
Salome HOME
56b45e7b95318b91562bddccae4f2abce19124ef
[modules/geom.git] / src / BasicGUI / BasicGUI.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BasicGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "BasicGUI.h"
31 #include "GeometryGUI.h"
32
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"
38
39 #include "utilities.h"
40
41 #include <Precision.hxx>
42 #include <BRep_Tool.hxx>
43 #include <ProjLib.hxx>
44 #include <ElSLib.hxx>
45 #include <TopoDS.hxx>
46
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
57
58 BasicGUI* BasicGUI::myGUIObject = 0;
59
60 //=======================================================================
61 // function : GetBasicGUI()
62 // purpose  : Get the only BasicGUI object [ static ]
63 //=======================================================================
64 BasicGUI* BasicGUI::GetBasicGUI()
65 {
66   if ( myGUIObject == 0 ) {
67     myGUIObject = new BasicGUI();
68   }
69   return myGUIObject;
70 }
71
72 //=======================================================================
73 // function : BasicGUI()
74 // purpose  : Constructor
75 //=======================================================================
76 BasicGUI::BasicGUI() :
77   GEOMGUI()
78 {
79 }
80
81
82 //=======================================================================
83 // function : ~BasicGUI()
84 // purpose  : Destructor
85 //=======================================================================
86 BasicGUI::~BasicGUI()
87 {
88 }
89
90
91 //=======================================================================
92 // function : OnGUIEvent()
93 // purpose  : 
94 //=======================================================================
95 bool BasicGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
96 {
97   GeometryGUI::GetGeomGUI()->EmitSignalDeactivateDialog();
98   SALOME_Selection* Sel = SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveStudy()->getSelection());
99   QDialog* aDlg = NULL;
100
101   switch ( theCommandID )
102     {
103     case 4011: // POINT
104       {
105         Handle(AIS_InteractiveContext) ic;
106         QAD_StudyFrame* aFrame = QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame();
107         if ( aFrame->getTypeView() == VIEW_OCC) 
108         {
109           OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)aFrame->getRightFrame()->getViewFrame())->getViewer();
110           ic = v3d->getAISContext();
111         }
112         aDlg = new BasicGUI_PointDlg( parent, "", Sel ); 
113         break;
114       }
115     case 4012:  // LINE
116       aDlg = new BasicGUI_LineDlg(parent, "",  Sel);
117       break;
118     case 4013:  // CIRCLE
119       aDlg = new BasicGUI_CircleDlg(parent, "", Sel);
120       break;
121     case 4014:  // ELLIPSE
122       aDlg = new BasicGUI_EllipseDlg(parent, "", Sel);
123       break;
124     case 4015:  // ARC
125       aDlg = new BasicGUI_ArcDlg(parent, "", Sel);
126       break ;
127     case 4016: // VECTOR
128       aDlg = new BasicGUI_VectorDlg(parent, "", Sel);
129       break;
130     case 4017: // PLANE
131       aDlg = new BasicGUI_PlaneDlg(parent, "", Sel);
132       break;
133     case 4018: // WORKING PLANE
134       aDlg = new BasicGUI_WorkingPlaneDlg(parent, "", Sel);
135       break;
136     case 4019: // CURVE
137       aDlg = new BasicGUI_CurveDlg( parent, "", Sel );
138       break;
139     case 4020: // REPAIR
140       aDlg = new BasicGUI_MarkerDlg( parent, Sel );
141       break;      
142     default:
143       parent->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
144       break;
145     }
146
147   if ( aDlg != NULL )
148     aDlg->show();
149
150   return true;
151 }
152
153
154 //=================================================================================
155 // function : 0nMousePress()
156 // purpose  : [static] manage mouse events
157 //=================================================================================
158 bool BasicGUI::OnMousePress( QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* theFrame )
159 {
160   QDialog* aDlg = GeometryGUI::GetGeomGUI()->GetActiveDialogBox();
161
162   // Create Point dialog, OCC viewer 
163   if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theFrame->getTypeView() == VIEW_OCC )
164   {
165     BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
166     if ( aPntDlg->acceptMouseEvent() )
167                 {
168         OCCViewer_Viewer3d* v3d = ((OCCViewer_ViewFrame*)theFrame->getRightFrame()->getViewFrame())->getViewer();
169         Handle (AIS_InteractiveContext) ic = v3d->getAISContext();
170       
171         gp_Pnt aPnt;    
172
173         ic->InitSelected();
174         if( pe->state() == Qt::ShiftButton )
175         v3d->getAISSelector()->shiftSelect();  // Append selection
176         else
177         v3d->getAISSelector()->select();       // New selection
178
179         ic->InitSelected();
180         if( ic->MoreSelected() )
181         {
182         TopoDS_Shape aShape = ic->SelectedShape();
183         if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
184                 aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
185         }
186         else
187         {
188                 OCCViewer_ViewPort* vp = ((OCCViewer_ViewFrame*)theFrame->getRightFrame()->getViewFrame())->getViewPort();
189         aPnt = ConvertClickToPoint( pe->x(), pe->y(), ((OCCViewer_ViewPort3d*)vp)->getView() );
190         }
191
192         aPntDlg->OnPointSelected( aPnt );  // "feed" the point to point construction dialog
193     } // acceptMouseEvent()
194   } 
195   return false;
196 }
197
198
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)
204 {
205   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
206   aView->Eye(XEye, YEye, ZEye);
207
208   aView->At(XAt, YAt, ZAt);
209   gp_Pnt EyePoint(XEye, YEye, ZEye);
210   gp_Pnt AtPoint(XAt, YAt, ZAt);
211
212   gp_Vec EyeVector(EyePoint, AtPoint);
213   gp_Dir EyeDir(EyeVector);
214
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);
219
220   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
221   gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
222   return ResultPoint;
223 }
224
225 //=====================================================================================
226 // EXPORTED METHODS
227 //=====================================================================================
228 extern "C"
229 {
230   GEOMGUI* GetLibGUI()
231   {
232     return BasicGUI::GetBasicGUI();
233   }
234 }