Salome HOME
180ee7ebbaf36144b182eee1263c35f2ba5e8de4
[modules/geom.git] / src / BasicGUI / BasicGUI.cxx
1 // Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : BasicGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
26 //
27 #include "BasicGUI.h"
28
29 #include "BasicGUI_PointDlg.h"        // Method POINT
30 #include "BasicGUI_LineDlg.h"         // Method LINE
31 #include "BasicGUI_CircleDlg.h"       // Method CIRCLE
32 #include "BasicGUI_EllipseDlg.h"      // Method ELLIPSE
33 #include "BasicGUI_ArcDlg.h"          // Method ARC
34 #include "BasicGUI_CurveDlg.h"        // Method CURVE
35 #include "BasicGUI_VectorDlg.h"       // Method VECTOR
36 #include "BasicGUI_PlaneDlg.h"        // Method PLANE
37 #include "BasicGUI_MarkerDlg.h"       // Method LOCAL COORDINATE SYSTEM
38
39 #include "GeometryGUI.h"
40 #include "GeometryGUI_Operations.h"
41 #include "GEOMUtils.hxx"
42
43 #include <SUIT_Session.h>
44 #include <SUIT_Desktop.h>
45 #include <SUIT_ViewWindow.h>
46 #include <OCCViewer_ViewWindow.h>
47 #include <OCCViewer_ViewModel.h>
48 #include <OCCViewer_ViewManager.h>
49 #include <OCCViewer_ViewPort3d.h>
50
51 #include <BRep_Tool.hxx>
52 #include <ProjLib.hxx>
53 #include <ElSLib.hxx>
54 #include <TopoDS.hxx>
55
56 #include <QMouseEvent>
57
58 //=======================================================================
59 // function : BasicGUI()
60 // purpose  : Constructor
61 //=======================================================================
62 BasicGUI::BasicGUI( GeometryGUI* parent )
63   : GEOMGUI( parent )
64 {
65 }
66
67 //=======================================================================
68 // function : ~BasicGUI()
69 // purpose  : Destructor
70 //=======================================================================
71 BasicGUI::~BasicGUI()
72 {
73 }
74
75
76 //=======================================================================
77 // function : OnGUIEvent()
78 // purpose  : 
79 //=======================================================================
80 bool BasicGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
81 {
82   getGeometryGUI()->EmitSignalDeactivateDialog();
83   QDialog* aDlg = NULL;
84
85   switch ( theCommandID ) {
86   case GEOMOp::OpPoint:    // POINT
87     aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent ); 
88     break;
89   case GEOMOp::OpLine:     // LINE
90     aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
91     break;
92   case GEOMOp::OpCircle:   // CIRCLE
93     aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
94     break;
95   case GEOMOp::OpEllipse:  // ELLIPSE
96     aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
97     break;
98   case GEOMOp::OpArc:      // ARC
99     aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
100     break ;
101   case GEOMOp::OpVector:   // VECTOR
102     aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
103     break;
104   case GEOMOp::OpPlane:    // PLANE
105     aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
106     break;
107   case GEOMOp::OpCurve:    // CURVE
108     aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
109     break;
110   case GEOMOp::OpLCS:      // LOCAL COORDINATE SYSTEM
111     aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
112     break;      
113   default:
114     SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
115     break;
116   }
117   
118   if ( aDlg != NULL )
119     aDlg->show();
120   
121   return true;
122 }
123
124
125 //=================================================================================
126 // function : 0nMousePress()
127 // purpose  : [static] manage mouse events
128 //=================================================================================
129 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* /*parent*/, SUIT_ViewWindow* theViewWindow )
130 {
131   QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
132
133   // Create Point dialog, OCC viewer 
134   if ( aDlg && ( QString( aDlg->metaObject()->className() ).compare( "BasicGUI_PointDlg" ) == 0 ) &&
135        theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() &&
136        pe->modifiers() != Qt::ControlModifier ) {
137     BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
138     if ( aPntDlg->acceptMouseEvent() ) {
139       OCCViewer_Viewer* anOCCViewer =
140         ( (OCCViewer_ViewManager*)( theViewWindow->getViewManager() ) )->getOCCViewer();
141       Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
142
143       gp_Pnt aPnt;    
144
145       ic->InitSelected();
146       if ( pe->modifiers() == Qt::ShiftModifier )
147         ic->ShiftSelect( Standard_True );  // Append selection
148       else
149         ic->Select( Standard_True );       // New selection
150
151       ic->InitSelected();
152       if ( ic->MoreSelected() ) {
153         TopoDS_Shape aShape = ic->SelectedShape();
154         if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
155           aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
156       }
157       else {
158         OCCViewer_ViewPort3d* vp =  ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
159         aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
160       }
161
162       aPntDlg->OnPointSelected( aPnt );  // "feed" the point to point construction dialog
163     } // acceptMouseEvent()
164   }
165   return false;
166 }
167
168
169 //=====================================================================================
170 // EXPORTED METHODS
171 //=====================================================================================
172 extern "C"
173 {
174 #ifdef WIN32
175   __declspec( dllexport )
176 #endif
177   GEOMGUI* GetLibGUI( GeometryGUI* parent )
178   {
179     return new BasicGUI( parent );
180   }
181 }