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"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "macros.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"
|
2010-11-10 15:30:12 +00:00
|
|
|
#include "richio.h"
|
|
|
|
|
2007-06-05 12:10:51 +00:00
|
|
|
#include "general.h"
|
|
|
|
#include "protos.h"
|
2011-01-12 21:47:54 +00:00
|
|
|
#include "sch_junction.h"
|
2010-11-10 15:30:12 +00:00
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
|
2009-12-02 21:44:03 +00:00
|
|
|
/**********************/
|
|
|
|
/* class SCH_JUNCTION */
|
|
|
|
/**********************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) :
|
|
|
|
SCH_ITEM( NULL, SCH_JUNCTION_T )
|
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
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
SCH_JUNCTION::SCH_JUNCTION( const SCH_JUNCTION& aJunction ) :
|
|
|
|
SCH_ITEM( aJunction )
|
|
|
|
{
|
|
|
|
m_Pos = aJunction.m_Pos;
|
|
|
|
m_Size = aJunction.m_Size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
EDA_ITEM* SCH_JUNCTION::doClone() const
|
|
|
|
{
|
|
|
|
return new SCH_JUNCTION( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-10 15:30:12 +00:00
|
|
|
bool SCH_JUNCTION::Load( LINE_READER& aLine, wxString& aErrorMsg )
|
|
|
|
{
|
|
|
|
char name[256];
|
|
|
|
char* line = (char*) aLine;
|
|
|
|
|
|
|
|
while( (*line != ' ' ) && *line )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if( sscanf( line, "%s %d %d", name, &m_Pos.x, &m_Pos.y ) != 3 )
|
|
|
|
{
|
|
|
|
aErrorMsg.Printf( wxT( "EESchema file connection load error at line %d, aborted" ),
|
|
|
|
aLine.LineNumber() );
|
|
|
|
aErrorMsg << wxT( "\n" ) << CONV_FROM_UTF8( (char*) aLine );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect SCH_JUNCTION::GetBoundingBox() const
|
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
|
|
|
|
2011-01-21 19:30:59 +00:00
|
|
|
void SCH_JUNCTION::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
|
2010-12-21 15:13:09 +00:00
|
|
|
int aDrawMode, int aColor )
|
2009-04-05 20:49:15 +00:00
|
|
|
{
|
|
|
|
int color;
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
if( aColor >= 0 )
|
|
|
|
color = aColor;
|
2009-04-05 20:49:15 +00:00
|
|
|
else
|
|
|
|
color = ReturnLayerColor( m_Layer );
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
GRSetDrawMode( aDC, aDrawMode );
|
|
|
|
|
|
|
|
GRFilledCircle( &aPanel->m_ClipBox, aDC, m_Pos.x + aOffset.x, m_Pos.y + aOffset.y,
|
|
|
|
( m_Size.x / 2 ), 0, color, 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;
|
2010-12-10 19:47:44 +00:00
|
|
|
NEGATE( m_Pos.y );
|
2010-09-05 17:01:48 +00:00
|
|
|
m_Pos.y += aXaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_JUNCTION::Mirror_Y( int aYaxis_position )
|
|
|
|
{
|
|
|
|
m_Pos.x -= aYaxis_position;
|
2010-12-10 19:47:44 +00:00
|
|
|
NEGATE( m_Pos.x );
|
2010-09-05 17:01:48 +00:00
|
|
|
m_Pos.x += aYaxis_position;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_JUNCTION::Rotate( wxPoint rotationPoint )
|
|
|
|
{
|
|
|
|
RotatePoint( &m_Pos, rotationPoint, 900 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-03 14:13:15 +00:00
|
|
|
void SCH_JUNCTION::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
|
|
|
|
{
|
|
|
|
DANGLING_END_ITEM item( JUNCTION_END, this );
|
|
|
|
item.m_Pos = m_Pos;
|
|
|
|
aItemList.push_back( item );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SCH_JUNCTION::IsSelectStateChanged( const wxRect& aRect )
|
|
|
|
{
|
|
|
|
bool previousState = IsSelected();
|
|
|
|
|
|
|
|
if( aRect.Contains( m_Pos ) )
|
|
|
|
m_Flags |= SELECTED;
|
|
|
|
else
|
|
|
|
m_Flags &= ~SELECTED;
|
|
|
|
|
|
|
|
return previousState != IsSelected();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SCH_JUNCTION::GetConnectionPoints( vector< wxPoint >& aPoints ) const
|
|
|
|
{
|
|
|
|
aPoints.push_back( m_Pos );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
2010-10-26 20:25:48 +00:00
|
|
|
NestedSpace( nestLevel, os ) << '<' << s.Lower().mb_str() << m_Pos << "/>\n";
|
2008-04-22 16:38:23 +00:00
|
|
|
}
|
2010-12-10 19:47:44 +00:00
|
|
|
#endif
|
2008-04-22 16:38:23 +00:00
|
|
|
|
2009-07-01 16:07:18 +00:00
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_JUNCTION::doHitTest( const wxPoint& aPoint, int aAccuracy, SCH_FILTER_T aFilter ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
2010-12-13 15:59:00 +00:00
|
|
|
if( !( aFilter & JUNCTION_T ) )
|
|
|
|
return false;
|
|
|
|
|
2010-12-10 19:47:44 +00:00
|
|
|
EDA_Rect rect = GetBoundingBox();
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
2010-12-20 17:44:25 +00:00
|
|
|
return rect.Contains( aPoint );
|
2010-12-10 19:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_JUNCTION::doHitTest( const EDA_Rect& aRect, bool aContained, int aAccuracy ) const
|
2010-12-10 19:47:44 +00:00
|
|
|
{
|
|
|
|
EDA_Rect rect = aRect;
|
|
|
|
|
|
|
|
rect.Inflate( aAccuracy );
|
|
|
|
|
|
|
|
if( aContained )
|
2010-12-20 17:44:25 +00:00
|
|
|
return rect.Contains( GetBoundingBox() );
|
2010-12-10 19:47:44 +00:00
|
|
|
|
|
|
|
return rect.Intersects( GetBoundingBox() );
|
|
|
|
}
|
2008-04-22 16:38:23 +00:00
|
|
|
|
|
|
|
|
2010-12-21 15:13:09 +00:00
|
|
|
bool SCH_JUNCTION::doIsConnected( const wxPoint& aPosition ) const
|
2010-12-13 15:59:00 +00:00
|
|
|
{
|
|
|
|
return m_Pos == aPosition;
|
|
|
|
}
|