3D view: now displays polygons used in footprint shapes, like logos. Fixed very minor issues (minor warnings in debug mode)

This commit is contained in:
jean-pierre charras 2010-08-19 16:21:05 +02:00
parent ba3e69dd72
commit 3820154aed
6 changed files with 3178 additions and 3101 deletions

View File

@ -45,10 +45,11 @@ static GLfloat Get3DLayerSide( int act_layer );
#endif #endif
// CALLBACK functions for GLU_TESS // CALLBACK functions for GLU_TESS
void CALLBACK tessBeginCB( GLenum which ); static void CALLBACK tessBeginCB( GLenum which );
void CALLBACK tessEndCB(); static void CALLBACK tessEndCB();
void CALLBACK tessErrorCB( GLenum errorCode ); static void CALLBACK tessErrorCB( GLenum errorCode );
void CALLBACK tessVertexCB( const GLvoid* data ); static void CALLBACK tessCPolyPt2Vertex( const GLvoid* data );
static void CALLBACK tesswxPoint2Vertex( const GLvoid* data );
void Pcb3D_GLCanvas::Redraw( bool finish ) void Pcb3D_GLCanvas::Redraw( bool finish )
{ {
@ -241,7 +242,8 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List()
{ {
ZONE_CONTAINER* curr_zone = pcb->GetArea( ii ); ZONE_CONTAINER* curr_zone = pcb->GetArea( ii );
if( curr_zone->m_FillMode == 0 ) if( curr_zone->m_FillMode == 0 )
{ // solid polygons only are used to fill areas {
// solid polygons only are used to fill areas
if( curr_zone->m_FilledPolysList.size() > 3 ) if( curr_zone->m_FilledPolysList.size() > 3 )
{ {
Draw3D_SolidPolygonsInZones( curr_zone ); Draw3D_SolidPolygonsInZones( curr_zone );
@ -249,7 +251,7 @@ GLuint Pcb3D_GLCanvas::CreateDrawGL_List()
} }
else else
{ {
// segments are used to fill ares // segments are used to fill areas
for( unsigned iseg = 0; iseg < curr_zone->m_FillSegmList.size(); iseg++ ) for( unsigned iseg = 0; iseg < curr_zone->m_FillSegmList.size(); iseg++ )
{ {
SEGZONE dummysegment( pcb ); SEGZONE dummysegment( pcb );
@ -408,9 +410,10 @@ void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* zone_c )
gluTessCallback( tess, GLU_TESS_BEGIN, ( void (CALLBACK*)() )tessBeginCB ); gluTessCallback( tess, GLU_TESS_BEGIN, ( void (CALLBACK*)() )tessBeginCB );
gluTessCallback( tess, GLU_TESS_END, ( void (CALLBACK*)() )tessEndCB ); gluTessCallback( tess, GLU_TESS_END, ( void (CALLBACK*)() )tessEndCB );
gluTessCallback( tess, GLU_TESS_ERROR, ( void (CALLBACK*)() )tessErrorCB ); gluTessCallback( tess, GLU_TESS_ERROR, ( void (CALLBACK*)() )tessErrorCB );
gluTessCallback( tess, GLU_TESS_VERTEX, ( void (CALLBACK*)() )tessVertexCB ); gluTessCallback( tess, GLU_TESS_VERTEX, ( void (CALLBACK*)() )tessCPolyPt2Vertex );
GLdouble v_data[3]; GLdouble v_data[3];
v_data[2] = zpos;
//gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); //gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
@ -420,13 +423,12 @@ void Pcb3D_GLCanvas::Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* zone_c )
{ {
if( StartContour == 1 ) if( StartContour == 1 )
{ {
gluTessBeginPolygon( tess, 0 ); gluTessBeginPolygon( tess, NULL );
gluTessBeginContour( tess ); gluTessBeginContour( tess );
StartContour = 0; StartContour = 0;
} }
v_data[0] = zone_c->m_FilledPolysList[ii].x * g_Parm_3D_Visu.m_BoardScale; v_data[0] = zone_c->m_FilledPolysList[ii].x * g_Parm_3D_Visu.m_BoardScale;
v_data[1] = zone_c->m_FilledPolysList[ii].y * g_Parm_3D_Visu.m_BoardScale * -1; v_data[1] = -zone_c->m_FilledPolysList[ii].y * g_Parm_3D_Visu.m_BoardScale;
v_data[2] = zpos;
gluTessVertex( tess, v_data, &zone_c->m_FilledPolysList[ii] ); gluTessVertex( tess, v_data, &zone_c->m_FilledPolysList[ii] );
if( zone_c->m_FilledPolysList[ii].end_contour == 1 ) if( zone_c->m_FilledPolysList[ii].end_contour == 1 )
@ -712,7 +714,7 @@ void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas )
{ {
wxString s; wxString s;
int dx, dy; int dx, dy;
double scale, x, y, fx, fy, w, zpos; double x, y, fx, fy, w, zpos;
if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( m_Layer ) == false ) if( g_Parm_3D_Visu.m_BoardSettings->IsLayerVisible( m_Layer ) == false )
return; return;
@ -722,7 +724,6 @@ void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas )
SetGLColor( color ); SetGLColor( color );
glNormal3f( 0.0, 0.0, (m_Layer == LAYER_N_BACK) ? -1.0 : 1.0 ); glNormal3f( 0.0, 0.0, (m_Layer == LAYER_N_BACK) ? -1.0 : 1.0 );
scale = g_Parm_3D_Visu.m_BoardScale;
dx = m_End.x; dx = m_End.x;
dy = m_End.y; dy = m_End.y;
@ -748,6 +749,26 @@ void EDGE_MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas )
Draw3D_ArcSegment( x, -y, fx, -fy, (double) m_Angle, w, zpos ); Draw3D_ArcSegment( x, -y, fx, -fy, (double) m_Angle, w, zpos );
break; break;
case S_POLYGON:
{
// We must compute true coordinates from m_PolyPoints
// which are relative to module position and module orientation = 0
std::vector<wxPoint> points = m_PolyPoints;
MODULE* module = (MODULE*) m_Parent;
if( module == NULL )
break;
for( unsigned ii = 0; ii < points.size(); ii++ )
{
wxPoint& pt = points[ii];
RotatePoint( &pt.x, &pt.y, module->m_Orient );
pt += module->m_Pos;
}
glcanvas->Draw3D_Polygon( points, zpos );
}
break;
default: default:
s.Printf( wxT( "Error: Shape nr %d not implemented!\n" ), m_Shape ); s.Printf( wxT( "Error: Shape nr %d not implemented!\n" ), m_Shape );
D( printf( "%s", CONV_TO_UTF8( s ) ); ) D( printf( "%s", CONV_TO_UTF8( s ) ); )
@ -1248,6 +1269,46 @@ static void Draw3D_CircleSegment( double startx, double starty, double endx,
} }
/** Function Pcb3D_GLCanvas::Draw3D_Polygon
* draw one solid polygon
* @param aCornersList = a std::vector<wxPoint> liste of corners, in physical coordinates
* @param aZpos = the z position in 3D units
*/
void Pcb3D_GLCanvas::Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos )
{
g_Parm_3D_Visu.m_ActZpos = aZpos;
GLUtesselator* tess = gluNewTess();
gluTessCallback( tess, GLU_TESS_BEGIN, ( void (CALLBACK*)() )tessBeginCB );
gluTessCallback( tess, GLU_TESS_END, ( void (CALLBACK*)() )tessEndCB );
gluTessCallback( tess, GLU_TESS_ERROR, ( void (CALLBACK*)() )tessErrorCB );
gluTessCallback( tess, GLU_TESS_VERTEX, ( void (CALLBACK*)() )tesswxPoint2Vertex );
GLdouble v_data[3];
v_data[2] = aZpos;
//gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
// Draw solid polygon
gluTessBeginPolygon( tess, NULL );
gluTessBeginContour( tess );
for( unsigned ii = 0; ii < aCornersList.size(); ii++ )
{
v_data[0] = aCornersList[ii].x * g_Parm_3D_Visu.m_BoardScale;
v_data[1] = -aCornersList[ii].y * g_Parm_3D_Visu.m_BoardScale;
// gluTessVertex store pointers on data, not data, so do not store
// different corners values in a temporary variable
// but send pointer on each corner value in aCornersList
gluTessVertex( tess, v_data, &aCornersList[ii] );
}
gluTessEndContour( tess );
gluTessEndPolygon( tess );
gluDeleteTess( tess );
}
static int Get3DLayerEnable( int act_layer ) static int Get3DLayerEnable( int act_layer )
{ {
bool enablelayer; bool enablelayer;
@ -1297,13 +1358,22 @@ void CALLBACK tessEndCB()
} }
void CALLBACK tessVertexCB( const GLvoid* data ) void CALLBACK tessCPolyPt2Vertex( const GLvoid* data )
{ {
// cast back to double type // cast back to double type
const CPolyPt* ptr = (const CPolyPt*) data; const CPolyPt* ptr = (const CPolyPt*) data;
glVertex3f( (*ptr).x * g_Parm_3D_Visu.m_BoardScale, glVertex3f( ptr->x * g_Parm_3D_Visu.m_BoardScale,
(*ptr).y * g_Parm_3D_Visu.m_BoardScale * -1, -ptr->y * g_Parm_3D_Visu.m_BoardScale,
g_Parm_3D_Visu.m_ActZpos );
}
void CALLBACK tesswxPoint2Vertex( const GLvoid* data )
{
const wxPoint* ptr = (const wxPoint*) data;
glVertex3f( ptr->x * g_Parm_3D_Visu.m_BoardScale,
-ptr->y * g_Parm_3D_Visu.m_BoardScale,
g_Parm_3D_Visu.m_ActZpos ); g_Parm_3D_Visu.m_ActZpos );
} }

View File

@ -171,6 +171,13 @@ public:
* @param aZone_c = the zone to draw * @param aZone_c = the zone to draw
*/ */
void Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone_c ); void Draw3D_SolidPolygonsInZones( ZONE_CONTAINER* aZone_c );
/** Function Draw3D_Polygon
* draw one solid polygon
* @param aCornersList = a std::vector<wxPoint> liste of corners, in physical coordinates
* @param aZpos = the z position in 3D units
*/
void Draw3D_Polygon( std::vector<wxPoint>& aCornersList, double aZpos );
void Draw3D_Via( SEGVIA* via ); void Draw3D_Via( SEGVIA* via );
void Draw3D_DrawSegment( DRAWSEGMENT* segment ); void Draw3D_DrawSegment( DRAWSEGMENT* segment );
void Draw3D_DrawText( TEXTE_PCB* text ); void Draw3D_DrawText( TEXTE_PCB* text );

View File

@ -115,7 +115,7 @@ WinEDA_ExecBlockCmdFrame::WinEDA_ExecBlockCmdFrame( WinEDA_BasePcbFrame* parent,
/* Sizer 1 creation */ /* Sizer 1 creation */
wxFlexGridSizer* fgSizer1; wxFlexGridSizer* fgSizer1;
fgSizer1 = new wxFlexGridSizer( 1, 1, 0, 0 ); fgSizer1 = new wxFlexGridSizer( 7, 1, 0, 0 );
fgSizer1->SetFlexibleDirection( wxBOTH ); fgSizer1->SetFlexibleDirection( wxBOTH );
fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); fgSizer1->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );

View File

@ -149,7 +149,7 @@ DIALOG_MODULE_BOARD_EDITOR_BASE::DIALOG_MODULE_BOARD_EDITOR_BASE( wxWindow* pare
sbSizerLocalProperties->Add( m_staticTextInfo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 ); sbSizerLocalProperties->Add( m_staticTextInfo, 0, wxALL|wxALIGN_CENTER_HORIZONTAL, 5 );
wxFlexGridSizer* fgSizerClearances; wxFlexGridSizer* fgSizerClearances;
fgSizerClearances = new wxFlexGridSizer( 3, 3, 0, 0 ); fgSizerClearances = new wxFlexGridSizer( 5, 3, 0, 0 );
fgSizerClearances->SetFlexibleDirection( wxBOTH ); fgSizerClearances->SetFlexibleDirection( wxBOTH );
fgSizerClearances->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); fgSizerClearances->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );

View File

@ -1466,7 +1466,7 @@
<property name="name">fgSizerClearances</property> <property name="name">fgSizerClearances</property>
<property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property> <property name="non_flexible_grow_mode">wxFLEX_GROWMODE_SPECIFIED</property>
<property name="permission">none</property> <property name="permission">none</property>
<property name="rows">3</property> <property name="rows">5</property>
<property name="vgap">0</property> <property name="vgap">0</property>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
<property name="border">5</property> <property name="border">5</property>