2007-06-05 12:10:51 +00:00
|
|
|
/**********************************************************/
|
|
|
|
/* libclass.cpp */
|
|
|
|
/**********************************************************/
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "libcmp.h"
|
|
|
|
#include "general.h"
|
|
|
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/*******************************************************/
|
|
|
|
/* Methodes relatives a la manipulation des librairies */
|
|
|
|
/*******************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/***************************************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
LibraryStruct::LibraryStruct( int type, const wxString& name, const wxString& fullname )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Type = type; /* type indicator */
|
|
|
|
m_Name = name; /* Name of library loaded. */
|
|
|
|
m_FullFileName = fullname; /* Full File Name (with path) of library loaded. */
|
|
|
|
m_NumOfParts = 0; /* Number of parts this library has. */
|
|
|
|
m_Entries = NULL; /* Parts themselves are saved here. */
|
|
|
|
m_Pnext = NULL; /* Point on next lib in chain. */
|
|
|
|
m_Modified = FALSE; /* flag indicateur d'edition */
|
|
|
|
m_TimeStamp = 0;
|
|
|
|
m_Flags = 0;
|
|
|
|
m_IsLibCache = FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
void FreeLibraryEntry( LibCmpEntry* Entry )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Used by PQFreeFunc() to delete all entries
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2008-02-12 21:12:46 +00:00
|
|
|
SAFE_DELETE( Entry );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************/
|
|
|
|
LibraryStruct::~LibraryStruct()
|
|
|
|
/******************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
if( m_Entries )
|
|
|
|
PQFreeFunc( m_Entries, ( void( * ) ( void* ) )FreeLibraryEntry );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
bool LibraryStruct::WriteHeader( FILE* file )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*******************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Ecrit l'entete du fichier librairie
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
char BufLine[1024];
|
|
|
|
bool succes = TRUE;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
DateAndTime( BufLine );
|
|
|
|
if( fprintf( file, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
|
|
|
|
LIB_VERSION_MAJOR, LIB_VERSION_MINOR,
|
|
|
|
BufLine ) != 5 )
|
|
|
|
succes = FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
#if 0
|
2007-08-24 15:10:46 +00:00
|
|
|
if( fprintf( file, "$HEADER\n" ) != 1 )
|
|
|
|
succes = FALSE;
|
|
|
|
if( fprintf( file, "TimeStamp %8.8lX\n", m_TimeStamp ) != 2 )
|
|
|
|
succes = FALSE;
|
|
|
|
if( fprintf( file, "Parts %d\n", m_NumOfParts ) != 2 )
|
|
|
|
succes = FALSE;
|
|
|
|
if( fprintf( file, "$ENDHEADER\n" ) != 1 )
|
|
|
|
succes = FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
#endif
|
2007-08-24 15:10:46 +00:00
|
|
|
return succes;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
bool LibraryStruct::ReadHeader( FILE* libfile, int* LineNum )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***********************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Ecrit l'entete du fichier librairie
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
char Line[1024], * text, * data;
|
|
|
|
|
|
|
|
while( GetLine( libfile, Line, LineNum, sizeof(Line) ) )
|
|
|
|
{
|
|
|
|
text = strtok( Line, " \t\r\n" );
|
|
|
|
data = strtok( NULL, " \t\r\n" );
|
|
|
|
if( stricmp( text, "TimeStamp" ) == 0 )
|
|
|
|
m_TimeStamp = atol( data );
|
|
|
|
if( stricmp( text, "$ENDHEADER" ) == 0 )
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
return FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/*********************/
|
|
|
|
/* class LibCmpEntry */
|
|
|
|
/*********************/
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Basic class for librarty oomponent description
|
2007-08-24 15:10:46 +00:00
|
|
|
* Not directly used
|
|
|
|
* Used to create the 2 derived classes :
|
|
|
|
* - EDA_LibCmpAliasStruct
|
|
|
|
* - EDA_LibComponentStruct
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/********************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
LibCmpEntry::LibCmpEntry( LibrEntryType CmpType, const wxChar* CmpName ) :
|
|
|
|
EDA_BaseStruct( LIBCOMPONENT_STRUCT_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
Type = CmpType;
|
|
|
|
m_Name.m_FieldId = VALUE;
|
|
|
|
if( CmpName )
|
|
|
|
m_Name.m_Text = CmpName;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibCmpEntry::~LibCmpEntry()
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************/
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/*******************************/
|
|
|
|
/* class EDA_LibCmpAliasStruct */
|
|
|
|
/*******************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* Class to define an alias of a component
|
2007-08-24 15:10:46 +00:00
|
|
|
* An alias uses the component defintion (graphic, pins...)
|
|
|
|
* but has its own name and documentation.
|
|
|
|
* Therefore, when the component is modified, alias of this component are modified.
|
|
|
|
* This is a simple method to create components with differs very few
|
|
|
|
* (like 74LS00, 74HC00 ... and many op amps )
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
EDA_LibCmpAliasStruct:: EDA_LibCmpAliasStruct( const wxChar* CmpName,
|
|
|
|
const wxChar* CmpRootName ) :
|
|
|
|
LibCmpEntry( ALIAS, CmpName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
if( CmpRootName == NULL )
|
|
|
|
m_RootName.Empty();
|
|
|
|
else
|
|
|
|
m_RootName = CmpRootName;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
EDA_LibCmpAliasStruct::~EDA_LibCmpAliasStruct()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/********************************/
|
|
|
|
/* class EDA_LibComponentStruct */
|
|
|
|
/********************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
/* This is a standard component (in library)
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
|
|
|
EDA_LibComponentStruct:: EDA_LibComponentStruct( const wxChar* CmpName ) :
|
|
|
|
LibCmpEntry( ROOT, CmpName )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Drawings = NULL;
|
|
|
|
m_LastDate = 0;
|
|
|
|
m_UnitCount = 1;
|
|
|
|
m_TextInside = 40;
|
|
|
|
m_Options = ENTRY_NORMAL;
|
|
|
|
m_UnitSelectionLocked = FALSE;
|
|
|
|
m_DrawPinNum = m_DrawPinName = 1;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
Fields = NULL;
|
|
|
|
m_Prefix.m_FieldId = REFERENCE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
EDA_LibComponentStruct::~EDA_LibComponentStruct()
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibEDA_BaseStruct* DrawItem, * NextDrawItem;
|
|
|
|
LibDrawField* TempField, * field;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
field = Fields; Fields = NULL;
|
|
|
|
while( field )
|
|
|
|
{
|
|
|
|
TempField = field; field = (LibDrawField*) field->Pnext;
|
2008-02-12 21:12:46 +00:00
|
|
|
SAFE_DELETE( TempField );
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/* suppression des elements dependants */
|
|
|
|
DrawItem = m_Drawings; m_Drawings = NULL;
|
|
|
|
while( DrawItem )
|
|
|
|
{
|
|
|
|
NextDrawItem = DrawItem->Next();
|
2008-02-12 21:12:46 +00:00
|
|
|
SAFE_DELETE( DrawItem );
|
2007-08-24 15:10:46 +00:00
|
|
|
DrawItem = NextDrawItem;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert )
|
2007-06-05 12:10:51 +00:00
|
|
|
/**********************************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Return the componenty boundary box ( in user coordinates )
|
2007-08-24 15:10:46 +00:00
|
|
|
* The unit Unit, and the shape Convert are considered.
|
|
|
|
* If Unit == 0, Unit is not used
|
|
|
|
* if Convert == 0 Convert is non used
|
|
|
|
**/
|
|
|
|
{
|
|
|
|
int xmin, xmax, ymin, ymax, x1, y1;
|
|
|
|
int* pt, ii;
|
|
|
|
LibEDA_BaseStruct* DrawEntry;
|
|
|
|
EDA_Rect BoundaryBox;
|
|
|
|
|
|
|
|
DrawEntry = m_Drawings;
|
|
|
|
if( DrawEntry )
|
|
|
|
{
|
|
|
|
xmin = ymin = 0x7FFFFFFF;
|
|
|
|
xmax = ymax = 0x80000000;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xmin = ymin = -50;
|
|
|
|
xmax = ymax = 50; // Min size in 1/1000 inch
|
|
|
|
}
|
|
|
|
|
|
|
|
for( ; DrawEntry != NULL; DrawEntry = DrawEntry->Next() )
|
|
|
|
{
|
|
|
|
if( DrawEntry->m_Unit > 0 ) // The item is non common to units
|
|
|
|
if( (m_UnitCount > 1 ) && (Unit > 0) && (Unit != DrawEntry->m_Unit) )
|
|
|
|
continue;
|
|
|
|
if( DrawEntry->m_Convert > 0 ) //The item is not common to alls convert
|
|
|
|
if( (Convert > 0) && (Convert != DrawEntry->m_Convert) )
|
|
|
|
continue;
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
switch( DrawEntry->Type() )
|
2007-08-24 15:10:46 +00:00
|
|
|
{
|
|
|
|
case COMPONENT_ARC_DRAW_TYPE:
|
|
|
|
{
|
|
|
|
// Arc is reduced to a line from m_Start to m_End.
|
|
|
|
// TO DO better.
|
|
|
|
LibDrawArc* Arc = (LibDrawArc*) DrawEntry;
|
|
|
|
x1 = Arc->m_ArcStart.x;
|
|
|
|
y1 = Arc->m_ArcStart.y;
|
|
|
|
xmin = MIN( xmin, x1 );
|
|
|
|
ymin = MIN( ymin, y1 );
|
|
|
|
xmax = MAX( xmax, x1 );
|
|
|
|
ymax = MAX( ymax, y1 );
|
|
|
|
x1 = Arc->m_ArcEnd.x;
|
|
|
|
y1 = Arc->m_ArcEnd.y;
|
|
|
|
xmin = MIN( xmin, x1 );
|
|
|
|
ymin = MIN( ymin, y1 );
|
|
|
|
xmax = MAX( xmax, x1 );
|
|
|
|
ymax = MAX( ymax, y1 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_CIRCLE_DRAW_TYPE:
|
|
|
|
{
|
|
|
|
LibDrawCircle* Circle = (LibDrawCircle*) DrawEntry;
|
|
|
|
x1 = Circle->m_Pos.x - Circle->m_Rayon;
|
|
|
|
y1 = Circle->m_Pos.y - Circle->m_Rayon;
|
|
|
|
xmin = MIN( xmin, x1 );
|
|
|
|
ymin = MIN( ymin, y1 );
|
|
|
|
x1 = Circle->m_Pos.x + Circle->m_Rayon;
|
|
|
|
y1 = Circle->m_Pos.y + Circle->m_Rayon;
|
|
|
|
xmax = MAX( xmax, x1 );
|
|
|
|
ymax = MAX( ymax, y1 );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_RECT_DRAW_TYPE:
|
|
|
|
{
|
|
|
|
LibDrawSquare* Square = (LibDrawSquare*) DrawEntry;
|
|
|
|
xmin = MIN( xmin, Square->m_Pos.x );
|
|
|
|
xmin = MIN( xmin, Square->m_End.x );
|
|
|
|
xmax = MAX( xmax, Square->m_Pos.x );
|
|
|
|
xmax = MAX( xmax, Square->m_End.x );
|
|
|
|
ymin = MIN( ymin, Square->m_Pos.y );
|
|
|
|
ymin = MIN( ymin, Square->m_End.y );
|
|
|
|
ymax = MAX( ymax, Square->m_Pos.y );
|
|
|
|
ymax = MAX( ymax, Square->m_End.y );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_PIN_DRAW_TYPE:
|
|
|
|
{
|
|
|
|
LibDrawPin* Pin = (LibDrawPin*) DrawEntry;
|
|
|
|
x1 = Pin->m_Pos.x;
|
|
|
|
y1 = Pin->m_Pos.y;
|
|
|
|
xmin = MIN( xmin, x1 );
|
|
|
|
xmax = MAX( xmax, x1 );
|
|
|
|
ymin = MIN( ymin, y1 );
|
|
|
|
ymax = MAX( ymax, y1 );
|
|
|
|
#if 0 \
|
|
|
|
// 0 pour englober le point origine de la pin, 1 pour englober toute la pin
|
|
|
|
switch( Pin->Orient )
|
|
|
|
{
|
|
|
|
case PIN_UP:
|
|
|
|
y1 += Pin->Len; break;
|
|
|
|
|
|
|
|
case PIN_DOWN:
|
|
|
|
y1 -= Pin->Len; break;
|
|
|
|
|
|
|
|
case PIN_LEFT:
|
|
|
|
x1 -= Pin->Len; break;
|
|
|
|
|
|
|
|
case PIN_RIGHT:
|
|
|
|
x1 += Pin->Len; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
xmin = MIN( xmin, x1 );
|
|
|
|
xmax = MAX( xmax, x1 );
|
|
|
|
ymin = MIN( ymin, y1 );
|
|
|
|
ymax = MAX( ymax, y1 );
|
2007-06-05 12:10:51 +00:00
|
|
|
#endif
|
2007-08-24 15:10:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMPONENT_POLYLINE_DRAW_TYPE:
|
|
|
|
{
|
|
|
|
LibDrawPolyline* polyline = (LibDrawPolyline*) DrawEntry;
|
|
|
|
pt = polyline->PolyList;
|
|
|
|
for( ii = 0; ii < polyline->n; ii++ )
|
|
|
|
{
|
|
|
|
if( xmin > *pt )
|
|
|
|
xmin = *pt;
|
|
|
|
if( xmax < *pt )
|
|
|
|
xmax = *pt;
|
|
|
|
pt++;
|
|
|
|
if( ymin > *pt )
|
|
|
|
ymin = *pt;
|
|
|
|
if( ymax < *pt )
|
|
|
|
ymax = *pt;
|
|
|
|
pt++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the BoundaryBox. Remenber the fact the screen Y axis is the reverse */
|
|
|
|
ymax = -ymax; ymin = -ymin; // Y is is screen axis sense
|
|
|
|
// Ensure w and H > 0 (wxRect assume it)
|
|
|
|
if( xmax < xmin )
|
|
|
|
EXCHG( xmax, xmin );
|
|
|
|
if( ymax < ymin )
|
|
|
|
EXCHG( ymax, ymin );
|
|
|
|
BoundaryBox.SetX( xmin ); BoundaryBox.SetWidth( xmax - xmin );
|
|
|
|
BoundaryBox.SetY( ymin ); BoundaryBox.SetHeight( ymax - ymin );
|
|
|
|
|
|
|
|
return BoundaryBox;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***************************/
|
|
|
|
/* class LibraryFieldEntry */
|
|
|
|
/***************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
/* a Field is a string linked to a component.
|
|
|
|
* Unlike a pure graphic text, fields can be used in netlist generation
|
|
|
|
* and other things.
|
|
|
|
*
|
|
|
|
* 4 fields have a special meaning:
|
|
|
|
* REFERENCE
|
|
|
|
* VALUE
|
|
|
|
* FOOTPRINT NAME
|
|
|
|
* SCHEMATIC LINK (reserved but not used in kicad)
|
|
|
|
*/
|
|
|
|
LibDrawField::LibDrawField( int idfield ) : LibEDA_BaseStruct( COMPONENT_FIELD_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_FieldId = idfield; /* 0 a 11, 0 = REFERENCE, 1 = VALUE*/
|
|
|
|
if( m_FieldId < 0 )
|
|
|
|
m_FieldId = 0;
|
|
|
|
if( m_FieldId >= NUMBER_OF_FIELDS )
|
|
|
|
m_FieldId = NUMBER_OF_FIELDS - 1;
|
|
|
|
m_Size.x = m_Size.y = DEFAULT_SIZE_TEXT;
|
|
|
|
m_Orient = 0; /* Orientation */
|
|
|
|
m_Attributs = 0; /* Attributs = unvisible ... */
|
|
|
|
m_Width = 0;
|
|
|
|
m_HJustify = GR_TEXT_HJUSTIFY_CENTER;
|
|
|
|
m_VJustify = GR_TEXT_VJUSTIFY_CENTER; /* Horizontal and vertical text justification */
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawField::~LibDrawField()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
// Creation et Duplication d'un field
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawField* LibDrawField::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawField* newfield = new LibDrawField( m_FieldId );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
Copy( newfield );
|
|
|
|
|
|
|
|
return newfield;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
// copie du field dans le field Target
|
|
|
|
void LibDrawField::Copy( LibDrawField* Target )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
Target->m_Pos = m_Pos;
|
|
|
|
Target->m_Size = m_Size;
|
|
|
|
Target->m_Width = m_Width;
|
|
|
|
Target->m_Orient = m_Orient;
|
|
|
|
Target->m_Attributs = m_Attributs;
|
|
|
|
Target->m_Text = m_Text;
|
|
|
|
Target->m_Name = m_Name;
|
|
|
|
Target->m_HJustify = m_HJustify;
|
|
|
|
Target->m_VJustify = m_VJustify;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Elements Graphiques */
|
2007-08-24 15:10:46 +00:00
|
|
|
LibEDA_BaseStruct::LibEDA_BaseStruct( KICAD_T struct_type ) :
|
|
|
|
EDA_BaseStruct( struct_type )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Unit = 0; /* Unit identification (for multi part per package)
|
|
|
|
* 0 if the item is common to all units */
|
|
|
|
m_Convert = 0; /* Shape identification (for parts which have a convert shape)
|
|
|
|
* 0 if the item is common to all shapes */
|
|
|
|
m_Width = 0; /* Default value to draw lines or arc ... */
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawPin::LibDrawPin() : LibEDA_BaseStruct( COMPONENT_PIN_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_PinLen = 300; /* default Pin len */
|
|
|
|
m_Orient = PIN_RIGHT; /* Pin oprient: Up, Down, Left, Right */
|
|
|
|
m_PinShape = NONE; /* Bit a bit: Pin shape (voir enum prec) */
|
|
|
|
m_PinType = PIN_UNSPECIFIED; /* electrical type of pin */
|
|
|
|
m_Attributs = 0; /* bit 0 != 0: pin invisible */
|
|
|
|
m_PinNum = 0; /*pin number ( i.e. 4 codes Ascii ) */
|
|
|
|
m_PinNumSize = 50;
|
|
|
|
m_PinNameSize = 50; /* Default size for pin name and num */
|
|
|
|
m_Width = 0;
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
// m_PinNumWidth = m_PinNameWidth = 0; // Unused
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
wxPoint LibDrawPin::ReturnPinEndPoint()
|
2007-06-05 12:10:51 +00:00
|
|
|
/******************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* return the pin end position, for a component in normal orient
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
wxPoint pos = m_Pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
switch( m_Orient )
|
|
|
|
{
|
|
|
|
case PIN_UP:
|
|
|
|
pos.y += m_PinLen; break;
|
|
|
|
|
|
|
|
case PIN_DOWN:
|
|
|
|
pos.y -= m_PinLen; break;
|
|
|
|
|
|
|
|
case PIN_LEFT:
|
|
|
|
pos.x -= m_PinLen; break;
|
|
|
|
|
|
|
|
case PIN_RIGHT:
|
|
|
|
pos.x += m_PinLen; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pos;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
int LibDrawPin::ReturnPinDrawOrient( int TransMat[2][2] )
|
2007-06-05 12:10:51 +00:00
|
|
|
/********************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* Return the pin real orientation (PIN_UP, PIN_DOWN, PIN_RIGHT, PIN_LEFT),
|
2007-08-24 15:10:46 +00:00
|
|
|
* according to its orientation,
|
|
|
|
* AND the matrix transform (rot, mirror) TransMat
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
int orient;
|
|
|
|
int x1 = 0, y1 = 0;
|
|
|
|
int t1, t2;
|
|
|
|
|
|
|
|
switch( m_Orient )
|
|
|
|
{
|
|
|
|
case PIN_UP:
|
|
|
|
y1 = 1; break;
|
|
|
|
|
|
|
|
case PIN_DOWN:
|
|
|
|
y1 = -1; break;
|
|
|
|
|
|
|
|
case PIN_LEFT:
|
|
|
|
x1 = -1; break;
|
|
|
|
|
|
|
|
case PIN_RIGHT:
|
|
|
|
x1 = 1; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
t1 = TransMat[0][0] * x1 + TransMat[0][1] * y1;
|
|
|
|
t2 = TransMat[1][0] * x1 + TransMat[1][1] * y1;
|
|
|
|
orient = PIN_UP;
|
|
|
|
if( t1 == 0 )
|
|
|
|
{
|
|
|
|
if( t2 > 0 )
|
|
|
|
orient = PIN_DOWN;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
orient = PIN_RIGHT;
|
|
|
|
if( t1 < 0 )
|
|
|
|
orient = PIN_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
return orient;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
void LibDrawPin::ReturnPinStringNum( wxString& buffer )
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* fill the buffer with pin num as a wxString
|
2007-08-24 15:10:46 +00:00
|
|
|
* Pin num is coded as a long
|
|
|
|
* Used to print/draw the pin num
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
char ascii_buf[5];
|
|
|
|
|
|
|
|
strncpy( ascii_buf, (char*) &m_PinNum, 4 );
|
|
|
|
ascii_buf[4] = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
buffer = CONV_FROM_UTF8( ascii_buf );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2007-08-24 15:10:46 +00:00
|
|
|
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
void LibDrawPin::SetPinNumFromString( wxString& buffer )
|
2007-06-05 12:10:51 +00:00
|
|
|
/****************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* fill the buffer with pin num as a wxString
|
2007-08-24 15:10:46 +00:00
|
|
|
* Pin num is coded as a long
|
|
|
|
* Used to print/draw the pin num
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
char ascii_buf[4];
|
|
|
|
unsigned ii, len = buffer.Len();
|
|
|
|
|
|
|
|
ascii_buf[0] = ascii_buf[1] = ascii_buf[2] = ascii_buf[3] = 0;
|
|
|
|
if( len > 4 )
|
|
|
|
len = 4;
|
|
|
|
for( ii = 0; ii < len; ii++ )
|
|
|
|
{
|
|
|
|
ascii_buf[ii] = buffer.GetChar( ii ) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
strncpy( (char*) &m_PinNum, ascii_buf, 4 );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawPin* LibDrawPin::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
/*************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawPin* newpin = new LibDrawPin();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newpin->m_Pos = m_Pos;
|
|
|
|
newpin->m_PinLen = m_PinLen;
|
|
|
|
newpin->m_Orient = m_Orient;
|
|
|
|
newpin->m_PinShape = m_PinShape;
|
|
|
|
newpin->m_PinType = m_PinType;
|
|
|
|
newpin->m_Attributs = m_Attributs;
|
|
|
|
newpin->m_PinNum = m_PinNum;
|
|
|
|
newpin->m_PinNumSize = m_PinNumSize;
|
|
|
|
newpin->m_PinNameSize = m_PinNameSize;
|
|
|
|
newpin->m_Unit = m_Unit;
|
|
|
|
newpin->m_Convert = m_Convert;
|
|
|
|
newpin->m_Flags = m_Flags;
|
|
|
|
newpin->m_Width = m_Width;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newpin->m_PinName = m_PinName;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
return newpin;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/**************************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawArc::LibDrawArc() : LibEDA_BaseStruct( COMPONENT_ARC_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
/**************************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Rayon = 0;
|
|
|
|
t1 = t2 = 0;
|
|
|
|
m_Width = 0;
|
|
|
|
m_Fill = NO_FILL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawArc* LibDrawArc::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawArc* newitem = new LibDrawArc();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_ArcStart = m_ArcStart;
|
|
|
|
newitem->m_ArcEnd = m_ArcEnd;
|
|
|
|
newitem->m_Rayon = m_Rayon;
|
|
|
|
newitem->t1 = t1;
|
|
|
|
newitem->t2 = t2;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawCircle::LibDrawCircle() : LibEDA_BaseStruct( COMPONENT_CIRCLE_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
/**********************************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Rayon = 0;
|
|
|
|
m_Fill = NO_FILL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/*******************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawCircle* LibDrawCircle::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
/*******************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawCircle* newitem = new LibDrawCircle();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_Rayon = m_Rayon;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawText::LibDrawText() : LibEDA_BaseStruct( COMPONENT_GRAPHIC_TEXT_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
/*****************************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Horiz = TEXT_ORIENT_HORIZ;
|
|
|
|
m_Size = wxSize( 50, 50 );
|
|
|
|
m_Type = 0;
|
|
|
|
m_Width = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawText* LibDrawText::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawText* newitem = new LibDrawText();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_Horiz = m_Horiz;
|
|
|
|
newitem->m_Size = m_Size;
|
|
|
|
newitem->m_Type = m_Type;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Text = m_Text;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawSquare::LibDrawSquare() : LibEDA_BaseStruct( COMPONENT_RECT_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Width = 0;
|
|
|
|
m_Fill = NO_FILL;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawSquare* LibDrawSquare::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawSquare* newitem = new LibDrawSquare();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_End = m_End;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawSegment::LibDrawSegment() : LibEDA_BaseStruct( COMPONENT_LINE_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
m_Width = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawSegment* LibDrawSegment::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawSegment* newitem = new LibDrawSegment();
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_End = m_End;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawPolyline::LibDrawPolyline() : LibEDA_BaseStruct( COMPONENT_POLYLINE_DRAW_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
n = 0;
|
|
|
|
PolyList = NULL;
|
|
|
|
m_Fill = NO_FILL;
|
|
|
|
m_Width = 0;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************************/
|
2007-09-01 12:00:30 +00:00
|
|
|
LibDrawPolyline* LibDrawPolyline::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
/************************************************/
|
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
LibDrawPolyline* newitem = new LibDrawPolyline();
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
|
|
|
newitem->n = n;
|
|
|
|
size = sizeof(int) * 2 * n;
|
|
|
|
if( size )
|
|
|
|
{
|
|
|
|
newitem->PolyList = (int*) MyMalloc( size );
|
|
|
|
memcpy( newitem->PolyList, PolyList, size );
|
|
|
|
}
|
|
|
|
newitem->m_Pos = m_Pos;
|
|
|
|
newitem->m_Width = m_Width;
|
|
|
|
newitem->m_Unit = m_Unit;
|
|
|
|
newitem->m_Convert = m_Convert;
|
|
|
|
newitem->m_Flags = m_Flags;
|
|
|
|
newitem->m_Fill = m_Fill;
|
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
void LibDrawPolyline::AddPoint( const wxPoint& point )
|
2007-06-05 12:10:51 +00:00
|
|
|
/***************************************************/
|
2007-08-24 15:10:46 +00:00
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
/* add a point to the polyline coordinate list, and realloc the memory
|
2007-08-24 15:10:46 +00:00
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-24 15:10:46 +00:00
|
|
|
int allocsize;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
n++;
|
|
|
|
allocsize = 2 * sizeof(int) * n;
|
|
|
|
if( PolyList == NULL )
|
|
|
|
PolyList = (int*) MyMalloc( allocsize );
|
|
|
|
else
|
|
|
|
PolyList = (int*) realloc( PolyList, allocsize );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-24 15:10:46 +00:00
|
|
|
PolyList[(n * 2) - 2] = point.x;
|
|
|
|
PolyList[(n * 2) - 1] = -point.y;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|