kicad/pcbnew/classpcb.cpp

484 lines
13 KiB
C++
Raw Normal View History

/**********************************************************************/
/* fonctions membres des classes utilisees dans pcbnew (voir pcbstruct.h */
/* sauf routines relatives aux pistes (voir class_track.cpp) */
/**********************************************************************/
#include "fctsys.h"
#include "wxstruct.h"
#include "gr_basic.h"
#include "common.h"
#include "pcbnew.h"
#ifdef CVPCB
#include "cvpcb.h"
#endif
#include "protos.h"
2007-08-08 20:51:08 +00:00
#include "trigo.h"
/**************************************************************/
2007-08-06 21:02:23 +00:00
void EDA_BaseStruct::Place( WinEDA_DrawFrame* frame, wxDC* DC )
/**************************************************************/
2007-08-06 21:02:23 +00:00
/* fonction virtuelle de placement: non utilisee en pcbnew (utilisee eeschema)
2007-08-06 21:02:23 +00:00
* ---- A mieux utiliser (TODO...)
*/
{
}
2007-08-06 21:02:23 +00:00
/**********************/
/* Classe EDGE_ZONE */
/**********************/
/* Classe EDGE_ZONE: constructeur */
2007-08-23 04:28:46 +00:00
EDGE_ZONE::EDGE_ZONE( BOARD_ITEM* parent ) :
2007-08-06 21:02:23 +00:00
DRAWSEGMENT( parent, TYPEEDGEZONE )
{
}
2007-08-06 21:02:23 +00:00
/* Effacement memoire de la structure */
2007-09-01 12:00:30 +00:00
EDGE_ZONE:: ~EDGE_ZONE()
{
}
2007-08-06 21:02:23 +00:00
/**********************/
/* Classe DRAWSEGMENT */
/**********************/
/* Classe DRAWSEGMENT: constructeur */
DRAWSEGMENT::DRAWSEGMENT( BOARD_ITEM* StructFather, KICAD_T idtype ) :
2007-08-23 04:28:46 +00:00
BOARD_ITEM( StructFather, idtype )
{
m_Width = m_Flags = m_Shape = m_Type = m_Angle = 0;
}
2007-08-06 21:02:23 +00:00
/* Effacement memoire de la structure */
2007-09-01 12:00:30 +00:00
DRAWSEGMENT:: ~DRAWSEGMENT()
{
}
2007-08-06 21:02:23 +00:00
2007-09-01 12:00:30 +00:00
void DRAWSEGMENT::UnLink()
{
2007-08-06 21:02:23 +00:00
/* Modification du chainage arriere */
if( Pback )
{
2007-09-01 12:00:30 +00:00
if( Pback->Type() != TYPEPCB )
2007-08-06 21:02:23 +00:00
{
Pback->Pnext = Pnext;
}
else /* Le chainage arriere pointe sur la structure "Pere" */
{
2007-08-23 04:28:46 +00:00
( (BOARD*) Pback )->m_Drawings = (BOARD_ITEM*) Pnext;
2007-08-06 21:02:23 +00:00
}
}
/* Modification du chainage avant */
if( Pnext )
Pnext->Pback = Pback;
Pnext = Pback = NULL;
}
/*******************************************/
2007-08-06 21:02:23 +00:00
void DRAWSEGMENT::Copy( DRAWSEGMENT* source )
/*******************************************/
{
2007-08-06 21:02:23 +00:00
m_Type = source->m_Type;
m_Layer = source->m_Layer;
m_Width = source->m_Width;
m_Start = source->m_Start;
m_End = source->m_End;
m_Shape = source->m_Shape;
m_Angle = source->m_Angle;
m_TimeStamp = source->m_TimeStamp;
}
/********************************************************/
2007-08-06 21:02:23 +00:00
bool DRAWSEGMENT::WriteDrawSegmentDescr( FILE* File )
/********************************************************/
{
2007-08-06 21:02:23 +00:00
if( GetState( DELETED ) )
return FALSE;
fprintf( File, "$DRAWSEGMENT\n" );
fprintf( File, "Po %d %d %d %d %d %d\n",
m_Shape,
m_Start.x, m_Start.y,
m_End.x, m_End.y, m_Width );
fprintf( File, "De %d %d %d %lX %X\n",
m_Layer, m_Type, m_Angle,
m_TimeStamp, ReturnStatus() );
fprintf( File, "$EndDRAWSEGMENT\n" );
return TRUE;
}
2007-08-06 21:02:23 +00:00
/******************************************************************/
2007-08-06 21:02:23 +00:00
bool DRAWSEGMENT::ReadDrawSegmentDescr( FILE* File, int* LineNum )
/******************************************************************/
2007-08-06 21:02:23 +00:00
/* Lecture de la description de 1 segment type Drawing PCB
2007-08-06 21:02:23 +00:00
*/
{
2007-08-06 21:02:23 +00:00
char Line[2048];
while( GetLine( File, Line, LineNum ) != NULL )
{
if( strnicmp( Line, "$End", 4 ) == 0 )
return TRUE; /* fin de liste */
if( Line[0] == 'P' )
{
sscanf( Line + 2, " %d %d %d %d %d %d",
&m_Shape, &m_Start.x, &m_Start.y,
&m_End.x, &m_End.y, &m_Width );
if( m_Width < 0 )
m_Width = 0;
}
if( Line[0] == 'D' )
{
int status;
sscanf( Line + 2, " %d %d %d %lX %X",
&m_Layer, &m_Type, &m_Angle,
&m_TimeStamp, &status );
if( m_Layer < FIRST_NO_COPPER_LAYER )
m_Layer = FIRST_NO_COPPER_LAYER;
if( m_Layer > LAST_NO_COPPER_LAYER )
m_Layer = LAST_NO_COPPER_LAYER;
SetState( status, ON );
}
}
return FALSE;
}
// see pcbstruct.h
void DRAWSEGMENT::Display_Infos( WinEDA_DrawFrame* frame )
{
int itype;
wxString msg;
frame->MsgPanel->EraseMsgBox();
itype = m_Type & 0x0F;
msg = wxT( "DRAWING" );
Affiche_1_Parametre( frame, 1, _( "Type" ), msg, DARKCYAN );
Affiche_1_Parametre( frame, 16, _( "Shape" ), wxEmptyString, RED );
if( m_Shape == S_CIRCLE )
Affiche_1_Parametre( frame, -1, wxEmptyString, _( "Circle" ), RED );
else if( m_Shape == S_ARC )
{
Affiche_1_Parametre( frame, -1, wxEmptyString, _( " Arc " ), RED );
msg.Printf( wxT( "%d" ), m_Angle );
Affiche_1_Parametre( frame, 32, wxT( " l.arc " ), msg, RED );
}
else
Affiche_1_Parametre( frame, -1, wxEmptyString, _( "Segment" ), RED );
Affiche_1_Parametre( frame, 48, _( "Layer" ),
ReturnPcbLayerName( m_Layer ), BROWN );
/* Affiche Epaisseur */
valeur_param( (unsigned) m_Width, msg );
Affiche_1_Parametre( frame, 60, _( "Width" ), msg, DARKCYAN );
}
2007-08-08 20:51:08 +00:00
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param ref_pos A wxPoint to test
* @return bool - true if a hit, else false
*/
bool DRAWSEGMENT::HitTest( const wxPoint& ref_pos )
{
int ux0 = m_Start.x;
int uy0 = m_Start.y;
/* recalcul des coordonnees avec ux0, uy0 = origine des coordonnees */
int dx = m_End.x - ux0;
int dy = m_End.y - uy0;
int spot_cX = ref_pos.x - ux0;
int spot_cY = ref_pos.y - uy0;
if( m_Shape==S_CIRCLE || m_Shape==S_ARC )
{
int rayon, dist, stAngle, endAngle, mouseAngle;
rayon = (int) hypot( (double) (dx), (double) (dy) );
dist = (int) hypot( (double) (spot_cX), (double) (spot_cY) );
if( abs( rayon - dist ) <= (m_Width / 2) )
{
if( m_Shape == S_CIRCLE )
return true;
/* pour un arc, controle complementaire */
mouseAngle = (int) ArcTangente( spot_cY, spot_cX );
stAngle = (int) ArcTangente( dy, dx );
endAngle = stAngle + m_Angle;
if( endAngle > 3600 )
{
stAngle -= 3600;
endAngle -= 3600;
}
if( mouseAngle >= stAngle && mouseAngle <= endAngle )
return true;
}
}
else
{
if( DistanceTest( m_Width / 2, dx, dy, spot_cX, spot_cY ) )
return true;
}
return false;
}
2007-08-06 21:02:23 +00:00
/*******************/
/* Classe MARQUEUR */
/*******************/
2007-08-23 04:28:46 +00:00
MARQUEUR::MARQUEUR( BOARD_ITEM* StructFather ) :
BOARD_ITEM( StructFather, TYPEMARQUEUR )
{
2007-08-06 21:02:23 +00:00
m_Bitmap = NULL;
m_Type = 0;
m_Color = RED;
}
2007-08-06 21:02:23 +00:00
/* Effacement memoire de la structure */
2007-09-01 12:00:30 +00:00
MARQUEUR:: ~MARQUEUR()
{
}
/* supprime du chainage la structure Struct
2007-08-06 21:02:23 +00:00
* les structures arrieres et avant sont chainees directement
*/
2007-09-01 12:00:30 +00:00
void MARQUEUR::UnLink()
{
2007-08-06 21:02:23 +00:00
/* Modification du chainage arriere */
if( Pback )
{
2007-09-01 12:00:30 +00:00
if( Pback->Type() != TYPEPCB )
2007-08-06 21:02:23 +00:00
{
Pback->Pnext = Pnext;
}
else /* Le chainage arriere pointe sur la structure "Pere" */
{
2007-08-23 04:28:46 +00:00
( (BOARD*) Pback )->m_Drawings = (BOARD_ITEM*) Pnext;
2007-08-06 21:02:23 +00:00
}
}
/* Modification du chainage avant */
if( Pnext )
Pnext->Pback = Pback;
Pnext = Pback = NULL;
}
2007-10-03 19:45:32 +00:00
void MARQUEUR::Display_Infos( WinEDA_DrawFrame* frame )
{
int text_pos;
frame->MsgPanel->EraseMsgBox();
text_pos = 1;
Affiche_1_Parametre( frame, text_pos, _( "Type" ), _("Marker"), DARKCYAN );
text_pos = 12;
Affiche_1_Parametre( frame, text_pos, _( "Marker Error Text" ), m_Diag, RED );
}
bool MARQUEUR::HitTest( const wxPoint& refPos )
{
2007-10-09 12:29:02 +00:00
// the MARKER is 12 pixels by 12 pixels, but is not resized with zoom, so
// as zoom changes, the effective real size of the MARKER changes.
// @todo: compensate for the zoom. right now it is difficult to select marker when zoomed out.
const int halfSize = 6;
int xCenter = m_Pos.x + halfSize;
int yCenter = m_Pos.y + halfSize;
2007-10-03 19:45:32 +00:00
int dx = refPos.x - xCenter;
int dy = refPos.y - yCenter;
2007-10-09 12:29:02 +00:00
if( ABS(dx) <= halfSize && ABS(dy) <= halfSize )
2007-10-03 19:45:32 +00:00
return true;
else
return false;
}
2007-08-06 21:02:23 +00:00
/**************************************************/
/* Class SCREEN: classe de gestion d'un affichage */
/***************************************************/
/* Constructeur de SCREEN */
2007-08-06 21:02:23 +00:00
PCB_SCREEN::PCB_SCREEN( int idscreen ) : BASE_SCREEN( TYPESCREEN )
{
2007-08-06 21:02:23 +00:00
int zoom_list[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 0 };
m_Type = idscreen;
SetGridList( g_GridList );
SetZoomList( zoom_list );
Init();
}
2007-08-06 21:02:23 +00:00
/***************************/
2007-09-01 12:00:30 +00:00
PCB_SCREEN::~PCB_SCREEN()
/***************************/
{
}
/*************************/
2007-09-01 12:00:30 +00:00
void PCB_SCREEN::Init()
/*************************/
{
2007-08-06 21:02:23 +00:00
InitDatas();
m_Active_Layer = COPPER_LAYER_N; /* ref couche active 0.. 31 */
2007-08-06 21:02:23 +00:00
m_Route_Layer_TOP = CMP_N; /* ref couches par defaut pour vias (Cu.. Cmp) */
m_Route_Layer_BOTTOM = COPPER_LAYER_N;
2007-08-06 21:02:23 +00:00
m_Zoom = 128; /* valeur */
m_Grid = wxSize( 500, 500 ); /* pas de la grille en 1/10000 "*/
}
/*************************/
/* class DISPLAY_OPTIONS */
/*************************/
2007-08-06 21:02:23 +00:00
/*
* Handle display options like enable/disable some optional drawings:
2007-08-06 21:02:23 +00:00
*/
2007-09-01 12:00:30 +00:00
DISPLAY_OPTIONS::DISPLAY_OPTIONS()
{
2007-08-06 21:02:23 +00:00
DisplayPadFill = TRUE;
DisplayPadNum = TRUE;
DisplayPadNoConn = TRUE;
DisplayPadIsol = TRUE;
DisplayModEdge = TRUE;
DisplayModText = TRUE;
DisplayPcbTrackFill = TRUE; /* FALSE = sketch , TRUE = rempli */
DisplayTrackIsol = FALSE;
m_DisplayViaMode = VIA_HOLE_NOT_SHOW;
DisplayPolarCood = TRUE;
DisplayZones = TRUE;
Show_Modules_Cmp = TRUE;
Show_Modules_Cu = TRUE;
DisplayDrawItems = TRUE;
ContrastModeDisplay = FALSE;
}
/*****************************************************/
2007-09-01 12:00:30 +00:00
EDA_BoardDesignSettings::EDA_BoardDesignSettings()
/*****************************************************/
2007-08-06 21:02:23 +00:00
// Default values for designing boards
{
2007-08-06 21:02:23 +00:00
int ii;
int default_layer_color[32] = {
GREEN, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY, LIGHTGRAY, RED,
LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY,
MAGENTA, CYAN,
LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY,
LIGHTGRAY,
LIGHTGRAY, LIGHTGRAY,
LIGHTGRAY,
LIGHTGRAY,
LIGHTGRAY,
LIGHTGRAY
};
m_CopperLayerCount = 2; // Default design is a double sided board
m_ViaDrill = 250; // via drill (for the entire board)
m_CurrentViaSize = 450; // Current via size
m_CurrentViaType = VIA_NORMALE; /* via type (BLIND, TROUGHT ...), bits 1 and 2 (not 0 and 1)*/
m_CurrentTrackWidth = 170; // current track width
for( ii = 0; ii < HIST0RY_NUMBER; ii++ )
{
m_TrackWidhtHistory[ii] = 0; // Last HIST0RY_NUMBER used track widths
m_ViaSizeHistory[ii] = 0; // Last HIST0RY_NUMBER used via sizes
}
m_DrawSegmentWidth = 100; // current graphic line width (not EDGE layer)
m_EdgeSegmentWidth = 100; // current graphic line width (EDGE layer only)
m_PcbTextWidth = 100; // current Pcb (not module) Text width
m_PcbTextSize = wxSize( 500, 500 ); // current Pcb (not module) Text size
m_TrackClearence = 100; // track to track and track to pads clearance
m_ZoneClearence = 150; // zone to track and zone to pads clearance
m_MaskMargin = 150; // Solder mask margin
/* Color options for screen display of the Printed Board: */
m_PcbGridColor = DARKGRAY; // Grid color
for( ii = 0; ii < 32; ii++ )
m_LayerColor[ii] = default_layer_color[ii];
// Layer colors (tracks and graphic items)
m_ViaColor[VIA_BORGNE] = CYAN;
m_ViaColor[VIA_ENTERREE] = BROWN;
m_ViaColor[VIA_NORMALE] = WHITE;
m_ModuleTextCMPColor = LIGHTGRAY; // Text module color for modules on the COMPONENT layer
m_ModuleTextCUColor = MAGENTA; // Text module color for modules on the COPPER layer
m_ModuleTextNOVColor = DARKGRAY; // Text module color for "invisible" texts (must be BLACK if really not displayed)
m_AnchorColor = BLUE; // Anchor color for modules and texts
m_PadCUColor = GREEN; // Pad color for the COMPONENT side of the pad
m_PadCMPColor = RED; // Pad color for the COPPER side of the pad
m_RatsnestColor = WHITE; // Ratsnest color
}
// see pcbstruct.h
2007-08-30 22:20:52 +00:00
int EDA_BoardDesignSettings::GetVisibleLayers() const
{
int layerMask = 0;
for( int i=0, mask=1; i< 32; ++i, mask<<=1 )
{
if( !(m_LayerColor[i] & ITEM_NOT_SHOW) )
layerMask |= mask;
}
return layerMask;
}