3D view: now displays polygons used in footprint shapes, like logos.

Removed useless messages in debug mode.
Fixed very minor issues (minor warnings in debug mode)
3D export: Added patch from Lorenzo Marcantonio.
Fixed issue in VRML export dialog.
This commit is contained in:
jean-pierre charras 2010-08-19 16:24:58 +02:00
commit d979a35d93
9 changed files with 3180 additions and 3126 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,14 +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;
D( printf( "Tess gluTessVertex(%f,%f,%f)\n", v_data[0], v_data[1], v_data[2] ); )
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 )
@ -643,19 +644,6 @@ void MODULE::Draw3D( Pcb3D_GLCanvas* glcanvas )
{ {
D_PAD* pad = m_Pads; D_PAD* pad = m_Pads;
#if 0
if( !DisplayOpt.Show_Modules_Cmp )
{
if( m_Layer == LAYER_N_FRONT )
return;
}
if( !DisplayOpt.Show_Modules_Cu )
{
if( m_Layer == LAYER_N_BACK )
return;
}
#endif
/* Draw pads */ /* Draw pads */
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE ); glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );
glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis glNormal3f( 0.0, 0.0, 1.0 ); // Normal is Z axis
@ -726,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;
@ -736,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;
@ -762,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 ) ); )
@ -1262,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;
@ -1302,32 +1349,32 @@ static GLfloat Get3DLayerSide( int act_layer )
void CALLBACK tessBeginCB( GLenum which ) void CALLBACK tessBeginCB( GLenum which )
{ {
glBegin( which ); glBegin( which );
// DEBUG //
D( printf( "Tess glBegin()\n" ); )
} }
void CALLBACK tessEndCB() void CALLBACK tessEndCB()
{ {
glEnd(); glEnd();
// DEBUG //
D( printf( "Tess glEnd()\n" ); )
} }
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 ); g_Parm_3D_Visu.m_ActZpos );
}
// DEBUG // void CALLBACK tesswxPoint2Vertex( const GLvoid* data )
D( printf( "TessVertex glVertex3d(%d,%d,%f)\n", (*ptr).x, (*ptr).y, g_Parm_3D_Visu.m_ActZpos ); ) {
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 );
} }

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>

View File

@ -24,7 +24,7 @@ DIALOG_EXPORT_3DFILE_BASE::DIALOG_EXPORT_3DFILE_BASE( wxWindow* parent, wxWindow
m_staticText1->Wrap( -1 ); m_staticText1->Wrap( -1 );
bUpperSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 ); bUpperSizer->Add( m_staticText1, 0, wxTOP|wxRIGHT|wxLEFT, 5 );
m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Save VRML Board File"), wxT("*.wrl"), wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE|wxFLP_SAVE ); m_filePicker = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, _("Save VRML Board File"), wxT("*.wrl"), wxDefaultPosition, wxDefaultSize, wxFLP_SAVE|wxFLP_USE_TEXTCTRL );
bUpperSizer->Add( m_filePicker, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 ); bUpperSizer->Add( m_filePicker, 0, wxBOTTOM|wxRIGHT|wxLEFT|wxEXPAND, 5 );
m_staticText3 = new wxStaticText( this, wxID_ANY, _("Vrml 3D footprints shapes subdir:"), wxDefaultPosition, wxDefaultSize, 0 ); m_staticText3 = new wxStaticText( this, wxID_ANY, _("Vrml 3D footprints shapes subdir:"), wxDefaultPosition, wxDefaultSize, 0 );

View File

@ -154,7 +154,7 @@
<property name="permission">protected</property> <property name="permission">protected</property>
<property name="pos"></property> <property name="pos"></property>
<property name="size"></property> <property name="size"></property>
<property name="style">wxFLP_DEFAULT_STYLE|wxFLP_SAVE</property> <property name="style">wxFLP_SAVE|wxFLP_USE_TEXTCTRL</property>
<property name="subclass"></property> <property name="subclass"></property>
<property name="tooltip"></property> <property name="tooltip"></property>
<property name="value"></property> <property name="value"></property>

View File

@ -1085,7 +1085,7 @@ static void export_vrml_module( BOARD* aPcb, MODULE* aModule,
-vrmlm->m_MatPosition.y - aModule->m_Pos.y, -vrmlm->m_MatPosition.y - aModule->m_Pos.y,
vrmlm->m_MatPosition.z + layer_z[aModule->GetLayer()] ); vrmlm->m_MatPosition.z + layer_z[aModule->GetLayer()] );
fprintf( aOutputFile, fprintf( aOutputFile,
" children [\n Inline {\n url [ \"%s\" ]\n } ]\n", " children [\n Inline {\n url \"%s\"\n } ]\n",
CONV_TO_UTF8( fname ) ); CONV_TO_UTF8( fname ) );
fprintf( aOutputFile, " }\n" ); fprintf( aOutputFile, " }\n" );