kicad/eeschema/class_schematic_items.cpp

518 lines
12 KiB
C++
Raw Normal View History

/***********************************************************************/
/* Methodes de base de gestion des classes des elements de schematique */
/***********************************************************************/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "program.h"
#include "libcmp.h"
#include "general.h"
#include "id.h"
#include "protos.h"
2008-04-15 19:38:19 +00:00
/****************************/
/* class DrawBusEntryStruct */
/***************************/
/*******************************************************************/
2007-08-23 04:28:46 +00:00
DrawBusEntryStruct::DrawBusEntryStruct( const wxPoint& pos, int shape, int id ) :
SCH_ITEM( NULL, DRAW_BUSENTRY_STRUCT_TYPE )
/*******************************************************************/
{
2007-08-23 04:28:46 +00:00
m_Pos = pos;
m_Size.x = 100;
m_Size.y = 100;
m_Layer = LAYER_WIRE;
m_Width = 0;
if( id == BUS_TO_BUS )
{
m_Layer = LAYER_BUS;
m_Width = 1;
}
if( shape == '/' )
m_Size.y = -100;
}
/*************************************/
2008-04-15 19:38:19 +00:00
wxPoint DrawBusEntryStruct::m_End() const
/*************************************/
2007-08-23 04:28:46 +00:00
// retourne la coord de fin du raccord
{
2007-08-23 04:28:46 +00:00
return wxPoint( m_Pos.x + m_Size.x, m_Pos.y + m_Size.y );
}
2007-08-23 04:28:46 +00:00
/***************************************************/
2007-09-01 12:00:30 +00:00
DrawBusEntryStruct* DrawBusEntryStruct::GenCopy()
/***************************************************/
{
2007-08-23 04:28:46 +00:00
DrawBusEntryStruct* newitem = new DrawBusEntryStruct( m_Pos, 0, 0 );
2007-08-23 04:28:46 +00:00
newitem->m_Layer = m_Layer;
newitem->m_Width = m_Width;
newitem->m_Size = m_Size;
newitem->m_Flags = m_Flags;
2007-08-23 04:28:46 +00:00
return newitem;
}
2008-04-15 19:38:19 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool DrawBusEntryStruct::Save( FILE* aFile ) const
{
bool success = true;
const char* layer = "Wire";
const char* width = "Line";
if( GetLayer() == LAYER_BUS )
{
layer = "Bus"; width = "Bus";
}
if( fprintf( aFile, "Entry %s %s\n", layer, width ) == EOF )
{
success = false;
}
if( fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n",
m_Pos.x, m_Pos.y,
m_End().x, m_End().y ) == EOF )
{
success = false;
}
return success;
}
2007-08-23 04:28:46 +00:00
/****************************/
/* class DrawJunctionStruct */
/***************************/
/************************************************************/
2007-08-23 04:28:46 +00:00
DrawJunctionStruct::DrawJunctionStruct( const wxPoint& pos ) :
SCH_ITEM( NULL, DRAW_JUNCTION_STRUCT_TYPE )
/************************************************************/
{
2007-08-23 04:28:46 +00:00
m_Pos = pos;
m_Layer = LAYER_JUNCTION;
}
2007-08-23 04:28:46 +00:00
2007-09-01 12:00:30 +00:00
DrawJunctionStruct* DrawJunctionStruct::GenCopy()
{
2007-08-23 04:28:46 +00:00
DrawJunctionStruct* newitem = new DrawJunctionStruct( m_Pos );
2007-08-23 04:28:46 +00:00
newitem->m_Layer = m_Layer;
newitem->m_Flags = m_Flags;
2007-08-23 04:28:46 +00:00
return newitem;
}
2008-04-15 19:38:19 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool DrawJunctionStruct::Save( FILE* aFile ) const
{
bool success = true;
if( fprintf( aFile, "Connection ~ %-4d %-4d\n", m_Pos.x, m_Pos.y ) == EOF )
{
success = false;
}
return success;
}
EDA_Rect DrawJunctionStruct::GetBoundingBox()
{
int width = DRAWJUNCTION_SIZE * 2;
int xmin = m_Pos.x - DRAWJUNCTION_SIZE;
int ymin = m_Pos.y - DRAWJUNCTION_SIZE;
EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( width, width ) );
return ret;
};
2008-04-22 16:38:23 +00:00
#if defined(DEBUG)
void DrawJunctionStruct::Show( int nestLevel, std::ostream& os )
{
// XML output:
wxString s = GetClass();
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
<< m_Pos
<< "/>\n";
}
#endif
2007-08-23 04:28:46 +00:00
/*****************************/
/* class DrawNoConnectStruct */
/*****************************/
2007-08-23 04:28:46 +00:00
DrawNoConnectStruct::DrawNoConnectStruct( const wxPoint& pos ) :
SCH_ITEM( NULL, DRAW_NOCONNECT_STRUCT_TYPE )
{
2007-08-23 04:28:46 +00:00
m_Pos = pos;
}
2007-08-23 04:28:46 +00:00
2007-09-01 12:00:30 +00:00
DrawNoConnectStruct* DrawNoConnectStruct::GenCopy()
{
2007-08-23 04:28:46 +00:00
DrawNoConnectStruct* newitem = new DrawNoConnectStruct( m_Pos );
2007-08-23 04:28:46 +00:00
newitem->m_Flags = m_Flags;
2007-08-23 04:28:46 +00:00
return newitem;
}
2008-04-15 19:38:19 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool DrawNoConnectStruct::Save( FILE* aFile ) const
{
bool success = true;
if( fprintf( aFile, "NoConn ~ %-4d %-4d\n", m_Pos.x, m_Pos.y ) == EOF )
{
success = false;
}
return success;
}
2007-08-23 04:28:46 +00:00
/**************************/
/* class DrawMarkerStruct */
/**************************/
2007-08-23 04:28:46 +00:00
DrawMarkerStruct::DrawMarkerStruct( const wxPoint& pos, const wxString& text ) :
SCH_ITEM( NULL, DRAW_MARKER_STRUCT_TYPE )
{
2007-08-23 04:28:46 +00:00
m_Pos = pos; /* XY coordinates of marker. */
m_Type = MARQ_UNSPEC;
m_MarkFlags = 0; // complements d'information
m_Comment = text;
}
2007-08-23 04:28:46 +00:00
2007-09-01 12:00:30 +00:00
DrawMarkerStruct::~DrawMarkerStruct()
{
}
2007-08-23 04:28:46 +00:00
2007-09-01 12:00:30 +00:00
DrawMarkerStruct* DrawMarkerStruct::GenCopy()
{
2007-08-23 04:28:46 +00:00
DrawMarkerStruct* newitem = new DrawMarkerStruct( m_Pos, m_Comment );
newitem->m_Type = m_Type;
newitem->m_MarkFlags = m_MarkFlags;
2007-08-23 04:28:46 +00:00
return newitem;
}
2007-09-01 12:00:30 +00:00
wxString DrawMarkerStruct::GetComment()
{
2007-08-23 04:28:46 +00:00
return m_Comment;
}
2008-04-15 19:38:19 +00:00
#if defined (DEBUG)
2007-09-20 21:06:49 +00:00
/**
* Function Show
* is used to output the object tree, currently for debugging only.
2008-03-13 05:04:59 +00:00
* @param nestLevel An aid to prettier tree indenting, and is the level
2007-09-20 21:06:49 +00:00
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void DrawMarkerStruct::Show( int nestLevel, std::ostream& os )
{
// for now, make it look like XML:
2008-04-15 19:38:19 +00:00
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() << m_Pos
<< "/>\n";
2007-09-20 21:06:49 +00:00
}
#endif
2008-04-15 19:38:19 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool DrawMarkerStruct::Save( FILE* aFile ) const
{
bool success = true;
if( fprintf( aFile, "Kmarq %c %-4d %-4d \"%s\" F=%X\n",
2008-04-22 17:19:28 +00:00
int( m_Type ) + 'A',
2008-04-15 19:38:19 +00:00
m_Pos.x, m_Pos.y,
CONV_TO_UTF8( m_Comment ), m_MarkFlags ) == EOF )
{
success = false;
}
return success;
}
2007-09-20 21:06:49 +00:00
2007-08-23 04:28:46 +00:00
/***************************/
/* Class EDA_DrawLineStruct */
/***************************/
2007-08-23 04:28:46 +00:00
EDA_DrawLineStruct::EDA_DrawLineStruct( const wxPoint& pos, int layer ) :
SCH_ITEM( NULL, DRAW_SEGMENT_STRUCT_TYPE )
{
2007-08-23 04:28:46 +00:00
m_Start = pos;
m_End = pos;
m_StartIsDangling = m_EndIsDangling = FALSE;
switch( layer )
{
default:
m_Layer = LAYER_NOTES; /* Mettre ds Notes */
m_Width = GR_NORM_WIDTH;
break;
case LAYER_WIRE:
m_Layer = LAYER_WIRE;
m_Width = GR_NORM_WIDTH;
break;
case LAYER_BUS:
m_Layer = LAYER_BUS;
m_Width = GR_THICK_WIDTH;
break;
}
}
2007-08-23 04:28:46 +00:00
/***************************************************/
2007-09-01 12:00:30 +00:00
EDA_DrawLineStruct* EDA_DrawLineStruct::GenCopy()
/***************************************************/
{
2007-08-23 04:28:46 +00:00
EDA_DrawLineStruct* newitem = new EDA_DrawLineStruct( m_Start, m_Layer );
2007-08-23 04:28:46 +00:00
newitem->m_End = m_End;
2007-08-23 04:28:46 +00:00
return newitem;
}
2007-08-23 04:28:46 +00:00
/************************************************************/
2007-08-23 04:28:46 +00:00
bool EDA_DrawLineStruct::IsOneEndPointAt( const wxPoint& pos )
/************************************************************/
2007-08-23 04:28:46 +00:00
/* Return TRUE if the start or the end point is in position pos
2007-08-23 04:28:46 +00:00
*/
{
2007-08-23 04:28:46 +00:00
if( (pos.x == m_Start.x) && (pos.y == m_Start.y) )
return TRUE;
if( (pos.x == m_End.x) && (pos.y == m_End.y) )
return TRUE;
return FALSE;
}
2007-08-23 04:28:46 +00:00
2008-04-15 19:38:19 +00:00
#if defined (DEBUG)
2007-09-20 21:06:49 +00:00
/**
* Function Show
* is used to output the object tree, currently for debugging only.
2008-03-13 05:04:59 +00:00
* @param nestLevel An aid to prettier tree indenting, and is the level
2007-09-20 21:06:49 +00:00
* of nesting of this object within the overall tree.
* @param os The ostream& to output to.
*/
void EDA_DrawLineStruct::Show( int nestLevel, std::ostream& os )
{
2008-03-13 05:04:59 +00:00
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str() <<
2008-04-15 19:38:19 +00:00
" layer=\"" << m_Layer << '"' <<
" width=\"" << m_Width << '"' <<
" startIsDangling=\"" << m_StartIsDangling << '"' <<
" endIsDangling=\"" << m_EndIsDangling << '"' << ">" <<
" <start" << m_Start << "/>" <<
" <end" << m_End << "/>" <<
"</" << GetClass().Lower().mb_str() << ">\n";
2007-09-20 21:06:49 +00:00
}
2008-04-15 19:38:19 +00:00
#endif
2008-03-13 05:04:59 +00:00
2008-03-15 04:18:32 +00:00
EDA_Rect EDA_DrawLineStruct::GetBoundingBox()
2008-03-13 05:04:59 +00:00
{
2008-04-15 19:38:19 +00:00
int width = 25;
2008-03-13 05:04:59 +00:00
2008-04-15 19:38:19 +00:00
int xmin = MIN( m_Start.x, m_End.x ) - width;
int ymin = MIN( m_Start.y, m_End.y ) - width;
2008-03-13 05:04:59 +00:00
2008-04-15 19:38:19 +00:00
int xmax = MAX( m_Start.x, m_End.x ) + width;
int ymax = MAX( m_Start.y, m_End.y ) + width;
2008-03-13 05:04:59 +00:00
// return a rectangle which is [pos,dim) in nature. therefore the +1
2008-04-15 19:38:19 +00:00
EDA_Rect ret( wxPoint( xmin, ymin ), wxSize( xmax - xmin + 1, ymax - ymin + 1 ) );
2008-03-13 05:04:59 +00:00
return ret;
}
2008-03-15 04:18:32 +00:00
2008-04-15 19:38:19 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool EDA_DrawLineStruct::Save( FILE* aFile ) const
2008-03-15 04:18:32 +00:00
{
2008-04-15 19:38:19 +00:00
bool success = true;
const char* layer = "Notes";
const char* width = "Line";
if( GetLayer() == LAYER_WIRE )
layer = "Wire";
if( GetLayer() == LAYER_BUS )
layer = "Bus";
if( m_Width != GR_NORM_WIDTH )
layer = "Bus";
if( fprintf( aFile, "Wire %s %s\n", layer, width ) == EOF )
2008-03-15 04:18:32 +00:00
{
2008-04-15 19:38:19 +00:00
success = false;
}
if (fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n",
m_Start.x,m_Start.y,
m_End.x,m_End.y) == EOF)
{
success = false;
2008-03-15 04:18:32 +00:00
}
2008-03-13 05:04:59 +00:00
2008-04-15 19:38:19 +00:00
return success;
2008-03-15 04:18:32 +00:00
}
2008-03-13 05:04:59 +00:00
2008-04-15 19:38:19 +00:00
2007-08-23 04:28:46 +00:00
/****************************/
/* Class DrawPolylineStruct */
/****************************/
/***********************************************************/
2007-08-23 04:28:46 +00:00
DrawPolylineStruct::DrawPolylineStruct( int layer ) :
SCH_ITEM( NULL, DRAW_POLYLINE_STRUCT_TYPE )
/***********************************************************/
{
2007-08-23 04:28:46 +00:00
m_NumOfPoints = 0; /* Number of XY pairs in Points array. */
m_Points = NULL; /* XY pairs that forms the polyline. */
m_Width = GR_NORM_WIDTH;
switch( layer )
{
default:
m_Layer = LAYER_NOTES;
break;
case LAYER_WIRE:
case LAYER_NOTES:
m_Layer = layer;
break;
case LAYER_BUS:
m_Layer = layer;
m_Width = GR_THICK_WIDTH;
break;
}
}
/********************************************/
2007-09-01 12:00:30 +00:00
DrawPolylineStruct::~DrawPolylineStruct()
/*********************************************/
{
2007-08-23 04:28:46 +00:00
if( m_Points )
free( m_Points );
}
2007-08-23 04:28:46 +00:00
/*****************************************************/
2007-09-01 12:00:30 +00:00
DrawPolylineStruct* DrawPolylineStruct::GenCopy()
/*****************************************************/
{
2007-08-23 04:28:46 +00:00
int memsize;
2007-08-23 04:28:46 +00:00
DrawPolylineStruct* newitem =
new DrawPolylineStruct( m_Layer );
2007-08-23 04:28:46 +00:00
memsize = sizeof(int) * 2 * m_NumOfPoints;
newitem->m_NumOfPoints = m_NumOfPoints;
newitem->m_Points = (int*) MyZMalloc( memsize );
memcpy( newitem->m_Points, m_Points, memsize );
2007-08-23 04:28:46 +00:00
return newitem;
}
2008-04-15 19:38:19 +00:00
/**
* Function Save
* writes the data structures for this object out to a FILE in "*.brd" format.
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool DrawPolylineStruct::Save( FILE* aFile ) const
{
bool success = true;
const char* layer = "Notes";
const char* width = "Line";
if( GetLayer() == LAYER_WIRE )
layer = "Wire";
if( GetLayer() == LAYER_BUS )
layer = "Bus";
if( m_Width != GR_NORM_WIDTH )
width = "Bus";
if( fprintf( aFile, "Poly %s %s %d\n",
width, layer, m_NumOfPoints ) == EOF )
{
success = false;
return success;
}
for( int ii = 0; ii < m_NumOfPoints; ii++ )
{
if( fprintf( aFile, "\t%-4d %-4d\n",
m_Points[ii * 2],
m_Points[ii * 2 + 1] ) == EOF )
{
success = false;
break;
}
}
return success;
}