Commit 263d80fe authored by dickelbeck's avatar dickelbeck

beautified

parent 6153dadc
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// Name: 3d_aux.cpp // Name: 3d_aux.cpp
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
...@@ -24,91 +25,93 @@ ...@@ -24,91 +25,93 @@
#include "trackball.h" #include "trackball.h"
/**************************************************************************/ /**************************************************************************/
void Struct3D_Master::Set_Object_Coords(S3D_Vertex * coord, int nbcoord ) void Struct3D_Master::Set_Object_Coords( S3D_Vertex* coord, int nbcoord )
/**************************************************************************/ /**************************************************************************/
{ {
int ii; int ii;
/* adjust object scale, rotation and offset position */ /* adjust object scale, rotation and offset position */
for ( ii = 0; ii < nbcoord; ii++ ) for( ii = 0; ii < nbcoord; ii++ )
{ {
coord[ii].x *= m_MatScale.x; coord[ii].x *= m_MatScale.x;
coord[ii].y *= m_MatScale.y; coord[ii].y *= m_MatScale.y;
coord[ii].z *= m_MatScale.z; coord[ii].z *= m_MatScale.z;
/* adjust rotation */ /* adjust rotation */
if ( m_MatRotation.x ) if( m_MatRotation.x )
RotatePoint(&coord[ii].y, &coord[ii].z, RotatePoint( &coord[ii].y, &coord[ii].z,
(int)(m_MatRotation.x * 10)); (int) (m_MatRotation.x * 10) );
if ( m_MatRotation.y ) if( m_MatRotation.y )
RotatePoint(&coord[ii].z, &coord[ii].x, RotatePoint( &coord[ii].z, &coord[ii].x,
(int)(m_MatRotation.y * 10)); (int) (m_MatRotation.y * 10) );
if ( m_MatRotation.z ) if( m_MatRotation.z )
RotatePoint(&coord[ii].x, &coord[ii].y, RotatePoint( &coord[ii].x, &coord[ii].y,
(int)(m_MatRotation.z * 10)); (int) (m_MatRotation.z * 10) );
/* adjust offset position (offset is given in UNIT 3D (0.1 inch) */ /* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
#define SCALE_3D_CONV (PCB_INTERNAL_UNIT/UNITS3D_TO_UNITSPCB) #define SCALE_3D_CONV (PCB_INTERNAL_UNIT / UNITS3D_TO_UNITSPCB)
coord[ii].x += m_MatPosition.x * SCALE_3D_CONV; coord[ii].x += m_MatPosition.x * SCALE_3D_CONV;
coord[ii].y += m_MatPosition.y * SCALE_3D_CONV; coord[ii].y += m_MatPosition.y * SCALE_3D_CONV;
coord[ii].z += m_MatPosition.z * SCALE_3D_CONV; coord[ii].z += m_MatPosition.z * SCALE_3D_CONV;
} }
} }
/************************************************************/ /************************************************************/
void Set_Object_Data(const S3D_Vertex * coord, int nbcoord ) void Set_Object_Data( const S3D_Vertex* coord, int nbcoord )
/************************************************************/ /************************************************************/
{ {
int ii; int ii;
GLfloat ax,ay,az,bx,by,bz,nx,ny,nz,r; GLfloat ax, ay, az, bx, by, bz, nx, ny, nz, r;
/* ignore faces with less than 3 points */ /* ignore faces with less than 3 points */
if (nbcoord < 3) return; if( nbcoord < 3 )
return;
/* calculate normal direction */ /* calculate normal direction */
ax = coord[1].x - coord[0].x; ax = coord[1].x - coord[0].x;
ay = coord[1].y - coord[0].y; ay = coord[1].y - coord[0].y;
az = coord[1].z - coord[0].z; az = coord[1].z - coord[0].z;
bx = coord[nbcoord-1].x - coord[0].x; bx = coord[nbcoord - 1].x - coord[0].x;
by = coord[nbcoord-1].y - coord[0].y; by = coord[nbcoord - 1].y - coord[0].y;
bz = coord[nbcoord-1].z - coord[0].z; bz = coord[nbcoord - 1].z - coord[0].z;
nx = ay * bz - az * by; nx = ay * bz - az * by;
ny = az * bx - ax * bz; ny = az * bx - ax * bz;
nz = ax * by - ay * bx; nz = ax * by - ay * bx;
r = sqrt(nx*nx + ny*ny + nz*nz); r = sqrt( nx * nx + ny * ny + nz * nz );
if (r >= 0.000001) /* avoid division by zero */ if( r >= 0.000001 ) /* avoid division by zero */
{ {
nx /= r; ny /= r; nz /= r; nx /= r; ny /= r; nz /= r;
glNormal3f(nx,ny,nz); glNormal3f( nx, ny, nz );
} }
/* glBegin/glEnd */ /* glBegin/glEnd */
switch (nbcoord) switch( nbcoord )
{ {
case 3: case 3:
glBegin(GL_TRIANGLES); glBegin( GL_TRIANGLES );
break; break;
case 4: case 4:
glBegin(GL_QUADS); glBegin( GL_QUADS );
break; break;
default: default:
glBegin(GL_POLYGON); glBegin( GL_POLYGON );
break; break;
} }
/* draw polygon/triangle/quad */ /* draw polygon/triangle/quad */
for (ii = 0; ii < nbcoord; ii++) for( ii = 0; ii < nbcoord; ii++ )
{ {
glVertex3f(coord[ii].x * DataScale3D, glVertex3f( coord[ii].x * DataScale3D,
coord[ii].y * DataScale3D, coord[ii].y * DataScale3D,
coord[ii].z * DataScale3D); coord[ii].z * DataScale3D );
} }
glEnd(); glEnd();
} }
...@@ -116,43 +119,42 @@ GLfloat ax,ay,az,bx,by,bz,nx,ny,nz,r; ...@@ -116,43 +119,42 @@ GLfloat ax,ay,az,bx,by,bz,nx,ny,nz,r;
GLuint Pcb3D_GLCanvas::DisplayCubeforTest() GLuint Pcb3D_GLCanvas::DisplayCubeforTest()
/**********************************************/ /**********************************************/
{ {
GLuint gllist = glGenLists( 1 ); GLuint gllist = glGenLists( 1 );
glNewList( gllist, GL_COMPILE_AND_EXECUTE ); glNewList( gllist, GL_COMPILE_AND_EXECUTE );
/* draw six faces of a cube */ /* draw six faces of a cube */
glBegin(GL_QUADS); glBegin( GL_QUADS );
glNormal3f( 0.0F, 0.0F, 1.0F); 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 );
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); 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 );
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); 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 );
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); 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 );
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); 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 );
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); 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 );
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 );
glEnd(); glEnd();
glEndList(); glEndList();
return gllist; return gllist;
} }
/**********************/ /**********************/
/* class Info_3D_Visu */ /* class Info_3D_Visu */
/**********************/ /**********************/
...@@ -160,13 +162,16 @@ GLuint gllist = glGenLists( 1 ); ...@@ -160,13 +162,16 @@ GLuint gllist = glGenLists( 1 );
/* Constructor */ /* Constructor */
Info_3D_Visu::Info_3D_Visu() Info_3D_Visu::Info_3D_Visu()
{ {
int ii; int ii;
m_Beginx = m_Beginy = 0.0; /* position of mouse */
m_Zoom = 1.0; /* field of view in degrees */ m_Beginx = m_Beginy = 0.0; /* position of mouse */
trackball( m_Quat, 0.0, 0.0, 0.0, 0.0 ); m_Zoom = 1.0; /* field of view in degrees */
for ( ii = 0; ii < 4; ii++ ) m_Rot[ii] = 0.0; trackball( m_Quat, 0.0, 0.0, 0.0, 0.0 );
m_Layers = 1; for( ii = 0; ii < 4; ii++ )
m_BoardSettings = NULL; m_Rot[ii] = 0.0;
m_Layers = 1;
m_BoardSettings = NULL;
} }
...@@ -180,42 +185,92 @@ Info_3D_Visu::~Info_3D_Visu() ...@@ -180,42 +185,92 @@ Info_3D_Visu::~Info_3D_Visu()
/* en INCHES ou MM ou sans unites */ /* en INCHES ou MM ou sans unites */
/*****************************************************************/ /*****************************************************************/
WinEDA_VertexCtrl::WinEDA_VertexCtrl(wxWindow *parent, const wxString & title, WinEDA_VertexCtrl::WinEDA_VertexCtrl( wxWindow* parent, const wxString& title,
wxBoxSizer * BoxSizer, wxBoxSizer* BoxSizer,
int units, int internal_unit) int units, int internal_unit )
{ {
wxString text; wxString text;
wxStaticText * msgtitle; wxStaticText* msgtitle;
m_Units = units; m_Units = units;
m_Internal_Unit = internal_unit; m_Internal_Unit = internal_unit;
if ( title.IsEmpty() ) text = _("Vertex "); if( title.IsEmpty() )
else text = title; text = _( "Vertex " );
text += ReturnUnitSymbol(units); else
text = title;
msgtitle = new wxStaticText(parent, -1, text, wxDefaultPosition, wxSize(-1,-1), 0 ); text += ReturnUnitSymbol( units );
BoxSizer->Add(msgtitle, wxGROW|wxLEFT|wxRIGHT|wxTOP|wxBOTTOM|wxADJUST_MINSIZE);
msgtitle = new wxStaticText( parent, -1, text, wxDefaultPosition, wxSize(
wxFlexGridSizer * GridSizer = new wxFlexGridSizer(3, 2, 0, 0); -1,
BoxSizer->Add(GridSizer, 0, wxGROW|wxALL, 5); -1 ), 0 );
msgtitle = new wxStaticText(parent, -1, wxT("X:")); BoxSizer->Add( msgtitle, wxGROW | wxLEFT | wxRIGHT | wxTOP | wxBOTTOM | wxADJUST_MINSIZE );
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 ); wxFlexGridSizer* GridSizer = new wxFlexGridSizer( 3, 2, 0, 0 );
GridSizer->Add(m_XValueCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5);
BoxSizer->Add( GridSizer, 0, wxGROW | wxALL, 5 );
msgtitle = new wxStaticText(parent, -1, wxT("Y:"), wxDefaultPosition, wxSize(-1,-1), 0 );
GridSizer->Add(msgtitle, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5); msgtitle = new wxStaticText( parent, -1, wxT( "X:" ) );
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); GridSizer->Add( msgtitle,
0,
msgtitle = new wxStaticText(parent, -1, wxT("Z:"), wxDefaultPosition, wxSize(-1,-1), 0 ); wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT | wxADJUST_MINSIZE,
GridSizer->Add(msgtitle, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT|wxADJUST_MINSIZE, 5); 5 );
m_ZValueCtrl = new wxTextCtrl(parent, -1, wxEmptyString, wxDefaultPosition, wxSize(-1,-1), 0 ); m_XValueCtrl = new wxTextCtrl( parent,
GridSizer->Add(m_ZValueCtrl, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5); -1,
wxEmptyString,
wxDefaultPosition,
wxSize( -1, -1 ),
0 );
GridSizer->Add( m_XValueCtrl,
0,
wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT,
5 );
msgtitle = new wxStaticText( parent, -1, wxT(
"Y:" ), wxDefaultPosition, wxSize( -1,
-1 ), 0 );
GridSizer->Add( msgtitle,
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 );
} }
WinEDA_VertexCtrl::~WinEDA_VertexCtrl() WinEDA_VertexCtrl::~WinEDA_VertexCtrl()
{ {
} }
...@@ -224,46 +279,48 @@ WinEDA_VertexCtrl::~WinEDA_VertexCtrl() ...@@ -224,46 +279,48 @@ WinEDA_VertexCtrl::~WinEDA_VertexCtrl()
/*******************************************/ /*******************************************/
S3D_Vertex WinEDA_VertexCtrl::GetValue() S3D_Vertex WinEDA_VertexCtrl::GetValue()
/*******************************************/ /*******************************************/
/* Retourne (en unites internes) les coordonnes entrees (en unites utilisateur) /* Retourne (en unites internes) les coordonnes entrees (en unites utilisateur)
*/ */
{ {
S3D_Vertex value; S3D_Vertex value;
double dtmp; double dtmp;
m_XValueCtrl->GetValue().ToDouble(&dtmp); m_XValueCtrl->GetValue().ToDouble( &dtmp );
value.x = dtmp; value.x = dtmp;
m_YValueCtrl->GetValue().ToDouble(&dtmp); m_YValueCtrl->GetValue().ToDouble( &dtmp );
value.y = dtmp; value.y = dtmp;
m_ZValueCtrl->GetValue().ToDouble(&dtmp); m_ZValueCtrl->GetValue().ToDouble( &dtmp );
value.z = dtmp; value.z = dtmp;
return value; return value;
} }
/**************************************************/ /**************************************************/
void WinEDA_VertexCtrl::SetValue(S3D_Vertex vertex) void WinEDA_VertexCtrl::SetValue( S3D_Vertex vertex )
/**************************************************/ /**************************************************/
{ {
wxString text; wxString text;
text.Printf( wxT("%f"), vertex.x); text.Printf( wxT( "%f" ), vertex.x );
m_XValueCtrl->Clear(); m_XValueCtrl->Clear();
m_XValueCtrl->AppendText(text); m_XValueCtrl->AppendText( text );
text.Printf(wxT("%f"), vertex.y); text.Printf( wxT( "%f" ), vertex.y );
m_YValueCtrl->Clear(); m_YValueCtrl->Clear();
m_YValueCtrl->AppendText(text); m_YValueCtrl->AppendText( text );
text.Printf(wxT("%f"), vertex.z); text.Printf( wxT( "%f" ), vertex.z );
m_ZValueCtrl->Clear(); m_ZValueCtrl->Clear();
m_ZValueCtrl->AppendText(text); m_ZValueCtrl->AppendText( text );
} }
/*****************************************/ /*****************************************/
void WinEDA_VertexCtrl::Enable(bool onoff) void WinEDA_VertexCtrl::Enable( bool onoff )
/*****************************************/ /*****************************************/
{ {
m_XValueCtrl->Enable(onoff); m_XValueCtrl->Enable( onoff );
m_YValueCtrl->Enable(onoff); m_YValueCtrl->Enable( onoff );
m_ZValueCtrl->Enable(onoff); m_ZValueCtrl->Enable( onoff );
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment