1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : BasicGUI.cxx
25 // Author : Damien COQUERET, Open CASCADE S.A.S.
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
39 #include "GeometryGUI.h"
40 #include "GeometryGUI_Operations.h"
41 #include "GEOMUtils.hxx"
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>
51 #include <BRep_Tool.hxx>
52 #include <ProjLib.hxx>
56 #include <QMouseEvent>
58 //=======================================================================
59 // function : BasicGUI()
60 // purpose : Constructor
61 //=======================================================================
62 BasicGUI::BasicGUI( GeometryGUI* parent )
67 //=======================================================================
68 // function : ~BasicGUI()
69 // purpose : Destructor
70 //=======================================================================
76 //=======================================================================
77 // function : OnGUIEvent()
79 //=======================================================================
80 bool BasicGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent )
82 getGeometryGUI()->EmitSignalDeactivateDialog();
85 switch ( theCommandID ) {
86 case GEOMOp::OpPoint: // POINT
87 aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent );
89 case GEOMOp::OpLine: // LINE
90 aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent );
92 case GEOMOp::OpCircle: // CIRCLE
93 aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent );
95 case GEOMOp::OpEllipse: // ELLIPSE
96 aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent );
98 case GEOMOp::OpArc: // ARC
99 aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent );
101 case GEOMOp::OpVector: // VECTOR
102 aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent );
104 case GEOMOp::OpPlane: // PLANE
105 aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent );
107 case GEOMOp::OpCurve: // CURVE
108 aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent );
110 case GEOMOp::OpLCS: // LOCAL COORDINATE SYSTEM
111 aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
114 SUIT_Session::session()->activeApplication()->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) );
125 //=================================================================================
126 // function : 0nMousePress()
127 // purpose : [static] manage mouse events
128 //=================================================================================
129 bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
131 QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
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();
146 if ( pe->modifiers() == Qt::ShiftModifier )
147 ic->ShiftSelect( Standard_True ); // Append selection
149 ic->Select( Standard_True ); // New selection
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() ) );
158 OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
159 aPnt = GEOMUtils::ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
162 aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
163 } // acceptMouseEvent()
169 //=====================================================================================
171 //=====================================================================================
175 __declspec( dllexport )
177 GEOMGUI* GetLibGUI( GeometryGUI* parent )
179 return new BasicGUI( parent );