Beispiel #1
0
GLuint Pcb3D_GLCanvas::CreateDrawGL_List(void)
/**********************************************/
/* Creation de la liste des elements a afficher
*/
{
GLuint gllist = glGenLists( 1 );
WinEDA_BasePcbFrame * pcbframe = m_Parent->m_Parent;
BOARD * pcb = pcbframe->m_Pcb;
TRACK * pt_piste;
int ii;

	wxBusyCursor dummy;

	pcb->ComputeBoundaryBox();
	g_Parm_3D_Visu.m_BoardSettings = pcb->m_BoardSettings;
	g_Parm_3D_Visu.m_BoardSize = pcb->m_BoundaryBox.GetSize();
	g_Parm_3D_Visu.m_BoardPos = pcb->m_BoundaryBox.Centre();
	g_Parm_3D_Visu.m_BoardPos.y = - g_Parm_3D_Visu.m_BoardPos.y;
	g_Parm_3D_Visu.m_Layers = pcb->m_BoardSettings->m_CopperLayerCount;
	g_Parm_3D_Visu.m_BoardScale = 2.0 / MAX(g_Parm_3D_Visu.m_BoardSize.x, g_Parm_3D_Visu.m_BoardSize.y);
	float epoxy_width = 1.6;	// epoxy width in mm
	g_Parm_3D_Visu.m_Epoxy_Width = epoxy_width/2.54 * 1000
				* g_Parm_3D_Visu.m_BoardScale;

	/* calcul de l'altitude de chaque couche */
	for ( ii = 0; ii < 32; ii++ )
	{
		if ( ii < g_Parm_3D_Visu.m_Layers )
			g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width * ii
				/ (g_Parm_3D_Visu.m_Layers-1);
		else g_Parm_3D_Visu.m_LayerZcoord[ii] = g_Parm_3D_Visu.m_Epoxy_Width;
	}
	GLfloat zpos_cu =  500 * g_Parm_3D_Visu.m_BoardScale;
	GLfloat zpos_cmp = g_Parm_3D_Visu.m_Epoxy_Width + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[ADHESIVE_N_CU] = -zpos_cu*2;
	g_Parm_3D_Visu.m_LayerZcoord[ADHESIVE_N_CMP] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[SILKSCREEN_N_CU] = -zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[SILKSCREEN_N_CMP] = zpos_cmp;
	g_Parm_3D_Visu.m_LayerZcoord[DRAW_N] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[COMMENT_N] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[ECO1_N] = zpos_cmp + zpos_cu;
	g_Parm_3D_Visu.m_LayerZcoord[ECO2_N] = zpos_cmp + zpos_cu;

	glNewList( gllist, GL_COMPILE_AND_EXECUTE );

    glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);

	/* draw axes*/
	glEnable(GL_COLOR_MATERIAL);
	SetGLColor(WHITE);
    glBegin(GL_LINES);
 	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	glVertex3f( 0.0 , 0.0, 0.0); glVertex3f(1.0, 0.0, 0.0);	// X axis
	glVertex3f( 0.0 , 0.0, 0.0); glVertex3f(0.0, -1.0, 0.0);	// y axis
 	glNormal3f( 1.0, 0.0, 0.0);	// Normal is Y axis
	glVertex3f( 0.0 , 0.0, 0.0); glVertex3f(0.0, 0.0, 0.3);	// z axis
    glEnd();

	/* Draw epoxy limits (do not use, works and test in progress)*/
#if 0
glEnable(GL_FOG);
	GLfloat param;
//	param = GL_LINEAR; glFogfv(GL_FOG_MODE,& param);
	param = 0.2; glFogfv(GL_FOG_DENSITY,& param);
	param = g_Parm_3D_Visu.m_LayerZcoord[15]; glFogfv(GL_FOG_END,& param);
	glBegin(GL_QUADS);
	SetGLColor(g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[CMP_N]);
	double sx = DataScale3D * g_Parm_3D_Visu.m_BoardSize.x / 2;
	double sy = DataScale3D * g_Parm_3D_Visu.m_BoardSize.y / 2;
	double zpos = g_Parm_3D_Visu.m_LayerZcoord[15];
	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	sx = sy = 0.5;
	glVertex3f( -sx, -sy , zpos);
	glVertex3f( -sx, sy , zpos);
	glVertex3f( sx, sy , zpos);
	glVertex3f( sx, -sy , zpos);
	glEnd();
	glBegin(GL_QUADS);
	SetGLColor(g_Parm_3D_Visu.m_BoardSettings->m_LayerColor[CUIVRE_N]);
	glNormal3f( 0.0, 0.0, -1.0);	// Normal is -Z axis
	glVertex3f( -sx, -sy , 0);
	glVertex3f( -sx, sy , 0);
	glVertex3f( sx, sy , 0);
	glVertex3f( sx, -sy , 0);
	glEnd();
#endif

	/* Translation du tracé du BOARD pour placer son centre en 0, 0 */
    glTranslatef(-g_Parm_3D_Visu.m_BoardPos.x * g_Parm_3D_Visu.m_BoardScale,
			-g_Parm_3D_Visu.m_BoardPos.y * g_Parm_3D_Visu.m_BoardScale,
			0.0F);

 	glNormal3f( 0.0, 0.0, 1.0);	// Normal is Z axis
	/* Tracé des pistes : */
	for (pt_piste = pcb->m_Track ; pt_piste != NULL ; pt_piste = (TRACK*) pt_piste->Pnext )
		{
		if ( pt_piste->m_StructType == TYPEVIA )
			Draw3D_Via((SEGVIA*)pt_piste);
		else Draw3D_Track( pt_piste);
		}

	/* Tracé des edges */
EDA_BaseStruct * PtStruct;
	for ( PtStruct = pcb->m_Drawings; PtStruct != NULL; PtStruct = PtStruct->Pnext)
	{
		#define STRUCT ((DRAWSEGMENT *) PtStruct)
		if( PtStruct->m_StructType != TYPEDRAWSEGMENT ) continue;
		Draw3D_DrawSegment(STRUCT);
	}

	/* tracé des modules */
MODULE * Module = (MODULE*) pcb->m_Modules;
	for ( ; Module != NULL; Module = (MODULE *) Module->Pnext )
	{
		Module->Draw3D(this);
	}
    glEndList();

	/* Test for errors */
	GLenum err = glGetError();
	if ( err != GL_NO_ERROR )
		DisplayError(this, wxT("Error in GL commands") );
	return gllist;
}