diff --git a/common/common.cpp b/common/common.cpp index 9dc1d5d106..ec852db7c8 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -690,28 +690,6 @@ void Affiche_1_Parametre( WinEDA_DrawFrame* frame, int pos_X, } -/* - * Routine d'affichage de la documentation associee a un composant - */ -/****************************************************************************/ -void AfficheDoc( WinEDA_DrawFrame* frame, const wxString& Doc, - const wxString& KeyW ) -/****************************************************************************/ -{ - wxString Line1( wxT( "Doc: " ) ), Line2( wxT( "KeyW: " ) ); - - int color = BLUE; - - if( frame && frame->MsgPanel ) - { - frame->MsgPanel->EraseMsgBox(); - Line1 += Doc; - Line2 += KeyW; - frame->MsgPanel->Affiche_1_Parametre( 10, Line1, Line2, color ); - } -} - - /***********************/ int GetTimeStamp() /***********************/ diff --git a/common/drawpanel.cpp b/common/drawpanel.cpp index 535296a964..2f25ead66a 100644 --- a/common/drawpanel.cpp +++ b/common/drawpanel.cpp @@ -1379,7 +1379,8 @@ void WinEDA_DrawPanel::OnPan( wxCommandEvent& event ) } -void WinEDA_DrawPanel::UnManageCursor( void ) +void WinEDA_DrawPanel::UnManageCursor( int id, int cursor, + const wxString& title ) { wxClientDC dc( this ); @@ -1387,5 +1388,12 @@ void WinEDA_DrawPanel::UnManageCursor( void ) { ForceCloseManageCurseur( this, &dc ); m_AutoPAN_Request = false; + + if( id != -1 && cursor != -1 ) + { + wxASSERT( cursor > wxCURSOR_NONE && cursor < wxCURSOR_MAX ); + + m_Parent->SetToolID( id, cursor, title ); + } } } diff --git a/common/msgpanel.cpp b/common/msgpanel.cpp index 9c2d5127ef..728ff545cc 100644 --- a/common/msgpanel.cpp +++ b/common/msgpanel.cpp @@ -61,6 +61,20 @@ int WinEDA_MsgPanel::GetRequiredHeight() } +wxSize WinEDA_MsgPanel::computeTextSize( const wxString& text ) +{ + // Get size of the wxSYS_DEFAULT_GUI_FONT + wxSize textSizeInPixels; + + wxScreenDC dc; + + dc.SetFont( wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT ) ); + dc.GetTextExtent( text, &textSizeInPixels.x, &textSizeInPixels.y ); + + return textSizeInPixels; +} + + /*************************************************/ void WinEDA_MsgPanel::OnPaint( wxPaintEvent& event ) /*************************************************/ @@ -80,6 +94,36 @@ void WinEDA_MsgPanel::OnPaint( wxPaintEvent& event ) event.Skip(); } +void WinEDA_MsgPanel::AppendMessage( const wxString& textUpper, + const wxString& textLower, + int color, int pad ) +{ + wxString text; + wxSize drawSize = GetClientSize(); + + text = ( textUpper.Len() > textLower.Len() ) ? textUpper : textLower; + text.Append( ' ', pad ); + + MsgItem item; + + /* Don't put the first message a window client position 0. Offset by + * one 'W' character width. */ + if( m_last_x == 0 ) + m_last_x = m_fontSize.x; + + item.m_X = m_last_x; + + item.m_UpperY = ( drawSize.y / 2 ) - m_fontSize.y; + item.m_LowerY = drawSize.y - m_fontSize.y; + + item.m_UpperText = textUpper; + item.m_LowerText = textLower; + item.m_Color = color; + m_Items.push_back( item ); + m_last_x += computeTextSize( text ).x; + + Refresh(); +} /*****************************************************************************/ void WinEDA_MsgPanel::Affiche_1_Parametre( int pos_X, const wxString& texte_H, diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index 8ef6fd28f2..327c71f7e5 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -72,9 +72,9 @@ void ReAnnotatePowerSymbolsOnly( void ) { if( DrawList->Type() != TYPE_SCH_COMPONENT ) continue; - SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList; - EDA_LibComponentStruct* Entry = - ( EDA_LibComponentStruct* )FindLibPart( DrawLibItem->m_ChipName ); + SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) DrawList; + LIB_COMPONENT* Entry = + CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); if( (Entry == NULL) || (Entry->m_Options != ENTRY_POWER) ) continue; @@ -344,17 +344,18 @@ int AddComponentsInSheetToList( std::vector & aComponentsList, * @param the DrawSheetPath sheet to analyse */ { - int NbrCmp = 0; - EDA_BaseStruct* DrawList = aSheet->LastDrawList(); - SCH_COMPONENT* DrawLibItem; - EDA_LibComponentStruct* Entry; + int NbrCmp = 0; + EDA_BaseStruct* DrawList = aSheet->LastDrawList(); + SCH_COMPONENT* DrawLibItem; + LIB_COMPONENT* Entry; for( ; DrawList != NULL; DrawList = DrawList->Next() ) { if( DrawList->Type() == TYPE_SCH_COMPONENT ) { DrawLibItem = (SCH_COMPONENT*) DrawList; - Entry = ( EDA_LibComponentStruct* )FindLibPart( DrawLibItem->m_ChipName ); + Entry = + CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); if( Entry == NULL ) continue; diff --git a/eeschema/block.cpp b/eeschema/block.cpp index 9227fdf61b..bb6a7c3977 100644 --- a/eeschema/block.cpp +++ b/eeschema/block.cpp @@ -855,7 +855,7 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem, * @return a pointer to the pin */ { - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; static LibEDA_BaseStruct* NextItem; static int Multi, convert, TransMat[2][2]; LibEDA_BaseStruct* DEntry; @@ -866,8 +866,7 @@ static LibEDA_BaseStruct* GetNextPinPosition( SCH_COMPONENT* aDrawLibItem, if( aDrawLibItem ) { NextItem = NULL; - Entry = - ( EDA_LibComponentStruct* )FindLibPart( aDrawLibItem->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( aDrawLibItem->m_ChipName ); if( Entry == NULL ) return NULL; diff --git a/eeschema/block_libedit.cpp b/eeschema/block_libedit.cpp index d2bc3a6246..290f2f7c1a 100644 --- a/eeschema/block_libedit.cpp +++ b/eeschema/block_libedit.cpp @@ -18,18 +18,18 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, bool erase ); -static int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent, - EDA_Rect& Rect ); +static int MarkItemsInBloc( LIB_COMPONENT* LibComponent, + EDA_Rect& Rect ); -static void ClearMarkItems( EDA_LibComponentStruct* LibComponent ); -static void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ); -static void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ); -static void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, +static void ClearMarkItems( LIB_COMPONENT* LibComponent ); +static void CopyMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ); +static void MoveMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ); +static void MirrorMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ); -static void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry ); +static void DeleteMarkedItems( LIB_COMPONENT* LibEntry ); -void ClearMarkItems( EDA_LibComponentStruct* LibComponent ) +void ClearMarkItems( LIB_COMPONENT* LibComponent ) { LibEDA_BaseStruct* item; @@ -55,8 +55,8 @@ void ClearMarkItems( EDA_LibComponentStruct* LibComponent ) * only the pins specific to current part and current convert are marked * - all specific to current convert pins are marked; */ -int MarkItemsInBloc( EDA_LibComponentStruct* LibComponent, - EDA_Rect& Rect ) +int MarkItemsInBloc( LIB_COMPONENT* LibComponent, + EDA_Rect& Rect ) { LibEDA_BaseStruct* item; int ItemsCount = 0; @@ -389,7 +389,7 @@ static void DrawMovingBlockOutlines( WinEDA_DrawPanel* panel, wxDC* DC, /* * Copy marked items, at new position = old position + offset */ -void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ) +void CopyMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ) { LibEDA_BaseStruct* item; @@ -415,7 +415,7 @@ void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ) /* * Move marked items, at new position = old position + offset */ -void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ) +void MoveMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ) { LibEDA_BaseStruct* item; @@ -437,7 +437,7 @@ void MoveMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ) /* * Delete marked items */ -void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry ) +void DeleteMarkedItems( LIB_COMPONENT* LibEntry ) { LibEDA_BaseStruct* item, * next_item; @@ -458,7 +458,7 @@ void DeleteMarkedItems( EDA_LibComponentStruct* LibEntry ) /* * Mirror marked items, refer to a Vertical axis at position offset */ -void MirrorMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset ) +void MirrorMarkedItems( LIB_COMPONENT* LibEntry, wxPoint offset ) { #define SETMIRROR( z ) (z) -= offset.x; (z) = -(z); (z) += offset.x; LibEDA_BaseStruct* item; diff --git a/eeschema/build_BOM.cpp b/eeschema/build_BOM.cpp index 896c2b6568..d933f6a5df 100644 --- a/eeschema/build_BOM.cpp +++ b/eeschema/build_BOM.cpp @@ -576,12 +576,12 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( /* Print the B.O.M sorted by reference */ { - int Multi, Unit; - EDA_BaseStruct* DrawList; - SCH_COMPONENT* DrawLibItem; - EDA_LibComponentStruct* Entry; - char CmpName[80]; - wxString msg; + int Multi, Unit; + EDA_BaseStruct* DrawList; + SCH_COMPONENT* DrawLibItem; + LIB_COMPONENT* Entry; + char CmpName[80]; + wxString msg; if( CompactForm ) { @@ -649,7 +649,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( Multi = 0; Unit = ' '; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); if( Entry ) Multi = Entry->m_UnitCount; @@ -714,17 +714,16 @@ int DIALOG_BUILD_BOM::PrintComponentsListByRef( int DIALOG_BUILD_BOM::PrintComponentsListByVal( FILE* f, std::vector & aList, - bool - aIncludeSubComponents ) + bool aIncludeSubComponents ) /**********************************************************************************************/ { - int Multi; - wxChar Unit; - EDA_BaseStruct* DrawList; - SCH_COMPONENT* DrawLibItem; - EDA_LibComponentStruct* Entry; - char CmpName[80]; - wxString msg; + int Multi; + wxChar Unit; + EDA_BaseStruct* DrawList; + SCH_COMPONENT* DrawLibItem; + LIB_COMPONENT* Entry; + char CmpName[80]; + wxString msg; msg = _( "\n#Cmp ( order = Value )" ); @@ -749,7 +748,7 @@ int DIALOG_BUILD_BOM::PrintComponentsListByVal( Multi = 0; Unit = ' '; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); if( Entry ) Multi = Entry->m_UnitCount; diff --git a/eeschema/class_BodyItem_Text.cpp b/eeschema/class_BodyItem_Text.cpp index f1985a8862..4df8b99f89 100644 --- a/eeschema/class_BodyItem_Text.cpp +++ b/eeschema/class_BodyItem_Text.cpp @@ -22,7 +22,7 @@ -LibDrawText::LibDrawText(EDA_LibComponentStruct * aParent) : +LibDrawText::LibDrawText(LIB_COMPONENT * aParent) : LibEDA_BaseStruct( COMPONENT_GRAPHIC_TEXT_DRAW_TYPE, aParent ), EDA_TextStruct() { diff --git a/eeschema/class_libentry.cpp b/eeschema/class_libentry.cpp index 988e542940..eaf9ed0ffa 100644 --- a/eeschema/class_libentry.cpp +++ b/eeschema/class_libentry.cpp @@ -145,53 +145,63 @@ int SortItemsFct(const void* ref, const void* item) /*********************/ -/* class LibCmpEntry */ +/* class CMP_LIB_ENTRY */ /*********************/ /* Basic class for library component description * Not directly used * Used to create the 2 derived classes : - * - EDA_LibCmpAliasStruct - * - EDA_LibComponentStruct + * - LIB_ALIAS + * - LIB_COMPONENT */ /********************************************************************/ -LibCmpEntry::LibCmpEntry( LibrEntryType CmpType, const wxChar* CmpName ) : +CMP_LIB_ENTRY::CMP_LIB_ENTRY( LibrEntryType type, const wxString& name, + CMP_LIBRARY* lib ) : EDA_BaseStruct( LIBCOMPONENT_STRUCT_TYPE ) { - Type = CmpType; + Type = type; m_Name.m_FieldId = VALUE; m_Name.SetParent( this ); - if( CmpName ) - m_Name.m_Text = CmpName; + m_Name.m_Text = name; + m_lib = lib; } -LibCmpEntry::~LibCmpEntry() +CMP_LIB_ENTRY::~CMP_LIB_ENTRY() { } -bool LibCmpEntry::operator==( const wxChar* name ) const +wxString CMP_LIB_ENTRY::GetLibraryName() +{ + if( m_lib != NULL ) + return m_lib->GetName(); + + return wxEmptyString; +} + + +bool CMP_LIB_ENTRY::operator==( const wxChar* name ) const { return m_Name.m_Text.CmpNoCase( name ) == 0; } -bool operator<( const LibCmpEntry& item1, const LibCmpEntry& item2 ) +bool operator<( const CMP_LIB_ENTRY& item1, const CMP_LIB_ENTRY& item2 ) { return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) < 0; } -int LibraryEntryCompare( const LibCmpEntry* LE1, const LibCmpEntry* LE2 ) +int LibraryEntryCompare( const CMP_LIB_ENTRY* LE1, const CMP_LIB_ENTRY* LE2 ) { return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text ); } /*******************************/ -/* class EDA_LibCmpAliasStruct */ +/* class LIB_ALIAS */ /*******************************/ /* Class to define an alias of a component @@ -203,30 +213,37 @@ int LibraryEntryCompare( const LibCmpEntry* LE1, const LibCmpEntry* LE2 ) * (like 74LS00, 74HC00 ... and many op amps ) */ -EDA_LibCmpAliasStruct::EDA_LibCmpAliasStruct( const wxChar* CmpName, - const wxChar* CmpRootName ) : - LibCmpEntry( ALIAS, CmpName ) +LIB_ALIAS::LIB_ALIAS( const wxString& name, LIB_COMPONENT* root, + CMP_LIBRARY* lib ) : + CMP_LIB_ENTRY( ALIAS, name, lib ) { - if( CmpRootName == NULL ) - m_RootName.Empty(); - else - m_RootName = CmpRootName; + wxASSERT( root != NULL && root->Type == ROOT ); + + m_root = root; } -EDA_LibCmpAliasStruct::~EDA_LibCmpAliasStruct() +LIB_ALIAS::~LIB_ALIAS() { } +void LIB_ALIAS::SetComponent( LIB_COMPONENT* root ) +{ + wxASSERT( root != NULL && root->Type == ROOT ); + + m_root = root; +} + + /********************************/ -/* class EDA_LibComponentStruct */ +/* class LIB_COMPONENT */ /********************************/ /* This is a standard component (in library) */ -EDA_LibComponentStruct:: EDA_LibComponentStruct( const wxChar* CmpName ) : - LibCmpEntry( ROOT, CmpName ) +LIB_COMPONENT::LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib ) : + CMP_LIB_ENTRY( ROOT, name, lib ) { m_Drawings = NULL; m_LastDate = 0; @@ -241,7 +258,7 @@ EDA_LibComponentStruct:: EDA_LibComponentStruct( const wxChar* CmpName ) : } -EDA_LibComponentStruct::~EDA_LibComponentStruct() +LIB_COMPONENT::~LIB_COMPONENT() { LibEDA_BaseStruct* DrawItem; LibEDA_BaseStruct* NextDrawItem; @@ -259,12 +276,12 @@ EDA_LibComponentStruct::~EDA_LibComponentStruct() } -void EDA_LibComponentStruct::Draw( WinEDA_DrawPanel* panel, wxDC* dc, - const wxPoint& offset, int multi, - int convert, int drawMode, int color, - const int transformMatrix[2][2], - bool showPinText, bool drawFields, - bool onlySelected ) +void LIB_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* dc, + const wxPoint& offset, int multi, + int convert, int drawMode, int color, + const int transformMatrix[2][2], + bool showPinText, bool drawFields, + bool onlySelected ) { wxString fieldText; LibDrawField* Field; @@ -359,9 +376,9 @@ void EDA_LibComponentStruct::Draw( WinEDA_DrawPanel* panel, wxDC* dc, } -void EDA_LibComponentStruct::RemoveDrawItem( LibEDA_BaseStruct* item, - WinEDA_DrawPanel* panel, - wxDC* dc ) +void LIB_COMPONENT::RemoveDrawItem( LibEDA_BaseStruct* item, + WinEDA_DrawPanel* panel, + wxDC* dc ) { wxASSERT( item != NULL ); @@ -398,7 +415,7 @@ void EDA_LibComponentStruct::RemoveDrawItem( LibEDA_BaseStruct* item, * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ -bool EDA_LibComponentStruct::Save( FILE* aFile ) +bool LIB_COMPONENT::Save( FILE* aFile ) { LibEDA_BaseStruct* DrawEntry; LibDrawField* Field; @@ -517,8 +534,8 @@ bool EDA_LibComponentStruct::Save( FILE* aFile ) return true; } -bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum, - wxString& errorMsg ) +bool LIB_COMPONENT::Load( FILE* file, char* line, int* lineNum, + wxString& errorMsg ) { int unused; char* p; @@ -636,8 +653,8 @@ bool EDA_LibComponentStruct::Load( FILE* file, char* line, int* lineNum, } -bool EDA_LibComponentStruct::LoadDrawEntries( FILE* f, char* line, - int* lineNum, wxString& errorMsg ) +bool LIB_COMPONENT::LoadDrawEntries( FILE* f, char* line, + int* lineNum, wxString& errorMsg ) { LibEDA_BaseStruct* newEntry = NULL; LibEDA_BaseStruct* headEntry = NULL; @@ -729,7 +746,7 @@ to flush to end of drawing section." ); } -bool EDA_LibComponentStruct::LoadAliases( char* line, wxString& errorMsg ) +bool LIB_COMPONENT::LoadAliases( char* line, wxString& errorMsg ) { char* text = strtok( line, " \t\r\n" ); @@ -743,7 +760,7 @@ bool EDA_LibComponentStruct::LoadAliases( char* line, wxString& errorMsg ) } -bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg ) +bool LIB_COMPONENT::LoadField( char* line, wxString& errorMsg ) { LibDrawField* field = new LibDrawField( this ); @@ -772,8 +789,8 @@ bool EDA_LibComponentStruct::LoadField( char* line, wxString& errorMsg ) } -bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line, - int* lineNum, wxString& errorMsg ) +bool LIB_COMPONENT::LoadFootprints( FILE* file, char* line, + int* lineNum, wxString& errorMsg ) { while( true ) { @@ -799,7 +816,7 @@ bool EDA_LibComponentStruct::LoadFootprints( FILE* file, char* line, * items remplis en premier, pins en dernier * En cas de superposition d'items, c'est plus lisible */ -void EDA_LibComponentStruct::SortDrawItems() +void LIB_COMPONENT::SortDrawItems() { LibEDA_BaseStruct** Bufentry, ** BufentryBase, * Entry = m_Drawings; int ii, nbitems; @@ -842,7 +859,7 @@ void EDA_LibComponentStruct::SortDrawItems() * if Convert == 0 Convert is non used **/ /**********************************************************************/ -EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert ) +EDA_Rect LIB_COMPONENT::GetBoundaryBox( int Unit, int Convert ) { LibEDA_BaseStruct* DrawEntry; EDA_Rect bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) ); @@ -869,7 +886,7 @@ EDA_Rect EDA_LibComponentStruct::GetBoundaryBox( int Unit, int Convert ) * initialize fields from a vector of fields * @param aFields a std::vector to import. */ -void EDA_LibComponentStruct::SetFields( const std::vector aFields ) +void LIB_COMPONENT::SetFields( const std::vector aFields ) { // Init basic fields (Value = name in lib, and reference): aFields[VALUE].Copy( &m_Name ); @@ -918,7 +935,7 @@ void EDA_LibComponentStruct::SetFields( const std::vector aFields * lit date et time de modif composant sous le format: * "Ti yy/mm/jj hh:mm:ss" */ -bool EDA_LibComponentStruct::SaveDateAndTime( FILE* file ) +bool LIB_COMPONENT::SaveDateAndTime( FILE* file ) { int year, mon, day, hour, min, sec; @@ -942,7 +959,7 @@ bool EDA_LibComponentStruct::SaveDateAndTime( FILE* file ) /* lit date et time de modif composant sous le format: * "Ti yy/mm/jj hh:mm:ss" */ -bool EDA_LibComponentStruct::LoadDateAndTime( char* Line ) +bool LIB_COMPONENT::LoadDateAndTime( char* Line ) { int year, mon, day, hour, min, sec; char* text; @@ -963,7 +980,7 @@ bool EDA_LibComponentStruct::LoadDateAndTime( char* Line ) } -void EDA_LibComponentStruct::SetOffset( const wxPoint& offset ) +void LIB_COMPONENT::SetOffset( const wxPoint& offset ) { LibEDA_BaseStruct* DrawEntry; @@ -985,7 +1002,7 @@ void EDA_LibComponentStruct::SetOffset( const wxPoint& offset ) } -void EDA_LibComponentStruct::RemoveDuplicateDrawItems() +void LIB_COMPONENT::RemoveDuplicateDrawItems() { LibEDA_BaseStruct* DEntryRef; LibEDA_BaseStruct* DEntryCompare; @@ -1024,7 +1041,7 @@ void EDA_LibComponentStruct::RemoveDuplicateDrawItems() } -bool EDA_LibComponentStruct::HasConversion() const +bool LIB_COMPONENT::HasConversion() const { LibEDA_BaseStruct* entry; @@ -1046,7 +1063,7 @@ bool EDA_LibComponentStruct::HasConversion() const * @param aFile The FILE to write to. * @return bool - true if success writing else false. */ -bool LibCmpEntry::SaveDoc( FILE* aFile ) +bool CMP_LIB_ENTRY::SaveDoc( FILE* aFile ) { if( m_Doc.IsEmpty() && m_KeyWord.IsEmpty() && m_DocFile.IsEmpty() ) return true; diff --git a/eeschema/class_libentry.h b/eeschema/class_libentry.h index 47108725d6..2ef3cd3051 100644 --- a/eeschema/class_libentry.h +++ b/eeschema/class_libentry.h @@ -13,12 +13,15 @@ #include +class CMP_LIBRARY; + + /* Types for components in libraries * components can be a true component or an alias of a true component. */ enum LibrEntryType { - ROOT, /* This is a true component standard EDA_LibComponentStruct */ + ROOT, /* This is a true component standard LIB_COMPONENT */ ALIAS /* This is an alias of a true component */ }; @@ -35,7 +38,7 @@ enum LibrEntryOptions * * This class is not to be used directly. */ -class LibCmpEntry : public EDA_BaseStruct +class CMP_LIB_ENTRY : public EDA_BaseStruct { public: LibrEntryType Type; /* Type = ROOT; @@ -48,13 +51,16 @@ public: LibrEntryOptions m_Options; // special features (i.e. Entry is a POWER) public: - LibCmpEntry( LibrEntryType CmpType, const wxChar* CmpName ); - virtual ~LibCmpEntry(); + CMP_LIB_ENTRY( LibrEntryType CmpType, const wxString& name, + CMP_LIBRARY* lib = NULL ); + virtual ~CMP_LIB_ENTRY(); + virtual wxString GetClass() const { - return wxT( "LibCmpEntry" ); + return wxT( "CMP_LIB_ENTRY" ); } + wxString GetLibraryName(); const wxString& GetName() { return m_Name.m_Text; } @@ -75,15 +81,18 @@ public: { return !( *this == name ); } + +protected: + CMP_LIBRARY* m_lib; }; -typedef boost::ptr_vector< LibCmpEntry > LIB_ENTRY_LIST; +typedef boost::ptr_vector< CMP_LIB_ENTRY > LIB_ENTRY_LIST; -extern bool operator<( const LibCmpEntry& item1, const LibCmpEntry& item2 ); +extern bool operator<( const CMP_LIB_ENTRY& item1, const CMP_LIB_ENTRY& item2 ); -extern int LibraryEntryCompare( const LibCmpEntry* LE1, - const LibCmpEntry* LE2 ); +extern int LibraryEntryCompare( const CMP_LIB_ENTRY* LE1, + const CMP_LIB_ENTRY* LE2 ); /** @@ -93,7 +102,7 @@ extern int LibraryEntryCompare( const LibCmpEntry* LE1, * library file (.lib). Library components are different from schematic * components. */ -class EDA_LibComponentStruct : public LibCmpEntry +class LIB_COMPONENT : public CMP_LIB_ENTRY { public: LibDrawField m_Prefix; /* Prefix ( U, IC ... ) = REFERENCE */ @@ -120,12 +129,12 @@ public: public: virtual wxString GetClass() const { - return wxT( "EDA_LibComponentStruct" ); + return wxT( "LIB_COMPONENT" ); } - EDA_LibComponentStruct( const wxChar* CmpName ); - ~EDA_LibComponentStruct(); + LIB_COMPONENT( const wxString& name, CMP_LIBRARY* lib = NULL ); + ~LIB_COMPONENT(); EDA_Rect GetBoundaryBox( int Unit, int Convert ); @@ -248,19 +257,33 @@ public: * object not as children of a library object. This would greatly * simplify searching for components in libraries. */ -class EDA_LibCmpAliasStruct : public LibCmpEntry +class LIB_ALIAS : public CMP_LIB_ENTRY { -public: - wxString m_RootName; /* Root component Part name */ +protected: + LIB_COMPONENT* m_root; /* Root component of the alias. */ public: - EDA_LibCmpAliasStruct( const wxChar* CmpName, const wxChar* CmpRootName ); - ~EDA_LibCmpAliasStruct(); + LIB_ALIAS( const wxString& name, LIB_COMPONENT* root, + CMP_LIBRARY* lib = NULL ); + ~LIB_ALIAS(); virtual wxString GetClass() const { - return wxT( "EDA_LibCmpAliasStruct" ); + return wxT( "LIB_ALIAS" ); } + + /** + * Get the alias root component. + */ + LIB_COMPONENT* GetComponent( void ) const + { + return m_root; + } + + /** + * Set the alias root component. + */ + void SetComponent( LIB_COMPONENT* component ); }; diff --git a/eeschema/class_libentry_fields.cpp b/eeschema/class_libentry_fields.cpp index f2cc607578..d2868fd883 100644 --- a/eeschema/class_libentry_fields.cpp +++ b/eeschema/class_libentry_fields.cpp @@ -38,7 +38,7 @@ * * others = free fields */ -LibDrawField::LibDrawField(EDA_LibComponentStruct * aParent, int idfield ) : +LibDrawField::LibDrawField(LIB_COMPONENT * aParent, int idfield ) : LibEDA_BaseStruct( COMPONENT_FIELD_DRAW_TYPE, aParent ) { m_FieldId = idfield; @@ -327,7 +327,7 @@ bool LibDrawField::HitTest( wxPoint aPosRef, int aThreshold, { extraCharCount++; m_Text.Append('?'); - EDA_LibComponentStruct* parent = (EDA_LibComponentStruct*)m_Parent; + LIB_COMPONENT* parent = (LIB_COMPONENT*)m_Parent; if ( parent && ( parent->m_UnitCount > 1 ) ) { m_Text.Append('A'); diff --git a/eeschema/class_libentry_fields.h b/eeschema/class_libentry_fields.h index 416ebdae8a..5b0d473064 100644 --- a/eeschema/class_libentry_fields.h +++ b/eeschema/class_libentry_fields.h @@ -35,7 +35,7 @@ public: LibDrawField( int idfield = 2 ); - LibDrawField( EDA_LibComponentStruct * aParent, int idfield = 2 ); + LibDrawField( LIB_COMPONENT * aParent, int idfield = 2 ); ~LibDrawField(); virtual wxString GetClass() const { diff --git a/eeschema/class_library.cpp b/eeschema/class_library.cpp index 4aa3908848..122da6b247 100644 --- a/eeschema/class_library.cpp +++ b/eeschema/class_library.cpp @@ -18,52 +18,86 @@ #include +#include -bool operator==( const LibraryStruct& lib, const wxChar* name ) + +static const wxChar* duplicate_name_msg = _( "Component library <%s> has \ +duplicate entry name <%s>. This may cause some expected behavior when \ +loading components into a schematic." ); + + +static bool DuplicateEntryName( const CMP_LIB_ENTRY& item1, + const CMP_LIB_ENTRY& item2 ) { - return lib.m_Name.CmpNoCase( name ) == 0; + return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) == 0; } -bool operator!=( const LibraryStruct& lib, const wxChar* name ) +bool operator==( const CMP_LIBRARY& lib, const wxChar* name ) +{ + return lib.GetName().CmpNoCase( name ) == 0; +} + + +bool operator!=( const CMP_LIBRARY& lib, const wxChar* name ) { return !( lib == name ); } -LibraryStruct::LibraryStruct( int type, const wxString& name, - const wxString& fullname ) +bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 ) +{ + /* The cache library always is sorted to the end of the library list. */ + if( item1.IsCache() ) + return true; + if( item2.IsCache() ) + return false; + + /* If the sort order array isn't set, then sort alphabetically except. */ + if( CMP_LIBRARY::GetSortOrder().IsEmpty() ) + return item1.GetName().CmpNoCase( item2.GetName() ) < 0; + + int i1 = CMP_LIBRARY::GetSortOrder().Index( item1.GetName(), false ); + int i2 = CMP_LIBRARY::GetSortOrder().Index( item2.GetName(), false ); + + if( i1 == wxNOT_FOUND && i2 == wxNOT_FOUND ) + return true; + + if( i1 == wxNOT_FOUND && i2 != wxNOT_FOUND ) + return false; + + if( i1 != wxNOT_FOUND && i2 == wxNOT_FOUND ) + return true; + + return ( i1 - i2 ) < 0; +} + + +CMP_LIBRARY::CMP_LIBRARY( int type, const wxFileName& fileName ) { m_Type = type; /* type indicator */ - m_Name = name; /* Name of library loaded. */ - m_FullFileName = fullname; /* File name (with path) of library loaded. */ - m_Pnext = NULL; /* Point to next library in chain. */ m_IsModified = false; /* flag indicateur d'edition */ m_TimeStamp = 0; m_Flags = 0; - m_IsLibCache = false; + m_IsCache = false; m_DateTime = wxDateTime::Now(); -} - -LibraryStruct::LibraryStruct( const wxChar* fileName ) -{ - if( fileName == NULL ) - m_fileName = wxT( "unnamed.lib" ); - else + if( fileName.IsOk() ) m_fileName = fileName; + else + m_fileName = wxFileName( wxT( "unnamed.lib" ) ); } -LibraryStruct::~LibraryStruct() +CMP_LIBRARY::~CMP_LIBRARY() { } -void LibraryStruct::GetEntryNames( wxArrayString& names, bool sort, - bool makeUpperCase ) +void CMP_LIBRARY::GetEntryNames( wxArrayString& names, bool sort, + bool makeUpperCase ) { - BOOST_FOREACH( LibCmpEntry& entry, m_Entries ) + BOOST_FOREACH( CMP_LIB_ENTRY& entry, m_Entries ) { if( makeUpperCase ) names.Add( entry.m_Name.m_Text.MakeUpper() ); @@ -76,12 +110,12 @@ void LibraryStruct::GetEntryNames( wxArrayString& names, bool sort, } -void LibraryStruct::SearchEntryNames( wxArrayString& names, - const wxString& nameSearch, - const wxString& keySearch, - bool sort ) +void CMP_LIBRARY::SearchEntryNames( wxArrayString& names, + const wxString& nameSearch, + const wxString& keySearch, + bool sort ) { - BOOST_FOREACH( LibCmpEntry& entry, m_Entries ) + BOOST_FOREACH( CMP_LIB_ENTRY& entry, m_Entries ) { if( !keySearch.IsEmpty() && KeyWordOk( keySearch, entry.m_KeyWord ) ) names.Add( entry.GetName() ); @@ -96,9 +130,9 @@ void LibraryStruct::SearchEntryNames( wxArrayString& names, } -LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name ) +CMP_LIB_ENTRY* CMP_LIBRARY::FindEntry( const wxChar* name ) { - BOOST_FOREACH( LibCmpEntry& entry, m_Entries ) + BOOST_FOREACH( CMP_LIB_ENTRY& entry, m_Entries ) { if( entry.GetName().CmpNoCase( name ) == 0 ) return &entry; @@ -108,9 +142,9 @@ LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name ) } -LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name, LibrEntryType type ) +CMP_LIB_ENTRY* CMP_LIBRARY::FindEntry( const wxChar* name, LibrEntryType type ) { - BOOST_FOREACH( LibCmpEntry& entry, m_Entries ) + BOOST_FOREACH( CMP_LIB_ENTRY& entry, m_Entries ) { if( entry.GetName().CmpNoCase( name ) == 0 && entry.Type == type ) return &entry; @@ -120,31 +154,26 @@ LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name, LibrEntryType type ) } -EDA_LibComponentStruct* LibraryStruct::FindComponent( const wxChar* name, - bool searchAliases ) +LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* name ) { - if( !searchAliases ) - return (EDA_LibComponentStruct*) FindEntry( name, ROOT ); - - EDA_LibComponentStruct* component = NULL; - LibCmpEntry* entry = FindEntry( name ); + LIB_COMPONENT* component = NULL; + CMP_LIB_ENTRY* entry = FindEntry( name ); if( entry != NULL && entry->Type == ALIAS ) { - EDA_LibCmpAliasStruct* alias = (EDA_LibCmpAliasStruct*) entry; - component = (EDA_LibComponentStruct*) FindEntry( alias->m_RootName, - ROOT ); + LIB_ALIAS* alias = (LIB_ALIAS*) entry; + component = alias->GetComponent(); } else { - component = (EDA_LibComponentStruct*) entry; + component = (LIB_COMPONENT*) entry; } return component; } -bool LibraryStruct::AddAlias( EDA_LibCmpAliasStruct* alias ) +bool CMP_LIBRARY::AddAlias( LIB_ALIAS* alias ) { wxASSERT( alias != NULL ); @@ -153,55 +182,61 @@ bool LibraryStruct::AddAlias( EDA_LibCmpAliasStruct* alias ) wxString msg; msg.Printf( _( "Cannot add duplicate alias <%s> to library <%s>." ), - (const wxChar*) alias->GetName(), (const wxChar*) m_Name ); + (const wxChar*) alias->GetName(), + (const wxChar*) m_fileName.GetName() ); return false; } - m_Entries.push_back( (LibCmpEntry*) alias ); + m_Entries.push_back( (CMP_LIB_ENTRY*) alias ); m_IsModified = true; return true; } -EDA_LibComponentStruct* LibraryStruct::AddComponent( EDA_LibComponentStruct* cmp ) +LIB_COMPONENT* CMP_LIBRARY::AddComponent( LIB_COMPONENT* cmp ) { wxASSERT( cmp != NULL ); - EDA_LibComponentStruct* newCmp = CopyLibEntryStruct( cmp ); + LIB_COMPONENT* newCmp = CopyLibEntryStruct( cmp ); if( newCmp == NULL ) return NULL; - m_Entries.push_back( (LibCmpEntry*) newCmp ); + m_Entries.push_back( (CMP_LIB_ENTRY*) newCmp ); m_IsModified = true; - for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ ) + /* Cache libraries are component only libraries. Do not create alias + * entries. */ + if( !m_IsCache ) { - EDA_LibCmpAliasStruct* alias = FindAlias( newCmp->m_AliasList[ i ] ); + for( size_t i = 0; i < newCmp->m_AliasList.GetCount(); i++ ) + { + LIB_ALIAS* alias = FindAlias( newCmp->m_AliasList[ i ] ); - if( alias == NULL ) - { - alias = new EDA_LibCmpAliasStruct( newCmp->m_AliasList[ i ], - newCmp->GetName() ); - m_Entries.push_back( alias ); - } - else if( alias->m_RootName != newCmp->GetName() ) - { - wxLogError( _( "Conflict in library <%s>: alias <%s> already has \ -root name <%s> and will not be assigned to root name <%s>." ), - (const wxChar*) m_Name, - (const wxChar*) alias->m_RootName, + if( alias == NULL ) + { + alias = new LIB_ALIAS( newCmp->m_AliasList[ i ], newCmp ); + m_Entries.push_back( alias ); + } + else if( alias->GetComponent()->GetName().CmpNoCase( newCmp->GetName() ) != 0 ) + { + wxLogError( _( "Conflict in library <%s>: alias <%s> already \ +has root name <%s> and will not be assigned to root name <%s>." ), + (const wxChar*) m_fileName.GetName(), + (const wxChar*) alias->GetComponent()->GetName(), (const wxChar*) newCmp->GetName() ); + } } } m_Entries.sort(); + m_Entries.unique( DuplicateEntryName ); return newCmp; } -void LibraryStruct::RemoveEntry( const wxString& name ) +void CMP_LIBRARY::RemoveEntry( const wxString& name ) { LIB_ENTRY_LIST::iterator i; @@ -216,19 +251,19 @@ void LibraryStruct::RemoveEntry( const wxString& name ) } -void LibraryStruct::RemoveEntry( LibCmpEntry* entry ) +void CMP_LIBRARY::RemoveEntry( CMP_LIB_ENTRY* entry ) { wxASSERT( entry != NULL ); - EDA_LibComponentStruct* Root; - EDA_LibCmpAliasStruct* Alias; + LIB_COMPONENT* Root; + LIB_ALIAS* Alias; m_IsModified = true; if( entry->Type == ALIAS ) { - Alias = (EDA_LibCmpAliasStruct*) entry; - Root = FindComponent( Alias->m_RootName ); + Alias = (LIB_ALIAS*) entry; + Root = Alias->GetComponent(); /* Remove alias name from the root component alias list */ if( Root == NULL ) @@ -236,7 +271,7 @@ void LibraryStruct::RemoveEntry( LibCmpEntry* entry ) wxLogWarning( wxT( "No root component found for alias <%s> in \ library <%s>." ), ( const wxChar* ) entry->GetName(), - ( const wxChar* ) m_Name ); + ( const wxChar* ) m_fileName.GetName() ); } else { @@ -247,7 +282,7 @@ library <%s>." ), alias list in library <%s>" ), ( const wxChar* ) entry->GetName(), ( const wxChar* ) Root->GetName(), - ( const wxChar* ) m_Name ); + ( const wxChar* ) m_fileName.GetName() ); else Root->m_AliasList.RemoveAt( index ); } @@ -257,7 +292,7 @@ alias list in library <%s>" ), return; } - Root = ( EDA_LibComponentStruct* ) entry; + Root = ( LIB_COMPONENT* ) entry; /* Entry is a component with no aliases so removal is simple. */ if( Root->m_AliasList.GetCount() == 0 ) @@ -279,7 +314,7 @@ alias list in library <%s>" ), library <%s>" ), ( const wxChar* ) AliasName, ( const wxChar* ) Root->GetName(), - ( const wxChar* ) m_Name ); + ( const wxChar* ) m_fileName.GetName() ); return; } @@ -293,41 +328,20 @@ library <%s>" ), /* Remove the first alias from library. */ RemoveEntry( AliasName ); + /* Change the root name. */ Root->m_Name.m_Text = AliasName; - - /* Change the "RootName" for all other aliases */ - for( size_t ii = 0; ii < Root->m_AliasList.GetCount(); ii++ ) - { - Alias = FindAlias( Root->m_AliasList[ii] ); - - /* Should not occur if library was saved by the library editor. - * However, it is possible if the library was edited by hand or - * some other program or a there is a bug in the library editor. */ - if( Alias == NULL ) - { - wxLogWarning( wxT( "Alias <%s> for component <%s> not found in \ -library <%s>." ), - ( const wxChar* ) AliasName, - ( const wxChar* ) Root->GetName(), - ( const wxChar* ) m_Name ); - continue; - } - - Alias->m_RootName = Root->GetName(); - } } -EDA_LibComponentStruct* LibraryStruct::ReplaceComponent( - EDA_LibComponentStruct* oldComponent, - EDA_LibComponentStruct* newComponent ) +LIB_COMPONENT* CMP_LIBRARY::ReplaceComponent( LIB_COMPONENT* oldComponent, + LIB_COMPONENT* newComponent ) { wxASSERT( oldComponent != NULL && newComponent != NULL && oldComponent->GetName().CmpNoCase( newComponent->GetName() )== 0 ); size_t i; int index; - EDA_LibCmpAliasStruct* alias; + LIB_ALIAS* alias; if( oldComponent->m_AliasList != newComponent->m_AliasList ) { @@ -344,7 +358,7 @@ EDA_LibComponentStruct* LibraryStruct::ReplaceComponent( in library <%s>." ), (const wxChar*) oldComponent->m_AliasList[ i ], (const wxChar*) oldComponent->GetName(), - (const wxChar*) m_Name ); + (const wxChar*) m_fileName.GetName() ); RemoveEntry( oldComponent->m_AliasList[ i ] ); } @@ -363,32 +377,32 @@ in library <%s>." ), in library <%s>." ), (const wxChar*) newComponent->m_AliasList[ i ], (const wxChar*) newComponent->GetName(), - (const wxChar*) m_Name ); + (const wxChar*) m_fileName.GetName() ); - alias = new EDA_LibCmpAliasStruct( newComponent->m_AliasList[ i ], - newComponent->GetName() ); + alias = new LIB_ALIAS( newComponent->m_AliasList[ i ], + newComponent ); m_Entries.push_back( alias ); } } RemoveEntry( oldComponent->GetName() ); - EDA_LibComponentStruct* newCmp = CopyLibEntryStruct( newComponent ); + LIB_COMPONENT* newCmp = CopyLibEntryStruct( newComponent ); if( newCmp == NULL ) return NULL; - m_Entries.push_back( (LibCmpEntry*) newCmp ); + m_Entries.push_back( (CMP_LIB_ENTRY*) newCmp ); m_Entries.sort(); m_IsModified = true; return newCmp; } -LibCmpEntry* LibraryStruct::GetNextEntry( const wxChar* name ) +CMP_LIB_ENTRY* CMP_LIBRARY::GetNextEntry( const wxChar* name ) { size_t i; - LibCmpEntry* entry = NULL; + CMP_LIB_ENTRY* entry = NULL; for( i = 0; i < m_Entries.size(); i++ ) { @@ -409,10 +423,10 @@ LibCmpEntry* LibraryStruct::GetNextEntry( const wxChar* name ) } -LibCmpEntry* LibraryStruct::GetPreviousEntry( const wxChar* name ) +CMP_LIB_ENTRY* CMP_LIBRARY::GetPreviousEntry( const wxChar* name ) { size_t i; - LibCmpEntry* entry = NULL; + CMP_LIB_ENTRY* entry = NULL; for( i = 0; i < m_Entries.size(); i++ ) { @@ -426,44 +440,95 @@ LibCmpEntry* LibraryStruct::GetPreviousEntry( const wxChar* name ) } -bool LibraryStruct::Load( wxString& errMsg ) +bool CMP_LIBRARY::Load( wxString& errMsg ) { - FILE* f; - int LineNum = 0; - char Line[1024]; - EDA_LibComponentStruct* LibEntry; - wxString msg; + FILE* f; + int LineNum = 0; + char Line[1024]; + LIB_COMPONENT* LibEntry; + wxString msg; - if( m_FullFileName.IsEmpty() ) + if( m_fileName.GetFullPath().IsEmpty() ) { - errMsg = _( "library file name not set" ); + errMsg = _( "The component library file name is not set." ); return false; } - f = wxFopen( m_FullFileName, wxT( "rt" ) ); + f = wxFopen( m_fileName.GetFullPath(), wxT( "rt" ) ); if( f == NULL ) { - errMsg = _( "could not open file" ); + errMsg = _( "The file could not be opened." ); return false; } if( GetLine( f, Line, &LineNum, sizeof( Line ) ) == NULL ) { - errMsg = _( "file is empty!" ); - return false; - } - - if( strnicmp( Line, LIBFILE_IDENT, 10 ) != 0 ) - { - errMsg = _( "file is NOT an EESCHEMA library!" ); + errMsg = _( "The file is empty!" ); return false; } /* There is no header if this is a symbol library. */ if( m_Type == LIBRARY_TYPE_EESCHEMA ) + { + wxString tmp; + m_Header = CONV_FROM_UTF8( Line ); + wxStringTokenizer tkn( m_Header ); + + /* + * The file header (first line) in library versions 2.0 and lower + * apparently started with EESchema-LIB. Sometime after 2.0, it + * was changed to EESchema-LIBRARY. Therefore, the test for + * EESchema-LIB will work in both cases. Don't change this unless + * backwards compatability is no longer required. + */ + if( !tkn.HasMoreTokens() + || !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) ) + { + errMsg = _( "The file is NOT an EESCHEMA library!" ); + return false; + } + + if( !tkn.HasMoreTokens() ) + { + errMsg = _( "The file header is missing version and time stamp \ +information." ); + return false; + } + + if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() ) + { + errMsg = _( "The file header version information is invalid." ); + return false; + } + + long major, minor; + wxStringTokenizer vers( tkn.GetNextToken(), wxT( "." ) ); + + if( !vers.HasMoreTokens() || !vers.GetNextToken().ToLong( &major ) + || major < 1L || !vers.HasMoreTokens() + || !vers.GetNextToken().ToLong( & minor ) || minor < 0L + || minor > 99 ) + { + wxLogWarning( _( "The component library <%s> header version \ +number is invalid.\n\nIn future versions of EESchema this library may not \ +load correctly.\nTo resolve this problem open the library in the library \ +editor and save it.\nIf this library is the project cache library, save \ +the current schematic." ), + (const wxChar*) GetName() ); + } + else + { + m_verMajor = (int) major; + m_verMinor = (int) minor; + + wxLogDebug( wxT( "Component library <%s> is version %d.%d." ), + (const wxChar*) GetName(), m_verMajor, m_verMinor ); + } + } + while( GetLine( f, Line, &LineNum, sizeof( Line ) ) ) { if( m_Type == LIBRARY_TYPE_EESCHEMA @@ -471,7 +536,7 @@ bool LibraryStruct::Load( wxString& errMsg ) { if( !LoadHeader( f, &LineNum ) ) { - errMsg = _( "header read error" ); + errMsg = _( "An error occured attempting to read the header." ); return false; } @@ -481,18 +546,28 @@ bool LibraryStruct::Load( wxString& errMsg ) if( strnicmp( Line, "DEF", 3 ) == 0 ) { /* Read one DEF/ENDDEF part entry from library: */ - LibEntry = new EDA_LibComponentStruct( NULL ); + LibEntry = new LIB_COMPONENT( wxEmptyString, this ); if( LibEntry->Load( f, Line, &LineNum, msg ) ) { + /* Check for duplicate entry names and warn the user about + * the potential conflict. + */ + if( FindEntry( LibEntry->GetName() ) != NULL ) + { + wxLogWarning( duplicate_name_msg, + (const wxChar*) m_fileName.GetName(), + (const wxChar*) LibEntry->GetName() ); + } + /* If we are here, this part is O.k. - put it in: */ m_Entries.push_back( LibEntry ); LoadAliases( LibEntry ); } else { - wxLogWarning( wxT( "Library <%s> component load error %s." ), - (const wxChar*) m_Name, + wxLogWarning( _( "Library <%s> component load error %s." ), + (const wxChar*) m_fileName.GetName(), (const wxChar*) msg ); msg.Clear(); delete LibEntry; @@ -506,24 +581,29 @@ bool LibraryStruct::Load( wxString& errMsg ) } -void LibraryStruct::LoadAliases( EDA_LibComponentStruct* component ) +void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component ) { - wxASSERT( component != NULL ); + wxASSERT( component != NULL && component->Type == ROOT ); - EDA_LibCmpAliasStruct* AliasEntry; - unsigned ii; + LIB_ALIAS* alias; + unsigned ii; for( ii = 0; ii < component->m_AliasList.GetCount(); ii++ ) { - AliasEntry = - new EDA_LibCmpAliasStruct( component->m_AliasList[ii], - component->GetName() ); - m_Entries.push_back( AliasEntry ); + if( FindEntry( component->m_AliasList[ii] ) != NULL ) + { + wxLogError( duplicate_name_msg, + (const wxChar*) m_fileName.GetName(), + (const wxChar*) component->m_AliasList[ii] ); + } + + alias = new LIB_ALIAS( component->m_AliasList[ii], component, this ); + m_Entries.push_back( alias ); } } -bool LibraryStruct::LoadHeader( FILE* libfile, int* LineNum ) +bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum ) { char Line[1024], * text, * data; @@ -541,16 +621,15 @@ bool LibraryStruct::LoadHeader( FILE* libfile, int* LineNum ) } -bool LibraryStruct::LoadDocs( wxString& errMsg ) +bool CMP_LIBRARY::LoadDocs( wxString& errMsg ) { - int LineNum = 0; - char Line[1024], * Name, * Text; - LibCmpEntry* Entry; - FILE* f; - wxString msg; - wxFileName fn; + int LineNum = 0; + char Line[1024], * Name, * Text; + CMP_LIB_ENTRY* Entry; + FILE* f; + wxString msg; + wxFileName fn = m_fileName; - fn = m_FullFileName; fn.SetExt( DOC_EXT ); f = wxFopen( fn.GetFullPath(), wxT( "rt" ) ); @@ -627,7 +706,7 @@ document file." ), } -bool LibraryStruct::Save( const wxString& FullFileName ) +bool CMP_LIBRARY::Save( const wxString& FullFileName ) { FILE* libfile, *docfile; wxString msg; @@ -671,7 +750,8 @@ bool LibraryStruct::Save( const wxString& FullFileName ) if( libfile == NULL ) { - msg = wxT( "Failed to create Lib File " ) + libFileName.GetFullPath(); + msg = wxT( "Failed to create component library file " ) + + libFileName.GetFullPath(); DisplayError( NULL, msg ); return false; } @@ -680,7 +760,7 @@ bool LibraryStruct::Save( const wxString& FullFileName ) if( docfile == NULL ) { - msg = wxT( "Failed to create DocLib File " ) + + msg = wxT( "Failed to create component document library file " ) + docFileName.GetFullPath(); DisplayError( NULL, msg ); } @@ -698,12 +778,11 @@ bool LibraryStruct::Save( const wxString& FullFileName ) bool success = true; - BOOST_FOREACH( LibCmpEntry& entry, m_Entries ) + BOOST_FOREACH( CMP_LIB_ENTRY& entry, m_Entries ) { if ( entry.Type == ROOT ) { - EDA_LibComponentStruct* component = - ( EDA_LibComponentStruct* ) &entry; + LIB_COMPONENT* component = ( LIB_COMPONENT* ) &entry; if ( ! component->Save( libfile ) ) success = false; } @@ -723,7 +802,7 @@ bool LibraryStruct::Save( const wxString& FullFileName ) } -bool LibraryStruct::SaveHeader( FILE* file ) +bool CMP_LIBRARY::SaveHeader( FILE* file ) { char BufLine[1024]; bool succes = false; @@ -743,7 +822,180 @@ bool LibraryStruct::SaveHeader( FILE* file ) } -wxString LibraryStruct::GetName() +/* + * The static library list and list management methods. + */ +CMP_LIBRARY_LIST CMP_LIBRARY::m_LibraryList; +wxArrayString CMP_LIBRARY::m_LibraryListSortOrder; + + +CMP_LIBRARY* CMP_LIBRARY::LoadLibrary( const wxFileName& fileName, + wxString& errMsg ) { - return m_Name; + CMP_LIBRARY* lib = NULL; + + lib = new CMP_LIBRARY( LIBRARY_TYPE_EESCHEMA, fileName ); + + wxBusyCursor ShowWait; + + if( !lib->Load( errMsg ) ) + { + delete lib; + return NULL; + } + + lib->LoadDocs( errMsg ); + + return lib; +} + + +bool CMP_LIBRARY::AddLibrary( const wxFileName& fileName, wxString& errMsg ) +{ + CMP_LIBRARY* lib; + + /* Don't reload the library if it is already loaded. */ + lib = FindLibrary( fileName.GetName() ); + + if( lib != NULL ) + return true; + + lib = LoadLibrary( fileName, errMsg ); + + if( lib == NULL ) + return false; + + m_LibraryList.push_back( lib ); + + return true; +} + + +bool CMP_LIBRARY::AddLibrary( const wxFileName& fileName, wxString& errMsg, + CMP_LIBRARY_LIST::iterator& i ) +{ + CMP_LIBRARY* lib; + + /* Don't reload the library if it is already loaded. */ + lib = FindLibrary( fileName.GetName() ); + + if( lib != NULL ) + return true; + + lib = LoadLibrary( fileName, errMsg ); + + if( lib == NULL ) + return false; + + if( i >= m_LibraryList.begin() && i < m_LibraryList.end() ) + m_LibraryList.insert( i, lib ); + else + m_LibraryList.push_back( lib ); + + return true; +} + + +void CMP_LIBRARY::RemoveLibrary( const wxString& name ) +{ + if( name.IsEmpty() ) + return; + + CMP_LIBRARY_LIST::iterator i; + + for ( i = m_LibraryList.begin(); i < m_LibraryList.end(); i++ ) + { + if( i->GetName().CmpNoCase( name ) == 0 ) + { + CMP_LIBRARY::m_LibraryList.erase( i ); + return; + } + } +} + + +CMP_LIBRARY* CMP_LIBRARY::FindLibrary( const wxString& name ) +{ + BOOST_FOREACH( CMP_LIBRARY& lib, m_LibraryList ) + { + if( lib == name ) + return &lib; + } + + return NULL; +} + +wxArrayString CMP_LIBRARY::GetLibraryNames( bool sorted ) +{ + wxString cacheName; + wxArrayString names; + + BOOST_FOREACH( CMP_LIBRARY& lib, CMP_LIBRARY::m_LibraryList ) + { + if( lib.m_IsCache && sorted ) + cacheName = lib.GetName(); + else + names.Add( lib.GetName() ); + } + + /* Even sorted, the cache library is always at the end of the list. */ + if( sorted ) + names.Sort(); + + if( !cacheName.IsEmpty() ) + names.Add( cacheName ); + + return names; +} + + +LIB_COMPONENT* CMP_LIBRARY::FindLibraryComponent( const wxString& name, + const wxString& libName ) +{ + LIB_COMPONENT* component = NULL; + + BOOST_FOREACH( CMP_LIBRARY& lib, m_LibraryList ) + { + if( !libName.IsEmpty() && lib.GetName() != libName ) + continue; + + component = lib.FindComponent( name ); + + if( component != NULL ) + break; + } + + return component; +} + + +CMP_LIB_ENTRY* CMP_LIBRARY::FindLibraryEntry( const wxString& name, + const wxString& libName ) +{ + CMP_LIB_ENTRY* entry = NULL; + + BOOST_FOREACH( CMP_LIBRARY& lib, m_LibraryList ) + { + if( !libName.IsEmpty() && lib.GetName() != libName ) + continue; + + entry = lib.FindEntry( name ); + + if( entry != NULL ) + break; + } + + return entry; +} + + +void CMP_LIBRARY::RemoveCacheLibrary( void ) +{ + CMP_LIBRARY_LIST::iterator i; + + for ( i = m_LibraryList.begin(); i < m_LibraryList.end(); i++ ) + { + if( i->m_IsCache ) + m_LibraryList.erase( i-- ); + } } diff --git a/eeschema/class_library.h b/eeschema/class_library.h index 1ee0478477..dc64b9c971 100644 --- a/eeschema/class_library.h +++ b/eeschema/class_library.h @@ -9,6 +9,14 @@ #include "class_libentry.h" +/* Helpers for creating a list of component libraries. */ +class CMP_LIBRARY; + +typedef boost::ptr_vector< CMP_LIBRARY > CMP_LIBRARY_LIST; + +extern bool operator<( const CMP_LIBRARY& item1, const CMP_LIBRARY& item2 ); + + /** * Component library object. * @@ -16,22 +24,21 @@ * component library files. */ -class LibraryStruct +class CMP_LIBRARY { public: - int m_Type; /* type indicator */ - wxString m_Name; /* Library file name (without path). */ - wxString m_FullFileName; /* Full File Name (with path) of library. */ - wxString m_Header; /* first line of loaded library. */ - LibraryStruct* m_Pnext; /* Point on next lib in chain. */ - unsigned long m_TimeStamp; // Signature temporelle - int m_Flags; // variable used in some functions - bool m_IsLibCache; /* False for the "standard" libraries, - * True for the library cache */ + int m_Type; /* type indicator */ + wxString m_Header; /* first line of loaded library. */ + unsigned long m_TimeStamp; // Signature temporelle + int m_Flags; // variable used in some functions public: - LibraryStruct( int type, const wxString& name, const wxString& fullname ); - ~LibraryStruct(); + CMP_LIBRARY( int type, const wxFileName& fullname ); + CMP_LIBRARY( int type, const wxString& fullname ) + { + CMP_LIBRARY( type, wxFileName( fullname ) ); + } + ~CMP_LIBRARY(); /** * Save library to file. @@ -63,19 +70,17 @@ private: bool SaveHeader( FILE* file ); bool LoadHeader( FILE* file, int* LineNum ); - void LoadAliases( EDA_LibComponentStruct* component ); + void LoadAliases( LIB_COMPONENT* component ); void RemoveEntry( const wxString& name ); public: - LibraryStruct( const wxChar* fileName = NULL ); - /** * Get library entry status. * * @return true if there are no entries in the library. */ - bool IsEmpty() + bool IsEmpty() const { return m_Entries.empty(); } @@ -85,16 +90,26 @@ public: * * @return The number of component and alias entries. */ - int GetCount() + int GetCount() const { return m_Entries.size(); } - bool IsModified() + bool IsModified() const { return m_IsModified; } + + bool IsCache() const { return m_IsCache; } + + + void SetModified( void ) { m_IsModified = true; } + + + void SetCache( void ) { m_IsCache = true; } + + /** * Load a string array with the names of all the entries in this library. * @@ -132,7 +147,7 @@ public: * * @return Pointer to entry if found. NULL if not found. */ - LibCmpEntry* FindEntry( const wxChar* name ); + CMP_LIB_ENTRY* FindEntry( const wxChar* name ); /** * Find entry by name and type. @@ -142,13 +157,13 @@ public: * * @return Pointer to entry if found. NULL if not found. */ - LibCmpEntry* FindEntry( const wxChar* name, LibrEntryType type ); + CMP_LIB_ENTRY* FindEntry( const wxChar* name, LibrEntryType type ); /** * Find component by name. * - * This is a helper for FindEntry so casting a LibCmpEntry pointer to - * a EDA_LibComponentStruct pointer is not required. + * This is a helper for FindEntry so casting a CMP_LIB_ENTRY pointer to + * a LIB_COMPONENT pointer is not required. * * @param name - Name of component, case insensitive. * @param searchAliases - Searches for component by alias name as well as @@ -156,22 +171,21 @@ public: * * @return Pointer to component if found. NULL if not found. */ - EDA_LibComponentStruct* FindComponent( const wxChar* name, - bool searchAliases = true ); + LIB_COMPONENT* FindComponent( const wxChar* name ); /** * Find alias by name. * - * This is a helper for FindEntry so casting a LibCmpEntry pointer to - * a EDA_LibCmpAliasStruct pointer is not required. + * This is a helper for FindEntry so casting a CMP_LIB_ENTRY pointer to + * a LIB_ALIAS pointer is not required. * * @param name - Name of alias, case insensitive. * * @return Pointer to alias if found. NULL if not found. */ - EDA_LibCmpAliasStruct* FindAlias( const wxChar* name ) + LIB_ALIAS* FindAlias( const wxChar* name ) { - return (EDA_LibCmpAliasStruct*) FindEntry( name, ALIAS ); + return (LIB_ALIAS*) FindEntry( name, ALIAS ); } /** @@ -188,7 +202,7 @@ public: * @return bool - True if alias added to library. False if conflict * exists. */ - bool AddAlias( EDA_LibCmpAliasStruct* alias ); + bool AddAlias( LIB_ALIAS* alias ); /** * Add component entry to library. @@ -197,7 +211,7 @@ public: * * @return Pointer to added component if successful. */ - EDA_LibComponentStruct* AddComponent( EDA_LibComponentStruct* cmp ); + LIB_COMPONENT* AddComponent( LIB_COMPONENT* cmp ); /** * Remove an entry from the library. @@ -211,7 +225,7 @@ public: * * @param entry - Entry to remove from library. */ - void RemoveEntry( LibCmpEntry* entry ); + void RemoveEntry( CMP_LIB_ENTRY* entry ); /** * Replace an existing component entry in the library. @@ -219,16 +233,15 @@ public: * @param oldComponent - The component to replace. * @param newComponent - The new component. */ - EDA_LibComponentStruct* ReplaceComponent( - EDA_LibComponentStruct* oldComponent, - EDA_LibComponentStruct* newComponent ); + LIB_COMPONENT* ReplaceComponent( LIB_COMPONENT* oldComponent, + LIB_COMPONENT* newComponent ); /** * Return the first entry in the library. * * @return The first entry or NULL if the library has no entries. */ - LibCmpEntry* GetFirstEntry() + CMP_LIB_ENTRY* GetFirstEntry() { return &m_Entries.front(); } @@ -241,10 +254,10 @@ public: * * @param name - Name of current entry. * - * @return LibCmpEntry - Pointer to next entry if entry name is found. - * Otherwise NULL. + * @return CMP_LIB_ENTRY - Pointer to next entry if entry name is found. + * Otherwise NULL. */ - LibCmpEntry* GetNextEntry( const wxChar* name ); + CMP_LIB_ENTRY* GetNextEntry( const wxChar* name ); /** @@ -255,28 +268,175 @@ public: * * @param name - Name of current entry. * - * @return LibCmpEntry - Pointer to previous entry if entry name is found. - * Otherwise NULL. + * @return CMP_LIB_ENTRY - Pointer to previous entry if entry name is found. + * Otherwise NULL. */ - LibCmpEntry* GetPreviousEntry( const wxChar* name ); + CMP_LIB_ENTRY* GetPreviousEntry( const wxChar* name ); - wxString GetName(); + /** + * Return the file name without path or extension. + * + * @return wxString - Name of library file. + */ + wxString GetName() const { return m_fileName.GetName(); } + + /** + * Return the full file library name with path and extension. + * + * @return wxString - Full library file name with path and extension. + */ + wxString GetFullFileName() { return m_fileName.GetFullPath(); } + + /** + * Set the component library file name. + * + * @param fileName - New library file name. + */ + void SetFileName( const wxFileName fileName ) + { + if( fileName != m_fileName ) + m_fileName = fileName; + } + + /* + * The following static methods are for manipulating the list of + * component libraries. This eliminates the need for yet another + * global variable ( formerly g_LibraryList ) and gives some measure + * of safety from abusing the library list. + */ + + /** + * Load a component library file. + * + * @param fileName - File name of the component library to load. + * @param errMsg - Error message if the component library failed to load. + * + * @return Pointer to library object if library file loaded successfully. + * Otherwise NULL. + */ + static CMP_LIBRARY* LoadLibrary( const wxFileName& fileName, + wxString& errMsg ); + + /** + * Add a compnent library to the library list. + * + * @param fileName - File name object of component library. + * @param errMsg - Error message if the component library failed to load. + * + * @return bool - True if library loaded properly otherwise false. + */ + static bool AddLibrary( const wxFileName& fileName, wxString& errMsg ); + + /** + * Insert a compnent library to the library list. + * + * @param fileName - File name object of component library. + * @param errMsg - Error message if the component library failed to load. + * @param i - Iterator to insert library in front of. + * + * @return bool - True if library loaded properly otherwise false. + */ + static bool AddLibrary( const wxFileName& fileName, wxString& errMsg, + CMP_LIBRARY_LIST::iterator& i ); + + /** + * Remove component library from the library list. + * + * @param name - Name of component library to remove. + */ + static void RemoveLibrary( const wxString& name ); + + /** + * Find component library by name. + * + * @param name - Library file name without path or extension to find. + * + * @return CMP_LIBRARY* - Pointer to component library if found, + * otherwise NULL. + */ + static CMP_LIBRARY* FindLibrary( const wxString& name ); + + /** + * Get the list of component library file names without path and extension. + * + * @param sorted - Sort the list of name if true. Otherwise use the + * library load order. + * + * @return wxArrayString - The list of library names. + */ + static wxArrayString GetLibraryNames( bool sorted = true ); + + /** + * Search all libraries in the list for a component. + * + * A component object will always be returned. If the entry found + * is an alias. The root component will be found and returned. + * + * @param name - Name of component to search for. + * @param libNaem - Name of the library to search for component. + * + * @return Pointer to a valid component object if found. Otherwise NULL. + */ + static LIB_COMPONENT* FindLibraryComponent( + const wxString& name, const wxString& libName = wxEmptyString ); + + /** + * Search all libraries in the list for an entry. + * + * The object can be either a component or an alias. + * + * @param name - Name of component to search for. + * @param libNaem - Name of the library to search for entry. + * + * @return Pointer to a valid entry object if found. Otherwise NULL. + */ + static CMP_LIB_ENTRY* FindLibraryEntry( + const wxString& name, + const wxString& libName = wxEmptyString ); + + /** + * Remove all cache libraries from library list. + */ + static void RemoveCacheLibrary( void ); + + static int GetLibraryCount( void ) { return m_LibraryList.size(); } + + static CMP_LIBRARY_LIST& GetLibraryList( void ) + { + return m_LibraryList; + } + + static void SetSortOrder( const wxArrayString& sortOrder ) + { + m_LibraryListSortOrder = sortOrder; + } + + static wxArrayString& GetSortOrder( void ) + { + return m_LibraryListSortOrder; + } protected: wxFileName m_fileName; /* Library file name. */ wxDateTime m_DateTime; /* Library save time and date. */ - wxString m_Version; /* Library save version. */ + int m_verMajor; /* Library major version number. */ + int m_verMinor; /* Library minor version number. */ LIB_ENTRY_LIST m_Entries; /* Parts themselves are saved here. */ bool m_IsModified; /* Library modification status. */ + bool m_IsCache; /* False for the "standard" libraries, + * True for the library cache */ - friend class EDA_LibComponentStruct; + static CMP_LIBRARY_LIST m_LibraryList; + static wxArrayString m_LibraryListSortOrder; + + friend class CMP_LIB_ENTRY; }; /** * Case insensitive library name comparison. */ -extern bool operator==( const LibraryStruct& lib, const wxChar* name ); -extern bool operator!=( const LibraryStruct& lib, const wxChar* name ); +extern bool operator==( const CMP_LIBRARY& lib, const wxChar* name ); +extern bool operator!=( const CMP_LIBRARY& lib, const wxChar* name ); #endif // CLASS_LIBRARY_H diff --git a/eeschema/class_pin.cpp b/eeschema/class_pin.cpp index 74ed1ffff6..80b5075334 100644 --- a/eeschema/class_pin.cpp +++ b/eeschema/class_pin.cpp @@ -30,7 +30,7 @@ const wxChar* MsgPinElectricType[] = wxT( "?????" ) }; -LibDrawPin::LibDrawPin(EDA_LibComponentStruct * aParent) : +LibDrawPin::LibDrawPin(LIB_COMPONENT * aParent) : LibEDA_BaseStruct( COMPONENT_PIN_DRAW_TYPE, aParent ) { m_PinLen = 300; /* default Pin len */ @@ -324,7 +324,7 @@ void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel, return; } - EDA_LibComponentStruct* Entry = GetParent(); + LIB_COMPONENT* Entry = GetParent(); bool DrawPinText = true; if( ( aData != NULL ) && ( (bool*) aData == false ) ) diff --git a/eeschema/class_sch_cmp_field.cpp b/eeschema/class_sch_cmp_field.cpp index a7e5c387b6..3097a95537 100644 --- a/eeschema/class_sch_cmp_field.cpp +++ b/eeschema/class_sch_cmp_field.cpp @@ -405,7 +405,7 @@ bool SCH_CMP_FIELD::Save( FILE* aFile ) const void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) { int fieldNdx; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; frame->DrawPanel->ManageCurseur = NULL; frame->DrawPanel->ForceCloseManageCurseur = NULL; @@ -424,7 +424,7 @@ void SCH_CMP_FIELD::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) m_AddExtraText = 0; if( fieldNdx == REFERENCE ) { - Entry = ( EDA_LibComponentStruct* ) FindLibPart( component->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( component->m_ChipName ); if( Entry != NULL ) { if( Entry->m_UnitCount > 1 ) diff --git a/eeschema/class_sch_component.cpp b/eeschema/class_sch_component.cpp index 7ddf09c699..fcf37b72f6 100644 --- a/eeschema/class_sch_component.cpp +++ b/eeschema/class_sch_component.cpp @@ -17,7 +17,7 @@ /* Local variables */ -static EDA_LibComponentStruct* DummyCmp; +static LIB_COMPONENT* DummyCmp; /* Descr component used when a component is not found in library, * to draw a dummy shape @@ -33,7 +33,7 @@ static EDA_LibComponentStruct* DummyCmp; */ void CreateDummyCmp() { - DummyCmp = new EDA_LibComponentStruct( NULL ); + DummyCmp = new LIB_COMPONENT( wxEmptyString ); LibDrawSquare* Square = new LibDrawSquare(DummyCmp); @@ -58,8 +58,7 @@ void CreateDummyCmp() *****************************************************************************/ /* DrawMode = GrXOR, GrOR ..*/ void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC, - SCH_COMPONENT* Component, - EDA_LibComponentStruct* Entry, + SCH_COMPONENT* Component, LIB_COMPONENT* Entry, const wxPoint& Pos, const int TransMat[2][2], int Multi, int convert, int DrawMode, int Color, bool DrawPinText ) @@ -165,11 +164,11 @@ SCH_COMPONENT::SCH_COMPONENT( const SCH_COMPONENT& aTemplate ) : void SCH_COMPONENT::Draw( WinEDA_DrawPanel* panel, wxDC* DC, const wxPoint& offset, int DrawMode, int Color ) { - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; int ii; bool dummy = FALSE; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); if( Entry == NULL ) { @@ -477,8 +476,7 @@ void SCH_COMPONENT::AddField( const SCH_CMP_FIELD& aField ) EDA_Rect SCH_COMPONENT::GetBoundaryBox() const { - EDA_LibComponentStruct* Entry = - ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName ); + LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); EDA_Rect BoundaryBox; int x0, xm, y0, ym; @@ -587,13 +585,13 @@ void SCH_COMPONENT::Place( WinEDA_SchematicFrame* frame, wxDC* DC ) */ void SCH_COMPONENT::ClearAnnotation( DrawSheetPath* aSheet ) { - wxString defRef = m_PrefixString; - bool KeepMulti = false; - EDA_LibComponentStruct* Entry; - wxString separators( wxT( " " ) ); - wxArrayString reference_fields; + wxString defRef = m_PrefixString; + bool KeepMulti = false; + LIB_COMPONENT* Entry; + wxString separators( wxT( " " ) ); + wxArrayString reference_fields; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); if( Entry && Entry->m_UnitSelectionLocked ) KeepMulti = true; @@ -1025,8 +1023,7 @@ EDA_Rect SCH_COMPONENT::GetBoundingBox() void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) { - EDA_LibComponentStruct* Entry = - ( EDA_LibComponentStruct* ) FindLibPart( m_ChipName ); + LIB_COMPONENT* Entry = CMP_LIBRARY::FindLibraryComponent( m_ChipName ); wxString msg; @@ -1045,7 +1042,8 @@ void SCH_COMPONENT::DisplayInfo( WinEDA_DrawFrame* frame ) Affiche_1_Parametre( frame, 28, _( "RefLib" ), m_ChipName.GetData(), BROWN ); - msg = FindLibName; + msg = Entry->GetLibraryName(); + Affiche_1_Parametre( frame, 40, _( "Lib" ), msg, DARKRED ); if( Entry ) diff --git a/eeschema/class_sch_component.h b/eeschema/class_sch_component.h index 6e8b929cdf..468feda4f1 100644 --- a/eeschema/class_sch_component.h +++ b/eeschema/class_sch_component.h @@ -14,8 +14,7 @@ extern void DrawLibPartAux( WinEDA_DrawPanel* panel, wxDC* DC, - SCH_COMPONENT* Component, - EDA_LibComponentStruct* Entry, + SCH_COMPONENT* Component, LIB_COMPONENT* Entry, const wxPoint& Pos, const int TransMat[2][2], int Multi, int convert, int DrawMode, int Color = -1, bool DrawPinText = TRUE ); diff --git a/eeschema/classes_body_items.cpp b/eeschema/classes_body_items.cpp index 6d30e63648..305023ccc2 100644 --- a/eeschema/classes_body_items.cpp +++ b/eeschema/classes_body_items.cpp @@ -23,7 +23,7 @@ static int fill_tab[3] = { 'N', 'F', 'f' }; /* Base class (abstract) for components bodies items */ LibEDA_BaseStruct::LibEDA_BaseStruct( KICAD_T struct_type, - EDA_LibComponentStruct* aParent ) : + LIB_COMPONENT* aParent ) : EDA_BaseStruct( struct_type ) { m_Unit = 0; /* Unit identification (for multi part per package) @@ -83,7 +83,7 @@ bool LibEDA_BaseStruct::operator==( const LibEDA_BaseStruct& other ) const /** class LibDrawArc **/ /**********************/ -LibDrawArc::LibDrawArc( EDA_LibComponentStruct* aParent ) : +LibDrawArc::LibDrawArc( LIB_COMPONENT* aParent ) : LibEDA_BaseStruct( COMPONENT_ARC_DRAW_TYPE, aParent ) { m_Radius = 0; @@ -437,7 +437,7 @@ void LibDrawArc::DisplayInfo( WinEDA_DrawFrame* frame ) /** class LibDrawCircle **/ /*************************/ -LibDrawCircle::LibDrawCircle( EDA_LibComponentStruct* aParent ) : +LibDrawCircle::LibDrawCircle( LIB_COMPONENT* aParent ) : LibEDA_BaseStruct( COMPONENT_CIRCLE_DRAW_TYPE, aParent ) { m_Radius = 0; @@ -645,7 +645,7 @@ void LibDrawCircle::DisplayInfo( WinEDA_DrawFrame* frame ) /** class LibDrawSquare **/ /*************************/ -LibDrawSquare::LibDrawSquare( EDA_LibComponentStruct* aParent ) : +LibDrawSquare::LibDrawSquare( LIB_COMPONENT* aParent ) : LibEDA_BaseStruct( COMPONENT_RECT_DRAW_TYPE, aParent ) { m_Width = 0; @@ -863,7 +863,7 @@ bool LibDrawSquare::HitTest( wxPoint aRefPoint, int aThreshold, /**************************/ /** class LibDrawSegment **/ /**************************/ -LibDrawSegment::LibDrawSegment( EDA_LibComponentStruct* aParent ) : +LibDrawSegment::LibDrawSegment( LIB_COMPONENT* aParent ) : LibEDA_BaseStruct( COMPONENT_LINE_DRAW_TYPE, aParent ) { m_Width = 0; @@ -1015,7 +1015,7 @@ bool LibDrawSegment::HitTest( wxPoint aPosRef, int aThreshold, /***************************/ /** class LibDrawPolyline **/ /***************************/ -LibDrawPolyline::LibDrawPolyline( EDA_LibComponentStruct* aParent ) : +LibDrawPolyline::LibDrawPolyline( LIB_COMPONENT* aParent ) : LibEDA_BaseStruct( COMPONENT_POLYLINE_DRAW_TYPE, aParent ) { m_Fill = NO_FILL; @@ -1320,7 +1320,7 @@ void LibDrawPolyline::DisplayInfo( WinEDA_DrawFrame* frame ) /***************************/ /** class LibDrawBezier **/ /***************************/ -LibDrawBezier::LibDrawBezier( EDA_LibComponentStruct* aParent ) : +LibDrawBezier::LibDrawBezier( LIB_COMPONENT* aParent ) : LibEDA_BaseStruct( COMPONENT_BEZIER_DRAW_TYPE, aParent ) { m_Fill = NO_FILL; diff --git a/eeschema/classes_body_items.h b/eeschema/classes_body_items.h index 923bae4cb5..3811853d0d 100644 --- a/eeschema/classes_body_items.h +++ b/eeschema/classes_body_items.h @@ -105,7 +105,7 @@ public: } - LibEDA_BaseStruct( KICAD_T struct_type, EDA_LibComponentStruct * aParent ); + LibEDA_BaseStruct( KICAD_T struct_type, LIB_COMPONENT * aParent ); virtual ~LibEDA_BaseStruct() { } /** Function Draw (virtual pure) @@ -143,9 +143,9 @@ public: virtual bool Save( FILE* aFile ) const = 0; virtual bool Load( char* line, wxString& errorMsg ) = 0; - EDA_LibComponentStruct * GetParent() + LIB_COMPONENT * GetParent() { - return (EDA_LibComponentStruct *)m_Parent; + return (LIB_COMPONENT *)m_Parent; } /** @@ -266,7 +266,7 @@ public: int m_Width; /* Line width */ public: - LibDrawPin(EDA_LibComponentStruct * aParent); + LibDrawPin(LIB_COMPONENT * aParent); ~LibDrawPin() { } LibDrawPin* Next() const { return (LibDrawPin*) Pnext; } @@ -382,7 +382,7 @@ public: int m_Width; /* Line width */ public: - LibDrawArc(EDA_LibComponentStruct * aParent); + LibDrawArc(LIB_COMPONENT * aParent); ~LibDrawArc() { } virtual wxString GetClass() const { @@ -449,7 +449,7 @@ public: int m_Width; /* Line width */ public: - LibDrawCircle(EDA_LibComponentStruct * aParent); + LibDrawCircle(LIB_COMPONENT * aParent); ~LibDrawCircle() { } virtual wxString GetClass() const { @@ -514,7 +514,7 @@ protected: class LibDrawText : public LibEDA_BaseStruct, public EDA_TextStruct { public: - LibDrawText(EDA_LibComponentStruct * aParent); + LibDrawText(LIB_COMPONENT * aParent); ~LibDrawText() { } virtual wxString GetClass() const { @@ -591,7 +591,7 @@ public: int m_Width; /* Line width */ public: - LibDrawSquare(EDA_LibComponentStruct * aParent); + LibDrawSquare(LIB_COMPONENT * aParent); ~LibDrawSquare() { } virtual wxString GetClass() const { @@ -658,7 +658,7 @@ public: int m_Width; /* Line width */ public: - LibDrawSegment(EDA_LibComponentStruct * aParent); + LibDrawSegment(LIB_COMPONENT * aParent); ~LibDrawSegment() { } virtual wxString GetClass() const { @@ -723,7 +723,7 @@ public: std::vector m_PolyPoints; // list of points (>= 2) public: - LibDrawPolyline(EDA_LibComponentStruct * aParent); + LibDrawPolyline(LIB_COMPONENT * aParent); ~LibDrawPolyline() { } virtual wxString GetClass() const @@ -800,7 +800,7 @@ public: std::vector m_PolyPoints; // list of points (>= 2) public: - LibDrawBezier(EDA_LibComponentStruct * aParent); + LibDrawBezier(LIB_COMPONENT * aParent); ~LibDrawBezier() { } virtual wxString GetClass() const diff --git a/eeschema/dangling_ends.cpp b/eeschema/dangling_ends.cpp index 88d3218ff4..e4baf3401c 100644 --- a/eeschema/dangling_ends.cpp +++ b/eeschema/dangling_ends.cpp @@ -387,8 +387,8 @@ DanglingEndHandle* RebuildEndList( EDA_BaseStruct* DrawList ) { #undef STRUCT #define STRUCT ( (SCH_COMPONENT*) DrawItem ) - EDA_LibComponentStruct* Entry; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( STRUCT->m_ChipName ); + LIB_COMPONENT* Entry; + Entry = CMP_LIBRARY::FindLibraryComponent( STRUCT->m_ChipName ); if( Entry == NULL ) break; diff --git a/eeschema/database.cpp b/eeschema/database.cpp index 0bd4eb8801..61f0edcdc0 100644 --- a/eeschema/database.cpp +++ b/eeschema/database.cpp @@ -15,9 +15,10 @@ #include "program.h" #include "libcmp.h" #include "general.h" - #include "protos.h" +#include + /* * Routine de selection du nom d'un composant en librairie pour chargement, @@ -34,7 +35,6 @@ wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys, wxString& BufName ) { - LibraryStruct* Lib; wxArrayString nameList; wxString msg; @@ -42,9 +42,9 @@ wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys, Keys.MakeUpper(); /* Examen de la liste des librairies pour comptage */ - for( Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) + BOOST_FOREACH( CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() ) { - Lib->SearchEntryNames( nameList, BufName, Keys ); + lib.SearchEntryNames( nameList, BufName, Keys ); } if( nameList.IsEmpty() ) @@ -77,14 +77,9 @@ wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys, void DisplayCmpDoc( wxString& Name ) { - LibCmpEntry* CmpEntry = NULL; - LibraryStruct* Lib = g_LibraryList; + CMP_LIB_ENTRY* CmpEntry = NULL; - while( Lib != NULL && CmpEntry == NULL ) - { - CmpEntry = Lib->FindEntry( Name ); - Lib = Lib->m_Pnext; - } + CmpEntry = CMP_LIBRARY::FindLibraryEntry( Name ); if( CmpEntry == NULL ) return; diff --git a/eeschema/dialog_create_component.cpp b/eeschema/dialog_create_component.cpp index b520700008..62570373d1 100644 --- a/eeschema/dialog_create_component.cpp +++ b/eeschema/dialog_create_component.cpp @@ -101,7 +101,7 @@ bool WinEDA_CreateCmpDialog::Create( WinEDA_DrawFrame* parent, wxWindowID id, co /**********************************************************************************/ -void WinEDA_CreateCmpDialog::SetComponentData( EDA_LibComponentStruct & component ) +void WinEDA_CreateCmpDialog::SetComponentData( LIB_COMPONENT & component ) /**********************************************************************************/ { g_AsDeMorgan = m_AsConvert->GetValue(); diff --git a/eeschema/dialog_create_component.h b/eeschema/dialog_create_component.h index 4885eb0c9e..72f6bc7182 100644 --- a/eeschema/dialog_create_component.h +++ b/eeschema/dialog_create_component.h @@ -94,7 +94,7 @@ public: { return m_CmpName->GetValue(); } - void SetComponentData( EDA_LibComponentStruct & component ); + void SetComponentData( LIB_COMPONENT & component ); ////@begin WinEDA_CreateCmpDialog event handler declarations /// wxEVT_COMMAND_BUTTON_CLICKED event handler for wxID_OK diff --git a/eeschema/dialog_edit_component_in_schematic.cpp b/eeschema/dialog_edit_component_in_schematic.cpp index a495ffdd78..8e8cc7fe5f 100644 --- a/eeschema/dialog_edit_component_in_schematic.cpp +++ b/eeschema/dialog_edit_component_in_schematic.cpp @@ -171,7 +171,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::copyPanelToOptions() else if( newname.CmpNoCase( m_Cmp->m_ChipName ) ) { - if( FindLibPart( newname, wxEmptyString, ALIAS ) == NULL ) + if( CMP_LIBRARY::FindLibraryEntry( newname ) == NULL ) { wxString message; message.Printf( _( "Component [%s] not found!" ), newname.GetData() ); @@ -263,8 +263,8 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::OnOKButtonClick( wxCommandEvent& event ++i; } - EDA_LibComponentStruct* entry = - ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName ); + LIB_COMPONENT* entry = + CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName ); if( entry && entry->m_Options == ENTRY_POWER ) m_FieldsBuf[VALUE].m_Text = m_Cmp->m_ChipName; @@ -411,7 +411,7 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::InitBuffers( SCH_COMPONENT* aComponent { m_Cmp = aComponent; - m_LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName ); + m_LibEntry = CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName ); #if 0 && defined(DEBUG) for( int i = 0; iGetFieldCount(); ++i ) @@ -700,12 +700,12 @@ void DIALOG_EDIT_COMPONENT_IN_SCHEMATIC::SetInitCmp( wxCommandEvent& event ) /* reinitialise components parametres to default values found in lib */ { - EDA_LibComponentStruct* entry; + LIB_COMPONENT* entry; if( m_Cmp == NULL ) return; - entry = ( EDA_LibComponentStruct* ) FindLibPart( m_Cmp->m_ChipName ); + entry = CMP_LIBRARY::FindLibraryComponent( m_Cmp->m_ChipName ); if( entry == NULL ) return; diff --git a/eeschema/dialog_edit_component_in_schematic.h b/eeschema/dialog_edit_component_in_schematic.h index 72a2bb7889..54441e4953 100644 --- a/eeschema/dialog_edit_component_in_schematic.h +++ b/eeschema/dialog_edit_component_in_schematic.h @@ -15,18 +15,18 @@ class DIALOG_EDIT_COMPONENT_IN_SCHEMATIC : public DIALOG_EDIT_COMPONENT_IN_SCHEM friend void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos, SCH_COMPONENT* aComponent ); - WinEDA_SchematicFrame* m_Parent; - SCH_COMPONENT* m_Cmp; - EDA_LibComponentStruct* m_LibEntry; - bool m_skipCopyFromPanel; + WinEDA_SchematicFrame* m_Parent; + SCH_COMPONENT* m_Cmp; + LIB_COMPONENT* m_LibEntry; + bool m_skipCopyFromPanel; - static int s_SelectedRow; + static int s_SelectedRow; /// The size of the dialog window last time it was displayed; - static wxSize s_LastSize; + static wxSize s_LastSize; /// a copy of the edited component's SCH_CMP_FIELDs - SCH_CMP_FIELDS m_FieldsBuf; + SCH_CMP_FIELDS m_FieldsBuf; void setSelectedFieldNdx( int aFieldNdx ); diff --git a/eeschema/dialog_edit_libentry_fields_in_lib.cpp b/eeschema/dialog_edit_libentry_fields_in_lib.cpp index ffae1ed347..f91afaec06 100644 --- a/eeschema/dialog_edit_libentry_fields_in_lib.cpp +++ b/eeschema/dialog_edit_libentry_fields_in_lib.cpp @@ -28,15 +28,15 @@ class DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB : public DIALOG_EDIT_LIBENTRY_FIELDS_IN { private: WinEDA_LibeditFrame* m_Parent; - EDA_LibComponentStruct* m_LibEntry; + LIB_COMPONENT* m_LibEntry; bool m_skipCopyFromPanel; /// a copy of the edited component's LibDrawFields std::vector m_FieldsBuf; public: - DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( WinEDA_LibeditFrame* aParent, - EDA_LibComponentStruct* aLibEntry ); + DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( WinEDA_LibeditFrame* aParent, + LIB_COMPONENT* aLibEntry ); ~DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB(); private: @@ -121,8 +121,8 @@ void WinEDA_LibeditFrame::InstallFieldsEditorDialog( void ) /***********************************************************************/ DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB::DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB( - WinEDA_LibeditFrame* aParent, - EDA_LibComponentStruct* aLibEntry ) : + WinEDA_LibeditFrame* aParent, + LIB_COMPONENT* aLibEntry ) : DIALOG_EDIT_LIBENTRY_FIELDS_IN_LIB_BASE( aParent ) /***********************************************************************/ { diff --git a/eeschema/dialog_eeschema_config.cpp b/eeschema/dialog_eeschema_config.cpp index 6cfe228484..a62bc4b7f2 100644 --- a/eeschema/dialog_eeschema_config.cpp +++ b/eeschema/dialog_eeschema_config.cpp @@ -161,7 +161,7 @@ void DIALOG_EESCHEMA_CONFIG::OnOkClick( wxCommandEvent& event ) m_Parent->m_ComponentLibFiles.Add(m_ListLibr->GetString(ii) ); // take new list in account - LoadLibraries( m_Parent ); + m_Parent->LoadLibraries(); if( m_Parent->m_ViewlibFrame ) m_Parent->m_ViewlibFrame->ReCreateListLib(); } diff --git a/eeschema/edit_component_in_lib.cpp b/eeschema/edit_component_in_lib.cpp index 51f30cecc1..746b15f5c6 100644 --- a/eeschema/edit_component_in_lib.cpp +++ b/eeschema/edit_component_in_lib.cpp @@ -56,7 +56,7 @@ void WinEDA_LibeditFrame::EditComponentProperties() void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc() { - LibCmpEntry* entry; + CMP_LIB_ENTRY* entry; if( CurrentLibEntry == NULL ) return; @@ -67,7 +67,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::InitPanelDoc() } else { - entry = ( LibCmpEntry* ) CurrentLib->FindAlias( CurrentAliasName ); + entry = ( CMP_LIB_ENTRY* ) CurrentLib->FindAlias( CurrentAliasName ); if( entry == NULL ) return; @@ -138,7 +138,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) /* Update the doc, keyword and doc filename strings */ size_t i; int index; - LibCmpEntry* entry; + CMP_LIB_ENTRY* entry; if( CurrentAliasName.IsEmpty() ) { @@ -155,7 +155,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) msg.Printf( _( "Alias <%s> not found for component <%s> in library <%s>." ), (const wxChar*) CurrentAliasName, (const wxChar*) CurrentLibEntry->GetName(), - (const wxChar*) CurrentLib->m_Name ); + (const wxChar*) CurrentLib->GetName() ); wxMessageBox( msg, _( "Component Library Error" ), wxID_OK | wxICON_ERROR, this ); } @@ -168,7 +168,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) if( m_PartAliasList->GetStrings() != CurrentLibEntry->m_AliasList ) { - EDA_LibCmpAliasStruct* alias; + LIB_ALIAS* alias; wxArrayString aliases = m_PartAliasList->GetStrings(); /* Add names not existing in the old alias list. */ @@ -179,8 +179,8 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) if( index != wxNOT_FOUND ) continue; - alias = new EDA_LibCmpAliasStruct( aliases[ i ], - CurrentLibEntry->GetName() ); + alias = new LIB_ALIAS( aliases[ i ], CurrentLibEntry ); + if( !CurrentLib->AddAlias( alias ) ) { delete alias; @@ -196,7 +196,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::OnOkClick( wxCommandEvent& event ) if( index == wxNOT_FOUND ) continue; - LibCmpEntry* alias = + CMP_LIB_ENTRY* alias = CurrentLib->FindAlias( CurrentLibEntry->m_AliasList[ i ] ); if( alias != NULL ) CurrentLib->RemoveEntry( alias ); @@ -318,7 +318,7 @@ void DIALOG_EDIT_COMPONENT_IN_LIBRARY::AddAliasOfPart( wxCommandEvent& WXUNUSED msg.Printf( _( "Alias or component name <%s> already exists in \ library <%s>." ), (const wxChar*) aliasname, - (const wxChar*) CurrentLib->m_Name ); + (const wxChar*) CurrentLib->GetName() ); DisplayError( this, msg ); return; } diff --git a/eeschema/edit_component_in_schematic.cpp b/eeschema/edit_component_in_schematic.cpp index 1f623844fa..6e4e3d10ad 100644 --- a/eeschema/edit_component_in_schematic.cpp +++ b/eeschema/edit_component_in_schematic.cpp @@ -27,7 +27,7 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC ) /* Prepare le deplacement du texte en cours d'edition */ { - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; SetCurrentField( aField ); if( aField == NULL ) @@ -68,7 +68,7 @@ void WinEDA_SchematicFrame::StartMoveCmpField( SCH_CMP_FIELD* aField, wxDC* DC ) m_Multiflag = 0; if( aField->m_FieldId == REFERENCE ) { - Entry = ( EDA_LibComponentStruct* ) FindLibPart( comp->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( comp->m_ChipName ); if( Entry != NULL ) { @@ -91,7 +91,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC ) /* Edit the field Field (text, size) */ { int fieldNdx, flag; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; if( Field == NULL ) { @@ -104,7 +104,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC ) fieldNdx = Field->m_FieldId; if( fieldNdx == VALUE ) { - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName ); if( Entry && (Entry->m_Options == ENTRY_POWER) ) { @@ -119,7 +119,7 @@ void WinEDA_SchematicFrame::EditCmpFieldText( SCH_CMP_FIELD* Field, wxDC* DC ) flag = 0; if( fieldNdx == REFERENCE ) { - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName ); if( Entry != NULL ) { @@ -249,7 +249,7 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC ) /*********************************************************************************/ { int fieldNdx, flag; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; if( Field == NULL ) return; @@ -262,7 +262,8 @@ void WinEDA_SchematicFrame::RotateCmpField( SCH_CMP_FIELD* Field, wxDC* DC ) flag = 0; if( fieldNdx == REFERENCE ) { - Entry = ( EDA_LibComponentStruct* ) FindLibPart( ( (SCH_COMPONENT*) Field->GetParent() )->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( + ( (SCH_COMPONENT*) Field->GetParent() )->m_ChipName ); if( Entry != NULL ) { @@ -293,13 +294,13 @@ void WinEDA_SchematicFrame::EditComponentReference( SCH_COMPONENT* Cmp, wxDC* DC /**************************************************************************************************/ /* Edit the component text reference*/ { - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; int flag = 0; if( Cmp == NULL ) return; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName ); if( Entry == NULL ) return; @@ -334,12 +335,12 @@ void WinEDA_SchematicFrame::EditComponentValue( SCH_COMPONENT* Cmp, wxDC* DC ) /* Routine de changement du texte selectionne */ { wxString message; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; if( Cmp == NULL ) return; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName ); if( Entry == NULL ) return; @@ -372,13 +373,13 @@ void WinEDA_SchematicFrame::EditComponentFootprint( SCH_COMPONENT* Cmp, wxDC* DC /*****************************************************************************************/ { wxString message; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; bool wasEmpty = false; if( Cmp == NULL ) return; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Cmp->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Cmp->m_ChipName ); if( Entry == NULL ) return; diff --git a/eeschema/eeconfig.cpp b/eeschema/eeconfig.cpp index b9d078bd55..8cd257da28 100644 --- a/eeschema/eeconfig.cpp +++ b/eeschema/eeconfig.cpp @@ -233,9 +233,6 @@ bool WinEDA_SchematicFrame::LoadProjectFile( const wxString& CfgFileName, wxFileName fn; bool IsRead = TRUE; wxArrayString liblist_tmp = m_ComponentLibFiles; - WinEDA_SchematicFrame* frame; - - frame = (WinEDA_SchematicFrame*)wxGetApp().GetTopWindow(); if( CfgFileName.IsEmpty() ) fn = g_RootSheet->m_AssociatedScreen->m_FileName; @@ -265,12 +262,8 @@ bool WinEDA_SchematicFrame::LoadProjectFile( const wxString& CfgFileName, if( m_ComponentLibFiles.GetCount() == 0 ) m_ComponentLibFiles.Add( wxT( "power" ) ); - if( frame ) - { - frame->SetDrawBgColor( g_DrawBgColor ); - } - - LoadLibraries( frame ); + SetDrawBgColor( g_DrawBgColor ); + LoadLibraries(); return IsRead; } diff --git a/eeschema/eelibs_draw_components.cpp b/eeschema/eelibs_draw_components.cpp index 50d3a2239d..c32b07b8fb 100644 --- a/eeschema/eelibs_draw_components.cpp +++ b/eeschema/eelibs_draw_components.cpp @@ -10,13 +10,14 @@ #include "libcmp.h" #include "general.h" #include "protos.h" +#include "class_library.h" + +#include + //#define DRAW_ARC_WITH_ANGLE // Used to select function to draw arcs -/* Local functions */ - - /***************************************************************************/ /** Function TransformCoordinate * Calculate the wew coordinate from the old one, according to the transform @@ -40,57 +41,6 @@ wxPoint TransformCoordinate( const int aTransformMatrix[2][2], } -/*****************************************************************************/ -/* - * Routine to find a part in one of the libraries given its name. - * Name = Name of part. - * LibName = Name of Lib; if "": seach in all libs - * Alias = Flag: si flag != 0, retourne un pointeur sur une part ou un alias - * si flag = 0, retourne un pointeur sur une part meme si le nom - * correspond a un alias - * Alias = FIND_ROOT, ou Alias = FIND_ALIAS - */ -/*****************************************************************************/ -LibCmpEntry* FindLibPart( const wxChar* Name, const wxString& LibName, - LibrEntryType type ) -{ - LibCmpEntry* Entry = NULL; - LibraryStruct* Lib = g_LibraryList; - - FindLibName.Empty(); - - while( Lib ) - { - if( !LibName.IsEmpty() ) - { - if( Lib->m_Name != LibName ) - { - Lib = Lib->m_Pnext; - continue; - } - } - - if( Lib == NULL ) - break; - - if( type == ROOT ) - Entry = (LibCmpEntry*) Lib->FindComponent( Name ); - else - Entry = Lib->FindEntry( Name ); - - if( Entry != NULL ) - { - FindLibName = Lib->m_Name; - break; - } - - Lib = Lib->m_Pnext; - } - - return Entry; -} - - /***************************************************************************** * Routine to rotate the given angular direction by the given Transformation. * * Input (and output) angles must be as follows: * @@ -162,9 +112,9 @@ bool MapAngles( int* Angle1, int* Angle2, const int TransMat[2][2] ) * This routine is applied by the PlaceLibItem routine above. * *****************************************************************************/ void DrawingLibInGhost( WinEDA_DrawPanel* panel, wxDC* DC, - EDA_LibComponentStruct* LibEntry, - SCH_COMPONENT* DrawLibItem, int PartX, int PartY, - int multi, int convert, int Color, bool DrawPinText ) + LIB_COMPONENT* LibEntry, SCH_COMPONENT* DrawLibItem, + int PartX, int PartY, int multi, int convert, + int Color, bool DrawPinText ) { int DrawMode = g_XorMode; diff --git a/eeschema/eelibs_read_libraryfiles.cpp b/eeschema/eelibs_read_libraryfiles.cpp index e7487217c8..b25b91fe8e 100644 --- a/eeschema/eelibs_read_libraryfiles.cpp +++ b/eeschema/eelibs_read_libraryfiles.cpp @@ -3,113 +3,52 @@ /*****************************************************************/ #include "fctsys.h" -#include "gr_basic.h" -#include "common.h" #include "confirm.h" -#include "kicad_string.h" -#include "gestfich.h" #include "appl_wxstruct.h" #include "program.h" #include "libcmp.h" #include "general.h" -#include "protos.h" #include "dialog_load_error.h" -/** - * Function LoadLibraryName - * - * Routine to load the given library name. FullLibName should hold full path - * of file name to open, while LibName should hold only its name. - * If library already exists, it is NOT reloaded. - * - * @return : new lib or NULL - */ -LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame, - const wxString& FullLibName, - const wxString& LibName ) -{ - LibraryStruct* NewLib; - wxFileName fn; - wxString errMsg; - - if( ( NewLib = FindLibrary( LibName ) ) != NULL ) - { - if( NewLib->m_FullFileName == FullLibName ) - return NewLib; - - delete NewLib; - } - - NewLib = new LibraryStruct( LIBRARY_TYPE_EESCHEMA, LibName, FullLibName ); - - wxBusyCursor ShowWait; - - if( NewLib->Load( errMsg ) ) - { - if( g_LibraryList == NULL ) - g_LibraryList = NewLib; - else - { - LibraryStruct* tmplib = g_LibraryList; - while( tmplib->m_Pnext ) - tmplib = tmplib->m_Pnext; - - tmplib->m_Pnext = NewLib; - } - - NewLib->LoadDocs( errMsg ); - } - else - { - wxString msg; - msg.Printf( _( "Error <%s> occurred attempting to load component \ -library <%s>" ), - ( const wxChar* ) errMsg, - ( const wxChar* ) FullLibName ); - DisplayError( frame, msg ); - SAFE_DELETE( NewLib ); - } - - return NewLib; -} - - /** * Function LoadLibraries * - * Clear all already loaded libraries and load all librairies - * given in frame->m_ComponentLibFiles + * Clear all already loaded libraries and load all of the project libraries. */ -void LoadLibraries( WinEDA_SchematicFrame* frame ) +void WinEDA_SchematicFrame::LoadLibraries( void ) { + size_t ii; wxFileName fn; - wxString msg, tmp; + wxString msg, tmp, errMsg; wxString libraries_not_found; - unsigned ii, iimax = frame->m_ComponentLibFiles.GetCount(); - // Free the unwanted libraries (i.e. not in list) but keep the cache lib - LibraryStruct* nextlib, * lib = g_LibraryList; + CMP_LIBRARY_LIST::iterator i = CMP_LIBRARY::GetLibraryList().begin(); - for( ; lib != NULL; lib = nextlib ) + /* Free the unwanted libraries but keep the cache library. */ + while ( i < CMP_LIBRARY::GetLibraryList().end() ) { - nextlib = lib->m_Pnext; - if( lib->m_IsLibCache ) + if( i->IsCache() ) + { + i++; continue; + } - // is this library in "wanted list" frame->m_ComponentLibFiles ? - if( frame->m_ComponentLibFiles.Index( lib->m_Name ) == wxNOT_FOUND ) - FreeCmpLibrary( frame, lib->m_Name ); + if( m_ComponentLibFiles.Index( i->GetName(), false ) == wxNOT_FOUND ) + i = CMP_LIBRARY::GetLibraryList().erase( i ); + else + i++; } - // Load missing libraries (if any) - for( ii = 0; ii < iimax; ii++ ) + /* Load missing libraries. */ + for( ii = 0; ii < m_ComponentLibFiles.GetCount(); ii++ ) { - fn = frame->m_ComponentLibFiles[ii]; + fn = m_ComponentLibFiles[ii]; fn.SetExt( CompLibFileExtension ); + /* Skip if the file name is not valid.. */ if( !fn.IsOk() ) continue; @@ -129,164 +68,46 @@ void LoadLibraries( WinEDA_SchematicFrame* frame ) // Loaded library statusbar message msg = _( "Library " ) + tmp; + fn = tmp; - if( LoadLibraryName( frame, tmp, fn.GetName() ) ) + if( CMP_LIBRARY::AddLibrary( fn, errMsg ) ) + { msg += _( " loaded" ); + } else - msg += _( " error!" ); + { + wxString prompt; - frame->PrintMsg( msg ); + prompt.Printf( _( "Component library <%s> failed to load.\n\n\ +Error: %s" ), + ( const wxChar* ) fn.GetFullPath(), + ( const wxChar* ) errMsg ); + DisplayError( this, prompt ); + msg += _( " error!" ); + } + + PrintMsg( msg ); } /* Print the libraries not found */ if( !libraries_not_found.IsEmpty() ) { - DIALOG_LOAD_ERROR dialog( frame ); + DIALOG_LOAD_ERROR dialog( this ); dialog.MessageSet( _( "The following libraries could not be found:" ) ); dialog.ListSet( libraries_not_found ); libraries_not_found.empty(); dialog.ShowModal(); } - // reorder the linked list to match the order filename list: - int NumOfLibs = 0; + /* Put the libraries in the correct order. */ + CMP_LIBRARY::SetSortOrder( m_ComponentLibFiles ); + CMP_LIBRARY::GetLibraryList().sort(); - for( lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext ) - { - lib->m_Flags = 0; - NumOfLibs++; - } +#ifdef __WXDEBUG__ + wxLogDebug( wxT( "Component library sort order:" ) ); - if( NumOfLibs == 0 ) - return; - - LibraryStruct** libs = - (LibraryStruct**) MyZMalloc( sizeof(LibraryStruct*) * (NumOfLibs + 2) ); - - int jj = 0; - - for( ii = 0; ii < frame->m_ComponentLibFiles.GetCount(); ii++ ) - { - if( jj >= NumOfLibs ) - break; - fn = frame->m_ComponentLibFiles[ii]; - lib = FindLibrary( fn.GetName() ); - if( lib ) - { - lib->m_Flags = 1; - libs[jj++] = lib; - } - } - - /* Put lib cache at end of list */ - for( lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext ) - { - if( lib->m_Flags == 0 ) - libs[jj++] = lib; - } - - libs[jj] = NULL; - - /* Change the linked list pointers */ - for( ii = 0; libs[ii] != NULL; ii++ ) - libs[ii]->m_Pnext = libs[ii + 1]; - - g_LibraryList = libs[0]; - - MyFree( libs ); - - for( lib = g_LibraryList; lib != NULL; lib = lib->m_Pnext ) - lib->m_Flags = 0; -} - - -/** - * Function FreeCmpLibrary - * - * Routine to remove and free a library from the current loaded libraries. - */ -void FreeCmpLibrary( wxWindow* frame, const wxString& LibName ) -{ - int NumOfLibs = NumOfLibraries(); - LibraryStruct* Lib, * TempLib; - - if( NumOfLibs == 0 ) - { - DisplayError( frame, wxT( "No libraries are loaded" ), 20 ); - return; - } - - /* Search for this library name: */ - for( Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) - { - if( LibName == Lib->m_Name ) - break; - } - - if( Lib == NULL ) - return; - - if( Lib == g_LibraryList ) - g_LibraryList = Lib->m_Pnext; - else - { - for( TempLib = g_LibraryList; TempLib->m_Pnext != Lib; - TempLib = TempLib->m_Pnext ) - ; - - TempLib->m_Pnext = TempLib->m_Pnext->m_Pnext; - } - - SAFE_DELETE( Lib ); - - /* The removed librairy can be the current library in libedit. - * If so, clear the current library in libedit */ - if( Lib == CurrentLib ) - CurrentLib = NULL; -} - - -/** - * Function LibraryEntryCompare - * - * Routine to compare two EDA_LibComponentStruct for the PriorQue module. - * Comparison (insensitive case) is based on Part name. - */ -int LibraryEntryCompare( EDA_LibComponentStruct* LE1, - EDA_LibComponentStruct* LE2 ) -{ - return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text ); -} - - -/***************************************************************************** - * Routine to find the library given its name. - *****************************************************************************/ -LibraryStruct* FindLibrary( const wxString& Name ) -{ - LibraryStruct* Lib = g_LibraryList; - - while( Lib ) - { - if( *Lib == Name ) - return Lib; - Lib = Lib->m_Pnext; - } - - return NULL; -} - - -/***************************************************************************** - * Routine to find the number of libraries currently loaded. - *****************************************************************************/ -int NumOfLibraries() -{ - int ii; - LibraryStruct* Lib = g_LibraryList; - - for( ii = 0; Lib != NULL; Lib = Lib->m_Pnext ) - ii++; - - return ii; + for ( i = CMP_LIBRARY::GetLibraryList().begin(); + i < CMP_LIBRARY::GetLibraryList().end(); i++ ) + wxLogDebug( wxT( " " ) + i->GetName() ); +#endif } diff --git a/eeschema/eeredraw.cpp b/eeschema/eeredraw.cpp index 13c7d00bf6..f75d49bd5f 100644 --- a/eeschema/eeredraw.cpp +++ b/eeschema/eeredraw.cpp @@ -256,14 +256,15 @@ void DrawStructsInGhost( WinEDA_DrawPanel * aPanel, wxDC * aDC, SCH_ITEM * aItem case TYPE_SCH_COMPONENT: { - EDA_LibComponentStruct* LibEntry; - SCH_COMPONENT* Struct; + LIB_COMPONENT* LibEntry; + SCH_COMPONENT* Struct; Struct = (SCH_COMPONENT*) aItem; - LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Struct->m_ChipName ); + LibEntry = CMP_LIBRARY::FindLibraryComponent( Struct->m_ChipName ); if( LibEntry == NULL ) break; - DrawingLibInGhost( aPanel, aDC, LibEntry, Struct, Struct->m_Pos.x + aOffset.x, + DrawingLibInGhost( aPanel, aDC, LibEntry, Struct, + Struct->m_Pos.x + aOffset.x, Struct->m_Pos.y + aOffset.y, Struct->m_Multi, Struct->m_Convert, g_GhostColor, FALSE ); break; diff --git a/eeschema/eeschema.cpp b/eeschema/eeschema.cpp index 805b1a26a8..1b34d0d9f8 100644 --- a/eeschema/eeschema.cpp +++ b/eeschema/eeschema.cpp @@ -21,8 +21,6 @@ // Global variables -LibraryStruct* g_LibraryList; // All part libs are saved here. - int g_OptNetListUseNames; /* TRUE pour utiliser les noms de net plutot que * les numeros (netlist PSPICE seulement) */ SCH_ITEM* g_ItemToRepeat; /* pointeur sur la derniere structure @@ -103,8 +101,8 @@ int g_InvisibleItemColor = DARKGRAY; LibEDA_BaseStruct* LibItemToRepeat = NULL; /* pointer on a graphic item than * can be duplicated by the Ins key * (usually the last created item */ -LibraryStruct* CurrentLib = NULL; /* Current opened library */ -EDA_LibComponentStruct* CurrentLibEntry = NULL; /* Current component */ +CMP_LIBRARY* CurrentLib = NULL; /* Current opened library */ +LIB_COMPONENT* CurrentLibEntry = NULL; /* Current component */ LibEDA_BaseStruct* CurrentDrawItem = NULL; /* current edited item */ // Current selected alias (for components which have aliases) @@ -115,9 +113,6 @@ bool g_AsDeMorgan; int CurrentUnit = 1; int CurrentConvert = 1; -/* Library (name) containing the last component find by FindLibPart() */ -wxString FindLibName; - int DefaultTransformMatrix[2][2] = { { 1, 0 }, { 0, -1 } }; diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index da991fa019..a31b1e995d 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -1,5 +1,5 @@ /****************************/ -/* EESCHEMA - files-io.cpp */ +/* EESCHEMA - files-io.cpp */ /****************************/ #include "fctsys.h" @@ -45,19 +45,18 @@ void WinEDA_SchematicFrame::Save_File( wxCommandEvent& event ) } -/************************************************************************************/ +/* + * Load an entire project + * + * Schematic root file and its subhierarchies, the configuration and the libs + * which are not already loaded) + */ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, bool IsNew ) -/************************************************************************************/ { - /* - * Load an entire project - * ( schematic root file and its subhierarchies, the configuration and the libs - * which are not already loaded) - */ SCH_SCREEN* screen; wxString FullFileName, msg; - bool LibCacheExist = FALSE; + bool LibCacheExist = false; EDA_ScreenList ScreenList; @@ -133,13 +132,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, LoadProjectFile( wxEmptyString, FALSE ); // Delete old caches. - LibraryStruct* nextlib, * lib = g_LibraryList; - for( ; lib != NULL; lib = nextlib ) - { - nextlib = lib->m_Pnext; - if( lib->m_IsLibCache ) - FreeCmpLibrary( this, lib->m_Name ); - } + CMP_LIBRARY::RemoveCacheLibrary(); if( IsNew ) { @@ -164,29 +157,44 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, fn.SetExt( wxT( "cache.lib" ) ); use_oldcachename = true; } + if( fn.FileExists() ) { + wxString errMsg; + wxLogDebug( wxT( "Load schematic cache library file <%s>" ), fn.GetFullPath().c_str() ); msg = wxT( "Load " ) + fn.GetFullPath(); - LibraryStruct* LibCache = LoadLibraryName( this, fn.GetFullPath(), - fn.GetName() ); + + CMP_LIBRARY* LibCache = CMP_LIBRARY::LoadLibrary( fn, errMsg ); + if( LibCache ) { - LibCache->m_IsLibCache = TRUE; + LibCache->SetCache(); msg += wxT( " OK" ); if ( use_oldcachename ) // set the new name { fn.SetName(cachename); fn.SetExt( CompLibFileExtension ); - LibCache->m_Name = fn.GetName(); - LibCache->m_FullFileName = fn.GetFullPath(); + LibCache->SetFileName( fn ); } + + LibCacheExist = true; + CMP_LIBRARY::GetLibraryList().push_back( LibCache ); } else + { + wxString prompt; + + prompt.Printf( _( "Component library <%s> failed to load.\n\n\ +Error: %s" ), + ( const wxChar* ) fn.GetFullPath(), + ( const wxChar* ) errMsg ); + DisplayError( this, prompt ); msg += wxT( " ->Error" ); + } + PrintMsg( msg ); - LibCacheExist = TRUE; } if( !wxFileExists( g_RootSheet->m_AssociatedScreen->m_FileName ) @@ -194,7 +202,7 @@ int WinEDA_SchematicFrame::LoadOneEEProject( const wxString& FileName, { Zoom_Automatique( FALSE ); msg.Printf( _( "File <%s> not found." ), - g_RootSheet->m_AssociatedScreen->m_FileName.GetData() ); + g_RootSheet->m_AssociatedScreen->m_FileName.GetData() ); DisplayInfoMessage( this, msg, 0 ); return -1; } diff --git a/eeschema/find.cpp b/eeschema/find.cpp index eb06605698..e01c26903a 100644 --- a/eeschema/find.cpp +++ b/eeschema/find.cpp @@ -8,18 +8,21 @@ * in current sheet or whole the project */ #include "fctsys.h" - -//#include "gr_basic.h" #include "appl_wxstruct.h" #include "common.h" #include "class_drawpanel.h" #include "confirm.h" #include "kicad_string.h" #include "gestfich.h" + #include "program.h" #include "libcmp.h" #include "general.h" #include "class_marker_sch.h" +#include "protos.h" + +#include + /* Variables Locales */ static int s_ItemsCount, s_MarkerCount; @@ -28,9 +31,6 @@ static wxString s_OldStringFound; #include "dialog_find.cpp" -#include "protos.h" - - /**************************************************************/ void WinEDA_FindFrame::FindMarker( wxCommandEvent& event ) /**************************************************************/ @@ -645,25 +645,25 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) s_OldStringFound = Text; - if( NumOfLibraries() == 0 ) + if( CMP_LIBRARY::GetLibraryCount() == 0 ) { - DisplayError( this, _( "No libraries are loaded" ) ); + DisplayError( this, _( "No component libraries are loaded." ) ); Close(); return; } int nbitemsFound = 0; - for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) + BOOST_FOREACH( CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() ) { - Lib->SearchEntryNames( nameList, Text ); + lib.SearchEntryNames( nameList, Text ); if( nameList.IsEmpty() ) continue; nbitemsFound += nameList.GetCount(); - if( !Lib->m_IsLibCache ) + if( !lib.IsCache() ) FoundInLib = true; for( size_t i = 0; i < nameList.GetCount(); i++ ) @@ -671,7 +671,7 @@ void WinEDA_FindFrame::LocatePartInLibs( wxCommandEvent& event ) if( !FindList.IsEmpty() ) FindList += wxT( "\n" ); FindList << _( "Found " ) + nameList[i] + _( " in library " ) - + Lib->m_Name; + + lib.GetName(); } } diff --git a/eeschema/general.h b/eeschema/general.h index 46ea0c7e75..f4998ec30f 100644 --- a/eeschema/general.h +++ b/eeschema/general.h @@ -94,8 +94,6 @@ typedef enum { /* variables generales */ -extern LibraryStruct* g_LibraryList; // All part libs are saved here. - extern int g_OptNetListUseNames; /* TRUE pour utiliser les noms de net plutot que * les numeros (netlist PSPICE seulement) */ extern SCH_ITEM* g_ItemToRepeat; /* pointeur sur la derniere structure diff --git a/eeschema/getpart.cpp b/eeschema/getpart.cpp index 855b60e957..63271b2700 100644 --- a/eeschema/getpart.cpp +++ b/eeschema/getpart.cpp @@ -8,11 +8,15 @@ #include "common.h" #include "class_drawpanel.h" #include "confirm.h" + #include "get_component_dialog.h" #include "program.h" #include "libcmp.h" #include "general.h" #include "protos.h" +#include "class_library.h" + +#include /* Routines Locales */ @@ -65,36 +69,28 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, wxArrayString& HistoryList, bool UseLibBrowser ) { - int ii, CmpCount = 0; - EDA_LibComponentStruct* Entry = NULL; - SCH_COMPONENT* Component = NULL; - LibraryStruct* Library = NULL; - wxString Name, keys, msg; - bool AllowWildSeach = TRUE; + int ii, CmpCount = 0; + LIB_COMPONENT* Entry = NULL; + SCH_COMPONENT* Component = NULL; + CMP_LIBRARY* Library = NULL; + wxString Name, keys, msg; + bool AllowWildSeach = TRUE; g_ItemToRepeat = NULL; DrawPanel->m_IgnoreMouseEvents = TRUE; if( !libname.IsEmpty() ) { - Library = g_LibraryList; - while( Library ) - { - if( Library->GetName().CmpNoCase( libname ) == 0 ) - { - CmpCount = Library->GetCount(); - break; - } - Library = Library->m_Pnext; - } + Library = CMP_LIBRARY::FindLibrary( libname ); + + if( Library != NULL ) + CmpCount = Library->GetCount(); } else { - LibraryStruct* lib = g_LibraryList; - while( lib ) + BOOST_FOREACH( CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() ) { - CmpCount += lib->GetCount(); - lib = lib->m_Pnext; + CmpCount += lib.GetCount(); } } @@ -145,7 +141,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, } } - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Name, libname ); + Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname ); if( (Entry == NULL) && AllowWildSeach ) /* Attemp to search with wildcard */ { @@ -155,7 +151,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC, Name = DataBaseGetName( this, keys, Name ); if( !Name.IsEmpty() ) - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Name, libname ); + Entry = CMP_LIBRARY::FindLibraryComponent( Name, libname ); if( Entry == NULL ) { @@ -347,12 +343,12 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent, int unit, wxDC* DC ) { int m_UnitCount; - EDA_LibComponentStruct* LibEntry; + LIB_COMPONENT* LibEntry; if( DrawComponent == NULL ) return; - LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( DrawComponent->m_ChipName ); + LibEntry = CMP_LIBRARY::FindLibraryComponent( DrawComponent->m_ChipName ); if( LibEntry == NULL ) return; @@ -395,12 +391,12 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent, wxDC* DC ) { int ii; - EDA_LibComponentStruct* LibEntry; + LIB_COMPONENT* LibEntry; if( DrawComponent == NULL ) return; - LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( DrawComponent->m_ChipName ); + LibEntry = CMP_LIBRARY::FindLibraryComponent( DrawComponent->m_ChipName ); if( LibEntry == NULL ) return; @@ -441,7 +437,7 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent, * Si il y a une representation type "convert", * la valeur retournee est > 1 (typiquement 2) */ -int LookForConvertPart( EDA_LibComponentStruct* LibEntry ) +int LookForConvertPart( LIB_COMPONENT* LibEntry ) { int ii; LibEDA_BaseStruct* DrawLibEntry; diff --git a/eeschema/lib_export.cpp b/eeschema/lib_export.cpp index 3acfb8ae46..e3ed94f9dc 100644 --- a/eeschema/lib_export.cpp +++ b/eeschema/lib_export.cpp @@ -13,15 +13,13 @@ #include "class_drawpanel.h" #include "confirm.h" #include "gestfich.h" +#include "id.h" #include "program.h" #include "libcmp.h" #include "general.h" - #include "protos.h" -#include "id.h" - #include @@ -37,10 +35,10 @@ extern int ExportPartId; /*************************************************/ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event ) { + wxString errMsg; wxFileName fn; - LibraryStruct* LibTmp; - LibCmpEntry* LibEntry; - bool entryLoaded = false; + CMP_LIBRARY* LibTmp; + CMP_LIB_ENTRY* LibEntry; LibItemToRepeat = NULL; @@ -51,33 +49,35 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event ) if( dlg.ShowModal() == wxID_CANCEL ) return; - LibTmp = g_LibraryList; - g_LibraryList = NULL; + fn = dlg.GetPath(); - LoadLibraryName( this, dlg.GetPath(), wxT( "$tmplib$" ) ); + LibTmp = CMP_LIBRARY::LoadLibrary( fn, errMsg ); - if( g_LibraryList ) + if( LibTmp == NULL ) + return; + + LibEntry = LibTmp->GetFirstEntry(); + + if( LibEntry == NULL ) { - LibEntry = g_LibraryList->GetFirstEntry(); + wxString msg; - if( LibEntry ) - entryLoaded = LoadOneLibraryPartAux( LibEntry, g_LibraryList ); - FreeCmpLibrary( this, g_LibraryList->m_Name ); - - if( entryLoaded ) - { - fn = dlg.GetPath(); - m_LastLibImportPath = fn.GetPath(); - ReCreateHToolbar(); - DisplayLibInfos(); - GetScreen()->ClearUndoRedoList(); - DrawPanel->Refresh(); - } - else - DisplayError( this, _( "File is empty" ) ); + msg.Printf( _( "Component library file <%s> is empty." ), + (const wxChar*) fn.GetFullPath() ); + DisplayError( this, msg ); + return; } - g_LibraryList = LibTmp; + if( LoadOneLibraryPartAux( LibEntry, LibTmp ) ) + { + fn = dlg.GetPath(); + m_LastLibImportPath = fn.GetPath(); + DisplayLibInfos(); + GetScreen()->ClearUndoRedoList(); + DrawPanel->Refresh(); + } + + delete LibTmp; } @@ -90,18 +90,18 @@ void WinEDA_LibeditFrame::OnImportPart( wxCommandEvent& event ) */ void WinEDA_LibeditFrame::OnExportPart( wxCommandEvent& event ) { - wxFileName fn; - wxString Name, mask, title; - LibraryStruct* NewLib, * LibTmp, * CurLibTmp; - bool createLib = ( event.GetId() == ExportPartId ) ? false : true; + wxFileName fn; + wxString msg, title; + CMP_LIBRARY* CurLibTmp; + bool createLib = ( event.GetId() != ExportPartId ) ? false : true; if( CurrentLibEntry == NULL ) { - DisplayError( this, _( "No Part to Save" ), 10 ); + DisplayError( this, _( "There is no component selected to save." ) ); return; } - fn = CurrentLibEntry->m_Name.m_Text.Lower(); + fn = CurrentLibEntry->GetName().Lower(); fn.SetExt( CompLibFileExtension ); title = createLib ? _( "New Library" ) : _( "Export Component" ); @@ -114,38 +114,26 @@ void WinEDA_LibeditFrame::OnExportPart( wxCommandEvent& event ) fn = dlg.GetPath(); - /* Creation d'une librairie standard pour sauvegarde */ - - LibTmp = g_LibraryList; CurLibTmp = CurrentLib; - NewLib = new LibraryStruct( LIBRARY_TYPE_EESCHEMA, wxT( "$libTmp$" ), - fn.GetFullName() ); + CurrentLib = new CMP_LIBRARY( LIBRARY_TYPE_EESCHEMA, fn ); - g_LibraryList = NewLib; - - /* Sauvegarde du composant: */ - CurrentLib = NewLib; SaveOnePartInMemory(); - bool success = NewLib->Save( fn.GetFullPath() ); + + bool success = CurrentLib->Save( fn.GetFullPath() ); if( success ) - { m_LastLibExportPath = fn.GetPath(); - } - /* Suppression de la librarie temporaire */ - FreeCmpLibrary( this, NewLib->m_Name ); - g_LibraryList = LibTmp; - CurrentLib = CurLibTmp; + delete CurrentLib; + CurrentLib = CurLibTmp; - wxString msg; if( createLib && success ) { msg = fn.GetFullPath() + _( " - OK" ); - DisplayInfoMessage( this, - _( "Note: this new library will be available only \ -if it is loaded by eeschema.\nModify eeschema config if you want use it." ) ); + DisplayInfoMessage( this, _( "This library will not be available \ +until it is loaded by EESchema.\nModify the EESchema library configuration \ +if you want to include it as part of this project." ) ); } else msg = _( "Error creating " ) + fn.GetFullName(); diff --git a/eeschema/libarch.cpp b/eeschema/libarch.cpp index 7f5da48751..adb94ce514 100644 --- a/eeschema/libarch.cpp +++ b/eeschema/libarch.cpp @@ -2,123 +2,61 @@ /* libarch.cc */ /* Module de generation du fichier d'archivage des composants */ /**************************************************************/ -#include // to use sort vector -#include - #include "fctsys.h" #include "common.h" #include "confirm.h" -#include "kicad_string.h" -#include "gestfich.h" + #include "program.h" #include "libcmp.h" #include "general.h" #include "netlist.h" - #include "protos.h" -/* Local functions*/ -static bool SortCmpByName( const EDA_LibComponentStruct* Objet1, - const EDA_LibComponentStruct* Objet2 ); - - -/*******************************************************************/ -bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ) -/*******************************************************************/ /* - * Creates a library that contains all components used in the whole hierarchy + * Creates a library that contains all components used in the schematic. + * * return true if success */ +bool LibArchive( wxWindow* frame, const wxString& ArchFullFileName ) { - wxFileName docFileName; - wxString msg; - char Line[256]; - FILE* ArchiveFile, * DocFile; - EDA_LibComponentStruct* Entry; - - std::vector ListEntry; + wxString msg; + LIB_COMPONENT* Entry; + CMP_LIBRARY* libCache; EDA_ScreenList ScreenList; - /* examine all screens (not scheets) used and build the list of components found in lib - * complex hierarchies are not a problem because we just want to know used components in libraries + libCache = new CMP_LIBRARY( LIBRARY_TYPE_EESCHEMA, ArchFullFileName ); + libCache->SetCache(); + + /* examine all screens (not scheets) used and build the list of components + * found in lib complex hierarchies are not a problem because we just want + * to know used components in libraries */ - for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen != NULL; screen = ScreenList.GetNext() ) + for( SCH_SCREEN* screen = ScreenList.GetFirst(); screen != NULL; + screen = ScreenList.GetNext() ) { - for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; SchItem = SchItem->Next() ) + for( SCH_ITEM* SchItem = screen->EEDrawList; SchItem; + SchItem = SchItem->Next() ) { if( SchItem->Type() != TYPE_SCH_COMPONENT ) continue; - SCH_COMPONENT* DrawLibItem = (SCH_COMPONENT*) SchItem; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName ); + SCH_COMPONENT* component = (SCH_COMPONENT*) SchItem; + Entry = CMP_LIBRARY::FindLibraryComponent( component->m_ChipName ); if( Entry ) // if NULL : component not found - ListEntry.push_back( Entry ); + libCache->AddComponent( Entry ); } } - // Sort components (libraries entries) by name - // (they are components name in library, not in schematic) : - sort( ListEntry.begin(), ListEntry.end(), SortCmpByName ); - - /* calculate the file name for the associated doc file */ - docFileName = ArchFullFileName; - docFileName.SetExt( DOC_EXT ); - - if( ( ArchiveFile = wxFopen( ArchFullFileName, wxT( "wt" ) ) ) == NULL ) + if( !libCache->Save( ArchFullFileName ) ) { - msg = _( "Failed to create archive lib file " ) + ArchFullFileName; + msg.Printf( _( "An error occurrred attempting to save component \ +library <%s>." ), (const wxChar*) ArchFullFileName ); DisplayError( frame, msg ); - return FALSE; + return false; } - if( ( DocFile = wxFopen( docFileName.GetFullPath(), wxT( "wt" ) ) ) == NULL ) - { - msg = _( "Failed to create doc lib file " ) + docFileName.GetFullPath(); - DisplayError( frame, msg ); - } - - fprintf( ArchiveFile, "%s %s\n#\n", LIBFILE_IDENT, DateAndTime( Line ) ); - if( DocFile ) - fprintf( DocFile, "%s %s\n", DOCFILE_IDENT, DateAndTime( Line ) ); - - /* Save components in file */ - for( unsigned ii = 0; ii < ListEntry.size(); ii++ ) - { - if( (ii == 0) || ( ListEntry[ii - 1] != ListEntry[ii] ) ) - { - if( ListEntry[ii]->Type == ROOT ) // Must be always true, but just in case - ListEntry[ii]->Save( ArchiveFile ); - if( DocFile ) - ListEntry[ii]->SaveDoc( DocFile ); - } - } - - fprintf( ArchiveFile, "#\n#EndLibrary\n" ); - fclose( ArchiveFile ); - - if( DocFile ) - { - fprintf( DocFile, "#\n#End Doc Library\n" ); - fclose( DocFile ); - } - - return TRUE; -} - - -/***********************************************************************************************/ -bool SortCmpByName( const EDA_LibComponentStruct* Objet1, const EDA_LibComponentStruct* Objet2 ) -/***********************************************************************************************/ - -/* Compare function for sort() - * lib components are sorted by name - */ -{ - int ii; - - ii = Objet1->m_Name.m_Text.CmpNoCase( Objet2->m_Name.m_Text ); - return ii < 0; + return true; } diff --git a/eeschema/libcmp.h b/eeschema/libcmp.h index 2e91a8a08b..5759b0d4f2 100644 --- a/eeschema/libcmp.h +++ b/eeschema/libcmp.h @@ -8,19 +8,33 @@ #define LIB_VERSION_MAJOR 2 #define LIB_VERSION_MINOR 3 -#define LIBFILE_IDENT "EESchema-LIBRARY Version" /* Must be the first line of lib files. */ -#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0" /* Must be the first line of doc files. */ -#define DOC_EXT wxT( "dcm" ) /* Ext. of documentation files */ + +/* Must be the first line of component library (.lib) files. */ +#define LIBFILE_IDENT "EESchema-LIBRARY Version" + +#define LIB_VERSION( major, minor ) ( major * 100 + minor ) + +#define IS_LIB_CURRENT_VERSION( major, minor ) \ + ( \ + LIB_VERSION( major1, minor1 ) == \ + LIB_VERSION( LIB_VERSION_MAJOR, LIB_VERSION_MINOR) \ + ) + +/* Must be the first line of component library document (.dcm) files. */ +#define DOCFILE_IDENT "EESchema-DOCLIB Version 2.0" + +#define DOC_EXT wxT( "dcm" ) -enum LocateDrawStructType { - LOCATE_COMPONENT_ARC_DRAW_TYPE = 1, - LOCATE_COMPONENT_CIRCLE_DRAW_TYPE = 2, +enum LocateDrawStructType +{ + LOCATE_COMPONENT_ARC_DRAW_TYPE = 1, + LOCATE_COMPONENT_CIRCLE_DRAW_TYPE = 2, LOCATE_COMPONENT_GRAPHIC_TEXT_DRAW_TYPE = 4, - LOCATE_COMPONENT_RECT_DRAW_TYPE = 8, - LOCATE_LINE_DRAW_TYPE = 0x10, - LOCATE_COMPONENT_POLYLINE_DRAW_TYPE = 0x20, - LOCATE_COMPONENT_LINE_DRAW_TYPE = 0x40 + LOCATE_COMPONENT_RECT_DRAW_TYPE = 8, + LOCATE_LINE_DRAW_TYPE = 0x10, + LOCATE_COMPONENT_POLYLINE_DRAW_TYPE = 0x20, + LOCATE_COMPONENT_LINE_DRAW_TYPE = 0x40 }; #define LOCATE_ALL_DRAW_ITEM 0xFFFFFFFF @@ -29,21 +43,17 @@ enum LocateDrawStructType { #include "class_library.h" -/* Variables */ -extern LibraryStruct* LibraryList; /* All part libs are saved here. */ - /* Variables used by LibEdit */ -extern LibEDA_BaseStruct* LibItemToRepeat; /* pointer on a graphic item than can be duplicated by the Ins key - * (usually the last created item */ -extern LibraryStruct* CurrentLib; /* Current opened library */ -extern EDA_LibComponentStruct* CurrentLibEntry; /* Current component */ -extern LibEDA_BaseStruct* CurrentDrawItem; /* current edited item */ +extern LibEDA_BaseStruct* LibItemToRepeat; /* pointer on a graphic item than + * can be duplicated by the Ins key + * (usually the last created item */ +extern CMP_LIBRARY* CurrentLib; /* Current opened library */ +extern LIB_COMPONENT* CurrentLibEntry; /* Current component */ +extern LibEDA_BaseStruct* CurrentDrawItem; /* current edited item */ extern wxString CurrentAliasName; extern bool g_AsDeMorgan; extern int CurrentUnit; extern int CurrentConvert; -extern wxString FindLibName; - #endif // LIBCMP_H diff --git a/eeschema/libedit.cpp b/eeschema/libedit.cpp index c2d3904ab2..690a89ec55 100644 --- a/eeschema/libedit.cpp +++ b/eeschema/libedit.cpp @@ -28,42 +28,18 @@ void WinEDA_LibeditFrame::DisplayLibInfos() wxString msg = _( "Component Library Editor: " ); if( CurrentLib ) - msg += CurrentLib->m_FullFileName; + msg += CurrentLib->GetFullFileName(); else msg += _( "no library selected" ); SetTitle( msg ); - - msg = _( " Part: " ); - if( CurrentLibEntry == NULL ) - { - msg += _( "None" ); - } - else - { - msg += CurrentLibEntry->GetName(); - if( !CurrentAliasName.IsEmpty() ) - msg << _( " Alias " ) << CurrentAliasName; - } - static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); - msg << _( " Unit " ) << UnitLetter[CurrentUnit]; - - if( CurrentConvert > 1 ) - msg += _( " Convert" ); - else - msg += _( " Normal" ); - - if( CurrentLibEntry && ( CurrentLibEntry->m_Options == ENTRY_POWER ) ) - msg += _( " (Power Symbol)" ); - - SetStatusText( msg, 0 ); } /* Function to select the current library (working library) */ void WinEDA_LibeditFrame::SelectActiveLibrary() { - LibraryStruct* Lib; + CMP_LIBRARY* Lib; Lib = SelectLibraryFromList( this ); if( Lib ) @@ -83,10 +59,10 @@ void WinEDA_LibeditFrame::SelectActiveLibrary() */ bool WinEDA_LibeditFrame::LoadOneLibraryPart() { - int i; - wxString msg; - wxString CmpName; - LibCmpEntry* LibEntry = NULL; + int i; + wxString msg; + wxString CmpName; + CMP_LIB_ENTRY* LibEntry = NULL; if( g_ScreenLib->IsModify() ) { @@ -122,7 +98,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart() msg.Printf( _( "Component or alias name \"%s\" not found in \ library \"%s\"." ), (const wxChar*) CmpName, - (const wxChar*) CurrentLib->m_Name ); + (const wxChar*) CurrentLib->GetName() ); DisplayError( this, msg ); return false; } @@ -145,11 +121,11 @@ library \"%s\"." ), * 1 si err * CurrentLibEntry pointe la copie ainsi creee */ -bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( LibCmpEntry* LibEntry, - LibraryStruct* Library ) +bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, + CMP_LIBRARY* Library ) { wxString msg, cmpName, rootName; - EDA_LibComponentStruct* component; + LIB_COMPONENT* component; if( ( LibEntry == NULL ) || ( Library == NULL ) ) return false; @@ -166,29 +142,20 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( LibCmpEntry* LibEntry, if( LibEntry->Type != ROOT ) { - rootName = ( (EDA_LibCmpAliasStruct*) LibEntry )->m_RootName; - wxASSERT( !rootName.IsEmpty() ); + LIB_ALIAS* alias = (LIB_ALIAS*) LibEntry; + component = alias->GetComponent(); + + wxASSERT( component != NULL && component->Type == ROOT ); + wxLogDebug( wxT( "\"<%s>\" is alias of \"<%s>\"" ), - (const wxChar*) cmpName, (const wxChar*) rootName ); - - component = Library->FindComponent( rootName ); - - if( component == NULL ) - { - msg.Printf( wxT( "Root entry <%s> for alias <%s> not found in \ -library <%s>." ), - (const wxChar*) rootName, - (const wxChar*) cmpName, - (const wxChar*) Library->m_Name ); - DisplayError( this, msg ); - return false; - } + (const wxChar*) cmpName, + (const wxChar*) component->GetName() ); CurrentAliasName = cmpName; } else { - component = (EDA_LibComponentStruct*) LibEntry; + component = (LIB_COMPONENT*) LibEntry; } if( CurrentLibEntry ) @@ -200,7 +167,7 @@ library <%s>." ), { msg.Printf( _( "Could not create copy of part <%s> in library <%s>." ), (const wxChar*) LibEntry->GetName(), - (const wxChar*) Library->m_Name ); + (const wxChar*) Library->GetName() ); DisplayError( this, msg ); return false; } @@ -220,7 +187,7 @@ library <%s>." ), /* Display the document information based on the entry selected just in * case the entry is an alias. */ - DisplayCmpDoc( LibEntry->GetName() ); + DisplayCmpDoc(); return true; } @@ -275,8 +242,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) wxFileName fn; wxString msg; - DrawPanel->UnManageCursor(); - SetToolID( 0, wxCURSOR_ARROW, wxEmptyString ); + DrawPanel->UnManageCursor( 0, wxCURSOR_ARROW ); if( GetScreen()->IsModify() ) { @@ -290,7 +256,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) return; } - fn = wxFileName( CurrentLib->m_FullFileName ); + fn = wxFileName( CurrentLib->GetFullFileName() ); msg = _( "Modify library file \"" ) + fn.GetFullPath() + _( "\"?" ); @@ -305,7 +271,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) { msg = _( "Error while saving library file \"" ) + fn.GetFullPath() + _( "\"." ); - Affiche_1_Parametre( this, 1, wxT( " *** ERROR : **" ), msg, BLUE ); + MsgPanel->Affiche_1_Parametre( 1, wxT( "*** ERROR: ***" ), msg, RED ); DisplayError( this, msg ); } else @@ -314,7 +280,7 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) fn.SetExt( DOC_EXT ); wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() + wxT( "\" Ok" ); - Affiche_1_Parametre( this, 1, msg, msg1, BLUE ); + MsgPanel->Affiche_1_Parametre( 1, msg, msg1, BLUE ); } } @@ -323,20 +289,64 @@ void WinEDA_LibeditFrame::SaveActiveLibrary( wxCommandEvent& event ) * Affiche la documentation du composant selectionne * Utilisïe lors de l'affichage de la liste des composants en librairie */ -void WinEDA_LibeditFrame::DisplayCmpDoc( const wxString& Name ) +void WinEDA_LibeditFrame::DisplayCmpDoc() { - LibCmpEntry* CmpEntry; - - if( CurrentLib == NULL ) - return; + wxString msg; + LIB_ALIAS* alias = NULL; MsgPanel->EraseMsgBox(); - CmpEntry = CurrentLib->FindEntry( Name ); - if( CmpEntry == NULL ) + if( CurrentLib == NULL && CurrentLibEntry == NULL ) return; - AfficheDoc( this, CmpEntry->m_Doc, CmpEntry->m_KeyWord ); + msg = CurrentLibEntry->GetName(); + + MsgPanel->AppendMessage( _( "Part" ), msg, BLUE, 8 ); + + if( CurrentAliasName.IsEmpty() ) + { + msg = _( "None" ); + } + else + { + msg = CurrentAliasName; + alias = CurrentLib->FindAlias( CurrentAliasName ); + } + + MsgPanel->AppendMessage( _( "Alias" ), msg, RED, 8 ); + + static wxChar UnitLetter[] = wxT( "?ABCDEFGHIJKLMNOPQRSTUVWXYZ" ); + msg = UnitLetter[CurrentUnit]; + + MsgPanel->AppendMessage( _( "Unit" ), msg, BROWN, 8 ); + + if( CurrentConvert > 1 ) + msg = _( "Convert" ); + else + msg = _( "Normal" ); + + MsgPanel->AppendMessage( _( "Body" ), msg, GREEN, 8 ); + + if( CurrentLibEntry->m_Options == ENTRY_POWER ) + msg = _( "Power Symbol" ); + else + msg = _( "Component" ); + + MsgPanel->AppendMessage( _( "Type" ), msg, MAGENTA, 8 ); + + if( alias != NULL ) + msg = alias->m_Doc; + else + msg = CurrentLibEntry->m_Doc; + + MsgPanel->AppendMessage( _( "Description" ), msg, CYAN, 8 ); + + if( alias != NULL ) + msg = alias->m_KeyWord; + else + msg = CurrentLibEntry->m_KeyWord; + + MsgPanel->AppendMessage( _( "Key words" ), msg, DARKDARKGRAY ); } @@ -354,10 +364,10 @@ void WinEDA_LibeditFrame::DisplayCmpDoc( const wxString& Name ) */ void WinEDA_LibeditFrame::DeleteOnePart() { - wxString CmpName; - LibCmpEntry* LibEntry; - wxArrayString ListNames; - wxString msg; + wxString CmpName; + CMP_LIB_ENTRY* LibEntry; + wxArrayString ListNames; + wxString msg; CurrentDrawItem = NULL; @@ -377,14 +387,14 @@ void WinEDA_LibeditFrame::DeleteOnePart() if( ListNames.IsEmpty() ) { msg.Printf( _( "Component library <%s> is empty." ), - ( const wxChar* ) CurrentLib->m_Name ); + ( const wxChar* ) CurrentLib->GetName() ); wxMessageBox( msg, _( "Delete Entry Error" ), wxID_OK | wxICON_EXCLAMATION, this ); return; } msg.Printf( _( "Select 1 of %d components to delete\nfrom library <%s>." ), - ListNames.GetCount(), ( const wxChar* ) CurrentLib->m_Name ); + ListNames.GetCount(), ( const wxChar* ) CurrentLib->GetName() ); wxSingleChoiceDialog dlg( this, msg, _( "Delete Component" ), ListNames ); @@ -397,14 +407,14 @@ void WinEDA_LibeditFrame::DeleteOnePart() { msg.Printf( _( "Entry <%s> not found in library <%s>." ), ( const wxChar* ) dlg.GetStringSelection(), - ( const wxChar* ) CurrentLib->m_Name ); + ( const wxChar* ) CurrentLib->GetName() ); DisplayError( this, msg ); return; } msg.Printf( _( "Delete component \"%s\" from library \"%s\"?" ), (const wxChar*) LibEntry->GetName(), - (const wxChar*) CurrentLib->m_Name ); + (const wxChar*) CurrentLib->GetName() ); if( !IsOK( this, msg ) ) return; @@ -427,7 +437,7 @@ All changes will be lost. Discard changes?" ) ) ) return; wxString newCmpName; - LibCmpEntry* nextEntry; + CMP_LIB_ENTRY* nextEntry; /* * If the current component has no aliases, then the next entry @@ -475,12 +485,13 @@ All changes will be lost. Discard changes?" ) ) ) void WinEDA_LibeditFrame::CreateNewLibraryPart() { wxString msg; - EDA_LibComponentStruct* NewStruct; + LIB_COMPONENT* NewStruct; int diag; if( CurrentLibEntry && GetScreen()->IsModify() && !IsOK( this, - _( "Clear old component from screen (changes will be lost)?" ) ) ) + _( "All changes to the current component will be lost!\n\n\ +Clear the current component from the screen?" ) ) ) return; CurrentDrawItem = NULL; @@ -503,13 +514,13 @@ void WinEDA_LibeditFrame::CreateNewLibraryPart() wxString msg; msg.Printf( _( "Component \"%s\" exists in library \"%s\"." ), (const wxChar*) Dialogbox.ReturnCmpName(), - (const wxChar*) CurrentLib->m_Name ); + (const wxChar*) CurrentLib->GetName() ); DisplayError( this, msg ); return; } } - NewStruct = new EDA_LibComponentStruct( msg ); + NewStruct = new LIB_COMPONENT( msg ); Dialogbox.SetComponentData( *NewStruct ); if( NewStruct->m_Prefix.m_Text.IsEmpty() ) NewStruct->m_Prefix.m_Text = wxT( "U" ); @@ -524,7 +535,7 @@ void WinEDA_LibeditFrame::CreateNewLibraryPart() CurrentUnit = 1; CurrentConvert = 1; DisplayLibInfos(); - DisplayCmpDoc( CurrentLibEntry->GetName() ); + DisplayCmpDoc(); } @@ -537,9 +548,9 @@ void WinEDA_LibeditFrame::CreateNewLibraryPart() */ void WinEDA_LibeditFrame::SaveOnePartInMemory() { - EDA_LibComponentStruct* oldComponent; - EDA_LibComponentStruct* Component; - wxString msg; + LIB_COMPONENT* oldComponent; + LIB_COMPONENT* Component; + wxString msg; if( CurrentLibEntry == NULL ) { @@ -581,6 +592,6 @@ void WinEDA_LibeditFrame::SaveOnePartInMemory() msg.Printf( _( "Component %s saved in library %s" ), ( const wxChar* ) Component->GetName(), - ( const wxChar* ) CurrentLib->m_Name ); + ( const wxChar* ) CurrentLib->GetName() ); Affiche_Message( msg ); } diff --git a/eeschema/libedit_onleftclick.cpp b/eeschema/libedit_onleftclick.cpp index a97451c572..22514b1130 100644 --- a/eeschema/libedit_onleftclick.cpp +++ b/eeschema/libedit_onleftclick.cpp @@ -78,12 +78,7 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) DrawEntry->DisplayInfo( this ); else - { - if( CurrentAliasName.IsEmpty() ) - DisplayCmpDoc( CurrentAliasName ); - else - DisplayCmpDoc( CurrentLibEntry->GetName() ); - } + DisplayCmpDoc(); } } @@ -151,13 +146,7 @@ void WinEDA_LibeditFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos ) LOCATE_ALL_DRAW_ITEM ); } if( DrawEntry == NULL ) - { - if( CurrentAliasName.IsEmpty() ) - DisplayCmpDoc( CurrentLibEntry->GetName() ); - else - DisplayCmpDoc( CurrentAliasName ); - break; - } + DisplayCmpDoc(); SaveCopyInUndoList( CurrentLibEntry ); if( DrawEntry->Type() == COMPONENT_PIN_DRAW_TYPE ) DeletePin( DC, CurrentLibEntry, (LibDrawPin*) DrawEntry ); diff --git a/eeschema/libedit_undo_redo.cpp b/eeschema/libedit_undo_redo.cpp index c7de90d0f1..d9a6c243d9 100644 --- a/eeschema/libedit_undo_redo.cpp +++ b/eeschema/libedit_undo_redo.cpp @@ -19,11 +19,11 @@ void WinEDA_LibeditFrame::SaveCopyInUndoList( EDA_BaseStruct* ItemToCopy, int unused_flag ) /*************************************************************************/ { - EDA_BaseStruct* item; - EDA_LibComponentStruct* CopyItem; + EDA_BaseStruct* item; + LIB_COMPONENT* CopyItem; PICKED_ITEMS_LIST* lastcmd; - CopyItem = CopyLibEntryStruct( (EDA_LibComponentStruct*) ItemToCopy ); + CopyItem = CopyLibEntryStruct( (LIB_COMPONENT*) ItemToCopy ); if( CopyItem == NULL ) return; @@ -62,7 +62,7 @@ void WinEDA_LibeditFrame::GetComponentFromRedoList(wxCommandEvent& event) lastcmd = GetScreen()->PopCommandFromRedoList( ); wrapper = lastcmd->PopItem(); - CurrentLibEntry = (EDA_LibComponentStruct*) wrapper.m_PickedItem; + CurrentLibEntry = (LIB_COMPONENT*) wrapper.m_PickedItem; if( CurrentLibEntry ) CurrentLibEntry->SetNext( NULL ); CurrentDrawItem = NULL; @@ -92,7 +92,7 @@ void WinEDA_LibeditFrame::GetComponentFromUndoList(wxCommandEvent& event) lastcmd = GetScreen()->PopCommandFromUndoList( ); wrapper = lastcmd->PopItem(); - CurrentLibEntry = (EDA_LibComponentStruct*) wrapper.m_PickedItem; + CurrentLibEntry = (LIB_COMPONENT*) wrapper.m_PickedItem; if( CurrentLibEntry ) CurrentLibEntry->SetNext( NULL ); diff --git a/eeschema/libfield.cpp b/eeschema/libfield.cpp index fed5ba843e..b0c4e3a0d1 100644 --- a/eeschema/libfield.cpp +++ b/eeschema/libfield.cpp @@ -216,7 +216,7 @@ names in the alias list." ), entry in the component library <%s>.\nPlease choose another name that does \ not conflict with any library entries." ), (const wxChar*) Text, - (const wxChar*) CurrentLib->m_Name ); + (const wxChar*) CurrentLib->GetName() ); DisplayError( this, msg ); return; } @@ -294,7 +294,7 @@ void WinEDA_LibeditFrame::RotateField( wxDC* DC, LibDrawField* Field ) * return: * pointer on the field (or NULL ) */ -LibDrawField* WinEDA_LibeditFrame::LocateField( EDA_LibComponentStruct* LibEntry ) +LibDrawField* WinEDA_LibeditFrame::LocateField( LIB_COMPONENT* LibEntry ) { wxPoint refpos = GetScreen()->m_Curseur; /* Test reference */ diff --git a/eeschema/libframe.cpp b/eeschema/libframe.cpp index e0d0e8b39d..f1a3c0f00d 100644 --- a/eeschema/libframe.cpp +++ b/eeschema/libframe.cpp @@ -17,6 +17,9 @@ #include "bitmaps.h" #include "protos.h" #include "id.h" +#include "class_library.h" + +#include /* Library editor wxConfig entry names. */ @@ -147,6 +150,7 @@ WinEDA_LibeditFrame::WinEDA_LibeditFrame( wxWindow* father, ReCreateHToolbar(); ReCreateVToolbar(); DisplayLibInfos(); + DisplayCmpDoc(); UpdateAliasSelectList(); UpdatePartSelectList(); BestZoom(); @@ -204,8 +208,6 @@ void WinEDA_LibeditFrame::SaveSettings() void WinEDA_LibeditFrame::OnCloseWindow( wxCloseEvent& Event ) { - LibraryStruct* Lib; - if( GetScreen()->IsModify() ) { if( !IsOK( this, _( "Component was modified!\nDiscard changes?" ) ) ) @@ -217,13 +219,13 @@ void WinEDA_LibeditFrame::OnCloseWindow( wxCloseEvent& Event ) GetScreen()->ClrModify(); } - for( Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) + BOOST_FOREACH( const CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() ) { - if( Lib->IsModified() ) + if( lib.IsModified() ) { wxString msg; msg.Printf( _( "Library \"%s\" was modified!\nDiscard changes?" ), - Lib->m_Name.GetData() ); + (const wxChar*) lib.GetName() ); if( !IsOK( this, msg ) ) { Event.Veto(); @@ -358,7 +360,8 @@ void WinEDA_LibeditFrame::OnUpdateRedo( wxUpdateUIEvent& event ) void WinEDA_LibeditFrame::OnUpdateSaveCurrentLib( wxUpdateUIEvent& event ) { - event.Enable( CurrentLib != NULL ); + event.Enable( CurrentLib != NULL + && ( CurrentLib->IsModified() || GetScreen()->IsModify() ) ); } @@ -370,7 +373,7 @@ void WinEDA_LibeditFrame::OnUpdateViewDoc( wxUpdateUIEvent& event ) { if( !CurrentAliasName.IsEmpty() ) { - LibCmpEntry* entry = CurrentLib->FindEntry( CurrentAliasName ); + CMP_LIB_ENTRY* entry = CurrentLib->FindEntry( CurrentAliasName ); if( entry != NULL ) enable = !entry->m_DocFile.IsEmpty(); @@ -452,11 +455,9 @@ void WinEDA_LibeditFrame::OnSelectAlias( wxCommandEvent& event ) if( m_SelAliasBox->GetStringSelection().CmpNoCase(CurrentLibEntry->GetName() ) == 0 ) CurrentAliasName.Empty(); else - { CurrentAliasName = m_SelAliasBox->GetStringSelection(); - DisplayCmpDoc( CurrentAliasName ); - } + DisplayCmpDoc(); DrawPanel->Refresh(); } @@ -464,11 +465,14 @@ void WinEDA_LibeditFrame::OnSelectAlias( wxCommandEvent& event ) void WinEDA_LibeditFrame::OnSelectPart( wxCommandEvent& event ) { int i = event.GetSelection(); - if( i < 0 ) + + if( ( i == wxNOT_FOUND ) || ( ( i + 1 ) == CurrentUnit ) ) return; + LibItemToRepeat = NULL; CurrentUnit = i + 1; DrawPanel->Refresh(); + DisplayCmpDoc(); } @@ -585,7 +589,7 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event ) wxString docfilename; if( !CurrentAliasName.IsEmpty() ) { - LibCmpEntry* entry = CurrentLib->FindEntry( CurrentAliasName ); + CMP_LIB_ENTRY* entry = CurrentLib->FindEntry( CurrentAliasName ); if( entry != NULL ) docfilename = entry->m_DocFile; } diff --git a/eeschema/locate.cpp b/eeschema/locate.cpp index 93135788f7..69be8e37b1 100644 --- a/eeschema/locate.cpp +++ b/eeschema/locate.cpp @@ -612,12 +612,12 @@ static bool IsBox1InBox2( int StartX1, int StartY1, int EndX1, int EndY1, /*********************************************************************************/ -LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, - const wxPoint& aRefPoint, - EDA_LibComponentStruct* LibEntry, - int Unit, - int Convert, - int masque ) +LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, + const wxPoint& aRefPoint, + LIB_COMPONENT* LibEntry, + int Unit, + int Convert, + int masque ) /*********************************************************************************/ /* Locates a body item( not pins ) @@ -718,11 +718,11 @@ LibDrawPin* LocatePinByNumber( const wxString& ePin_Number, */ { LibEDA_BaseStruct* DrawItem; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; LibDrawPin* Pin; int Unit, Convert; - Entry = ( EDA_LibComponentStruct* )FindLibPart( eComponent->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( eComponent->m_ChipName ); if( Entry == NULL ) return NULL; @@ -760,8 +760,7 @@ LibDrawPin* LocatePinByNumber( const wxString& ePin_Number, /*******************************************************************/ -LibEDA_BaseStruct* LocatePin( const wxPoint& RefPos, - EDA_LibComponentStruct* Entry, +LibEDA_BaseStruct* LocatePin( const wxPoint& RefPos, LIB_COMPONENT* Entry, int Unit, int convert, SCH_COMPONENT* DrawLibItem ) /*******************************************************************/ @@ -850,7 +849,7 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, /**************************************************************************/ { SCH_ITEM* DrawStruct; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; SCH_COMPONENT* LibItem = NULL; LibDrawPin* Pin = NULL; @@ -859,7 +858,7 @@ LibDrawPin* LocateAnyPin( SCH_ITEM* DrawList, const wxPoint& RefPos, if( DrawStruct->Type() != TYPE_SCH_COMPONENT ) continue; LibItem = (SCH_COMPONENT*) DrawStruct; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( LibItem->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( LibItem->m_ChipName ); if( Entry == NULL ) continue; diff --git a/eeschema/netform.cpp b/eeschema/netform.cpp index 4155856584..fc2e2f29d6 100644 --- a/eeschema/netform.cpp +++ b/eeschema/netform.cpp @@ -28,9 +28,9 @@ static void WriteGENERICListOfNets( FILE* f, NETLIST_OBJECT_LIST& aObjectsList ) static void AddPinToComponentPinList( SCH_COMPONENT* Component, DrawSheetPath* sheet, LibDrawPin* PinEntry ); -static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component, - EDA_LibComponentStruct* Entry, - DrawSheetPath* Sheet_in ); +static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component, + LIB_COMPONENT* Entry, + DrawSheetPath* Sheet_in ); static bool SortPinsByNum( NETLIST_OBJECT* Pin1, NETLIST_OBJECT* Pin2 ); static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList ); @@ -108,9 +108,9 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( * Must be deallocated by the user */ { - SCH_COMPONENT* Component = NULL; - EDA_LibComponentStruct* Entry; - LibEDA_BaseStruct* DEntry; + SCH_COMPONENT* Component = NULL; + LIB_COMPONENT* Entry; + LibEDA_BaseStruct* DEntry; s_SortedComponentPinList.clear(); for( ; DrawList != NULL; DrawList = DrawList->Next() ) @@ -130,7 +130,7 @@ static SCH_COMPONENT* FindNextComponentAndCreatPinList( // removed because with multiple instances of one schematic // (several sheets pointing to 1 screen), this will be erroneously be toggled. - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName ); if( Entry == NULL ) continue; @@ -550,8 +550,8 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with break; /* Get the Component FootprintFilter and put the component in CmpList if filter is not void */ - EDA_LibComponentStruct* Entry = - ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName ); + LIB_COMPONENT* Entry = + CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName ); if( Entry != NULL ) { @@ -628,11 +628,11 @@ static void WriteNetListPCBNEW( WinEDA_SchematicFrame* frame, FILE* f, bool with if( with_pcbnew && CmpList ) { fprintf( f, "{ Allowed footprints by component:\n" ); - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; for( int ii = 0; ii < CmpListCount; ii++ ) { Component = CmpList[ii].m_RootCmp; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( Component->m_ChipName ); //Line.Printf(_("%s"), CmpList[ii].m_Ref); //Line.Replace( wxT( " " ), wxT( "_" ) ); @@ -754,9 +754,9 @@ static void EraseDuplicatePins( NETLIST_OBJECT_LIST& aPinList ) /**********************************************************************************/ -static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in, - EDA_LibComponentStruct* Entry, - DrawSheetPath* Sheet_in ) +static void FindAllsInstancesOfComponent( SCH_COMPONENT* Component_in, + LIB_COMPONENT* Entry, + DrawSheetPath* Sheet_in ) /**********************************************************************************/ /** diff --git a/eeschema/netlist.cpp b/eeschema/netlist.cpp index 39c56041f0..be07f0a0b2 100644 --- a/eeschema/netlist.cpp +++ b/eeschema/netlist.cpp @@ -353,7 +353,7 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, SCH_ITEM* DrawList; NETLIST_OBJECT* new_item; SCH_COMPONENT* DrawLibItem; - EDA_LibComponentStruct* Entry; + LIB_COMPONENT* Entry; LibEDA_BaseStruct* DEntry; Hierarchical_PIN_Sheet_Struct* SheetLabel; DrawSheetPath list; @@ -472,8 +472,8 @@ static void ListeObjetConnection( DrawSheetPath* sheetlist, case TYPE_SCH_COMPONENT: DrawLibItem = (SCH_COMPONENT*) DrawList; - Entry = ( EDA_LibComponentStruct* )FindLibPart( - DrawLibItem->m_ChipName ); + Entry = + CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); if( Entry == NULL ) break; diff --git a/eeschema/netlist.h b/eeschema/netlist.h index 14afa6e803..a5b308bae2 100644 --- a/eeschema/netlist.h +++ b/eeschema/netlist.h @@ -43,11 +43,11 @@ enum TypeNetForm { class OBJ_CMP_TO_LIST { public: - SCH_COMPONENT* m_RootCmp; // the component in schematic - EDA_LibComponentStruct* m_Entry; // the source component in library - int m_Unit; /* Selected part (For multi parts per package) depending on sheet path */ - DrawSheetPath m_SheetPath; /* the sheet path for this component */ - unsigned long m_TimeStamp; /* unique identification number depending on sheet path */ + SCH_COMPONENT* m_RootCmp; // the component in schematic + LIB_COMPONENT* m_Entry; // the source component in library + int m_Unit; /* Selected part (For multi parts per package) depending on sheet path */ + DrawSheetPath m_SheetPath; /* the sheet path for this component */ + unsigned long m_TimeStamp; /* unique identification number depending on sheet path */ bool m_IsNew; /* true for not yet annotated components */ wxString* m_Value; /* Component value (same for all instances) */ char m_Reference[32]; /* Component reference prefix, without number (for IC1, this is IC) ) */ diff --git a/eeschema/onrightclick.cpp b/eeschema/onrightclick.cpp index 0f90397fe7..b6479d066f 100644 --- a/eeschema/onrightclick.cpp +++ b/eeschema/onrightclick.cpp @@ -25,8 +25,10 @@ static void AddMenusForWire( wxMenu* PopMenu, EDA_DrawLineStruct* Wire, WinEDA_SchematicFrame* frame ); static void AddMenusForBus( wxMenu* PopMenu, EDA_DrawLineStruct* Bus, WinEDA_SchematicFrame* frame ); -static void AddMenusForHierchicalSheet( wxMenu* PopMenu, DrawSheetStruct* Sheet ); -static void AddMenusForPinSheet( wxMenu* PopMenu, Hierarchical_PIN_Sheet_Struct* PinSheet ); +static void AddMenusForHierchicalSheet( wxMenu* PopMenu, + DrawSheetStruct* Sheet ); +static void AddMenusForPinSheet( wxMenu* PopMenu, + Hierarchical_PIN_Sheet_Struct* PinSheet ); static void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text ); static void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label ); static void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel ); @@ -36,21 +38,21 @@ static void AddMenusForComponentField( wxMenu* PopMenu, SCH_CMP_FIELD* Field ); static void AddMenusForJunction( wxMenu* PopMenu, DrawJunctionStruct* Junction, WinEDA_SchematicFrame* frame ); static void AddMenusForMarkers( wxMenu* aPopMenu, MARKER_SCH* aMarker, - WinEDA_SchematicFrame* aFrame ); + WinEDA_SchematicFrame* aFrame ); /*****************************************************************/ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ) +{ /*****************************************************************/ - /* Prepare le menu PullUp affich� par un click sur le bouton droit * de la souris. * Ce menu est ensuite compl�t� par la liste des commandes de ZOOM */ -{ SCH_ITEM* DrawStruct = (SCH_ITEM*) GetScreen()->GetCurItem(); - bool BlockActive = (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE); + bool BlockActive = + (GetScreen()->m_BlockLocate.m_Command != BLOCK_IDLE); DrawPanel->m_CanStartBlock = -1; // Ne pas engager un debut de bloc sur validation menu @@ -62,8 +64,8 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, return true; } - if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) ) - { // Just try to locate items at cursor position + if( (DrawStruct == NULL) || (DrawStruct->m_Flags == 0) ) // Just try to locate items at cursor position + { DrawStruct = SchematicGeneralLocateAndDisplay( false ); if( DrawStruct && (DrawStruct->Type() == DRAW_SHEET_STRUCT_TYPE) ) { @@ -80,11 +82,13 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, { if( DrawStruct && DrawStruct->m_Flags ) { - ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, + _( "Cancel" ), cancel_xpm ); } else { - ADD_MENUITEM( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, _( "End Tool" ), cancel_tool_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_CLOSE_CURRENT_TOOL, + _( "End Tool" ), cancel_tool_xpm ); } PopMenu->AppendSeparator(); } @@ -92,7 +96,8 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, { if( DrawStruct && DrawStruct->m_Flags ) { - ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel" ), cancel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, + _( "Cancel" ), cancel_xpm ); PopMenu->AppendSeparator(); } } @@ -101,7 +106,8 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, { if( GetSheet()->Last() != g_RootSheet ) { - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_LEAVE_SHEET, _( "Leave Sheet" ), leave_sheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_LEAVE_SHEET, + _( "Leave Sheet" ), leave_sheet_xpm ); PopMenu->AppendSeparator(); } return true; @@ -117,7 +123,8 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, case DRAW_NOCONNECT_STRUCT_TYPE: // if( !flags ) PopMenu->Append(ID_POPUP_SCH_MOVE_ITEM_REQUEST, "Move Noconnect"); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Noconn" ), delete_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Noconn" ), + delete_xpm ); break; case DRAW_JUNCTION_STRUCT_TYPE: @@ -129,9 +136,11 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Bus Entry" ), move_xpm ); if( GetBusEntryShape( (DrawBusEntryStruct*) DrawStruct ) == '\\' ) - PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_SLASH, _( "Set Bus Entry /" ) ); + PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_SLASH, + _( "Set Bus Entry /" ) ); else - PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH, _( "Set Bus Entry \\" ) ); + PopMenu->Append( ID_POPUP_SCH_ENTRY_SELECT_ANTISLASH, + _( "Set Bus Entry \\" ) ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Bus Entry" ), delete_bus_xpm ); break; @@ -163,20 +172,22 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, break; // Many fields are inside a component. If this is the case, add the component menu - SCH_COMPONENT* Component = LocateSmallestComponent( (SCH_SCREEN*) GetScreen() ); + SCH_COMPONENT* Component = LocateSmallestComponent( + (SCH_SCREEN*) GetScreen() ); if( Component ) { PopMenu->AppendSeparator(); AddMenusForComponent( PopMenu, Component ); } } - break; + break; case TYPE_SCH_COMPONENT: AddMenusForComponent( PopMenu, (SCH_COMPONENT*) DrawStruct ); break; case DRAW_SEGMENT_STRUCT_TYPE: + // if( !flags ) PopMenu->Append(ID_POPUP_SCH_MOVE_ITEM_REQUEST, "Move"); switch( DrawStruct->GetLayer() ) { @@ -190,7 +201,8 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, default: if( is_new ) - ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "End Drawing" ), apply_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_END_LINE, _( "End Drawing" ), + apply_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Drawing" ), delete_xpm ); break; @@ -203,13 +215,14 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, break; case DRAW_HIERARCHICAL_PIN_SHEET_STRUCT_TYPE: - AddMenusForPinSheet( PopMenu, (Hierarchical_PIN_Sheet_Struct*) DrawStruct ); + AddMenusForPinSheet( PopMenu, + (Hierarchical_PIN_Sheet_Struct*) DrawStruct ); break; default: wxString msg; - msg.Printf( - wxT( "WinEDA_SchematicFrame::OnRightClick Error: unknown DrawType %d" ), + msg.Printf( wxT( "WinEDA_SchematicFrame::OnRightClick Error: unknown \ +DrawType %d" ), DrawStruct->Type() ); DisplayError( this, msg ); break; @@ -222,128 +235,155 @@ bool WinEDA_SchematicFrame::OnRightClick( const wxPoint& MousePos, /*************************************************************************/ void AddMenusForComponentField( wxMenu* PopMenu, SCH_CMP_FIELD* Field ) +{ /*************************************************************************/ - /* Add menu commands for a component field (like value, reference) */ -{ if( !Field->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Field" ), move_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_FIELD, _( "Rotate Field" ), rotate_field_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_FIELD, _( "Edit Field" ), edit_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, + _( "Move Field" ), move_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_FIELD, + _( "Rotate Field" ), rotate_field_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_FIELD, + _( "Edit Field" ), edit_text_xpm ); } /**************************************************************************/ void AddMenusForComponent( wxMenu* PopMenu, SCH_COMPONENT* Component ) +{ /**************************************************************************/ - /* Add menu commands for a component */ -{ if( Component->Type() != TYPE_SCH_COMPONENT ) { wxASSERT( 0 ); return; } - wxString msg; + wxString msg; + CMP_LIB_ENTRY* libEntry; + LIB_COMPONENT* libComponent = NULL; - EDA_LibComponentStruct* LibEntry; + libEntry = CMP_LIBRARY::FindLibraryEntry( Component->m_ChipName ); - LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName ); + if( libEntry ) + { + if( libEntry->Type == ALIAS ) + libComponent = ( (LIB_ALIAS*) libEntry )->GetComponent(); + else + libComponent = (LIB_COMPONENT*) libEntry; + } if( !Component->m_Flags ) { msg = _( "Move Component" ); - msg << wxT(" ") << Component->GetField( REFERENCE )->m_Text; + msg << wxT( " " ) << Component->GetField( REFERENCE )->m_Text; msg = AddHotkeyName( msg, s_Schematic_Hokeys_Descr, HK_MOVE_COMPONENT ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_CMP_REQUEST, msg, move_xpm ); - msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr, HK_DRAG_COMPONENT ); + msg = AddHotkeyName( _( "Drag Component" ), s_Schematic_Hokeys_Descr, + HK_DRAG_COMPONENT ); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_CMP_REQUEST, msg, move_xpm ); } // add menu orient et sous menu: wxMenu* orientmenu = new wxMenu; - msg = AddHotkeyName( _( "Rotate +" ), s_Schematic_Hokeys_Descr, HK_ROTATE_COMPONENT ); + msg = AddHotkeyName( _( "Rotate +" ), s_Schematic_Hokeys_Descr, + HK_ROTATE_COMPONENT ); ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_COUNTERCLOCKWISE, msg, rotate_pos_xpm ); - ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE, _( "Rotate -" ), rotate_neg_xpm ); - msg = AddHotkeyName( _( "Mirror --" ), s_Schematic_Hokeys_Descr, HK_MIRROR_X_COMPONENT ); + ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ROTATE_CMP_CLOCKWISE, + _( "Rotate -" ), rotate_neg_xpm ); + msg = AddHotkeyName( _( "Mirror --" ), s_Schematic_Hokeys_Descr, + HK_MIRROR_X_COMPONENT ); ADD_MENUITEM( orientmenu, ID_POPUP_SCH_MIROR_X_CMP, msg, mirror_V_xpm ); - msg = AddHotkeyName( _( "Mirror ||" ), s_Schematic_Hokeys_Descr, HK_MIRROR_Y_COMPONENT ); + msg = AddHotkeyName( _( "Mirror ||" ), s_Schematic_Hokeys_Descr, + HK_MIRROR_Y_COMPONENT ); ADD_MENUITEM( orientmenu, ID_POPUP_SCH_MIROR_Y_CMP, msg, mirror_H_xpm ); - msg = AddHotkeyName( _( "Normal" ), s_Schematic_Hokeys_Descr, HK_ORIENT_NORMAL_COMPONENT ); + msg = AddHotkeyName( _( "Normal" ), s_Schematic_Hokeys_Descr, + HK_ORIENT_NORMAL_COMPONENT ); ADD_MENUITEM( orientmenu, ID_POPUP_SCH_ORIENT_NORMAL_CMP, msg, normal_xpm ); ADD_MENUITEM_WITH_SUBMENU( PopMenu, orientmenu, - ID_POPUP_SCH_GENERIC_ORIENT_CMP, _( - "Orient Component" ), orient_xpm ); + ID_POPUP_SCH_GENERIC_ORIENT_CMP, + _( "Orient Component" ), orient_xpm ); wxMenu* editmenu = new wxMenu; - ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, _( "Edit" ), edit_component_xpm ); + ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CMP, _( "Edit" ), + edit_component_xpm ); - if( LibEntry && LibEntry->m_Options != ENTRY_POWER ) + if( libEntry && libEntry->m_Options != ENTRY_POWER ) { - msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_VALUE ); - ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_VALUE_CMP, msg, edit_comp_value_xpm ); + msg = AddHotkeyName( _( "Value " ), s_Schematic_Hokeys_Descr, + HK_EDIT_COMPONENT_VALUE ); + ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_VALUE_CMP, msg, + edit_comp_value_xpm ); - ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_REF_CMP, _( "Reference" ), edit_comp_ref_xpm ); + ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_REF_CMP, + _( "Reference" ), edit_comp_ref_xpm ); - msg = AddHotkeyName( _( - "Footprint " ), s_Schematic_Hokeys_Descr, + msg = AddHotkeyName( _( "Footprint " ), s_Schematic_Hokeys_Descr, HK_EDIT_COMPONENT_FOOTPRINT ); - ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_FOOTPRINT_CMP, msg, edit_comp_footprint_xpm ); + ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_FOOTPRINT_CMP, msg, + edit_comp_footprint_xpm ); } - if( LibEntry && (LookForConvertPart( LibEntry ) >= 2) ) - ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP,_( "Convert" ), component_select_alternate_shape_xpm ); - if( LibEntry && (LibEntry->m_UnitCount >= 2) ) + if( libComponent && libComponent->HasConversion() ) + ADD_MENUITEM( editmenu, ID_POPUP_SCH_EDIT_CONVERT_CMP, + _( "Convert" ), component_select_alternate_shape_xpm ); + + if( libComponent && ( libComponent->m_UnitCount >= 2 ) ) { wxMenu* sel_unit_menu = new wxMenu; int ii; - for( ii = 0; ii < LibEntry->m_UnitCount; ii++ ) + for( ii = 0; ii < libComponent->m_UnitCount; ii++ ) { - wxString num_unit; num_unit.Printf( _( - "Unit %d %c" ), ii + 1, - "?ABCDEFGHIJKLMNOPQRSTUVWXYZ"[ii + 1] ); - sel_unit_menu->Append( ID_POPUP_SCH_SELECT_UNIT1 + ii, - num_unit ); + wxString num_unit; + num_unit.Printf( _( "Unit %d %c" ), ii + 1, + "?ABCDEFGHIJKLMNOPQRSTUVWXYZ"[ ii + 1 ] ); + sel_unit_menu->Append( ID_POPUP_SCH_SELECT_UNIT1 + ii, num_unit ); } - ADD_MENUITEM_WITH_SUBMENU( editmenu, sel_unit_menu, ID_POPUP_SCH_SELECT_UNIT_CMP, _( "Unit" ), component_select_unit_xpm ); + + ADD_MENUITEM_WITH_SUBMENU( editmenu, sel_unit_menu, + ID_POPUP_SCH_SELECT_UNIT_CMP, + _( "Unit" ), component_select_unit_xpm ); } ADD_MENUITEM_WITH_SUBMENU( PopMenu, editmenu, - ID_POPUP_SCH_GENERIC_EDIT_CMP, _( - "Edit Component" ), edit_component_xpm ); + ID_POPUP_SCH_GENERIC_EDIT_CMP, + _( "Edit Component" ), edit_component_xpm ); if( !Component->m_Flags ) { - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_COMPONENT_CMP, _( "Copy Component" ), import_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CMP, _( "Delete Component" ), delete_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_COPY_COMPONENT_CMP, + _( "Copy Component" ), import_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CMP, + _( "Delete Component" ), delete_xpm ); } - LibEntry = ( EDA_LibComponentStruct* ) FindLibPart( Component->m_ChipName, - wxEmptyString, ALIAS ); - if( LibEntry && !LibEntry->m_DocFile.IsEmpty() ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), datasheet_xpm ); + if( libEntry && !libEntry->m_DocFile.IsEmpty() ) + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DISPLAYDOC_CMP, _( "Doc" ), + datasheet_xpm ); } /*******************************************************************/ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel ) +{ /*******************************************************************/ - /* Add menu commands for a Global Label */ -{ wxMenu* menu_change_type = new wxMenu; if( !GLabel->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Global Label" ), move_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, _( "Rotate Global Label" ), rotate_glabel_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, _( "Edit Global Label" ), edit_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Global Label" ), delete_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, + _( "Move Global Label" ), move_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, + _( "Rotate Global Label" ), rotate_glabel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, + _( "Edit Global Label" ), edit_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, + _( "Delete Global Label" ), delete_text_xpm ); // add menu change type text (to label, glabel, text): ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL, @@ -353,24 +393,28 @@ void AddMenusForGLabel( wxMenu* PopMenu, SCH_GLOBALLABEL* GLabel ) ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_COMMENT, _( "Change to Text" ), glabel2text_xpm ); ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, - ID_POPUP_SCH_CHANGE_TYPE_TEXT, _( "Change Type" ), gl_change_xpm ); + ID_POPUP_SCH_CHANGE_TYPE_TEXT, + _( "Change Type" ), gl_change_xpm ); } /*******************************************************************/ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel ) +{ /*******************************************************************/ - /* Add menu commands for a hierarchical Label */ -{ wxMenu* menu_change_type = new wxMenu; if( !HLabel->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Hierarchical Label" ), move_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, _( "Rotate Hierarchical Label" ), rotate_glabel_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, _( "Edit Hierarchical Label" ), edit_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Hierarchical label" ), delete_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, + _( "Move Hierarchical Label" ), move_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, + _( "Rotate Hierarchical Label" ), rotate_glabel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, + _( "Edit Hierarchical Label" ), edit_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, + _( "Delete Hierarchical label" ), delete_text_xpm ); // add menu change type text (to label, glabel, text): ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL, @@ -380,24 +424,28 @@ void AddMenusForHLabel( wxMenu* PopMenu, SCH_HIERLABEL* HLabel ) ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL, _( "Change to Global Label" ), label2glabel_xpm ); ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, - ID_POPUP_SCH_CHANGE_TYPE_TEXT, _( "Change Type" ), gl_change_xpm ); + ID_POPUP_SCH_CHANGE_TYPE_TEXT, + _( "Change Type" ), gl_change_xpm ); } /*****************************************************************/ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label ) +{ /*****************************************************************/ - /* Add menu commands for a Label */ -{ wxMenu* menu_change_type = new wxMenu; if( !Label->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Label" ), move_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, _( "Rotate Label" ), rotate_pos_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, _( "Edit Label" ), edit_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Label" ), delete_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, + _( "Move Label" ), move_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, + _( "Rotate Label" ), rotate_pos_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, + _( "Edit Label" ), edit_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, + _( "Delete Label" ), delete_text_xpm ); // add menu change type text (to label, glabel, text): ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL, @@ -407,38 +455,46 @@ void AddMenusForLabel( wxMenu* PopMenu, SCH_LABEL* Label ) ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL, _( "Change to Global Label" ), label2glabel_xpm ); ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, - ID_POPUP_SCH_CHANGE_TYPE_TEXT, _( "Change Type" ), gl_change_xpm ); + ID_POPUP_SCH_CHANGE_TYPE_TEXT, + _( "Change Type" ), gl_change_xpm ); } /*****************************************************************/ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text ) +{ /*****************************************************************/ - /* Add menu commands for a Text (a comment) */ -{ wxMenu* menu_change_type = new wxMenu; if( !Text->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Text" ), move_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, _( "Rotate Text" ), rotate_pos_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, _( "Edit Text" ), edit_text_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Text" ), delete_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, + _( "Move Text" ), move_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ROTATE_TEXT, _( "Rotate Text" ), + rotate_pos_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_TEXT, _( "Edit Text" ), + edit_text_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Text" ), + delete_text_xpm ); /* add menu change type text (to label, glabel, text), * but only if this is a single line text */ - if( Text->m_Text.Find( wxT("\n") ) == wxNOT_FOUND ) + if( Text->m_Text.Find( wxT( "\n" ) ) == wxNOT_FOUND ) { ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_LABEL, _( "Change to Label" ), label2text_xpm ); - ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL, - _( "Change to Hierarchical Label" ), label2glabel_xpm ); - ADD_MENUITEM( menu_change_type, ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL, + ADD_MENUITEM( menu_change_type, + ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_HLABEL, + _( "Change to Hierarchical Label" ), + label2glabel_xpm ); + ADD_MENUITEM( menu_change_type, + ID_POPUP_SCH_CHANGE_TYPE_TEXT_TO_GLABEL, _( "Change to Glabel" ), label2glabel_xpm ); ADD_MENUITEM_WITH_SUBMENU( PopMenu, menu_change_type, - ID_POPUP_SCH_CHANGE_TYPE_TEXT, _( "Change Type" ), gl_change_xpm ); + ID_POPUP_SCH_CHANGE_TYPE_TEXT, + _( "Change Type" ), gl_change_xpm ); } } @@ -446,28 +502,30 @@ void AddMenusForText( wxMenu* PopMenu, SCH_TEXT* Text ) /*****************************************************************/ void AddMenusForJunction( wxMenu* PopMenu, DrawJunctionStruct* Junction, WinEDA_SchematicFrame* frame ) +{ /*****************************************************************/ - /* Add menu commands for a junction */ -{ bool is_new = (Junction->m_Flags & IS_NEW) ? TRUE : FALSE; if( !is_new ) { if( PickStruct( frame->GetScreen()->m_Curseur, frame->GetScreen(), WIREITEM | BUSITEM | EXCLUDE_WIRE_BUS_ENDPOINTS ) ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, + _( "Break Wire" ), break_line_xpm ); } - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Junction" ), delete_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Junction" ), + delete_xpm ); if( PickStruct( frame->GetScreen()->m_Curseur, frame->GetScreen(), WIREITEM | BUSITEM ) ) { - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( - "Delete Connection" ), delete_connection_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, + _( "Delete Node" ), delete_node_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, + _( "Delete Connection" ), delete_connection_xpm ); } } @@ -475,11 +533,10 @@ void AddMenusForJunction( wxMenu* PopMenu, DrawJunctionStruct* Junction, /*****************************************************************/ void AddMenusForWire( wxMenu* PopMenu, EDA_DrawLineStruct* Wire, WinEDA_SchematicFrame* frame ) +{ /*****************************************************************/ - /* Add menu commands for a wire */ -{ bool is_new = (Wire->m_Flags & IS_NEW) ? TRUE : FALSE; wxPoint pos = frame->GetScreen()->m_Curseur; @@ -489,37 +546,42 @@ void AddMenusForWire( wxMenu* PopMenu, EDA_DrawLineStruct* Wire, return; } - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, _( "Drag Wire" ), move_track_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DRAG_WIRE_REQUEST, _( "Drag Wire" ), + move_track_xpm ); PopMenu->AppendSeparator(); ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Wire" ), delete_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), delete_node_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, _( - "Delete Connection" ), delete_connection_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_NODE, _( "Delete Node" ), + delete_node_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE_CONNECTION, + _( "Delete Connection" ), delete_connection_xpm ); if( PickStruct( frame->GetScreen()->m_Curseur, frame->GetScreen(), WIREITEM | BUSITEM | EXCLUDE_WIRE_BUS_ENDPOINTS ) ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), break_line_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Wire" ), + break_line_xpm ); PopMenu->AppendSeparator(); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, _( "Add Junction" ), add_junction_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, _( "Add Label" ), add_line_label_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, _( "Add Junction" ), + add_junction_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, _( "Add Label" ), + add_line_label_xpm ); // Place Global label command only if the cursor is over one end of the Wire: if( ( pos.x == Wire->m_Start.x && pos.y == Wire->m_Start.y) || ( pos.x == Wire->m_End.x && pos.y == Wire->m_End.y ) ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL, _( "Add Global Label" ), add_glabel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL, + _( "Add Global Label" ), add_glabel_xpm ); } /*****************************************************************/ void AddMenusForBus( wxMenu* PopMenu, EDA_DrawLineStruct* Bus, WinEDA_SchematicFrame* frame ) +{ /*****************************************************************/ - /* Add menu commands for a Bus */ -{ bool is_new = (Bus->m_Flags & IS_NEW) ? TRUE : FALSE; wxPoint pos = frame->GetScreen()->m_Curseur; @@ -529,116 +591,131 @@ void AddMenusForBus( wxMenu* PopMenu, EDA_DrawLineStruct* Bus, return; } - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, - _( "Delete Bus" ), delete_bus_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Bus" ), + delete_bus_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, - _( "Break Bus" ), break_bus_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_BREAK_WIRE, _( "Break Bus" ), + break_bus_xpm ); PopMenu->AppendSeparator(); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, _( "Add Junction" ), add_junction_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, _( "Add Label" ), add_line_label_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_JUNCTION, _( "Add Junction" ), + add_junction_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_LABEL, _( "Add Label" ), + add_line_label_xpm ); // Place Global label command only if the cursor is over one end of the Bus: if( ( pos.x == Bus->m_Start.x && pos.y == Bus->m_Start.y) || ( pos.x == Bus->m_End.x && pos.y == Bus->m_End.y ) ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL, _( "Add Global Label" ), add_glabel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ADD_GLABEL, + _( "Add Global Label" ), add_glabel_xpm ); } /************************************************************************/ void AddMenusForHierchicalSheet( wxMenu* PopMenu, DrawSheetStruct* Sheet ) +{ /************************************************************************/ - /* Add menu commands for a Sheet */ -{ if( !Sheet->m_Flags ) { - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET, _( "Enter Sheet" ), enter_sheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_ENTER_SHEET, + _( "Enter Sheet" ), enter_sheet_xpm ); PopMenu->AppendSeparator(); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, _( "Move Sheet" ), move_sheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_ITEM_REQUEST, + _( "Move Sheet" ), move_sheet_xpm ); } if( Sheet->m_Flags ) { - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ), apply_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_END_SHEET, _( "Place Sheet" ), + apply_xpm ); } else { - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_SHEET, _( "Edit Sheet" ), edit_sheet_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_RESIZE_SHEET, _( "Resize Sheet" ), resize_sheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_SHEET, _( "Edit Sheet" ), + edit_sheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_RESIZE_SHEET, _( "Resize Sheet" ), + resize_sheet_xpm ); PopMenu->AppendSeparator(); - ADD_MENUITEM( PopMenu, ID_POPUP_IMPORT_GLABEL, _("Import PinSheets"), - import_hierarchical_label_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_IMPORT_GLABEL, _( "Import PinSheets" ), + import_hierarchical_label_xpm ); if( Sheet->m_Label ) // Sheet has pin labels, and can be cleaned ADD_MENUITEM( PopMenu, ID_POPUP_SCH_CLEANUP_SHEET, _( "Cleanup PinSheets" ), options_pinsheet_xpm ); PopMenu->AppendSeparator(); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Sheet" ), delete_sheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete Sheet" ), + delete_sheet_xpm ); } } /************************************************************************/ -void AddMenusForPinSheet( wxMenu* PopMenu, Hierarchical_PIN_Sheet_Struct* PinSheet ) +void AddMenusForPinSheet( wxMenu* PopMenu, + Hierarchical_PIN_Sheet_Struct* PinSheet ) +{ /************************************************************************/ - /* Add menu commands for a Pin Sheet (or Sheet label) */ -{ if( !PinSheet->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_PINSHEET, _( "Move PinSheet" ), move_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_MOVE_PINSHEET, + _( "Move PinSheet" ), move_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_PINSHEET, _( "Edit PinSheet" ), edit_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_EDIT_PINSHEET, _( "Edit PinSheet" ), + edit_xpm ); if( !PinSheet->m_Flags ) - ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete PinSheet" ), delete_pinsheet_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_SCH_DELETE, _( "Delete PinSheet" ), + delete_pinsheet_xpm ); } /**********************************************************************/ void AddMenusForBlock( wxMenu* PopMenu, WinEDA_SchematicFrame* frame ) +{ /**********************************************************************/ - /* Add menu commands for block */ -{ - ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, _( "Cancel Block" ), cancel_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_CANCEL_CURRENT_COMMAND, + _( "Cancel Block" ), cancel_xpm ); PopMenu->AppendSeparator(); if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE ) - ADD_MENUITEM( PopMenu, ID_POPUP_ZOOM_BLOCK, - _( "Window Zoom" ), zoom_selected_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_ZOOM_BLOCK, _( "Window Zoom" ), + zoom_selected_xpm ); ADD_MENUITEM( PopMenu, ID_POPUP_PLACE_BLOCK, _( "Place Block" ), apply_xpm ); - if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE ) - { // After a block move (that is also a block selection) one can reselect a block function: + if( frame->GetScreen()->m_BlockLocate.m_Command == BLOCK_MOVE ) // After a block move (that is also a block selection) one can reselect a block function: + { ADD_MENUITEM( PopMenu, wxID_COPY, _( "Save Block" ), copy_button ); - ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK, - _( "Copy Block" ), copyblock_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_DRAG_BLOCK, - _( "Drag Block" ), move_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_DELETE_BLOCK, - _( "Delete Block" ), delete_xpm ); - ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, _( - "Mirror Block ||" ), mirror_H_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_COPY_BLOCK, _( "Copy Block" ), + copyblock_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_DRAG_BLOCK, _( "Drag Block" ), + move_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_DELETE_BLOCK, _( "Delete Block" ), + delete_xpm ); + ADD_MENUITEM( PopMenu, ID_POPUP_MIRROR_Y_BLOCK, + _( "Mirror Block ||" ), mirror_H_xpm ); #if 0 #ifdef __WINDOWS__ - ADD_MENUITEM( menu_other_block_commands, ID_GEN_COPY_BLOCK_TO_CLIPBOARD, + ADD_MENUITEM( menu_other_block_commands, + ID_GEN_COPY_BLOCK_TO_CLIPBOARD, _( "Copy to Clipboard" ), copy_button ); #endif #endif } } + /**********************************************************************/ void AddMenusForMarkers( wxMenu* aPopMenu, MARKER_SCH* aMarker, - WinEDA_SchematicFrame* aFrame ) -/**********************************************************************/ + WinEDA_SchematicFrame* aFrame ) { - ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_DELETE, _( "Delete Marker" ), delete_xpm ); - ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_GETINFO_MARKER, _( "Marker Error Info" ), info_xpm ); +/**********************************************************************/ + ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_DELETE, _( "Delete Marker" ), + delete_xpm ); + ADD_MENUITEM( aPopMenu, ID_POPUP_SCH_GETINFO_MARKER, + _( "Marker Error Info" ), info_xpm ); } diff --git a/eeschema/pinedit.cpp b/eeschema/pinedit.cpp index d93e4a98cc..995524f589 100644 --- a/eeschema/pinedit.cpp +++ b/eeschema/pinedit.cpp @@ -501,9 +501,9 @@ void WinEDA_PinPropertiesFrame::SetPinNum( const wxString& newnum, int newsize ) /*************************************************/ -void WinEDA_LibeditFrame::DeletePin( wxDC* DC, - EDA_LibComponentStruct* LibEntry, - LibDrawPin* Pin ) +void WinEDA_LibeditFrame::DeletePin( wxDC* DC, + LIB_COMPONENT* LibEntry, + LibDrawPin* Pin ) /*************************************************/ /* Routine d'effacement de la pin pointee par la souris @@ -956,7 +956,7 @@ int sort_by_pin_number( const void* ref, const void* tst ) /***************************************************************/ -bool WinEDA_LibeditFrame::TestPins( EDA_LibComponentStruct* LibEntry ) +bool WinEDA_LibeditFrame::TestPins( LIB_COMPONENT* LibEntry ) /***************************************************************/ // Test des pins ( duplicates...) diff --git a/eeschema/plot.cpp b/eeschema/plot.cpp index 45726f1c81..400385f166 100644 --- a/eeschema/plot.cpp +++ b/eeschema/plot.cpp @@ -50,14 +50,14 @@ static void PlotLibPart( PLOTTER* plotter, SCH_COMPONENT* DrawLibItem ) /*************************************************/ /* Polt a component */ { - int ii, t1, t2, * Poly, orient; - EDA_LibComponentStruct* Entry; - int TransMat[2][2], Multi, convert; - EDA_Colors CharColor = UNSPECIFIED_COLOR; - wxPoint pos; - bool draw_bgfill = false; + int ii, t1, t2, * Poly, orient; + LIB_COMPONENT* Entry; + int TransMat[2][2], Multi, convert; + EDA_Colors CharColor = UNSPECIFIED_COLOR; + wxPoint pos; + bool draw_bgfill = false; - Entry = ( EDA_LibComponentStruct* ) FindLibPart( DrawLibItem->m_ChipName ); + Entry = CMP_LIBRARY::FindLibraryComponent( DrawLibItem->m_ChipName ); if( Entry == NULL ) return;; memcpy( TransMat, DrawLibItem->m_Transform, sizeof(TransMat) ); diff --git a/eeschema/protos.h b/eeschema/protos.h index a72e9bec5a..15e42284f6 100644 --- a/eeschema/protos.h +++ b/eeschema/protos.h @@ -2,11 +2,11 @@ /* prototypage des fonctions de EESchema */ /*****************************************/ -LibEDA_BaseStruct* LocatePin( const wxPoint& RefPos, - EDA_LibComponentStruct* Entry, - int Unit, - int Convert, - SCH_COMPONENT* DrawItem = NULL ); +LibEDA_BaseStruct* LocatePin( const wxPoint& RefPos, + LIB_COMPONENT* Entry, + int Unit, + int Convert, + SCH_COMPONENT* DrawItem = NULL ); /* Routine de localisation d'une PIN de la PartLib pointee par Entry */ @@ -40,22 +40,16 @@ void InstallCmpeditFrame( WinEDA_SchematicFrame* parent, wxPoint& pos, /******************************/ /* EELIBS_DRAW_COMPONENTS.CPP */ /******************************/ -int NumOfLibraries(); - -LibCmpEntry* FindLibPart( const wxChar* Name, - const wxString& LibName = wxEmptyString, - LibrEntryType Alias = ROOT ); - -void DrawingLibInGhost( WinEDA_DrawPanel* panel, - wxDC* DC, - EDA_LibComponentStruct* LibEntry, - SCH_COMPONENT* DrawLibItem, - int PartX, - int PartY, - int Multi, - int convert, - int Color, - bool DrawPinText ); +void DrawingLibInGhost( WinEDA_DrawPanel* panel, + wxDC* DC, + LIB_COMPONENT* LibEntry, + SCH_COMPONENT* DrawLibItem, + int PartX, + int PartY, + int Multi, + int convert, + int Color, + bool DrawPinText ); bool MapAngles( int* Angle1, int* Angle2, @@ -73,14 +67,6 @@ bool MapAngles( int* Angle1, wxPoint TransformCoordinate( const int aTransformMatrix[2][2], const wxPoint& aPosition ); -LibraryStruct* FindLibrary( const wxString& Name ); -LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame, - const wxString& FullLibName, - const wxString& LibName ); -void LoadLibraries( WinEDA_SchematicFrame* frame ); -void FreeCmpLibrary( wxWindow* frame, - const wxString& LibName ); - void SnapLibItemPoint( int OrigX, int OrigY, int* ClosestX, @@ -153,12 +139,12 @@ SCH_ITEM* PickStruct( const wxPoint& refpos, int SearchMask ); -LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, - const wxPoint& refpoint, - EDA_LibComponentStruct* LibEntry, - int Unit, - int Convert, - int masque ); +LibEDA_BaseStruct* LocateDrawItem( SCH_SCREEN* Screen, + const wxPoint& refpoint, + LIB_COMPONENT* LibEntry, + int Unit, + int Convert, + int masque ); Hierarchical_PIN_Sheet_Struct* LocateSheetLabel( DrawSheetStruct* Sheet, const wxPoint& pos ); @@ -216,7 +202,7 @@ bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose ); /* SAVELIB.CPP */ /**************/ -EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry ); +LIB_COMPONENT* CopyLibEntryStruct( LIB_COMPONENT* OldEntry ); /* Routine de copie d'une partlib * Parametres d'entree: pointeur sur la structure de depart @@ -262,7 +248,7 @@ void DeleteAllMarkers( int type ); /* GETPART.CPP */ /**************/ -int LookForConvertPart( EDA_LibComponentStruct* LibEntry ); +int LookForConvertPart( LIB_COMPONENT* LibEntry ); /* Retourne la plus grande valeur trouvee dans la liste des elements * "drawings" du composant LibEntry, pour le membre .Convert @@ -295,7 +281,7 @@ void InstallPineditFrame( WinEDA_LibeditFrame* parent, * 0 si commande annulee */ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame, - LibraryStruct* Library, + CMP_LIBRARY* Library, wxString& Buffer, wxString& OldName ); @@ -305,7 +291,7 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame, * a library * This list is sorted, with the library cache always at end of the list */ -LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame ); +CMP_LIBRARY* SelectLibraryFromList( WinEDA_DrawFrame* frame ); /** * Function GetNameOfPartToLoad @@ -319,7 +305,7 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame ); * BufName */ int GetNameOfPartToLoad( WinEDA_DrawFrame* frame, - LibraryStruct* Lib, + CMP_LIBRARY* Lib, wxString& BufName ); /**************/ diff --git a/eeschema/save_schemas.cpp b/eeschema/save_schemas.cpp index ccc267d9c0..13674db03e 100644 --- a/eeschema/save_schemas.cpp +++ b/eeschema/save_schemas.cpp @@ -8,12 +8,16 @@ #include "confirm.h" #include "kicad_string.h" #include "gestfich.h" + #include "program.h" #include "libcmp.h" #include "general.h" #include "macros.h" - #include "protos.h" +#include "class_library.h" + +#include + /* Fonctions Locales */ static void SaveLayers( FILE* f ); @@ -119,11 +123,12 @@ bool SCH_SCREEN::Save( FILE* aFile ) const wxString datetime = DateAndTime( ); bool first = true; - for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) + + BOOST_FOREACH( const CMP_LIBRARY& lib, CMP_LIBRARY::GetLibraryList() ) { if( ! first ) Name += wxT( "," ); - Name += Lib->m_Name; + Name += lib.GetName(); first = false; } diff --git a/eeschema/savelib.cpp b/eeschema/savelib.cpp index cd550d89ee..4f1a8bb077 100644 --- a/eeschema/savelib.cpp +++ b/eeschema/savelib.cpp @@ -25,13 +25,13 @@ * Parametres de sortie: pointeur sur la structure creee * Do not copy new items ( i.e. with m_Flag & IS_NEW) */ -EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry ) +LIB_COMPONENT* CopyLibEntryStruct( LIB_COMPONENT* OldEntry ) { - wxString msg; - EDA_LibComponentStruct* NewStruct; - LibEDA_BaseStruct* NewDrawings, * OldDrawings; - LibEDA_BaseStruct* LastItem; - LibDrawField* OldField, * NewField; + wxString msg; + LIB_COMPONENT* NewStruct; + LibEDA_BaseStruct* NewDrawings, * OldDrawings; + LibEDA_BaseStruct* LastItem; + LibDrawField* OldField, * NewField; if( OldEntry->Type != ROOT ) { @@ -41,7 +41,7 @@ EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry ) return NULL; } - NewStruct = new EDA_LibComponentStruct( NULL ); + NewStruct = new LIB_COMPONENT( wxEmptyString ); OldEntry->m_Prefix.Copy( &NewStruct->m_Prefix ); OldEntry->m_Name.Copy( &NewStruct->m_Name ); diff --git a/eeschema/schedit.cpp b/eeschema/schedit.cpp index 49df2553db..6899f77bd7 100644 --- a/eeschema/schedit.cpp +++ b/eeschema/schedit.cpp @@ -649,10 +649,10 @@ void WinEDA_SchematicFrame::Process_Special_Functions( wxCommandEvent& event ) if( screen->GetCurItem() == NULL ) break; { - LibCmpEntry* LibEntry; - LibEntry = FindLibPart( - ( (SCH_COMPONENT*) screen->GetCurItem() )->m_ChipName, - wxEmptyString, ALIAS ); + CMP_LIB_ENTRY* LibEntry; + LibEntry = CMP_LIBRARY::FindLibraryEntry( + ( (SCH_COMPONENT*) screen->GetCurItem() )->m_ChipName ); + if( LibEntry && LibEntry->m_DocFile != wxEmptyString ) { GetAssociatedDocument( this, LibEntry->m_DocFile , diff --git a/eeschema/selpart.cpp b/eeschema/selpart.cpp index 8ffd0e292d..f014849d07 100644 --- a/eeschema/selpart.cpp +++ b/eeschema/selpart.cpp @@ -13,38 +13,24 @@ #include "protos.h" -LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame ) +CMP_LIBRARY* SelectLibraryFromList( WinEDA_DrawFrame* frame ) { static wxString OldLibName; - wxString LibName, msg; - int count = NumOfLibraries(); - LibraryStruct* Lib = NULL; + wxString msg; + wxArrayString libNamesList; + int count = CMP_LIBRARY::GetLibraryCount(); + CMP_LIBRARY* Lib = NULL; if( count == 0 ) { - DisplayError( frame, _( "No libraries are loaded" ) ); + DisplayError( frame, _( "No component libraries are loaded." ) ); return NULL; } + libNamesList = CMP_LIBRARY::GetLibraryNames(); + msg.Printf( _( " Select 1 of %d libraries." ), count ); - wxArrayString libNamesList; - LibraryStruct* libcache = NULL; - - for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) - { - if( Lib->m_IsLibCache ) - libcache = Lib; - else - libNamesList.Add( Lib->m_Name ); - } - - libNamesList.Sort(); - - // Add lib cache - if( libcache ) - libNamesList.Add( libcache->m_Name ); - wxSingleChoiceDialog dlg( frame, msg, _( "Select Library" ), libNamesList ); int index = libNamesList.Index( OldLibName ); @@ -55,7 +41,7 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame ) if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() ) return NULL; - Lib = FindLibrary( dlg.GetStringSelection() ); + Lib = CMP_LIBRARY::FindLibrary( dlg.GetStringSelection() ); if( Lib != NULL ) OldLibName = dlg.GetStringSelection(); @@ -65,7 +51,7 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame ) int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame, - LibraryStruct* Library, + CMP_LIBRARY* Library, wxString& Buffer, wxString& OldName ) { size_t i; @@ -105,7 +91,7 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame, } -int GetNameOfPartToLoad( WinEDA_DrawFrame* frame, LibraryStruct* Library, +int GetNameOfPartToLoad( WinEDA_DrawFrame* frame, CMP_LIBRARY* Library, wxString& BufName ) { int ii; diff --git a/eeschema/symbdraw.cpp b/eeschema/symbdraw.cpp index 963b6ce622..47629b074e 100644 --- a/eeschema/symbdraw.cpp +++ b/eeschema/symbdraw.cpp @@ -179,8 +179,8 @@ static void AbortSymbolTraceOn( WinEDA_DrawPanel* Panel, wxDC* DC ) /*******************************************************************************************/ -LibEDA_BaseStruct* WinEDA_LibeditFrame::CreateGraphicItem( EDA_LibComponentStruct* LibEntry, - wxDC* DC ) +LibEDA_BaseStruct* WinEDA_LibeditFrame::CreateGraphicItem( LIB_COMPONENT* LibEntry, + wxDC* DC ) /*******************************************************************************************/ /* Routine de creation d'un nouvel element type LibraryDrawStruct diff --git a/eeschema/symbedit.cpp b/eeschema/symbedit.cpp index c1ad72e63d..cba6ea09f0 100644 --- a/eeschema/symbedit.cpp +++ b/eeschema/symbedit.cpp @@ -30,11 +30,11 @@ */ void WinEDA_LibeditFrame::LoadOneSymbol( void ) { - EDA_LibComponentStruct* Component; - LibEDA_BaseStruct* DrawEntry; - FILE* ImportFile; - wxString msg, err; - LibraryStruct* Lib; + LIB_COMPONENT* Component; + LibEDA_BaseStruct* DrawEntry; + FILE* ImportFile; + wxString msg, err; + CMP_LIBRARY* Lib; /* Exit if no library entry is selected or a command is in progress. */ if( CurrentLibEntry == NULL @@ -70,8 +70,7 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void ) return; } - Lib = new LibraryStruct( LIBRARY_TYPE_SYMBOL, fn.GetName(), - fn.GetFullPath() ); + Lib = new CMP_LIBRARY( LIBRARY_TYPE_SYMBOL, fn ); if( !Lib->Load( err ) ) { @@ -96,7 +95,7 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void ) if( Lib->GetCount() > 1 ) DisplayError( this, _( "Warning: more than 1 part in Symbol File" ) ); - Component = (EDA_LibComponentStruct*) Lib->GetFirstEntry(); + Component = (LIB_COMPONENT*) Lib->GetFirstEntry(); DrawEntry = Component->m_Drawings; while( DrawEntry ) diff --git a/eeschema/tool_viewlib.cpp b/eeschema/tool_viewlib.cpp index fb39e9f5fd..aeadf60871 100644 --- a/eeschema/tool_viewlib.cpp +++ b/eeschema/tool_viewlib.cpp @@ -3,27 +3,23 @@ /****************************************************************/ #include "fctsys.h" - #include "common.h" +#include "bitmaps.h" +#include "id.h" + #include "program.h" #include "libcmp.h" #include "general.h" - -#include "wx/spinctrl.h" - #include "protos.h" - -#include "bitmaps.h" - -#include "id.h" +#include "class_library.h" void WinEDA_ViewlibFrame::ReCreateHToolbar() { int ii; - LibraryStruct* lib; - EDA_LibComponentStruct* component = NULL; - LibCmpEntry* entry = NULL; + CMP_LIBRARY* lib; + LIB_COMPONENT* component = NULL; + CMP_LIB_ENTRY* entry = NULL; bool asdeMorgan = false; if( m_HToolBar == NULL ) @@ -108,7 +104,7 @@ void WinEDA_ViewlibFrame::ReCreateHToolbar() if( (g_CurrentViewLibraryName != wxEmptyString) && (g_CurrentViewComponentName != wxEmptyString) ) { - lib = FindLibrary( g_CurrentViewLibraryName ); + lib = CMP_LIBRARY::FindLibrary( g_CurrentViewLibraryName ); if( lib != NULL ) { diff --git a/eeschema/viewlib_frame.cpp b/eeschema/viewlib_frame.cpp index 04d186d473..cb89159f5b 100644 --- a/eeschema/viewlib_frame.cpp +++ b/eeschema/viewlib_frame.cpp @@ -5,13 +5,15 @@ #include "fctsys.h" #include "appl_wxstruct.h" #include "common.h" +#include "id.h" #include "class_drawpanel.h" +#include "bitmaps.h" + #include "program.h" #include "libcmp.h" #include "general.h" -#include "bitmaps.h" #include "protos.h" -#include "id.h" + /*****************************/ /* class WinEDA_ViewlibFrame */ @@ -60,9 +62,9 @@ static wxAcceleratorEntry accels[] = #define EXTRA_BORDER_SIZE 2 -WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father, - LibraryStruct* Library, - wxSemaphore* semaphore ) : +WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father, + CMP_LIBRARY* Library, + wxSemaphore* semaphore ) : WinEDA_DrawFrame( father, VIEWER_FRAME, _( "Library browser" ), wxDefaultPosition, wxDefaultSize ) { @@ -117,7 +119,7 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father, } else { - g_CurrentViewLibraryName = Library->m_Name; + g_CurrentViewLibraryName = Library->GetName(); m_LibListSize.x = 0; } @@ -277,14 +279,14 @@ int WinEDA_ViewlibFrame::BestZoom() { int bestzoom, ii, jj; wxSize size, itemsize; - EDA_LibComponentStruct* component; - LibraryStruct* lib; + LIB_COMPONENT* component; + CMP_LIBRARY* lib; GetScreen()->m_Curseur.x = 0; GetScreen()->m_Curseur.y = 0; bestzoom = 16; - lib = FindLibrary( g_CurrentViewLibraryName ); + lib = CMP_LIBRARY::FindLibrary( g_CurrentViewLibraryName ); if( lib == NULL ) return bestzoom; @@ -314,37 +316,22 @@ int WinEDA_ViewlibFrame::BestZoom() } -/******************************************/ -void WinEDA_ViewlibFrame::ReCreateListLib() -/******************************************/ -/** Function ReCreateListLib +/** + * Function ReCreateListLib + * * Creates or recreates the list of current loaded libraries. * This list is sorted, with the library cache always at end of the list -*/ + */ +void WinEDA_ViewlibFrame::ReCreateListLib() { - LibraryStruct * libcache = NULL; - bool found = FALSE; + wxArrayString libNamesList; + bool found = false; if( m_LibList == NULL ) return; m_LibList->Clear(); - - wxArrayString libNamesList; - for( LibraryStruct* Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext ) - { - if ( Lib->m_IsLibCache ) - libcache = Lib; - else - libNamesList.Add( Lib->m_Name ); - } - - libNamesList.Sort(); - - // Add lib cache - if ( libcache ) - libNamesList.Add( libcache->m_Name ); - + libNamesList = CMP_LIBRARY::GetLibraryNames(); m_LibList->Append( libNamesList ); // Search for a previous selection: @@ -379,7 +366,7 @@ void WinEDA_ViewlibFrame::ReCreateListCmp() if( m_CmpList == NULL ) return; - LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName ); + CMP_LIBRARY* Library = CMP_LIBRARY::FindLibrary( g_CurrentViewLibraryName ); wxArrayString nameList; m_CmpList->Clear(); diff --git a/eeschema/viewlibs.cpp b/eeschema/viewlibs.cpp index 6797b5a00b..4556a88b7b 100644 --- a/eeschema/viewlibs.cpp +++ b/eeschema/viewlibs.cpp @@ -9,13 +9,13 @@ #include "class_drawpanel.h" #include "confirm.h" #include "eda_doc.h" +#include "id.h" #include "program.h" #include "libcmp.h" #include "general.h" #include "protos.h" -#include "id.h" #define NEXT_PART 1 #define NEW_PART 0 @@ -25,7 +25,7 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event ) { wxString msg; - EDA_LibComponentStruct* LibEntry; + CMP_LIB_ENTRY* LibEntry; int ii, id = event.GetId(); wxPoint pos; @@ -51,10 +51,9 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event ) break; case ID_LIBVIEW_VIEWDOC: - LibEntry = - ( EDA_LibComponentStruct* ) FindLibPart( g_CurrentViewComponentName, - g_CurrentViewLibraryName, - ALIAS ); + LibEntry = CMP_LIBRARY::FindLibraryEntry( g_CurrentViewComponentName, + g_CurrentViewLibraryName ); + if( LibEntry && ( !LibEntry->m_DocFile.IsEmpty() ) ) GetAssociatedDocument( this, LibEntry->m_DocFile, &wxGetApp().GetLibraryPathList() ); @@ -105,16 +104,16 @@ bool WinEDA_ViewlibFrame::OnRightClick( const wxPoint& MousePos, /* Affiche en Ligne d'info la librairie en cours de visualisation */ void WinEDA_ViewlibFrame::DisplayLibInfos() { - wxString msg; - LibraryStruct* Lib; + wxString msg; + CMP_LIBRARY* Lib; - Lib = FindLibrary( g_CurrentViewLibraryName ); + Lib = CMP_LIBRARY::FindLibrary( g_CurrentViewLibraryName ); msg = _( "Library browser" ); msg << wxT( " [" ); if( Lib ) - msg << Lib->m_FullFileName; + msg << Lib->GetFullFileName(); else msg += _( "none selected" ); @@ -128,13 +127,13 @@ void WinEDA_ViewlibFrame::DisplayLibInfos() /*****************************************/ void WinEDA_ViewlibFrame::SelectCurrentLibrary() { - LibraryStruct* Lib; + CMP_LIBRARY* Lib; Lib = SelectLibraryFromList( this ); if( Lib ) { g_CurrentViewComponentName.Empty(); - g_CurrentViewLibraryName = Lib->m_Name; + g_CurrentViewLibraryName = Lib->GetName(); DisplayLibInfos(); if( m_LibList ) { @@ -155,14 +154,14 @@ void WinEDA_ViewlibFrame::SelectCurrentLibrary() */ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option ) { - LibraryStruct* Lib; + CMP_LIBRARY* Lib; if( g_CurrentViewLibraryName.IsEmpty() ) SelectCurrentLibrary(); if( g_CurrentViewLibraryName.IsEmpty() ) return; - Lib = FindLibrary( g_CurrentViewLibraryName ); + Lib = CMP_LIBRARY::FindLibrary( g_CurrentViewLibraryName ); if( Lib == NULL ) return; @@ -172,7 +171,7 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option ) return; } - LibCmpEntry* LibEntry = Lib->FindEntry( g_CurrentViewComponentName ); + CMP_LIB_ENTRY* LibEntry = Lib->FindEntry( g_CurrentViewComponentName ); if( LibEntry == NULL ) return; @@ -188,12 +187,12 @@ void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option ) /*************************************************/ /* Routine to view one selected library content. */ /*************************************************/ -void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag ) +void WinEDA_ViewlibFrame::ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag ) { - int NumOfParts = 0; - LibCmpEntry* LibEntry; - wxString CmpName; - wxClientDC dc( DrawPanel ); + int NumOfParts = 0; + CMP_LIB_ENTRY* LibEntry; + wxString CmpName; + wxClientDC dc( DrawPanel ); DrawPanel->PrepareGraphicContext( &dc ); @@ -256,15 +255,15 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag ) /*****************************************************************************/ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) { - EDA_LibComponentStruct* component; - LibCmpEntry* entry; - LibraryStruct* lib; - wxString msg; - wxString tmp; + LIB_COMPONENT* component; + CMP_LIB_ENTRY* entry; + CMP_LIBRARY* lib; + wxString msg; + wxString tmp; ActiveScreen = GetScreen(); - lib = FindLibrary( g_CurrentViewLibraryName ); + lib = CMP_LIBRARY::FindLibrary( g_CurrentViewLibraryName ); if( lib == NULL ) return; @@ -286,24 +285,12 @@ void WinEDA_ViewlibFrame::RedrawActiveWindow( wxDC* DC, bool EraseBg ) if( entry->Type != ROOT ) { - EDA_LibCmpAliasStruct* alias = (EDA_LibCmpAliasStruct*) entry; + LIB_ALIAS* alias = (LIB_ALIAS*) entry; + component = alias->GetComponent(); - component = lib->FindComponent( alias->m_RootName ); + wxASSERT( component != NULL && component->Type == ROOT ); - if( component == NULL ) - { - msg.Printf( _( "Root component <%s> for alias <%s> not found in \ -library." ), - (const wxChar*) alias->m_RootName, - (const wxChar*) entry->GetName(), - (const wxChar*) lib->m_Name ); - DisplayError( this, msg ); - return; - } - - msg.Printf( _( "Current Part: <%s> (is Alias of <%s>)" ), - (const wxChar*) entry->GetName(), - (const wxChar*) alias->m_RootName ); + msg = alias->GetName(); /* Temporarily change the name field text to reflect the alias name. */ tmp = component->GetName(); @@ -316,9 +303,8 @@ library." ), } else { - component = (EDA_LibComponentStruct*) entry; - msg.Printf( _( "Current Part: <%s>" ), - (const wxChar*) component->GetName() ); + component = (LIB_COMPONENT*) entry; + msg = _( "None" ); } component->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_ViewUnit, @@ -327,9 +313,11 @@ library." ), if( !tmp.IsEmpty() ) component->m_Name.m_Text = tmp; - AfficheDoc( this, entry->m_Doc, entry->m_KeyWord ); - - SetStatusText( msg, 0 ); + MsgPanel->EraseMsgBox(); + MsgPanel->AppendMessage( _( "Part" ), component->GetName(), BLUE, 6 ); + MsgPanel->AppendMessage( _( "Alias" ), msg, RED, 6 ); + MsgPanel->AppendMessage( _( "Description" ), entry->m_Doc, CYAN, 6 ); + MsgPanel->AppendMessage( _( "Key words" ), entry->m_KeyWord, DARKDARKGRAY ); DrawPanel->Trace_Curseur( DC ); } diff --git a/include/class_drawpanel.h b/include/class_drawpanel.h index dc29fb828c..43e206595b 100644 --- a/include/class_drawpanel.h +++ b/include/class_drawpanel.h @@ -155,7 +155,8 @@ public: * Check to see if the cursor is being managed for block or editing * commands and release it. */ - void UnManageCursor( void ); + void UnManageCursor( int id = -1, int cursor = -1, + const wxString& title = wxEmptyString ); DECLARE_EVENT_TABLE() }; diff --git a/include/common.h b/include/common.h index 624f39cf28..e714d4d5ac 100644 --- a/include/common.h +++ b/include/common.h @@ -289,9 +289,6 @@ void Affiche_1_Parametre( WinEDA_DrawFrame* frame, const wxString& texte_L, int color ); -void AfficheDoc( WinEDA_DrawFrame* frame, const wxString& Doc, - const wxString& KeyW ); - /* Routine d'affichage de la documentation associee a un composant */ int GetTimeStamp(); diff --git a/include/wxEeschemaStruct.h b/include/wxEeschemaStruct.h index d3986c7c1e..8029490da6 100644 --- a/include/wxEeschemaStruct.h +++ b/include/wxEeschemaStruct.h @@ -18,9 +18,9 @@ class DRAWSEGMENT; class DrawPickedStruct; class SCH_ITEM; class DrawNoConnectStruct; -class LibraryStruct; -class EDA_LibComponentStruct; -class LibCmpEntry; +class CMP_LIBRARY; +class LIB_COMPONENT; +class CMP_LIB_ENTRY; class LibEDA_BaseStruct; class EDA_BaseStruct; class DrawBusEntryStruct; @@ -448,6 +448,11 @@ public: */ int CheckAnnotate( wxArrayString * aMessageList, bool aOneSheetOnly ); + /** + * Load component libraries defined in project file. + */ + void LoadLibraries( void ); + DECLARE_EVENT_TABLE() }; @@ -522,10 +527,10 @@ private: bool LoadOneLibraryPart(); void SaveActiveLibrary( wxCommandEvent& event ); - bool LoadOneLibraryPartAux( LibCmpEntry* LibEntry, - LibraryStruct* Library ); + bool LoadOneLibraryPartAux( CMP_LIB_ENTRY* LibEntry, + CMP_LIBRARY* Library ); - void DisplayCmpDoc( const wxString& Name ); + void DisplayCmpDoc(); void EditComponentProperties(); // General editing @@ -539,20 +544,19 @@ private: // Edition des Pins: void CreatePin( wxDC* DC ); - void DeletePin( wxDC* DC, - EDA_LibComponentStruct* LibEntry, - LibDrawPin* Pin ); + void DeletePin( wxDC* DC, + LIB_COMPONENT* LibEntry, + LibDrawPin* Pin ); void StartMovePin( wxDC* DC ); // Test des pins ( duplicates...) - bool TestPins( EDA_LibComponentStruct* LibEntry ); + bool TestPins( LIB_COMPONENT* LibEntry ); // Edition de l'ancre void PlaceAncre(); // Edition des graphismes: - LibEDA_BaseStruct* CreateGraphicItem( EDA_LibComponentStruct* LibEntry, - wxDC* DC ); + LibEDA_BaseStruct* CreateGraphicItem( LIB_COMPONENT* LibEntry, wxDC* DC ); void GraphicItemBeginDraw( wxDC* DC ); void StartMoveDrawSymbol( wxDC* DC ); void EndDrawGraphicItem( wxDC* DC ); @@ -563,7 +567,7 @@ private: void EditSymbolText( wxDC* DC, LibEDA_BaseStruct* DrawItem ); void RotateSymbolText( wxDC* DC ); void DeleteDrawPoly( wxDC* DC ); - LibDrawField* LocateField( EDA_LibComponentStruct* LibEntry ); + LibDrawField* LocateField( LIB_COMPONENT* LibEntry ); LibEDA_BaseStruct* LocateItemUsingCursor(); void RotateField( wxDC* DC, LibDrawField* Field ); void PlaceField( wxDC* DC, LibDrawField* Field ); @@ -592,9 +596,6 @@ protected: }; -/************************************************************************************************/ -/************************************************************************************************/ -class LibraryStruct; class WinEDA_ViewlibFrame : public WinEDA_DrawFrame { private: @@ -615,9 +616,9 @@ private: wxString m_ConfigPath; // subpath for configuartion public: - WinEDA_ViewlibFrame( wxWindow* father, - LibraryStruct* Library = NULL, - wxSemaphore* semaphore = NULL ); + WinEDA_ViewlibFrame( wxWindow* father, + CMP_LIBRARY* Library = NULL, + wxSemaphore* semaphore = NULL ); ~WinEDA_ViewlibFrame(); @@ -647,7 +648,7 @@ private: void SelectCurrentLibrary(); void SelectAndViewLibraryPart( int option ); void ExportToSchematicLibraryPart( wxCommandEvent& event ); - void ViewOneLibraryContent( LibraryStruct* Lib, int Flag ); + void ViewOneLibraryContent( CMP_LIBRARY* Lib, int Flag ); bool OnRightClick( const wxPoint& MousePos, wxMenu* PopMenu ); DECLARE_EVENT_TABLE() diff --git a/include/wxstruct.h b/include/wxstruct.h index 02a75b4869..1e55d2f2a2 100644 --- a/include/wxstruct.h +++ b/include/wxstruct.h @@ -362,6 +362,10 @@ protected: */ static wxSize computeFontSize(); + /** + * Calculate the width and height of a text string using the system UI font. + */ + wxSize computeTextSize( const wxString& text ); public: WinEDA_DrawFrame* m_Parent; @@ -386,6 +390,21 @@ public: void Affiche_1_Parametre( int pos_X, const wxString& texte_H, const wxString& texte_L, int color ); + /** + * Append a message to the message panel. + * + * This method automatically adjusts for the width of the text string. + * Making consectutive calls to AppendMessage will append each message + * to the right of the last message. This message is not compatible + * with Affiche_1_Parametre. + * + * @param textUpper - The message upper text. + * @param textLower - The message lower text. + * @param color - A color ID from the Kicad color list (see colors.h). + * @param pad - Number of spaces to pad between messages (default = 4). + */ + void AppendMessage( const wxString& textUpper, const wxString& textLower, + int color, int pad = 4 ); DECLARE_EVENT_TABLE() };