diff --git a/common/base_struct.cpp b/common/base_struct.cpp index e9376ec0ff..ee04f8c214 100644 --- a/common/base_struct.cpp +++ b/common/base_struct.cpp @@ -81,7 +81,6 @@ EDA_ITEM* EDA_ITEM::doClone() const } -// see base_struct.h SEARCH_RESULT EDA_ITEM::IterateForward( EDA_ITEM* listStart, INSPECTOR* inspector, const void* testData, @@ -135,6 +134,15 @@ wxString EDA_ITEM::GetSelectMenuText() const } +bool EDA_ITEM::operator<( const EDA_ITEM& aItem ) const +{ + wxFAIL_MSG( wxString::Format( wxT( "Less than operator not defined for item type %s." ), + GetChars( GetClass() ) ) ); + + return false; +} + + #if defined(DEBUG) diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index cc3552fb3a..b30a650873 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -94,6 +94,7 @@ set(EESCHEMA_SRCS lib_arc.cpp lib_bezier.cpp lib_circle.cpp + lib_collectors.cpp lib_draw_item.cpp lib_export.cpp lib_field.cpp diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index c978174a40..2172f02faa 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -189,7 +189,7 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) : LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) : EDA_ITEM( aComponent ) { - LIB_DRAW_ITEM* newItem; + LIB_ITEM* newItem; m_library = aLibrary; m_name = aComponent.m_name; @@ -202,12 +202,12 @@ LIB_COMPONENT::LIB_COMPONENT( LIB_COMPONENT& aComponent, CMP_LIBRARY* aLibrary ) m_dateModified = aComponent.m_dateModified; m_options = aComponent.m_options; - BOOST_FOREACH( LIB_DRAW_ITEM& oldItem, aComponent.GetDrawItemList() ) + BOOST_FOREACH( LIB_ITEM& oldItem, aComponent.GetDrawItemList() ) { if( oldItem.IsNew() ) continue; - newItem = oldItem.GenCopy(); + newItem = (LIB_ITEM*) oldItem.Clone(); newItem->SetParent( this ); drawings.push_back( newItem ); } @@ -294,7 +294,7 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff */ if( ! (screen->m_IsPrinting && GetGRForceBlackPenState()) && (aColor == -1) ) { - BOOST_FOREACH( LIB_DRAW_ITEM& drawItem, drawings ) + BOOST_FOREACH( LIB_ITEM& drawItem, drawings ) { if( drawItem.m_Fill != FILLED_WITH_BG_BODYCOLOR ) continue; @@ -327,7 +327,7 @@ void LIB_COMPONENT::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDc, const wxPoint& aOff } } - BOOST_FOREACH( LIB_DRAW_ITEM& drawItem, drawings ) + BOOST_FOREACH( LIB_ITEM& drawItem, drawings ) { if( aOnlySelected && drawItem.m_Selected == 0 ) continue; @@ -389,7 +389,7 @@ void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert, { wxASSERT( aPlotter != NULL ); - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) ) continue; @@ -404,7 +404,7 @@ void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert, } -void LIB_COMPONENT::RemoveDrawItem( LIB_DRAW_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc ) +void LIB_COMPONENT::RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel, wxDC* aDc ) { wxASSERT( aItem != NULL ); @@ -424,7 +424,7 @@ from component %s in library %s." ), } } - LIB_DRAW_ITEM_LIST::iterator i; + LIB_ITEMS::iterator i; for( i = drawings.begin(); i < drawings.end(); i++ ) { @@ -441,7 +441,7 @@ from component %s in library %s." ), } -void LIB_COMPONENT::AddDrawItem( LIB_DRAW_ITEM* aItem ) +void LIB_COMPONENT::AddDrawItem( LIB_ITEM* aItem ) { wxASSERT( aItem != NULL ); @@ -450,7 +450,7 @@ void LIB_COMPONENT::AddDrawItem( LIB_DRAW_ITEM* aItem ) } -LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* aItem, KICAD_T aType ) +LIB_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType ) { /* Return the next draw object pointer. * If item is NULL return the first item of type in the list. @@ -486,7 +486,7 @@ LIB_DRAW_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_DRAW_ITEM* aItem, KICAD_T aTy } -void LIB_COMPONENT::GetPins( LIB_PIN_LIST& aList, int aUnit, int aConvert ) +void LIB_COMPONENT::GetPins( LIB_PINS& aList, int aUnit, int aConvert ) { /* Notes: * when aUnit == 0: no unit filtering @@ -494,7 +494,7 @@ void LIB_COMPONENT::GetPins( LIB_PIN_LIST& aList, int aUnit, int aConvert ) * when .m_Unit == 0, the body item is common to units * when .m_Convert == 0, the body item is common to shapes */ - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.Type() != LIB_PIN_T ) // we search pins only continue; @@ -514,8 +514,8 @@ void LIB_COMPONENT::GetPins( LIB_PIN_LIST& aList, int aUnit, int aConvert ) LIB_PIN* LIB_COMPONENT::GetPin( const wxString& aNumber, int aUnit, int aConvert ) { - wxString pNumber; - LIB_PIN_LIST pinList; + wxString pNumber; + LIB_PINS pinList; GetPins( pinList, aUnit, aConvert ); @@ -581,7 +581,7 @@ bool LIB_COMPONENT::Save( FILE* aFile ) if( !SaveDateAndTime( aFile ) ) return false; - LIB_FIELD_LIST fields; + LIB_FIELDS fields; GetFields( fields ); // Fixed fields: @@ -657,7 +657,7 @@ bool LIB_COMPONENT::Save( FILE* aFile ) if( fprintf( aFile, "DRAW\n" ) < 0 ) return false; - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.Type() == LIB_FIELD_T ) continue; @@ -811,7 +811,7 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aEr bool LIB_COMPONENT::LoadDrawEntries( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg ) { - LIB_DRAW_ITEM* newEntry = NULL; + LIB_ITEM* newEntry = NULL; while( true ) { @@ -829,31 +829,31 @@ bool LIB_COMPONENT::LoadDrawEntries( FILE* aFile, char* aLine, switch( aLine[0] ) { case 'A': /* Arc */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_ARC(this); + newEntry = ( LIB_ITEM* ) new LIB_ARC( this ); break; case 'C': /* Circle */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_CIRCLE(this); + newEntry = ( LIB_ITEM* ) new LIB_CIRCLE( this ); break; case 'T': /* Text */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_TEXT(this); + newEntry = ( LIB_ITEM* ) new LIB_TEXT( this ); break; case 'S': /* Square */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_RECTANGLE(this); + newEntry = ( LIB_ITEM* ) new LIB_RECTANGLE( this ); break; case 'X': /* Pin Description */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_PIN(this); + newEntry = ( LIB_ITEM* ) new LIB_PIN( this ); break; case 'P': /* Polyline */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_POLYLINE(this); + newEntry = ( LIB_ITEM* ) new LIB_POLYLINE( this ); break; case 'B': /* Bezier Curves */ - newEntry = ( LIB_DRAW_ITEM* ) new LIB_BEZIER(this); + newEntry = ( LIB_ITEM* ) new LIB_BEZIER( this ); break; default: @@ -970,7 +970,7 @@ EDA_RECT LIB_COMPONENT::GetBoundingBox( int aUnit, int aConvert ) const { EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); - BOOST_FOREACH( const LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( const LIB_ITEM& item, drawings ) { if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 ) && ( aUnit != item.m_Unit ) ) ) @@ -1000,7 +1000,7 @@ EDA_RECT LIB_COMPONENT::GetBodyBoundingBox( int aUnit, int aConvert ) const { EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); - BOOST_FOREACH( const LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( const LIB_ITEM& item, drawings ) { if( ( item.m_Unit > 0 ) && ( ( m_unitCount > 1 ) && ( aUnit > 0 ) && ( aUnit != item.m_Unit ) ) ) @@ -1021,7 +1021,7 @@ EDA_RECT LIB_COMPONENT::GetBodyBoundingBox( int aUnit, int aConvert ) const void LIB_COMPONENT::deleteAllFields() { - LIB_DRAW_ITEM_LIST::iterator it; + LIB_ITEMS::iterator it; for( it = drawings.begin(); it!=drawings.end(); /* deleting */ ) { @@ -1055,7 +1055,7 @@ void LIB_COMPONENT::SetFields( const std::vector & aFields ) } -void LIB_COMPONENT::GetFields( LIB_FIELD_LIST& aList ) +void LIB_COMPONENT::GetFields( LIB_FIELDS& aList ) { LIB_FIELD* field; @@ -1075,7 +1075,7 @@ void LIB_COMPONENT::GetFields( LIB_FIELD_LIST& aList ) } // Now grab all the rest of fields. - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.Type() != LIB_FIELD_T ) continue; @@ -1091,7 +1091,7 @@ void LIB_COMPONENT::GetFields( LIB_FIELD_LIST& aList ) LIB_FIELD* LIB_COMPONENT::GetField( int aId ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.Type() != LIB_FIELD_T ) continue; @@ -1108,7 +1108,7 @@ LIB_FIELD* LIB_COMPONENT::GetField( int aId ) LIB_FIELD* LIB_COMPONENT::FindField( const wxString& aFieldName ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.Type() != LIB_FIELD_T ) continue; @@ -1188,7 +1188,7 @@ bool LIB_COMPONENT::LoadDateAndTime( char* aLine ) void LIB_COMPONENT::SetOffset( const wxPoint& aOffset ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { item.SetOffset( aOffset ); } @@ -1203,7 +1203,7 @@ void LIB_COMPONENT::RemoveDuplicateDrawItems() bool LIB_COMPONENT::HasConversion() const { - BOOST_FOREACH( const LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( const LIB_ITEM& item, drawings ) { if( item.m_Convert > 1 ) return true; @@ -1215,7 +1215,7 @@ bool LIB_COMPONENT::HasConversion() const void LIB_COMPONENT::ClearStatus() { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) item.m_Flags = 0; } @@ -1224,7 +1224,7 @@ int LIB_COMPONENT::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool a { int itemCount = 0; - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { item.m_Selected = 0; @@ -1253,7 +1253,7 @@ int LIB_COMPONENT::SelectItems( EDA_RECT& aRect, int aUnit, int aConvert, bool a void LIB_COMPONENT::MoveSelectedItems( const wxPoint& aOffset ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.m_Selected == 0 ) continue; @@ -1268,14 +1268,14 @@ void LIB_COMPONENT::MoveSelectedItems( const wxPoint& aOffset ) void LIB_COMPONENT::ClearSelectedItems() { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) item.m_Flags = item.m_Selected = 0; } void LIB_COMPONENT::DeleteSelectedItems() { - LIB_DRAW_ITEM_LIST::iterator item = drawings.begin(); + LIB_ITEMS::iterator item = drawings.begin(); // We *do not* remove the 2 mandatory fields: reference and value // so skip them (do not remove) if they are flagged selected. @@ -1312,7 +1312,7 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset ) unsigned icnt = drawings.size(); for( unsigned ii = 0; ii < icnt; ii++ ) { - LIB_DRAW_ITEM& item = drawings[ii]; + LIB_ITEM& item = drawings[ii]; // We *do not* copy fields because they are unique for the whole component // so skip them (do not duplicate) if they are flagged selected. if( item.Type() == LIB_FIELD_T ) @@ -1322,7 +1322,7 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset ) continue; item.m_Selected = 0; - LIB_DRAW_ITEM* newItem = item.GenCopy(); + LIB_ITEM* newItem = (LIB_ITEM*) item.Clone(); newItem->m_Selected = IS_SELECTED; drawings.push_back( newItem ); } @@ -1335,7 +1335,7 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset ) void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& aCenter ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( item.m_Selected == 0 ) continue; @@ -1348,22 +1348,10 @@ void LIB_COMPONENT::MirrorSelectedItemsH( const wxPoint& aCenter ) } - -/** - * Locate a draw object. - * - * @param aUnit - Unit number of draw item. - * @param aConvert - Body style of draw item. - * @param aType - Draw object type, set to 0 to search for any type. - * @param aPoint - Coordinate for hit testing. - * - * @return LIB_DRAW_ITEM - Pointer the the draw object if found. - * Otherwise NULL. - */ -LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, - KICAD_T aType, const wxPoint& aPoint ) +LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, + KICAD_T aType, const wxPoint& aPoint ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { if( ( aUnit && item.m_Unit && ( aUnit != item.m_Unit) ) || ( aConvert && item.m_Convert && ( aConvert != item.m_Convert ) ) @@ -1378,15 +1366,15 @@ LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, } -LIB_DRAW_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, - const wxPoint& aPoint, const TRANSFORM& aTransform ) +LIB_ITEM* LIB_COMPONENT::LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, + const wxPoint& aPoint, const TRANSFORM& aTransform ) { /* we use LocateDrawItem( int aUnit, int convert, KICAD_T type, const * wxPoint& pt ) to search items. * because this function uses DefaultTransformMatrix as orient/mirror matrix * we temporary copy aTransMat in DefaultTransformMatrix */ - LIB_DRAW_ITEM* item; + LIB_ITEM* item; TRANSFORM transform = DefaultTransform; DefaultTransform = aTransform; @@ -1406,7 +1394,7 @@ void LIB_COMPONENT::SetPartCount( int aCount ) if( aCount < m_unitCount ) { - LIB_DRAW_ITEM_LIST::iterator i; + LIB_ITEMS::iterator i; i = drawings.begin(); while( i != drawings.end() ) @@ -1432,7 +1420,7 @@ void LIB_COMPONENT::SetPartCount( int aCount ) for( int j = prevCount + 1; j <= aCount; j++ ) { - LIB_DRAW_ITEM* newItem = drawings[ii].GenCopy(); + LIB_ITEM* newItem = (LIB_ITEM*) drawings[ii].Clone(); newItem->m_Unit = j; drawings.push_back( newItem ); } @@ -1454,14 +1442,14 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert ) if( aSetConvert ) { - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawings ) + BOOST_FOREACH( LIB_ITEM& item, drawings ) { /* Only pins are duplicated. */ if( item.Type() != LIB_PIN_T ) continue; if( item.m_Convert == 1 ) { - LIB_DRAW_ITEM* newItem = item.GenCopy(); + LIB_ITEM* newItem = (LIB_ITEM*) item.Clone(); newItem->m_Convert = 2; drawings.push_back( newItem ); } @@ -1471,7 +1459,7 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert ) { // Delete converted shape items because the converted shape does // not exist - LIB_DRAW_ITEM_LIST::iterator i = drawings.begin(); + LIB_ITEMS::iterator i = drawings.begin(); while( i != drawings.end() ) { @@ -1488,7 +1476,7 @@ wxArrayString LIB_COMPONENT::GetAliasNames( bool aIncludeRoot ) const { wxArrayString names; - LIB_ALIAS_LIST::const_iterator it; + LIB_ALIASES::const_iterator it; for( it=m_aliases.begin(); it LIB_ALIAS_MAP; -typedef std::vector< LIB_ALIAS* > LIB_ALIAS_LIST; +typedef std::vector< LIB_ALIAS* > LIB_ALIASES; /* values for member .m_options */ enum LibrEntryOptions @@ -161,10 +161,10 @@ class LIB_COMPONENT : public EDA_ITEM long m_dateModified; ///< Date the component was last modified. LibrEntryOptions m_options; ///< Special component features such as POWER or NORMAL.) int m_unitCount; ///< Number of units (parts) per package. - LIB_DRAW_ITEM_LIST drawings; ///< How to draw this part. + LIB_ITEMS drawings; ///< How to draw this part. wxArrayString m_FootprintList; /**< List of suitable footprint names for the component (wild card names accepted). */ - LIB_ALIAS_LIST m_aliases; ///< List of alias object pointers associated with the + LIB_ALIASES m_aliases; ///< List of alias object pointers associated with the ///< component. CMP_LIBRARY* m_library; ///< Library the component belongs to if any. @@ -308,7 +308,7 @@ public: * * @param aList - List to add fields to */ - void GetFields( LIB_FIELD_LIST& aList ); + void GetFields( LIB_FIELDS& aList ); /** * Function FindField @@ -373,7 +373,7 @@ public: * * @param aItem - New draw object to add to component. */ - void AddDrawItem( LIB_DRAW_ITEM* aItem ); + void AddDrawItem( LIB_ITEM* aItem ); /** * Remove draw \a aItem from list. @@ -382,7 +382,7 @@ public: * @param aPanel - Panel to remove part from. * @param aDc - Device context to remove part from. */ - void RemoveDrawItem( LIB_DRAW_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL ); + void RemoveDrawItem( LIB_ITEM* aItem, EDA_DRAW_PANEL* aPanel = NULL, wxDC* aDc = NULL ); /** * Return the next draw object pointer. @@ -393,7 +393,7 @@ public: * if TYPE_NOT_INIT search for all items types * @return - The next drawing object in the list if found, otherwise NULL. */ - LIB_DRAW_ITEM* GetNextDrawItem( LIB_DRAW_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT ); + LIB_ITEM* GetNextDrawItem( LIB_ITEM* aItem = NULL, KICAD_T aType = TYPE_NOT_INIT ); /** * Return the next pin object from the draw list. @@ -406,7 +406,7 @@ public: */ LIB_PIN* GetNextPin( LIB_PIN* aItem = NULL ) { - return (LIB_PIN*) GetNextDrawItem( (LIB_DRAW_ITEM*) aItem, LIB_PIN_T ); + return (LIB_PIN*) GetNextDrawItem( (LIB_ITEM*) aItem, LIB_PIN_T ); } @@ -423,7 +423,7 @@ public: * @param aConvert - Convert number of pin to add to list. Set to 0 to * get pins from any convert of component. */ - void GetPins( LIB_PIN_LIST& aList, int aUnit = 0, int aConvert = 0 ); + void GetPins( LIB_PINS& aList, int aUnit = 0, int aConvert = 0 ); /** * Return pin object with the requested pin \a aNumber. @@ -521,7 +521,7 @@ public: * @param aPoint - Coordinate for hit testing. * @return The draw object if found. Otherwise NULL. */ - LIB_DRAW_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint ); + LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, const wxPoint& aPoint ); /** * Locate a draw object (overlaid) @@ -533,15 +533,15 @@ public: * @param aTransform = the transform matrix * @return The draw object if found. Otherwise NULL. */ - LIB_DRAW_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, - const wxPoint& aPoint, const TRANSFORM& aTransform ); + LIB_ITEM* LocateDrawItem( int aUnit, int aConvert, KICAD_T aType, + const wxPoint& aPoint, const TRANSFORM& aTransform ); /** * Return a reference to the draw item list. * - * @return LIB_DRAW_ITEM_LIST& - Reference to the draw item object list. + * @return LIB_ITEMS& - Reference to the draw item object list. */ - LIB_DRAW_ITEM_LIST& GetDrawItemList() { return drawings; } + LIB_ITEMS& GetDrawItemList() { return drawings; } /** * Set the part per package count. diff --git a/eeschema/controle.cpp b/eeschema/controle.cpp index 31b34b75bd..9a5d617d99 100644 --- a/eeschema/controle.cpp +++ b/eeschema/controle.cpp @@ -142,7 +142,7 @@ SCH_ITEM* SCH_EDIT_FRAME::LocateItem( const wxPoint& aPosition, const KICAD_T aF { wxString text = m_collectedItems[i]->GetSelectMenuText(); const char** xpm = m_collectedItems[i]->GetMenuImage(); - ADD_MENUITEM( &selectMenu, ID_SCH_SELECT_ITEM_START + i, text, xpm ); + ADD_MENUITEM( &selectMenu, ID_SELECT_ITEM_START + i, text, xpm ); } // Set to NULL in case user aborts the clarification context menu. @@ -220,7 +220,7 @@ void SCH_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( DrawPanel->IsMouseCaptured() ) { - DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, aPosition, TRUE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, aPosition, true ); } } @@ -293,16 +293,13 @@ void LIB_EDIT_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( DrawPanel->IsMouseCaptured() ) { - DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, aPosition, TRUE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, aPosition, true ); } } if( aHotKey ) { - if( screen->GetCurItem() && screen->GetCurItem()->GetFlags() ) - OnHotKey( aDC, aHotKey, aPosition, screen->GetCurItem() ); - else - OnHotKey( aDC, aHotKey, aPosition, NULL ); + OnHotKey( aDC, aHotKey, aPosition, NULL ); } UpdateStatusBar(); @@ -366,7 +363,7 @@ void LIB_VIEW_FRAME::GeneralControl( wxDC* aDC, const wxPoint& aPosition, int aH if( DrawPanel->IsMouseCaptured() ) { - DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, aPosition, TRUE ); + DrawPanel->m_mouseCaptureCallback( DrawPanel, aDC, aPosition, true ); } } diff --git a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp index 6a359c27c7..274756d3e6 100644 --- a/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp @@ -416,7 +416,7 @@ int DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::getSelectedFieldNdx() * Function findfield * searches a LIB_FIELD_LIST for aFieldName. */ -static LIB_FIELD* findfield( const LIB_FIELD_LIST& aList, const wxString& aFieldName ) +static LIB_FIELD* findfield( const LIB_FIELDS& aList, const wxString& aFieldName ) { const LIB_FIELD* field = NULL; @@ -447,7 +447,7 @@ LIB_FIELD* DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::findField( const wxString& aField void DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::InitBuffers() /***********************************************************/ { - LIB_FIELD_LIST cmpFields; + LIB_FIELDS cmpFields; m_LibEntry->GetFields( cmpFields ); diff --git a/eeschema/eeschema_id.h b/eeschema/eeschema_id.h index 0cdbad886f..adf2a66edf 100644 --- a/eeschema/eeschema_id.h +++ b/eeschema/eeschema_id.h @@ -145,8 +145,8 @@ enum id_eeschema_frm ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE, ID_POPUP_SCH_ORIENT_NORMAL_CMP, - ID_SCH_SELECT_ITEM_START, - ID_SCH_SELECT_ITEM_END = ID_SCH_SELECT_ITEM_START + MAX_SELECT_ITEM_IDS, + ID_SELECT_ITEM_START, + ID_SELECT_ITEM_END = ID_SELECT_ITEM_START + MAX_SELECT_ITEM_IDS, ID_POPUP_SCH_MOVE_ITEM, diff --git a/eeschema/hotkeys.cpp b/eeschema/hotkeys.cpp index 0e6619b38a..db89bae335 100644 --- a/eeschema/hotkeys.cpp +++ b/eeschema/hotkeys.cpp @@ -844,11 +844,10 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, return; wxCommandEvent cmd( wxEVT_COMMAND_MENU_SELECTED ); - wxCommandEvent toolCmd( wxEVT_COMMAND_TOOL_CLICKED ); cmd.SetEventObject( this ); - bool itemInEdit = GetScreen()->GetCurItem() && GetScreen()->GetCurItem()->GetFlags(); + bool itemInEdit = m_drawItem && m_drawItem->GetFlags(); /* Convert lower to upper case (the usual toupper function has problem * with non ascii codes like function keys */ @@ -905,16 +904,16 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, case HK_UNDO: if( !itemInEdit ) { - toolCmd.SetId( wxID_UNDO ); - GetEventHandler()->ProcessEvent( toolCmd ); + cmd.SetId( wxID_UNDO ); + GetEventHandler()->ProcessEvent( cmd ); } break; case HK_REDO: if( !itemInEdit ) { - toolCmd.SetId( wxID_REDO ); - GetEventHandler()->ProcessEvent( toolCmd ); + cmd.SetId( wxID_REDO ); + GetEventHandler()->ProcessEvent( cmd ); } break; @@ -979,9 +978,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( m_drawItem && !m_drawItem->InEditMode() ) { - wxCommandEvent evt; - evt.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM ); - Process_Special_Functions( evt ); + cmd.SetId( ID_POPUP_LIBEDIT_DELETE_ITEM ); + Process_Special_Functions( cmd ); } break; @@ -992,9 +990,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( m_drawItem ) { - wxCommandEvent evt; - evt.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST ); - Process_Special_Functions( evt ); + cmd.SetId( ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST ); + Process_Special_Functions( cmd ); } } break; @@ -1004,9 +1001,8 @@ void LIB_EDIT_FRAME::OnHotKey( wxDC* aDC, int aHotKey, const wxPoint& aPosition, if( m_drawItem && !m_drawItem->InEditMode() ) { - wxCommandEvent evt; - evt.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM ); - Process_Special_Functions( evt ); + cmd.SetId( ID_POPUP_LIBEDIT_MODIFY_ITEM ); + Process_Special_Functions( cmd ); } break; } diff --git a/eeschema/lib_arc.cpp b/eeschema/lib_arc.cpp index ae3e794ca4..36c6d77570 100644 --- a/eeschema/lib_arc.cpp +++ b/eeschema/lib_arc.cpp @@ -53,7 +53,7 @@ static wxPoint calcCenter( const wxPoint& A, const wxPoint& B, const wxPoint& C } -LIB_ARC::LIB_ARC( LIB_COMPONENT* aParent ) : LIB_DRAW_ITEM( LIB_ARC_T, aParent ) +LIB_ARC::LIB_ARC( LIB_COMPONENT* aParent ) : LIB_ITEM( LIB_ARC_T, aParent ) { m_Radius = 0; m_t1 = 0; @@ -67,7 +67,7 @@ LIB_ARC::LIB_ARC( LIB_COMPONENT* aParent ) : LIB_DRAW_ITEM( LIB_ARC_T, aParent ) } -LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_DRAW_ITEM( aArc ) +LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_ITEM( aArc ) { m_Radius = aArc.m_Radius; m_t1 = aArc.m_t1; @@ -211,27 +211,13 @@ bool LIB_ARC::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTran } -LIB_DRAW_ITEM* LIB_ARC::DoGenCopy() +EDA_ITEM* LIB_ARC::doClone() const { - LIB_ARC* newitem = new LIB_ARC( GetParent() ); - - newitem->m_Pos = m_Pos; - newitem->m_ArcStart = m_ArcStart; - newitem->m_ArcEnd = m_ArcEnd; - newitem->m_Radius = m_Radius; - newitem->m_t1 = m_t1; - newitem->m_t2 = m_t2; - newitem->m_Width = m_Width; - newitem->m_Unit = m_Unit; - newitem->m_Convert = m_Convert; - newitem->m_Flags = m_Flags; - newitem->m_Fill = m_Fill; - - return (LIB_DRAW_ITEM*) newitem; + return new LIB_ARC( *this ); } -int LIB_ARC::DoCompare( const LIB_DRAW_ITEM& aOther ) const +int LIB_ARC::DoCompare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_ARC_T ); @@ -479,7 +465,7 @@ void LIB_ARC::DisplayInfo( EDA_DRAW_FRAME* aFrame ) wxString msg; EDA_RECT bBox = GetBoundingBox(); - LIB_DRAW_ITEM::DisplayInfo( aFrame ); + LIB_ITEM::DisplayInfo( aFrame ); msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true ); @@ -492,6 +478,15 @@ void LIB_ARC::DisplayInfo( EDA_DRAW_FRAME* aFrame ) } +wxString LIB_ARC::GetSelectMenuText() const +{ + return wxString::Format( _( "Arc center (%s, %s), radius %s" ), + GetChars( CoordinateToString( m_Pos.x, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_Pos.y, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_Radius, EESCHEMA_INTERNAL_UNIT ) ) ); +} + + void LIB_ARC::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0, diff --git a/eeschema/lib_arc.h b/eeschema/lib_arc.h index 4c79c907a2..e96460e78a 100644 --- a/eeschema/lib_arc.h +++ b/eeschema/lib_arc.h @@ -12,7 +12,7 @@ class TRANSFORM; -class LIB_ARC : public LIB_DRAW_ITEM +class LIB_ARC : public LIB_ITEM { enum SELECT_T { @@ -105,22 +105,26 @@ public: virtual int GetPenSize( ) const; /** - * See LIB_DRAW_ITEM::BeginEdit(). + * See LIB_ITEM::BeginEdit(). */ void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); /** - * See LIB_DRAW_ITEM::ContinueEdit(). + * See LIB_ITEM::ContinueEdit(). */ bool ContinueEdit( const wxPoint aNextPoint ); /** - * See LIB_DRAW_ITEM::AbortEdit(). + * See LIB_ITEM::AbortEdit(). */ void EndEdit( const wxPoint& aPosition, bool aAbort = false ); + virtual wxString GetSelectMenuText() const; + + virtual const char** GetMenuImage() const { return (const char**) add_arc_xpm; } + protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the arc draw object specific comparison. @@ -131,7 +135,7 @@ protected: * - Arc start angle. * - Arc end angle. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; virtual void DoMove( const wxPoint& aPosition ); diff --git a/eeschema/lib_bezier.cpp b/eeschema/lib_bezier.cpp index 1c35e26f30..7fc8244009 100644 --- a/eeschema/lib_bezier.cpp +++ b/eeschema/lib_bezier.cpp @@ -19,7 +19,7 @@ LIB_BEZIER::LIB_BEZIER( LIB_COMPONENT* aParent ) : - LIB_DRAW_ITEM( LIB_BEZIER_T, aParent ) + LIB_ITEM( LIB_BEZIER_T, aParent ) { m_Fill = NO_FILL; m_Width = 0; @@ -28,7 +28,7 @@ LIB_BEZIER::LIB_BEZIER( LIB_COMPONENT* aParent ) : } -LIB_BEZIER::LIB_BEZIER( const LIB_BEZIER& aBezier ) : LIB_DRAW_ITEM( aBezier ) +LIB_BEZIER::LIB_BEZIER( const LIB_BEZIER& aBezier ) : LIB_ITEM( aBezier ) { m_PolyPoints = aBezier.m_PolyPoints; m_BezierPoints = aBezier.m_BezierPoints; // Vector copy @@ -113,21 +113,13 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg ) } -LIB_DRAW_ITEM* LIB_BEZIER::DoGenCopy() +EDA_ITEM* LIB_BEZIER::doClone() const { - LIB_BEZIER* newitem = new LIB_BEZIER(GetParent()); - - newitem->m_BezierPoints = m_BezierPoints; // Vector copy - newitem->m_Width = m_Width; - newitem->m_Unit = m_Unit; - newitem->m_Convert = m_Convert; - newitem->m_Flags = m_Flags; - newitem->m_Fill = m_Fill; - return (LIB_DRAW_ITEM*) newitem; + return new LIB_BEZIER( *this ); } -int LIB_BEZIER::DoCompare( const LIB_DRAW_ITEM& aOther ) const +int LIB_BEZIER::DoCompare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_BEZIER_T ); @@ -366,7 +358,7 @@ void LIB_BEZIER::DisplayInfo( EDA_DRAW_FRAME* aFrame ) wxString msg; EDA_RECT bBox = GetBoundingBox(); - LIB_DRAW_ITEM::DisplayInfo( aFrame ); + LIB_ITEM::DisplayInfo( aFrame ); msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true ); diff --git a/eeschema/lib_bezier.h b/eeschema/lib_bezier.h index 7a0fc7ff49..71c427475c 100644 --- a/eeschema/lib_bezier.h +++ b/eeschema/lib_bezier.h @@ -9,7 +9,7 @@ /**************************************************/ /* Graphic Body Item: Bezier Curve (set of lines) */ /**************************************************/ -class LIB_BEZIER : public LIB_DRAW_ITEM +class LIB_BEZIER : public LIB_ITEM { int m_Width; // Line width std::vector m_BezierPoints; // list of parameter (3|4) @@ -77,7 +77,7 @@ public: virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the bezier curve draw object specific comparison. @@ -86,7 +86,7 @@ protected: * - Bezier point horizontal (X) point position. * - Bezier point vertical (Y) point position. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; diff --git a/eeschema/lib_circle.cpp b/eeschema/lib_circle.cpp index a6b238658d..b5299475cc 100644 --- a/eeschema/lib_circle.cpp +++ b/eeschema/lib_circle.cpp @@ -5,6 +5,7 @@ #include "fctsys.h" #include "gr_basic.h" #include "common.h" +#include "macros.h" #include "class_drawpanel.h" #include "plot_common.h" #include "trigo.h" @@ -17,7 +18,7 @@ LIB_CIRCLE::LIB_CIRCLE( LIB_COMPONENT* aParent ) : - LIB_DRAW_ITEM( LIB_CIRCLE_T, aParent ) + LIB_ITEM( LIB_CIRCLE_T, aParent ) { m_Radius = 0; m_Fill = NO_FILL; @@ -27,7 +28,7 @@ LIB_CIRCLE::LIB_CIRCLE( LIB_COMPONENT* aParent ) : LIB_CIRCLE::LIB_CIRCLE( const LIB_CIRCLE& aCircle ) : - LIB_DRAW_ITEM( aCircle ) + LIB_ITEM( aCircle ) { m_Pos = aCircle.m_Pos; m_Radius = aCircle.m_Radius; @@ -105,23 +106,13 @@ bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra } -LIB_DRAW_ITEM* LIB_CIRCLE::DoGenCopy() +EDA_ITEM* LIB_CIRCLE::doClone() const { - LIB_CIRCLE* newitem = new LIB_CIRCLE( GetParent() ); - - newitem->m_Pos = m_Pos; - newitem->m_Radius = m_Radius; - newitem->m_Width = m_Width; - newitem->m_Unit = m_Unit; - newitem->m_Convert = m_Convert; - newitem->m_Flags = m_Flags; - newitem->m_Fill = m_Fill; - - return (LIB_DRAW_ITEM*) newitem; + return new LIB_CIRCLE( *this ); } -int LIB_CIRCLE::DoCompare( const LIB_DRAW_ITEM& aOther ) const +int LIB_CIRCLE::DoCompare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_CIRCLE_T ); @@ -255,7 +246,7 @@ void LIB_CIRCLE::DisplayInfo( EDA_DRAW_FRAME* aFrame ) wxString msg; EDA_RECT bBox = GetBoundingBox(); - LIB_DRAW_ITEM::DisplayInfo( aFrame ); + LIB_ITEM::DisplayInfo( aFrame ); msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true ); @@ -271,6 +262,15 @@ void LIB_CIRCLE::DisplayInfo( EDA_DRAW_FRAME* aFrame ) } +wxString LIB_CIRCLE::GetSelectMenuText() const +{ + return wxString::Format( _( "Circle center (%s, %s), radius %s" ), + GetChars( CoordinateToString( m_Pos.x, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_Pos.y, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_Radius, EESCHEMA_INTERNAL_UNIT ) ) ); +} + + void LIB_CIRCLE::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0, diff --git a/eeschema/lib_circle.h b/eeschema/lib_circle.h index dd70d8ea32..be4d1783b5 100644 --- a/eeschema/lib_circle.h +++ b/eeschema/lib_circle.h @@ -9,7 +9,7 @@ #include "lib_draw_item.h" -class LIB_CIRCLE : public LIB_DRAW_ITEM +class LIB_CIRCLE : public LIB_ITEM { int m_Radius; wxPoint m_Pos; // Position or centre (Arc and Circle) or start point (segments). @@ -73,22 +73,26 @@ public: virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); /** - * See LIB_DRAW_ITEM::BeginEdit(). + * See LIB_ITEM::BeginEdit(). */ void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); /** - * See LIB_DRAW_ITEM::ContinueEdit(). + * See LIB_ITEM::ContinueEdit(). */ bool ContinueEdit( const wxPoint aNextPoint ); /** - * See LIB_DRAW_ITEM::AbortEdit(). + * See LIB_ITEM::AbortEdit(). */ void EndEdit( const wxPoint& aPosition, bool aAbort = false ); + virtual wxString GetSelectMenuText() const; + + virtual const char** GetMenuImage() const { return (const char**) add_circle_xpm; } + protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the circle draw object specific comparison. @@ -98,7 +102,7 @@ protected: * - Circle vertical (Y) position. * - Circle radius. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; diff --git a/eeschema/lib_collectors.cpp b/eeschema/lib_collectors.cpp new file mode 100644 index 0000000000..0b5b57f0bf --- /dev/null +++ b/eeschema/lib_collectors.cpp @@ -0,0 +1,131 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 2004-2011 Kicad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "macros.h" +#include "general.h" +#include "transform.h" +#include "lib_collectors.h" + + +const KICAD_T LIB_COLLECTOR::AllItems[] = { + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_PIN_T, + LIB_FIELD_T, + EOT +}; + + +const KICAD_T LIB_COLLECTOR::AllItemsButPins[] = { + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_FIELD_T, + EOT +}; + + +const KICAD_T LIB_COLLECTOR::EditableItems[] = { + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_PIN_T, + LIB_FIELD_T, + EOT +}; + + +const KICAD_T LIB_COLLECTOR::MovableItems[] = { + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_PIN_T, + LIB_FIELD_T, + EOT +}; + + +const KICAD_T LIB_COLLECTOR::RotatableItems[] = { + LIB_ARC_T, + LIB_CIRCLE_T, + LIB_TEXT_T, + LIB_RECTANGLE_T, + LIB_POLYLINE_T, + LIB_BEZIER_T, + LIB_PIN_T, + LIB_FIELD_T, + EOT +}; + + +SEARCH_RESULT LIB_COLLECTOR::Inspect( EDA_ITEM* aItem, const void* aTestData ) +{ + LIB_ITEM* item = (LIB_ITEM*) aItem; + + wxLogDebug( wxT( "Inspecting item %s, unit %d, convert %d" ), + GetChars( item->GetSelectMenuText() ), item->GetUnit(), item->GetConvert() ); + + if( ( m_data.m_unit && item->GetUnit() && ( m_data.m_unit != item->GetUnit() ) ) + || ( m_data.m_convert && item->GetConvert() && ( m_data.m_convert != item->GetConvert() ) ) + || !item->HitTest( m_RefPos, 2, DefaultTransform ) ) + return SEARCH_CONTINUE; + + Append( aItem ); + + return SEARCH_CONTINUE; +} + + +void LIB_COLLECTOR::Collect( LIB_ITEMS& aItems, const KICAD_T aFilterList[], + const wxPoint& aPosition, int aUnit, int aConvert ) +{ + Empty(); // empty the collection just in case + + SetScanTypes( aFilterList ); + + // remember where the snapshot was taken from and pass refPos to the Inspect() function. + SetRefPos( aPosition ); + + m_data.m_unit = aUnit; + m_data.m_convert = aConvert; + + for( size_t i = 0; i < aItems.size(); i++ ) + { + if( SEARCH_QUIT == aItems[i].Visit( this, NULL, m_ScanTypes ) ) + break; + } +} diff --git a/eeschema/lib_collectors.h b/eeschema/lib_collectors.h new file mode 100644 index 0000000000..38937283c9 --- /dev/null +++ b/eeschema/lib_collectors.h @@ -0,0 +1,135 @@ +/* + * This program source code file is part of KICAD, a free EDA CAD application. + * + * Copyright (C) 2011 Wayne Stambaugh + * Copyright (C) 2004-20011 Kicad Developers, see change_log.txt for contributors. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, you may find one here: + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html + * or you may search the http://www.gnu.org website for the version 2 license, + * or you may write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef _LIB_COLLECTORS_H_ +#define _LIB_COLLECTORS_H_ + + +#include "class_collector.h" +#include "lib_draw_item.h" + + +class LIB_COLLECTOR; + + +class LIB_COLLECTOR_DATA +{ + int m_unit; + int m_convert; + + friend class LIB_COLLECTOR; + +public: + LIB_COLLECTOR_DATA() : + m_unit( 0 ), + m_convert( 0 ) {} +}; + + +/** + * Class LIB_COLLECTOR + */ +class LIB_COLLECTOR : public COLLECTOR +{ + LIB_COLLECTOR_DATA m_data; + +public: + + /** + * A scan list for all schematic items. + */ + static const KICAD_T AllItems[]; + + /** + * A scan list for all editable schematic items. + */ + static const KICAD_T EditableItems[]; + + /** + * A scan list for all movable schematic items. + */ + static const KICAD_T MovableItems[]; + + /** + * A scan list for all rotatable schematic items. + */ + static const KICAD_T RotatableItems[]; + + /** + * A scan list for all schematic items except pins. + */ + static const KICAD_T AllItemsButPins[]; + + /** + * Constructor LIB_COLLECTOR + */ + LIB_COLLECTOR( const KICAD_T* aScanTypes = LIB_COLLECTOR::AllItems ) + { + SetScanTypes( aScanTypes ); + } + + /** + * Operator [] + * overloads COLLECTOR::operator[](int) to return a LIB_ITEM* instead of + * an EDA_ITEM* type. + * @param aIndex The index into the list. + * @return LIB_ITEM* at \a aIndex or NULL. + */ + LIB_ITEM* operator[]( int aIndex ) const + { + if( (unsigned)aIndex < (unsigned)GetCount() ) + return (LIB_ITEM*) m_List[ aIndex ]; + + return NULL; + } + + /** + * Function Inspect + * is the examining function within the INSPECTOR which is passed to the + * Iterate function. + * + * @param aItem An EDA_ITEM to examine. + * @param aTestData is not used in this class. + * @return SEARCH_RESULT #SEARCH_QUIT if the iterator is to stop the scan, + * else #SEARCH_CONTINUE; + */ + SEARCH_RESULT Inspect( EDA_ITEM* aItem, const void* aTestData = NULL ); + + /** + * Function Collect + * scans a SCH_ITEM using this class's Inspector method, which does the collection. + * @param aItem A SCH_ITEM to scan. + * @param aFilterList A list of #KICAD_T types with a terminating #EOT, that determines + * what is to be collected and the priority order of the resulting + * collection. + * @param aPosition A wxPoint to use in hit-testing. + * @param aUnit The unit of the items to collect or zero if all units. + * @param aConvert The convert of the items to collect or zero if all conversions. + */ + void Collect( LIB_ITEMS& aItem, const KICAD_T aFilterList[], const wxPoint& aPosition, + int aUnit = 0, int aConvert = 0 ); +}; + + +#endif // _LIB_COLLECTORS_H_ diff --git a/eeschema/lib_draw_item.cpp b/eeschema/lib_draw_item.cpp index 7ab8989d87..b664c38d8d 100644 --- a/eeschema/lib_draw_item.cpp +++ b/eeschema/lib_draw_item.cpp @@ -17,11 +17,11 @@ const int fill_tab[3] = { 'N', 'F', 'f' }; /* Base class (abstract) for components bodies items */ -LIB_DRAW_ITEM::LIB_DRAW_ITEM( KICAD_T aType, - LIB_COMPONENT* aComponent, - int aUnit, - int aConvert, - FILL_T aFillType ) : +LIB_ITEM::LIB_ITEM( KICAD_T aType, + LIB_COMPONENT* aComponent, + int aUnit, + int aConvert, + FILL_T aFillType ) : EDA_ITEM( aType ) { m_Unit = aUnit; @@ -34,15 +34,15 @@ LIB_DRAW_ITEM::LIB_DRAW_ITEM( KICAD_T aType, } -LIB_DRAW_ITEM::LIB_DRAW_ITEM( const LIB_DRAW_ITEM& aItem ) : +LIB_ITEM::LIB_ITEM( const LIB_ITEM& aItem ) : EDA_ITEM( aItem ) { m_Unit = aItem.m_Unit; m_Convert = aItem.m_Convert; m_Fill = aItem.m_Fill; - m_Parent = aItem.m_Parent; m_typeName = aItem.m_typeName; m_isFillable = aItem.m_isFillable; + m_eraseLastDrawItem = false; } @@ -53,7 +53,7 @@ LIB_DRAW_ITEM::LIB_DRAW_ITEM( const LIB_DRAW_ITEM& aItem ) : * all library items. Call the base class from the derived class or the * common information will not be updated in the message panel. */ -void LIB_DRAW_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame ) +void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame ) { wxString msg; @@ -78,7 +78,7 @@ void LIB_DRAW_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame ) } -bool LIB_DRAW_ITEM::operator==( const LIB_DRAW_ITEM& aOther ) const +bool LIB_ITEM::operator==( const LIB_ITEM& aOther ) const { return ( ( Type() == aOther.Type() ) && ( m_Unit == aOther.m_Unit ) @@ -87,7 +87,7 @@ bool LIB_DRAW_ITEM::operator==( const LIB_DRAW_ITEM& aOther ) const } -bool LIB_DRAW_ITEM::operator<( const LIB_DRAW_ITEM& aOther ) const +bool LIB_ITEM::operator<( const LIB_ITEM& aOther ) const { int result = m_Convert - aOther.m_Convert; @@ -108,8 +108,8 @@ bool LIB_DRAW_ITEM::operator<( const LIB_DRAW_ITEM& aOther ) const } -void LIB_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, - int aDrawMode, void* aData, const TRANSFORM& aTransform ) +void LIB_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, int aColor, + int aDrawMode, void* aData, const TRANSFORM& aTransform ) { if( InEditMode() ) { @@ -143,7 +143,7 @@ void LIB_DRAW_ITEM::Draw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOff } -int LIB_DRAW_ITEM::GetDefaultColor() +int LIB_ITEM::GetDefaultColor() { return ReturnLayerColor( LAYER_DEVICE ); } diff --git a/eeschema/lib_draw_item.h b/eeschema/lib_draw_item.h index 1c3a85350b..6128ab8bd5 100644 --- a/eeschema/lib_draw_item.h +++ b/eeschema/lib_draw_item.h @@ -4,8 +4,8 @@ /* Definitions of graphic items used to create shapes in component libraries. */ -#ifndef _LIB_DRAW_ITEM_H_ -#define _LIB_DRAW_ITEM_H_ +#ifndef _LIB_ITEM_H_ +#define _LIB_ITEM_H_ #include "base_struct.h" #include "transform.h" @@ -15,7 +15,7 @@ class LIB_COMPONENT; class PLOTTER; -class LIB_DRAW_ITEM; +class LIB_ITEM; class LIB_PIN; @@ -31,14 +31,14 @@ extern const int fill_tab[]; * in them. If you access a object pointer from the list, do not delete * it directly. */ -typedef boost::ptr_vector< LIB_DRAW_ITEM > LIB_DRAW_ITEM_LIST; +typedef boost::ptr_vector< LIB_ITEM > LIB_ITEMS; /** * Helper for defining a list of pin object pointers. The list does not * use a Boost pointer class so the object pointers do not accidently get * deleted when the container is deleted. */ -typedef std::vector< LIB_PIN* > LIB_PIN_LIST; +typedef std::vector< LIB_PIN* > LIB_PINS; /****************************************************************************/ @@ -50,7 +50,7 @@ typedef std::vector< LIB_PIN* > LIB_PIN_LIST; * Base class for drawable items used in library components. * (graphic shapes, texts, fields, pins) */ -class LIB_DRAW_ITEM : public EDA_ITEM +class LIB_ITEM : public EDA_ITEM { /** * Draws the item. @@ -111,15 +111,15 @@ protected: public: - LIB_DRAW_ITEM( KICAD_T aType, - LIB_COMPONENT* aComponent = NULL, - int aUnit = 0, - int aConvert = 0, - FILL_T aFillType = NO_FILL ); + LIB_ITEM( KICAD_T aType, + LIB_COMPONENT* aComponent = NULL, + int aUnit = 0, + int aConvert = 0, + FILL_T aFillType = NO_FILL ); - LIB_DRAW_ITEM( const LIB_DRAW_ITEM& aItem ); + LIB_ITEM( const LIB_ITEM& aItem ); - virtual ~LIB_DRAW_ITEM() { } + virtual ~LIB_ITEM() { } wxString GetTypeName() { return m_typeName; } @@ -236,23 +236,13 @@ public: virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); /** - * Make a copy of this draw item. - * - * Classes derived from LIB_DRAW_ITEM must implement DoGenCopy(). - * This is just a placeholder for the derived class. - * - * @return Copy of this draw item. - */ - LIB_DRAW_ITEM* GenCopy() { return DoGenCopy(); } - - /** - * Test LIB_DRAW_ITEM objects for equivalence. + * Test LIB_ITEM objects for equivalence. * * @param aOther - Object to test against. * @return - True if object is identical to this object. */ - bool operator==( const LIB_DRAW_ITEM& aOther ) const; - bool operator==( const LIB_DRAW_ITEM* aOther ) const + bool operator==( const LIB_ITEM& aOther ) const; + bool operator==( const LIB_ITEM* aOther ) const { return *this == *aOther; } @@ -263,7 +253,7 @@ public: * @param aOther - Draw item to compare against. * @return - True if object is less than this object. */ - bool operator<( const LIB_DRAW_ITEM& aOther) const; + bool operator<( const LIB_ITEM& aOther) const; /** * Set drawing object offset from the current position. @@ -369,7 +359,6 @@ public: FILL_T GetFillMode() const { return m_Fill; } protected: - virtual LIB_DRAW_ITEM* DoGenCopy() = 0; /** * Provide the draw object specific comparison. @@ -382,7 +371,7 @@ protected: * - KICAD_T enum value. * - Result of derived classes comparison. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const = 0; + virtual int DoCompare( const LIB_ITEM& aOther ) const = 0; virtual void DoOffset( const wxPoint& aOffset ) = 0; virtual bool DoTestInside( EDA_RECT& aRect ) const = 0; virtual void DoMove( const wxPoint& aPosition ) = 0; @@ -398,4 +387,4 @@ protected: }; -#endif // _LIB_DRAW_ITEM_H_ +#endif // _LIB_ITEM_H_ diff --git a/eeschema/lib_field.cpp b/eeschema/lib_field.cpp index e25dbdda4a..3f845cbfc1 100644 --- a/eeschema/lib_field.cpp +++ b/eeschema/lib_field.cpp @@ -41,19 +41,19 @@ * others = free fields */ LIB_FIELD::LIB_FIELD(LIB_COMPONENT * aParent, int idfield ) : - LIB_DRAW_ITEM( LIB_FIELD_T, aParent ) + LIB_ITEM( LIB_FIELD_T, aParent ) { Init( idfield ); } -LIB_FIELD::LIB_FIELD( int idfield ) : LIB_DRAW_ITEM( LIB_FIELD_T, NULL ) +LIB_FIELD::LIB_FIELD( int idfield ) : LIB_ITEM( LIB_FIELD_T, NULL ) { Init( idfield ); } -LIB_FIELD::LIB_FIELD( const LIB_FIELD& field ) : LIB_DRAW_ITEM( field ) +LIB_FIELD::LIB_FIELD( const LIB_FIELD& field ) : LIB_ITEM( field ) { m_id = field.m_id; m_Pos = field.m_Pos; @@ -390,13 +390,13 @@ bool LIB_FIELD::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTr } -LIB_DRAW_ITEM* LIB_FIELD::DoGenCopy() +EDA_ITEM* LIB_FIELD::doClone() const { LIB_FIELD* newfield = new LIB_FIELD( m_id ); Copy( newfield ); - return (LIB_DRAW_ITEM*) newfield; + return (EDA_ITEM*) newfield; } @@ -417,7 +417,7 @@ void LIB_FIELD::Copy( LIB_FIELD* aTarget ) const } -int LIB_FIELD::DoCompare( const LIB_DRAW_ITEM& other ) const +int LIB_FIELD::DoCompare( const LIB_ITEM& other ) const { wxASSERT( other.Type() == LIB_FIELD_T ); @@ -654,6 +654,14 @@ void LIB_FIELD::SetText( const wxString& aText ) } +wxString LIB_FIELD::GetSelectMenuText() const +{ + return wxString::Format( _( "Field %s %s" ), + GetChars( GetName() ), + GetChars( GetText() ) ); +} + + void LIB_FIELD::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0, @@ -723,7 +731,7 @@ void LIB_FIELD::DisplayInfo( EDA_DRAW_FRAME* aFrame ) { wxString msg; - LIB_DRAW_ITEM::DisplayInfo( aFrame ); + LIB_ITEM::DisplayInfo( aFrame ); // Display style: msg = GetTextStyleName(); diff --git a/eeschema/lib_field.h b/eeschema/lib_field.h index 54b3054b9d..1fffc8bba3 100644 --- a/eeschema/lib_field.h +++ b/eeschema/lib_field.h @@ -15,7 +15,7 @@ * the component property editor assumes it. * @see enum NumFieldType */ -class LIB_FIELD : public LIB_DRAW_ITEM, public EDA_TEXT +class LIB_FIELD : public LIB_ITEM, public EDA_TEXT { int m_id; ///< @see enum NumFieldType wxString m_name; ///< Name (not the field text value itself, that is .m_Text) @@ -190,17 +190,17 @@ public: int GetDefaultColor(); /** - * See LIB_DRAW_ITEM::BeginEdit(). + * See LIB_ITEM::BeginEdit(). */ void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); /** - * See LIB_DRAW_ITEM::ContinueEdit(). + * See LIB_ITEM::ContinueEdit(). */ bool ContinueEdit( const wxPoint aNextPoint ); /** - * See LIB_DRAW_ITEM::AbortEdit(). + * See LIB_ITEM::AbortEdit(). */ void EndEdit( const wxPoint& aPosition, bool aAbort = false ); @@ -219,8 +219,12 @@ public: */ void SetText( const wxString& aText ); + virtual wxString GetSelectMenuText() const; + + virtual const char** GetMenuImage() const { return (const char**) move_field_xpm; } + protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the field draw object specific comparison. @@ -234,7 +238,7 @@ protected: * - Field width. * - Field height. */ - virtual int DoCompare( const LIB_DRAW_ITEM& other ) const; + virtual int DoCompare( const LIB_ITEM& other ) const; virtual void DoOffset( const wxPoint& offset ); virtual bool DoTestInside( EDA_RECT& rect ) const; @@ -247,6 +251,6 @@ protected: virtual void DoSetWidth( int width ) { m_Thickness = width; } }; -typedef std::vector< LIB_FIELD > LIB_FIELD_LIST; +typedef std::vector< LIB_FIELD > LIB_FIELDS; #endif // CLASS_LIBENTRY_FIELDS_H diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp index c2447d41c2..073d80ef37 100644 --- a/eeschema/lib_pin.cpp +++ b/eeschema/lib_pin.cpp @@ -162,7 +162,7 @@ extern void PlotPinSymbol( PLOTTER* plotter, const wxPoint& pos, LIB_PIN::LIB_PIN( LIB_COMPONENT* aParent ) : - LIB_DRAW_ITEM( LIB_PIN_T, aParent ) + LIB_ITEM( LIB_PIN_T, aParent ) { m_length = 300; /* default Pin len */ m_orientation = PIN_RIGHT; /* Pin orient: Up, Down, Left, Right */ @@ -181,7 +181,7 @@ LIB_PIN::LIB_PIN( LIB_COMPONENT* aParent ) : } -LIB_PIN::LIB_PIN( const LIB_PIN& pin ) : LIB_DRAW_ITEM( pin ) +LIB_PIN::LIB_PIN( const LIB_PIN& pin ) : LIB_ITEM( pin ) { m_position = pin.m_position; m_length = pin.m_length; @@ -216,7 +216,7 @@ void LIB_PIN::SetName( const wxString& aName ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -241,7 +241,7 @@ void LIB_PIN::SetNameTextSize( int size ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -285,7 +285,7 @@ void LIB_PIN::SetNumberTextSize( int size ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -310,7 +310,7 @@ void LIB_PIN::SetOrientation( int orientation ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -335,7 +335,7 @@ void LIB_PIN::SetShape( int aShape ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -362,7 +362,7 @@ void LIB_PIN::SetType( int aType ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -387,7 +387,7 @@ void LIB_PIN::SetLength( int length ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -427,7 +427,7 @@ void LIB_PIN::SetPartNumber( int part ) || ( pin->m_orientation != m_orientation ) ) continue; - GetParent()->RemoveDrawItem( (LIB_DRAW_ITEM*) pin ); + GetParent()->RemoveDrawItem( (LIB_ITEM*) pin ); } } } @@ -458,7 +458,7 @@ void LIB_PIN::SetConversion( int style ) || ( pin->m_orientation != m_orientation ) ) continue; - GetParent()->RemoveDrawItem( (LIB_DRAW_ITEM*) pin ); + GetParent()->RemoveDrawItem( (LIB_ITEM*) pin ); } } } @@ -479,7 +479,7 @@ void LIB_PIN::SetVisible( bool visible ) if( GetParent() == NULL ) return; - LIB_PIN_LIST pinList; + LIB_PINS pinList; GetParent()->GetPins( pinList ); for( size_t i = 0; i < pinList.size(); i++ ) @@ -499,7 +499,7 @@ void LIB_PIN::SetVisible( bool visible ) void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin ) { - LIB_PIN_LIST pinList; + LIB_PINS pinList; if( GetParent() == NULL ) return; @@ -525,22 +525,16 @@ void LIB_PIN::EnableEditMode( bool enable, bool editPinByPin ) bool LIB_PIN::HitTest( const wxPoint& aPosition ) { - int mindist = m_width ? m_width / 2 : g_DrawDefaultLineThickness / 2; - - // Have a minimal tolerance for hit test - if( mindist < 3 ) - mindist = 3; // = 3 mils - - return HitTest( aPosition, mindist, DefaultTransform ); + return HitTest( aPosition, 0, DefaultTransform ); } bool LIB_PIN::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ) { - wxPoint pinPos = aTransform.TransformCoordinate( m_position ); - wxPoint pinEnd = aTransform.TransformCoordinate( ReturnPinEndPoint() ); + EDA_RECT rect = GetBoundingBox(); + rect.Inflate( aThreshold ); - return TestSegmentHit( aPosition, pinPos, pinEnd, aThreshold ); + return rect.Contains( aPosition ); } @@ -1599,34 +1593,13 @@ void LIB_PIN::SetPinNumFromString( wxString& buffer ) } -LIB_DRAW_ITEM* LIB_PIN::DoGenCopy() +EDA_ITEM* LIB_PIN::doClone() const { - LIB_PIN* newpin = new LIB_PIN( GetParent() ); - - newpin->m_position = m_position; - newpin->m_length = m_length; - newpin->m_orientation = m_orientation; - newpin->m_shape = m_shape; - newpin->m_type = m_type; - newpin->m_attributes = m_attributes; - newpin->m_number = m_number; - newpin->m_PinNumSize = m_PinNumSize; - newpin->m_PinNameSize = m_PinNameSize; - newpin->m_PinNumShapeOpt = m_PinNumShapeOpt; - newpin->m_PinNameShapeOpt = m_PinNameShapeOpt; - newpin->m_PinNumPositionOpt = m_PinNumPositionOpt; - newpin->m_PinNamePositionOpt = m_PinNamePositionOpt; - newpin->m_Unit = m_Unit; - newpin->m_Convert = m_Convert; - newpin->m_Flags = m_Flags; - newpin->m_width = m_width; - newpin->m_name = m_name; - - return (LIB_DRAW_ITEM*) newpin; + return new LIB_PIN( *this ); } -int LIB_PIN::DoCompare( const LIB_DRAW_ITEM& other ) const +int LIB_PIN::DoCompare( const LIB_ITEM& other ) const { wxASSERT( other.Type() == LIB_PIN_T ); @@ -1724,7 +1697,7 @@ void LIB_PIN::DisplayInfo( EDA_DRAW_FRAME* frame ) { wxString Text; - LIB_DRAW_ITEM::DisplayInfo( frame ); + LIB_ITEM::DisplayInfo( frame ); frame->AppendMsgPanel( _( "Name" ), m_name, DARKCYAN ); @@ -1766,35 +1739,57 @@ EDA_RECT LIB_PIN::GetBoundingBox() const EDA_RECT bbox; wxPoint begin; wxPoint end; - int pinname_offset = 0; + int nameTextOffset = 0; + bool showName = !m_name.IsEmpty() && (m_name != wxT( "~" )); + int symbolX = TARGET_PIN_DIAM / 2; + int symbolY = TARGET_PIN_DIAM / 2; if( entry ) - pinname_offset = entry->GetPinNameOffset(); + { + if( entry->ShowPinNames() ) + nameTextOffset = entry->GetPinNameOffset(); + else + showName = false; + } // First, calculate boundary box corners position - int pinnum_len = m_PinNumSize * GetNumberString().Len(); + int numberTextLength = m_PinNumSize * GetNumberString().Len(); // Actual text height are bigger than text size - int pinname_hight = wxRound( m_PinNameSize * 1.3 ); - int pinnum_hight = wxRound( m_PinNumSize * 1.3 ); + int nameTextHeight = wxRound( m_PinNameSize * 1.1 ); + int numberTextHeight = wxRound( m_PinNumSize * 1.1 ); + + if( m_shape & INVERT ) + symbolX = symbolY = INVERT_PIN_RADIUS; // calculate top left corner position // for the default pin orientation (PIN_RIGHT) - begin.y = pinnum_hight + TXTMARGE; - begin.x = MIN( -TARGET_PIN_DIAM, m_length - pinnum_len / 2 ); + begin.y = numberTextHeight + TXTMARGE; + begin.x = MIN( -TARGET_PIN_DIAM / 2, m_length - (numberTextLength / 2) ); // calculate bottom right corner position and adjust top left corner position - int pinname_len = m_PinNameSize * m_name.Len(); - if( pinname_offset ) + int nameTextLength = 0; + + if( showName ) { - end.y = -pinname_hight / 2; - end.x = m_length + pinname_offset + pinname_len; + int length = m_name.Len(); + + // Don't count the line over text symbol. + if( m_name.Left( 1 ) == wxT( "~" ) ) + length -= 1; + + nameTextLength = ( m_PinNameSize * length ) + nameTextOffset; + } + + if( showName ) + { + end.y = -nameTextHeight / 2; + end.x = m_length + nameTextLength; } else { - end.y = -pinname_hight - TXTMARGE; - end.x = MAX( m_length, pinname_len / 2 ); - begin.x = MIN( begin.x, m_length - pinname_len / 2 ); + end.y = -symbolY; + end.x = m_length; } // Now, calculate boundary box corners position for the actual pin orientation diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h index f2cc0dd740..0d7e38b147 100644 --- a/eeschema/lib_pin.h +++ b/eeschema/lib_pin.h @@ -80,7 +80,7 @@ enum DrawPinOrient { }; -class LIB_PIN : public LIB_DRAW_ITEM +class LIB_PIN : public LIB_ITEM { wxPoint m_position; ///< Position of the pin. int m_length; ///< Length of the pin. @@ -455,7 +455,7 @@ public: virtual wxString GetSelectMenuText() const; protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the pin draw object specific comparison. @@ -466,7 +466,7 @@ protected: * - Pin horizontal (X) position. * - Pin vertical (Y) position. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; virtual void DoMove( const wxPoint& aPosition ); diff --git a/eeschema/lib_polyline.cpp b/eeschema/lib_polyline.cpp index 9371a5fee3..39916b334f 100644 --- a/eeschema/lib_polyline.cpp +++ b/eeschema/lib_polyline.cpp @@ -20,7 +20,7 @@ LIB_POLYLINE::LIB_POLYLINE( LIB_COMPONENT* aParent ) : - LIB_DRAW_ITEM( LIB_POLYLINE_T, aParent ) + LIB_ITEM( LIB_POLYLINE_T, aParent ) { m_Fill = NO_FILL; m_Width = 0; @@ -30,11 +30,10 @@ LIB_POLYLINE::LIB_POLYLINE( LIB_COMPONENT* aParent ) : LIB_POLYLINE::LIB_POLYLINE( const LIB_POLYLINE& polyline ) : - LIB_DRAW_ITEM( polyline ) + LIB_ITEM( polyline ) { m_PolyPoints = polyline.m_PolyPoints; // Vector copy m_Width = polyline.m_Width; - m_Fill = polyline.m_Fill; } @@ -64,8 +63,7 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg ) int i, ccount = 0; wxPoint pt; - i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, - &m_Width ); + i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width ); m_Fill = NO_FILL; @@ -115,22 +113,13 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg ) } -LIB_DRAW_ITEM* LIB_POLYLINE::DoGenCopy() +EDA_ITEM* LIB_POLYLINE::doClone() const { - LIB_POLYLINE* newitem = new LIB_POLYLINE( GetParent() ); - - newitem->m_PolyPoints = m_PolyPoints; // Vector copy - newitem->m_Width = m_Width; - newitem->m_Unit = m_Unit; - newitem->m_Convert = m_Convert; - newitem->m_Flags = m_Flags; - newitem->m_Fill = m_Fill; - - return (LIB_DRAW_ITEM*) newitem; + return new LIB_POLYLINE( *this ); } -int LIB_POLYLINE::DoCompare( const LIB_DRAW_ITEM& aOther ) const +int LIB_POLYLINE::DoCompare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_POLYLINE_T ); @@ -383,7 +372,7 @@ void LIB_POLYLINE::DisplayInfo( EDA_DRAW_FRAME* aFrame ) wxString msg; EDA_RECT bBox = GetBoundingBox(); - LIB_DRAW_ITEM::DisplayInfo( aFrame ); + LIB_ITEM::DisplayInfo( aFrame ); msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true ); @@ -396,6 +385,17 @@ void LIB_POLYLINE::DisplayInfo( EDA_DRAW_FRAME* aFrame ) } +wxString LIB_POLYLINE::GetSelectMenuText() const +{ + return wxString::Format( _( "Polyline at (%s, %s) with %u points" ), + GetChars( CoordinateToString( m_PolyPoints[0].x, + EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_PolyPoints[0].y, + EESCHEMA_INTERNAL_UNIT ) ), + m_PolyPoints.size() ); +} + + void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0, diff --git a/eeschema/lib_polyline.h b/eeschema/lib_polyline.h index 6964b6f46b..2cbe75bbf6 100644 --- a/eeschema/lib_polyline.h +++ b/eeschema/lib_polyline.h @@ -9,7 +9,7 @@ #include "lib_draw_item.h" -class LIB_POLYLINE : public LIB_DRAW_ITEM +class LIB_POLYLINE : public LIB_ITEM { int m_Width; // Line width std::vector m_PolyPoints; // list of points (>= 2) @@ -91,22 +91,26 @@ public: virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); /** - * See LIB_DRAW_ITEM::BeginEdit(). + * See LIB_ITEM::BeginEdit(). */ void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); /** - * See LIB_DRAW_ITEM::ContinueEdit(). + * See LIB_ITEM::ContinueEdit(). */ bool ContinueEdit( const wxPoint aNextPoint ); /** - * See LIB_DRAW_ITEM::AbortEdit(). + * See LIB_ITEM::AbortEdit(). */ void EndEdit( const wxPoint& aPosition, bool aAbort = false ); + virtual wxString GetSelectMenuText() const; + + virtual const char** GetMenuImage() const { return (const char**) add_polygon_xpm; } + protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the polyline segment draw object specific comparison. @@ -115,7 +119,7 @@ protected: * - Line segment point horizontal (X) position. * - Line segment point vertical (Y) position. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; diff --git a/eeschema/lib_rectangle.cpp b/eeschema/lib_rectangle.cpp index 57effb96b2..826e5794e8 100644 --- a/eeschema/lib_rectangle.cpp +++ b/eeschema/lib_rectangle.cpp @@ -5,6 +5,7 @@ #include "fctsys.h" #include "gr_basic.h" #include "common.h" +#include "macros.h" #include "class_drawpanel.h" #include "plot_common.h" #include "trigo.h" @@ -17,7 +18,7 @@ LIB_RECTANGLE::LIB_RECTANGLE( LIB_COMPONENT* aParent ) : - LIB_DRAW_ITEM( LIB_RECTANGLE_T, aParent ) + LIB_ITEM( LIB_RECTANGLE_T, aParent ) { m_Width = 0; m_Fill = NO_FILL; @@ -30,7 +31,7 @@ LIB_RECTANGLE::LIB_RECTANGLE( LIB_COMPONENT* aParent ) : LIB_RECTANGLE::LIB_RECTANGLE( const LIB_RECTANGLE& aRect ) : - LIB_DRAW_ITEM( aRect ) + LIB_ITEM( aRect ) { m_Pos = aRect.m_Pos; m_End = aRect.m_End; @@ -72,23 +73,13 @@ bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg ) } -LIB_DRAW_ITEM* LIB_RECTANGLE::DoGenCopy() +EDA_ITEM* LIB_RECTANGLE::doClone() const { - LIB_RECTANGLE* newitem = new LIB_RECTANGLE( GetParent() ); - - newitem->m_Pos = m_Pos; - newitem->m_End = m_End; - newitem->m_Width = m_Width; - newitem->m_Unit = m_Unit; - newitem->m_Convert = m_Convert; - newitem->m_Flags = m_Flags; - newitem->m_Fill = m_Fill; - - return (LIB_DRAW_ITEM*) newitem; + return new LIB_RECTANGLE( *this ); } -int LIB_RECTANGLE::DoCompare( const LIB_DRAW_ITEM& aOther ) const +int LIB_RECTANGLE::DoCompare( const LIB_ITEM& aOther ) const { wxASSERT( aOther.Type() == LIB_RECTANGLE_T ); @@ -221,7 +212,7 @@ void LIB_RECTANGLE::DisplayInfo( EDA_DRAW_FRAME* aFrame ) { wxString msg; - LIB_DRAW_ITEM::DisplayInfo( aFrame ); + LIB_ITEM::DisplayInfo( aFrame ); msg = ReturnStringFromValue( g_UserUnit, m_Width, EESCHEMA_INTERNAL_UNIT, true ); @@ -289,6 +280,16 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& } +wxString LIB_RECTANGLE::GetSelectMenuText() const +{ + return wxString::Format( _( "Rectangle from (%s, %s) to (%s, %s)" ), + GetChars( CoordinateToString( m_Pos.x, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_Pos.y, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_End.x, EESCHEMA_INTERNAL_UNIT ) ), + GetChars( CoordinateToString( m_End.y, EESCHEMA_INTERNAL_UNIT ) ) ); +} + + void LIB_RECTANGLE::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0, diff --git a/eeschema/lib_rectangle.h b/eeschema/lib_rectangle.h index b023c81c2e..bfe41bab3c 100644 --- a/eeschema/lib_rectangle.h +++ b/eeschema/lib_rectangle.h @@ -9,7 +9,7 @@ #include "lib_draw_item.h" -class LIB_RECTANGLE : public LIB_DRAW_ITEM +class LIB_RECTANGLE : public LIB_ITEM { wxPoint m_End; // Rectangle end point. wxPoint m_Pos; // Rectangle start point. @@ -79,22 +79,26 @@ public: virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); /** - * See LIB_DRAW_ITEM::BeginEdit(). + * See LIB_ITEM::BeginEdit(). */ void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); /** - * See LIB_DRAW_ITEM::ContinueEdit(). + * See LIB_ITEM::ContinueEdit(). */ bool ContinueEdit( const wxPoint aNextPoint ); /** - * See LIB_DRAW_ITEM::AbortEdit(). + * See LIB_ITEM::AbortEdit(). */ void EndEdit( const wxPoint& aPosition, bool aAbort = false ); + virtual wxString GetSelectMenuText() const; + + virtual const char** GetMenuImage() const { return (const char**) add_rectangle_xpm; } + protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the rectangle draw object specific comparison. @@ -105,7 +109,7 @@ protected: * - Rectangle horizontal (X) end position. * - Rectangle vertical (Y) end position. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; diff --git a/eeschema/lib_text.cpp b/eeschema/lib_text.cpp index 1469561973..8061c642f2 100644 --- a/eeschema/lib_text.cpp +++ b/eeschema/lib_text.cpp @@ -25,7 +25,7 @@ LIB_TEXT::LIB_TEXT(LIB_COMPONENT * aParent) : - LIB_DRAW_ITEM( LIB_TEXT_T, aParent ), + LIB_ITEM( LIB_TEXT_T, aParent ), EDA_TEXT() { m_Size = wxSize( 50, 50 ); @@ -187,7 +187,7 @@ bool LIB_TEXT::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTra } -LIB_DRAW_ITEM* LIB_TEXT::DoGenCopy() +EDA_ITEM* LIB_TEXT::doClone() const { LIB_TEXT* newitem = new LIB_TEXT(NULL); @@ -204,11 +204,11 @@ LIB_DRAW_ITEM* LIB_TEXT::DoGenCopy() newitem->m_Bold = m_Bold; newitem->m_HJustify = m_HJustify; newitem->m_VJustify = m_VJustify; - return (LIB_DRAW_ITEM*) newitem; + return (EDA_ITEM*) newitem; } -int LIB_TEXT::DoCompare( const LIB_DRAW_ITEM& other ) const +int LIB_TEXT::DoCompare( const LIB_ITEM& other ) const { wxASSERT( other.Type() == LIB_TEXT_T ); @@ -379,7 +379,7 @@ void LIB_TEXT::DisplayInfo( EDA_DRAW_FRAME* frame ) { wxString msg; - LIB_DRAW_ITEM::DisplayInfo( frame ); + LIB_ITEM::DisplayInfo( frame ); msg = ReturnStringFromValue( g_UserUnit, m_Thickness, EESCHEMA_INTERNAL_UNIT, true ); @@ -440,6 +440,20 @@ void LIB_TEXT::SetText( const wxString& aText ) } +wxString LIB_TEXT::GetSelectMenuText() const +{ + wxString tmp = GetText(); + tmp.Replace( wxT( "\n" ), wxT( " " ) ); + tmp.Replace( wxT( "\r" ), wxT( " " ) ); + tmp.Replace( wxT( "\t" ), wxT( " " ) ); + tmp =( tmp.Length() > 15 ) ? tmp.Left( 12 ) + wxT( "..." ) : tmp; + + wxString msg; + msg.Printf( _( "Graphic Text %s" ), GetChars( tmp ) ); + return msg; +} + + void LIB_TEXT::BeginEdit( int aEditMode, const wxPoint aPosition ) { wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED ) ) != 0, diff --git a/eeschema/lib_text.h b/eeschema/lib_text.h index 614fd902f9..dc9e926eee 100644 --- a/eeschema/lib_text.h +++ b/eeschema/lib_text.h @@ -12,7 +12,7 @@ /* Fields like Ref , value... are not Text, */ /* they are a separate class */ /*********************************************/ -class LIB_TEXT : public LIB_DRAW_ITEM, public EDA_TEXT +class LIB_TEXT : public LIB_ITEM, public EDA_TEXT { wxString m_savedText; ///< Temporary storage for the string when edition. bool m_rotate; ///< Flag to indicate a rotation occurred while editing. @@ -103,22 +103,26 @@ public: void Rotate(); /** - * See LIB_DRAW_ITEM::BeginEdit(). + * See LIB_ITEM::BeginEdit(). */ void BeginEdit( int aEditMode, const wxPoint aStartPoint = wxPoint( 0, 0 ) ); /** - * See LIB_DRAW_ITEM::ContinueEdit(). + * See LIB_ITEM::ContinueEdit(). */ bool ContinueEdit( const wxPoint aNextPoint ); /** - * See LIB_DRAW_ITEM::AbortEdit(). + * See LIB_ITEM::AbortEdit(). */ void EndEdit( const wxPoint& aPosition, bool aAbort = false ); + virtual wxString GetSelectMenuText() const; + + virtual const char** GetMenuImage() const { return (const char**) add_text_xpm; } + protected: - virtual LIB_DRAW_ITEM* DoGenCopy(); + virtual EDA_ITEM* doClone() const; /** * Provide the text draw object specific comparison. @@ -130,7 +134,7 @@ protected: * - Text width. * - Text height. */ - virtual int DoCompare( const LIB_DRAW_ITEM& aOther ) const; + virtual int DoCompare( const LIB_ITEM& aOther ) const; virtual void DoOffset( const wxPoint& aOffset ); virtual bool DoTestInside( EDA_RECT& aRect ) const; diff --git a/eeschema/libedit_onleftclick.cpp b/eeschema/libedit_onleftclick.cpp index 539e35f995..3520ba34fc 100644 --- a/eeschema/libedit_onleftclick.cpp +++ b/eeschema/libedit_onleftclick.cpp @@ -20,27 +20,32 @@ void LIB_EDIT_FRAME::OnLeftClick( wxDC* DC, const wxPoint& aPosition ) { - LIB_DRAW_ITEM* DrawEntry = m_drawItem; + LIB_ITEM* item = m_drawItem; if( m_component == NULL ) // No component loaded ! return; - if( DrawEntry == NULL || DrawEntry->m_Flags == 0 ) + if( item == NULL || item->m_Flags == 0 ) { - DrawEntry = LocateItemUsingCursor( aPosition ); + item = LocateItemUsingCursor( aPosition ); - if( DrawEntry ) - DrawEntry->DisplayInfo( this ); + if( item ) + item->DisplayInfo( this ); else + { DisplayCmpDoc(); + + if( DrawPanel->m_AbortRequest ) + DrawPanel->m_AbortRequest = false; + } } switch( GetToolId() ) { case ID_NO_TOOL_SELECTED: - if( DrawEntry && DrawEntry->m_Flags ) // moved object + if( item && item->m_Flags ) // moved object { - switch( DrawEntry->Type() ) + switch( item->Type() ) { case LIB_PIN_T: PlacePin( DC ); diff --git a/eeschema/libedit_onrightclick.cpp b/eeschema/libedit_onrightclick.cpp index 4fef2311e0..007da67efe 100644 --- a/eeschema/libedit_onrightclick.cpp +++ b/eeschema/libedit_onrightclick.cpp @@ -13,6 +13,7 @@ #include "bitmaps.h" #include "eeschema_id.h" #include "hotkeys.h" +#include "class_drawpanel.h" #include "class_sch_screen.h" #include "general.h" @@ -30,7 +31,7 @@ static void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) { - LIB_DRAW_ITEM* DrawEntry = GetDrawItem(); + LIB_ITEM* item = GetDrawItem(); bool BlockActive = GetScreen()->IsBlockActive(); if( BlockActive ) @@ -44,38 +45,47 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) return true; // If Command in progress, put menu "cancel" - if( DrawEntry && DrawEntry->GetFlags() ) + if( item && item->GetFlags() ) { ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "Cancel" ), cancel_xpm ); PopMenu->AppendSeparator(); } else { - DrawEntry = LocateItemUsingCursor( aPosition ); + item = LocateItemUsingCursor( aPosition ); + + // If the clarify item selection context menu is aborted, don't show the context menu. + if( item == NULL && DrawPanel->m_AbortRequest ) + { + DrawPanel->m_AbortRequest = false; + return false; + } + if( GetToolId() != ID_NO_TOOL_SELECTED ) { // If a tool is active, put menu "end tool" - ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ), cancel_tool_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_CANCEL_EDITING, _( "End Tool" ), + cancel_tool_xpm ); PopMenu->AppendSeparator(); } } - if( DrawEntry ) - DrawEntry->DisplayInfo( this ); + if( item ) + item->DisplayInfo( this ); else return true; - m_drawItem = DrawEntry; + m_drawItem = item; wxString msg; - switch( DrawEntry->Type() ) + switch( item->Type() ) { case LIB_PIN_T: - AddMenusForPin( PopMenu, (LIB_PIN*) DrawEntry, this ); + AddMenusForPin( PopMenu, (LIB_PIN*) item, this ); break; case LIB_ARC_T: - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Move Arc" ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); @@ -87,7 +97,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) msg = AddHotkeyName( _( "Edit Arc Options" ), s_Libedit_Hokeys_Descr, HK_EDIT ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_arc_xpm ); - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Delete Arc" ), s_Libedit_Hokeys_Descr, HK_DELETE ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_arc_xpm ); @@ -95,14 +105,14 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) break; case LIB_CIRCLE_T: - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Move Circle" ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST, msg, move_circle_xpm ); } - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Drag Circle Outline" ), s_Libedit_Hokeys_Descr, HK_DRAG ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_rectangle_xpm ); @@ -111,7 +121,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) msg = AddHotkeyName( _( "Edit Circle Options" ), s_Libedit_Hokeys_Descr, HK_EDIT ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_circle_xpm ); - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Delete Circle" ), s_Libedit_Hokeys_Descr, HK_DELETE ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_circle_xpm ); @@ -119,7 +129,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) break; case LIB_RECTANGLE_T: - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Move Rectangle" ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); @@ -129,13 +139,13 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) msg = AddHotkeyName( _( "Edit Rectangle Options" ), s_Libedit_Hokeys_Descr, HK_EDIT ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_rectangle_xpm ); - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Drag Rectangle Edge" ), s_Libedit_Hokeys_Descr, HK_DRAG ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_rectangle_xpm ); } - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Delete Rectangle" ), s_Libedit_Hokeys_Descr, HK_DELETE ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_rectangle_xpm ); @@ -144,7 +154,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) break; case LIB_TEXT_T: - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Move Text" ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); @@ -157,7 +167,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) msg = AddHotkeyName( _( "Rotate Text" ), s_Libedit_Hokeys_Descr, HK_ROTATE ); ADD_MENUITEM( PopMenu, ID_LIBEDIT_ROTATE_ITEM, msg, edit_text_xpm ); - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Delete Text" ), s_Libedit_Hokeys_Descr, HK_DELETE ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_text_xpm ); @@ -165,7 +175,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) break; case LIB_POLYLINE_T: - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Move Line" ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); @@ -174,7 +184,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_MODIFY_ITEM, msg, move_line_xpm ); } - if( DrawEntry->m_Flags & IS_NEW ) + if( item->IsNew() ) { ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_END_CREATE_ITEM, _( "Line End" ), apply_xpm ); } @@ -182,14 +192,14 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) msg = AddHotkeyName( _( "Edit Line Options" ), s_Libedit_Hokeys_Descr, HK_EDIT ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_BODY_EDIT_ITEM, msg, options_segment_xpm ); - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Delete Line " ), s_Libedit_Hokeys_Descr, HK_DELETE ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_ITEM, msg, delete_segment_xpm ); } - else if( (DrawEntry->m_Flags & IS_NEW) ) + else if( item->IsNew() ) { - if( ( (LIB_POLYLINE*) DrawEntry )->GetCornerCount() > 2 ) + if( ( (LIB_POLYLINE*) item )->GetCornerCount() > 2 ) { msg = AddHotkeyName( _( "Delete Segment" ), s_Libedit_Hokeys_Descr, HK_DELETE ); ADD_MENUITEM( PopMenu, ID_POPUP_LIBEDIT_DELETE_CURRENT_POLY_SEGMENT, @@ -200,7 +210,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) break; case LIB_FIELD_T: - if( DrawEntry->m_Flags == 0 ) + if( item->GetFlags() == 0 ) { msg = AddHotkeyName( _( "Move Field" ), s_Libedit_Hokeys_Descr, HK_LIBEDIT_MOVE_GRAPHIC_ITEM ); @@ -214,10 +224,8 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) default: - wxString msg; - msg.Printf( wxT( "LIB_EDIT_FRAME::OnRightClick Error: unknown StructType %d" ), - DrawEntry->Type() ); - DisplayError( this, msg ); + wxFAIL_MSG( wxString::Format( wxT( "Unknown library item type %d" ), + item->Type() ) ); m_drawItem = NULL; break; } @@ -230,7 +238,7 @@ bool LIB_EDIT_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* PopMenu ) void AddMenusForPin( wxMenu* PopMenu, LIB_PIN* Pin, LIB_EDIT_FRAME* frame ) { bool selected = (Pin->m_Selected & IS_SELECTED) != 0; - bool not_in_move = (Pin->m_Flags == 0); + bool not_in_move = (Pin->GetFlags() == 0); wxString msg; if( not_in_move ) diff --git a/eeschema/libeditframe.cpp b/eeschema/libeditframe.cpp index 72aa395f00..0020341f8b 100644 --- a/eeschema/libeditframe.cpp +++ b/eeschema/libeditframe.cpp @@ -61,8 +61,8 @@ CMP_LIBRARY* LIB_EDIT_FRAME:: m_library = NULL; wxString LIB_EDIT_FRAME:: m_aliasName; int LIB_EDIT_FRAME:: m_unit = 1; int LIB_EDIT_FRAME:: m_convert = 1; -LIB_DRAW_ITEM* LIB_EDIT_FRAME::m_lastDrawItem = NULL; -LIB_DRAW_ITEM* LIB_EDIT_FRAME::m_drawItem = NULL; +LIB_ITEM* LIB_EDIT_FRAME::m_lastDrawItem = NULL; +LIB_ITEM* LIB_EDIT_FRAME::m_drawItem = NULL; bool LIB_EDIT_FRAME:: m_showDeMorgan = false; wxSize LIB_EDIT_FRAME:: m_clientSize = wxSize( -1, -1 ); int LIB_EDIT_FRAME:: m_textSize = DEFAULT_SIZE_TEXT; @@ -123,6 +123,9 @@ BEGIN_EVENT_TABLE( LIB_EDIT_FRAME, EDA_DRAW_FRAME ) EVT_MENU( ID_COLORS_SETUP, LIB_EDIT_FRAME::Process_Config ) EVT_MENU( ID_LIBEDIT_DIMENSIONS, LIB_EDIT_FRAME::InstallDimensionsDialog ) + // Multple item selection context menu commands. + EVT_MENU_RANGE( ID_SELECT_ITEM_START, ID_SELECT_ITEM_END, LIB_EDIT_FRAME::OnSelectItem ) + EVT_MENU_RANGE( ID_PREFERENCES_HOTKEY_START, ID_PREFERENCES_HOTKEY_END, LIB_EDIT_FRAME::Process_Config ) @@ -282,7 +285,7 @@ void LIB_EDIT_FRAME::LoadSettings() } -void LIB_EDIT_FRAME::SetDrawItem( LIB_DRAW_ITEM* drawItem ) +void LIB_EDIT_FRAME::SetDrawItem( LIB_ITEM* drawItem ) { m_drawItem = drawItem; } @@ -722,7 +725,7 @@ void LIB_EDIT_FRAME::Process_Special_Functions( wxCommandEvent& event ) case ID_POPUP_LIBEDIT_MOVE_ITEM_REQUEST: if( m_drawItem == NULL ) break; - DrawPanel->MoveCursorToCrossHair(); + if( m_drawItem->Type() == LIB_PIN_T ) StartMovePin( &dc ); else @@ -906,7 +909,7 @@ void LIB_EDIT_FRAME::SVG_Print_Component( const wxString& FullFileName ) } -void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) +void LIB_EDIT_FRAME::EditSymbolText( wxDC* DC, LIB_ITEM* DrawItem ) { if ( ( DrawItem == NULL ) || ( DrawItem->Type() != LIB_TEXT_T ) ) return; @@ -1075,18 +1078,77 @@ void LIB_EDIT_FRAME::OnRotateItem( wxCommandEvent& aEvent ) } -LIB_DRAW_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition ) +LIB_ITEM* LIB_EDIT_FRAME::LocateItemUsingCursor( const wxPoint& aPosition, + const KICAD_T aFilterList[] ) { if( m_component == NULL ) return NULL; - LIB_DRAW_ITEM* item = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, - aPosition ); + LIB_ITEM* item = locateItem( aPosition, aFilterList ); + + if( item == NULL ) + return NULL; wxPoint pos = GetScreen()->GetNearestGridPosition( aPosition ); if( item == NULL && aPosition != pos ) - item = m_component->LocateDrawItem( m_unit, m_convert, TYPE_NOT_INIT, pos ); + item = locateItem( pos, aFilterList ); + + return item; +} + + +LIB_ITEM* LIB_EDIT_FRAME::locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] ) +{ + if( m_component == NULL ) + return NULL; + + LIB_ITEM* item = NULL; + + m_collectedItems.Collect( m_component->GetDrawItemList(), aFilterList, aPosition, + m_unit, m_convert ); + + if( m_collectedItems.GetCount() == 0 ) + { + ClearMsgPanel(); + } + else if( m_collectedItems.GetCount() == 1 ) + { + item = m_collectedItems[0]; + } + else + { + if( item == NULL ) + { + wxASSERT_MSG( m_collectedItems.GetCount() <= MAX_SELECT_ITEM_IDS, + wxT( "Select item clarification context menu size limit exceeded." ) ); + + wxMenu selectMenu; + wxMenuItem* title = new wxMenuItem( &selectMenu, wxID_NONE, _( "Clarify Selection" ) ); + + selectMenu.Append( title ); + selectMenu.AppendSeparator(); + + for( int i = 0; i < m_collectedItems.GetCount() && i < MAX_SELECT_ITEM_IDS; i++ ) + { + wxString text = m_collectedItems[i]->GetSelectMenuText(); + const char** xpm = m_collectedItems[i]->GetMenuImage(); + ADD_MENUITEM( &selectMenu, ID_SELECT_ITEM_START + i, text, xpm ); + } + + // Set to NULL in case user aborts the clarification context menu. + m_drawItem = NULL; + DrawPanel->m_AbortRequest = true; // Changed to false if an item is selected + PopupMenu( &selectMenu ); + DrawPanel->MoveCursorToCrossHair(); + item = m_drawItem; + } + } + + if( item ) + item->DisplayInfo( this ); + else + ClearMsgPanel(); return item; } @@ -1104,7 +1166,7 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) LIB_PIN* pin = (LIB_PIN*) m_drawItem; wxPoint pos = pin->GetPosition(); - m_component->RemoveDrawItem( (LIB_DRAW_ITEM*) pin, DrawPanel, aDC ); + m_component->RemoveDrawItem( (LIB_ITEM*) pin, DrawPanel, aDC ); if( g_EditPinByPinIsOn == false ) { @@ -1118,7 +1180,7 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) if( pin->GetPosition() != pos ) continue; - m_component->RemoveDrawItem( (LIB_DRAW_ITEM*) pin ); + m_component->RemoveDrawItem( (LIB_ITEM*) pin ); } } } @@ -1134,3 +1196,18 @@ void LIB_EDIT_FRAME::deleteItem( wxDC* aDC ) OnModify(); DrawPanel->CrossHairOn( aDC ); } + + +void LIB_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent ) +{ + int id = aEvent.GetId(); + int index = id - ID_SELECT_ITEM_START; + + if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END) + && (index >= 0 && index < m_collectedItems.GetCount()) ) + { + LIB_ITEM* item = m_collectedItems[index]; + DrawPanel->m_AbortRequest = false; + m_drawItem = item; + } +} diff --git a/eeschema/libeditframe.h b/eeschema/libeditframe.h index 782ebf581a..ce09274dda 100644 --- a/eeschema/libeditframe.h +++ b/eeschema/libeditframe.h @@ -10,6 +10,7 @@ #include "class_sch_screen.h" #include "lib_draw_item.h" +#include "lib_collectors.h" class SCH_EDIT_FRAME; @@ -26,6 +27,9 @@ class DIALOG_LIB_EDIT_TEXT; class LIB_EDIT_FRAME : public EDA_DRAW_FRAME { LIB_COMPONENT* m_tempCopyComponent; ///< Temporary copy of current component during edit. + LIB_COLLECTOR m_collectedItems; // Used for hit testing. + + LIB_ITEM* locateItem( const wxPoint& aPosition, const KICAD_T aFilterList[] ); public: wxComboBox* m_SelpartBox; // a Box to select a part to edit (if any) @@ -74,6 +78,7 @@ public: void OnCheckComponent( wxCommandEvent& event ); void OnSelectBodyStyle( wxCommandEvent& event ); void OnEditPin( wxCommandEvent& event ); + void OnSelectItem( wxCommandEvent& aEvent ); void OnUpdateSelectTool( wxUpdateUIEvent& aEvent ); void OnUpdateEditingPart( wxUpdateUIEvent& event ); @@ -159,17 +164,17 @@ public: } - LIB_DRAW_ITEM* GetLastDrawItem( void ) { return m_lastDrawItem; } + LIB_ITEM* GetLastDrawItem( void ) { return m_lastDrawItem; } - void SetLastDrawItem( LIB_DRAW_ITEM* drawItem ) + void SetLastDrawItem( LIB_ITEM* drawItem ) { m_lastDrawItem = drawItem; } - LIB_DRAW_ITEM* GetDrawItem( void ) { return m_drawItem; } + LIB_ITEM* GetDrawItem( void ) { return m_drawItem; } - void SetDrawItem( LIB_DRAW_ITEM* drawItem ); + void SetDrawItem( LIB_ITEM* drawItem ); bool GetShowDeMorgan( void ) { return m_showDeMorgan; } @@ -253,16 +258,17 @@ private: void PlaceAncre(); // Editing graphic items - LIB_DRAW_ITEM* CreateGraphicItem( LIB_COMPONENT* LibEntry, wxDC* DC ); + LIB_ITEM* CreateGraphicItem( LIB_COMPONENT* LibEntry, wxDC* DC ); void GraphicItemBeginDraw( wxDC* DC ); void StartMoveDrawSymbol( wxDC* DC ); void StartModifyDrawSymbol( wxDC* DC ); //InEditMode() ) { SaveCopyInUndoList( parent ); - ( (LIB_DRAW_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, - &fieldText, DefaultTransform ); + ( (LIB_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + &fieldText, DefaultTransform ); } if( !aField->InEditMode() ) { fieldText = aField->GetFullText( m_unit ); - ( (LIB_DRAW_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, - &fieldText, DefaultTransform ); + ( (LIB_ITEM*) aField )->Draw( DrawPanel, DC, wxPoint( 0, 0 ), -1, g_XorMode, + &fieldText, DefaultTransform ); } OnModify(); diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 16765e3823..04d2914cbc 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -596,7 +596,7 @@ SCH_COMPONENT* EXPORT_HELP::findNextComponentAndCreatePinList( EDA_ITEM* a else // entry->GetPartCount() <= 1 means one part per package { - LIB_PIN_LIST pins; // constructed once here + LIB_PINS pins; // constructed once here entry->GetPins( pins, comp->GetUnitSelection( aSheetPath ), comp->GetConvert() ); @@ -727,8 +727,8 @@ XNODE* EXPORT_HELP::makeGenericLibParts() wxString sFprints = wxT( "footprints" ); wxString sFp = wxT( "fp" ); - LIB_PIN_LIST pinList; - LIB_FIELD_LIST fieldList; + LIB_PINS pinList; + LIB_FIELDS fieldList; m_Libraries.clear(); diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp index a411c51a28..1a613eac50 100644 --- a/eeschema/pinedit.cpp +++ b/eeschema/pinedit.cpp @@ -144,13 +144,15 @@ static void AbortPinMove( EDA_DRAW_PANEL* Panel, wxDC* DC ) if( parent == NULL ) return; - LIB_PIN* CurrentPin = (LIB_PIN*) parent->GetDrawItem(); + LIB_PIN* pin = (LIB_PIN*) parent->GetDrawItem(); - if( CurrentPin == NULL || CurrentPin->Type() != LIB_PIN_T ) + if( pin == NULL || pin->Type() != LIB_PIN_T ) return; - if( CurrentPin->IsNew() ) - delete CurrentPin; + pin->ClearFlags(); + + if( pin->IsNew() ) + delete pin; else parent->RestoreComponent(); @@ -408,7 +410,7 @@ static void CreateImagePins( LIB_PIN* Pin, int unit, int convert, bool asDeMorga /* Create "convert" pin at the current position. */ if( CreateConv == true ) { - NewPin = (LIB_PIN*) Pin->GenCopy(); + NewPin = (LIB_PIN*) Pin->Clone(); if( Pin->GetConvert() > 1 ) NewPin->SetConvert( 1 ); @@ -423,7 +425,7 @@ static void CreateImagePins( LIB_PIN* Pin, int unit, int convert, bool asDeMorga if( ii == unit || Pin->GetUnit() == 0 ) continue; /* Pin common to all units. */ - NewPin = (LIB_PIN*) Pin->GenCopy(); + NewPin = (LIB_PIN*) Pin->Clone(); if( convert != 0 ) NewPin->SetConvert( 1 ); @@ -434,7 +436,7 @@ static void CreateImagePins( LIB_PIN* Pin, int unit, int convert, bool asDeMorga if( CreateConv == false ) continue; - NewPin = (LIB_PIN*) Pin->GenCopy(); + NewPin = (LIB_PIN*) Pin->Clone(); NewPin->SetConvert( 2 ); if( Pin->GetUnit() != 0 ) @@ -510,7 +512,7 @@ void LIB_EDIT_FRAME::RepeatPinItem( wxDC* DC, LIB_PIN* SourcePin ) if( m_component == NULL || SourcePin == NULL || SourcePin->Type() != LIB_PIN_T ) return; - Pin = (LIB_PIN*) SourcePin->GenCopy(); + Pin = (LIB_PIN*) SourcePin->Clone(); Pin->m_Flags = IS_NEW; Pin->SetPosition( Pin->GetPosition() + wxPoint( g_RepeatStep.x, -g_RepeatStep.y ) ); wxString nextName = Pin->GetName(); @@ -570,12 +572,12 @@ bool sort_by_pin_number( const LIB_PIN* ref, const LIB_PIN* tst ) void LIB_EDIT_FRAME::OnCheckComponent( wxCommandEvent& event ) { #define MIN_GRID_SIZE 25 - int dup_error; - int offgrid_error; - LIB_PIN* Pin; - LIB_PIN_LIST PinList; - wxString msg; - wxString aux_msg; + int dup_error; + int offgrid_error; + LIB_PIN* Pin; + LIB_PINS PinList; + wxString msg; + wxString aux_msg; if( m_component == NULL ) return; diff --git a/eeschema/sch_component.cpp b/eeschema/sch_component.cpp index c1bba31611..9415ec6bd9 100644 --- a/eeschema/sch_component.cpp +++ b/eeschema/sch_component.cpp @@ -85,11 +85,11 @@ SCH_COMPONENT::SCH_COMPONENT( LIB_COMPONENT& libComponent, SCH_SHEET_PATH* sheet m_Flags = IS_NEW | IS_MOVED; // Import user defined fields from the library component: - LIB_FIELD_LIST libFields; + LIB_FIELDS libFields; libComponent.GetFields( libFields ); - for( LIB_FIELD_LIST::iterator it = libFields.begin(); it!=libFields.end(); ++it ) + for( LIB_FIELDS::iterator it = libFields.begin(); it!=libFields.end(); ++it ) { // Can no longer insert an empty name, since names are now keys. The // field index is not used beyond the first MANDATORY_FIELDS @@ -1506,7 +1506,7 @@ bool SCH_COMPONENT::Matches( wxFindReplaceData& aSearchData, void* aAuxData, if( Entry ) { - LIB_PIN_LIST pinList; + LIB_PINS pinList; Entry->GetPins( pinList, m_unit, m_convert ); // Search for a match in pinList @@ -1611,7 +1611,7 @@ void SCH_COMPONENT::GetConnectionPoints( vector< wxPoint >& aPoints ) const } -LIB_DRAW_ITEM* SCH_COMPONENT::GetDrawItem( const wxPoint& aPosition, KICAD_T aType ) +LIB_ITEM* SCH_COMPONENT::GetDrawItem( const wxPoint& aPosition, KICAD_T aType ) { LIB_COMPONENT* component = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); @@ -1663,7 +1663,7 @@ SEARCH_RESULT SCH_COMPONENT::Visit( INSPECTOR* aInspector, const void* aTestData if( component != NULL ) { - LIB_PIN_LIST pins; + LIB_PINS pins; component->GetPins( pins, m_unit, m_convert ); diff --git a/eeschema/sch_component.h b/eeschema/sch_component.h index 6e065d03fa..190c39f223 100644 --- a/eeschema/sch_component.h +++ b/eeschema/sch_component.h @@ -12,7 +12,7 @@ class SCH_SHEET_PATH; -class LIB_DRAW_ITEM; +class LIB_ITEM; class LIB_PIN; class LIB_COMPONENT; @@ -357,7 +357,7 @@ public: * @param aType - Type of component library object to find or any if set to TYPE_NOT_INIT. * @return A pointer to the component library object if found, otherwise NULL. */ - LIB_DRAW_ITEM* GetDrawItem( const wxPoint& aPosition, KICAD_T aType = TYPE_NOT_INIT ); + LIB_ITEM* GetDrawItem( const wxPoint& aPosition, KICAD_T aType = TYPE_NOT_INIT ); virtual wxString GetSelectMenuText() const; diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index 545da8d9a0..6ab0509946 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -631,7 +631,7 @@ wxString SCH_TEXT::GetSelectMenuText() const tmp =( tmp.Length() > 15 ) ? tmp.Left( 12 ) + wxT( "..." ) : tmp; wxString msg; - msg.Printf(_( "Graphic Text %s" ), GetChars(tmp)); + msg.Printf( _( "Graphic Text %s" ), GetChars( tmp ) ); return msg; } diff --git a/eeschema/schframe.cpp b/eeschema/schframe.cpp index 8152c1ffe4..7b16657d5b 100644 --- a/eeschema/schframe.cpp +++ b/eeschema/schframe.cpp @@ -129,8 +129,7 @@ BEGIN_EVENT_TABLE( SCH_EDIT_FRAME, EDA_DRAW_FRAME ) SCH_EDIT_FRAME::OnChangeComponentOrientation ) // Multple item selection context menu commands. - EVT_MENU_RANGE( ID_SCH_SELECT_ITEM_START, ID_SCH_SELECT_ITEM_END, - SCH_EDIT_FRAME::OnSelectItem ) + EVT_MENU_RANGE( ID_SELECT_ITEM_START, ID_SELECT_ITEM_END, SCH_EDIT_FRAME::OnSelectItem ) /* Handle user interface update events. */ EVT_UPDATE_UI( wxID_CUT, SCH_EDIT_FRAME::OnUpdateBlockSelected ) @@ -769,19 +768,19 @@ void SCH_EDIT_FRAME::SVG_Print( wxCommandEvent& event ) * @param aPrintMirrorMode = not used here (Set when printing in mirror mode) * @param aData = a pointer on an auxiliary data (not used here) */ -void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, - bool aPrintMirrorMode, void* aData) +void SCH_EDIT_FRAME::PrintPage( wxDC* aDC, int aPrintMask, bool aPrintMirrorMode, void* aData ) { GetScreen()->Draw( DrawPanel, aDC, GR_DEFAULT_DRAWMODE ); TraceWorkSheet( aDC, GetScreen(), g_DrawDefaultLineThickness ); } + void SCH_EDIT_FRAME::OnSelectItem( wxCommandEvent& aEvent ) { int id = aEvent.GetId(); - int index = id - ID_SCH_SELECT_ITEM_START; + int index = id - ID_SELECT_ITEM_START; - if( (id >= ID_SCH_SELECT_ITEM_START && id <= ID_SCH_SELECT_ITEM_END) + if( (id >= ID_SELECT_ITEM_START && id <= ID_SELECT_ITEM_END) && (index >= 0 && index < m_collectedItems.GetCount()) ) { SCH_ITEM* item = m_collectedItems[index]; diff --git a/eeschema/symbdraw.cpp b/eeschema/symbdraw.cpp index 99083388f7..08fc58cc2e 100644 --- a/eeschema/symbdraw.cpp +++ b/eeschema/symbdraw.cpp @@ -32,7 +32,7 @@ static void RedrawWhileMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx /* * Show the dialog box for editing a graphical item properties */ -void LIB_EDIT_FRAME::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) +void LIB_EDIT_FRAME::EditGraphicSymbol( wxDC* DC, LIB_ITEM* DrawItem ) { if( DrawItem == NULL ) return; @@ -102,7 +102,7 @@ void LIB_EDIT_FRAME::EditGraphicSymbol( wxDC* DC, LIB_DRAW_ITEM* DrawItem ) static void AbortSymbolTraceOn( EDA_DRAW_PANEL* Panel, wxDC* DC ) { LIB_EDIT_FRAME* parent = (LIB_EDIT_FRAME*) Panel->GetParent(); - LIB_DRAW_ITEM* item = parent->GetDrawItem(); + LIB_ITEM* item = parent->GetDrawItem(); if( item == NULL ) return; @@ -122,7 +122,7 @@ static void AbortSymbolTraceOn( EDA_DRAW_PANEL* Panel, wxDC* DC ) } -LIB_DRAW_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_COMPONENT* LibEntry, wxDC* DC ) +LIB_ITEM* LIB_EDIT_FRAME::CreateGraphicItem( LIB_COMPONENT* LibEntry, wxDC* DC ) { DrawPanel->SetMouseCapture( SymbolDisplayDraw, AbortSymbolTraceOn ); wxPoint drawPos = GetScreen()->GetCrossHairPosition( true ); @@ -229,7 +229,7 @@ void LIB_EDIT_FRAME::GraphicItemBeginDraw( wxDC* DC ) static void RedrawWhileMovingCursor( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition, bool aErase ) { - LIB_DRAW_ITEM* item; + LIB_ITEM* item; item = ( (LIB_EDIT_FRAME*) aPanel->GetParent() )->GetDrawItem(); @@ -286,7 +286,7 @@ static void SymbolDisplayDraw( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& bool aErase ) { BASE_SCREEN* Screen = aPanel->GetScreen(); - LIB_DRAW_ITEM* item = ( (LIB_EDIT_FRAME*) aPanel->GetParent() )->GetDrawItem(); + LIB_ITEM* item = ( (LIB_EDIT_FRAME*) aPanel->GetParent() )->GetDrawItem(); if( item == NULL ) return; diff --git a/eeschema/symbedit.cpp b/eeschema/symbedit.cpp index bc3dfce15e..e39a04318d 100644 --- a/eeschema/symbedit.cpp +++ b/eeschema/symbedit.cpp @@ -86,9 +86,9 @@ void LIB_EDIT_FRAME::LoadOneSymbol( void ) } Component = Lib->GetFirstEntry()->GetComponent(); - LIB_DRAW_ITEM_LIST& drawList = Component->GetDrawItemList(); + LIB_ITEMS& drawList = Component->GetDrawItemList(); - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawList ) + BOOST_FOREACH( LIB_ITEM& item, drawList ) { if( item.Type() == LIB_FIELD_T ) continue; @@ -99,7 +99,7 @@ void LIB_EDIT_FRAME::LoadOneSymbol( void ) item.m_Flags = IS_NEW; item.m_Selected = IS_SELECTED; - LIB_DRAW_ITEM* newItem = item.GenCopy(); + LIB_ITEM* newItem = (LIB_ITEM*) item.Clone(); newItem->SetParent( m_component ); m_component->AddDrawItem( newItem ); } @@ -196,9 +196,9 @@ void LIB_EDIT_FRAME::SaveOneSymbol() || !file.Write( wxT( "DRAW\n" ) ) ) return; - LIB_DRAW_ITEM_LIST& drawList = m_component->GetDrawItemList(); + LIB_ITEMS& drawList = m_component->GetDrawItemList(); - BOOST_FOREACH( LIB_DRAW_ITEM& item, drawList ) + BOOST_FOREACH( LIB_ITEM& item, drawList ) { if( item.Type() == LIB_FIELD_T ) continue; diff --git a/include/base_struct.h b/include/base_struct.h index 624a1c5905..d2c6ef5162 100644 --- a/include/base_struct.h +++ b/include/base_struct.h @@ -359,8 +359,8 @@ public: * editing */ // member used in undo/redo function - EDA_ITEM* m_Image; // Link to an image copy to save a copy of - // old parameters values + EDA_ITEM* m_Image; // Link to an image copy to save a copy of + // old parameters values private: void InitVars(); @@ -576,6 +576,24 @@ public: */ virtual const char** GetMenuImage() const { return (const char**) right_xpm; } + /** + * Test if another item is less than this object. + * + * @param aItem - Item to compare against. + * @return - True if \a aItem is less than the item. + */ + bool operator<( const EDA_ITEM& aItem ) const; + + /** + * Function Sort + * is a helper function to be used by the C++ STL sort algorithm for sorting a STL + * container of EDA_ITEM pointers. + * + * @param aLeft The left hand item to compare. + * @param aRight The right hand item to compare. + * @return True if \a aLeft is less than \a aRight. + */ + static bool Sort( const EDA_ITEM* aLeft, const EDA_ITEM* aRight ) { return *aLeft < *aRight; } #if defined(DEBUG)