2004-01-07 20:46:21 +05:00
|
|
|
// GEOM GEOMGUI : GUI for Geometry component
|
|
|
|
//
|
|
|
|
// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
|
|
|
|
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
|
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2.1 of the License.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
//
|
|
|
|
// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// File : BasicGUI.cxx
|
|
|
|
// Author : Damien COQUERET
|
|
|
|
// Module : GEOM
|
2004-12-01 15:39:14 +05:00
|
|
|
// $Header$
|
2004-01-07 20:46:21 +05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
#include "BasicGUI.h"
|
2004-12-01 15:39:14 +05:00
|
|
|
#include "GeometryGUI.h"
|
2004-01-07 20:46:21 +05:00
|
|
|
|
2005-06-02 13:17:09 +06:00
|
|
|
#include "SUIT_Session.h"
|
|
|
|
#include "SUIT_Desktop.h"
|
|
|
|
#include "SUIT_ViewWindow.h"
|
|
|
|
#include "OCCViewer_ViewWindow.h"
|
|
|
|
#include "OCCViewer_ViewModel.h"
|
|
|
|
#include "OCCViewer_ViewManager.h"
|
2004-01-07 20:46:21 +05:00
|
|
|
#include "OCCViewer_ViewPort3d.h"
|
2004-12-01 15:39:14 +05:00
|
|
|
#include "utilities.h"
|
|
|
|
|
2004-01-07 20:46:21 +05:00
|
|
|
#include <Precision.hxx>
|
|
|
|
#include <BRep_Tool.hxx>
|
|
|
|
#include <ProjLib.hxx>
|
|
|
|
#include <ElSLib.hxx>
|
2004-12-01 15:39:14 +05:00
|
|
|
#include <TopoDS.hxx>
|
2004-01-07 20:46:21 +05:00
|
|
|
|
|
|
|
#include "BasicGUI_PointDlg.h" // Method POINT
|
|
|
|
#include "BasicGUI_LineDlg.h" // Method LINE
|
|
|
|
#include "BasicGUI_CircleDlg.h" // Method CIRCLE
|
|
|
|
#include "BasicGUI_EllipseDlg.h" // Method ELLIPSE
|
|
|
|
#include "BasicGUI_ArcDlg.h" // Method ARC
|
2004-12-01 15:39:14 +05:00
|
|
|
#include "BasicGUI_CurveDlg.h" // Method CURVE
|
2004-01-07 20:46:21 +05:00
|
|
|
#include "BasicGUI_VectorDlg.h" // Method VECTOR
|
|
|
|
#include "BasicGUI_PlaneDlg.h" // Method PLANE
|
|
|
|
#include "BasicGUI_WorkingPlaneDlg.h" // Method WORKING PLANE
|
2004-12-01 15:39:14 +05:00
|
|
|
#include "BasicGUI_MarkerDlg.h" // Method REPAIR
|
|
|
|
|
|
|
|
BasicGUI* BasicGUI::myGUIObject = 0;
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
// function : GetBasicGUI()
|
|
|
|
// purpose : Get the only BasicGUI object [ static ]
|
|
|
|
//=======================================================================
|
2005-06-02 13:17:09 +06:00
|
|
|
BasicGUI* BasicGUI::GetBasicGUI( GeometryGUI* parent )
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
if ( myGUIObject == 0 ) {
|
2005-06-02 13:17:09 +06:00
|
|
|
myGUIObject = new BasicGUI( parent );
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
|
|
|
return myGUIObject;
|
|
|
|
}
|
2004-01-07 20:46:21 +05:00
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
// function : BasicGUI()
|
|
|
|
// purpose : Constructor
|
|
|
|
//=======================================================================
|
2005-06-02 13:17:09 +06:00
|
|
|
BasicGUI::BasicGUI( GeometryGUI* parent ) :
|
|
|
|
GEOMGUI(parent)
|
2004-01-07 20:46:21 +05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
// function : ~BasicGUI()
|
|
|
|
// purpose : Destructor
|
|
|
|
//=======================================================================
|
|
|
|
BasicGUI::~BasicGUI()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
// function : OnGUIEvent()
|
|
|
|
// purpose :
|
|
|
|
//=======================================================================
|
2005-06-02 13:17:09 +06:00
|
|
|
bool BasicGUI::OnGUIEvent(int theCommandID, SUIT_Desktop* parent)
|
2004-01-07 20:46:21 +05:00
|
|
|
{
|
2005-06-02 13:17:09 +06:00
|
|
|
getGeometryGUI()->EmitSignalDeactivateDialog();
|
2004-12-01 15:39:14 +05:00
|
|
|
QDialog* aDlg = NULL;
|
2004-01-07 20:46:21 +05:00
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
switch ( theCommandID )
|
2004-01-07 20:46:21 +05:00
|
|
|
{
|
|
|
|
case 4011: // POINT
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_PointDlg( getGeometryGUI(), parent, "" );
|
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4012: // LINE
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_LineDlg( getGeometryGUI(), parent, "" );
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4013: // CIRCLE
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_CircleDlg( getGeometryGUI(), parent, "");
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4014: // ELLIPSE
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_EllipseDlg( getGeometryGUI(), parent, "" );
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4015: // ARC
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_ArcDlg( getGeometryGUI(), parent, "" );
|
2004-12-01 15:39:14 +05:00
|
|
|
break ;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4016: // VECTOR
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_VectorDlg( getGeometryGUI(), parent, "" );
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4017: // PLANE
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_PlaneDlg( getGeometryGUI(), parent, "");
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
case 4018: // WORKING PLANE
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_WorkingPlaneDlg( getGeometryGUI(), parent, "" );
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
|
|
|
case 4019: // CURVE
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_CurveDlg( getGeometryGUI(), parent, "" );
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
|
|
|
case 4020: // REPAIR
|
2005-06-02 13:17:09 +06:00
|
|
|
aDlg = new BasicGUI_MarkerDlg( getGeometryGUI(), parent );
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
default:
|
2005-06-02 13:17:09 +06:00
|
|
|
SUIT_Session::session()->activeApplication()->putInfo(tr("GEOM_PRP_COMMAND").arg(theCommandID));
|
2004-12-01 15:39:14 +05:00
|
|
|
break;
|
2004-01-07 20:46:21 +05:00
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
if ( aDlg != NULL )
|
|
|
|
aDlg->show();
|
|
|
|
|
2004-01-07 20:46:21 +05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=================================================================================
|
|
|
|
// function : 0nMousePress()
|
|
|
|
// purpose : [static] manage mouse events
|
|
|
|
//=================================================================================
|
2005-06-02 13:17:09 +06:00
|
|
|
bool BasicGUI::OnMousePress( QMouseEvent* pe, SUIT_Desktop* parent, SUIT_ViewWindow* theViewWindow )
|
2004-01-07 20:46:21 +05:00
|
|
|
{
|
2005-06-02 13:17:09 +06:00
|
|
|
QDialog* aDlg = getGeometryGUI()->GetActiveDialogBox();
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
// Create Point dialog, OCC viewer
|
2005-06-02 13:17:09 +06:00
|
|
|
if ( aDlg && aDlg->isA( "BasicGUI_PointDlg" ) && theViewWindow->getViewManager()->getType() == OCCViewer_Viewer::Type() && pe->state() != Qt::ControlButton )
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
|
|
|
BasicGUI_PointDlg* aPntDlg = (BasicGUI_PointDlg*) aDlg;
|
|
|
|
if ( aPntDlg->acceptMouseEvent() )
|
2005-06-02 13:17:09 +06:00
|
|
|
{
|
|
|
|
OCCViewer_Viewer* anOCCViewer = ((OCCViewer_ViewManager*)(theViewWindow->getViewManager()))->getOCCViewer();
|
|
|
|
Handle(AIS_InteractiveContext) ic = anOCCViewer->getAISContext();
|
|
|
|
|
2004-12-01 15:39:14 +05:00
|
|
|
gp_Pnt aPnt;
|
|
|
|
|
|
|
|
ic->InitSelected();
|
|
|
|
if( pe->state() == Qt::ShiftButton )
|
2005-06-02 13:17:09 +06:00
|
|
|
ic->ShiftSelect(); // Append selection
|
2004-12-01 15:39:14 +05:00
|
|
|
else
|
2005-06-02 13:17:09 +06:00
|
|
|
ic->Select(); // New selection
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
ic->InitSelected();
|
|
|
|
if( ic->MoreSelected() )
|
2005-06-02 13:17:09 +06:00
|
|
|
{
|
|
|
|
TopoDS_Shape aShape = ic->SelectedShape();
|
|
|
|
if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
|
|
|
|
aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
else
|
2005-06-02 13:17:09 +06:00
|
|
|
{
|
|
|
|
OCCViewer_ViewPort3d* vp = ((OCCViewer_ViewWindow*)theViewWindow)->getViewPort();
|
|
|
|
aPnt = ConvertClickToPoint( pe->x(), pe->y(), vp->getView() );
|
|
|
|
}
|
2004-12-01 15:39:14 +05:00
|
|
|
|
|
|
|
aPntDlg->OnPointSelected( aPnt ); // "feed" the point to point construction dialog
|
2005-06-02 13:17:09 +06:00
|
|
|
} // acceptMouseEvent()
|
2004-01-07 20:46:21 +05:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=======================================================================
|
|
|
|
// function : ConvertClickToPoint()
|
|
|
|
// purpose : Returns the point clicked in 3D view
|
|
|
|
//=======================================================================
|
2004-12-01 15:39:14 +05:00
|
|
|
gp_Pnt BasicGUI::ConvertClickToPoint( int x, int y, Handle(V3d_View) aView)
|
2004-01-07 20:46:21 +05:00
|
|
|
{
|
|
|
|
V3d_Coordinate XEye, YEye, ZEye, XAt, YAt, ZAt;
|
|
|
|
aView->Eye(XEye, YEye, ZEye);
|
|
|
|
|
|
|
|
aView->At(XAt, YAt, ZAt);
|
|
|
|
gp_Pnt EyePoint(XEye, YEye, ZEye);
|
|
|
|
gp_Pnt AtPoint(XAt, YAt, ZAt);
|
|
|
|
|
|
|
|
gp_Vec EyeVector(EyePoint, AtPoint);
|
|
|
|
gp_Dir EyeDir(EyeVector);
|
|
|
|
|
|
|
|
gp_Pln PlaneOfTheView = gp_Pln(AtPoint,EyeDir);
|
|
|
|
Standard_Real X, Y, Z;
|
2004-12-01 15:39:14 +05:00
|
|
|
aView->Convert(x, y, X, Y, Z);
|
2004-01-07 20:46:21 +05:00
|
|
|
gp_Pnt ConvertedPoint(X, Y, Z);
|
|
|
|
|
|
|
|
gp_Pnt2d ConvertedPointOnPlane = ProjLib::Project(PlaneOfTheView, ConvertedPoint);
|
|
|
|
gp_Pnt ResultPoint = ElSLib::Value(ConvertedPointOnPlane.X(), ConvertedPointOnPlane.Y(), PlaneOfTheView);
|
|
|
|
return ResultPoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================================
|
|
|
|
// EXPORTED METHODS
|
|
|
|
//=====================================================================================
|
|
|
|
extern "C"
|
|
|
|
{
|
2005-06-02 13:17:09 +06:00
|
|
|
GEOMGUI* GetLibGUI( GeometryGUI* parent )
|
2004-12-01 15:39:14 +05:00
|
|
|
{
|
2005-06-02 13:17:09 +06:00
|
|
|
return BasicGUI::GetBasicGUI( parent );
|
2004-12-01 15:39:14 +05:00
|
|
|
}
|
2004-01-07 20:46:21 +05:00
|
|
|
}
|