2007-08-06 20:26:59 +00:00
|
|
|
/****************************************************/
|
|
|
|
/* class_module.cpp : fonctions de la classe MODULE */
|
|
|
|
/****************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "wxstruct.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "trigo.h"
|
|
|
|
|
|
|
|
#ifdef PCBNEW
|
|
|
|
#include "pcbnew.h"
|
|
|
|
#include "autorout.h"
|
|
|
|
#include "drag.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CVPCB
|
|
|
|
#include "cvpcb.h"
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
#define MAX_WIDTH 10000 // Epaisseur (en 1/10000 ") max raisonnable des traits, textes...
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
/******************************************/
|
|
|
|
/* class EDGE_MODULE ( contour de module ) */
|
|
|
|
/******************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
EDGE_MODULE::EDGE_MODULE( MODULE* parent ) :
|
2007-08-23 04:28:46 +00:00
|
|
|
BOARD_ITEM( parent, TYPEEDGEMODULE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Width = 0;
|
2007-08-06 20:26:59 +00:00
|
|
|
m_Shape = S_SEGMENT;
|
|
|
|
m_Angle = 0;
|
|
|
|
m_Width = 120;
|
|
|
|
m_PolyCount = 0; // For polygons : number of points (> 2)
|
|
|
|
m_PolyList = NULL; // For polygons: coord list (1 point = 2 coord)
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
EDGE_MODULE::~EDGE_MODULE()
|
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
if( m_PolyList )
|
|
|
|
free( m_PolyList );
|
|
|
|
m_PolyList = NULL;
|
|
|
|
m_PolyCount = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************/
|
2007-08-06 20:26:59 +00:00
|
|
|
void EDGE_MODULE:: Copy( EDGE_MODULE* source ) // copy structure
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************/
|
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
if( source == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_Start = source->m_Start;
|
|
|
|
m_End = source->m_End;
|
|
|
|
m_Shape = source->m_Shape;
|
|
|
|
m_Start0 = source->m_Start0; // coord relatives a l'ancre du point de depart(Orient 0)
|
|
|
|
m_End0 = source->m_End0; // coord relatives a l'ancre du point de fin (Orient 0)
|
|
|
|
m_Angle = source->m_Angle; // pour les arcs de cercle: longueur de l'arc en 0,1 degres
|
|
|
|
m_Layer = source->m_Layer;
|
|
|
|
m_Width = source->m_Width;
|
|
|
|
if( m_PolyList )
|
|
|
|
free( m_PolyList );
|
|
|
|
m_PolyCount = 0;
|
|
|
|
m_PolyList = NULL;
|
|
|
|
if( source->m_PolyCount && source->m_PolyList )
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
m_PolyCount = source->m_PolyCount; // For polygons : number of points
|
|
|
|
size = m_PolyCount * 2 * sizeof(int); // For polygons: 1 point = 2 coord
|
|
|
|
m_PolyList = (int*) MyMalloc( size );
|
|
|
|
memcpy( m_PolyList, source->m_PolyList, size );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
void EDGE_MODULE::UnLink()
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************/
|
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
/* Modification du chainage arriere */
|
|
|
|
if( Pback )
|
|
|
|
{
|
2007-09-01 12:00:30 +00:00
|
|
|
if( Pback->Type() != TYPEMODULE )
|
2007-08-06 20:26:59 +00:00
|
|
|
{
|
|
|
|
Pback->Pnext = Pnext;
|
|
|
|
}
|
|
|
|
else /* Le chainage arriere pointe sur la structure "Pere" */
|
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
( (MODULE*) Pback )->m_Drawings = (BOARD_ITEM*) Pnext;
|
2007-08-06 20:26:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Modification du chainage avant */
|
|
|
|
if( Pnext )
|
|
|
|
Pnext->Pback = Pback;
|
|
|
|
|
|
|
|
Pnext = Pback = NULL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
void EDGE_MODULE::SetDrawCoord()
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************/
|
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
MODULE* Module = (MODULE*) m_Parent;
|
|
|
|
|
|
|
|
m_Start = m_Start0;
|
|
|
|
m_End = m_End0;
|
|
|
|
|
|
|
|
if( Module )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Start.x, &m_Start.y, Module->m_Orient );
|
|
|
|
RotatePoint( &m_End.x, &m_End.y, Module->m_Orient );
|
|
|
|
m_Start.x += Module->m_Pos.x;
|
|
|
|
m_Start.y += Module->m_Pos.y;
|
|
|
|
m_End.x += Module->m_Pos.x;
|
|
|
|
m_End.y += Module->m_Pos.y;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************************************/
|
2007-08-06 20:26:59 +00:00
|
|
|
void EDGE_MODULE::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
const wxPoint& offset, int draw_mode )
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************************/
|
|
|
|
|
|
|
|
/* Affichage d'un segment contour de module :
|
2007-08-06 20:26:59 +00:00
|
|
|
* Entree : ox, oy = offset de trace
|
|
|
|
* draw_mode = mode de trace ( GR_OR, GR_XOR, GR_AND)
|
|
|
|
* Les contours sont de differents type:
|
|
|
|
* - Segment
|
|
|
|
* - Cercles
|
|
|
|
* - Arcs
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
int ux0, uy0, dx, dy, rayon, StAngle, EndAngle;
|
|
|
|
int color, type_trace;
|
|
|
|
int zoom;
|
|
|
|
int typeaff;
|
|
|
|
PCB_SCREEN* screen;
|
|
|
|
WinEDA_BasePcbFrame* frame;
|
|
|
|
MODULE* Module = NULL;
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
if( m_Parent && (m_Parent->Type() == TYPEMODULE) )
|
2007-08-06 20:26:59 +00:00
|
|
|
Module = (MODULE*) m_Parent;
|
|
|
|
|
|
|
|
color = g_DesignSettings.m_LayerColor[m_Layer];
|
|
|
|
if( (color & ITEM_NOT_SHOW) != 0 )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( panel )
|
|
|
|
screen = (PCB_SCREEN*) panel->m_Parent->m_CurrentScreen;
|
|
|
|
else
|
|
|
|
screen = (PCB_SCREEN*) ActiveScreen;
|
|
|
|
|
|
|
|
frame = (WinEDA_BasePcbFrame*) panel->m_Parent;
|
|
|
|
|
|
|
|
zoom = screen->GetZoom();
|
|
|
|
|
|
|
|
type_trace = m_Shape;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
ux0 = m_Start.x - offset.x;
|
|
|
|
uy0 = m_Start.y - offset.y;
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
dx = m_End.x - offset.x;
|
|
|
|
dy = m_End.y - offset.y;
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, draw_mode );
|
|
|
|
typeaff = frame->m_DisplayModEdge;
|
|
|
|
if( m_Layer <= CMP_N )
|
|
|
|
{
|
|
|
|
typeaff = frame->m_DisplayPcbTrackFill;
|
|
|
|
if( !typeaff )
|
|
|
|
typeaff = SKETCH;
|
|
|
|
}
|
|
|
|
if( (m_Width / zoom) < L_MIN_DESSIN )
|
|
|
|
typeaff = FILAIRE;
|
|
|
|
|
|
|
|
switch( type_trace )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
if( typeaff == FILAIRE )
|
|
|
|
GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, 0, color );
|
|
|
|
else if( typeaff == FILLED )
|
|
|
|
GRLine( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, m_Width, color );
|
|
|
|
else
|
|
|
|
// SKETCH Mode
|
|
|
|
GRCSegm( &panel->m_ClipBox, DC, ux0, uy0, dx, dy, m_Width, color );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
|
|
|
|
if( typeaff == FILAIRE )
|
|
|
|
{
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( typeaff == FILLED )
|
|
|
|
{
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon, m_Width, color );
|
|
|
|
}
|
|
|
|
else // SKETCH Mode
|
|
|
|
{
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon + (m_Width / 2), color );
|
|
|
|
GRCircle( &panel->m_ClipBox, DC, ux0, uy0, rayon - (m_Width / 2), color );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
rayon = (int) hypot( (double) (dx - ux0), (double) (dy - uy0) );
|
|
|
|
StAngle = (int) ArcTangente( dy - uy0, dx - ux0 );
|
|
|
|
EndAngle = StAngle + m_Angle;
|
|
|
|
if( StAngle > EndAngle )
|
|
|
|
EXCHG( StAngle, EndAngle );
|
|
|
|
if( typeaff == FILAIRE )
|
|
|
|
{
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon, color );
|
|
|
|
}
|
|
|
|
else if( typeaff == FILLED )
|
|
|
|
{
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle, rayon,
|
|
|
|
m_Width, color );
|
|
|
|
}
|
|
|
|
else // SKETCH Mode
|
|
|
|
{
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle,
|
|
|
|
rayon + (m_Width / 2), color );
|
|
|
|
GRArc( &panel->m_ClipBox, DC, ux0, uy0, StAngle, EndAngle,
|
|
|
|
rayon - (m_Width / 2), color );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
{
|
|
|
|
// We must compute true coordinates from m_PolyList
|
|
|
|
// which are relative to module position, orientation 0
|
|
|
|
int ii, * source, * ptr, * ptr_base;
|
|
|
|
ptr = ptr_base = (int*) MyMalloc( 2 * m_PolyCount * sizeof(int) );
|
|
|
|
source = m_PolyList;
|
|
|
|
for( ii = 0; ii < m_PolyCount; ii++ )
|
|
|
|
{
|
|
|
|
int x, y;
|
|
|
|
x = *source; source++; y = *source; source++;
|
|
|
|
if( Module )
|
|
|
|
{
|
|
|
|
RotatePoint( &x, &y, Module->m_Orient );
|
|
|
|
x += Module->m_Pos.x;
|
|
|
|
y += Module->m_Pos.y;
|
|
|
|
}
|
|
|
|
x += m_Start0.x - offset.x;
|
|
|
|
y += m_Start0.y - offset.y;
|
|
|
|
*ptr = x; ptr++; *ptr = y; ptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRPoly( &panel->m_ClipBox, DC, m_PolyCount, ptr_base,
|
|
|
|
TRUE, m_Width, color, color );
|
|
|
|
free( ptr_base );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
// see class_edge_mod.h
|
|
|
|
void EDGE_MODULE::Display_Infos( WinEDA_DrawFrame* frame )
|
|
|
|
{
|
|
|
|
wxString bufcar;
|
|
|
|
|
|
|
|
MODULE* module = (MODULE*) m_Parent;
|
|
|
|
if( !module )
|
|
|
|
return;
|
|
|
|
|
|
|
|
frame->MsgPanel->EraseMsgBox();
|
|
|
|
|
|
|
|
Affiche_1_Parametre( frame, 1, _( "Seg" ), wxEmptyString, DARKCYAN );
|
|
|
|
|
|
|
|
Affiche_1_Parametre( frame, 5, _( "Module" ), module->m_Reference->m_Text, DARKCYAN );
|
|
|
|
Affiche_1_Parametre( frame, 14, _( "Value" ), module->m_Value->m_Text, BLUE );
|
|
|
|
bufcar.Printf( wxT( "%8.8lX" ), module->m_TimeStamp );
|
|
|
|
|
|
|
|
Affiche_1_Parametre( frame, 24, _( "TimeStamp" ), bufcar, BROWN );
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
Affiche_1_Parametre( frame, 34, _( "Mod Layer" ), ReturnPcbLayerName( module->GetLayer() ), RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
Affiche_1_Parametre( frame, 44, _( "Seg Layer" ),
|
2007-08-23 04:28:46 +00:00
|
|
|
ReturnPcbLayerName( module->GetLayer() ), RED );
|
2007-08-20 19:33:15 +00:00
|
|
|
|
|
|
|
valeur_param( m_Width, bufcar );
|
|
|
|
Affiche_1_Parametre( frame, 54, _( "Width" ), bufcar, BLUE );
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
2007-10-30 21:30:58 +00:00
|
|
|
#if 0 // replaced by Save()
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************/
|
2007-08-06 20:26:59 +00:00
|
|
|
int EDGE_MODULE::WriteDescr( FILE* File )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************/
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Write one EDGE_MODULE description
|
2007-08-06 20:26:59 +00:00
|
|
|
* File must be opened.
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
int NbLigne = 0, ii, * ptr;
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
fprintf( File, "DS %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
NbLigne++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
fprintf( File, "DC %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
NbLigne++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
fprintf( File, "DA %d %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Angle,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
NbLigne++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
fprintf( File, "DP %d %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_PolyCount,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
NbLigne++;
|
|
|
|
for( ii = 0, ptr = m_PolyList; ii < m_PolyCount; ii++ )
|
|
|
|
{
|
|
|
|
fprintf( File, "Dl %d %d\n",
|
|
|
|
*ptr, *(ptr + 1) );
|
|
|
|
NbLigne++; ptr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DisplayError( NULL, wxT( "Type Edge Module inconnu" ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NbLigne;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-10-30 21:30:58 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
bool EDGE_MODULE::Save( FILE* aFile ) const
|
|
|
|
{
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
ret = fprintf( aFile, "DS %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
ret = fprintf( aFile, "DC %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
ret = fprintf( aFile, "DA %d %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_Angle,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
ret = fprintf( aFile, "DP %d %d %d %d %d %d %d\n",
|
|
|
|
m_Start0.x, m_Start0.y,
|
|
|
|
m_End0.x, m_End0.y,
|
|
|
|
m_PolyCount,
|
|
|
|
m_Width, m_Layer );
|
|
|
|
|
|
|
|
int* pInt;
|
|
|
|
pInt = m_PolyList;
|
|
|
|
for( int i=0; i<m_PolyCount; ++i, pInt+=2 )
|
|
|
|
fprintf( aFile, "Dl %d %d\n", pInt[0], pInt[1] );
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// future: throw an exception here
|
2007-10-31 06:40:15 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
printf( "EDGE_MODULE::Save(): unexpected m_Shape: %d\n", m_Shape );
|
|
|
|
#endif
|
2007-10-30 21:30:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (ret > 5);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
/****************************************************************/
|
2007-08-06 20:26:59 +00:00
|
|
|
int EDGE_MODULE::ReadDescr( char* Line, FILE* File,
|
|
|
|
int* LineNum )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************************/
|
2007-08-06 20:26:59 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Read a description line like:
|
2007-08-06 20:26:59 +00:00
|
|
|
* DS 2600 0 2600 -600 120 21
|
|
|
|
* this description line is in Line
|
|
|
|
* EDGE_MODULE type can be:
|
|
|
|
* - Circle,
|
|
|
|
* - Segment (line)
|
|
|
|
* - Arc
|
|
|
|
* - Polygon
|
|
|
|
*
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-06 20:26:59 +00:00
|
|
|
int ii, * ptr;
|
|
|
|
int error = 0;
|
|
|
|
char Buf[1024];
|
|
|
|
|
|
|
|
|
|
|
|
switch( Line[1] )
|
|
|
|
{
|
|
|
|
case 'S':
|
|
|
|
m_Shape = S_SEGMENT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
m_Shape = S_CIRCLE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'A':
|
|
|
|
m_Shape = S_ARC;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'P':
|
|
|
|
m_Shape = S_POLYGON;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxString msg;
|
|
|
|
msg.Printf( wxT( "Unknown EDGE_MODULE type <%s>" ), Line );
|
|
|
|
DisplayError( NULL, msg );
|
|
|
|
error = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_ARC:
|
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_Angle, &m_Width, &m_Layer );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_SEGMENT:
|
|
|
|
case S_CIRCLE:
|
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_Width, &m_Layer );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_POLYGON:
|
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_PolyCount, &m_Width, &m_Layer );
|
|
|
|
(*LineNum)++;
|
|
|
|
m_PolyList = (int*) MyZMalloc( 2 * m_PolyCount * sizeof(int) );
|
|
|
|
for( ii = 0, ptr = m_PolyList; ii < m_PolyCount; ii++ )
|
|
|
|
{
|
|
|
|
if( GetLine( File, Buf, LineNum, sizeof(Buf) - 1 ) != NULL )
|
|
|
|
{
|
|
|
|
if( strncmp( Buf, "Dl", 2 ) != 0 )
|
|
|
|
{
|
|
|
|
error = 1; break;
|
|
|
|
}
|
|
|
|
sscanf( Buf + 3, "%d %d\n", ptr, ptr + 1 );
|
|
|
|
(*LineNum)++; ptr += 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
error = 1; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sscanf( Line + 3, "%d %d %d %d %d %d",
|
|
|
|
&m_Start0.x, &m_Start0.y,
|
|
|
|
&m_End0.x, &m_End0.y,
|
|
|
|
&m_Width, &m_Layer );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Controle d'epaisseur raisonnable:
|
|
|
|
if( m_Width <= 1 )
|
|
|
|
m_Width = 1;
|
|
|
|
if( m_Width > MAX_WIDTH )
|
|
|
|
m_Width = MAX_WIDTH;
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-08 20:51:08 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
|
|
|
* tests if the given wxPoint is within the bounds of this object.
|
|
|
|
* @param refPos A wxPoint to test
|
|
|
|
* @return bool - true if a hit, else false
|
|
|
|
*/
|
|
|
|
bool EDGE_MODULE::HitTest( const wxPoint& ref_pos )
|
|
|
|
{
|
|
|
|
int uxf, uyf;
|
|
|
|
int rayon, dist;
|
|
|
|
int dx, dy, spot_cX, spot_cY;
|
|
|
|
int ux0, uy0;
|
|
|
|
|
|
|
|
ux0 = m_Start.x;
|
|
|
|
uy0 = m_Start.y;
|
|
|
|
|
|
|
|
uxf = m_End.x;
|
|
|
|
uyf = m_End.y;
|
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT:
|
|
|
|
/* recalcul des coordonnees avec ux0,uy0 = origine des coord. */
|
|
|
|
spot_cX = ref_pos.x - ux0;
|
|
|
|
spot_cY = ref_pos.y - uy0;
|
|
|
|
|
|
|
|
dx = uxf - ux0;
|
|
|
|
dy = uyf - uy0;
|
|
|
|
if( DistanceTest( m_Width/2, dx, dy, spot_cX, spot_cY ) )
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_CIRCLE:
|
|
|
|
rayon = (int) hypot( (double) (uxf - ux0), (double) (uyf - uy0) );
|
|
|
|
dist = (int) hypot( (double) (ref_pos.x - ux0), (double) (ref_pos.y - uy0) );
|
|
|
|
if( abs( rayon - dist ) <= m_Width )
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case S_ARC:
|
|
|
|
rayon = (int) hypot( (double) (uxf - ux0), (double) (uyf - uy0) );
|
|
|
|
dist = (int) hypot( (double) (ref_pos.x - ux0), (double) (ref_pos.y - uy0) );
|
|
|
|
|
|
|
|
if( abs( rayon - dist ) > m_Width )
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* pour un arc, controle complementaire */
|
|
|
|
int mouseAngle = (int) ArcTangente( ref_pos.y - uy0, ref_pos.x - ux0 );
|
|
|
|
int stAngle = (int) ArcTangente( uyf - uy0, uxf - ux0 );
|
|
|
|
int endAngle = stAngle + m_Angle;
|
|
|
|
|
|
|
|
if( endAngle > 3600 )
|
|
|
|
{
|
|
|
|
stAngle -= 3600;
|
|
|
|
endAngle -= 3600;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( (mouseAngle >= stAngle) && (mouseAngle <= endAngle) )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; // an unknown m_Shape also returns false
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
#if defined(DEBUG)
|
|
|
|
/**
|
|
|
|
* Function Show
|
|
|
|
* is used to output the object tree, currently for debugging only.
|
|
|
|
* @param nestLevel An aid to prettier tree indenting, and is the level
|
|
|
|
* of nesting of this object within the overall tree.
|
|
|
|
* @param os The ostream& to output to.
|
|
|
|
*/
|
|
|
|
void EDGE_MODULE::Show( int nestLevel, std::ostream& os )
|
|
|
|
{
|
2007-08-09 01:41:30 +00:00
|
|
|
const char* cp;
|
2007-08-08 03:50:44 +00:00
|
|
|
|
|
|
|
switch( m_Shape )
|
|
|
|
{
|
|
|
|
case S_SEGMENT: cp = "line"; break;
|
|
|
|
case S_RECT: cp = "rect"; break;
|
|
|
|
case S_ARC: cp = "arc"; break;
|
|
|
|
case S_CIRCLE: cp = "circle"; break;
|
|
|
|
case S_ARC_RECT: cp = "arc_rect"; break;
|
|
|
|
case S_SPOT_OVALE: cp = "spot_oval"; break;
|
|
|
|
case S_SPOT_CIRCLE: cp = "spot_circle"; break;
|
|
|
|
case S_SPOT_RECT: cp = "spot_rect"; break;
|
|
|
|
case S_POLYGON: cp = "polygon"; break;
|
2007-08-09 01:41:30 +00:00
|
|
|
default: cp = "??EDGE??"; break;
|
2007-08-08 03:50:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
// for now, make it look like XML:
|
2007-08-08 03:50:44 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
|
2007-08-09 01:41:30 +00:00
|
|
|
" type=\"" << cp << "\">";
|
2007-08-08 03:50:44 +00:00
|
|
|
|
2007-08-09 01:41:30 +00:00
|
|
|
os << " <start" << m_Start0 << "/>";
|
|
|
|
os << " <end" << m_End0 << "/>";
|
|
|
|
|
|
|
|
os << " </" << GetClass().Lower().mb_str() << ">\n";
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-06 20:26:59 +00:00
|
|
|
#endif
|