Commit f37812f8 authored by Lorenzo Marcantonio's avatar Lorenzo Marcantonio

Refactoring: split in two the SCH_BUS_ENTRY class

parent 0dd413a7
...@@ -43,28 +43,36 @@ ...@@ -43,28 +43,36 @@
static int s_LastShape = '\\'; static int s_LastShape = '\\';
SCH_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusEntry( wxDC* aDC, int aType ) SCH_BUS_BUS_ENTRY* SCH_EDIT_FRAME::CreateBusBusEntry( wxDC* aDC )
{ {
SCH_SCREEN* screen = GetScreen(); SCH_SCREEN* screen = GetScreen();
// Create and place a new bus entry at cursor position // Create and place a new bus entry at cursor position
SCH_BUS_ENTRY* busEntry = new SCH_BUS_ENTRY( screen->GetCrossHairPosition(), s_LastShape, SCH_BUS_BUS_ENTRY* busEntry = new SCH_BUS_BUS_ENTRY( screen->GetCrossHairPosition(), s_LastShape );
aType );
busEntry->SetFlags( IS_NEW ); busEntry->SetFlags( IS_NEW );
GetScreen()->SetCurItem( busEntry ); GetScreen()->SetCurItem( busEntry );
addCurrentItemToList( aDC ); addCurrentItemToList( aDC );
return busEntry; return busEntry;
} }
SCH_BUS_WIRE_ENTRY* SCH_EDIT_FRAME::CreateBusWireEntry( wxDC* aDC )
{
SCH_SCREEN* screen = GetScreen();
// Create and place a new bus entry at cursor position
SCH_BUS_WIRE_ENTRY* busEntry = new SCH_BUS_WIRE_ENTRY( screen->GetCrossHairPosition(), s_LastShape );
busEntry->SetFlags( IS_NEW );
GetScreen()->SetCurItem( busEntry );
addCurrentItemToList( aDC );
return busEntry;
}
/* set the shape of BusEntry (shape = / or \ ) /* set the shape of BusEntry (shape = / or \ )
*/ */
void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_shape ) void SCH_EDIT_FRAME::SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY_BASE* BusEntry, char entry_shape )
{ {
if( BusEntry == NULL ) if( BusEntry == NULL )
return; return;
if( BusEntry->Type() != SCH_BUS_ENTRY_T )
{ {
DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) ); DisplayError( this, wxT( "SetBusEntryType: Bad StructType" ) );
return; return;
......
...@@ -147,6 +147,7 @@ again." ); ...@@ -147,6 +147,7 @@ again." );
while( reader.ReadLine() ) while( reader.ReadLine() )
{ {
itemLoaded = false;
line = reader.Line(); line = reader.Line();
item = NULL; item = NULL;
...@@ -167,6 +168,8 @@ again." ); ...@@ -167,6 +168,8 @@ again." );
itemLoaded = ReadSchemaDescr( &reader, msgDiag, aScreen ); itemLoaded = ReadSchemaDescr( &reader, msgDiag, aScreen );
else if( line[1] == 'B' ) else if( line[1] == 'B' )
item = new SCH_BITMAP(); item = new SCH_BITMAP();
else if( line[1] == 'E' )
itemLoaded = true; // The EOF marker
break; break;
case 'L': // Its a library item. case 'L': // Its a library item.
...@@ -178,7 +181,9 @@ again." ); ...@@ -178,7 +181,9 @@ again." );
break; break;
case 'E': // Its a WIRE or BUS item. case 'E': // Its a WIRE or BUS item.
item = new SCH_BUS_ENTRY(); /* The bus entry can be represented by two different
* classes, so we need a factory function */
itemLoaded = SCH_BUS_ENTRY_BASE::Load( reader, msgDiag, &item );
break; break;
case 'C': // It is a connection item. case 'C': // It is a connection item.
...@@ -220,6 +225,8 @@ again." ); ...@@ -220,6 +225,8 @@ again." );
if( item ) if( item )
{ {
// Load it if it wasn't by a factory
if( !itemLoaded )
itemLoaded = item->Load( reader, msgDiag ); itemLoaded = item->Load( reader, msgDiag );
if( !itemLoaded ) if( !itemLoaded )
......
...@@ -70,7 +70,8 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -70,7 +70,8 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
case SCH_TEXT_T: case SCH_TEXT_T:
case SCH_SHEET_PIN_T: case SCH_SHEET_PIN_T:
case SCH_SHEET_T: case SCH_SHEET_T:
case SCH_BUS_ENTRY_T: case SCH_BUS_WIRE_ENTRY_T:
case SCH_BUS_BUS_ENTRY_T:
case SCH_JUNCTION_T: case SCH_JUNCTION_T:
case SCH_COMPONENT_T: case SCH_COMPONENT_T:
case SCH_FIELD_T: case SCH_FIELD_T:
...@@ -157,11 +158,20 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition ) ...@@ -157,11 +158,20 @@ void SCH_EDIT_FRAME::OnLeftClick( wxDC* aDC, const wxPoint& aPosition )
break; break;
case ID_WIRETOBUS_ENTRY_BUTT: case ID_WIRETOBUS_ENTRY_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{
CreateBusWireEntry( aDC );
m_canvas->SetAutoPanRequest( true );
}
else
{
addCurrentItemToList( aDC );
}
break;
case ID_BUSTOBUS_ENTRY_BUTT: case ID_BUSTOBUS_ENTRY_BUTT:
if( ( item == NULL ) || ( item->GetFlags() == 0 ) ) if( ( item == NULL ) || ( item->GetFlags() == 0 ) )
{ {
CreateBusEntry( aDC, ( GetToolId() == ID_WIRETOBUS_ENTRY_BUTT ) ? CreateBusBusEntry( aDC );
WIRE_TO_BUS : BUS_TO_BUS );
m_canvas->SetAutoPanRequest( true ); m_canvas->SetAutoPanRequest( true );
} }
else else
......
...@@ -64,7 +64,7 @@ static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ); ...@@ -64,7 +64,7 @@ static void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component );
static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field ); static void AddMenusForComponentField( wxMenu* PopMenu, SCH_FIELD* Field );
static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame ); static void AddMenusForMarkers( wxMenu* aPopMenu, SCH_MARKER* aMarker, SCH_EDIT_FRAME* aFrame );
static void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap ); static void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap );
static void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY * aBusEntry ); static void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY_BASE * aBusEntry );
...@@ -219,8 +219,9 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ...@@ -219,8 +219,9 @@ bool SCH_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu )
addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item ); addJunctionMenuEntries( PopMenu, (SCH_JUNCTION*) item );
break; break;
case SCH_BUS_ENTRY_T: case SCH_BUS_BUS_ENTRY_T:
AddMenusForBusEntry( PopMenu, (SCH_BUS_ENTRY*) item ); case SCH_BUS_WIRE_ENTRY_T:
AddMenusForBusEntry( PopMenu, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ) );
break; break;
case SCH_MARKER_T: case SCH_MARKER_T:
...@@ -873,7 +874,7 @@ void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap ) ...@@ -873,7 +874,7 @@ void AddMenusForBitmap( wxMenu* aPopMenu, SCH_BITMAP * aBitmap )
} }
} }
void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY * aBusEntry ) void AddMenusForBusEntry( wxMenu* aPopMenu, SCH_BUS_ENTRY_BASE* aBusEntry )
{ {
wxString msg; wxString msg;
if( !aBusEntry->GetFlags() ) if( !aBusEntry->GetFlags() )
......
...@@ -31,7 +31,8 @@ void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen ) ...@@ -31,7 +31,8 @@ void SetSchItemParent( SCH_ITEM* Struct, SCH_SCREEN* Screen )
case SCH_HIERARCHICAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T:
case SCH_COMPONENT_T: case SCH_COMPONENT_T:
case SCH_LINE_T: case SCH_LINE_T:
case SCH_BUS_ENTRY_T: case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_SHEET_T: case SCH_SHEET_T:
case SCH_MARKER_T: case SCH_MARKER_T:
case SCH_NO_CONNECT_T: case SCH_NO_CONNECT_T:
...@@ -185,7 +186,8 @@ void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList, ...@@ -185,7 +186,8 @@ void DuplicateItemsInList( SCH_SCREEN* screen, PICKED_ITEMS_LIST& aItemsList,
{ {
case SCH_JUNCTION_T: case SCH_JUNCTION_T:
case SCH_LINE_T: case SCH_LINE_T:
case SCH_BUS_ENTRY_T: case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_TEXT_T: case SCH_TEXT_T:
case SCH_LABEL_T: case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T: case SCH_GLOBAL_LABEL_T:
......
...@@ -42,80 +42,81 @@ ...@@ -42,80 +42,81 @@
#include <sch_bus_entry.h> #include <sch_bus_entry.h>
SCH_BUS_ENTRY::SCH_BUS_ENTRY( const wxPoint& pos, int shape, int id ) : SCH_BUS_ENTRY_BASE::SCH_BUS_ENTRY_BASE( KICAD_T aType, const wxPoint& pos, char shape ) :
SCH_ITEM( NULL, SCH_BUS_ENTRY_T ) SCH_ITEM( NULL, aType )
{ {
m_pos = pos; m_pos = pos;
m_size.x = 100; m_size.x = 100;
m_size.y = 100; m_size.y = 100;
m_Layer = LAYER_WIRE;
m_width = 0;
if( id == BUS_TO_BUS )
{
m_Layer = LAYER_BUS;
}
if( shape == '/' ) if( shape == '/' )
m_size.y = -100; m_size.y = -100;
} }
SCH_BUS_WIRE_ENTRY::SCH_BUS_WIRE_ENTRY( const wxPoint& pos, char shape ) :
SCH_BUS_ENTRY_BASE( SCH_BUS_WIRE_ENTRY_T, pos, shape )
{
m_Layer = LAYER_WIRE;
}
SCH_BUS_BUS_ENTRY::SCH_BUS_BUS_ENTRY( const wxPoint& pos, char shape ) :
SCH_BUS_ENTRY_BASE( SCH_BUS_BUS_ENTRY_T, pos, shape )
{
m_Layer = LAYER_BUS;
}
EDA_ITEM* SCH_BUS_WIRE_ENTRY::Clone() const
{
return new SCH_BUS_WIRE_ENTRY( *this );
}
EDA_ITEM* SCH_BUS_ENTRY::Clone() const EDA_ITEM* SCH_BUS_BUS_ENTRY::Clone() const
{ {
return new SCH_BUS_ENTRY( *this ); return new SCH_BUS_BUS_ENTRY( *this );
} }
wxPoint SCH_BUS_ENTRY::m_End() const wxPoint SCH_BUS_ENTRY_BASE::m_End() const
{ {
return wxPoint( m_pos.x + m_size.x, m_pos.y + m_size.y ); return wxPoint( m_pos.x + m_size.x, m_pos.y + m_size.y );
} }
void SCH_BUS_ENTRY::SwapData( SCH_ITEM* aItem ) void SCH_BUS_ENTRY_BASE::SwapData( SCH_ITEM* aItem )
{ {
wxCHECK_RET( (aItem != NULL) && (aItem->Type() == SCH_BUS_ENTRY_T), SCH_BUS_ENTRY_BASE* item = dynamic_cast<SCH_BUS_ENTRY_BASE*>( aItem );
wxT( "Cannot swap bus entry data with invalid item." ) ); wxCHECK_RET( item, wxT( "Cannot swap bus entry data with invalid item." ) );
SCH_BUS_ENTRY* item = (SCH_BUS_ENTRY*)aItem;
EXCHG( m_pos, item->m_pos ); EXCHG( m_pos, item->m_pos );
EXCHG( m_size, item->m_size ); EXCHG( m_size, item->m_size );
EXCHG( m_width, item->m_width );
} }
bool SCH_BUS_ENTRY::Save( FILE* aFile ) const bool SCH_BUS_WIRE_ENTRY::Save( FILE* aFile ) const
{ {
bool success = true; if( fprintf( aFile, "Entry Wire Line\n\t%-4d %-4d %-4d %-4d\n",
m_pos.x, m_pos.y, m_End().x, m_End().y ) == EOF )
const char* layer = "Wire"; return false;
const char* width = "Line"; return true;
}
if( GetLayer() == LAYER_BUS )
{
layer = "Bus"; width = "Bus";
}
if( fprintf( aFile, "Entry %s %s\n", layer, width ) == EOF ) bool SCH_BUS_BUS_ENTRY::Save( FILE* aFile ) const
{ {
success = false; if( fprintf( aFile, "Entry Bus Bus\n\t%-4d %-4d %-4d %-4d\n",
}
if( fprintf( aFile, "\t%-4d %-4d %-4d %-4d\n",
m_pos.x, m_pos.y, m_End().x, m_End().y ) == EOF ) m_pos.x, m_pos.y, m_End().x, m_End().y ) == EOF )
{ return false;
success = false; return true;
}
return success;
} }
bool SCH_BUS_ENTRY::Load( LINE_READER& aLine, wxString& aErrorMsg ) bool SCH_BUS_ENTRY_BASE::Load( LINE_READER& aLine, wxString& aErrorMsg,
SCH_ITEM **out )
{ {
char Name1[256]; char Name1[256];
char Name2[256]; char Name2[256];
char* line = (char*) aLine; char* line = (char*) aLine;
*out = NULL;
while( (*line != ' ' ) && *line ) while( (*line != ' ' ) && *line )
line++; line++;
...@@ -128,13 +129,16 @@ bool SCH_BUS_ENTRY::Load( LINE_READER& aLine, wxString& aErrorMsg ) ...@@ -128,13 +129,16 @@ bool SCH_BUS_ENTRY::Load( LINE_READER& aLine, wxString& aErrorMsg )
return false; return false;
} }
m_Layer = LAYER_WIRE; SCH_BUS_ENTRY_BASE *this_new;
if( Name1[0] == 'B' ) if( Name1[0] == 'B' )
m_Layer = LAYER_BUS; this_new = new SCH_BUS_BUS_ENTRY;
else
this_new = new SCH_BUS_WIRE_ENTRY;
*out = this_new;
if( !aLine.ReadLine() || sscanf( (char*) aLine, "%d %d %d %d ", &m_pos.x, &m_pos.y, if( !aLine.ReadLine() || sscanf( (char*) aLine, "%d %d %d %d ",
&m_size.x, &m_size.y ) != 4 ) &this_new->m_pos.x, &this_new->m_pos.y,
&this_new->m_size.x, &this_new->m_size.y ) != 4 )
{ {
aErrorMsg.Printf( wxT( "Eeschema file bus entry load error at line %d" ), aErrorMsg.Printf( wxT( "Eeschema file bus entry load error at line %d" ),
aLine.LineNumber() ); aLine.LineNumber() );
...@@ -142,14 +146,14 @@ bool SCH_BUS_ENTRY::Load( LINE_READER& aLine, wxString& aErrorMsg ) ...@@ -142,14 +146,14 @@ bool SCH_BUS_ENTRY::Load( LINE_READER& aLine, wxString& aErrorMsg )
return false; return false;
} }
m_size.x -= m_pos.x; this_new->m_size.x -= this_new->m_pos.x;
m_size.y -= m_pos.y; this_new->m_size.y -= this_new->m_pos.y;
return true; return true;
} }
EDA_RECT SCH_BUS_ENTRY::GetBoundingBox() const EDA_RECT SCH_BUS_ENTRY_BASE::GetBoundingBox() const
{ {
EDA_RECT box; EDA_RECT box;
...@@ -157,27 +161,25 @@ EDA_RECT SCH_BUS_ENTRY::GetBoundingBox() const ...@@ -157,27 +161,25 @@ EDA_RECT SCH_BUS_ENTRY::GetBoundingBox() const
box.SetEnd( m_End() ); box.SetEnd( m_End() );
box.Normalize(); box.Normalize();
int width = ( m_width == 0 ) ? GetDefaultLineThickness() : m_width; box.Inflate( GetPenSize() / 2 );
box.Inflate( width / 2 );
return box; return box;
} }
int SCH_BUS_ENTRY::GetPenSize() const int SCH_BUS_WIRE_ENTRY::GetPenSize() const
{ {
int pensize = ( m_width == 0 ) ? GetDefaultLineThickness() : m_width; return GetDefaultLineThickness();
}
if( m_Layer == LAYER_BUS )
{
pensize = ( m_width == 0 ) ? GetDefaultBusThickness() : m_width;
}
return pensize; int SCH_BUS_BUS_ENTRY::GetPenSize() const
{
return GetDefaultBusThickness();
} }
void SCH_BUS_ENTRY::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void SCH_BUS_ENTRY_BASE::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor ) GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor )
{ {
EDA_COLOR_T color; EDA_COLOR_T color;
...@@ -194,7 +196,7 @@ void SCH_BUS_ENTRY::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff ...@@ -194,7 +196,7 @@ void SCH_BUS_ENTRY::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff
} }
void SCH_BUS_ENTRY::MirrorX( int aXaxis_position ) void SCH_BUS_ENTRY_BASE::MirrorX( int aXaxis_position )
{ {
m_pos.y -= aXaxis_position; m_pos.y -= aXaxis_position;
NEGATE( m_pos.y ); NEGATE( m_pos.y );
...@@ -203,7 +205,7 @@ void SCH_BUS_ENTRY::MirrorX( int aXaxis_position ) ...@@ -203,7 +205,7 @@ void SCH_BUS_ENTRY::MirrorX( int aXaxis_position )
} }
void SCH_BUS_ENTRY::MirrorY( int aYaxis_position ) void SCH_BUS_ENTRY_BASE::MirrorY( int aYaxis_position )
{ {
m_pos.x -= aYaxis_position; m_pos.x -= aYaxis_position;
NEGATE( m_pos.x ); NEGATE( m_pos.x );
...@@ -212,14 +214,14 @@ void SCH_BUS_ENTRY::MirrorY( int aYaxis_position ) ...@@ -212,14 +214,14 @@ void SCH_BUS_ENTRY::MirrorY( int aYaxis_position )
} }
void SCH_BUS_ENTRY::Rotate( wxPoint aPosition ) void SCH_BUS_ENTRY_BASE::Rotate( wxPoint aPosition )
{ {
RotatePoint( &m_pos, aPosition, 900 ); RotatePoint( &m_pos, aPosition, 900 );
RotatePoint( &m_size.x, &m_size.y, 900 ); RotatePoint( &m_size.x, &m_size.y, 900 );
} }
void SCH_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) void SCH_BUS_ENTRY_BASE::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
{ {
DANGLING_END_ITEM item( ENTRY_END, this, m_pos ); DANGLING_END_ITEM item( ENTRY_END, this, m_pos );
aItemList.push_back( item ); aItemList.push_back( item );
...@@ -229,44 +231,47 @@ void SCH_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList ) ...@@ -229,44 +231,47 @@ void SCH_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
} }
bool SCH_BUS_ENTRY::IsSelectStateChanged( const wxRect& aRect ) bool SCH_BUS_ENTRY_BASE::IsSelectStateChanged( const wxRect& aRect )
{ {
bool previousState = IsSelected(); bool previousState = IsSelected();
// If either end of the bus entry is inside the selection rectangle, the entire // If either end of the bus entry is inside the selection rectangle, the entire
// bus entry is selected. Bus entries have a fixed length and angle. // bus entry is selected. Bus entries have a fixed length and angle.
if( aRect.Contains( m_pos ) || aRect.Contains( m_End() ) ) if( aRect.Contains( m_pos ) || aRect.Contains( m_End() ) )
m_Flags |= SELECTED; SetFlags( SELECTED );
else else
m_Flags &= ~SELECTED; ClearFlags( SELECTED );
return previousState != IsSelected(); return previousState != IsSelected();
} }
void SCH_BUS_ENTRY::GetConnectionPoints( vector< wxPoint >& aPoints ) const void SCH_BUS_ENTRY_BASE::GetConnectionPoints( vector< wxPoint >& aPoints ) const
{ {
aPoints.push_back( m_pos ); aPoints.push_back( m_pos );
aPoints.push_back( m_End() ); aPoints.push_back( m_End() );
} }
wxString SCH_BUS_ENTRY::GetSelectMenuText() const wxString SCH_BUS_WIRE_ENTRY::GetSelectMenuText() const
{ {
if( m_Layer == LAYER_WIRE )
return wxString( _( "Bus to Wire Entry" ) ); return wxString( _( "Bus to Wire Entry" ) );
}
wxString SCH_BUS_BUS_ENTRY::GetSelectMenuText() const
{
return wxString( _( "Bus to Bus Entry" ) ); return wxString( _( "Bus to Bus Entry" ) );
} }
bool SCH_BUS_ENTRY::HitTest( const wxPoint& aPosition, int aAccuracy ) const bool SCH_BUS_ENTRY_BASE::HitTest( const wxPoint& aPosition, int aAccuracy ) const
{ {
return TestSegmentHit( aPosition, m_pos, m_End(), aAccuracy ); return TestSegmentHit( aPosition, m_pos, m_End(), aAccuracy );
} }
bool SCH_BUS_ENTRY::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const bool SCH_BUS_ENTRY_BASE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccuracy ) const
{ {
EDA_RECT rect = aRect; EDA_RECT rect = aRect;
...@@ -279,7 +284,7 @@ bool SCH_BUS_ENTRY::HitTest( const EDA_RECT& aRect, bool aContained, int aAccura ...@@ -279,7 +284,7 @@ bool SCH_BUS_ENTRY::HitTest( const EDA_RECT& aRect, bool aContained, int aAccura
} }
void SCH_BUS_ENTRY::Plot( PLOTTER* aPlotter ) void SCH_BUS_ENTRY_BASE::Plot( PLOTTER* aPlotter )
{ {
aPlotter->SetCurrentLineWidth( GetPenSize() ); aPlotter->SetCurrentLineWidth( GetPenSize() );
aPlotter->SetColor( ReturnLayerColor( GetLayer() ) ); aPlotter->SetColor( ReturnLayerColor( GetLayer() ) );
...@@ -291,7 +296,7 @@ void SCH_BUS_ENTRY::Plot( PLOTTER* aPlotter ) ...@@ -291,7 +296,7 @@ void SCH_BUS_ENTRY::Plot( PLOTTER* aPlotter )
* Set the shape of the bus entry. * Set the shape of the bus entry.
* aShape = ascii code '/' or '\' * aShape = ascii code '/' or '\'
*/ */
void SCH_BUS_ENTRY::SetBusEntryShape( int aShape ) void SCH_BUS_ENTRY_BASE::SetBusEntryShape( char aShape )
{ {
switch( aShape ) switch( aShape )
{ {
...@@ -311,12 +316,11 @@ void SCH_BUS_ENTRY::SetBusEntryShape( int aShape ) ...@@ -311,12 +316,11 @@ void SCH_BUS_ENTRY::SetBusEntryShape( int aShape )
/* GetBusEntryShape: /* GetBusEntryShape:
* return the shape of the bus entry, as an ascii code '/' or '\' * return the shape of the bus entry, as an ascii code '/' or '\'
*/ */
int SCH_BUS_ENTRY::GetBusEntryShape() const char SCH_BUS_ENTRY_BASE::GetBusEntryShape() const
{ {
int shape = '\\';
if( GetSize().y < 0 ) if( GetSize().y < 0 )
shape = '/'; return '/';
else
return shape; return '\\';
} }
...@@ -33,33 +33,23 @@ ...@@ -33,33 +33,23 @@
#include <sch_item_struct.h> #include <sch_item_struct.h>
/* Flags for BUS ENTRY (bus to bus or wire to bus */
#define WIRE_TO_BUS 0
#define BUS_TO_BUS 1
/** /**
* Class SCH_BUS_ENTRY * Class SCH_BUS_ENTRY_BASE
* *
* Defines a bus or wire entry. * Base class for a bus or wire entry.
*/ */
class SCH_BUS_ENTRY : public SCH_ITEM class SCH_BUS_ENTRY_BASE : public SCH_ITEM
{ {
protected:
wxPoint m_pos; wxPoint m_pos;
int m_width;
wxSize m_size; wxSize m_size;
public: public:
SCH_BUS_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), int shape = '\\', int id = WIRE_TO_BUS ); SCH_BUS_ENTRY_BASE( KICAD_T aType, const wxPoint& pos = wxPoint( 0, 0 ), char shape = '\\' );
// Do not create a copy constructor. The one generated by the compiler is adequate. // Do not create a copy constructor. The one generated by the compiler is adequate.
~SCH_BUS_ENTRY() { } ~SCH_BUS_ENTRY_BASE() { }
wxString GetClass() const
{
return wxT( "SCH_BUS_ENTRY" );
}
wxPoint m_End() const; wxPoint m_End() const;
...@@ -67,17 +57,13 @@ public: ...@@ -67,17 +57,13 @@ public:
* function GetBusEntryShape * function GetBusEntryShape
* @return the shape of the bus entry, as an ascii code '/' or '\' * @return the shape of the bus entry, as an ascii code '/' or '\'
*/ */
int GetBusEntryShape() const; char GetBusEntryShape() const;
/** /**
* function SetBusEntryShape * function SetBusEntryShape
* @param aShape = the shape of the bus entry, as an ascii code '/' or '\' * @param aShape = the shape of the bus entry, as an ascii code '/' or '\'
*/ */
void SetBusEntryShape( int aShape ); void SetBusEntryShape( char aShape );
int GetWidth() const { return m_width; }
void SetWidth( int aWidth ) { m_width = aWidth; }
wxSize GetSize() const { return m_size; } wxSize GetSize() const { return m_size; }
...@@ -88,14 +74,10 @@ public: ...@@ -88,14 +74,10 @@ public:
void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR ); GR_DRAWMODE aDrawMode, EDA_COLOR_T aColor = UNSPECIFIED_COLOR );
bool Save( FILE* aFile ) const; static bool Load( LINE_READER& aLine, wxString& aErrorMsg, SCH_ITEM **out );
bool Load( LINE_READER& aLine, wxString& aErrorMsg );
EDA_RECT GetBoundingBox() const; EDA_RECT GetBoundingBox() const;
int GetPenSize() const;
void Move( const wxPoint& aMoveVector ) void Move( const wxPoint& aMoveVector )
{ {
m_pos += aMoveVector; m_pos += aMoveVector;
...@@ -116,8 +98,6 @@ public: ...@@ -116,8 +98,6 @@ public:
void GetConnectionPoints( vector< wxPoint >& aPoints ) const; void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
wxString GetSelectMenuText() const;
BITMAP_DEF GetMenuImage() const { return add_entry_xpm; } BITMAP_DEF GetMenuImage() const { return add_entry_xpm; }
wxPoint GetPosition() const { return m_pos; } wxPoint GetPosition() const { return m_pos; }
...@@ -130,12 +110,61 @@ public: ...@@ -130,12 +110,61 @@ public:
void Plot( PLOTTER* aPlotter ); void Plot( PLOTTER* aPlotter );
EDA_ITEM* Clone() const;
#if defined(DEBUG) #if defined(DEBUG)
void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override void Show( int nestLevel, std::ostream& os ) const { ShowDummy( os ); } // override
#endif #endif
}; };
/**
* Class SCH_BUS_WIRE_ENTRY
*
* Class for a wire to bus entry.
*/
class SCH_BUS_WIRE_ENTRY : public SCH_BUS_ENTRY_BASE
{
public:
SCH_BUS_WIRE_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), char shape = '\\' );
~SCH_BUS_WIRE_ENTRY() { }
wxString GetClass() const
{
return wxT( "SCH_BUS_WIRE_ENTRY" );
}
bool Save( FILE* aFile ) const;
int GetPenSize() const;
wxString GetSelectMenuText() const;
EDA_ITEM* Clone() const;
};
/**
* Class SCH_BUS_WIRE_ENTRY
*
* Class for a bus to bus entry.
*/
class SCH_BUS_BUS_ENTRY : public SCH_BUS_ENTRY_BASE
{
public:
SCH_BUS_BUS_ENTRY( const wxPoint& pos = wxPoint( 0, 0 ), char shape = '\\' );
~SCH_BUS_BUS_ENTRY() { }
wxString GetClass() const
{
return wxT( "SCH_BUS_BUS_ENTRY" );
}
bool Save( FILE* aFile ) const;
int GetPenSize() const;
wxString GetSelectMenuText() const;
EDA_ITEM* Clone() const;
};
#endif // _SCH_BUS_ENTRY_H_ #endif // _SCH_BUS_ENTRY_H_
...@@ -33,13 +33,15 @@ ...@@ -33,13 +33,15 @@
#include <sch_collectors.h> #include <sch_collectors.h>
#include <sch_component.h> #include <sch_component.h>
#include <sch_line.h> #include <sch_line.h>
#include <sch_bus_entry.h>
const KICAD_T SCH_COLLECTOR::AllItems[] = { const KICAD_T SCH_COLLECTOR::AllItems[] = {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T,
SCH_BUS_ENTRY_T, SCH_BUS_BUS_ENTRY_T,
SCH_BUS_WIRE_ENTRY_T,
SCH_LINE_T, SCH_LINE_T,
SCH_BITMAP_T, SCH_BITMAP_T,
SCH_TEXT_T, SCH_TEXT_T,
...@@ -59,7 +61,8 @@ const KICAD_T SCH_COLLECTOR::AllItemsButPins[] = { ...@@ -59,7 +61,8 @@ const KICAD_T SCH_COLLECTOR::AllItemsButPins[] = {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T,
SCH_BUS_ENTRY_T, SCH_BUS_BUS_ENTRY_T,
SCH_BUS_WIRE_ENTRY_T,
SCH_LINE_T, SCH_LINE_T,
SCH_BITMAP_T, SCH_BITMAP_T,
SCH_TEXT_T, SCH_TEXT_T,
...@@ -107,7 +110,8 @@ const KICAD_T SCH_COLLECTOR::MovableItems[] = { ...@@ -107,7 +110,8 @@ const KICAD_T SCH_COLLECTOR::MovableItems[] = {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T,
SCH_BUS_ENTRY_T, SCH_BUS_BUS_ENTRY_T,
SCH_BUS_WIRE_ENTRY_T,
// SCH_LINE_T, // SCH_LINE_T,
SCH_BITMAP_T, SCH_BITMAP_T,
SCH_TEXT_T, SCH_TEXT_T,
...@@ -124,7 +128,8 @@ const KICAD_T SCH_COLLECTOR::MovableItems[] = { ...@@ -124,7 +128,8 @@ const KICAD_T SCH_COLLECTOR::MovableItems[] = {
const KICAD_T SCH_COLLECTOR::DraggableItems[] = { const KICAD_T SCH_COLLECTOR::DraggableItems[] = {
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_BUS_ENTRY_T, SCH_BUS_BUS_ENTRY_T,
SCH_BUS_WIRE_ENTRY_T,
SCH_LINE_T, SCH_LINE_T,
SCH_LABEL_T, SCH_LABEL_T,
SCH_GLOBAL_LABEL_T, SCH_GLOBAL_LABEL_T,
...@@ -152,7 +157,8 @@ const KICAD_T SCH_COLLECTOR::ParentItems[] = { ...@@ -152,7 +157,8 @@ const KICAD_T SCH_COLLECTOR::ParentItems[] = {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T,
SCH_BUS_ENTRY_T, SCH_BUS_BUS_ENTRY_T,
SCH_BUS_WIRE_ENTRY_T,
SCH_LINE_T, SCH_LINE_T,
SCH_TEXT_T, SCH_TEXT_T,
SCH_LABEL_T, SCH_LABEL_T,
...@@ -241,13 +247,16 @@ bool SCH_COLLECTOR::IsCorner() const ...@@ -241,13 +247,16 @@ bool SCH_COLLECTOR::IsCorner() const
if( GetCount() != 2 ) if( GetCount() != 2 )
return false; return false;
bool is_busentry0 = dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_List[0] );
bool is_busentry1 = dynamic_cast<SCH_BUS_ENTRY_BASE*>( m_List[1] );
if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_LINE_T) ) if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_LINE_T) )
return true; return true;
if( (m_List[0]->Type() == SCH_LINE_T) && (m_List[1]->Type() == SCH_BUS_ENTRY_T) ) if( (m_List[0]->Type() == SCH_LINE_T) && is_busentry1 )
return true; return true;
if( (m_List[0]->Type() == SCH_BUS_ENTRY_T) && (m_List[1]->Type() == SCH_LINE_T) ) if( is_busentry0 && (m_List[1]->Type() == SCH_LINE_T) )
return true; return true;
return false; return false;
......
...@@ -394,7 +394,10 @@ bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer ) ...@@ -394,7 +394,10 @@ bool SCH_SCREEN::IsTerminalPoint( const wxPoint& aPosition, int aLayer )
break; break;
case LAYER_WIRE: case LAYER_WIRE:
if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_ENTRY_T ) ) if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_WIRE_ENTRY_T) )
return true;
if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_BUS_BUS_ENTRY_T) )
return true; return true;
if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_JUNCTION_T ) ) if( GetItem( aPosition, std::max( GetDefaultLineThickness(), 3 ), SCH_JUNCTION_T ) )
...@@ -958,13 +961,15 @@ bool SCH_SCREEN::BreakSegmentsOnJunctions() ...@@ -958,13 +961,15 @@ bool SCH_SCREEN::BreakSegmentsOnJunctions()
if( BreakSegment( junction->GetPosition() ) ) if( BreakSegment( junction->GetPosition() ) )
brokenSegments = true; brokenSegments = true;
} }
else if( item->Type() == SCH_BUS_ENTRY_T ) else
{
SCH_BUS_ENTRY_BASE* busEntry = dynamic_cast<SCH_BUS_ENTRY_BASE*>( item );
if( busEntry )
{ {
SCH_BUS_ENTRY* busEntry = ( SCH_BUS_ENTRY* ) item;
if( BreakSegment( busEntry->GetPosition() ) if( BreakSegment( busEntry->GetPosition() )
|| BreakSegment( busEntry->m_End() ) ) || BreakSegment( busEntry->m_End() ) )
brokenSegments = true; brokenSegments = true;
}
} }
} }
......
...@@ -137,12 +137,12 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) ...@@ -137,12 +137,12 @@ void SCH_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event )
case ID_POPUP_SCH_ENTRY_SELECT_SLASH: case ID_POPUP_SCH_ENTRY_SELECT_SLASH:
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
SetBusEntryShape( &dc, (SCH_BUS_ENTRY*) item, '/' ); SetBusEntryShape( &dc, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ), '/' );
break; break;
case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH: case ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH:
m_canvas->MoveCursorToCrossHair(); m_canvas->MoveCursorToCrossHair();
SetBusEntryShape( &dc, (SCH_BUS_ENTRY*) item, '\\' ); SetBusEntryShape( &dc, dynamic_cast<SCH_BUS_ENTRY_BASE*>( item ), '\\' );
break; break;
case ID_POPUP_CANCEL_CURRENT_COMMAND: case ID_POPUP_CANCEL_CURRENT_COMMAND:
...@@ -417,7 +417,8 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent ) ...@@ -417,7 +417,8 @@ void SCH_EDIT_FRAME::OnMoveItem( wxCommandEvent& aEvent )
case SCH_JUNCTION_T: case SCH_JUNCTION_T:
case SCH_NO_CONNECT_T: case SCH_NO_CONNECT_T:
case SCH_BUS_ENTRY_T: case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_LABEL_T: case SCH_LABEL_T:
case SCH_GLOBAL_LABEL_T: case SCH_GLOBAL_LABEL_T:
case SCH_HIERARCHICAL_LABEL_T: case SCH_HIERARCHICAL_LABEL_T:
...@@ -939,7 +940,8 @@ void SCH_EDIT_FRAME::OnDragItem( wxCommandEvent& aEvent ) ...@@ -939,7 +940,8 @@ void SCH_EDIT_FRAME::OnDragItem( wxCommandEvent& aEvent )
switch( item->Type() ) switch( item->Type() )
{ {
case SCH_BUS_ENTRY_T: case SCH_BUS_BUS_ENTRY_T:
case SCH_BUS_WIRE_ENTRY_T:
case SCH_LINE_T: case SCH_LINE_T:
case SCH_JUNCTION_T: case SCH_JUNCTION_T:
if( item->GetLayer() == LAYER_BUS ) if( item->GetLayer() == LAYER_BUS )
......
...@@ -82,7 +82,8 @@ enum KICAD_T { ...@@ -82,7 +82,8 @@ enum KICAD_T {
SCH_MARKER_T, SCH_MARKER_T,
SCH_JUNCTION_T, SCH_JUNCTION_T,
SCH_NO_CONNECT_T, SCH_NO_CONNECT_T,
SCH_BUS_ENTRY_T, SCH_BUS_WIRE_ENTRY_T,
SCH_BUS_BUS_ENTRY_T,
SCH_LINE_T, SCH_LINE_T,
SCH_BITMAP_T, SCH_BITMAP_T,
SCH_TEXT_T, SCH_TEXT_T,
......
...@@ -48,7 +48,9 @@ class CMP_LIBRARY; ...@@ -48,7 +48,9 @@ class CMP_LIBRARY;
class LIB_COMPONENT; class LIB_COMPONENT;
class LIB_DRAW_ITEM; class LIB_DRAW_ITEM;
class EDA_ITEM; class EDA_ITEM;
class SCH_BUS_ENTRY; class SCH_BUS_ENTRY_BASE;
class SCH_BUS_WIRE_ENTRY;
class SCH_BUS_BUS_ENTRY;
class SCH_GLOBALLABEL; class SCH_GLOBALLABEL;
class SCH_TEXT; class SCH_TEXT;
class SCH_BITMAP; class SCH_BITMAP;
...@@ -811,8 +813,9 @@ private: ...@@ -811,8 +813,9 @@ private:
void UpdateTitle(); void UpdateTitle();
// Bus Entry // Bus Entry
SCH_BUS_ENTRY* CreateBusEntry( wxDC* DC, int entry_type ); SCH_BUS_WIRE_ENTRY* CreateBusWireEntry( wxDC* DC );
void SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY* BusEntry, int entry_type ); SCH_BUS_BUS_ENTRY* CreateBusBusEntry( wxDC* DC );
void SetBusEntryShape( wxDC* DC, SCH_BUS_ENTRY_BASE* BusEntry, char entry_shape );
/** /**
* Function AddNoConnect * Function AddNoConnect
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment