Minor schematic object improvements and code cleaning.

This commit is contained in:
Wayne Stambaugh 2010-11-03 10:13:15 -04:00
parent 3584323840
commit aeb6dd8cc7
22 changed files with 1442 additions and 1243 deletions

View File

@ -4,6 +4,20 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with
email address.
2010-nov-3 UPDATE Wayne Stambaugh <stambaughw@verizon.net>
================================================================================
++common
* Initial ground work for using Boost container for storing draw items
instead of internal linked list.
++EESchema
* Move tests for dangling end code back into schematic objects.
* Add clear draw object state helper to SCH_SCREEN object.
* Add support for schematic objects to keep temporary list of connection
objects for dangling end and other connection related tests.
* Rearrange schematic label object code.
* Remove duplicate error message boxes when loading schematic items.
2010-oct-28, UPDATE Jean-Pierre Charras <jean-pierre.charras@gipsa-lab.inpg.fr>
================================================================================
PolyLine.cpp:

View File

@ -542,6 +542,22 @@ PICKED_ITEMS_LIST* BASE_SCREEN::PopCommandFromRedoList( )
}
void BASE_SCREEN::AddItem( EDA_BaseStruct* aItem )
{
wxCHECK_RET( aItem != NULL, wxT( "Attempt to add NULL item pointer to " ) + GetClass() +
wxT( "item list" ) );
m_items.push_back( aItem );
}
void BASE_SCREEN::InsertItem( EDA_ITEMS::iterator aIter, EDA_BaseStruct* aItem )
{
wxCHECK_RET( aItem != NULL, wxT( "Attempt to insert NULL item pointer to " ) + GetClass() +
wxT( "item list" ) );
m_items.insert( aIter, aItem );
}
#if defined(DEBUG)
/**
* Function Show

View File

@ -19,16 +19,11 @@
// Imported functions:
void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList,
const wxPoint aMoveVector );
void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList,
wxPoint& Center );
void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList,
wxPoint& aMirrorPoint );
void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList,
wxPoint& Center );
void DeleteItemsInList( WinEDA_DrawPanel* panel,
PICKED_ITEMS_LIST& aItemsList );
void MoveItemsInList( PICKED_ITEMS_LIST& aItemsList, const wxPoint aMoveVector );
void RotateListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
void Mirror_X_ListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& aMirrorPoint );
void MirrorListOfItems( PICKED_ITEMS_LIST& aItemsList, wxPoint& Center );
void DeleteItemsInList( WinEDA_DrawPanel* panel, PICKED_ITEMS_LIST& aItemsList );
void DuplicateItemsInList( SCH_SCREEN* screen,
PICKED_ITEMS_LIST& aItemsList,
const wxPoint aMoveVector );
@ -38,9 +33,7 @@ static void AddPickedItem( SCH_SCREEN* screen, wxPoint aPosition );
static LIB_PIN* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem,
wxPoint& aPosition,
bool aSearchFirst );
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel,
wxDC* DC,
bool erase );
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase );
static void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList );
@ -114,8 +107,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
{
wxString msg;
err = TRUE;
msg.Printf( wxT( "HandleBlockPLace() error : no items to place (cmd \
%d, state %d)" ),
msg.Printf( wxT( "HandleBlockPLace() error : no items to place (cmd %d, state %d)" ),
block->m_Command, block->m_State );
DisplayError( this, msg );
}
@ -136,10 +128,7 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
if( DrawPanel->ManageCurseur )
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
SaveCopyInUndoList( block->m_ItemsSelection,
UR_MOVED,
block->m_MoveVector );
SaveCopyInUndoList( block->m_ItemsSelection, UR_MOVED, block->m_MoveVector );
MoveItemsInList( block->m_ItemsSelection, block->m_MoveVector );
block->ClearItemsList();
break;
@ -149,13 +138,10 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
if( DrawPanel->ManageCurseur )
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
DuplicateItemsInList(
GetScreen(), block->m_ItemsSelection, block->m_MoveVector );
DuplicateItemsInList( GetScreen(), block->m_ItemsSelection, block->m_MoveVector );
SaveCopyInUndoList(
block->m_ItemsSelection,
(block->m_Command ==
BLOCK_PRESELECT_MOVE) ? UR_CHANGED : UR_NEW );
SaveCopyInUndoList( block->m_ItemsSelection,
( block->m_Command == BLOCK_PRESELECT_MOVE ) ? UR_CHANGED : UR_NEW );
block->ClearItemsList();
break;
@ -178,12 +164,8 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
OnModify();
/* clear struct.m_Flags */
SCH_ITEM* Struct;
for( Struct = GetScreen()->EEDrawList;
Struct != NULL;
Struct = Struct->Next() )
Struct->m_Flags = 0;
// clear struct.m_Flags.
GetScreen()->ClearDrawingState();
DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL;
@ -196,13 +178,11 @@ void WinEDA_SchematicFrame::HandleBlockPlace( wxDC* DC )
if( block->GetCount() )
{
DisplayError( this,
wxT( "HandleBlockPLace() error: some items left in buffer" ) );
DisplayError( this, wxT( "HandleBlockPLace() error: some items left in buffer" ) );
block->ClearItemsList();
}
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor,
wxEmptyString );
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
DrawPanel->Refresh();
}
@ -288,11 +268,9 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC )
DrawAndSizingBlockOutlines( DrawPanel, DC, FALSE );
if( block->GetCount() )
{
wxPoint move_vector =
-GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
SaveStructListForPaste( block->m_ItemsSelection );
MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection,
move_vector );
MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector );
ii = -1;
}
block->ClearItemsList();
@ -317,12 +295,7 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC )
if( block->m_Command == BLOCK_ABORT )
{
/* clear struct.m_Flags */
EDA_BaseStruct* Struct;
for( Struct = GetScreen()->EEDrawList;
Struct != NULL;
Struct = Struct->Next() )
Struct->m_Flags = 0;
GetScreen()->ClearDrawingState();
}
if( ii <= 0 )
@ -333,9 +306,7 @@ int WinEDA_SchematicFrame::HandleBlockEnd( wxDC* DC )
DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL;
GetScreen()->SetCurItem( NULL );
SetToolID( m_ID_current_state,
DrawPanel->m_PanelDefaultCursor,
wxEmptyString );
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
}
if( zoom_command )
@ -415,8 +386,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
DrawPanel->ManageCurseur( DrawPanel, DC, FALSE );
if( block->GetCount() )
{
wxPoint move_vector =
-GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
wxPoint move_vector = -GetScreen()->m_BlockLocate.m_BlockLastCursorPosition;
SaveStructListForPaste( block->m_ItemsSelection );
MoveItemsInList( g_BlockSaveDataList.m_ItemsSelection, move_vector );
}
@ -424,8 +394,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
case BLOCK_ZOOM: /* Window Zoom */
DrawPanel->ForceCloseManageCurseur( DrawPanel, DC );
DrawPanel->SetCursor(
DrawPanel->m_PanelCursor = DrawPanel->m_PanelDefaultCursor );
DrawPanel->SetCursor( DrawPanel->m_PanelCursor = DrawPanel->m_PanelDefaultCursor );
Window_Zoom( GetScreen()->m_BlockLocate );
break;
@ -439,9 +408,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
/* Compute the rotation center and put it on grid */
wxPoint rotationPoint = block->Centre();
PutOnGrid( &rotationPoint );
SaveCopyInUndoList( block->m_ItemsSelection,
UR_ROTATED,
rotationPoint );
SaveCopyInUndoList( block->m_ItemsSelection, UR_ROTATED, rotationPoint );
RotateListOfItems( block->m_ItemsSelection, rotationPoint );
OnModify();
}
@ -460,9 +427,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
/* Compute the mirror center and put it on grid */
wxPoint mirrorPoint = block->Centre();
PutOnGrid( &mirrorPoint );
SaveCopyInUndoList( block->m_ItemsSelection,
UR_MIRRORED_X,
mirrorPoint );
SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_X, mirrorPoint );
Mirror_X_ListOfItems( block->m_ItemsSelection, mirrorPoint );
OnModify();
// block->m_State = STATE_BLOCK_MOVE;
@ -481,9 +446,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
/* Compute the mirror center and put it on grid */
wxPoint mirrorPoint = block->Centre();
PutOnGrid( &mirrorPoint );
SaveCopyInUndoList( block->m_ItemsSelection,
UR_MIRRORED_Y,
mirrorPoint );
SaveCopyInUndoList( block->m_ItemsSelection, UR_MIRRORED_Y, mirrorPoint );
MirrorListOfItems( block->m_ItemsSelection, mirrorPoint );
OnModify();
// block->m_State = STATE_BLOCK_MOVE;
@ -506,9 +469,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
DrawPanel->ManageCurseur = NULL;
DrawPanel->ForceCloseManageCurseur = NULL;
GetScreen()->SetCurItem( NULL );
SetToolID( m_ID_current_state,
DrawPanel->m_PanelDefaultCursor,
wxEmptyString );
SetToolID( m_ID_current_state, DrawPanel->m_PanelDefaultCursor, wxEmptyString );
}
}
@ -516,8 +477,7 @@ void WinEDA_SchematicFrame::HandleBlockEndByPopUp( int Command, wxDC* DC )
/* Traces the outline of the search block structures
* The entire block follows the cursor
*/
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
bool erase )
static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
{
BLOCK_SELECTOR* block = &panel->GetScreen()->m_BlockLocate;;
@ -555,9 +515,7 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC,
*/
void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )
{
g_BlockSaveDataList.ClearListAndDeleteItems(); // delete previous
// saved list, if
// exists
g_BlockSaveDataList.ClearListAndDeleteItems(); // delete previous saved list, if exists
/* save the new list: */
ITEM_PICKER item;
@ -569,8 +527,7 @@ void SaveStructListForPaste( PICKED_ITEMS_LIST& aItemsList )
for( unsigned ii = 0; ii < aItemsList.GetCount(); ii++ )
{
/* Make a copy of the original picked item. */
SCH_ITEM* DrawStructCopy = DuplicateStruct(
(SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
SCH_ITEM* DrawStructCopy = DuplicateStruct( (SCH_ITEM*) aItemsList.GetPickedItem( ii ) );
DrawStructCopy->SetParent( NULL );
item.m_PickedItem = DrawStructCopy;
g_BlockSaveDataList.PushItem( item );
@ -599,8 +556,7 @@ void WinEDA_SchematicFrame::PasteListOfItems( wxDC* DC )
for( unsigned ii = 0; ii < g_BlockSaveDataList.GetCount(); ii++ )
{
Struct = DuplicateStruct(
(SCH_ITEM*) g_BlockSaveDataList.m_ItemsSelection.GetPickedItem(
ii ) );
(SCH_ITEM*) g_BlockSaveDataList.m_ItemsSelection.GetPickedItem( ii ) );
picker.m_PickedItem = Struct;
picklist.PushItem( picker );
@ -621,10 +577,7 @@ void WinEDA_SchematicFrame::PasteListOfItems( wxDC* DC )
MoveItemsInList( picklist, GetScreen()->m_BlockLocate.m_MoveVector );
/* clear .m_Flags member for all items */
for( Struct = GetScreen()->EEDrawList;
Struct != NULL;
Struct = Struct->Next() )
Struct->m_Flags = 0;
GetScreen()->ClearDrawingState();
OnModify();
@ -646,11 +599,7 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
if( pickedlist->GetCount() == 0 )
return;
/* .m_Flags member is used to handle how a wire is exactly selected
* (fully selected, or partially selected by an end point )
*/
for( Struct = screen->EEDrawList; Struct != NULL; Struct = Struct->Next() )
Struct->m_Flags = 0;
screen->ClearDrawingState();
for( unsigned ii = 0; ii < pickedlist->GetCount(); ii++ )
{
@ -724,7 +673,8 @@ static void CollectStructsToDrag( SCH_SCREEN* screen )
SCH_SHEET* sheet = (SCH_SHEET*) Struct;
// Add all pins sheets of a selected hierarchical sheet to the list
BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() ) {
BOOST_FOREACH( SCH_SHEET_PIN label, sheet->GetSheetPins() )
{
AddPickedItem( screen, label.m_Pos );
}
}

View File

@ -898,6 +898,70 @@ void SCH_SHEET::renumberLabels()
}
void SCH_SHEET::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
// Using BOOST_FOREACH here creates problems (bad pointer value to pinsheet).
// I do not know why.
for( unsigned ii = 0; ii < GetSheetPins().size(); ii++ )
{
SCH_SHEET_PIN &pinsheet = GetSheetPins()[ii];
wxCHECK2_MSG( pinsheet.Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE, continue,
wxT( "Invalid item in schematic sheet pin list. Bad programmer!" ) );
pinsheet.GetEndPoints( aItemList );
}
}
bool SCH_SHEET::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList )
{
bool currentState = IsDangling();
BOOST_FOREACH( SCH_SHEET_PIN& pinsheet, GetSheetPins() )
{
pinsheet.IsDanglingStateChanged( aItemList );
}
return currentState != IsDangling();
}
bool SCH_SHEET::IsDangling() const
{
// If any hierarchical label in the sheet is dangling, then the sheet is dangling.
for( size_t i = 0; i < GetSheetPins().size(); i++ )
{
if( GetSheetPins()[i].IsDangling() )
return true;
}
return false;
}
bool SCH_SHEET::IsSelectStateChanged( const wxRect& aRect )
{
bool previousState = IsSelected();
EDA_Rect boundingBox = GetBoundingBox();
if( aRect.Intersects( boundingBox ) )
m_Flags |= SELECTED;
else
m_Flags &= ~SELECTED;
return previousState != IsSelected();
}
void SCH_SHEET::GetConnectionPoints( vector< wxPoint >& aPoints ) const
{
for( size_t i = 0; i < GetSheetPins().size(); i++ )
aPoints.push_back( GetSheetPins()[i].m_Pos );
}
#if defined(DEBUG)
void SCH_SHEET::Show( int nestLevel, std::ostream& os )

View File

@ -23,7 +23,6 @@ extern SCH_SHEET* g_RootSheet;
* the sheet, it corresponds to a hierarchical label.
*/
//class SCH_SHEET_PIN : public SCH_ITEM, public EDA_TextStruct
class SCH_SHEET_PIN : public SCH_HIERLABEL
{
private:
@ -31,15 +30,15 @@ private:
///< Sheet label numbering begins at 2.
///< 0 is reserved for the sheet name.
///< 1 is reserve for the sheet file name.
int m_Edge; /* For pin labels only: sheet edge (0 to 3) of the pin
* m_Edge define on which edge the pin is positionned:
* 0: pin on left side
* 1: pin on right side
* 2: pin on top side
* 3: pin on bottom side
* for compatibility reasons, this does not follow same values as text
* orientation.
*/
int m_Edge; /* For pin labels only: sheet edge (0 to 3) of the pin
* m_Edge define on which edge the pin is positionned:
* 0: pin on left side
* 1: pin on right side
* 2: pin on top side
* 3: pin on bottom side
* for compatibility reasons, this does not follow same values as text
* orientation.
*/
public:
SCH_SHEET_PIN( SCH_SHEET* parent,
@ -168,8 +167,9 @@ public:
* @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
* @return True if this item matches the search criteria.
*/
virtual bool Matches( wxFindReplaceData& aSearchData,
void* aAuxData, wxPoint * aFindLocation );
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
};
@ -251,6 +251,11 @@ public:
SCH_SHEET_PIN_LIST& GetSheetPins() { return m_labels; }
SCH_SHEET_PIN_LIST& GetSheetPins() const
{
return const_cast< SCH_SHEET_PIN_LIST& >( m_labels );
}
/**
* Remove a sheet label from this sheet.
*
@ -412,7 +417,9 @@ public:
virtual void Move( const wxPoint& aMoveVector )
{
m_Pos += aMoveVector;
BOOST_FOREACH( SCH_SHEET_PIN & label, m_labels ) {
BOOST_FOREACH( SCH_SHEET_PIN & label, m_labels )
{
label.Move( aMoveVector );
}
}
@ -437,8 +444,7 @@ public:
*
* @return True if this item matches the search criteria.
*/
virtual bool Matches( wxFindReplaceData& aSearchData,
void* aAuxData, wxPoint * aFindLocation );
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
/**
* Resize this sheet to aSize and adjust all of the labels accordingly.
@ -457,6 +463,16 @@ public:
*/
wxPoint GetFileNamePosition ();
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList );
virtual bool IsDangling() const;
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
#if defined(DEBUG)
// comment inherited by Doxygen from Base_Struct

View File

@ -340,6 +340,46 @@ void SCH_SHEET_PIN::Rotate( wxPoint rotationPoint )
}
/** Virtual Function SCH_SHEET_PIN::CreateGraphicShape
* calculates the graphic shape (a polygon) associated to the text
* @param aCorner_list = a buffer to fill with polygon corners coordinates
* @param aPos = Position of the shape
*/
void SCH_SHEET_PIN::CreateGraphicShape( std::vector <wxPoint>& aCorner_list,
const wxPoint& aPos )
{
/* This is the same icon shapes as SCH_HIERLABEL
* but the graphic icon is slightly different in 2 cases:
* for INPUT type the icon is the OUTPUT shape of SCH_HIERLABEL
* for OUTPUT type the icon is the INPUT shape of SCH_HIERLABEL
*/
int tmp = m_Shape;
switch( m_Shape )
{
case NET_INPUT:
m_Shape = NET_OUTPUT;
break;
case NET_OUTPUT:
m_Shape = NET_INPUT;
break;
default:
break;
}
SCH_HIERLABEL::CreateGraphicShape( aCorner_list, aPos );
m_Shape = tmp;
}
void SCH_SHEET_PIN::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
DANGLING_END_ITEM item( SHEET_LABEL_END, this );
item.m_Pos = m_Pos;
aItemList.push_back( item );
}
#if defined(DEBUG)
void SCH_SHEET_PIN::Show( int nestLevel, std::ostream& os )
{

View File

@ -180,3 +180,16 @@ void SCH_MARKER::Mirror_Y( int aYaxis_position )
m_Pos.x = -m_Pos.x;
m_Pos.x += aYaxis_position;
}
bool SCH_MARKER::IsSelectStateChanged( const wxRect& aRect )
{
bool previousState = IsSelected();
if( aRect.Contains( m_Pos ) )
m_Flags |= SELECTED;
else
m_Flags &= ~SELECTED;
return previousState != IsSelected();
}

View File

@ -116,6 +116,8 @@ public:
*/
void DisplayInfo( WinEDA_DrawFrame* aFrame );
virtual bool IsSelectStateChanged( const wxRect& aRect );
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );

View File

@ -973,9 +973,9 @@ bool SCH_COMPONENT::Save( FILE* f ) const
if( GetField( REFERENCE )->m_Text.IsEmpty() )
strncpy( Name1, CONV_TO_UTF8( m_PrefixString ), sizeof( Name1 ) );
else
strncpy( Name1, CONV_TO_UTF8( GetField( REFERENCE )->m_Text ),
sizeof( Name1 ) );
strncpy( Name1, CONV_TO_UTF8( GetField( REFERENCE )->m_Text ), sizeof( Name1 ) );
}
for( ii = 0; ii < (int) strlen( Name1 ); ii++ )
{
#if defined(KICAD_GOST)
@ -1284,3 +1284,77 @@ bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxP
return false;
}
void SCH_COMPONENT::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
if( Entry == NULL )
return;
for( LIB_PIN* Pin = Entry->GetNextPin(); Pin != NULL; Pin = Entry->GetNextPin( Pin ) )
{
wxASSERT( Pin->Type() == COMPONENT_PIN_DRAW_TYPE );
if( Pin->GetUnit() && m_Multi && ( m_Multi != Pin->GetUnit() ) )
continue;
if( Pin->GetConvert() && m_Convert && ( m_Convert != Pin->GetConvert() ) )
continue;
DANGLING_END_ITEM item( PIN_END, Pin );
item.m_Pos = GetPinPhysicalPosition( Pin );
aItemList.push_back( item );
}
}
wxPoint SCH_COMPONENT::GetPinPhysicalPosition( LIB_PIN* Pin )
{
wxCHECK_MSG( Pin != NULL && Pin->Type() == COMPONENT_PIN_DRAW_TYPE, wxPoint( 0, 0 ),
wxT( "Cannot get physical position of pin." ) );
return m_Transform.TransformCoordinate( Pin->m_Pos ) + m_Pos;
}
bool SCH_COMPONENT::IsSelectStateChanged( const wxRect& aRect )
{
bool previousState = IsSelected();
EDA_Rect boundingBox = GetBoundingBox();
if( aRect.Intersects( boundingBox ) )
m_Flags |= SELECTED;
else
m_Flags &= ~SELECTED;
return previousState != IsSelected();
}
void SCH_COMPONENT::GetConnectionPoints( vector< wxPoint >& aPoints ) const
{
LIB_PIN* pin;
LIB_COMPONENT* component = CMP_LIBRARY::FindLibraryComponent( m_ChipName );
wxCHECK_RET( component != NULL,
wxT( "Cannot add connection points to list. Cannot find component <" ) +
m_ChipName + wxT( "> in any of the loaded libraries." ) );
for( pin = component->GetNextPin( pin ); pin != NULL; pin = component->GetNextPin( pin ) )
{
wxCHECK_RET( pin->Type() == COMPONENT_PIN_DRAW_TYPE,
wxT( "GetNextPin() did not return a pin object. Bad programmer!" ) );
// Skip items not used for this part.
if( m_Multi && pin->GetUnit() && ( pin->GetUnit() != m_Multi ) )
continue;
if( m_Convert && pin->GetConvert() && ( pin->GetConvert() != m_Convert ) )
continue;
// Calculate the pin position relative to the component position and orientation.
aPoints.push_back( m_Transform.TransformCoordinate( pin->m_Pos ) + m_Pos );
}
}

View File

@ -1,6 +1,6 @@
/*****************************************************/
/******************************************************/
/* Definitions for the Component classes for EESchema */
/*****************************************************/
/******************************************************/
#ifndef COMPONENT_CLASS_H
#define COMPONENT_CLASS_H
@ -85,8 +85,7 @@ private:
void Init( const wxPoint& pos = wxPoint( 0, 0 ) );
public:
SCH_COMPONENT( const wxPoint& pos = wxPoint( 0, 0 ),
SCH_ITEM* aParent = NULL );
SCH_COMPONENT( const wxPoint& pos = wxPoint( 0, 0 ), SCH_ITEM* aParent = NULL );
/**
* Create schematic component from library component object.
@ -122,6 +121,7 @@ public:
return wxT( "SCH_COMPONENT" );
}
TRANSFORM& GetTransform() const { return const_cast< TRANSFORM& >( m_Transform ); }
/**
* Function Save
@ -312,8 +312,7 @@ public:
int GetUnitSelection( SCH_SHEET_PATH* aSheet );
// Set the unit selection, for the given sheet path.
void SetUnitSelection( SCH_SHEET_PATH* aSheet,
int aUnitSelection );
void SetUnitSelection( SCH_SHEET_PATH* aSheet, int aUnitSelection );
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
@ -355,8 +354,15 @@ public:
* @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
* @return True if this component reference or value field matches the search criteria.
*/
virtual bool Matches( wxFindReplaceData& aSearchData,
void* aAuxData, wxPoint * aFindLocation );
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
wxPoint GetPinPhysicalPosition( LIB_PIN* Pin );
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
#if defined(DEBUG)

View File

@ -353,6 +353,13 @@ void SCH_SCREEN::ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount
}
void SCH_SCREEN::ClearDrawingState()
{
for( SCH_ITEM* item = EEDrawList; item != NULL; item = item->Next() )
item->m_Flags = 0;
}
/******************************************************************/
/* Class SCH_SCREENS to handle the list of screens in a hierarchy */
/******************************************************************/

View File

@ -167,12 +167,45 @@ void SCH_BUS_ENTRY::Rotate( wxPoint rotationPoint )
}
void SCH_BUS_ENTRY::GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList )
{
DANGLING_END_ITEM item( ENTRY_END, this );
item.m_Pos = m_Pos;
DANGLING_END_ITEM item1( ENTRY_END, this );
item1.m_Pos = m_End();
aItemList.push_back( item );
aItemList.push_back( item1 );
}
bool SCH_BUS_ENTRY::IsSelectStateChanged( const wxRect& aRect )
{
bool previousState = IsSelected();
// 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.
if( aRect.Contains( m_Pos ) || aRect.Contains( m_End() ) )
m_Flags |= SELECTED;
else
m_Flags &= ~SELECTED;
return previousState != IsSelected();
}
void SCH_BUS_ENTRY::GetConnectionPoints( vector< wxPoint >& aPoints ) const
{
aPoints.push_back( m_Pos );
aPoints.push_back( m_End() );
}
/**********************/
/* class SCH_JUNCTION */
/**********************/
SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) :
SCH_ITEM( NULL, DRAW_JUNCTION_STRUCT_TYPE )
SCH_JUNCTION::SCH_JUNCTION( const wxPoint& pos ) : SCH_ITEM( NULL, DRAW_JUNCTION_STRUCT_TYPE )
{
#define DRAWJUNCTION_DIAMETER 32 /* Diameter of junction symbol between wires */
m_Pos = pos;
@ -289,6 +322,33 @@ void SCH_JUNCTION::Rotate( wxPoint rotationPoint )
}
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 );
}
#if defined(DEBUG)
void SCH_JUNCTION::Show( int nestLevel, std::ostream& os )
{
@ -306,8 +366,7 @@ void SCH_JUNCTION::Show( int nestLevel, std::ostream& os )
/* class SCH_NO_CONNECT */
/************************/
SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) :
SCH_ITEM( NULL, DRAW_NOCONNECT_STRUCT_TYPE )
SCH_NO_CONNECT::SCH_NO_CONNECT( const wxPoint& pos ) : SCH_ITEM( NULL, DRAW_NOCONNECT_STRUCT_TYPE )
{
#define DRAWNOCONNECT_SIZE 48 /* No symbol connection range. */
m_Pos = pos;
@ -430,6 +489,25 @@ void SCH_NO_CONNECT::Rotate( wxPoint rotationPoint )
}
bool SCH_NO_CONNECT::IsSelectStateChanged( const wxRect& aRect )
{
bool previousState = IsSelected();
if( aRect.Contains( m_Pos ) )
m_Flags |= SELECTED;
else
m_Flags &= ~SELECTED;
return previousState != IsSelected();
}
void SCH_NO_CONNECT::GetConnectionPoints( vector< wxPoint >& aPoints ) const
{
aPoints.push_back( m_Pos );
}
/******************/
/* Class SCH_LINE */
/******************/
@ -634,9 +712,7 @@ bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
wxCHECK_MSG( aLine != NULL && aLine->Type() == DRAW_SEGMENT_STRUCT_TYPE, false,
wxT( "Cannot test line segment for overlap." ) );
if( this == aLine )
return false;
if( GetLayer() != aLine->GetLayer() )
if( this == aLine || GetLayer() != aLine->GetLayer() )
return false;
// Search for a common end, and modify coordinates to ensure RefSegm->m_End
@ -658,8 +734,10 @@ bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
EXCHG( aLine->m_Start, aLine->m_End );
}
else if( m_End != aLine->m_Start )
{
// No common end point, segments cannot be merged.
return false;
}
/* Test alignment: */
if( m_Start.y == m_End.y ) // Horizontal segment
@ -693,12 +771,86 @@ bool SCH_LINE::MergeOverlap( SCH_LINE* aLine )
}
/***********************/
/* Class SCH_POLYLINE */
/***********************/
void SCH_LINE::GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList )
{
if( GetLayer() == LAYER_NOTES )
return;
SCH_POLYLINE::SCH_POLYLINE( int layer ) :
SCH_ITEM( NULL, DRAW_POLYLINE_STRUCT_TYPE )
if( ( GetLayer() == LAYER_BUS ) || ( GetLayer() == LAYER_WIRE ) )
{
DANGLING_END_ITEM item( (GetLayer() == LAYER_BUS) ? BUS_START_END : WIRE_START_END, this );
item.m_Pos = m_Start;
DANGLING_END_ITEM item1( (GetLayer() == LAYER_BUS) ? BUS_END_END : WIRE_END_END, this );
item1.m_Pos = m_End;
aItemList.push_back( item );
aItemList.push_back( item1 );
}
}
bool SCH_LINE::IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList )
{
bool previousStartState = m_StartIsDangling;
bool previousEndState = m_EndIsDangling;
if( GetLayer() == LAYER_WIRE )
{
BOOST_FOREACH( DANGLING_END_ITEM item, aItemList )
{
if( item.m_Item == this )
continue;
if( m_Start == item.m_Pos )
m_StartIsDangling = false;
if( m_End == item.m_Pos )
m_EndIsDangling = false;
if( (m_StartIsDangling == false) && (m_EndIsDangling == false) )
break;
}
}
else if( GetLayer() == LAYER_BUS || GetLayer() == LAYER_NOTES )
{
// Lines on the notes layer and the bus layer cannot be tested for dangling ends.
previousStartState = previousEndState = m_StartIsDangling = m_EndIsDangling = false;
}
return ( previousStartState != m_StartIsDangling ) || ( previousEndState != m_EndIsDangling );
}
bool SCH_LINE::IsSelectStateChanged( const wxRect& aRect )
{
bool previousState = IsSelected();
if( aRect.Contains( m_Start ) )
m_Flags |= STARTPOINT | SELECTED;
else
m_Flags &= ~( STARTPOINT | SELECTED );
if( aRect.Contains( m_End ) )
m_Flags |= ENDPOINT | SELECTED;
else
m_Flags &= ~( ENDPOINT | SELECTED );
return previousState != IsSelected();
}
void SCH_LINE::GetConnectionPoints( vector< wxPoint >& aPoints ) const
{
aPoints.push_back( m_Start );
aPoints.push_back( m_End );
}
/**********************/
/* Class SCH_POLYLINE */
/**********************/
SCH_POLYLINE::SCH_POLYLINE( int layer ) : SCH_ITEM( NULL, DRAW_POLYLINE_STRUCT_TYPE )
{
m_Width = 0;

View File

@ -108,6 +108,16 @@ public:
*/
bool MergeOverlap( SCH_LINE* aLine );
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList );
virtual bool IsDangling() const { return m_StartIsDangling || m_EndIsDangling; }
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );
@ -185,6 +195,10 @@ public:
virtual void Mirror_Y( int aYaxis_position );
virtual void Mirror_X( int aXaxis_position );
virtual void Rotate( wxPoint rotationPoint );
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
};
@ -259,6 +273,12 @@ public:
virtual void Mirror_Y( int aYaxis_position );
virtual void Mirror_X( int aXaxis_position );
virtual void Rotate( wxPoint rotationPoint );
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
};
class SCH_POLYLINE : public SCH_ITEM
@ -405,6 +425,12 @@ public:
virtual void Mirror_X( int aXaxis_position );
virtual void Rotate( wxPoint rotationPoint );
virtual void GetEndPoints( std::vector <DANGLING_END_ITEM>& aItemList );
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );

File diff suppressed because it is too large Load Diff

View File

@ -167,8 +167,17 @@ public:
* @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
* @return True if this schematic text item matches the search criteria.
*/
virtual bool Matches( wxFindReplaceData& aSearchData,
void* aAuxData, wxPoint * aFindLocation );
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation );
virtual void GetEndPoints( std::vector< DANGLING_END_ITEM >& aItemList );
virtual bool IsDanglingStateChanged( std::vector< DANGLING_END_ITEM >& aItemList );
virtual bool IsDangling() const { return m_IsDangling; }
virtual bool IsSelectStateChanged( const wxRect& aRect );
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const;
#if defined(DEBUG)
void Show( int nestLevel, std::ostream& os );

View File

@ -4,55 +4,14 @@
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
#include "program.h"
#include "general.h"
#include "netlist.h"
#include "protos.h"
#include "class_library.h"
#include "class_libentry.h"
#include "lib_pin.h"
enum End_Type {
UNKNOWN = 0,
WIRE_START_END,
WIRE_END_END,
BUS_START_END,
BUS_END_END,
JUNCTION_END,
PIN_END,
LABEL_END,
ENTRY_END,
SHEET_LABEL_END
};
// A helper class to store a list of items that can be connected to something:
class DANGLING_END_ITEM
{
public:
const void* m_Item; // a pointer to the parent
wxPoint m_Pos; // the position of the connecting point
int m_Type; // type of parent
DANGLING_END_ITEM( int type, const void* aItem )
{
m_Item = aItem;
m_Type = type;
}
};
static void TestWireForDangling( std::vector <DANGLING_END_ITEM>& aItemList,
SCH_LINE* DrawRef,
WinEDA_SchematicFrame* frame,
wxDC* aDC );
void TestLabelForDangling( std::vector <DANGLING_END_ITEM>& aItemList,
SCH_TEXT* aLabel,
WinEDA_SchematicFrame* aFrame,
wxDC* aDC );
void RebuildEndPointsList( std::vector <DANGLING_END_ITEM>& aItemList, SCH_ITEM* aDrawList );
/* Returns true if the point P is on the segment S. */
bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint )
{
@ -64,60 +23,27 @@ bool SegmentIntersect( wxPoint aSegStart, wxPoint aSegEnd, wxPoint aTestPoint )
return false; /* Cross product non-zero, vectors not parallel */
if( ( (long long) vectSeg.x * vectPoint.x + (long long) vectSeg.y * vectPoint.y ) <
( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
( (long long) vectPoint.x * vectPoint.x + (long long) vectPoint.y * vectPoint.y ) )
return false; /* Point not on segment */
return true;
}
void WinEDA_SchematicFrame::TestDanglingEnds( SCH_ITEM* DrawList, wxDC* DC )
void WinEDA_SchematicFrame::TestDanglingEnds( SCH_ITEM* aDrawList, wxDC* aDC )
{
// this list is static to avoid many useles memory allocation.
std::vector <DANGLING_END_ITEM> itemList;
SCH_ITEM* item;
std::vector< DANGLING_END_ITEM > endPoints;
RebuildEndPointsList( itemList, DrawList );
for( item = aDrawList; item != NULL; item = item->Next() )
item->GetEndPoints( endPoints );
for( SCH_ITEM* item = DrawList; item; item = item->Next() )
for( item = aDrawList; item; item = item->Next() )
{
switch( item->Type() )
if( item->IsDanglingStateChanged( endPoints ) && aDC != NULL )
{
case TYPE_SCH_GLOBALLABEL:
case TYPE_SCH_HIERLABEL:
case TYPE_SCH_LABEL:
TestLabelForDangling( itemList, (SCH_LABEL*) item, this, DC );
break;
case DRAW_SHEET_STRUCT_TYPE:
{
SCH_SHEET* sheet = (SCH_SHEET*) item;
// Read the hierarchical pins list and teast for dangling pins:
BOOST_FOREACH( SCH_SHEET_PIN & pinsheet, sheet->GetSheetPins() )
{
TestLabelForDangling( itemList, &pinsheet, this, DC );
}
}
break;
case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT
#define STRUCT ( (SCH_LINE*) item )
if( STRUCT->GetLayer() == LAYER_WIRE )
{
TestWireForDangling( itemList, STRUCT, this, DC );
break;
}
if( STRUCT->GetLayer() == LAYER_NOTES )
break;
if( STRUCT->GetLayer() == LAYER_BUS )
{
STRUCT->m_StartIsDangling = STRUCT->m_EndIsDangling = false;
break;
}
break;
default:
break;
RedrawOneStruct( DrawPanel, aDC, item, g_XorMode );
RedrawOneStruct( DrawPanel, aDC, item, GR_DEFAULT_DRAWMODE );
}
}
}
@ -129,8 +55,7 @@ void WinEDA_SchematicFrame::TestDanglingEnds( SCH_ITEM* DrawList, wxDC* DC )
* @param DrawList = List of SCH_ITEMs to check.
* @return a LIB_PIN pointer to the located pin or NULL if no pin was found.
*/
LIB_PIN* WinEDA_SchematicFrame::LocatePinEnd( SCH_ITEM* DrawList,
const wxPoint& pos )
LIB_PIN* WinEDA_SchematicFrame::LocatePinEnd( SCH_ITEM* DrawList, const wxPoint& pos )
{
SCH_COMPONENT* DrawLibItem;
LIB_PIN* Pin;
@ -153,234 +78,3 @@ LIB_PIN* WinEDA_SchematicFrame::LocatePinEnd( SCH_ITEM* DrawList,
return Pin;
return NULL;
}
void TestWireForDangling( std::vector <DANGLING_END_ITEM>& aItemList,
SCH_LINE* DrawRef,
WinEDA_SchematicFrame* frame,
wxDC* DC )
{
bool Sdangstate = true, Edangstate = true;
BOOST_FOREACH( DANGLING_END_ITEM terminal_item, aItemList )
{
if( terminal_item.m_Item == DrawRef )
continue;
if( DrawRef->m_Start == terminal_item.m_Pos )
Sdangstate = false;
if( DrawRef->m_End == terminal_item.m_Pos )
Edangstate = false;
if( (Sdangstate == false) && (Edangstate == false) )
break;
}
if( (Sdangstate != DrawRef->m_StartIsDangling)
|| (Edangstate != DrawRef->m_EndIsDangling) )
{
if( DC )
RedrawOneStruct( frame->DrawPanel, DC, DrawRef, g_XorMode );
DrawRef->m_StartIsDangling = Sdangstate;
DrawRef->m_EndIsDangling = Edangstate;
if( DC )
RedrawOneStruct( frame->DrawPanel, DC, DrawRef,
GR_DEFAULT_DRAWMODE );
}
}
void TestLabelForDangling( std::vector <DANGLING_END_ITEM>& aItemList,
SCH_TEXT* aLabel,
WinEDA_SchematicFrame* aFrame,
wxDC* aDC )
{
bool dangstate = true;
for( unsigned ii = 0; ii < aItemList.size(); ii++ )
{
DANGLING_END_ITEM & terminal_item = aItemList[ii];
if( terminal_item.m_Item == aLabel )
continue;
switch( terminal_item.m_Type )
{
case PIN_END:
case LABEL_END:
case SHEET_LABEL_END:
if( aLabel->m_Pos == terminal_item.m_Pos )
dangstate = false;
break;
case WIRE_START_END:
case BUS_START_END:
{
// these schematic items have created 2 DANGLING_END_ITEM
// one per end.
ii++;
DANGLING_END_ITEM & next_terminal = aItemList[ii];
dangstate = !SegmentIntersect( terminal_item.m_Pos,
next_terminal.m_Pos,
aLabel->m_Pos );
}
break;
case UNKNOWN:
case JUNCTION_END:
case ENTRY_END:
case WIRE_END_END:
case BUS_END_END:
break;
}
if( dangstate == false )
break;
}
if( dangstate != aLabel->m_IsDangling )
{
if( aDC )
RedrawOneStruct( aFrame->DrawPanel, aDC, aLabel, g_XorMode );
aLabel->m_IsDangling = dangstate;
if( aDC )
RedrawOneStruct( aFrame->DrawPanel, aDC, aLabel, GR_DEFAULT_DRAWMODE );
}
}
/* Returns the physical position of the pin relative to the component
* orientation. */
wxPoint ReturnPinPhysicalPosition( LIB_PIN* Pin, SCH_COMPONENT* DrawLibItem )
{
wxPoint PinPos = Pin->m_Pos;
if( DrawLibItem == NULL )
NEGATE( PinPos.y );
else
PinPos = DrawLibItem->m_Transform.TransformCoordinate( Pin->m_Pos ) + DrawLibItem->m_Pos;
return PinPos;
}
void RebuildEndPointsList( std::vector <DANGLING_END_ITEM>& aItemList, SCH_ITEM* aDrawList )
{
SCH_ITEM* schItem;
aItemList.clear();
for( schItem = aDrawList; schItem != NULL; schItem = schItem->Next() )
{
switch( schItem->Type() )
{
case TYPE_SCH_LABEL:
case TYPE_SCH_GLOBALLABEL:
case TYPE_SCH_HIERLABEL:
{
#undef STRUCT
#define STRUCT ( (SCH_LABEL*) schItem )
DANGLING_END_ITEM item( LABEL_END, schItem );
item.m_Pos = STRUCT->m_Pos;
aItemList.push_back( item );
}
break;
case DRAW_SEGMENT_STRUCT_TYPE:
#undef STRUCT
#define STRUCT ( (SCH_LINE*) schItem )
if( STRUCT->GetLayer() == LAYER_NOTES )
break;
if( ( STRUCT->GetLayer() == LAYER_BUS )
|| (STRUCT->GetLayer() == LAYER_WIRE ) )
{
DANGLING_END_ITEM item( (STRUCT->GetLayer() == LAYER_BUS) ?
BUS_START_END : WIRE_START_END, schItem );
item.m_Pos = STRUCT->m_Start;
DANGLING_END_ITEM item1( (STRUCT->GetLayer() == LAYER_BUS) ?
BUS_END_END : WIRE_END_END, schItem );
item1.m_Pos = STRUCT->m_End;
aItemList.push_back( item );
aItemList.push_back( item1 );
}
break;
case DRAW_JUNCTION_STRUCT_TYPE:
{
#undef STRUCT
#define STRUCT ( (SCH_JUNCTION*) schItem )
DANGLING_END_ITEM item( JUNCTION_END, schItem );
item.m_Pos = STRUCT->m_Pos;
aItemList.push_back( item );
}
break;
case DRAW_BUSENTRY_STRUCT_TYPE:
{
#undef STRUCT
#define STRUCT ( (SCH_BUS_ENTRY*) schItem )
DANGLING_END_ITEM item( ENTRY_END, schItem );
item.m_Pos = STRUCT->m_Pos;
DANGLING_END_ITEM item1( ENTRY_END, schItem );
item1.m_Pos = STRUCT->m_End();
aItemList.push_back( item );
aItemList.push_back( item1 );
}
break;
case TYPE_SCH_COMPONENT:
{
#undef STRUCT
#define STRUCT ( (SCH_COMPONENT*) schItem )
LIB_COMPONENT* Entry;
Entry = CMP_LIBRARY::FindLibraryComponent( STRUCT->m_ChipName );
if( Entry == NULL )
break;
for( LIB_PIN* Pin = Entry->GetNextPin(); Pin != NULL;
Pin = Entry->GetNextPin( Pin ) )
{
wxASSERT( Pin->Type() == COMPONENT_PIN_DRAW_TYPE );
if( Pin->GetUnit() && STRUCT->m_Multi && ( STRUCT->m_Multi != Pin->GetUnit() ) )
continue;
if( Pin->GetConvert() && STRUCT->m_Convert
&& ( STRUCT->m_Convert != Pin->GetConvert() ) )
continue;
DANGLING_END_ITEM item( PIN_END, Pin );
item.m_Pos = ReturnPinPhysicalPosition( Pin, STRUCT );
aItemList.push_back( item );
}
break;
}
case DRAW_SHEET_STRUCT_TYPE:
{
SCH_SHEET* sheet = (SCH_SHEET*) schItem;
// Using BOOST_FOREACH here creates problems (bad pointer value to pinsheet).
// I do not know why.
for( unsigned ii = 0; ii < sheet->GetSheetPins().size(); ii++ )
{
SCH_SHEET_PIN &pinsheet = sheet->GetSheetPins()[ii];
wxASSERT( pinsheet.Type() == DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE );
DANGLING_END_ITEM item( SHEET_LABEL_END, &pinsheet );
item.m_Pos = pinsheet.m_Pos;
aItemList.push_back( item );
}
}
break;
default:
;
}
}
}

View File

@ -16,11 +16,11 @@
/* in read_from_file_schematic_items_description.cpp */
SCH_ITEM* ReadTextDescr( LINE_READER* aLine, wxString& aMsgDiag, int aSchematicFileVersion );
int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
int ReadSheetDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
bool ReadSchemaDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
int ReadPartDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
int ReadPartDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window );
static void LoadLayers( LINE_READER* aLine );
@ -29,8 +29,7 @@ static void LoadLayers( LINE_READER* aLine );
* Routine to load an EESchema file.
* Returns true if file has been loaded (at least partially.)
*/
bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen,
const wxString& FullFileName )
bool WinEDA_SchematicFrame::LoadOneEEFile( SCH_SCREEN* screen, const wxString& FullFileName )
{
char Name1[256],
Name2[256];
@ -122,13 +121,13 @@ again." );
{
case '$': // identification block
if( line[1] == 'C' )
Failed = ReadPartDescr( this, &reader, MsgDiag, screen );
Failed = ReadPartDescr( &reader, MsgDiag, screen );
else if( line[1] == 'S' )
Failed = ReadSheetDescr( this, &reader, MsgDiag, screen );
Failed = ReadSheetDescr( &reader, MsgDiag, screen );
else if( line[1] == 'D' )
Failed = ReadSchemaDescr( this, &reader, MsgDiag, screen );
Failed = ReadSchemaDescr( &reader, MsgDiag, screen );
else if( line[1] == 'T' ) // text part
{
@ -148,7 +147,7 @@ again." );
break;
case 'L': // Its a library item.
Failed = ReadPartDescr( this, &reader, MsgDiag, screen );
Failed = ReadPartDescr( &reader, MsgDiag, screen );
break;
case 'W': // Its a Segment (WIRE or BUS) item.

View File

@ -175,7 +175,7 @@ SCH_ITEM* ReadTextDescr( LINE_READER* aLine, wxString& aMsgDiag, int aSchematicF
/* Function used by LoadEEFile().
* Get the lines for a description of a piece of hierarchy.
*/
int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
int ReadSheetDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
{
int ii, fieldNdx, size;
char Name1[256], Char1[256], Char2[256];
@ -286,7 +286,6 @@ int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BAS
aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( line );
DisplayError( frame, aMsgDiag );
}
if( size == 0 )
size = DEFAULT_SIZE_TEXT;
@ -316,7 +315,6 @@ int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BAS
aMsgDiag.Printf( wxT( "EESchema file sheet label error at line %d, ignoring.\n" ),
aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( line );
DisplayError( frame, aMsgDiag );
continue;
}
@ -391,7 +389,7 @@ int ReadSheetDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BAS
/* Read the schematic header. */
bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
bool ReadSchemaDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
{
char Text[256], buf[1024];
int ii;
@ -427,7 +425,6 @@ bool ReadSchemaDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, B
line %d, \aAbort reading file.\n" ),
aLine->LineNumber() );
aMsgDiag << CONV_FROM_UTF8( line );
DisplayError( frame, aMsgDiag );
}
Window->m_CurrentSheetDesc = wsheet;
@ -509,7 +506,7 @@ line %d, \aAbort reading file.\n" ),
* Get the lines for a description of a schematic component.
*/
int ReadPartDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
int ReadPartDescr( LINE_READER* aLine, wxString& aMsgDiag, BASE_SCREEN* Window )
{
int ii;
char Name1[256], Name2[256],
@ -754,7 +751,6 @@ int ReadPartDescr( wxWindow* frame, LINE_READER* aLine, wxString& aMsgDiag, BASE
aMsgDiag.Printf(
wxT( "Component Field error line %d, aborted" ),
aLine->LineNumber() );
DisplayError( frame, aMsgDiag );
continue;
}

View File

@ -348,6 +348,7 @@ public:
inline bool IsModified() const { return m_Flags & IS_CHANGED; }
inline bool IsMoving() const { return m_Flags & IS_MOVED; }
inline bool IsDragging() const { return m_Flags & IS_DRAGGED; }
inline bool IsSelected() const { return m_Flags & SELECTED; }
int GetState( int type ) const
{

View File

@ -14,12 +14,23 @@
#include "block_commande.h"
#include "common.h"
#include <boost/ptr_container/ptr_vector.hpp>
// Forward declarations:
class SCH_ITEM;
class Ki_PageDescr;
/**
* Define list of drawing items for screens.
*
* The Boost containter was choosen over the statand C++ contain because you can detach
* the pointer from a list with the release method.
*/
typedef boost::ptr_vector< EDA_BaseStruct > EDA_ITEMS;
/* Simple class for handling grid arrays. */
class GRID_TYPE
{
@ -56,17 +67,16 @@ WX_DECLARE_OBJARRAY( GRID_TYPE, GridArray );
/*******************************************************************/
class BASE_SCREEN : public EDA_BaseStruct
{
EDA_ITEMS m_items; ///< The drawing items associated with this screen.
public:
wxPoint m_DrawOrg; /* offsets for drawing the circuit on the
* screen */
wxPoint m_Curseur; /* Screen cursor coordinate (on grid) in user
* units. */
wxPoint m_MousePosition; /* Mouse cursor coordinate (off grid) in user
* units. */
wxPoint m_DrawOrg; /* offsets for drawing the circuit on the screen */
wxPoint m_Curseur; /* Screen cursor coordinate (on grid) in user units. */
wxPoint m_MousePosition; /* Mouse cursor coordinate (off grid) in user units. */
wxPoint m_MousePositionInPixels;
wxPoint m_O_Curseur; /* Relative Screen cursor coordinate (on grid)
* in user units.
* (coordinates from last reset position)*/
wxPoint m_O_Curseur; /* Relative Screen cursor coordinate (on grid)
* in user units.
* (coordinates from last reset position)*/
// Scrollbars management:
int m_ScrollPixelsPerUnitX; /* Pixels per scroll unit in the horizontal direction. */
int m_ScrollPixelsPerUnitY; /* Pixels per scroll unit in the vertical direction. */
@ -280,8 +290,7 @@ public:
/**
* Function SetZoomList
* sets the list of zoom factors.
* @param aZoomList An array of zoom factors in ascending order, zero
* terminated
* @param aZoomList An array of zoom factors in ascending order, zero terminated
*/
void SetZoomList( const wxArrayInt& zoomlist );
@ -300,8 +309,7 @@ public:
bool SetFirstZoom();
bool SetLastZoom();
//----<grid
// stuff>----------------------------------------------------------
//----<grid stuff>----------------------------------------------------------
/**
* Return the command ID of the currently selected grid.
@ -359,6 +367,13 @@ public:
return wxT( "BASE_SCREEN" );
}
/**
* Helpers for accessing the draw item list.
*/
EDA_ITEMS::iterator Begin() { return m_items.begin(); }
EDA_ITEMS::iterator End() { return m_items.end(); }
virtual void AddItem( EDA_BaseStruct* aItem );
virtual void InsertItem( EDA_ITEMS::iterator aIter, EDA_BaseStruct* aItem );
#if defined(DEBUG)

View File

@ -6,7 +6,7 @@
#define CLASS_SCREEN_H
#include "macros.h"
#include "base_struct.h"
#include "sch_item_struct.h"
#include "class_base_screen.h"
@ -17,8 +17,9 @@
class SCH_SCREEN : public BASE_SCREEN
{
public:
int m_RefCount; /*how many sheets reference this screen?
* delete when it goes to zero. */
int m_RefCount; ///< Number of sheets referencing this screen.
///< Delete when it goes to zero.
SCH_SCREEN( KICAD_T aType = SCREEN_STRUCT_TYPE );
~SCH_SCREEN();
@ -80,7 +81,7 @@ public:
* items are removed from the beginning of the list.
* So this function can be called to remove old commands
*/
virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 );
virtual void ClearUndoORRedoList( UNDO_REDO_CONTAINER& aList, int aItemCount = -1 );
/**
* Function Save
@ -90,6 +91,17 @@ public:
* @return bool - true if success writing else false.
*/
bool Save( FILE* aFile ) const;
/**
* Clear the state flags of all the items in the screen.
*/
void ClearDrawingState();
virtual void AddItem( SCH_ITEM* aItem ) { BASE_SCREEN::AddItem( (EDA_BaseStruct*) aItem ); }
virtual void InsertItem( EDA_ITEMS::iterator aIter, SCH_ITEM* aItem )
{
BASE_SCREEN::InsertItem( aIter, (EDA_BaseStruct*) aItem );
}
};

View File

@ -5,11 +5,46 @@
#ifndef SCH_ITEM_STRUCT_H
#define SCH_ITEM_STRUCT_H
#include <vector>
#include <class_base_screen.h>
using namespace std;
class SCH_ITEM;
class WinEDA_SchematicFrame;
class wxFindReplaceData;
enum DANGLING_END_T {
UNKNOWN = 0,
WIRE_START_END,
WIRE_END_END,
BUS_START_END,
BUS_END_END,
JUNCTION_END,
PIN_END,
LABEL_END,
ENTRY_END,
SHEET_LABEL_END
};
// A helper class to store a list of items that can be connected to something:
class DANGLING_END_ITEM
{
public:
const void* m_Item; // a pointer to the parent
wxPoint m_Pos; // the position of the connecting point
DANGLING_END_T m_Type; // type of parent
DANGLING_END_ITEM( DANGLING_END_T type, const void* aItem )
{
m_Item = aItem;
m_Type = type;
}
};
/**
* Class SCH_ITEM
* is a base class for any item which can be embedded within the SCHEMATIC
@ -21,7 +56,7 @@ class SCH_ITEM : public EDA_BaseStruct
{
protected:
int m_Layer;
EDA_ITEMS m_connections; ///< List of items connected to this item.
public:
SCH_ITEM( EDA_BaseStruct* aParent, KICAD_T aType );
@ -72,15 +107,15 @@ public:
* move item to a new position.
* @param aMoveVector = the deplacement vector
*/
virtual void Move(const wxPoint& aMoveVector) = 0;
virtual void Move( const wxPoint& aMoveVector ) = 0;
/** virtual function Mirror_Y
* mirror item relative to an Y axis
* @param aYaxis_position = the y axis position
*/
virtual void Mirror_Y(int aYaxis_position) = 0;
virtual void Mirror_X(int aXaxis_position) = 0;
virtual void Rotate(wxPoint rotationPoint) = 0;
virtual void Mirror_Y( int aYaxis_position ) = 0;
virtual void Mirror_X( int aXaxis_position ) = 0;
virtual void Rotate( wxPoint rotationPoint ) = 0;
/**
@ -109,8 +144,7 @@ public:
* @param aFindLocation - a wxPoint where to put the location of matched item. can be NULL.
* @return True if this schematic text item matches the search criteria.
*/
virtual bool Matches( wxFindReplaceData& aSearchData,
void * aAuxData, wxPoint * aFindLocation )
virtual bool Matches( wxFindReplaceData& aSearchData, void* aAuxData, wxPoint* aFindLocation )
{ return false; }
/**
@ -121,6 +155,62 @@ public:
* @return True if this item matches the search criteria.
*/
bool Matches( const wxString& aText, wxFindReplaceData& aSearchData );
/**
* Add schematic item end points to \a aItemList if the item has endpoints.
*
* The default version doesn't do anything since many of the schematic object cannot
* be tested for dangling ends. If you add a new schematic item that can have a
* dangling end ( no connect ), override this method to provide the correct end
* points.
*
* @param aItemList - List of DANGLING_END_ITEMS to add to.
*/
virtual void GetEndPoints( vector< DANGLING_END_ITEM >& aItemList ) {}
/**
* Test the schematic item to \a aItemList to check if it's dangling state has changed.
*
* Note that the return value only true when the state of the test has changed. Use
* the IsDangling() method to get the current dangling state of the item. Some of
* the schematic objects cannot be tested for a dangling state, the default method
* always returns false. Only override the method if the item can be tested for a
* dangling state.
*
* @param aItemList - List of items to test item against.
* @return True if the dangling state has changed from it's current setting.
*/
virtual bool IsDanglingStateChanged( vector< DANGLING_END_ITEM >& aItemList ) { return false; }
virtual bool IsDangling() const { return false; }
/**
* Check if the selection state of an item inside \a aRect has changed.
*
* The is used by the block selection code to verify if an item is selected or not.
* True is be return anytime the select state changes. If you need to know the
* the current selection state, use the IsSelected() method.
*
* @param aRect - Rectange to test against.
*/
virtual bool IsSelectStateChanged( const wxRect& aRect ) { return false; }
/**
* Get a list of connection points for this item.
*
* Not all schematic items have connection points so the default method does nothing.
*
* @param aPoints - List of connection points to add to.
*/
virtual void GetConnectionPoints( vector< wxPoint >& aPoints ) const { }
/**
* Clear all of the connection items from the list.
*
* The vector release method is used to prevent the item pointers from being deleted.
* Do not use the vector erase method on the connection list.
*/
void ClearConnections() { m_connections.release(); }
};
#endif /* SCH_ITEM_STRUCT_H */