2008-03-22 05:55:06 +00:00
|
|
|
/******************************************/
|
|
|
|
/* Kicad: Common plot HPGL Routines */
|
|
|
|
/******************************************/
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "base_struct.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "plot_common.h"
|
|
|
|
#include "macros.h"
|
|
|
|
|
|
|
|
/* parametre HPGL pour trace de cercle: */
|
|
|
|
#define CHORD_ANGLE 10
|
|
|
|
|
|
|
|
|
|
|
|
//Variables locales
|
2008-03-22 05:55:06 +00:00
|
|
|
void Move_Plume_HPGL( wxPoint pos, int plume );
|
|
|
|
void Plume_HPGL( int plume );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************************/
|
2008-12-22 21:06:44 +00:00
|
|
|
void InitPlotParametresHPGL( wxPoint offset, double aXScale, double aYScale, int orient )
|
2007-05-28 18:09:49 +00:00
|
|
|
/***********************************************************************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* Set the plot offset for the current plotting
|
2008-12-22 21:06:44 +00:00
|
|
|
* g_Plot_XScale,g_Plot_YScale = coordinate scale (scale coefficient for coordinates)
|
|
|
|
* device_g_Plot_XScale,device_g_Plot_YScale = device coordinate scale (i.e scale used by plot device)
|
2008-03-22 05:55:06 +00:00
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-12-22 21:06:44 +00:00
|
|
|
g_Plot_PlotOffset = offset;
|
|
|
|
g_Plot_XScale = aXScale;
|
|
|
|
g_Plot_YScale = aYScale;
|
|
|
|
g_Plot_DefaultPenWidth = 6; /* epaisseur du trait standard en 1/1000 pouce */
|
|
|
|
g_Plot_PlotOrientOptions = orient;
|
|
|
|
g_Plot_CurrentPenWidth = -1;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
bool PrintHeaderHPGL( FILE* plot_file, int pen_speed, int pen_num )
|
2007-05-28 18:09:49 +00:00
|
|
|
/*****************************************************************/
|
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
char Line[256];
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
g_Plot_PlotOutputFile = plot_file;
|
|
|
|
g_Plot_PenState = 'U';
|
2008-03-22 05:55:06 +00:00
|
|
|
sprintf( Line, "IN;VS%d;PU;PA;SP%d;\n", pen_speed, pen_num );
|
|
|
|
fputs( Line, plot_file );
|
|
|
|
return TRUE;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/**********************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
bool CloseFileHPGL( FILE* plot_file )
|
2007-05-28 18:09:49 +00:00
|
|
|
/**********************************/
|
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
fputs( "PU;PA;SP0;\n", plot_file );
|
|
|
|
fclose( plot_file );
|
|
|
|
return TRUE;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
2008-06-30 13:47:55 +00:00
|
|
|
/************************************************************/
|
2008-08-05 16:06:45 +00:00
|
|
|
void PlotRectHPGL( wxPoint p1, wxPoint p2, bool fill, int width )
|
2008-06-30 13:47:55 +00:00
|
|
|
/************************************************************/
|
|
|
|
{
|
|
|
|
char Line[256];
|
|
|
|
|
|
|
|
UserToDeviceCoordinate( p1 );
|
|
|
|
UserToDeviceCoordinate( p2 );
|
|
|
|
|
|
|
|
Plume_HPGL( 'U' );
|
|
|
|
sprintf( Line, "PA %d,%d;EA %d,%d;\n", p1.x, p1.y, p2.x, p2.y );
|
2008-12-22 21:06:44 +00:00
|
|
|
fputs( Line, g_Plot_PlotOutputFile );
|
2008-06-30 13:47:55 +00:00
|
|
|
|
|
|
|
Plume_HPGL( 'U' ); return;
|
|
|
|
}
|
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
|
|
|
|
/************************************************************/
|
2008-08-05 16:06:45 +00:00
|
|
|
void PlotCircleHPGL( wxPoint centre, int diameter, bool fill, int width )
|
2007-05-28 18:09:49 +00:00
|
|
|
/************************************************************/
|
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
int rayon;
|
|
|
|
char Line[256];
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
UserToDeviceCoordinate( centre );
|
2008-12-22 21:06:44 +00:00
|
|
|
rayon = (int) (diameter / 2 * g_Plot_XScale);
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
if( rayon < 0 )
|
|
|
|
rayon = 0;
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
Plume_HPGL( 'U' );
|
|
|
|
sprintf( Line, "PA %d,%d;CI %d,%d;\n", centre.x, centre.y, rayon, CHORD_ANGLE );
|
2008-12-22 21:06:44 +00:00
|
|
|
fputs( Line, g_Plot_PlotOutputFile );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
Plume_HPGL( 'U' ); return;
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************/
|
2008-08-05 16:06:45 +00:00
|
|
|
void PlotArcHPGL( wxPoint centre, int StAngle, int EndAngle, int rayon, bool fill, int width )
|
2007-05-28 18:09:49 +00:00
|
|
|
/********************************************************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* trace d'un arc de cercle:
|
2008-03-22 05:55:06 +00:00
|
|
|
* centre = coord du centre
|
|
|
|
* StAngle, EndAngle = angle de debut et fin
|
|
|
|
* rayon = rayon de l'arc
|
|
|
|
* commande
|
|
|
|
* PU;PA x,y;PD;AA start_arc_X, start_arc_Y, angle, NbSegm; PU;
|
|
|
|
* ou PU;PA x,y;PD;AA start_arc_X, start_arc_Y, angle; PU;
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
char Line[256];
|
|
|
|
wxPoint cmap; /* point de depart */
|
|
|
|
wxPoint cpos; /* centre */
|
|
|
|
float angle; /* angle de l'arc*/
|
|
|
|
|
|
|
|
if( rayon <= 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
cpos = centre; UserToDeviceCoordinate( cpos );
|
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
if( g_Plot_PlotOrientOptions == PLOT_MIROIR )
|
2008-03-22 05:55:06 +00:00
|
|
|
{
|
|
|
|
EndAngle = -EndAngle;
|
|
|
|
StAngle = -StAngle;
|
|
|
|
EXCHG( StAngle, EndAngle );
|
|
|
|
}
|
|
|
|
angle = (EndAngle - StAngle) / 10.0;
|
|
|
|
/* Calcul des coord du point de depart : */
|
|
|
|
cmap.x = (int) ( centre.x + ( rayon * cos( StAngle * M_PI / 1800 ) ) );
|
|
|
|
cmap.y = (int) ( centre.y + ( rayon * sin( StAngle * M_PI / 1800 ) ) );
|
|
|
|
UserToDeviceCoordinate( cmap );
|
|
|
|
|
|
|
|
Plume_HPGL( 'U' );
|
|
|
|
sprintf( Line, "PU;PA %d,%d;PD;AA %d,%d, ", cmap.x, cmap.y, cpos.x, cpos.y );
|
2008-12-22 21:06:44 +00:00
|
|
|
fputs( Line, g_Plot_PlotOutputFile );
|
2008-03-22 05:55:06 +00:00
|
|
|
sprintf( Line, "%f", -angle ); to_point( Line ); // Transforme , et . du separateur
|
2008-12-22 21:06:44 +00:00
|
|
|
fputs( Line, g_Plot_PlotOutputFile );
|
|
|
|
sprintf( Line, ", %d", CHORD_ANGLE ); fputs( Line, g_Plot_PlotOutputFile );
|
|
|
|
sprintf( Line, ";PU;\n" ); fputs( Line, g_Plot_PlotOutputFile );
|
2008-03-22 05:55:06 +00:00
|
|
|
Plume_HPGL( 'U' );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************/
|
2008-08-05 16:06:45 +00:00
|
|
|
void PlotPolyHPGL( int nb, int* coord, bool fill, int width )
|
2007-05-28 18:09:49 +00:00
|
|
|
/*****************************************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* Trace un polygone (ferme si rempli) en format HPGL
|
2008-03-22 05:55:06 +00:00
|
|
|
* coord = tableau des coord des sommets
|
|
|
|
* nb = nombre de coord ( 1 coord = 2 elements: X et Y du tableau )
|
|
|
|
* fill : si != 0 polygone rempli
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
int ii;
|
|
|
|
|
|
|
|
if( nb <= 1 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
Move_Plume_HPGL( wxPoint( coord[0], coord[1] ), 'U' );
|
|
|
|
for( ii = 1; ii < nb; ii++ )
|
|
|
|
{
|
|
|
|
Move_Plume_HPGL( wxPoint( coord[ii * 2], coord[(ii * 2) + 1] ), 'D' );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fermeture eventuelle du polygone */
|
|
|
|
if( fill )
|
|
|
|
{
|
|
|
|
ii = (nb - 1) * 2;
|
|
|
|
if( (coord[ii] != coord[0] ) || (coord[ii + 1] != coord[0]) )
|
|
|
|
Move_Plume_HPGL( wxPoint( coord[0], coord[1] ), 'D' );
|
|
|
|
}
|
|
|
|
Plume_HPGL( 'U' );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************/
|
|
|
|
void Move_Plume_HPGL( wxPoint pos, int plume )
|
|
|
|
/**********************************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/*
|
2008-03-22 05:55:06 +00:00
|
|
|
* deplace la plume levee (plume = 'U') ou baissee (plume = 'D')
|
|
|
|
* en position x,y
|
|
|
|
* Unites en Unites DESSIN
|
|
|
|
* Si plume = 'Z' lever de plume sans deplacement
|
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
char Line[256];
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-03-22 05:55:06 +00:00
|
|
|
if( plume == 'Z' )
|
|
|
|
{
|
|
|
|
Plume_HPGL( 'U' );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Plume_HPGL( plume );
|
|
|
|
UserToDeviceCoordinate( pos );
|
2007-05-28 18:09:49 +00:00
|
|
|
|
2008-12-22 21:06:44 +00:00
|
|
|
sprintf( Line, "PA %d,%d;\n", pos.x, pos.y ); fputs( Line, g_Plot_PlotOutputFile );
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************/
|
|
|
|
void Plume_HPGL( int plume )
|
|
|
|
/***************************/
|
2008-03-22 05:55:06 +00:00
|
|
|
|
2007-05-28 18:09:49 +00:00
|
|
|
/* leve (plume = 'U') ou baisse (plume = 'D') la plume
|
2008-03-22 05:55:06 +00:00
|
|
|
*/
|
2007-05-28 18:09:49 +00:00
|
|
|
{
|
2008-03-22 05:55:06 +00:00
|
|
|
if( plume == 'U' )
|
|
|
|
{
|
2008-12-22 21:06:44 +00:00
|
|
|
if( g_Plot_PenState != 'U' )
|
|
|
|
fputs( "PU;", g_Plot_PlotOutputFile );
|
|
|
|
g_Plot_PenState = 'U';
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-12-22 21:06:44 +00:00
|
|
|
if( g_Plot_PenState != 'D' )
|
|
|
|
fputs( "PD;", g_Plot_PlotOutputFile );
|
|
|
|
g_Plot_PenState = 'D';
|
2008-03-22 05:55:06 +00:00
|
|
|
}
|
2007-05-28 18:09:49 +00:00
|
|
|
}
|