2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2010-01-19 20:43:44 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
// Name: 3d_canvas.cpp
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
|
|
|
|
#include "wx/image.h"
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/dataobj.h"
|
|
|
|
#include "wx/clipbrd.h"
|
2010-01-19 20:43:44 +00:00
|
|
|
#include <wx/wupdlock.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "gestfich.h"
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "3d_viewer.h"
|
|
|
|
#include "trackball.h"
|
|
|
|
|
|
|
|
/* Tool and button Bitmaps */
|
|
|
|
#include "bitmaps.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pcb3D_GLCanvas implementation
|
|
|
|
*/
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
BEGIN_EVENT_TABLE( Pcb3D_GLCanvas, wxGLCanvas )
|
2010-01-19 20:43:44 +00:00
|
|
|
EVT_PAINT( Pcb3D_GLCanvas::OnPaint )
|
|
|
|
|
|
|
|
// key event:
|
|
|
|
EVT_CHAR( Pcb3D_GLCanvas::OnChar )
|
|
|
|
|
|
|
|
// mouse events
|
|
|
|
EVT_RIGHT_DOWN( Pcb3D_GLCanvas::OnRightClick )
|
|
|
|
EVT_MOUSEWHEEL( Pcb3D_GLCanvas::OnMouseWheel )
|
|
|
|
EVT_MOTION( Pcb3D_GLCanvas::OnMouseMove )
|
|
|
|
|
|
|
|
// other events
|
|
|
|
EVT_ERASE_BACKGROUND( Pcb3D_GLCanvas::OnEraseBackground )
|
|
|
|
EVT_MENU_RANGE( ID_POPUP_3D_VIEW_START, ID_POPUP_3D_VIEW_END,
|
|
|
|
Pcb3D_GLCanvas::OnPopUpMenu )
|
2007-05-06 16:03:28 +00:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2009-04-29 12:10:15 +00:00
|
|
|
Pcb3D_GLCanvas::Pcb3D_GLCanvas( WinEDA3D_DrawFrame* parent ) :
|
2009-07-20 13:44:41 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
2009-11-04 20:46:53 +00:00
|
|
|
wxGLCanvas( parent, -1, NULL, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxFULL_REPAINT_ON_RESIZE )
|
2009-07-20 13:44:41 +00:00
|
|
|
#else
|
2009-11-04 20:46:53 +00:00
|
|
|
wxGLCanvas( parent, -1, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxFULL_REPAINT_ON_RESIZE )
|
2009-07-20 13:44:41 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
m_init = FALSE;
|
|
|
|
m_gllist = 0;
|
|
|
|
m_Parent = parent;
|
2009-07-13 15:25:41 +00:00
|
|
|
|
2009-07-20 13:44:41 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2009-07-13 15:25:41 +00:00
|
|
|
// Explicitly create a new rendering context instance for this canvas.
|
2009-11-04 20:46:53 +00:00
|
|
|
m_glRC = new wxGLContext( this );
|
2009-07-20 13:44:41 +00:00
|
|
|
#endif
|
2009-08-20 11:44:06 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
DisplayStatus();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
Pcb3D_GLCanvas::~Pcb3D_GLCanvas()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
ClearLists();
|
2009-05-28 08:42:24 +00:00
|
|
|
m_init = FALSE;
|
2009-07-20 13:44:41 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
2009-07-13 15:25:41 +00:00
|
|
|
delete m_glRC;
|
2009-07-20 13:44:41 +00:00
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
void Pcb3D_GLCanvas::ClearLists()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
if( m_gllist > 0 )
|
|
|
|
glDeleteLists( m_gllist, 1 );
|
|
|
|
m_gllist = 0;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
void Pcb3D_GLCanvas::OnChar( wxKeyEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
SetView3D( event.GetKeyCode() );
|
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
void Pcb3D_GLCanvas::SetView3D( int keycode )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int ii;
|
|
|
|
double delta_move = 0.7 * g_Parm_3D_Visu.m_Zoom;
|
|
|
|
|
|
|
|
switch( keycode )
|
|
|
|
{
|
|
|
|
case WXK_LEFT:
|
|
|
|
g_Draw3d_dx -= delta_move;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_RIGHT:
|
|
|
|
g_Draw3d_dx += delta_move;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_UP:
|
|
|
|
g_Draw3d_dy += delta_move;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_DOWN:
|
|
|
|
g_Draw3d_dy -= delta_move;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_HOME:
|
|
|
|
g_Parm_3D_Visu.m_Zoom = 1.0;
|
|
|
|
g_Draw3d_dx = g_Draw3d_dy = 0;
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_END:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_F1:
|
|
|
|
g_Parm_3D_Visu.m_Zoom /= 1.4;
|
|
|
|
if( g_Parm_3D_Visu.m_Zoom <= 0.01 )
|
|
|
|
g_Parm_3D_Visu.m_Zoom = 0.01;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WXK_F2:
|
|
|
|
g_Parm_3D_Visu.m_Zoom *= 1.4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '+':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '-':
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r':
|
|
|
|
case 'R':
|
|
|
|
g_Draw3d_dx = g_Draw3d_dy = 0;
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'x':
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
g_Parm_3D_Visu.m_ROTZ = -90;
|
|
|
|
g_Parm_3D_Visu.m_ROTX = -90;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'X':
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
g_Parm_3D_Visu.m_ROTZ = 90;
|
|
|
|
g_Parm_3D_Visu.m_ROTX = -90;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'y':
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
g_Parm_3D_Visu.m_ROTX = -90;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Y':
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
g_Parm_3D_Visu.m_ROTX = -90;
|
|
|
|
g_Parm_3D_Visu.m_ROTZ = -180;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'Z':
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
g_Parm_3D_Visu.m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
trackball( g_Parm_3D_Visu.m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
g_Parm_3D_Visu.m_ROTX = -180;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayStatus();
|
|
|
|
Refresh( FALSE );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2010-01-19 20:43:44 +00:00
|
|
|
|
2010-01-11 14:44:49 +00:00
|
|
|
void Pcb3D_GLCanvas::OnMouseWheel( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxSize size( GetClientSize() );
|
|
|
|
|
2010-01-11 14:44:49 +00:00
|
|
|
if( event.ShiftDown() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-01-11 14:44:49 +00:00
|
|
|
if( event.GetWheelRotation() < 0 )
|
|
|
|
{
|
|
|
|
/* up */
|
|
|
|
SetView3D( WXK_UP );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* down */
|
|
|
|
SetView3D( WXK_DOWN );
|
|
|
|
}
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-01-11 14:44:49 +00:00
|
|
|
else if( event.ControlDown() )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-01-11 14:44:49 +00:00
|
|
|
if( event.GetWheelRotation() > 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-01-11 14:44:49 +00:00
|
|
|
/* right */
|
|
|
|
SetView3D( WXK_RIGHT );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2010-01-11 14:44:49 +00:00
|
|
|
else
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-01-11 14:44:49 +00:00
|
|
|
/* left */
|
|
|
|
SetView3D( WXK_LEFT );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2010-01-11 14:44:49 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( event.GetWheelRotation() > 0 )
|
2007-08-20 01:20:48 +00:00
|
|
|
{
|
2010-01-11 14:44:49 +00:00
|
|
|
g_Parm_3D_Visu.m_Zoom /= 1.4;
|
|
|
|
if( g_Parm_3D_Visu.m_Zoom <= 0.01 )
|
|
|
|
g_Parm_3D_Visu.m_Zoom = 0.01;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2010-01-11 14:44:49 +00:00
|
|
|
else
|
|
|
|
g_Parm_3D_Visu.m_Zoom *= 1.4;
|
|
|
|
DisplayStatus();
|
|
|
|
Refresh( FALSE );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2010-01-11 14:44:49 +00:00
|
|
|
g_Parm_3D_Visu.m_Beginx = event.GetX();
|
|
|
|
g_Parm_3D_Visu.m_Beginy = event.GetY();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pcb3D_GLCanvas::OnMouseMove( wxMouseEvent& event )
|
|
|
|
{
|
|
|
|
wxSize size( GetClientSize() );
|
|
|
|
double spin_quat[4];
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( event.Dragging() )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-03 08:00:26 +00:00
|
|
|
if( event.LeftIsDown() )
|
|
|
|
{
|
|
|
|
/* drag in progress, simulate trackball */
|
|
|
|
trackball( spin_quat,
|
|
|
|
(2.0 * g_Parm_3D_Visu.m_Beginx - size.x) / size.x,
|
|
|
|
(size.y - 2.0 * g_Parm_3D_Visu.m_Beginy) / size.y,
|
|
|
|
( 2.0 * event.GetX() - size.x) / size.x,
|
|
|
|
( size.y - 2.0 * event.GetY() ) / size.y );
|
|
|
|
|
|
|
|
add_quats( spin_quat, g_Parm_3D_Visu.m_Quat, g_Parm_3D_Visu.m_Quat );
|
|
|
|
}
|
|
|
|
else if( event.MiddleIsDown() )
|
|
|
|
{
|
|
|
|
/* middle button drag -> pan */
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
/* Current zoom and an additional factor are taken into account
|
|
|
|
* for the amount of panning. */
|
2008-10-30 10:55:46 +00:00
|
|
|
const double PAN_FACTOR = 8.0 * g_Parm_3D_Visu.m_Zoom;
|
2009-11-04 20:46:53 +00:00
|
|
|
g_Draw3d_dx -= PAN_FACTOR *
|
|
|
|
( g_Parm_3D_Visu.m_Beginx - event.GetX() ) / size.x;
|
|
|
|
g_Draw3d_dy -= PAN_FACTOR *
|
|
|
|
(event.GetY() - g_Parm_3D_Visu.m_Beginy) / size.y;
|
2008-03-03 08:00:26 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* orientation has changed, redraw mesh */
|
2007-08-20 01:20:48 +00:00
|
|
|
DisplayStatus();
|
|
|
|
Refresh( FALSE );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_Parm_3D_Visu.m_Beginx = event.GetX();
|
|
|
|
g_Parm_3D_Visu.m_Beginy = event.GetY();
|
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Construct and display a popup menu when the right button is clicked.
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void Pcb3D_GLCanvas::OnRightClick( wxMouseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPoint pos;
|
|
|
|
wxMenu PopUpMenu;
|
|
|
|
|
|
|
|
pos.x = event.GetX(); pos.y = event.GetY();
|
|
|
|
wxMenuItem* item = new wxMenuItem( &PopUpMenu, ID_POPUP_ZOOMIN,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Zoom +" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( zoom_in_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_ZOOMOUT,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Zoom -" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( zoom_out_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
PopUpMenu.AppendSeparator();
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_VIEW_ZPOS,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Top View" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( axis3d_top_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_VIEW_ZNEG,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Bottom View" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( axis3d_bottom_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
PopUpMenu.AppendSeparator();
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_VIEW_XPOS,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Right View" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( axis3d_right_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_VIEW_XNEG,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Left View" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( axis3d_left_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
|
|
|
|
PopUpMenu.AppendSeparator();
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_VIEW_YPOS,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Front View" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( axis3d_front_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_VIEW_YNEG,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Back View" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( axis3d_back_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
PopUpMenu.AppendSeparator();
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_LEFT,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Move left <-" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( left_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_RIGHT,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Move right ->" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( right_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_UP,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Move Up ^" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( up_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
item = new wxMenuItem( &PopUpMenu, ID_POPUP_MOVE3D_DOWN,
|
2010-01-19 20:43:44 +00:00
|
|
|
_( "Move Down" ) );
|
2007-08-20 01:20:48 +00:00
|
|
|
item->SetBitmap( down_xpm );
|
|
|
|
PopUpMenu.Append( item );
|
|
|
|
|
|
|
|
PopupMenu( &PopUpMenu, pos );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
void Pcb3D_GLCanvas::OnPopUpMenu( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
int key = 0;
|
|
|
|
|
|
|
|
switch( event.GetId() )
|
|
|
|
{
|
|
|
|
case ID_POPUP_ZOOMIN:
|
|
|
|
key = WXK_F1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_ZOOMOUT:
|
|
|
|
key = WXK_F2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_VIEW_XPOS:
|
|
|
|
key = 'x';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_VIEW_XNEG:
|
|
|
|
key = 'X';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_VIEW_YPOS:
|
|
|
|
key = 'y';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_VIEW_YNEG:
|
|
|
|
key = 'Y';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_VIEW_ZPOS:
|
|
|
|
key = 'z';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_VIEW_ZNEG:
|
|
|
|
key = 'Z';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_MOVE3D_LEFT:
|
|
|
|
key = WXK_LEFT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_MOVE3D_RIGHT:
|
|
|
|
key = WXK_RIGHT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_MOVE3D_UP:
|
|
|
|
key = WXK_UP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_POPUP_MOVE3D_DOWN:
|
|
|
|
key = WXK_DOWN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SetView3D( key );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
void Pcb3D_GLCanvas::DisplayStatus()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxString msg;
|
|
|
|
|
|
|
|
msg.Printf( wxT( "dx %3.2f" ), g_Draw3d_dx );
|
|
|
|
m_Parent->SetStatusText( msg, 1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
msg.Printf( wxT( "dy %3.2f" ), g_Draw3d_dy );
|
|
|
|
m_Parent->SetStatusText( msg, 2 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
msg.Printf( wxT( "View: %3.1f" ), 45 * g_Parm_3D_Visu.m_Zoom );
|
|
|
|
m_Parent->SetStatusText( msg, 3 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Pcb3D_GLCanvas::OnPaint( wxPaintEvent& event )
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxPaintDC dc( this );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
Redraw();
|
|
|
|
event.Skip();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
void Pcb3D_GLCanvas::OnEraseBackground( wxEraseEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
// Do nothing, to avoid flashing.
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Initialize broad parameters for OpenGL */
|
2007-05-06 16:03:28 +00:00
|
|
|
void Pcb3D_GLCanvas::InitGL()
|
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
wxSize size = GetClientSize();
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( !m_init )
|
|
|
|
{
|
|
|
|
m_init = TRUE;
|
|
|
|
g_Parm_3D_Visu.m_Zoom = 1.0;
|
|
|
|
ZBottom = 1.0; ZTop = 10.0;
|
2009-08-04 18:21:32 +00:00
|
|
|
|
|
|
|
glDisable( GL_CULL_FACE ); // show back faces
|
|
|
|
|
|
|
|
glEnable( GL_DEPTH_TEST ); // Enable z-buferring
|
|
|
|
|
|
|
|
glEnable( GL_LINE_SMOOTH );
|
|
|
|
glEnable( GL_COLOR_MATERIAL );
|
|
|
|
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
|
|
|
|
|
|
|
|
/* speedups */
|
|
|
|
glEnable( GL_DITHER );
|
|
|
|
glShadeModel( GL_SMOOTH );
|
|
|
|
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
|
|
|
|
glHint( GL_POLYGON_SMOOTH_HINT, GL_FASTEST );
|
|
|
|
|
|
|
|
/* blend */
|
|
|
|
glEnable( GL_BLEND );
|
|
|
|
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
|
2007-08-20 01:20:48 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* set viewing projection */
|
2009-11-04 20:46:53 +00:00
|
|
|
|
|
|
|
// Ratio width / height of the window display
|
|
|
|
double ratio_HV = (double) size.x / size.y;
|
2007-08-20 01:20:48 +00:00
|
|
|
glMatrixMode( GL_PROJECTION );
|
2007-05-06 16:03:28 +00:00
|
|
|
glLoadIdentity();
|
|
|
|
|
2009-05-28 08:42:24 +00:00
|
|
|
#define MAX_VIEW_ANGLE 160.0 / 45.0
|
2007-08-20 01:20:48 +00:00
|
|
|
if( g_Parm_3D_Visu.m_Zoom > MAX_VIEW_ANGLE )
|
|
|
|
g_Parm_3D_Visu.m_Zoom = MAX_VIEW_ANGLE;
|
|
|
|
gluPerspective( 45.0 * g_Parm_3D_Visu.m_Zoom, ratio_HV, 1, 10 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
// glFrustum(-1., 1.1F, -1.1F, 1.1F, ZBottom, ZTop);
|
|
|
|
|
|
|
|
/* position viewer */
|
2007-08-20 01:20:48 +00:00
|
|
|
glMatrixMode( GL_MODELVIEW );
|
|
|
|
glLoadIdentity();
|
|
|
|
glTranslatef( 0.0F, 0.0F, -( ZBottom + ZTop) / 2 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* clear color and depth buffers */
|
|
|
|
glClearColor( g_Parm_3D_Visu.m_BgColor.m_Red,
|
2007-08-20 01:20:48 +00:00
|
|
|
g_Parm_3D_Visu.m_BgColor.m_Green,
|
|
|
|
g_Parm_3D_Visu.m_BgColor.m_Blue, 1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
/* Setup light souces: */
|
|
|
|
SetLights();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Initialize OpenGL light sources. */
|
2007-09-01 12:00:30 +00:00
|
|
|
void Pcb3D_GLCanvas::SetLights()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2007-08-20 01:20:48 +00:00
|
|
|
double light;
|
|
|
|
GLfloat light_color[4];
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* set viewing projection */
|
2007-08-20 01:20:48 +00:00
|
|
|
light_color[3] = 1.0;
|
|
|
|
GLfloat Z_axis_pos[4] = { 0.0, 0.0, 3.0, 0.0 };
|
|
|
|
GLfloat lowZ_axis_pos[4] = { 0.0, 0.0, -3.0, 0.5 };
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* activate light */
|
2007-08-20 01:20:48 +00:00
|
|
|
light = 1.0;
|
|
|
|
light_color[0] = light_color[1] = light_color[2] = light;
|
|
|
|
glLightfv( GL_LIGHT0, GL_POSITION, Z_axis_pos );
|
|
|
|
glLightfv( GL_LIGHT0, GL_DIFFUSE, light_color );
|
|
|
|
light = 0.3;
|
|
|
|
light_color[0] = light_color[1] = light_color[2] = light;
|
|
|
|
glLightfv( GL_LIGHT1, GL_POSITION, lowZ_axis_pos );
|
|
|
|
glLightfv( GL_LIGHT1, GL_DIFFUSE, light_color );
|
|
|
|
glEnable( GL_LIGHT0 ); // White spot on Z axis
|
|
|
|
glEnable( GL_LIGHT1 ); // White spot on Z axis ( bottom)
|
|
|
|
glEnable( GL_LIGHTING );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Create a Screenshot of the current 3D view.
|
2010-01-25 14:01:46 +00:00
|
|
|
* Output file format is png or jpeg, or image is copied to the clipboard
|
2007-08-20 01:20:48 +00:00
|
|
|
*/
|
2009-11-04 20:46:53 +00:00
|
|
|
void Pcb3D_GLCanvas::TakeScreenshot( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn( m_Parent->m_Parent->GetScreen()->m_FileName );
|
2009-05-28 08:42:24 +00:00
|
|
|
wxString FullFileName;
|
|
|
|
wxString file_ext, mask;
|
|
|
|
bool fmt_is_jpeg = FALSE;
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
if( event.GetId() == ID_MENU_SCREENCOPY_JPEG )
|
|
|
|
fmt_is_jpeg = TRUE;
|
|
|
|
if( event.GetId() != ID_TOOL_SCREENCOPY_TOCLIBBOARD )
|
|
|
|
{
|
2010-01-25 14:01:46 +00:00
|
|
|
file_ext = fmt_is_jpeg ? wxT( "jpg" ) : wxT( "png" );
|
|
|
|
mask = wxT( "*." ) + file_ext;
|
2007-08-20 01:20:48 +00:00
|
|
|
FullFileName = m_Parent->m_Parent->GetScreen()->m_FileName;
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.SetExt( file_ext );
|
2007-08-20 01:20:48 +00:00
|
|
|
|
|
|
|
FullFileName =
|
2009-11-04 20:46:53 +00:00
|
|
|
EDA_FileSelector( _( "3D Image filename:" ), wxEmptyString,
|
|
|
|
fn.GetFullName(), file_ext, mask, this,
|
|
|
|
wxFD_SAVE, TRUE );
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( FullFileName.IsEmpty() )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Redraw( true );
|
2009-05-28 08:42:24 +00:00
|
|
|
|
2009-08-20 11:44:06 +00:00
|
|
|
wxSize image_size = GetClientSize();
|
2010-01-19 20:43:44 +00:00
|
|
|
#ifndef __WXMAC__
|
2009-08-20 11:44:06 +00:00
|
|
|
wxClientDC dc( this );
|
|
|
|
wxBitmap bitmap( image_size.x, image_size.y );
|
|
|
|
wxMemoryDC memdc;
|
|
|
|
memdc.SelectObject( bitmap );
|
|
|
|
memdc.Blit( 0, 0, image_size.x, image_size.y, &dc, 0, 0 );
|
|
|
|
memdc.SelectObject( wxNullBitmap );
|
2010-01-19 20:43:44 +00:00
|
|
|
#else
|
|
|
|
struct vieport_params
|
|
|
|
{
|
|
|
|
GLint originx;
|
|
|
|
GLint originy;
|
|
|
|
GLint x;
|
|
|
|
GLint y;
|
|
|
|
} viewport;
|
|
|
|
|
|
|
|
wxWindowUpdateLocker noUpdates( this );
|
|
|
|
glGetIntegerv( GL_VIEWPORT, (GLint*) &viewport );
|
|
|
|
|
|
|
|
unsigned char* pixelbuffer = (unsigned char*) malloc( viewport.x * viewport.y * 3 );
|
|
|
|
unsigned char* alphabuffer = (unsigned char*) malloc( viewport.x * viewport.y );
|
|
|
|
wxImage image( viewport.x, viewport.y );
|
|
|
|
|
2010-01-24 16:27:36 +00:00
|
|
|
glPixelStorei( GL_PACK_ALIGNMENT, 1 );
|
2010-01-19 20:43:44 +00:00
|
|
|
glReadBuffer( GL_BACK_LEFT );
|
|
|
|
glReadPixels( viewport.originx,
|
|
|
|
viewport.originy,
|
|
|
|
viewport.x,
|
|
|
|
viewport.y,
|
|
|
|
GL_RGB,
|
2010-01-24 16:27:36 +00:00
|
|
|
GL_UNSIGNED_BYTE,
|
2010-01-19 20:43:44 +00:00
|
|
|
pixelbuffer );
|
|
|
|
glReadPixels( viewport.originx,
|
|
|
|
viewport.originy,
|
|
|
|
viewport.x,
|
|
|
|
viewport.y,
|
|
|
|
GL_ALPHA,
|
2010-01-24 16:27:36 +00:00
|
|
|
GL_UNSIGNED_BYTE,
|
2010-01-19 20:43:44 +00:00
|
|
|
alphabuffer );
|
|
|
|
|
|
|
|
|
|
|
|
image.SetData( pixelbuffer );
|
|
|
|
image.SetAlpha( alphabuffer );
|
|
|
|
image = image.Mirror( false );
|
|
|
|
wxBitmap bitmap( image );
|
|
|
|
#endif
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( event.GetId() == ID_TOOL_SCREENCOPY_TOCLIBBOARD )
|
|
|
|
{
|
|
|
|
wxBitmapDataObject* dobjBmp = new wxBitmapDataObject;
|
|
|
|
dobjBmp->SetBitmap( bitmap );
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
if( !wxTheClipboard->SetData( dobjBmp ) )
|
|
|
|
wxLogError( _T( "Failed to copy image to clipboard" ) );
|
2009-11-04 20:46:53 +00:00
|
|
|
wxTheClipboard->Flush(); /* the data in clipboard will stay
|
|
|
|
* available after the
|
|
|
|
* application exits */
|
2007-08-20 01:20:48 +00:00
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-08-20 11:44:06 +00:00
|
|
|
wxImage image = bitmap.ConvertToImage();
|
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
if( !image.SaveFile( FullFileName,
|
2009-11-04 20:46:53 +00:00
|
|
|
fmt_is_jpeg ? wxBITMAP_TYPE_JPEG :
|
|
|
|
wxBITMAP_TYPE_PNG ) )
|
2007-08-20 01:20:48 +00:00
|
|
|
wxLogError( wxT( "Can't save file" ) );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2007-08-20 01:20:48 +00:00
|
|
|
image.Destroy();
|
|
|
|
}
|
|
|
|
}
|