dodge seg fault, caused by a bad layer number

This commit is contained in:
dickelbeck 2007-12-11 20:28:13 +00:00
parent af80a3cb7e
commit 86885a7aef
1 changed files with 652 additions and 572 deletions

View File

@ -23,7 +23,6 @@ static void Plot_Edges_Modules(BOARD * pcb, int format_plot, int masque_layer);
static void PlotTextModule( TEXTE_MODULE* pt_texte );
/**********************************************************/
void WinEDA_BasePcbFrame::Plot_Serigraphie( int format_plot,
FILE* File, int masque_layer )
@ -48,22 +47,26 @@ wxString msg;
{
case TYPEDRAWSEGMENT:
PlotDrawSegment( (DRAWSEGMENT*) PtStruct, format_plot, masque_layer );
// (Following line has been superceded by new commands elsewhere.)
// EDGE_LAYER | masque_layer );
break;
case TYPETEXTE:
PlotTextePcb( (TEXTE_PCB*) PtStruct, format_plot, masque_layer );
// EDGE_LAYER | masque_layer );
break;
case TYPECOTATION:
PlotCotation( (COTATION*) PtStruct, format_plot, masque_layer );
// EDGE_LAYER | masque_layer );
break;
case TYPEMIRE:
PlotMirePcb( (MIREPCB*) PtStruct, format_plot, masque_layer );
// EDGE_LAYER | masque_layer );
break;
@ -93,7 +96,8 @@ wxString msg;
/* Tst si layer OK */
if( (pt_pad->m_Masque_Layer & masque_layer) == 0 )
{
if( ! Plot_Pads_All_Layers ) continue;
if( !Plot_Pads_All_Layers )
continue;
}
shape_pos = pt_pad->ReturnShapePos();
pos = shape_pos; size = pt_pad->m_Size;
@ -101,6 +105,7 @@ wxString msg;
switch( pt_pad->m_PadShape & 0x7F )
{
case CIRCLE:
switch( format_plot )
{
case PLOT_FORMAT_GERBER:
@ -116,9 +121,11 @@ wxString msg;
trace_1_pastille_RONDE_POST( pos, size.x, FILAIRE );
break;
}
break;
case OVALE:
switch( format_plot )
{
case PLOT_FORMAT_GERBER:
@ -137,6 +144,7 @@ wxString msg;
pt_pad->m_Orient, FILAIRE );
break;
}
break;
case TRAPEZE:
@ -164,11 +172,13 @@ wxString msg;
FILAIRE );
break;
}
break;
}
case RECT:
default:
switch( format_plot )
{
case PLOT_FORMAT_GERBER:
@ -186,8 +196,10 @@ wxString msg;
(int) pt_pad->m_Orient, FILAIRE );
break;
}
break;
}
nb_items++; msg.Printf( wxT( "%d" ), nb_items );
Affiche_1_Parametre( this, 56, wxEmptyString, msg, GREEN );
}
@ -204,14 +216,26 @@ wxString msg;
trace_val = Sel_Texte_Valeur;
trace_ref = Sel_Texte_Reference; // les 2 autorisations de tracer sont donnees
if( (g_TabOneLayerMask[Module->m_Reference->GetLayer()] & masque_layer) == 0)
trace_ref = FALSE;
if(Module->m_Reference->m_NoShow && !Sel_Texte_Invisible)
TEXTE_MODULE* text = Module->m_Reference;
int textLayer = text->GetLayer();
wxASSERT( (unsigned) textLayer < 32 );
if( ( (1 << textLayer) & masque_layer ) == 0 )
trace_ref = FALSE;
if( (g_TabOneLayerMask[Module->m_Value->GetLayer()] & masque_layer) == 0)
if( text->m_NoShow && !Sel_Texte_Invisible )
trace_ref = FALSE;
text = Module->m_Value;
textLayer = text->GetLayer();
wxASSERT( (unsigned) textLayer < 32 );
if( ( (1 << textLayer) & masque_layer ) == 0 )
trace_val = FALSE;
if(Module->m_Value->m_NoShow && !Sel_Texte_Invisible)
if( text->m_NoShow && !Sel_Texte_Invisible )
trace_val = FALSE;
/* Trace effectif des textes */
@ -234,9 +258,11 @@ wxString msg;
pt_texte = (TEXTE_MODULE*) Module->m_Drawings;
for( ; pt_texte != NULL; pt_texte = (TEXTE_MODULE*) pt_texte->Pnext )
{
if(pt_texte->Type() != TYPETEXTEMODULE ) continue;
if( pt_texte->Type() != TYPETEXTEMODULE )
continue;
if( !Sel_Texte_Divers ) continue;
if( !Sel_Texte_Divers )
continue;
if( (pt_texte->m_NoShow) && !Sel_Texte_Invisible )
continue;
if( (g_TabOneLayerMask[pt_texte->GetLayer()] & masque_layer) == 0 )
@ -249,6 +275,7 @@ wxString msg;
}
}
/**************************************************/
static void PlotTextModule( TEXTE_MODULE* pt_texte )
/**************************************************/
@ -265,9 +292,11 @@ int orient, epaisseur, no_miroir;
no_miroir = pt_texte->m_Miroir & 1;
epaisseur = pt_texte->m_Width;
if ( Plot_Mode == FILAIRE ) epaisseur = g_PlotLine_Width;
if( Plot_Mode == FILAIRE )
epaisseur = g_PlotLine_Width;
if ( no_miroir == 0 ) size.y = -size.y; // Text is mirrored
if( no_miroir == 0 )
size.y = -size.y; // Text is mirrored
Plot_1_texte( format_plot, pt_texte->m_Text,
orient, epaisseur,
@ -275,14 +304,14 @@ int orient, epaisseur, no_miroir;
}
/*******************************************************************************/
void PlotCotation( COTATION* Cotation, int format_plot, int masque_layer )
/*******************************************************************************/
{
DRAWSEGMENT* DrawTmp;
if( (g_TabOneLayerMask[Cotation->GetLayer()] & masque_layer) == 0) return;
if( (g_TabOneLayerMask[Cotation->GetLayer()] & masque_layer) == 0 )
return;
DrawTmp = new DRAWSEGMENT( NULL );
@ -332,7 +361,8 @@ void PlotMirePcb( MIREPCB* Mire, int format_plot,int masque_layer)
DRAWSEGMENT* DrawTmp;
int dx1, dx2, dy1, dy2, rayon;
if( (g_TabOneLayerMask[Mire->GetLayer()] & masque_layer) == 0) return;
if( (g_TabOneLayerMask[Mire->GetLayer()] & masque_layer) == 0 )
return;
DrawTmp = new DRAWSEGMENT( NULL );
@ -386,16 +416,20 @@ wxString msg;
PtEdge = (EDGE_MODULE*) Module->m_Drawings;
for( ; PtEdge != NULL; PtEdge = (EDGE_MODULE*) PtEdge->Pnext )
{
if(PtEdge->Type() != TYPEEDGEMODULE) continue;
if( (g_TabOneLayerMask[PtEdge->GetLayer()] & masque_layer) == 0) continue;
if( PtEdge->Type() != TYPEEDGEMODULE )
continue;
if( (g_TabOneLayerMask[PtEdge->GetLayer()] & masque_layer) == 0 )
continue;
Plot_1_EdgeModule( format_plot, PtEdge );
}
/* Affichage du nombre de modules traites */
nb_items++;
msg.Printf( wxT( "%d" ), nb_items );
}
}
/**************************************************************/
void Plot_1_EdgeModule( int format_plot, EDGE_MODULE* PtEdge )
/**************************************************************/
@ -407,17 +441,21 @@ int rayon; /* rayon des cercles a tracer */
int StAngle, EndAngle;
wxPoint pos, end; /* Coord des segments a tracer */
if(PtEdge->Type() != TYPEEDGEMODULE) return;
if( PtEdge->Type() != TYPEEDGEMODULE )
return;
type_trace = PtEdge->m_Shape;
epaisseur = PtEdge->m_Width;
if ( Plot_Mode == FILAIRE ) epaisseur = g_PlotLine_Width;
if( Plot_Mode == FILAIRE )
epaisseur = g_PlotLine_Width;
pos = PtEdge->m_Start;
end = PtEdge->m_End;
switch( type_trace )
{
case S_SEGMENT: /* segment simple */
case S_SEGMENT:
/* segment simple */
switch( format_plot )
{
case PLOT_FORMAT_GERBER:
@ -432,6 +470,7 @@ wxPoint pos, end; /* Coord des segments a tracer */
PlotFilledSegmentPS( pos, end, epaisseur );
break;
}
break; /* Fin trace segment simple */
case S_CIRCLE:
@ -443,7 +482,8 @@ wxPoint pos, end; /* Coord des segments a tracer */
rayon = (int) hypot( (double) (end.x - pos.x), (double) (end.y - pos.y) );
StAngle = ArcTangente( end.y - pos.y, end.x - pos.x );
EndAngle = StAngle + PtEdge->m_Angle;
if ( StAngle > EndAngle) EXCHG (StAngle, EndAngle);
if( StAngle > EndAngle )
EXCHG( StAngle, EndAngle );
PlotArc( format_plot, pos, StAngle, EndAngle, rayon, epaisseur );
break;
@ -471,16 +511,15 @@ wxPoint pos, end; /* Coord des segments a tracer */
y += PtEdge->m_Start0.y;
*ptr = x; ptr++; *ptr = y; ptr++;
}
PlotPolygon( format_plot, TRUE, PtEdge->m_PolyCount, ptr_base );
free( ptr_base );
break;
}
}
}
/****************************************************************************/
void PlotTextePcb( TEXTE_PCB* pt_texte, int format_plot, int masque_layer )
/****************************************************************************/
@ -490,8 +529,10 @@ int no_miroir, orient, epaisseur;
wxPoint pos;
wxSize size;
if( pt_texte->m_Text.IsEmpty() ) return;
if( (g_TabOneLayerMask[pt_texte->GetLayer()] & masque_layer) == 0 ) return ;
if( pt_texte->m_Text.IsEmpty() )
return;
if( (g_TabOneLayerMask[pt_texte->GetLayer()] & masque_layer) == 0 )
return;
/* calcul des parametres du texte :*/
size = pt_texte->m_Size;
@ -500,23 +541,26 @@ wxSize size;
no_miroir = pt_texte->m_Miroir & 1;
epaisseur = pt_texte->m_Width;
if ( no_miroir == FALSE) size.x = - size.x;
if( no_miroir == FALSE )
size.x = -size.x;
Plot_1_texte( format_plot, pt_texte->m_Text, orient,
epaisseur, pos.x, pos.y, size.x, size.y );
}
/**********************************************************************/
void Plot_1_texte( int format_plot, const wxString& Text, int angle,
int epaisseur, int cX, int cY, int size_h, int size_v,
bool centreX, bool centreY )
/***********************************************************************/
/*
Trace de 1 texte:
ptr = pointeur sur le texte
angle = angle d'orientation, dependant aussi du mode de trace (miroir..)
cX, cY = position du centre du texte
size_h , size_v = dimensions ( algebriques );
* Trace de 1 texte:
* ptr = pointeur sur le texte
* angle = angle d'orientation, dependant aussi du mode de trace (miroir..)
* cX, cY = position du centre du texte
* size_h , size_v = dimensions ( algebriques );
*/
{
int kk = 0, k1, k2, end;
@ -530,17 +574,21 @@ int nbcodes = Text.Len();
espacement = ( (10 * size_h) / 9 ) + ( (size_h >= 0 ) ? epaisseur : -epaisseur );
/* calcul de la position du debut du texte */
if ( centreX ) sx = cX - ((espacement * nbcodes) / 2 ) + (espacement /9);
else sx = cX;
if ( centreY ) sy = cY + (size_v / 2);
else sy = cY;
if( centreX )
sx = cX - ( (espacement * nbcodes) / 2 ) + (espacement / 9);
else
sx = cX;
if( centreY )
sy = cY + (size_v / 2);
else
sy = cY;
/* trace du texte */
for( ; kk < nbcodes; kk++ )
{
int code = Text.GetChar( kk ) & 0xFF;
ptcar = graphic_fonte_shape[code]; /* ptcar pointe la description
du caractere a dessiner */
* du caractere a dessiner */
plume = 'U'; ox = sx; oy = sy;
RotatePoint( &ox, &oy, cX, cY, angle );
@ -548,14 +596,18 @@ int nbcodes = Text.Len();
for( end = 0; end == 0; ptcar++ )
{
f_cod = * ptcar; /* get code n de la forme selectionnee */
f_cod = *ptcar;
/* get code n de la forme selectionnee */
switch( f_cod )
{
case 'X' : end = 1;/* fin du caractere */
case 'X':
end = 1; /* fin du caractere */
break;
case 'U':
case 'D' : plume = f_cod ; break ;
case 'D':
plume = f_cod; break;
default:
k1 = f_cod; // Coord X
@ -583,24 +635,29 @@ int nbcodes = Text.Len();
case PLOT_FORMAT_POST:
PlotFilledSegmentPS( wxPoint( ox, oy ), wxPoint( fx, fy ), epaisseur );
break;
}
}
ox = fx; oy = fy;
} /* fin switch decodade matrice de forme */
}
} /* end boucle for = end trace de 1 caractere */
/* fin switch decodade matrice de forme */
}
/* end boucle for = end trace de 1 caractere */
sx += espacement;
} /* end trace du texte */
}
/* end trace du texte */
}
/***********************************/
void Affiche_erreur( int nb_err )
/***********************************/
/* Affiche le nombre d'erreurs commises ( segments traces avec plume trop grosse
ou autres */
* ou autres */
{
// sprintf(msg,"%d",nb_err) ;
// Affiche_1_Parametre(this, 30,"Err",msg,GREEN) ;
@ -610,18 +667,21 @@ void Affiche_erreur( int nb_err)
/******************************************************************************/
void PlotDrawSegment( DRAWSEGMENT* pt_segm, int Format, int masque_layer )
/******************************************************************************/
/* Trace un element du type DRAWSEGMENT draw appartenant
aux couches specifiees par masque_layer
* aux couches specifiees par masque_layer
*/
{
wxPoint start, end;
int epaisseur;
int rayon = 0, StAngle = 0, EndAngle = 0;
if( (g_TabOneLayerMask[pt_segm->GetLayer()] & masque_layer) == 0) return;
if( (g_TabOneLayerMask[pt_segm->GetLayer()] & masque_layer) == 0 )
return;
epaisseur = pt_segm->m_Width;
if ( Plot_Mode == FILAIRE) epaisseur = g_PlotLine_Width;
if( Plot_Mode == FILAIRE )
epaisseur = g_PlotLine_Width;
start = pt_segm->m_Start; end = pt_segm->m_End;
@ -635,7 +695,8 @@ int rayon = 0, StAngle = 0, EndAngle = 0;
rayon = (int) hypot( (double) (end.x - start.x), (double) (end.y - start.y) );
StAngle = ArcTangente( end.y - start.y, end.x - start.x );
EndAngle = StAngle + pt_segm->m_Angle;
if ( StAngle > EndAngle) EXCHG (StAngle, EndAngle);
if( StAngle > EndAngle )
EXCHG( StAngle, EndAngle );
}
switch( Format )
@ -646,7 +707,8 @@ int rayon = 0, StAngle = 0, EndAngle = 0;
else if( pt_segm->m_Shape == S_ARC )
PlotArc( PLOT_FORMAT_GERBER, start,
StAngle, EndAngle, rayon, epaisseur );
else PlotGERBERLine(start, end, epaisseur) ;
else
PlotGERBERLine( start, end, epaisseur );
break;
case PLOT_FORMAT_HPGL:
@ -654,7 +716,8 @@ int rayon = 0, StAngle = 0, EndAngle = 0;
PlotCircle( PLOT_FORMAT_HPGL, epaisseur, start, rayon );
else if( pt_segm->m_Shape == S_ARC )
PlotArc( PLOT_FORMAT_HPGL, start, StAngle, EndAngle, rayon, epaisseur );
else trace_1_segment_HPGL(start.x,start.y, end.x,end.y, epaisseur) ;
else
trace_1_segment_HPGL( start.x, start.y, end.x, end.y, epaisseur );
break;
case PLOT_FORMAT_POST:
@ -663,7 +726,8 @@ int rayon = 0, StAngle = 0, EndAngle = 0;
else if( pt_segm->m_Shape == S_ARC )
PlotArc( PLOT_FORMAT_POST, start,
StAngle, EndAngle, rayon, epaisseur );
else PlotFilledSegmentPS(start, end, epaisseur) ;
else
PlotFilledSegmentPS( start, end, epaisseur );
break;
}
}
@ -712,19 +776,22 @@ void PlotPolygon(int format_plot, bool Filled, int nbpoints, int * coord)
}
}
/************************************************************************/
void PlotArc( int format_plot, wxPoint centre, int start_angle, int end_angle,
int rayon, int epaisseur )
/************************************************************************/
/* Polt 1 arc
start, end = angles in 1/10 degree for start and stop point
* start, end = angles in 1/10 degree for start and stop point
*/
{
int ii;
int ox, oy, fx, fy;
int delta;/* increment (en 0.1 degres) angulaire pour trace de cercles */
if ( Plot_Mode == FILAIRE) epaisseur = g_PlotLine_Width;
if( Plot_Mode == FILAIRE )
epaisseur = g_PlotLine_Width;
if( format_plot == PLOT_FORMAT_POST )
{
@ -738,10 +805,13 @@ int delta; /* increment (en 0.1 degres) angulaire pour trace de cercles */
EXCHG( start_angle, end_angle );
/* Correction pour petits cercles par rapport a l'epaisseur du trait */
if( rayon < (epaisseur * 10) ) delta = 225; /* 16 segm pour 360 deg */
if( rayon < (epaisseur * 5) ) delta = 300; /* 12 segm pour 360 deg */
if( rayon < (epaisseur * 10) )
delta = 225; /* 16 segm pour 360 deg */
if( rayon < (epaisseur * 5) )
delta = 300; /* 12 segm pour 360 deg */
if ( start_angle > end_angle ) end_angle += 3600;
if( start_angle > end_angle )
end_angle += 3600;
ox = rayon; oy = 0;
RotatePoint( &ox, &oy, start_angle );
@ -750,6 +820,7 @@ int delta; /* increment (en 0.1 degres) angulaire pour trace de cercles */
{
fx = rayon; fy = 0;
RotatePoint( &fx, &fy, ii );
switch( format_plot )
{
case PLOT_FORMAT_GERBER:
@ -758,17 +829,23 @@ int delta; /* increment (en 0.1 degres) angulaire pour trace de cercles */
break;
case PLOT_FORMAT_HPGL:
trace_1_segment_HPGL(centre.x+ox,centre.y+oy,centre.x+fx,centre.y+fy, epaisseur) ;
trace_1_segment_HPGL( centre.x + ox,
centre.y + oy,
centre.x + fx,
centre.y + fy,
epaisseur );
break;
case PLOT_FORMAT_POST:
break;
}
ox = fx; oy = fy;
}
fx = rayon; fy = 0;
RotatePoint( &fx, &fy, end_angle );
switch( format_plot )
{
case PLOT_FORMAT_GERBER:
@ -777,11 +854,14 @@ int delta; /* increment (en 0.1 degres) angulaire pour trace de cercles */
break;
case PLOT_FORMAT_HPGL:
trace_1_segment_HPGL(centre.x+ox,centre.y+oy,centre.x+fx,centre.y+fy, epaisseur) ;
trace_1_segment_HPGL( centre.x + ox,
centre.y + oy,
centre.x + fx,
centre.y + fy,
epaisseur );
break;
case PLOT_FORMAT_POST:
break;
}
}