2009-11-03 13:26:31 +00:00
|
|
|
/*****************************/
|
|
|
|
/* class_schematic_items.cpp */
|
|
|
|
/*****************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "gr_basic.h"
|
2009-04-05 20:49:15 +00:00
|
|
|
#include "class_drawpanel.h"
|
2010-09-05 17:01:48 +00:00
|
|
|
#include "trigo.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "common.h"
|
|
|
|
#include "program.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
/* used to calculate the pen size from default value
|
|
|
|
* the actual pen size is default value * BUS_WIDTH_EXPAND
|
|
|
|
*/
|
2010-02-04 21:24:26 +00:00
|
|
|
#if defined(KICAD_GOST)
|
2010-02-09 19:13:21 +00:00
|
|
|
#define BUS_WIDTH_EXPAND 3.6
|
2010-02-04 21:24:26 +00:00
|
|
|
#else
|
|
|
|
#define BUS_WIDTH_EXPAND 1.4
|
|
|
|
#endif
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/***********************/
|
|
|
|
/* class SCH_BUS_ENTRY */
|
|
|
|
/***********************/
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_BUS_ENTRY::SCH_BUS_ENTRY( const wxPoint& pos, int shape, int id ) :
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM( NULL, DRAW_BUSENTRY_STRUCT_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( shape == '/' )
|
|
|
|
m_Size.y = -100;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
wxPoint SCH_BUS_ENTRY::m_End() const
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
return wxPoint( m_Pos.x + m_Size.x, m_Pos.y + m_Size.y );
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_BUS_ENTRY* SCH_BUS_ENTRY::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_BUS_ENTRY* newitem = new SCH_BUS_ENTRY( m_Pos, 0, 0 );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
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-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
2009-11-03 13:26:31 +00:00
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
2008-04-15 19:38:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_BUS_ENTRY::Save( FILE* aFile ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
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",
|
2009-04-05 20:49:15 +00:00
|
|
|
m_Pos.x, m_Pos.y, m_End().x, m_End().y ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
EDA_Rect SCH_BUS_ENTRY::GetBoundingBox()
|
2009-01-31 18:08:47 +00:00
|
|
|
{
|
2010-03-01 11:25:08 +00:00
|
|
|
EDA_Rect box;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
|
|
|
box.SetOrigin( m_Pos );
|
|
|
|
box.SetEnd( m_End() );
|
2009-01-31 18:08:47 +00:00
|
|
|
|
|
|
|
box.Normalize();
|
2010-09-05 17:01:48 +00:00
|
|
|
int width = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2010-03-01 11:25:08 +00:00
|
|
|
box.Inflate( width / 2 );
|
2009-01-31 18:08:47 +00:00
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_BUS_ENTRY::GetPenSize()
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
int pensize = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-07-01 16:07:18 +00:00
|
|
|
|
|
|
|
if( m_Layer == LAYER_BUS && m_Width == 0 )
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
2009-07-01 16:07:18 +00:00
|
|
|
pensize = wxRound( g_DrawDefaultLineThickness * BUS_WIDTH_EXPAND );
|
|
|
|
pensize = MAX( pensize, 3 );
|
2009-06-30 19:21:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_BUS_ENTRY::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
const wxPoint& offset, int DrawMode, int Color )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int color;
|
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
GRLine( &panel->m_ClipBox, DC, m_Pos.x + offset.x, m_Pos.y + offset.y,
|
2009-07-01 16:07:18 +00:00
|
|
|
m_End().x + offset.x, m_End().y + offset.y, GetPenSize(), color );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_BUS_ENTRY::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Pos.y );
|
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
NEGATE( m_Size.y );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_BUS_ENTRY::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Pos.x );
|
|
|
|
m_Pos.x += aYaxis_position;
|
|
|
|
NEGATE( m_Size.x );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_BUS_ENTRY::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
|
|
|
RotatePoint( &m_Size.x, &m_Size.y, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/**********************/
|
|
|
|
/* class SCH_JUNCTION */
|
|
|
|
/**********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) :
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM( NULL, DRAW_JUNCTION_STRUCT_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
#define DRAWJUNCTION_DIAMETER 32 /* Diameter of junction symbol between wires */
|
|
|
|
m_Pos = pos;
|
|
|
|
m_Layer = LAYER_JUNCTION;
|
2009-11-28 09:24:37 +00:00
|
|
|
m_Size.x = m_Size.y = DRAWJUNCTION_DIAMETER;
|
|
|
|
#undef DRAWJUNCTION_DIAMETER
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_JUNCTION* SCH_JUNCTION::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_JUNCTION* newitem = new SCH_JUNCTION( m_Pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
newitem->m_Size = m_Size;
|
2007-08-23 04:28:46 +00:00
|
|
|
newitem->m_Layer = m_Layer;
|
|
|
|
newitem->m_Flags = m_Flags;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
2009-11-03 13:26:31 +00:00
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
2008-04-15 19:38:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_JUNCTION::Save( FILE* aFile ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if( fprintf( aFile, "Connection ~ %-4d %-4d\n", m_Pos.x, m_Pos.y ) == EOF )
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
EDA_Rect SCH_JUNCTION::GetBoundingBox()
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2009-11-28 09:24:37 +00:00
|
|
|
EDA_Rect rect;
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
rect.SetOrigin( m_Pos );
|
|
|
|
rect.Inflate( ( GetPenSize() + m_Size.x ) / 2 );
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
return rect;
|
2010-10-04 12:58:07 +00:00
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-01-31 18:08:47 +00:00
|
|
|
/** Function HitTest
|
|
|
|
* @return true if the point aPosRef is within item area
|
|
|
|
* @param aPosRef = a wxPoint to test
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_JUNCTION::HitTest( const wxPoint& aPosRef )
|
2009-01-31 18:08:47 +00:00
|
|
|
{
|
|
|
|
wxPoint dist = aPosRef - m_Pos;
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return sqrt( ( (double) ( dist.x * dist.x ) ) +
|
2010-09-05 17:01:48 +00:00
|
|
|
( (double) ( dist.y * dist.y ) ) ) < ( m_Size.x / 2 );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
2009-12-02 21:44:03 +00:00
|
|
|
* has no meaning for SCH_JUNCTION
|
2009-06-30 19:21:41 +00:00
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_JUNCTION::GetPenSize()
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/*****************************************************************************
|
2009-11-03 13:26:31 +00:00
|
|
|
* Routine to redraw connection struct. *
|
2009-04-05 20:49:15 +00:00
|
|
|
*****************************************************************************/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_JUNCTION::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
const wxPoint& offset, int DrawMode, int Color )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int color;
|
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
GRFilledCircle( &panel->m_ClipBox, DC, m_Pos.x + offset.x,
|
2010-09-05 17:01:48 +00:00
|
|
|
m_Pos.y + offset.y, (m_Size.x / 2), 0, color,
|
2009-11-03 13:26:31 +00:00
|
|
|
color );
|
2009-01-31 18:08:47 +00:00
|
|
|
}
|
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_JUNCTION::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Pos.y );
|
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_JUNCTION::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Pos.x );
|
|
|
|
m_Pos.x += aYaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_JUNCTION::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#if defined(DEBUG)
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_JUNCTION::Show( int nestLevel, std::ostream& os )
|
2008-04-22 16:38:23 +00:00
|
|
|
{
|
|
|
|
// XML output:
|
|
|
|
wxString s = GetClass();
|
|
|
|
|
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str()
|
2009-07-01 16:07:18 +00:00
|
|
|
<< m_Pos << "/>\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2008-04-22 16:38:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/************************/
|
|
|
|
/* class SCH_NO_CONNECT */
|
|
|
|
/************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM( NULL, DRAW_NOCONNECT_STRUCT_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-11-28 09:24:37 +00:00
|
|
|
#define DRAWNOCONNECT_SIZE 48 /* No symbol connection range. */
|
2010-09-05 17:01:48 +00:00
|
|
|
m_Pos = pos;
|
2009-11-28 09:24:37 +00:00
|
|
|
m_Size.x = m_Size.y = DRAWNOCONNECT_SIZE;
|
|
|
|
#undef DRAWNOCONNECT_SIZE
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_NO_CONNECT* SCH_NO_CONNECT::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_NO_CONNECT* newitem = new SCH_NO_CONNECT( m_Pos );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
newitem->m_Size = m_Size;
|
2007-08-23 04:28:46 +00:00
|
|
|
newitem->m_Flags = m_Flags;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
EDA_Rect SCH_NO_CONNECT::GetBoundingBox()
|
2009-01-31 18:08:47 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
int delta = ( GetPenSize() + m_Size.x ) / 2;
|
|
|
|
EDA_Rect box;
|
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
box.SetOrigin( m_Pos );
|
2009-12-02 21:44:03 +00:00
|
|
|
box.Inflate( delta );
|
2009-01-31 18:08:47 +00:00
|
|
|
|
|
|
|
return box;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
/**
|
|
|
|
* Function HitTest
|
2009-01-31 18:08:47 +00:00
|
|
|
* @return true if the point aPosRef is within item area
|
|
|
|
* @param aPosRef = a wxPoint to test
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_NO_CONNECT::HitTest( const wxPoint& aPosRef )
|
2009-01-31 18:08:47 +00:00
|
|
|
{
|
2009-07-01 16:07:18 +00:00
|
|
|
int width = g_DrawDefaultLineThickness;
|
2009-12-02 21:44:03 +00:00
|
|
|
int delta = ( m_Size.x + width ) / 2;
|
2009-01-31 18:08:47 +00:00
|
|
|
|
|
|
|
wxPoint dist = aPosRef - m_Pos;
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( ABS( dist.x ) <= delta ) && ( ABS( dist.y ) <= delta ) )
|
2009-01-31 18:08:47 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
/**
|
|
|
|
* Function Save
|
2009-11-03 13:26:31 +00:00
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
2008-04-15 19:38:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_NO_CONNECT::Save( FILE* aFile ) const
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
if( fprintf( aFile, "NoConn ~ %-4d %-4d\n", m_Pos.x, m_Pos.y ) == EOF )
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_NO_CONNECT::GetPenSize()
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
|
|
|
return g_DrawDefaultLineThickness;
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_NO_CONNECT::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
const wxPoint& offset, int DrawMode, int Color )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
2010-09-05 17:01:48 +00:00
|
|
|
int pX, pY, color;
|
|
|
|
int delta = m_Size.x / 2;
|
|
|
|
int width = g_DrawDefaultLineThickness;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
pX = m_Pos.x + offset.x;
|
|
|
|
pY = m_Pos.y + offset.y;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( LAYER_NOCONNECT );
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
2009-11-28 09:24:37 +00:00
|
|
|
GRLine( &panel->m_ClipBox, DC, pX - delta, pY - delta, pX + delta,
|
|
|
|
pY + delta, width, color );
|
|
|
|
GRLine( &panel->m_ClipBox, DC, pX + delta, pY - delta, pX - delta,
|
|
|
|
pY + delta, width, color );
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_NO_CONNECT::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Pos.y );
|
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Pos.x );
|
|
|
|
m_Pos.x += aYaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_NO_CONNECT::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/******************/
|
|
|
|
/* Class SCH_LINE */
|
|
|
|
/******************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE::SCH_LINE( const wxPoint& pos, int layer ) :
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM( NULL, DRAW_SEGMENT_STRUCT_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2007-08-23 04:28:46 +00:00
|
|
|
m_Start = pos;
|
|
|
|
m_End = pos;
|
2009-06-02 07:26:49 +00:00
|
|
|
m_Width = 0; // Default thickness used
|
2007-08-23 04:28:46 +00:00
|
|
|
m_StartIsDangling = m_EndIsDangling = FALSE;
|
|
|
|
|
|
|
|
switch( layer )
|
|
|
|
{
|
|
|
|
default:
|
2009-11-03 13:26:31 +00:00
|
|
|
m_Layer = LAYER_NOTES;
|
2007-08-23 04:28:46 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
|
|
|
m_Layer = LAYER_WIRE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_BUS:
|
|
|
|
m_Layer = LAYER_BUS;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE* SCH_LINE::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_LINE* newitem = new SCH_LINE( m_Start, m_Layer );
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
newitem->m_End = m_End;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_LINE::IsOneEndPointAt( const wxPoint& pos )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( pos.x == m_Start.x ) && ( pos.y == m_Start.y ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return TRUE;
|
2009-12-02 21:44:03 +00:00
|
|
|
if( ( pos.x == m_End.x ) && ( pos.y == m_End.y ) )
|
2007-08-23 04:28:46 +00:00
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
#if defined(DEBUG)
|
2008-04-15 19:38:19 +00:00
|
|
|
|
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.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_LINE::Show( int nestLevel, std::ostream& os )
|
2007-09-20 21:06:49 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << GetClass().Lower().mb_str()
|
|
|
|
<< " 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
|
|
|
}
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
|
2008-04-15 19:38:19 +00:00
|
|
|
#endif
|
|
|
|
|
2008-03-13 05:04:59 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
EDA_Rect SCH_LINE::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
|
2009-04-05 20:49:15 +00:00
|
|
|
EDA_Rect ret( wxPoint( xmin, ymin ),
|
2010-09-05 17:01:48 +00:00
|
|
|
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
|
2009-11-03 13:26:31 +00:00
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
2008-04-15 19:38:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_LINE::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( 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;
|
|
|
|
}
|
2009-07-01 16:07:18 +00:00
|
|
|
if( fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n", m_Start.x, m_Start.y,
|
|
|
|
m_End.x, m_End.y ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_LINE::GetPenSize()
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
int pensize = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-07-01 16:07:18 +00:00
|
|
|
|
|
|
|
if( m_Layer == LAYER_BUS && m_Width == 0 )
|
|
|
|
{
|
|
|
|
pensize = wxRound( g_DrawDefaultLineThickness * BUS_WIDTH_EXPAND );
|
|
|
|
pensize = MAX( pensize, 3 );
|
|
|
|
}
|
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_LINE::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset,
|
|
|
|
int DrawMode, int Color )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int color;
|
2009-07-01 16:07:18 +00:00
|
|
|
int width = GetPenSize();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
|
|
|
GRDashedLine( &panel->m_ClipBox, DC, m_Start.x + offset.x,
|
|
|
|
m_Start.y + offset.y, m_End.x + offset.x,
|
|
|
|
m_End.y + offset.y, width, color );
|
|
|
|
else
|
|
|
|
GRLine( &panel->m_ClipBox, DC, m_Start.x + offset.x,
|
|
|
|
m_Start.y + offset.y, m_End.x + offset.x, m_End.y + offset.y,
|
|
|
|
width, color );
|
|
|
|
|
|
|
|
if( m_StartIsDangling )
|
|
|
|
DrawDanglingSymbol( panel, DC, m_Start + offset, color );
|
|
|
|
|
|
|
|
if( m_EndIsDangling )
|
|
|
|
DrawDanglingSymbol( panel, DC, m_End + offset, color );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-05 17:01:48 +00:00
|
|
|
void SCH_LINE::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
m_Start.y -= aXaxis_position;
|
|
|
|
NEGATE( m_Start.y );
|
|
|
|
m_Start.y += aXaxis_position;
|
|
|
|
m_End.y -= aXaxis_position;
|
|
|
|
NEGATE( m_End.y );
|
|
|
|
m_End.y += aXaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
|
|
|
m_Start.x -= aYaxis_position;
|
|
|
|
NEGATE( m_Start.x );
|
|
|
|
m_Start.x += aYaxis_position;
|
|
|
|
m_End.x -= aYaxis_position;
|
|
|
|
NEGATE( m_End.x );
|
|
|
|
m_End.x += aYaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_LINE::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Start, rotationPoint, 900 );
|
|
|
|
RotatePoint( &m_End, rotationPoint, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/***********************/
|
|
|
|
/* Class SCH_POLYLINE */
|
|
|
|
/***********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_POLYLINE::SCH_POLYLINE( int layer ) :
|
2008-04-14 19:22:48 +00:00
|
|
|
SCH_ITEM( NULL, DRAW_POLYLINE_STRUCT_TYPE )
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-07-01 16:07:18 +00:00
|
|
|
m_Width = 0;
|
2007-08-23 04:28:46 +00:00
|
|
|
|
|
|
|
switch( layer )
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
m_Layer = LAYER_NOTES;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYER_WIRE:
|
|
|
|
case LAYER_NOTES:
|
|
|
|
case LAYER_BUS:
|
|
|
|
m_Layer = layer;
|
|
|
|
break;
|
|
|
|
}
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_POLYLINE::~SCH_POLYLINE()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-08-23 04:28:46 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_POLYLINE* SCH_POLYLINE::GenCopy()
|
2007-06-05 12:10:51 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
SCH_POLYLINE* newitem = new SCH_POLYLINE( m_Layer );
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-01-02 17:07:50 +00:00
|
|
|
newitem->m_PolyPoints = m_PolyPoints; // std::vector copy
|
2007-08-23 04:28:46 +00:00
|
|
|
return newitem;
|
2007-06-05 12:10:51 +00:00
|
|
|
}
|
2008-04-15 19:38:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Save
|
2009-11-03 13:26:31 +00:00
|
|
|
* writes the data structures for this object out to a FILE in "*.sch" format.
|
2008-04-15 19:38:19 +00:00
|
|
|
* @param aFile The FILE to write to.
|
|
|
|
* @return bool - true if success writing else false.
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
bool SCH_POLYLINE::Save( FILE* aFile ) const
|
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( fprintf( aFile, "Poly %s %s %d\n",
|
2010-09-05 17:01:48 +00:00
|
|
|
width, layer, GetCornerCount() ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
return false;
|
2008-04-15 19:38:19 +00:00
|
|
|
}
|
2009-01-02 17:07:50 +00:00
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
if( fprintf( aFile, "\t%-4d %-4d\n",
|
2009-04-05 20:49:15 +00:00
|
|
|
m_PolyPoints[ii ].x, m_PolyPoints[ii].y ) == EOF )
|
2008-04-15 19:38:19 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
/** Function GetPenSize
|
|
|
|
* @return the size of the "pen" that be used to draw or plot this item
|
|
|
|
*/
|
2009-12-02 21:44:03 +00:00
|
|
|
int SCH_POLYLINE::GetPenSize()
|
2009-06-30 19:21:41 +00:00
|
|
|
{
|
2009-12-02 21:44:03 +00:00
|
|
|
int pensize = ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-06-30 19:21:41 +00:00
|
|
|
return pensize;
|
|
|
|
}
|
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
void SCH_POLYLINE::Draw( WinEDA_DrawPanel* panel, wxDC* DC,
|
|
|
|
const wxPoint& offset, int DrawMode, int Color )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int color;
|
2009-07-01 16:07:18 +00:00
|
|
|
int width = GetPenSize();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
if( Color >= 0 )
|
|
|
|
color = Color;
|
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
|
|
|
|
GRSetDrawMode( DC, DrawMode );
|
|
|
|
|
|
|
|
if( m_Layer == LAYER_BUS )
|
|
|
|
{
|
|
|
|
width *= 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRMoveTo( m_PolyPoints[0].x, m_PolyPoints[0].y );
|
|
|
|
|
|
|
|
if( m_Layer == LAYER_NOTES )
|
|
|
|
{
|
|
|
|
for( unsigned i = 1; i < GetCornerCount(); i++ )
|
|
|
|
GRDashedLineTo( &panel->m_ClipBox, DC, m_PolyPoints[i].x + offset.x,
|
|
|
|
m_PolyPoints[i].y + offset.y, width, color );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( unsigned i = 1; i < GetCornerCount(); i++ )
|
|
|
|
GRLineTo( &panel->m_ClipBox, DC, m_PolyPoints[i].x + offset.x,
|
|
|
|
m_PolyPoints[i].y + offset.y, width, color );
|
|
|
|
}
|
|
|
|
}
|
2010-09-05 17:01:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
void SCH_POLYLINE::Mirror_X( int aXaxis_position )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
|
|
|
m_PolyPoints[ii].y -= aXaxis_position;
|
|
|
|
NEGATE( m_PolyPoints[ii].y );
|
|
|
|
m_PolyPoints[ii].y = aXaxis_position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_POLYLINE::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
|
|
|
m_PolyPoints[ii].x -= aYaxis_position;
|
|
|
|
NEGATE( m_PolyPoints[ii].x );
|
|
|
|
m_PolyPoints[ii].x = aYaxis_position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_POLYLINE::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
for( unsigned ii = 0; ii < GetCornerCount(); ii++ )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_PolyPoints[ii], rotationPoint, 900 );
|
|
|
|
}
|
|
|
|
}
|