2011-11-10 15:55:05 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2012-12-15 08:52:02 +00:00
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2012 Wayne Stambaugh <stambaughw@verizon.net>
|
|
|
|
* Copyright (C) 1992-2012 KiCad Developers, see AUTHORS.txt for contributors.
|
2011-11-10 15:55:05 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file 3d_aux.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <wxBasePcbFrame.h>
|
2011-09-23 13:57:12 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <class_board_design_settings.h>
|
|
|
|
#include <class_zone.h>
|
|
|
|
#include <class_text_mod.h>
|
|
|
|
#include <class_module.h>
|
|
|
|
#include <class_drawsegment.h>
|
|
|
|
#include <class_pcb_text.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <3d_viewer.h>
|
2012-12-15 08:52:02 +00:00
|
|
|
#include <3d_canvas.h>
|
2012-08-11 12:52:13 +00:00
|
|
|
#include <info3d_visu.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <trackball.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
// Exported function:
|
|
|
|
void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits );
|
|
|
|
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
void S3D_MASTER::Set_Object_Coords( std::vector< S3D_VERTEX >& aVertices )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
unsigned ii;
|
2008-03-11 05:41:06 +00:00
|
|
|
|
|
|
|
/* adjust object scale, rotation and offset position */
|
2011-11-10 15:55:05 +00:00
|
|
|
for( ii = 0; ii < aVertices.size(); ii++ )
|
2008-03-11 05:41:06 +00:00
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
aVertices[ii].x *= m_MatScale.x;
|
|
|
|
aVertices[ii].y *= m_MatScale.y;
|
|
|
|
aVertices[ii].z *= m_MatScale.z;
|
2011-09-17 15:31:21 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
// adjust rotation
|
2008-03-11 05:41:06 +00:00
|
|
|
if( m_MatRotation.x )
|
2013-05-01 17:32:36 +00:00
|
|
|
RotatePoint( &aVertices[ii].y, &aVertices[ii].z, m_MatRotation.x * 10 );
|
2011-09-17 15:31:21 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
if( m_MatRotation.y )
|
2013-05-01 17:32:36 +00:00
|
|
|
RotatePoint( &aVertices[ii].z, &aVertices[ii].x, m_MatRotation.y * 10 );
|
2011-09-17 15:31:21 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
if( m_MatRotation.z )
|
2013-05-01 17:32:36 +00:00
|
|
|
RotatePoint( &aVertices[ii].x, &aVertices[ii].y, m_MatRotation.z * 10 );
|
2011-09-17 15:31:21 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
/* adjust offset position (offset is given in UNIT 3D (0.1 inch) */
|
2012-04-27 14:15:11 +00:00
|
|
|
#define SCALE_3D_CONV ((IU_PER_MILS * 1000) / UNITS3D_TO_UNITSPCB)
|
2011-11-10 15:55:05 +00:00
|
|
|
aVertices[ii].x += m_MatPosition.x * SCALE_3D_CONV;
|
|
|
|
aVertices[ii].y += m_MatPosition.y * SCALE_3D_CONV;
|
|
|
|
aVertices[ii].z += m_MatPosition.z * SCALE_3D_CONV;
|
2008-03-11 05:41:06 +00:00
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2012-08-26 13:59:55 +00:00
|
|
|
void Set_Object_Data( std::vector< S3D_VERTEX >& aVertices, double aBiuTo3DUnits )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
unsigned ii;
|
2008-03-11 05:41:06 +00:00
|
|
|
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 */
|
2011-11-10 15:55:05 +00:00
|
|
|
if( aVertices.size() < 3 )
|
2008-03-11 05:41:06 +00:00
|
|
|
return;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* calculate normal direction */
|
2011-11-10 15:55:05 +00:00
|
|
|
ax = aVertices[1].x - aVertices[0].x;
|
|
|
|
ay = aVertices[1].y - aVertices[0].y;
|
|
|
|
az = aVertices[1].z - aVertices[0].z;
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2011-11-10 15:55:05 +00:00
|
|
|
bx = aVertices[aVertices.size() - 1].x - aVertices[0].x;
|
|
|
|
by = aVertices[aVertices.size() - 1].y - aVertices[0].y;
|
|
|
|
bz = aVertices[aVertices.size() - 1].z - aVertices[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 );
|
2011-09-17 15:31:21 +00:00
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
if( r >= 0.000001 ) /* avoid division by zero */
|
|
|
|
{
|
2011-11-10 15:55:05 +00:00
|
|
|
nx /= r;
|
|
|
|
ny /= r;
|
|
|
|
nz /= r;
|
2008-03-11 05:41:06 +00:00
|
|
|
glNormal3f( nx, ny, nz );
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
/* glBegin/glEnd */
|
2011-11-10 15:55:05 +00:00
|
|
|
switch( aVertices.size() )
|
2008-03-11 05:41:06 +00:00
|
|
|
{
|
|
|
|
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 */
|
2011-11-10 15:55:05 +00:00
|
|
|
for( ii = 0; ii < aVertices.size(); ii++ )
|
2008-03-11 05:41:06 +00:00
|
|
|
{
|
2012-08-28 06:51:18 +00:00
|
|
|
glVertex3d( aVertices[ii].x * aBiuTo3DUnits,
|
2012-08-26 13:59:55 +00:00
|
|
|
aVertices[ii].y * aBiuTo3DUnits,
|
|
|
|
aVertices[ii].z * aBiuTo3DUnits );
|
2008-03-11 05:41:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
glEnd();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-17 15:31:21 +00:00
|
|
|
GLuint EDA_3D_CANVAS::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
|
|
|
}
|
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
VERTEX_VALUE_CTRL::VERTEX_VALUE_CTRL( wxWindow* aParent, wxBoxSizer* aBoxSizer )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2013-08-28 07:23:14 +00:00
|
|
|
wxString text;
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
wxFlexGridSizer* gridSizer = new wxFlexGridSizer( 0, 2, 0, 0 );
|
|
|
|
gridSizer->AddGrowableCol( 1 );
|
|
|
|
gridSizer->SetFlexibleDirection( wxHORIZONTAL );
|
|
|
|
gridSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
aBoxSizer->Add( gridSizer, 0, wxEXPAND, 5 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
wxStaticText* msgtitle = new wxStaticText( aParent, wxID_ANY, wxT( "X:" ) );
|
|
|
|
gridSizer->Add( msgtitle, 0, wxALL , 5 );
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
m_XValueCtrl = new wxTextCtrl( aParent, wxID_ANY, wxEmptyString,
|
|
|
|
wxDefaultPosition,wxDefaultSize, 0 );
|
|
|
|
gridSizer->Add( m_XValueCtrl, 0, wxALL|wxEXPAND, 5 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
msgtitle = new wxStaticText( aParent, wxID_ANY, wxT( "Y:" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, 0 );
|
|
|
|
gridSizer->Add( msgtitle, 0, wxALL, 5 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
m_YValueCtrl = new wxTextCtrl( aParent, wxID_ANY, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
gridSizer->Add( m_YValueCtrl, 0, wxALL|wxEXPAND, 5 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
msgtitle = new wxStaticText( aParent, wxID_ANY, wxT( "Z:" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, 0 );
|
|
|
|
gridSizer->Add( msgtitle, 0, wxALL, 5 );
|
2009-11-04 20:46:53 +00:00
|
|
|
|
2013-08-28 07:23:14 +00:00
|
|
|
m_ZValueCtrl = new wxTextCtrl( aParent, wxID_ANY, wxEmptyString,
|
|
|
|
wxDefaultPosition, wxDefaultSize, 0 );
|
|
|
|
gridSizer->Add( m_ZValueCtrl, 0, wxALL|wxEXPAND, 5 );
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2008-03-11 05:41:06 +00:00
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
VERTEX_VALUE_CTRL::~VERTEX_VALUE_CTRL()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
S3D_VERTEX VERTEX_VALUE_CTRL::GetValue()
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2012-08-21 10:45:54 +00:00
|
|
|
S3D_VERTEX value;
|
2008-03-11 05:41:06 +00:00
|
|
|
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
|
|
|
|
2012-08-21 10:45:54 +00:00
|
|
|
void VERTEX_VALUE_CTRL::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
|
|
|
|
2012-08-11 12:52:13 +00:00
|
|
|
void VERTEX_VALUE_CTRL::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
|
|
|
}
|