2007-05-06 16:03:28 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: 3d_aux.cpp
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
|
|
|
#if !wxUSE_GLCANVAS
|
|
|
|
#error Please set wxUSE_GLCANVAS to 1 in setup.h.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
|
|
|
|
#include "3d_viewer.h"
|
|
|
|
#include "trackball.h"
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2008-12-06 08:21:54 +00:00
|
|
|
void S3D_MASTER::Set_Object_Coords( S3D_Vertex* coord, int nbcoord )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
int ii;
|
|
|
|
|
|
|
|
|
|
|
|
/* adjust object scale, rotation and offset position */
|
|
|
|
for( ii = 0; ii < nbcoord; ii++ )
|
|
|
|
{
|
|
|
|
coord[ii].x *= m_MatScale.x;
|
|
|
|
coord[ii].y *= m_MatScale.y;
|
|
|
|
coord[ii].z *= m_MatScale.z;
|
|
|
|
/* adjust rotation */
|
|
|
|
if( m_MatRotation.x )
|
|
|
|
RotatePoint( &coord[ii].y, &coord[ii].z,
|
2009-11-04 20:46:53 +00:00
|
|
|
(int) (m_MatRotation.x * 10) );
|
2008-03-11 05:41:06 +00:00
|
|
|
if( m_MatRotation.y )
|
|
|
|
RotatePoint( &coord[ii].z, &coord[ii].x,
|
2009-11-04 20:46:53 +00:00
|
|
|
(int) (m_MatRotation.y * 10) );
|
2008-03-11 05:41:06 +00:00
|
|
|
if( m_MatRotation.z )
|
|
|
|
RotatePoint( &coord[ii].x, &coord[ii].y,
|
2009-11-04 20:46:53 +00:00
|
|
|
(int) (m_MatRotation.z * 10) );
|
2008-03-11 05:41:06 +00:00
|
|
|
/* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
|
|
|
|
#define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB)
|
|
|
|
coord[ii].x += m_MatPosition.x * SCALE_3D_CONV;
|
|
|
|
coord[ii].y += m_MatPosition.y * SCALE_3D_CONV;
|
|
|
|
coord[ii].z += m_MatPosition.z * SCALE_3D_CONV;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
int ii;
|
|
|
|
GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* ignore faces with less than 3 points */
|
2008-03-11 05:41:06 +00:00
|
|
|
if( nbcoord < 3 )
|
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* calculate normal direction */
|
|
|
|
ax = coord[1].x - coord[0].x;
|
|
|
|
ay = coord[1].y - coord[0].y;
|
|
|
|
az = coord[1].z - coord[0].z;
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
bx = coord[nbcoord - 1].x - coord[0].x;
|
|
|
|
by = coord[nbcoord - 1].y - coord[0].y;
|
|
|
|
bz = coord[nbcoord - 1].z - coord[0].z;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
nx = ay * bz - az * by;
|
|
|
|
ny = az * bx - ax * bz;
|
|
|
|
nz = ax * by - ay * bx;
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
r = sqrt( nx * nx + ny * ny + nz * nz );
|
|
|
|
if( r >= 0.000001 ) /* avoid division by zero */
|
|
|
|
{
|
|
|
|
nx /= r; ny /= r; nz /= r;
|
|
|
|
glNormal3f( nx, ny, nz );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* glBegin/glEnd */
|
2008-03-11 05:41:06 +00:00
|
|
|
switch( nbcoord )
|
|
|
|
{
|
|
|
|
case 3:
|
|
|
|
glBegin( GL_TRIANGLES );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
glBegin( GL_QUADS );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
glBegin( GL_POLYGON );
|
|
|
|
break;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* draw polygon/triangle/quad */
|
2008-03-11 05:41:06 +00:00
|
|
|
for( ii = 0; ii < nbcoord; ii++ )
|
|
|
|
{
|
|
|
|
glVertex3f( coord[ii].x * DataScale3D,
|
2009-11-04 20:46:53 +00:00
|
|
|
coord[ii].y * DataScale3D,
|
|
|
|
coord[ii].z * DataScale3D );
|
2008-03-11 05:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glEnd();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
GLuint Pcb3D_GLCanvas::DisplayCubeforTest()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
GLuint gllist = glGenLists( 1 );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
glNewList( gllist, GL_COMPILE_AND_EXECUTE );
|
|
|
|
/* draw six faces of a cube */
|
2008-03-11 05:41:06 +00:00
|
|
|
glBegin( GL_QUADS );
|
|
|
|
glNormal3f( 0.0F, 0.0F, 1.0F );
|
|
|
|
glVertex3f( 0.5F, 0.5F, 0.5F ); glVertex3f( -0.5F, 0.5F, 0.5F );
|
|
|
|
glVertex3f( -0.5F, -0.5F, 0.5F ); glVertex3f( 0.5F, -0.5F, 0.5F );
|
|
|
|
|
|
|
|
glNormal3f( 0.0F, 0.0F, -1.0F );
|
|
|
|
glVertex3f( -0.5F, -0.5F, -0.5F ); glVertex3f( -0.5F, 0.5F, -0.5F );
|
|
|
|
glVertex3f( 0.5F, 0.5F, -0.5F ); glVertex3f( 0.5F, -0.5F, -0.5F );
|
|
|
|
|
|
|
|
glNormal3f( 0.0F, 1.0F, 0.0F );
|
|
|
|
glVertex3f( 0.5F, 0.5F, 0.5F ); glVertex3f( 0.5F, 0.5F, -0.5F );
|
|
|
|
glVertex3f( -0.5F, 0.5F, -0.5F ); glVertex3f( -0.5F, 0.5F, 0.5F );
|
|
|
|
|
|
|
|
glNormal3f( 0.0F, -1.0F, 0.0F );
|
|
|
|
glVertex3f( -0.5F, -0.5F, -0.5F ); glVertex3f( 0.5F, -0.5F, -0.5F );
|
|
|
|
glVertex3f( 0.5F, -0.5F, 0.5F ); glVertex3f( -0.5F, -0.5F, 0.5F );
|
|
|
|
|
|
|
|
glNormal3f( 1.0F, 0.0F, 0.0F );
|
|
|
|
glVertex3f( 0.5F, 0.5F, 0.5F ); glVertex3f( 0.5F, -0.5F, 0.5F );
|
|
|
|
glVertex3f( 0.5F, -0.5F, -0.5F ); glVertex3f( 0.5F, 0.5F, -0.5F );
|
|
|
|
|
|
|
|
glNormal3f( -1.0F, 0.0F, 0.0F );
|
|
|
|
glVertex3f( -0.5F, -0.5F, -0.5F ); glVertex3f( -0.5F, -0.5F, 0.5F );
|
|
|
|
glVertex3f( -0.5F, 0.5F, 0.5F ); glVertex3f( -0.5F, 0.5F, -0.5F );
|
2007-05-06 16:03:28 +00:00
|
|
|
glEnd();
|
|
|
|
|
|
|
|
glEndList();
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
return gllist;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************/
|
|
|
|
/* class Info_3D_Visu */
|
|
|
|
/**********************/
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
Info_3D_Visu::Info_3D_Visu()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
int ii;
|
|
|
|
|
|
|
|
m_Beginx = m_Beginy = 0.0; /* position of mouse */
|
|
|
|
m_Zoom = 1.0; /* field of view in degrees */
|
|
|
|
trackball( m_Quat, 0.0, 0.0, 0.0, 0.0 );
|
|
|
|
for( ii = 0; ii < 4; ii++ )
|
|
|
|
m_Rot[ii] = 0.0;
|
|
|
|
|
|
|
|
m_Layers = 1;
|
2008-10-26 19:09:20 +00:00
|
|
|
m_BoardSettings = NULL;
|
|
|
|
m_Draw3DAxis = TRUE;
|
|
|
|
m_Draw3DModule = TRUE;
|
|
|
|
m_Draw3DZone = TRUE;
|
|
|
|
m_Draw3DComments = TRUE;
|
|
|
|
m_Draw3DDrawings = TRUE;
|
2009-11-04 20:46:53 +00:00
|
|
|
m_Draw3DEco1 = TRUE;
|
|
|
|
m_Draw3DEco2 = TRUE;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
Info_3D_Visu::~Info_3D_Visu()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Display and edit a Vertex (triplet of values) in INCHES or MM or without
|
|
|
|
* units */
|
2008-03-11 05:41:06 +00:00
|
|
|
WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title,
|
|
|
|
wxBoxSizer* BoxSizer,
|
2010-07-12 14:07:09 +00:00
|
|
|
UserUnitType units, int internal_unit )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
wxString text;
|
|
|
|
wxStaticText* msgtitle;
|
|
|
|
|
|
|
|
m_Units = units;
|
|
|
|
m_Internal_Unit = internal_unit;
|
|
|
|
|
|
|
|
if( title.IsEmpty() )
|
|
|
|
text = _( "Vertex " );
|
|
|
|
else
|
|
|
|
text = title;
|
|
|
|
text += ReturnUnitSymbol( units );
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
msgtitle = new wxStaticText( parent, -1, text, wxDefaultPosition,
|
|
|
|
wxSize( -1, -1 ), 0 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
BoxSizer->Add(
|
|
|
|
msgtitle,
|
|
|
|
wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM |
|
|
|
|
wxADJUST_MINSIZE );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
wxFlexGridSizer* GridSizer = new wxFlexGridSizer( 3, 2, 0, 0 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
BoxSizer->Add( GridSizer, 0, wxGROW | wxALL, 5 );
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
msgtitle = new wxStaticText( parent, -1, wxT( "X:" ) );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
GridSizer->Add( msgtitle, 0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
|
|
|
|
5 );
|
|
|
|
m_XValueCtrl = new wxTextCtrl( parent, -1, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxSize( -1, -1 ), 0 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
GridSizer->Add( m_XValueCtrl,
|
2009-11-04 20:46:53 +00:00
|
|
|
0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT,
|
|
|
|
5 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
msgtitle = new wxStaticText( parent, -1, wxT( "Y:" ), wxDefaultPosition,
|
|
|
|
wxSize( -1, -1 ), 0 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
GridSizer->Add( msgtitle,
|
2009-11-04 20:46:53 +00:00
|
|
|
0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
|
|
|
|
5 );
|
|
|
|
m_YValueCtrl = new wxTextCtrl( parent, -1, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxSize( -1, -1 ), 0 );
|
|
|
|
|
|
|
|
GridSizer->Add( m_YValueCtrl, 0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT,
|
|
|
|
5 );
|
|
|
|
|
|
|
|
msgtitle = new wxStaticText( parent, -1, wxT( "Z:" ), wxDefaultPosition,
|
|
|
|
wxSize( -1, -1 ), 0 );
|
|
|
|
|
|
|
|
GridSizer->Add( msgtitle, 0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
|
|
|
|
5 );
|
|
|
|
m_ZValueCtrl = new wxTextCtrl( parent, -1, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxSize( -1, -1 ), 0 );
|
|
|
|
|
|
|
|
GridSizer->Add( m_ZValueCtrl, 0,
|
|
|
|
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL |
|
|
|
|
wxLEFT | wxRIGHT,
|
|
|
|
5 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2007-09-13 11:55:46 +00:00
|
|
|
WinEDA_VertexCtrl::~WinEDA_VertexCtrl()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
/* Returns (in internal units) to coordinate between (in user units) */
|
2007-09-13 11:55:46 +00:00
|
|
|
S3D_Vertex WinEDA_VertexCtrl::GetValue()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
S3D_Vertex value;
|
|
|
|
double dtmp;
|
|
|
|
|
|
|
|
m_XValueCtrl->GetValue().ToDouble( &dtmp );
|
|
|
|
value.x = dtmp;
|
|
|
|
m_YValueCtrl->GetValue().ToDouble( &dtmp );
|
|
|
|
value.y = dtmp;
|
|
|
|
m_ZValueCtrl->GetValue().ToDouble( &dtmp );
|
|
|
|
value.z = dtmp;
|
|
|
|
return value;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
void WinEDA_VertexCtrl::SetValue( S3D_Vertex vertex )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
wxString text;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
text.Printf( wxT( "%f" ), vertex.x );
|
|
|
|
m_XValueCtrl->Clear();
|
|
|
|
m_XValueCtrl->AppendText( text );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
text.Printf( wxT( "%f" ), vertex.y );
|
|
|
|
m_YValueCtrl->Clear();
|
|
|
|
m_YValueCtrl->AppendText( text );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
text.Printf( wxT( "%f" ), vertex.z );
|
|
|
|
m_ZValueCtrl->Clear();
|
|
|
|
m_ZValueCtrl->AppendText( text );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
void WinEDA_VertexCtrl::Enable( bool onoff )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2008-03-11 05:41:06 +00:00
|
|
|
m_XValueCtrl->Enable( onoff );
|
|
|
|
m_YValueCtrl->Enable( onoff );
|
|
|
|
m_ZValueCtrl->Enable( onoff );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|