]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI.cxx
Salome HOME
8c47c0f4bbdb8a40c74d4403e012d4bd4b97f8d2
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : BasicGUI.cxx
25 //  Author : Damien COQUERET
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI.h"
30 #include "GeometryGUI.h"
31
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"
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 using namespace std;
59
60 //=======================================================================
61 // function : GetBasicGUI()
62 // purpose  : Get the only BasicGUI object [ static ]
63 //=======================================================================
64 BasicGUI* BasicGUI::GetBasicGUI( GeometryGUI* parent )
65 {
66   return new BasicGUI( parent );
67 }
68
69 //=======================================================================
70 // function : BasicGUI()
71 // purpose  : Constructor
72 //=======================================================================
73 BasicGUI::BasicGUI( GeometryGUI* parent ) :
74   GEOMGUI(parent)
75 {
76 }
77
78 //=======================================================================
79 // function : ~BasicGUI()
80 // purpose  : Destructor
81 //=======================================================================
82 BasicGUI::~BasicGUI()
83 {
84 }
85
86
87 //=======================================================================
88 // function : OnGUIEvent()
89 // purpose  : 
90 //=======================================================================
91 bool BasicGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
92 {
93   getGeometryGUI()->EmitSignalDeactivateDialog();
94   QDialog* aDlg = NULL;
95
96   switch ( theCommandID )
97     {
98     case 4011: // POINT
99       aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent, "" ); 
100       break;
101     case 4012:  // LINE
102       aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent, "" );
103       break;
104     case 4013:  // CIRCLE
105       aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent, "");
106       break;
107     case 4014:  // ELLIPSE
108       aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent, "" );
109       break;
110     case 4015:  // ARC
111       aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent, "" );
112       break ;
113     case 4016: // VECTOR
114       aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent, "" );
115       break;
116     case 4017: // PLANE
117       aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent, "");
118       break;
119     case 4018: // WORKING PLANE
120       aDlg = new BasicGUI_WorkingPlaneDlg( getGeometryGUI(), parent, "" );
121       break;
122     case 4019: // CURVE
123       aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent, "" );
124       break;
125     case 4020: // REPAIR
126       aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
127       break;      
128     default:
129       SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
130       break;
131     }
132
133   if ( aDlg != NULL )
134     aDlg->show();
135
136   return true;
137 }
138
139
140 //=================================================================================
141 // function : 0nMousePress()
142 // purpose  : [static] manage mouse events
143 //=================================================================================
144 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
145 {
146   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
147
148   // Create Point dialog, OCC viewer 
149   if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&  pe->state() != Qt::ControlButton )
150   {
151     BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
152     if ( aPntDlg->acceptMouseEvent() )
153       {
154         OCCViewer_Viewer* anOCCViewer = ((OCCViewer_ViewManager*)(theViewWindow->getViewManager()))->getOCCViewer();
155         Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
156         
157         gp_Pnt aPnt;    
158
159         ic->InitSelected();
160         if( pe->state() == Qt::ShiftButton )
161           ic->ShiftSelect();  // Append selection
162         else
163           ic->Select();       // New selection
164
165         ic->InitSelected();
166         if( ic->MoreSelected() )
167           {
168             TopoDS_Shape aShape = ic->SelectedShape();
169             if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
170               aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
171           }
172         else
173           {
174             OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
175             aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
176           }
177
178         aPntDlg->OnPointSelected( aPnt );  // "feed" the point to point construction dialog
179       } // acceptMouseEvent()
180   } 
181   return false;
182 }
183
184
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)
190 {
191   V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
192   aView->Eye(XEye, YEye, ZEye);
193
194   aView->At(XAt, YAt, ZAt);
195   gp_Pnt EyePoint(XEye, YEye, ZEye);
196   gp_Pnt AtPoint(XAt, YAt, ZAt);
197
198   gp_Vec EyeVector(EyePoint, AtPoint);
199   gp_Dir EyeDir(EyeVector);
200
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);
205
206   gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
207   gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
208   return ResultPoint;
209 }
210
211 //=====================================================================================
212 // EXPORTED METHODS
213 //=====================================================================================
214 extern "C"
215 {
216 #ifdef WNT
217         __declspec( dllexport )
218 #endif
219   GEOMGUI* GetLibGUI( GeometryGUI* parent )
220   {
221     return BasicGUI::GetBasicGUI( parent );
222   }
223 }