Commit 79c9be25 authored by stambaughw's avatar stambaughw

Replace PriorQue with boost::ptr_vector for component library entries.

* Replaced WinEDAListBox buttons with wxStdDialogButtonSizer.
* Moved library draw entries GenCopy method to base class.
* Remove priorque.cpp and priorque.h from CMakeLists.txt.
* The usual code cleaning and uncrustification.
parent 27a0c73c
......@@ -40,17 +40,13 @@ END_EVENT_TABLE()
*/
WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* parent, const wxString& title,
const wxChar** itemlist,
const wxString& reftext,
const wxChar** itemlist, const wxString& reftext,
void(* movefct)(wxString& Text) ,
const wxColour& colour, wxPoint dialog_position ) :
wxDialog( parent, -1, title, dialog_position, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER
)
wxDEFAULT_DIALOG_STYLE | MAYBE_RESIZE_BORDER )
{
wxSize size;
const wxChar** names;
int ii;
m_ItemList = itemlist;
m_Parent = parent;
......@@ -58,34 +54,12 @@ WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* parent, const wxString& title,
m_WinMsg = NULL;
SetReturnCode( -1 );
if( itemlist )
for( names = m_ItemList, ii = 0; *names != NULL; names++ )
ii++;
else
ii = 30;
wxBoxSizer* GeneralBoxSizer = new wxBoxSizer( wxVERTICAL );
SetSizer( GeneralBoxSizer );
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxHORIZONTAL );
GeneralBoxSizer->Add( MainBoxSizer, 0, wxGROW | wxEXPAND | wxALL, 1 );
wxBoxSizer* LeftBoxSizer = new wxBoxSizer( wxVERTICAL );
MainBoxSizer->Add( LeftBoxSizer, 0, wxGROW | wxALL, 5 );
wxBoxSizer* RightBoxSizer = new wxBoxSizer( wxVERTICAL );
MainBoxSizer->Add( RightBoxSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5 );
size.x = 200;
size.y = 350;
m_List = new wxListBox( this,
ID_LISTBOX_LIST,
wxDefaultPosition, size,
0, NULL,
m_List = new wxListBox( this, ID_LISTBOX_LIST, wxDefaultPosition,
wxSize( 300, 200 ), 0, NULL,
wxLB_NEEDED_SB | wxLB_SINGLE | wxLB_HSCROLL );
if( colour != wxNullColour )
......@@ -93,38 +67,33 @@ WinEDAListBox::WinEDAListBox( WinEDA_DrawFrame* parent, const wxString& title,
m_List->SetBackgroundColour( colour );
m_List->SetForegroundColour( *wxBLACK );
}
LeftBoxSizer->Add( m_List, 0, wxGROW | wxALL, 5 );
GeneralBoxSizer->Add( m_List, 0, wxGROW | wxALL, 5 );
if( itemlist )
for( names = m_ItemList, ii = 0; *names != NULL; names++, ii++ )
{
for( names = m_ItemList; *names != NULL; names++ )
m_List->Append( *names );
}
wxButton* butt = new wxButton( this, wxID_OK, _( "OK" ) );
RightBoxSizer->Add( butt, 0, wxGROW | wxALL, 5 );
butt->SetDefault();
butt = new wxButton( this, wxID_CANCEL, _( "Cancel" ) );
RightBoxSizer->Add( butt, 0, wxGROW | wxALL, 5 );
if( m_MoveFct )
{
size.x = -1;
size.y = 60;
m_WinMsg = new wxTextCtrl( this, -1, wxEmptyString, wxDefaultPosition,
size, wxTE_READONLY | wxTE_MULTILINE );
m_WinMsg = new wxTextCtrl( this, -1, wxEmptyString,
wxDefaultPosition, wxSize( -1, 60 ),
wxTE_READONLY | wxTE_MULTILINE );
GeneralBoxSizer->Add( m_WinMsg, 0, wxGROW | wxALL, 5 );
}
wxSizer* buttonSizer = CreateButtonSizer( wxOK | wxCANCEL );
if( buttonSizer )
GeneralBoxSizer->Add( buttonSizer, 0, wxGROW | wxALL, 5 );
GetSizer()->Fit( this );
GetSizer()->SetSizeHints( this );
if( dialog_position == wxDefaultPosition ) // Put the window on the parent centre
if( dialog_position == wxDefaultPosition )
{
Centre();
}
......
......@@ -101,7 +101,6 @@ set(EESCHEMA_SRCS
plothpgl.cpp
plotps.cpp
plotdxf.cpp
priorque.cpp
read_from_file_schematic_items_descriptions.cpp
savelib.cpp
save_schemas.cpp
......
......@@ -512,7 +512,7 @@ void CopyMarkedItems( EDA_LibComponentStruct* LibEntry, wxPoint offset )
if( item->m_Selected == 0 )
continue;
item->m_Selected = 0;
LibEDA_BaseStruct* newitem = CopyDrawEntryStruct( item );
LibEDA_BaseStruct* newitem = item->GenCopy();
newitem->m_Selected = IS_SELECTED;
newitem->SetNext( LibEntry->m_Drawings );
LibEntry->m_Drawings = newitem;
......
......@@ -168,7 +168,7 @@ bool LibDrawText::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[
}
LibDrawText* LibDrawText::GenCopy()
LibEDA_BaseStruct* LibDrawText::DoGenCopy()
{
LibDrawText* newitem = new LibDrawText(NULL);
......@@ -185,7 +185,7 @@ LibDrawText* LibDrawText::GenCopy()
newitem->m_Bold = m_Bold;
newitem->m_HJustify = m_HJustify;
newitem->m_VJustify = m_VJustify;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
......@@ -247,4 +247,3 @@ void LibDrawText::DisplayInfo( WinEDA_DrawFrame* frame )
frame->MsgPanel->Affiche_1_Parametre( 20, _( "Line width" ), msg, BLUE );
}
......@@ -179,13 +179,13 @@ bool LibCmpEntry::operator==( const wxChar* name ) const
}
bool operator<( LibCmpEntry& item1, LibCmpEntry& item2 )
bool operator<( const LibCmpEntry& item1, const LibCmpEntry& item2 )
{
return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) == -1;
return item1.m_Name.m_Text.CmpNoCase( item2.m_Name.m_Text ) < 0;
}
int LibraryEntryCompare( LibCmpEntry* LE1, LibCmpEntry* LE2 )
int LibraryEntryCompare( const LibCmpEntry* LE1, const LibCmpEntry* LE2 )
{
return LE1->m_Name.m_Text.CmpNoCase( LE2->m_Name.m_Text );
}
......
......@@ -16,13 +16,15 @@
/* Types for components in libraries
* components can be a true component or an alias of a true component.
*/
enum LibrEntryType {
enum LibrEntryType
{
ROOT, /* This is a true component standard EDA_LibComponentStruct */
ALIAS /* This is an alias of a true component */
};
/* values for member .m_Options */
enum LibrEntryOptions {
enum LibrEntryOptions
{
ENTRY_NORMAL, // Libentry is a standard component (real or alias)
ENTRY_POWER // Libentry is a power symbol
};
......@@ -76,9 +78,10 @@ public:
typedef boost::ptr_vector< LibCmpEntry > LIB_ENTRY_LIST;
extern bool operator<( LibCmpEntry& item1, LibCmpEntry& item2 );
extern bool operator<( const LibCmpEntry& item1, const LibCmpEntry& item2 );
extern int LibraryEntryCompare( LibCmpEntry* LE1, LibCmpEntry* LE2 );
extern int LibraryEntryCompare( const LibCmpEntry* LE1,
const LibCmpEntry* LE2 );
/**
......@@ -173,7 +176,7 @@ public:
*
* @todo Alias objects should really be defined as children of a component
* object not as children of a library object. This would greatly
* simply searching for components in libraries.
* simplify searching for components in libraries.
*/
class EDA_LibCmpAliasStruct : public LibCmpEntry
{
......
......@@ -347,13 +347,13 @@ bool LibDrawField::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat
}
// Creation et Duplication d'un field
LibDrawField* LibDrawField::GenCopy()
LibEDA_BaseStruct* LibDrawField::DoGenCopy()
{
LibDrawField* newfield = new LibDrawField( m_FieldId );
Copy( newfield );
return newfield;
return (LibEDA_BaseStruct*) newfield;
}
......
......@@ -58,8 +58,6 @@ public:
virtual bool Save( FILE* aFile ) const;
virtual bool Load( char* line, wxString& errorMsg );
LibDrawField* GenCopy();
/** Function Copy
* copy parameters of this to Target. Pointers are not copied
* @param aTarget = the LibDrawField to set with "this" values
......@@ -104,6 +102,9 @@ public:
m_VJustify = field.m_VJustify;
m_Parent = field.m_Parent;
}
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
#endif // CLASS_LIBENTRY_FIELDS_H
......@@ -16,11 +16,7 @@
#include "protos.h"
#include "class_library.h"
void FreeLibraryEntry( LibCmpEntry* Entry )
{
SAFE_DELETE( Entry );
}
#include <boost/foreach.hpp>
bool operator==( const LibraryStruct& lib, const wxChar* name )
......@@ -41,13 +37,11 @@ LibraryStruct::LibraryStruct( int type, const wxString& name,
m_Type = type; /* type indicator */
m_Name = name; /* Name of library loaded. */
m_FullFileName = fullname; /* File name (with path) of library loaded. */
m_NumOfParts = 0; /* Number of parts this library has. */
m_Pnext = NULL; /* Point to next library in chain. */
m_Entries = NULL;
m_Modified = FALSE; /* flag indicateur d'edition */
m_IsModified = false; /* flag indicateur d'edition */
m_TimeStamp = 0;
m_Flags = 0;
m_IsLibCache = FALSE;
m_IsLibCache = false;
m_DateTime = wxDateTime::Now();
}
......@@ -63,19 +57,18 @@ LibraryStruct::LibraryStruct( const wxChar* fileName )
LibraryStruct::~LibraryStruct()
{
if( m_Entries )
PQFreeFunc( m_Entries, ( void( * ) ( void* ) )FreeLibraryEntry );
}
void LibraryStruct::GetEntryNames( wxArrayString& names, bool sort )
void LibraryStruct::GetEntryNames( wxArrayString& names, bool sort,
bool makeUpperCase )
{
LibCmpEntry* entry = ( LibCmpEntry* ) PQFirst( &m_Entries, false );
while( entry != NULL )
BOOST_FOREACH( LibCmpEntry& entry, m_Entries )
{
names.Add( entry->m_Name.m_Text );
entry = ( LibCmpEntry* ) PQNext( m_Entries, entry, NULL );
if( makeUpperCase )
names.Add( entry.m_Name.m_Text.MakeUpper() );
else
names.Add( entry.m_Name.m_Text );
}
if( sort )
......@@ -88,32 +81,30 @@ void LibraryStruct::SearchEntryNames( wxArrayString& names,
const wxString& keySearch,
bool sort )
{
LibCmpEntry* Entry;
Entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
while( Entry )
BOOST_FOREACH( LibCmpEntry& entry, m_Entries )
{
if( !keySearch.IsEmpty() && KeyWordOk( keySearch, Entry->m_KeyWord ) )
names.Add( Entry->m_Name.m_Text );
if( !keySearch.IsEmpty() && KeyWordOk( keySearch, entry.m_KeyWord ) )
names.Add( entry.m_Name.m_Text );
if( !nameSearch.IsEmpty() && WildCompareString( nameSearch,
Entry->m_Name.m_Text,
entry.m_Name.m_Text,
false ) )
names.Add( Entry->m_Name.m_Text );
Entry = (LibCmpEntry*) PQNext( m_Entries, Entry, NULL );
names.Add( entry.m_Name.m_Text );
}
if( sort )
names.Sort();
}
LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name )
{
static LibCmpEntry tmp( ALIAS, wxEmptyString );
tmp.m_Name.m_Text = name;
PQCompFunc( ( PQCompFuncType ) LibraryEntryCompare );
BOOST_FOREACH( LibCmpEntry& entry, m_Entries )
{
if( entry.m_Name.m_Text.CmpNoCase( name ) == 0 )
return &entry;
}
return ( LibCmpEntry* ) PQFind( m_Entries, &tmp );
return NULL;
}
......@@ -121,22 +112,14 @@ LibCmpEntry* LibraryStruct::FindEntry( const wxChar* name, LibrEntryType type )
{
LibCmpEntry* entry = FindEntry( name );
if( entry != NULL && entry->Type != ROOT && type == ROOT )
if( entry && entry->Type != ROOT && type == ROOT )
{
EDA_LibCmpAliasStruct* alias = ( EDA_LibCmpAliasStruct* ) entry;
const wxChar* rootname = alias->m_RootName.GetData();
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
while( entry )
{
if( entry->m_Name.m_Text.CmpNoCase( rootname ) == 0
&& entry->Type == ROOT )
break;
entry = FindEntry( alias->m_RootName );
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
}
if( entry && entry->Type != ROOT )
return NULL;
}
return entry;
......@@ -154,10 +137,8 @@ EDA_LibComponentStruct* LibraryStruct::AddComponent( EDA_LibComponentStruct* cmp
return NULL;
newCmp->m_AliasList.Clear();
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
PQInsert( &m_Entries, (void*) newCmp );
m_NumOfParts++;
m_Modified = 1;
m_Entries.push_back( (LibCmpEntry*) newCmp );
m_IsModified = true;
for( unsigned ii = 0; ii < cmp->m_AliasList.GetCount(); ii += ALIAS_NEXT )
{
......@@ -167,15 +148,30 @@ EDA_LibComponentStruct* LibraryStruct::AddComponent( EDA_LibComponentStruct* cmp
Alias->m_Doc = cmp->m_AliasList[ii + ALIAS_DOC];
Alias->m_KeyWord = cmp->m_AliasList[ii + ALIAS_KEYWORD];
Alias->m_DocFile = cmp->m_AliasList[ii + ALIAS_DOC_FILENAME];
PQInsert( &m_Entries, (void*) Alias );
m_NumOfParts++;
m_Entries.push_back( (LibCmpEntry *) Alias );
}
m_Entries.sort();
return newCmp;
}
void LibraryStruct::RemoveEntry( const wxString& name )
{
LIB_ENTRY_LIST::iterator i;
for( i = m_Entries.begin(); i < m_Entries.end(); i++ )
{
if( i->m_Name.m_Text.CmpNoCase( name ) == 0 )
{
m_Entries.erase( i );
return;
}
}
}
void LibraryStruct::RemoveEntry( LibCmpEntry* entry )
{
wxASSERT( entry != NULL );
......@@ -183,8 +179,7 @@ void LibraryStruct::RemoveEntry( LibCmpEntry* entry )
EDA_LibComponentStruct* Root;
EDA_LibCmpAliasStruct* Alias;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
m_Modified = 1;
m_IsModified = true;
if( entry->Type == ALIAS )
{
......@@ -213,35 +208,25 @@ alias list in library <%s>" ),
Root->m_AliasList.RemoveAt( index );
}
/* Effacement memoire pour cet alias */
PQDelete( &m_Entries, (void*) Alias );
SAFE_DELETE( Alias );
if( m_NumOfParts > 0 )
m_NumOfParts--;
RemoveEntry( Alias->m_Name.m_Text );
return;
}
Root = ( EDA_LibComponentStruct* ) entry;
/* Entry is a component with no aliases so removal is simple */
/* Entry is a component with no aliases so removal is simple. */
if( Root->m_AliasList.GetCount() == 0 )
{
PQDelete( &m_Entries, (void*) Root );
SAFE_DELETE( Root );
if( m_NumOfParts > 0 )
m_NumOfParts--;
RemoveEntry( Root->m_Name.m_Text );
return;
}
/* Entry is a component with alias
* We must change the first alias to a "root" component, and for all the
* aliases we must change the root component (which is deleted) by the
* first alias */
/* Entry is a component with one or more alias. */
wxString AliasName = Root->m_AliasList[0];
/* The root component is not really deleted, it is renamed with the first
* alias name */
* alias name. */
Alias = (EDA_LibCmpAliasStruct*) FindEntry( AliasName, ALIAS );
if( Alias == NULL || Alias->Type == ROOT )
......@@ -251,41 +236,32 @@ library <%s>" ),
( const wxChar* ) AliasName,
( const wxChar* ) Root->m_Name.m_Text,
( const wxChar* ) m_Name );
return;
}
else
{
if( m_NumOfParts > 0 )
m_NumOfParts--;
/* remove the root component from library */
PQDelete( &m_Entries, Root );
/* remove the first alias from library*/
PQDelete( &m_Entries, Alias );
/* remove the first alias name from alias list: */
/* Remove the first alias name from the component alias list. */
Root->m_AliasList.RemoveAt( 0 );
/* change the old name. New name for "root" is the name of the first
* alias */
entry->m_Name.m_Text = AliasName;
entry->m_Doc = Alias->m_Doc;
entry->m_KeyWord = Alias->m_KeyWord;
FreeLibraryEntry( ( LibCmpEntry* ) Alias );
/* Rename the component to the name of the first alias. */
Root->m_Doc = Alias->m_Doc;
Root->m_KeyWord = Alias->m_KeyWord;
/* root component (renamed) placed in library */
PQInsert( &m_Entries, entry );
}
/* Remove the first alias from library. */
RemoveEntry( AliasName );
/* Change the "RootName", for other aliases */
for( unsigned ii = 0; ii < Root->m_AliasList.GetCount(); ii++ )
Root->m_Name.m_Text = AliasName;
/* Change the "RootName" for all other aliases */
for( size_t ii = 0; ii < Root->m_AliasList.GetCount(); ii++ )
{
AliasName = Root->m_AliasList[ii];
Alias = (EDA_LibCmpAliasStruct*) FindEntry( AliasName, ALIAS );
Alias = (EDA_LibCmpAliasStruct*) FindEntry( Root->m_AliasList[ii],
ALIAS );
if( Alias == NULL )
/* 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 || Alias->Type != ALIAS )
{
// Should not occurs. If happens, this is an error (or bug)
wxLogWarning( wxT( "Alias <%s> for component <%s> not found in \
library <%s>." ),
( const wxChar* ) AliasName,
......@@ -293,41 +269,31 @@ library <%s>." ),
( const wxChar* ) m_Name );
continue;
}
if( Alias->Type != ALIAS )
{
// Should not occurs. If happens, this is an error (or bug)
wxLogWarning( wxT( "Entry <%s> for component <%s> in library \
<%s> is not an alias." ),
( const wxChar* ) AliasName,
( const wxChar* ) Root->m_Name.m_Text,
( const wxChar* ) m_Name );
continue;
}
Alias->m_RootName = entry->m_Name.m_Text;
Alias->m_RootName = Root->m_Name.m_Text;
}
}
LibCmpEntry* LibraryStruct::GetNextEntry( const wxChar* name )
{
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
LibCmpEntry* entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
size_t i;
LibCmpEntry* entry = NULL;
while( entry )
for( i = 0; i < m_Entries.size(); i++ )
{
if( entry->m_Name.m_Text.CmpNoCase( name ) == 0 )
if( m_Entries[i].m_Name.m_Text.CmpNoCase( name ) == 0 )
{
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
if( i < m_Entries.size() - 1 )
{
entry = &m_Entries[ i + 1 ];
break;
}
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
}
}
if( entry == NULL )
entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
entry = &m_Entries.front();
return entry;
}
......@@ -335,45 +301,18 @@ LibCmpEntry* LibraryStruct::GetNextEntry( const wxChar* name )
LibCmpEntry* LibraryStruct::GetPreviousEntry( const wxChar* name )
{
LibCmpEntry* previousEntry = NULL;
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
size_t i;
LibCmpEntry* entry = NULL;
LibCmpEntry* entry = (LibCmpEntry*) PQFirst( &m_Entries, false );
while( entry )
{
if( entry->m_Name.m_Text.CmpNoCase( name ) == 0 )
for( i = 0; i < m_Entries.size(); i++ )
{
if( previousEntry )
if( m_Entries[i].m_Name.m_Text.CmpNoCase( name ) == 0 && entry )
break;
}
previousEntry = entry;
entry = (LibCmpEntry*) PQNext( m_Entries, entry, NULL );
entry = &m_Entries[i];
}
return previousEntry;
}
bool LibraryStruct::WriteHeader( FILE* file )
{
char BufLine[1024];
bool succes = false;
DateAndTime( BufLine );
if( fprintf( file, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
succes = false;
#if 0
if( ( fprintf( file, "$HEADER\n" ) < 0 )
|| ( fprintf( file, "TimeStamp %8.8lX\n", m_TimeStamp ) < 0 )
|| ( fprintf( file, "Parts %d\n", m_NumOfParts ) != 2 )
|| ( fprintf( file, "$ENDHEADER\n" ) != 1 ) )
succes = false;
#endif
return succes;
return entry;
}
......@@ -399,8 +338,6 @@ bool LibraryStruct::Load( wxString& errMsg )
return false;
}
m_NumOfParts = 0;
if( GetLine( f, Line, &LineNum, sizeof( Line ) ) == NULL )
{
errMsg = _( "file is empty!" );
......@@ -413,9 +350,6 @@ bool LibraryStruct::Load( wxString& errMsg )
return false;
}
PQInit( &m_Entries );
PQCompFunc( (PQCompFuncType) LibraryEntryCompare );
/* There is no header if this is a symbol library. */
if( m_Type == LIBRARY_TYPE_EESCHEMA )
m_Header = CONV_FROM_UTF8( Line );
......@@ -425,7 +359,7 @@ bool LibraryStruct::Load( wxString& errMsg )
if( m_Type == LIBRARY_TYPE_EESCHEMA
&& strnicmp( Line, "$HEADER", 7 ) == 0 )
{
if( !ReadHeader( f, &LineNum ) )
if( !LoadHeader( f, &LineNum ) )
{
errMsg = _( "header read error" );
return false;
......@@ -442,9 +376,8 @@ bool LibraryStruct::Load( wxString& errMsg )
if( LibEntry->Load( f, Line, &LineNum, msg ) )
{
/* If we are here, this part is O.k. - put it in: */
m_NumOfParts += 1;
PQInsert( &m_Entries, LibEntry );
InsertAliases( &m_Entries, LibEntry );
m_Entries.push_back( LibEntry );
LoadAliases( LibEntry );
}
else
{
......@@ -457,14 +390,15 @@ bool LibraryStruct::Load( wxString& errMsg )
}
}
m_Entries.sort();
return true;
}
void LibraryStruct::InsertAliases( PriorQue** PQ,
EDA_LibComponentStruct* component )
void LibraryStruct::LoadAliases( EDA_LibComponentStruct* component )
{
wxASSERT( component != NULL && PQ != NULL );
wxASSERT( component != NULL );
EDA_LibCmpAliasStruct* AliasEntry;
unsigned ii;
......@@ -474,13 +408,12 @@ void LibraryStruct::InsertAliases( PriorQue** PQ,
AliasEntry =
new EDA_LibCmpAliasStruct( component->m_AliasList[ii],
component->m_Name.m_Text );
PQInsert( PQ, AliasEntry );
m_NumOfParts += 1;
m_Entries.push_back( AliasEntry );
}
}
bool LibraryStruct::ReadHeader( FILE* libfile, int* LineNum )
bool LibraryStruct::LoadHeader( FILE* libfile, int* LineNum )
{
char Line[1024], * text, * data;
......@@ -498,7 +431,93 @@ bool LibraryStruct::ReadHeader( FILE* libfile, int* LineNum )
}
bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
bool LibraryStruct::LoadDocs( wxString& errMsg )
{
int LineNum = 0;
char Line[1024], * Name, * Text;
LibCmpEntry* Entry;
FILE* f;
wxString msg;
wxFileName fn;
fn = m_FullFileName;
fn.SetExt( DOC_EXT );
f = wxFopen( fn.GetFullPath(), wxT( "rt" ) );
if( f == NULL )
{
errMsg.Printf( _( "Could not open component document libray file\n<%s>." ),
(const wxChar*) fn.GetFullPath() );
return false;
}
if( GetLine( f, Line, &LineNum, sizeof(Line) ) == NULL )
{
errMsg.Printf( _( "Component document libray file <%s> is empty." ),
(const wxChar*) fn.GetFullPath() );
fclose( f );
return false;
}
if( strnicmp( Line, DOCFILE_IDENT, 10 ) != 0 )
{
errMsg.Printf( _( "File <%s> is not a valid component library \
document file." ),
(const wxChar*) fn.GetFullPath() );
fclose( f );
return false;
}
while( GetLine( f, Line, &LineNum, sizeof(Line) ) )
{
if( strncmp( Line, "$CMP", 4 ) != 0 )
{
errMsg.Printf( wxT( "$CMP command expected in line %d, aborted." ),
LineNum );
fclose( f );
return false;
}
/* Read one $CMP/$ENDCMP part entry from library: */
Name = strtok( Line + 5, "\n\r" );
wxString cmpname = CONV_FROM_UTF8( Name );
Entry = FindEntry( cmpname, ALIAS );
while( GetLine( f, Line, &LineNum, sizeof(Line) ) )
{
if( strncmp( Line, "$ENDCMP", 7 ) == 0 )
break;
Text = strtok( Line + 2, "\n\r" );
switch( Line[0] )
{
case 'D':
if( Entry )
Entry->m_Doc = CONV_FROM_UTF8( Text );
break;
case 'K':
if( Entry )
Entry->m_KeyWord = CONV_FROM_UTF8( Text );
break;
case 'F':
if( Entry )
Entry->m_DocFile = CONV_FROM_UTF8( Text );
break;
}
}
}
fclose( f );
return true;
}
bool LibraryStruct::Save( const wxString& FullFileName )
{
FILE* libfile, *docfile;
wxString msg;
......@@ -538,7 +557,6 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
}
}
libfile = wxFopen( libFileName.GetFullPath(), wxT( "wt" ) );
if( libfile == NULL )
......@@ -557,11 +575,11 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
DisplayError( NULL, msg );
}
m_Modified = 0;
m_IsModified = false;
/* Creation de l'entete de la librairie */
m_TimeStamp = GetTimeStamp();
WriteHeader( libfile );
SaveHeader( libfile );
/* Sauvegarde des composant: */
char Line[256];
......@@ -570,24 +588,20 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
bool success = true;
LibCmpEntry* entry = ( LibCmpEntry* ) PQFirst( &m_Entries, false );
while( entry != NULL )
BOOST_FOREACH( LibCmpEntry& entry, m_Entries )
{
if ( entry->Type == ROOT )
if ( entry.Type == ROOT )
{
EDA_LibComponentStruct* component =
( EDA_LibComponentStruct* ) entry;
( EDA_LibComponentStruct* ) &entry;
if ( ! component->Save( libfile ) )
success = false;
}
if ( docfile )
{
if ( ! entry->SaveDoc( docfile ) )
if ( ! entry.SaveDoc( docfile ) )
success = false;
}
entry = ( LibCmpEntry* ) PQNext( m_Entries, entry, NULL );
}
fprintf( libfile, "#\n#End Library\n" );
......@@ -599,6 +613,26 @@ bool LibraryStruct::SaveLibrary( const wxString& FullFileName )
}
bool LibraryStruct::SaveHeader( FILE* file )
{
char BufLine[1024];
bool succes = false;
DateAndTime( BufLine );
if( fprintf( file, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
succes = false;
#if 0
if( ( fprintf( file, "$HEADER\n" ) < 0 )
|| ( fprintf( file, "TimeStamp %8.8lX\n", m_TimeStamp ) < 0 )
|| ( fprintf( file, "Parts %d\n", m_Entries.size() ) != 2 )
|| ( fprintf( file, "$ENDHEADER\n" ) != 1 ) )
succes = false;
#endif
return succes;
}
wxString LibraryStruct::GetName()
{
return m_Name;
......
......@@ -9,9 +9,12 @@
#include "class_libentry.h"
/******************************/
/* Class to handle a library */
/******************************/
/**
* Component library object.
*
* Component libraries are used to load, save, search, and otherwise manipulate
* component library files.
*/
class LibraryStruct
{
......@@ -20,10 +23,7 @@ public:
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. */
int m_NumOfParts; /* Number of parts this library has. */
LibraryStruct* m_Pnext; /* Point on next lib in chain. */
int m_Modified; /* flag indicateur d'edition */
int m_Size; // Size in bytes (for statistics)
unsigned long m_TimeStamp; // Signature temporelle
int m_Flags; // variable used in some functions
bool m_IsLibCache; /* False for the "standard" libraries,
......@@ -46,14 +46,26 @@ public:
*
* @return bool - true if success writing else false.
*/
bool SaveLibrary( const wxString& aFullFileName );
bool ReadHeader( FILE* file, int* LineNum );
bool Save( const wxString& aFullFileName );
/**
* Load library from file.
*
* @param errMsg - Error message if load fails.
*
* @return bool - True if load was successful otherwise false.
*/
bool Load( wxString& errMsg );
void InsertAliases( PriorQue** PQ, EDA_LibComponentStruct* component );
bool LoadDocs( wxString& errMsg );
private:
bool WriteHeader( FILE* file );
bool SaveHeader( FILE* file );
bool LoadHeader( FILE* file, int* LineNum );
void LoadAliases( EDA_LibComponentStruct* component );
void RemoveEntry( const wxString& name );
public:
LibraryStruct( const wxChar* fileName = NULL );
......@@ -65,7 +77,22 @@ public:
*/
bool IsEmpty()
{
return m_Entries == NULL;
return m_Entries.empty();
}
/**
* Get the number of entries in the library.
*
* @return The number of component and alias entries.
*/
int GetCount()
{
return m_Entries.size();
}
bool IsModified()
{
return m_IsModified;
}
/**
......@@ -73,8 +100,10 @@ public:
*
* @param names - String array to place entry names into.
* @param sort - Sort names if true.
* @param makeUpperCase - Force entry names to upper case.
*/
void GetEntryNames( wxArrayString& names, bool sort = true );
void GetEntryNames( wxArrayString& names, bool sort = true,
bool makeUpperCase = true );
/**
* Load string array with entry names matching name and/or key word.
......@@ -150,7 +179,7 @@ public:
*/
LibCmpEntry* GetFirstEntry()
{
return (LibCmpEntry*) PQFirst( &m_Entries, false );
return &m_Entries.front();
}
/**
......@@ -180,23 +209,19 @@ public:
*/
LibCmpEntry* GetPreviousEntry( const wxChar* name );
bool Save( const wxString& saveAsFile );
wxString GetName();
protected:
wxFileName m_fileName; /* Library file name. */
wxDateTime m_DateTime; /* Library save time and date. */
wxString m_Version; /* Library save version. */
PriorQue* m_Entries; /* Parts themselves are saved here. */
LIB_ENTRY_LIST m_Entries; /* Parts themselves are saved here. */
bool m_IsModified; /* Library modification status. */
friend class EDA_LibComponentStruct;
};
extern void FreeLibraryEntry( LibCmpEntry* Entry );
/**
* Case insensitive library name comparison.
*/
......
......@@ -73,7 +73,8 @@ bool LibDrawPin::HitTest( const wxPoint& aRefPos )
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
*/
bool LibDrawPin::HitTest( wxPoint aRefPos, int aThreshold, const int aTransMat[2][2] )
bool LibDrawPin::HitTest( wxPoint aRefPos, int aThreshold,
const int aTransMat[2][2] )
{
wxPoint pinPos = TransformCoordinate( aTransMat, m_Pos );
wxPoint pinEnd = TransformCoordinate( aTransMat, ReturnPinEndPoint() );
......@@ -286,7 +287,6 @@ int LibDrawPin::GetPenSize( )
}
/**********************************************************************************************/
void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel,
wxDC* aDC,
const wxPoint& aOffset,
......@@ -294,10 +294,9 @@ void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel,
int aDrawMode,
void* aData,
const int aTransformMatrix[2][2] )
/**********************************************************************************************/
{
// Invisibles pins are only drawn on request.
// But in libedit they are drawn in g_InvisibleItemColor because we must see them
// Invisible pins are only drawn on request. In libedit they are drawn
// in g_InvisibleItemColor because we must see them.
WinEDA_SchematicFrame* frame =
(WinEDA_SchematicFrame*) wxGetApp().GetTopWindow();
......@@ -312,7 +311,7 @@ void LibDrawPin::Draw( WinEDA_DrawPanel* aPanel,
EDA_LibComponentStruct* Entry = ( (DrawPinPrms*) aData )->m_Entry;
bool DrawPinText = ( (DrawPinPrms*) aData )->m_DrawPinText;
/* Calculate Pin orient takin in account the component orientation */
/* Calculate pin orient taking in account the component orientation. */
int orient = ReturnPinDrawOrient( aTransformMatrix );
/* Calculate the pin position */
......@@ -655,8 +654,7 @@ void LibDrawPin::DrawPinTexts( WinEDA_DrawPanel* panel,
if( DrawPinName )
{
x = (x1 + pin_pos.x) / 2;
DrawGraphicText( panel, DC, wxPoint( x,
y1 - TXTMARGE ),
DrawGraphicText( panel, DC, wxPoint( x, y1 - TXTMARGE ),
NameColor, m_PinName,
TEXT_ORIENT_HORIZ, PinNameSize,
GR_TEXT_HJUSTIFY_CENTER,
......@@ -666,8 +664,7 @@ void LibDrawPin::DrawPinTexts( WinEDA_DrawPanel* panel,
if( DrawPinNum )
{
x = (x1 + pin_pos.x) / 2;
DrawGraphicText( panel, DC, wxPoint( x,
y1 + TXTMARGE ),
DrawGraphicText( panel, DC, wxPoint( x, y1 + TXTMARGE ),
NumColor, StringPinNum,
TEXT_ORIENT_HORIZ, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
......@@ -680,8 +677,7 @@ void LibDrawPin::DrawPinTexts( WinEDA_DrawPanel* panel,
if( DrawPinName )
{
y = (y1 + pin_pos.y) / 2;
DrawGraphicText( panel, DC, wxPoint( x1 - TXTMARGE,
y ),
DrawGraphicText( panel, DC, wxPoint( x1 - TXTMARGE, y ),
NameColor, m_PinName,
TEXT_ORIENT_VERT, PinNameSize,
GR_TEXT_HJUSTIFY_CENTER,
......@@ -692,8 +688,7 @@ void LibDrawPin::DrawPinTexts( WinEDA_DrawPanel* panel,
if( DrawPinNum )
{
DrawGraphicText( panel, DC,
wxPoint( x1 + TXTMARGE,
(y1 + pin_pos.y) / 2 ),
wxPoint( x1 + TXTMARGE, (y1 + pin_pos.y) / 2 ),
NumColor, StringPinNum,
TEXT_ORIENT_VERT, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
......@@ -784,7 +779,8 @@ void LibDrawPin::PlotPinTexts( PLOTTER *plotter,
}
if( DrawPinNum )
{
plotter->text( wxPoint( (x1 + pin_pos.x) / 2, y1 - TXTMARGE ),
plotter->text( wxPoint( (x1 + pin_pos.x) / 2,
y1 - TXTMARGE ),
NumColor, StringPinNum,
TEXT_ORIENT_HORIZ, PinNumSize,
GR_TEXT_HJUSTIFY_CENTER,
......@@ -1018,7 +1014,7 @@ void LibDrawPin::SetPinNumFromString( wxString& buffer )
/*************************************/
LibDrawPin* LibDrawPin::GenCopy()
LibEDA_BaseStruct* LibDrawPin::DoGenCopy()
/*************************************/
{
LibDrawPin* newpin = new LibDrawPin( GetParent() );
......@@ -1043,7 +1039,7 @@ LibDrawPin* LibDrawPin::GenCopy()
newpin->m_PinName = m_PinName;
return newpin;
return (LibEDA_BaseStruct*) newpin;
}
......
......@@ -218,7 +218,7 @@ bool LibDrawArc::HitTest( wxPoint aRefPoint, int aThreshold, const int aTransMat
}
LibDrawArc* LibDrawArc::GenCopy()
LibEDA_BaseStruct* LibDrawArc::DoGenCopy()
{
LibDrawArc* newitem = new LibDrawArc( GetParent() );
......@@ -233,7 +233,7 @@ LibDrawArc* LibDrawArc::GenCopy()
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
newitem->m_Fill = m_Fill;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
......@@ -477,7 +477,7 @@ bool LibDrawCircle::HitTest( wxPoint aPosRef, int aThreshold, const int aTransMa
}
LibDrawCircle* LibDrawCircle::GenCopy()
LibEDA_BaseStruct* LibDrawCircle::DoGenCopy()
{
LibDrawCircle* newitem = new LibDrawCircle( GetParent() );
......@@ -488,7 +488,7 @@ LibDrawCircle* LibDrawCircle::GenCopy()
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
newitem->m_Fill = m_Fill;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
......@@ -619,7 +619,7 @@ bool LibDrawSquare::Load( char* line, wxString& errorMsg )
}
LibDrawSquare* LibDrawSquare::GenCopy()
LibEDA_BaseStruct* LibDrawSquare::DoGenCopy()
{
LibDrawSquare* newitem = new LibDrawSquare( GetParent() );
......@@ -630,7 +630,7 @@ LibDrawSquare* LibDrawSquare::GenCopy()
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
newitem->m_Fill = m_Fill;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
......@@ -788,7 +788,7 @@ bool LibDrawSegment::Load( char* line, wxString& errorMsg )
}
LibDrawSegment* LibDrawSegment::GenCopy()
LibEDA_BaseStruct* LibDrawSegment::DoGenCopy()
{
LibDrawSegment* newitem = new LibDrawSegment( GetParent() );
......@@ -798,7 +798,7 @@ LibDrawSegment* LibDrawSegment::GenCopy()
newitem->m_Unit = m_Unit;
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
......@@ -976,7 +976,7 @@ bool LibDrawPolyline::Load( char* line, wxString& errorMsg )
}
LibDrawPolyline* LibDrawPolyline::GenCopy()
LibEDA_BaseStruct* LibDrawPolyline::DoGenCopy()
{
LibDrawPolyline* newitem = new LibDrawPolyline( GetParent() );
......@@ -986,7 +986,7 @@ LibDrawPolyline* LibDrawPolyline::GenCopy()
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
newitem->m_Fill = m_Fill;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
......@@ -1238,7 +1238,7 @@ bool LibDrawBezier::Load( char* line, wxString& errorMsg )
}
LibDrawBezier* LibDrawBezier::GenCopy()
LibEDA_BaseStruct* LibDrawBezier::DoGenCopy()
{
LibDrawBezier* newitem = new LibDrawBezier(GetParent());
......@@ -1248,7 +1248,7 @@ LibDrawBezier* LibDrawBezier::GenCopy()
newitem->m_Convert = m_Convert;
newitem->m_Flags = m_Flags;
newitem->m_Fill = m_Fill;
return newitem;
return (LibEDA_BaseStruct*) newitem;
}
/** Function GetPenSize
......
/****************************************************************/
/* Headers fo library definition and lib component definitions */
/* Headers for library definition and lib component definitions */
/****************************************************************/
/* Definitions of graphic items used to create shapes in component libraries.
......@@ -92,7 +92,7 @@ public:
};
/****************************************************************************/
/* Classes for handle the body items of a compoment: pins add graphic items */
/* Classes for handle the body items of a component: pins add graphic items */
/****************************************************************************/
......@@ -103,7 +103,7 @@ public:
class LibEDA_BaseStruct : public EDA_BaseStruct
{
public:
int m_Unit; /* Unit identification (for multi part per parkage)
int m_Unit; /* Unit identification (for multi part per package)
* 0 if the item is common to all units */
int m_Convert; /* Shape identification (for parts which have a convert
* shape) 0 if the item is common to all shapes */
......@@ -130,12 +130,12 @@ public:
* @param aColor = -1 to use the normal body item color, or use this color
* if >= 0
* @param aDrawMode = GR_OR, GR_XOR, ...
* @param aData = value or pointer used to pass others parametres,
* @param aData = value or pointer used to pass others parameters,
* depending on body items. used for some items to force
* to force no fill mode ( has meaning only for items what
* can be filled ). used in printing or moving objects mode
* or to pass refernce to the lib component for pins
* @param aTransformMatrix = Transform Matrix (rotaion, mirror ..)
* or to pass reference to the lib component for pins
* @param aTransformMatrix = Transform Matrix (rotation, mirror ..)
*/
virtual void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC,
const wxPoint &aOffset, int aColor, int aDrawMode,
......@@ -172,13 +172,15 @@ public:
return false; // derived classes should override this function
}
/** Function HitTest (overlayed)
/** Function HitTest (overlaid)
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] ) = 0;
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] ) = 0;
/** Function GetBoundingBox
* @return the boundary box for this, in library coordinates
......@@ -189,6 +191,19 @@ public:
}
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
/**
* Make a copy of this draw item.
*
* Classes derived from LibEDA_BaseStruct must implement DoGenCopy().
* This is just a placeholder for the derived class.
*
* @return Copy of this draw item.
*/
LibEDA_BaseStruct* GenCopy() { return DoGenCopy(); }
protected:
virtual LibEDA_BaseStruct* DoGenCopy() = 0;
};
......@@ -198,22 +213,25 @@ public:
class LibDrawPin : public LibEDA_BaseStruct
{
public:
int m_PinLen; /* Pin lenght */
int m_PinLen; /* Pin length */
int m_Orient; /* Pin orientation (Up, Down, Left, Right) */
int m_PinShape; /* Bitwise ORed: Pin shape (see enum DrawPinShape) */
int m_PinType; /* Electrical pin properties */
int m_Attributs; /* bit 0 != 0: pin invisible */
long m_PinNum; /* Pin number: 4 Ascii code like "12" or "anod"
long m_PinNum; /* Pin number: 4 ASCII code like "12" or "anod"
* or "G6" "12" is stored as "12\0\0" ans does not
* depend on endian type*/
wxString m_PinName;
int m_PinNumSize;
int m_PinNameSize; /* Pin num and Pin name sizes */
// (Currently Unused) Pin num and Pin name text opt: italic/normal/bold, 0 = default:
char m_PinNumShapeOpt, m_PinNameShapeOpt;
/* (Currently Unused) Pin num and Pin name text options: italic/normal
* /bold, 0 = default */
char m_PinNumShapeOpt;
char m_PinNameShapeOpt;
// (Currently Unused) Pin num and Pin name text opt position, 0 = default:
char m_PinNumPositionOpt, m_PinNamePositionOpt;
char m_PinNumPositionOpt;
char m_PinNamePositionOpt;
wxPoint m_Pos; /* Position or centre (Arc and Circle) or start
* point (segments) */
......@@ -254,12 +272,13 @@ public:
/** Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
LibDrawPin* GenCopy();
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
virtual EDA_Rect GetBoundingBox();
wxPoint ReturnPinEndPoint();
......@@ -268,16 +287,18 @@ public:
/** Function ReturnPinStringNum
* fill a buffer with pin num as a wxString
* Pin num is coded as a long or 4 ascii chars
* Pin num is coded as a long or 4 ASCII chars
* Used to print/draw the pin num
* @param aStringBuffer = the wxString to store the pin num as an unicode string
* @param aStringBuffer = the wxString to store the pin num as an unicode
* string
*/
void ReturnPinStringNum( wxString& aStringBuffer ) const;
/** Function ReturnPinStringNum (static function)
* Pin num is coded as a long or 4 ascii chars
* @param aPinNum = a long containing a pin num
* @return aStringBuffer = the wxString to store the pin num as an unicode string
* @return aStringBuffer = the wxString to store the pin num as an
* unicode string
*/
static wxString ReturnPinStringNum( long aPinNum );
......@@ -307,6 +328,9 @@ public:
bool DrawPinNum,
bool DrawPinNameint,
int aWidth);
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
......@@ -355,12 +379,12 @@ public:
/** Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
LibDrawArc* GenCopy();
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
void Draw( WinEDA_DrawPanel * aPanel, wxDC * aDC, const wxPoint &aOffset,
int aColor, int aDrawMode, void* aData,
......@@ -373,6 +397,8 @@ public:
*/
virtual int GetPenSize( );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
......@@ -417,12 +443,12 @@ public:
/** Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
LibDrawCircle* GenCopy();
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
......@@ -435,6 +461,9 @@ public:
virtual EDA_Rect GetBoundingBox();
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
......@@ -479,7 +508,8 @@ public:
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/**
* Function HitTest (overlayed)
......@@ -493,8 +523,6 @@ public:
return TextHitTest( refArea );
}
LibDrawText* GenCopy();
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
......@@ -505,6 +533,9 @@ public:
const int aTransformMatrix[2][2] );
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
......@@ -548,12 +579,12 @@ public:
/** Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
LibDrawSquare* GenCopy();
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
......@@ -566,6 +597,9 @@ public:
virtual EDA_Rect GetBoundingBox();
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
/**********************************/
......@@ -609,12 +643,12 @@ public:
/** Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aThreshold = max distance to this object (usually the half
* thickness of a line)
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
LibDrawSegment* GenCopy();
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/** Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
......@@ -626,6 +660,9 @@ public:
const int aTransformMatrix[2][2] );
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
......@@ -658,7 +695,6 @@ public:
virtual bool Save( FILE* aFile ) const;
virtual bool Load( char* line, wxString& errorMsg );
LibDrawPolyline* GenCopy();
void AddPoint( const wxPoint& point );
/** Function GetCornerCount
......@@ -680,7 +716,8 @@ public:
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/** Function GetBoundingBox
* @return the boundary box for this, in library coordinates
......@@ -697,6 +734,9 @@ public:
const int aTransformMatrix[2][2] );
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
/**********************************************************/
......@@ -729,7 +769,6 @@ public:
virtual bool Save( FILE* aFile ) const;
virtual bool Load( char* line, wxString& errorMsg );
LibDrawBezier* GenCopy();
void AddPoint( const wxPoint& point );
/** Function GetCornerCount
......@@ -751,7 +790,8 @@ public:
* @param aThreshold = max distance to a segment
* @param aTransMat = the transform matrix
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const int aTransMat[2][2] );
virtual bool HitTest( wxPoint aPosRef, int aThreshold,
const int aTransMat[2][2] );
/** Function GetBoundingBox
* @return the boundary box for this, in library coordinates
......@@ -768,6 +808,9 @@ public:
const int aTransformMatrix[2][2] );
virtual void DisplayInfo( WinEDA_DrawFrame* frame );
protected:
virtual LibEDA_BaseStruct* DoGenCopy();
};
#endif // CLASSES_BODY_ITEMS_H
......@@ -77,13 +77,22 @@ wxString DataBaseGetName( WinEDA_DrawFrame* frame, wxString& Keys,
void DisplayCmpDoc( wxString& Name )
{
LibCmpEntry* CmpEntry;
LibCmpEntry* CmpEntry = NULL;
LibraryStruct* Lib = g_LibraryList;
CmpEntry = FindLibPart( Name, wxEmptyString, ALIAS );
while( Lib != NULL && CmpEntry == NULL )
{
CmpEntry = Lib->FindEntry( Name );
Lib = Lib->m_Pnext;
}
if( CmpEntry == NULL )
return;
wxLogDebug( wxT( "Selected component <%s>, m_Doc: <%s>, m_KeyWord: <%s>." ),
(const wxChar*) Name, (const wxChar*) CmpEntry->m_Doc,
(const wxChar*) CmpEntry->m_KeyWord );
Name = wxT( "Description: " ) + CmpEntry->m_Doc;
Name += wxT( "\nKey Words: " ) + CmpEntry->m_KeyWord;
}
......@@ -452,7 +452,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::ChangeNbUnitsPerPackage( int MaxUnit )
{
for( ii = OldNumUnits + 1; ii <= MaxUnit; ii++ )
{
NextDrawItem = CopyDrawEntryStruct( DrawItem );
NextDrawItem = DrawItem->GenCopy();
NextDrawItem->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = NextDrawItem;
NextDrawItem->m_Unit = ii;
......@@ -499,7 +499,7 @@ bool DIALOG_EDIT_COMPONENT_IN_LIBRARY::SetUnsetConvert()
g_AsDeMorgan = 0; return FALSE;
}
}
NextDrawItem = CopyDrawEntryStruct( DrawItem );
NextDrawItem = DrawItem->GenCopy();
NextDrawItem->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = NextDrawItem;
NextDrawItem->m_Convert = 2;
......
......@@ -18,15 +18,15 @@
#include "dialog_load_error.h"
/****************************************************************************/
/** Function LoadLibraryName
/**
* 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 )
......@@ -60,9 +60,7 @@ LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame,
tmplib->m_Pnext = NewLib;
}
fn = FullLibName;
fn.SetExt( DOC_EXT );
LoadDocLib( frame, fn.GetFullPath(), NewLib->m_Name );
NewLib->LoadDocs( errMsg );
}
else
{
......@@ -79,7 +77,9 @@ library <%s>" ),
}
/** Function LoadLibraries
/**
* Function LoadLibraries
*
* Clear all already loaded libraries and load all librairies
* given in frame->m_ComponentLibFiles
*/
......@@ -200,12 +200,11 @@ void LoadLibraries( WinEDA_SchematicFrame* frame )
}
/**************************************************************/
/** Function FreeCmpLibrary
/**
* Function FreeCmpLibrary
*
* Routine to remove and free a library from the current loaded libraries.
*/
/**************************************************************/
void FreeCmpLibrary( wxWindow* frame, const wxString& LibName )
{
int NumOfLibs = NumOfLibraries();
......@@ -247,7 +246,9 @@ void FreeCmpLibrary( wxWindow* frame, const wxString& LibName )
}
/** Function LibraryEntryCompare
/**
* Function LibraryEntryCompare
*
* Routine to compare two EDA_LibComponentStruct for the PriorQue module.
* Comparison (insensitive case) is based on Part name.
*/
......@@ -259,8 +260,8 @@ int LibraryEntryCompare( EDA_LibComponentStruct* LE1,
/*****************************************************************************
* Routine to find the library given its name. *
*****************************************************************************/
* Routine to find the library given its name.
*****************************************************************************/
LibraryStruct* FindLibrary( const wxString& Name )
{
LibraryStruct* Lib = g_LibraryList;
......@@ -277,8 +278,8 @@ LibraryStruct* FindLibrary( const wxString& Name )
/*****************************************************************************
* Routine to find the number of libraries currently loaded. *
*****************************************************************************/
* Routine to find the number of libraries currently loaded.
*****************************************************************************/
int NumOfLibraries()
{
int ii;
......@@ -289,83 +290,3 @@ int NumOfLibraries()
return ii;
}
/*******************************************************/
/* Routines de lecture des Documentation de composants */
/*******************************************************/
/* Routine to load a library from given open file.*/
int LoadDocLib( WinEDA_DrawFrame* frame, const wxString& FullDocLibName,
const wxString& Libname )
{
int LineNum = 0;
char Line[1024], * Name, * Text;
LibCmpEntry* Entry;
FILE* f;
wxString msg;
f = wxFopen( FullDocLibName, wxT( "rt" ) );
if( f == NULL )
return 0;
if( GetLine( f, Line, &LineNum, sizeof(Line) ) == NULL )
{
/* pas de lignes utiles */
fclose( f );
return 0;
}
if( strnicmp( Line, DOCFILE_IDENT, 10 ) != 0 )
{
DisplayError( frame, wxT( "File is NOT EESCHEMA doclib!" ) );
fclose( f );
return 0;
}
while( GetLine( f, Line, &LineNum, sizeof(Line) ) )
{
if( strncmp( Line, "$CMP", 4 ) != 0 )
{
msg.Printf( wxT( "$CMP command expected in line %d, aborted." ),
LineNum );
DisplayError( frame, msg );
fclose( f );
return 0;
}
/* Read one $CMP/$ENDCMP part entry from library: */
Name = strtok( Line + 5, "\n\r" );
wxString cmpname;
cmpname = CONV_FROM_UTF8( Name );
Entry = FindLibPart( cmpname, Libname, ALIAS );
while( GetLine( f, Line, &LineNum, sizeof(Line) ) )
{
if( strncmp( Line, "$ENDCMP", 7 ) == 0 )
break;
Text = strtok( Line + 2, "\n\r" );
switch( Line[0] )
{
case 'D':
if( Entry )
Entry->m_Doc = CONV_FROM_UTF8( Text );
break;
case 'K':
if( Entry )
Entry->m_KeyWord = CONV_FROM_UTF8( Text );
break;
case 'F':
if( Entry )
Entry->m_DocFile = CONV_FROM_UTF8( Text );
break;
}
}
}
fclose( f );
return 1;
}
......@@ -24,9 +24,7 @@ static int OldTransMat[2][2];
static wxPoint OldPos;
/*******************************************************/
wxString SelectFromLibBrowser( WinEDA_DrawFrame* parent )
/*******************************************************/
{
wxString name;
WinEDA_ViewlibFrame* Viewer;
......@@ -56,17 +54,16 @@ wxString SelectFromLibBrowser( WinEDA_DrawFrame* parent )
}
/**************************************************************************/
SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
const wxString& libname,
wxArrayString& HistoryList,
bool UseLibBrowser )
/**************************************************************************/
/* load from a library and place a component
/*
* load from a library and place a component
* if libname != "", search in lib "libname"
* else search in all loaded libs
*/
SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
const wxString& libname,
wxArrayString& HistoryList,
bool UseLibBrowser )
{
int ii, CmpCount = 0;
EDA_LibComponentStruct* Entry = NULL;
......@@ -85,7 +82,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
{
if( Library->GetName().CmpNoCase( libname ) == 0 )
{
CmpCount = Library->m_NumOfParts;
CmpCount = Library->GetCount();
break;
}
Library = Library->m_Pnext;
......@@ -96,7 +93,7 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
LibraryStruct* lib = g_LibraryList;
while( lib )
{
CmpCount += lib->m_NumOfParts;
CmpCount += lib->GetCount();
lib = lib->m_Pnext;
}
}
......@@ -204,13 +201,15 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
Component->SetRef( GetSheet(), msg );
/* Init champ Reference */
Component->GetField( REFERENCE )->m_Pos = Entry->m_Prefix.m_Pos + Component->m_Pos;
Component->GetField( REFERENCE )->m_Pos =
Entry->m_Prefix.m_Pos + Component->m_Pos;
Component->GetField( REFERENCE )->ImportValues( Entry->m_Prefix );
Component->m_PrefixString = Entry->m_Prefix.m_Text;
/* Init des autres champs si predefinis dans la librairie */
LibDrawField* EntryField;
for( EntryField = Entry->m_Fields; EntryField != NULL; EntryField = EntryField->Next() )
for( EntryField = Entry->m_Fields; EntryField != NULL;
EntryField = EntryField->Next() )
{
if( EntryField->m_Text.IsEmpty() && EntryField->m_Name.IsEmpty() )
continue;
......@@ -224,7 +223,8 @@ SCH_COMPONENT* WinEDA_SchematicFrame::Load_Component( wxDC* DC,
while( ii >= Component->GetFieldCount() )
{
int field_id = Component->GetFieldCount();
SCH_CMP_FIELD field( wxPoint( 0, 0 ), field_id, Component, ReturnDefaultFieldName( ii ) );
SCH_CMP_FIELD field( wxPoint( 0, 0 ), field_id, Component,
ReturnDefaultFieldName( ii ) );
Component->AddField( field );
}
}
......@@ -271,14 +271,12 @@ static void ShowWhileMoving( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
}
/**************************************************************************/
void WinEDA_SchematicFrame::CmpRotationMiroir(
SCH_COMPONENT* DrawComponent, wxDC* DC, int type_rotate )
/**************************************************************************/
/* Routine permettant les rotations et les miroirs d'un composant
/*
* Routine permettant les rotations et les miroirs d'un composant
* Si DC = NULL : pas de redessin
*/
void WinEDA_SchematicFrame::CmpRotationMiroir( SCH_COMPONENT* DrawComponent,
wxDC* DC, int type_rotate )
{
if( DrawComponent == NULL )
return;
......@@ -288,7 +286,7 @@ void WinEDA_SchematicFrame::CmpRotationMiroir(
{
DrawPanel->CursorOff( DC );
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
else
{
DrawPanel->PostDirtyRect( DrawComponent->GetBoundingBox() );
......@@ -303,8 +301,7 @@ void WinEDA_SchematicFrame::CmpRotationMiroir(
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0,
0 ),
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ),
GR_DEFAULT_DRAWMODE );
DrawPanel->CursorOn( DC );
}
......@@ -314,12 +311,10 @@ void WinEDA_SchematicFrame::CmpRotationMiroir(
}
/************************************************************/
static void ExitPlaceCmp( WinEDA_DrawPanel* Panel, wxDC* DC )
/************************************************************/
/* Routine de sortie de la fonction de placement de composant
/*
* Routine de sortie de la fonction de placement de composant
*/
static void ExitPlaceCmp( WinEDA_DrawPanel* Panel, wxDC* DC )
{
SCH_SCREEN* screen = (SCH_SCREEN*) Panel->GetScreen();
......@@ -339,18 +334,17 @@ static void ExitPlaceCmp( WinEDA_DrawPanel* Panel, wxDC* DC )
}
Panel->Refresh( TRUE );
Panel->ManageCurseur = NULL;
Panel->ForceCloseManageCurseur = NULL;
screen->SetCurItem( NULL );
}
/************************************************************************/
/*
* Selection de l'unite dans les boitiers a multiples Parts
*/
void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
int unit, wxDC* DC )
/************************************************************************/
/* Selection de l'unite dans les boitiers a multiples Parts */
{
int m_UnitCount;
EDA_LibComponentStruct* LibEntry;
......@@ -377,7 +371,7 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
/* Efface le trace precedent */
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
......@@ -387,19 +381,18 @@ void WinEDA_SchematicFrame::SelPartUnit( SCH_COMPONENT* DrawComponent,
/* Redessine le composant dans la nouvelle position */
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ),
GR_DEFAULT_DRAWMODE );
TestDanglingEnds( GetScreen()->EEDrawList, DC );
GetScreen()->SetModify();
}
/************************************************************************/
void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
wxDC* DC )
/************************************************************************/
{
int ii;
EDA_LibComponentStruct* LibEntry;
......@@ -414,12 +407,13 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
if( ( ii = LookForConvertPart( LibEntry ) ) < 2 )
{
DisplayError( this, wxT( "No Convert found" ), 10 ); return;
DisplayError( this, wxT( "No convert found" ) );
return;
}
/* Efface le trace precedent */
if( DrawComponent->m_Flags )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), g_XorMode );
......@@ -429,26 +423,25 @@ void WinEDA_SchematicFrame::ConvertPart( SCH_COMPONENT* DrawComponent,
/* Redessine le composant dans la nouvelle position */
if( DrawComponent->m_Flags & IS_MOVED )
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint(0,0) );
DrawStructsInGhost( DrawPanel, DC, DrawComponent, wxPoint( 0, 0 ) );
else
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ), GR_DEFAULT_DRAWMODE );
DrawComponent->Draw( DrawPanel, DC, wxPoint( 0, 0 ),
GR_DEFAULT_DRAWMODE );
TestDanglingEnds( GetScreen()->EEDrawList, DC );
GetScreen()->SetModify();
}
/**********************************************************/
int LookForConvertPart( EDA_LibComponentStruct* LibEntry )
/**********************************************************/
/* Retourne la plus grande valeur trouvee dans la liste des elements
/*
* Retourne la plus grande valeur trouvee dans la liste des elements
* "drawings" du composant LibEntry, pour le membre .Convert
* Si il n'y a pas de representation type "convert", la valeur
* retournee est 0 ou 1
* Si il y a une representation type "convert",
* la valeur retournee est > 1 (typiquement 2)
*/
int LookForConvertPart( EDA_LibComponentStruct* LibEntry )
{
int ii;
LibEDA_BaseStruct* DrawLibEntry;
......@@ -466,10 +459,8 @@ int LookForConvertPart( EDA_LibComponentStruct* LibEntry )
}
/***********************************************************************************/
void WinEDA_SchematicFrame::StartMovePart( SCH_COMPONENT* Component,
wxDC* DC )
/***********************************************************************************/
{
if( Component == NULL )
return;
......
......@@ -127,7 +127,7 @@ void WinEDA_LibeditFrame::OnExportPart( wxCommandEvent& event )
/* Sauvegarde du composant: */
CurrentLib = NewLib;
SaveOnePartInMemory();
bool success = NewLib->SaveLibrary( fn.GetFullPath() );
bool success = NewLib->Save( fn.GetFullPath() );
if( success )
{
......
......@@ -5,7 +5,6 @@
#ifndef LIBCMP_H
#define LIBCMP_H
#include "priorque.h"
#define LIB_VERSION_MAJOR 2
#define LIB_VERSION_MINOR 3
......@@ -14,7 +13,7 @@
#define DOC_EXT wxT( "dcm" ) /* Ext. of documentation files */
//Offsets used in editing library component, for handle aliad dats
//Offsets used in editing library component, for handle alias data
#define ALIAS_NAME 0
#define ALIAS_DOC 1
#define ALIAS_KEYWORD 2
......
......@@ -86,7 +86,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart()
if( g_ScreenLib->IsModify() )
{
if( !IsOK( this, _( "Current Part not saved.\nContinue?" ) ) )
if( !IsOK( this, _( "Current part not saved.\nContinue?" ) ) )
return FALSE;
}
......@@ -115,7 +115,8 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPart()
if( LibEntry == NULL )
{
msg = _( "Component \"" ); msg << CmpName << _( "\" not found." );
msg = _( "Component \"" );
msg << CmpName << _( "\" not found." );
DisplayError( this, msg );
return FALSE;
}
......@@ -144,7 +145,7 @@ bool WinEDA_LibeditFrame::LoadOneLibraryPartAux( LibCmpEntry* LibEntry,
{
wxString msg, cmpName, rootName;
if( (LibEntry == NULL) || (Library == NULL) )
if( ( LibEntry == NULL ) || ( Library == NULL ) )
return false;
if( LibEntry->m_Name.m_Text.IsEmpty() )
......@@ -263,33 +264,33 @@ void WinEDA_LibeditFrame::SaveActiveLibrary()
if( CurrentLib == NULL )
{
DisplayError( this, wxT( "No Library specified" ) );
DisplayError( this, wxT( "No library specified" ) );
return;
}
fn = wxFileName( CurrentLib->m_FullFileName );
msg = _( "Modify Library File \"" ) + fn.GetFullPath() + _( "\"?" );
msg = _( "Modify library file \"" ) + fn.GetFullPath() + _( "\"?" );
if( !IsOK( this, msg ) )
return;
bool success = CurrentLib->SaveLibrary( fn.GetFullPath() );
bool success = CurrentLib->Save( fn.GetFullPath() );
MsgPanel->EraseMsgBox();
if( !success )
{
msg = _( "Error while saving Library File \"" ) + fn.GetFullPath() +
msg = _( "Error while saving library file \"" ) + fn.GetFullPath() +
_( "\"." );
Affiche_1_Parametre( this, 1, wxT( " *** ERROR : **" ), msg, BLUE );
DisplayError( this, msg );
}
else
{
msg = _( "Library File \"" ) + fn.GetFullName() + wxT( "\" Ok" );
msg = _( "Library file \"" ) + fn.GetFullName() + wxT( "\" Ok" );
fn.SetExt( DOC_EXT );
wxString msg1 = _( "Document File \"" ) + fn.GetFullPath() +
wxString msg1 = _( "Document file \"" ) + fn.GetFullPath() +
wxT( "\" Ok" );
Affiche_1_Parametre( this, 1, msg, msg1, BLUE );
}
......@@ -476,7 +477,7 @@ void WinEDA_LibeditFrame::SaveOnePartInMemory()
if( CurrentLib == NULL )
{
DisplayError( this, _( "No Library specified." ) );
DisplayError( this, _( "No library specified." ) );
return;
}
......
......@@ -200,7 +200,7 @@ void WinEDA_LibeditFrame::OnCloseWindow( wxCloseEvent& Event )
for( Lib = g_LibraryList; Lib != NULL; Lib = Lib->m_Pnext )
{
if( Lib->m_Modified )
if( Lib->IsModified() )
{
wxString msg;
msg.Printf( _( "Library \"%s\" was modified!\nDiscard changes?" ),
......@@ -352,7 +352,7 @@ int WinEDA_LibeditFrame::BestZoom()
}
size = DrawPanel->GetClientSize();
size -= wxSize(100,100); // reserve 100 mils margin
size -= wxSize( 100, 100 ); // reserve 100 mils margin
ii = abs( dx / size.x );
jj = abs( dy / size.y );
......@@ -659,7 +659,8 @@ void WinEDA_LibeditFrame::Process_Special_Functions( wxCommandEvent& event )
case ID_LIBEDIT_DELETE_ITEM_BUTT:
if( CurrentLibEntry == NULL )
{
wxBell(); break;
wxBell();
break;
}
SetToolID( id, wxCURSOR_BULLSEYE, _( "Delete item" ) );
break;
......
......@@ -68,13 +68,16 @@ void WinEDA_PinPropertiesFrame::PinPropertiesAccept( wxCommandEvent& event )
LastPinNoDraw = m_NoDraw->GetValue();
msg = m_PinSizeCtrl->GetValue();
LastPinSize = ReturnValueFromString( g_UnitMetric, msg, m_Parent->m_InternalUnits );
LastPinSize = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_PinNameSizeCtrl->GetValue();
LastPinNameSize = ReturnValueFromString( g_UnitMetric, msg, m_Parent->m_InternalUnits );
LastPinNameSize = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
msg = m_PinNumSizeCtrl->GetValue();
LastPinNumSize = ReturnValueFromString( g_UnitMetric, msg, m_Parent->m_InternalUnits );
LastPinNumSize = ReturnValueFromString( g_UnitMetric, msg,
m_Parent->m_InternalUnits );
if( CurrentDrawItem ) // Set Pin Name & Num
{
......@@ -82,7 +85,8 @@ void WinEDA_PinPropertiesFrame::PinPropertiesAccept( wxCommandEvent& event )
m_Parent->SaveCopyInUndoList( CurrentLibEntry );
SetPinName( m_PinNameCtrl->GetValue(), LastPinNameSize );
msg = m_PinNumCtrl->GetValue(); if( msg.IsEmpty() )
msg = m_PinNumCtrl->GetValue();
if( msg.IsEmpty() )
msg = wxT( "~" );
SetPinNum( msg, LastPinNumSize );
NewSizePin( LastPinSize );
......@@ -126,10 +130,10 @@ void WinEDA_LibeditFrame::InitEditOnePin()
continue;
if( Pin == CurrentPin )
continue;
if( (Pin->m_Pos == CurrentPin->m_Pos)
&& (Pin->m_Orient == CurrentPin->m_Orient)
&& ( !(CurrentPin->m_Flags & IS_NEW) )
&& (g_EditPinByPinIsOn == false) // This is set by the tool of the main toolbar
if( ( Pin->m_Pos == CurrentPin->m_Pos )
&& ( Pin->m_Orient == CurrentPin->m_Orient )
&& ( !( CurrentPin->m_Flags & IS_NEW ) )
&& ( g_EditPinByPinIsOn == false ) // This is set by the tool of the main toolbar
)
Pin->m_Flags |= IS_LINKED | IN_EDIT;
else
......@@ -150,7 +154,8 @@ static void AbortPinMove( WinEDA_DrawPanel* Panel, wxDC* DC )
LibDrawPin* CurrentPin = (LibDrawPin*) CurrentDrawItem;
if( CurrentPin && ( CurrentPin->m_Flags & IS_NEW ) )
DeleteOneLibraryDrawStruct( Panel, DC, CurrentLibEntry, CurrentPin, true );
DeleteOneLibraryDrawStruct( Panel, DC, CurrentLibEntry,
CurrentPin, true );
/* clear edit flags */
LibEDA_BaseStruct* item = CurrentLibEntry->m_Drawings;
......@@ -235,8 +240,8 @@ void WinEDA_LibeditFrame::PlacePin( wxDC* DC )
}
DrawPanel->CursorOff( DC );
DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint(0, 0), CurrentPin,
GR_DEFAULT_DRAWMODE );
DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint( 0, 0 ),
CurrentPin, GR_DEFAULT_DRAWMODE );
DrawPanel->CursorOn( DC );
CurrentDrawItem = NULL;
......@@ -294,8 +299,9 @@ void WinEDA_LibeditFrame::StartMovePin( wxDC* DC )
continue;
if( Pin == CurrentPin )
continue;
if( (Pin->m_Pos == CurrentPin->m_Pos) && (Pin->m_Orient == CurrentPin->m_Orient)
&& (g_EditPinByPinIsOn == false ) )
if( ( Pin->m_Pos == CurrentPin->m_Pos )
&& ( Pin->m_Orient == CurrentPin->m_Orient )
&& ( g_EditPinByPinIsOn == false ) )
Pin->m_Flags |= IS_LINKED | IS_MOVED;
}
......@@ -326,7 +332,7 @@ static void DrawMovePin( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
wxPoint pinpos = CurrentPin->m_Pos;
/* Erase pin in old position */
if( erase || (CurrentPin->m_Flags & IS_NEW) )
if( erase || ( CurrentPin->m_Flags & IS_NEW ) )
{
CurrentPin->m_Pos = PinPreviousPos;
DrawLibraryDrawStruct( panel, DC, CurrentLibEntry, wxPoint(0, 0),
......@@ -336,7 +342,8 @@ static void DrawMovePin( WinEDA_DrawPanel* panel, wxDC* DC, bool erase )
/* Redraw pin in new position */
CurrentPin->m_Pos.x = panel->GetScreen()->m_Curseur.x;
CurrentPin->m_Pos.y = -panel->GetScreen()->m_Curseur.y;
DrawLibraryDrawStruct( panel, DC, CurrentLibEntry, wxPoint(0, 0), CurrentPin, g_XorMode );
DrawLibraryDrawStruct( panel, DC, CurrentLibEntry, wxPoint( 0, 0 ),
CurrentPin, g_XorMode );
PinPreviousPos = CurrentPin->m_Pos;
......@@ -481,7 +488,7 @@ void WinEDA_PinPropertiesFrame::SetPinNum( const wxString& newnum, int newsize )
{
if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
if( (Pin->m_Flags & IS_LINKED) == 0 )
if( ( Pin->m_Flags & IS_LINKED ) == 0 )
continue;
if( Pin->m_Unit != CurrentPin->m_Unit )
continue;
......@@ -659,7 +666,8 @@ void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw,
continue;
if( Pin == CurrentPin )
continue;
if( CurrentPin->m_Convert && (CurrentPin->m_Convert != Pin->m_Convert) )
if( CurrentPin->m_Convert
&& (CurrentPin->m_Convert != Pin->m_Convert) )
continue;
if( CurrentPin->m_Pos != Pin->m_Pos )
continue;
......@@ -683,7 +691,8 @@ void WinEDA_PinPropertiesFrame::SetAttributsPin( bool draw,
DrawItem = CurrentLibEntry->m_Drawings;
for( ; DrawItem != NULL; )
{
Pin = (LibDrawPin*) DrawItem; DrawItem = DrawItem->Next();
Pin = (LibDrawPin*) DrawItem;
DrawItem = DrawItem->Next();
if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
if( Pin->m_Flags == 0 )
......@@ -787,7 +796,7 @@ static void CreateImagePins( LibDrawPin* Pin )
/* Creation de la pin " convert " pour la part courante */
if( CreateConv == true )
{
NewPin = Pin->GenCopy();
NewPin = (LibDrawPin*) Pin->GenCopy();
if( Pin->m_Convert > 1 )
NewPin->m_Convert = 1;
else
......@@ -804,7 +813,7 @@ static void CreateImagePins( LibDrawPin* Pin )
continue; /* Pin commune a toutes les unites */
/* Creation pour la representation "normale" */
NewPin = Pin->GenCopy();
NewPin = (LibDrawPin*) Pin->GenCopy();
if( CurrentConvert != 0 )
NewPin->m_Convert = 1;
NewPin->m_Unit = ii;
......@@ -815,7 +824,7 @@ static void CreateImagePins( LibDrawPin* Pin )
if( CreateConv == false )
continue;
NewPin = Pin->GenCopy();
NewPin = (LibDrawPin*)Pin->GenCopy();
NewPin->m_Convert = 2;
if( Pin->m_Unit != 0 )
NewPin->m_Unit = ii;
......@@ -838,7 +847,7 @@ void WinEDA_LibeditFrame::GlobalSetPins( wxDC* DC,
*/
{
LibDrawPin* Pin;
bool selected = (MasterPin->m_Selected & IS_SELECTED) != 0;
bool selected = ( MasterPin->m_Selected & IS_SELECTED ) != 0;
if( (CurrentLibEntry == NULL) || (MasterPin == NULL) )
return;
......@@ -852,14 +861,15 @@ void WinEDA_LibeditFrame::GlobalSetPins( wxDC* DC,
{
if( Pin->Type() != COMPONENT_PIN_DRAW_TYPE )
continue;
if( (Pin->m_Convert) && (Pin->m_Convert != CurrentConvert) )
if( ( Pin->m_Convert ) && ( Pin->m_Convert != CurrentConvert ) )
continue;
// Is it the "selected mode" ?
if( selected && (Pin->m_Selected & IS_SELECTED) == 0 )
continue;
DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry, wxPoint(0, 0), Pin, g_XorMode );
DrawLibraryDrawStruct( DrawPanel, DC, CurrentLibEntry,
wxPoint( 0, 0 ), Pin, g_XorMode );
switch( id )
{
......@@ -897,13 +907,15 @@ void WinEDA_LibeditFrame::RepeatPinItem( wxDC* DC, LibDrawPin* SourcePin )
if( SourcePin->Type() != COMPONENT_PIN_DRAW_TYPE )
return;
Pin = SourcePin->GenCopy();
Pin = (LibDrawPin*)SourcePin->GenCopy();
Pin->SetNext( CurrentLibEntry->m_Drawings );
CurrentLibEntry->m_Drawings = Pin;
Pin->m_Flags = IS_NEW;
Pin->m_Pos.x += g_RepeatStep.x; ox = Pin->m_Pos.x;
Pin->m_Pos.y += -g_RepeatStep.y; oy = Pin->m_Pos.y; // ici axe Y comme en math
Pin->m_Pos.x += g_RepeatStep.x;
ox = Pin->m_Pos.x;
Pin->m_Pos.y += -g_RepeatStep.y;
oy = Pin->m_Pos.y; // ici axe Y comme en math
/*** Increment du numero de label ***/
IncrementLabelMember( Pin->m_PinName );
......
/*****************************************************************************
* PriorQue.c - implement priority queue, using regular binary trees *
* (that guarantees only average time of NlogN...) and with the following *
* operations: *
* 1. PQInit(&PQ) - initialize the queue, must be called before usage. *
* 2. PQEmpty(PQ) - returns TRUE iff PQ is empty. *
* 3. PQCompFunc(&CompFunc) - sets (a pointer to) the function that is *
* used to compere two items in the queue. the function should get two *
* item pointers, and should return >1, 0, <1 as comparison result for *
* greater than, equal, or less than respectively. *
* 4. PQFirst(&PQ, Delete) - returns the first element of the priority *
* queue, and delete it from queue if delete is TRUE. *
* 5. PQInsert(&PQ, NewItem) - insert NewItem into the queue *
* (NewItem is a pointer to it), using the comparison function CompFunc. *
* 6. PQDelete(&PQ, OldItem) - Delete old item from the queue *
* again using the comparison function CompFunc. *
* 7. PQFind(PQ, OldItem) - Find old item in queue, again using the *
* comparison function CompFunc. *
* 8. PQNext(PQ, CmpItem, NULL) - returns the smallest item which is bigger *
* than given item CmpItem. PQ is not modified. Return NULL if none. *
* 9. PQPrint(PQ, &PrintFunc) - print the queue in order using the given *
* printing function PrintFunc. *
*10. PQFree(&PQ, FreeItems) - Free the queue. The items are also freed if *
* FreeItems is TRUE. *
* *
* Written by Gershon Elber, Dec 88 *
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include "priorque.h"
/* Definition des fonction MyFree() ( free() ) et MyMalloc() (malloc() */
void * MyMalloc( size_t );
void MyFree(void*);
#define SIGN(x) ((x) > 0 ? 1 : ((x) < 0 ? -1 : 0))
#define PQ_NEW_NODE(PQ) { \
PQ = (PriorQue *) MyMalloc(sizeof(PriorQue)); \
(PQ) -> Right = (PQ) -> Left = NULL; \
(PQ) -> Data = NULL; }
#define PQ_FREE_NODE(PQ) { MyFree((char *) (PQ)); PQ = NULL; }
static PQCompFuncType CompFunc; // = (PQCompFuncType) strcmp;
/******************************************************************************
* PQEmpty - initialize the queue... *
******************************************************************************/
void PQInit(PriorQue **PQ)
{
*PQ = NULL;
}
/******************************************************************************
* PQEmpty - returns TRUE iff PQ priority queue is empty. *
******************************************************************************/
int PQEmpty(PriorQue *PQ)
{
return PQ == NULL;
}
/******************************************************************************
* PQCompFunc - sets (a pointer to) the function that is used to compere two *
* items in the queue. The function should get two item pointers, and should *
* return >1, 0, <1 as comparison result for greater than, equal, or less than *
* respectively. *
******************************************************************************/
void PQCompFunc(PQCompFuncType NewCompFunc)
{
CompFunc = NewCompFunc;
}
/******************************************************************************
* PQFirst - returns the first element of the priority queue, and delete it *
* from queue if Delete is TRUE. return NULL if empty queue *
******************************************************************************/
void * PQFirst(PriorQue **PQ, int Delete)
{
void * Data;
PriorQue *Ptemp = (*PQ);
if (*PQ == NULL) return NULL;
while (Ptemp -> Right != NULL)
Ptemp = Ptemp -> Right; /* Find smallest item. */
Data = Ptemp -> Data;
if (Delete) PQDelete(PQ, Data);
return Data;
}
/******************************************************************************
* PQInsert - insert new item into the queue (NewItem is a pointer to it), *
* using given compare function CompFunc. CompFunc should return >1, 0, <1 *
* as two item comparison result for greater than, equal, or less than *
* respectively. *
* Insert is always as a leaf of the tree. *
* Return pointer to old data if was replaced or NULL if the item is new. *
******************************************************************************/
void * PQInsert(PriorQue **PQ, void * NewItem)
{
int Compare;
void * Data;
if ((*PQ) == NULL) {
PQ_NEW_NODE(*PQ);
(*PQ) -> Data = NewItem;
return NULL;
}
else {
Compare = (*CompFunc)(NewItem, (*PQ) -> Data);
Compare = SIGN(Compare);
switch (Compare) {
case -1:
return PQInsert(&((*PQ) -> Right), NewItem);
case 0:
Data = (*PQ) -> Data;
(*PQ) -> Data = NewItem;
return Data;
case 1:
return PQInsert(&((*PQ) -> Left), NewItem);
}
}
return NULL; /* Makes warning silent. */
}
/******************************************************************************
* PQDelete - Delete old item from the queue, again using the comparison *
* function CompFunc. *
* Returns pointer to Deleted item if was fould and deleted, NULL otherwise. *
******************************************************************************/
void * PQDelete(PriorQue **PQ, void * OldItem)
{
int Compare;
PriorQue *Ptemp;
void * Data;
void * OldData;
if ((*PQ) == NULL) return NULL;
else
{
Compare = (*CompFunc)(OldItem, (*PQ) -> Data);
Compare = SIGN(Compare);
switch (Compare)
{
case -1:
return PQDelete(&((*PQ) -> Right), OldItem);
case 0:
OldData = (*PQ) -> Data; /* The returned deleted item. */
if ((*PQ) -> Right == NULL && (*PQ) -> Left == NULL)
{
/* Thats easy - we delete a leaf: */
Data = (*PQ) -> Data;
PQ_FREE_NODE(*PQ); /* Note *PQ is also set to NULL here. */
}
else if ((*PQ) -> Right != NULL)
{
/* replace this node by the biggest in the Right branch: */
/* move once to the Right and then Left all the time... */
Ptemp = (*PQ) -> Right;
if (Ptemp -> Left != NULL)
{
while (Ptemp -> Left -> Left != NULL)
Ptemp = Ptemp -> Left;
Data = Ptemp -> Left -> Data;/*Save the data pointer.*/
PQDelete(&(Ptemp -> Left), Data); /* Delete recurs. */
(*PQ) -> Data = Data; /* And put that data instead...*/
}
else
{
Data = Ptemp -> Data; /* Save the data pointer. */
PQDelete(&((*PQ) -> Right), Data); /* Delete recurs. */
(*PQ) -> Data = Data; /* And put that data instead...*/
}
}
else /* Left != NULL. */
{
/* replace this node by the biggest in the Left branch: */
/* move once to the Left and then Right all the time... */
Ptemp = (*PQ) -> Left;
if (Ptemp -> Right != NULL)
{
while (Ptemp -> Right -> Right != NULL)
Ptemp = Ptemp -> Right;
Data = Ptemp -> Right -> Data; /* Save data pointer. */
PQDelete(&(Ptemp -> Right), Data); /*Delete recurs. */
(*PQ) -> Data = Data; /* And put that data instead...*/
}
else
{
Data = Ptemp -> Data; /* Save the data pointer. */
PQDelete(&((*PQ) -> Left), Data); /* Delete recurs. */
(*PQ) -> Data = Data; /* And put that data instead...*/
}
}
return OldData;
case 1:
return PQDelete(&((*PQ) -> Left), OldItem);
}
}
return NULL; /* Makes warning silent. */
}
/******************************************************************************
* PQFind - Find old item from the queue, again using the comparison *
* function CompFunc. *
* Returns pointer to item if was fould, NULL otherwise. *
******************************************************************************/
void * PQFind(PriorQue *PQ, void * OldItem)
{
int Compare;
if (PQ == NULL) {
return NULL;
}
else {
Compare = (*CompFunc)(OldItem, PQ -> Data);
Compare = SIGN(Compare);
switch (Compare) {
case -1:
return PQFind(PQ -> Right, OldItem);
case 0:
return PQ -> Data;
case 1:
return PQFind(PQ -> Left, OldItem);
}
}
return NULL; /* Makes warning silent. */
}
/******************************************************************************
* PQNext - returns the smallest item which is bigger than given item CmpItem. *
* PQ is not modified. Return NULL if none was found. *
* BiggerThan will allways hold the smallest Item bigger than current one. *
******************************************************************************/
void * PQNext(PriorQue *PQ, void * CmpItem, void * BiggerThan)
{
int Compare;
PriorQue *Ptemp;
if (PQ == NULL)
return BiggerThan;
else {
Compare = (*CompFunc)(CmpItem, PQ -> Data);
Compare = SIGN(Compare);
switch (Compare) {
case -1:
return PQNext(PQ -> Right, CmpItem, PQ -> Data);
case 0:
/* Found it - if its right tree is not empty, returns its */
/* smallest, else returns BiggerThan... */
if (PQ -> Left != NULL) {
Ptemp = PQ -> Left;
while (Ptemp -> Right != NULL) Ptemp = Ptemp -> Right;
return Ptemp -> Data;
}
else
return BiggerThan;
case 1:
return PQNext(PQ -> Left, CmpItem, BiggerThan);
}
}
return NULL; /* Makes warning silent. */
}
/******************************************************************************
* PQPrint - print the queue in order using the given printing functionq *
* PrintFunc. *
******************************************************************************/
void PQPrint(PriorQue *PQ, void (*PrintFunc)(void *))
{
if (PQ == NULL) return;
PQPrint(PQ -> Right, PrintFunc);
(*PrintFunc)(PQ -> Data);
PQPrint(PQ -> Left, PrintFunc);
}
/******************************************************************************
* PQFree - Free the queue. The items are also freed if FreeItems is TRUE. *
******************************************************************************/
void PQFree(PriorQue *PQ, int FreeItem)
{
if (PQ == NULL) return;
PQFree(PQ -> Right, FreeItem);
PQFree(PQ -> Left, FreeItem);
if (FreeItem) MyFree((char *) PQ -> Data);
MyFree((char *) PQ);
}
/******************************************************************************
* PQFreeFunc - Free queue. Items are also freed by calling FreeFunc on them. *
******************************************************************************/
void PQFreeFunc(PriorQue *PQ, void (*FreeFunc)(void *))
{
if (PQ == NULL) return;
PQFreeFunc(PQ -> Right, FreeFunc);
PQFreeFunc(PQ -> Left, FreeFunc);
(FreeFunc)(PQ -> Data);
MyFree((char *) PQ);
}
/*****************************************************************************
* Definitions, visible to others, of Priority Queue module: *
*****************************************************************************/
#ifndef PRIOR_Q_GH
#define PRIOR_Q_GH
typedef struct PriorQue
{
struct PriorQue *Right, *Left; /* Pointers to two sons of this node. */
void * Data; /* Pointers to the data itself. */
} PriorQue;
typedef int (*PQCompFuncType)( void *, void *); /* Comparison function. */
/* And global function prototypes: */
void PQInit(PriorQue **PQ);
int PQEmpty(PriorQue *PQ);
void PQCompFunc(PQCompFuncType NewCompFunc);
void * PQFirst(PriorQue **PQ, int Delete);
void * PQInsert(PriorQue **PQ, void * NewItem);
void * PQDelete(PriorQue **PQ, void * NewItem);
void * PQFind(PriorQue *PQ, void * OldItem);
void * PQNext(PriorQue *PQ, void * CmpItem, void * BiggerThan);
void PQPrint(PriorQue *PQ, void (*PrintFunc)());
void PQFree(PriorQue *PQ, int FreeItems);
void PQFreeFunc(PriorQue *PQ, void (*FreeFunc)(void *));
#endif /* PRIOR_Q_GH */
......@@ -91,9 +91,6 @@ wxPoint TransformCoordinate( const int aTransformMatrix[2][2],
const wxPoint& aPosition );
LibraryStruct* FindLibrary( const wxString& Name );
int LoadDocLib( WinEDA_DrawFrame* frame,
const wxString& FullDocLibName,
const wxString& Libname );
LibraryStruct* LoadLibraryName( WinEDA_DrawFrame* frame,
const wxString& FullLibName,
const wxString& LibName );
......@@ -236,18 +233,6 @@ bool Read_Hotkey_Config( WinEDA_DrawFrame* frame, bool verbose );
/* SAVELIB.CPP */
/**************/
LibEDA_BaseStruct* CopyDrawEntryStruct( LibEDA_BaseStruct* DrawItem );
/* Routine de Duplication d'une structure DrawLibItem d'une partlib
* Parametres d'entree:
* DrawEntry = pointeur sur la structure a dupliquer
* La structure nouvelle est creee, mais n'est pas inseree dans le
* chainage
* Retourne:
* Pointeur sur la structure creee (ou NULL si impossible)
*/
EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry );
/* Routine de copie d'une partlib
......
......@@ -19,61 +19,6 @@
#include "protos.h"
/** Function CopyDrawEntryStruct
* Duplicate a DrawLibItem
* the new item is only created, it is not put in the current component linked
* list
* @param DrawEntry = DrawLibItem * item to duplicate
* @return a pointer to the new item
* A better way to duplicate a DrawLibItem is to have a virtual GenCopy() in
* LibEDA_BaseStruct class (ToDo).
*/
LibEDA_BaseStruct* CopyDrawEntryStruct( LibEDA_BaseStruct* DrawItem )
{
wxString msg;
LibEDA_BaseStruct* NewDrawItem = NULL;
switch( DrawItem->Type() )
{
case COMPONENT_ARC_DRAW_TYPE:
NewDrawItem = ( (LibDrawArc*) DrawItem )->GenCopy();
break;
case COMPONENT_CIRCLE_DRAW_TYPE:
NewDrawItem = ( (LibDrawCircle*) DrawItem )->GenCopy();
break;
case COMPONENT_RECT_DRAW_TYPE:
NewDrawItem = ( (LibDrawSquare*) DrawItem )->GenCopy();
break;
case COMPONENT_PIN_DRAW_TYPE:
NewDrawItem = ( (LibDrawPin*) DrawItem )->GenCopy();
break;
case COMPONENT_GRAPHIC_TEXT_DRAW_TYPE:
NewDrawItem = ( (LibDrawText*) DrawItem )->GenCopy();
break;
case COMPONENT_POLYLINE_DRAW_TYPE:
NewDrawItem = ( (LibDrawPolyline*) DrawItem )->GenCopy();
break;
case COMPONENT_BEZIER_DRAW_TYPE:
NewDrawItem = ( (LibDrawBezier*) DrawItem )->GenCopy();
break;
default:
msg.Printf( wxT( "CopyDrawLibEntryStruct: unknown Draw Type %d" ),
DrawItem->Type() );
wxLogError( msg );
break;
}
return NewDrawItem;
}
/*
* Routine de copie d'une partlib
* Parametres d'entree: pointeur sur la structure de depart
......@@ -118,7 +63,7 @@ EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry )
for( OldField = OldEntry->m_Fields; OldField != NULL;
OldField = OldField->Next() )
{
NewField = OldField->GenCopy();
NewField = (LibDrawField*) OldField->GenCopy();
NewStruct->m_Fields.PushBack( NewField );
}
......@@ -130,7 +75,8 @@ EDA_LibComponentStruct* CopyLibEntryStruct( EDA_LibComponentStruct* OldEntry )
if( ( OldDrawings->m_Flags & IS_NEW ) != 0 )
continue;
NewDrawings = CopyDrawEntryStruct( OldDrawings );
NewDrawings = OldDrawings->GenCopy();
if( NewDrawings )
{
if( LastItem == NULL )
......
......@@ -2,9 +2,6 @@
/* EESchema - selpart.cpp */
/**************************/
/* Routine de selection d'un composant en librairie
*/
#include "fctsys.h"
#include "gr_basic.h"
#include "common.h"
......@@ -16,32 +13,24 @@
#include "protos.h"
/* Routines locales */
/* Variables locales */
/***************************************************************/
LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame )
/***************************************************************/
{
int ii, NumOfLibs = NumOfLibraries();
LibraryStruct* Lib = NULL;
static wxString OldLibName;
wxString LibName;
wxString LibName, msg;
int count = NumOfLibraries();
LibraryStruct* Lib = NULL;
if( NumOfLibs == 0 )
if( count == 0 )
{
DisplayError( frame, _( "No libraries are loaded" ) );
return NULL;
}
WinEDAListBox ListBox( frame, _( "Select Lib" ),
NULL, OldLibName, NULL,
wxColour( 255, 255, 255 ) ); // Library browser background color
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 )
......@@ -56,17 +45,20 @@ LibraryStruct* SelectLibraryFromList( WinEDA_DrawFrame* frame )
if( libcache )
libNamesList.Add( libcache->m_Name );
ListBox.InsertItems( libNamesList );
wxSingleChoiceDialog dlg( frame, msg, _( "Select Library" ), libNamesList );
int index = libNamesList.Index( OldLibName );
ListBox.MoveMouseToOrigin();
if( index != wxNOT_FOUND )
dlg.SetSelection( index );
ii = ListBox.ShowModal();
if( dlg.ShowModal() == wxID_CANCEL || dlg.GetStringSelection().IsEmpty() )
return NULL;
if( ii >= 0 ) /* Recherche de la librairie */
{
Lib = FindLibrary( libNamesList[ii] );
}
Lib = FindLibrary( dlg.GetStringSelection() );
if( Lib != NULL )
OldLibName = dlg.GetStringSelection();
return Lib;
}
......@@ -77,7 +69,6 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
wxString& Buffer, wxString& OldName )
{
size_t i;
wxString msg;
wxArrayString nameList;
const wxChar** ListNames;
......@@ -92,14 +83,11 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
ListNames = (const wxChar**) MyZMalloc( ( nameList.GetCount() + 1 ) *
sizeof( wxChar* ) );
msg.Printf( _( "Select 1 of %d components from library <%s>" ),
nameList.GetCount(), (const wxChar*) Library->m_Name );
for( i = 0; i < nameList.GetCount(); i++ )
ListNames[i] = (const wxChar*) nameList[i];
WinEDAListBox dlg( frame, msg, ListNames, OldName, DisplayCmpDoc,
wxColour( 255, 255, 255 ) );
WinEDAListBox dlg( frame, _( "Select Component" ), ListNames, OldName,
DisplayCmpDoc, wxColour( 255, 255, 255 ) );
dlg.MoveMouseToOrigin();
......@@ -117,10 +105,8 @@ int DisplayComponentsNamesInLib( WinEDA_DrawFrame* frame,
}
/************************************************************/
int GetNameOfPartToLoad( WinEDA_DrawFrame* frame,
LibraryStruct* Library, wxString& BufName )
/************************************************************/
int GetNameOfPartToLoad( WinEDA_DrawFrame* frame, LibraryStruct* Library,
wxString& BufName )
{
int ii;
static wxString OldCmpName;
......
......@@ -109,7 +109,7 @@ void WinEDA_LibeditFrame::LoadOneSymbol( void )
return;
}
if( Lib->m_NumOfParts > 1 )
if( Lib->GetCount() > 1 )
DisplayError( this, _( "Warning: more than 1 part in Symbol File" ) );
Component = (EDA_LibComponentStruct*) Lib->GetFirstEntry();
......@@ -240,10 +240,10 @@ void WinEDA_LibeditFrame::SaveOneSymbol()
for( ; DrawEntry != NULL; DrawEntry = DrawEntry->Next() )
{
/* Elimination des elements non relatifs a l'unite */
if( Unit && DrawEntry->m_Unit && (DrawEntry->m_Unit != Unit) )
if( Unit && DrawEntry->m_Unit && ( DrawEntry->m_Unit != Unit ) )
continue;
if( convert && DrawEntry->m_Convert
&& (DrawEntry->m_Convert != convert) )
&& ( DrawEntry->m_Convert != convert ) )
continue;
DrawEntry->Save( ExportFile );
......
......@@ -111,7 +111,8 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
m_LibList =
new wxListBox( m_LibListWindow, ID_LIBVIEW_LIB_LIST,
wxPoint( 0, 0 ),
m_LibListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0),
m_LibListWindow->GetClientSize() -
wxSize( EXTRA_BORDER_SIZE * 2, 0 ),
0, NULL, wxLB_HSCROLL );
}
else
......@@ -135,7 +136,8 @@ WinEDA_ViewlibFrame::WinEDA_ViewlibFrame( wxWindow* father,
m_CmpListWindow->SetExtraBorderSize( EXTRA_BORDER_SIZE );
m_CmpList = new wxListBox( m_CmpListWindow, ID_LIBVIEW_CMP_LIST,
wxPoint( 0, 0 ),
m_CmpListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0),
m_CmpListWindow->GetClientSize() -
wxSize( EXTRA_BORDER_SIZE * 2, 0 ),
0, NULL, wxLB_HSCROLL );
if( m_LibList )
......@@ -231,7 +233,8 @@ void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
if( m_VToolBar )
{
Vtoolbar_size = m_VToolBar->GetSize();
m_VToolBar->SetSize( clientsize.x - maintoolbar_size.y, 0, -1, clientsize.y );
m_VToolBar->SetSize( clientsize.x - maintoolbar_size.y, 0, -1,
clientsize.y );
}
if( MsgPanel )
......@@ -242,7 +245,8 @@ void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
if( DrawPanel )
{
DrawPanel->SetSize( m_LibListSize.x + m_CmpListSize.x, 0,
clientsize.x - Vtoolbar_size.x - m_LibListSize.x - m_CmpListSize.x,
clientsize.x - Vtoolbar_size.x -
m_LibListSize.x - m_CmpListSize.x,
clientsize.y );
}
......@@ -250,7 +254,8 @@ void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
{
m_LibListSize.y = clientsize.y - 2;
m_LibListWindow->SetSize( m_LibListSize );
m_LibList->SetSize( m_LibListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0) );
m_LibList->SetSize( m_LibListWindow->GetClientSize() -
wxSize( EXTRA_BORDER_SIZE * 2, 0 ) );
}
if( m_CmpList && m_CmpListWindow )
......@@ -258,7 +263,8 @@ void WinEDA_ViewlibFrame::OnSize( wxSizeEvent& SizeEv )
m_CmpListSize.y = clientsize.y - 2;
m_CmpListWindow->SetSize( m_CmpListSize );
m_CmpListWindow->SetPosition( wxPoint( m_LibListSize.x, 0 ) );
m_CmpList->SetSize( m_CmpListWindow->GetClientSize() - wxSize(EXTRA_BORDER_SIZE*2,0) );
m_CmpList->SetSize( m_CmpListWindow->GetClientSize() -
wxSize( EXTRA_BORDER_SIZE * 2, 0 ) );
}
SizeEv.Skip();
......@@ -285,7 +291,8 @@ int WinEDA_ViewlibFrame::BestZoom()
return bestzoom;
}
EDA_Rect BoundaryBox = CurrentLibEntry->GetBoundaryBox( g_ViewUnit, g_ViewConvert );
EDA_Rect BoundaryBox = CurrentLibEntry->GetBoundaryBox( g_ViewUnit,
g_ViewConvert );
itemsize = BoundaryBox.GetSize();
size = DrawPanel->GetClientSize();
......@@ -331,12 +338,12 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
if ( libcache )
libNamesList.Add( libcache->m_Name );
m_LibList->Append(libNamesList);
m_LibList->Append( libNamesList );
// Search for a previous selection:
for ( unsigned ii = 0; ii < m_LibList->GetCount(); ii++ )
{
if( g_CurrentViewLibraryName.Cmp( m_LibList->GetString(ii) ) == 0 )
if( g_CurrentViewLibraryName.Cmp( m_LibList->GetString( ii ) ) == 0 )
{
m_LibList->SetSelection( ii, TRUE );
found = TRUE;
......@@ -344,7 +351,8 @@ void WinEDA_ViewlibFrame::ReCreateListLib()
}
}
/* If not found, clear current library selection because it can be deleted after a config change
/* If not found, clear current library selection because it can be
* deleted after a config change.
*/
if( !found )
{
......@@ -364,7 +372,7 @@ void WinEDA_ViewlibFrame::ReCreateListCmp()
if( m_CmpList == NULL )
return;
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName.GetData() );
LibraryStruct* Library = FindLibrary( g_CurrentViewLibraryName );
wxArrayString nameList;
m_CmpList->Clear();
......@@ -378,9 +386,7 @@ void WinEDA_ViewlibFrame::ReCreateListCmp()
}
/********************************************************************/
void WinEDA_ViewlibFrame::ClickOnLibList( wxCommandEvent& event )
/********************************************************************/
{
int ii = m_LibList->GetSelection();
......@@ -398,9 +404,7 @@ void WinEDA_ViewlibFrame::ClickOnLibList( wxCommandEvent& event )
}
/****************************************************************/
void WinEDA_ViewlibFrame::ClickOnCmpList( wxCommandEvent& event )
/****************************************************************/
{
int ii = m_CmpList->GetSelection();
......@@ -418,12 +422,11 @@ void WinEDA_ViewlibFrame::ClickOnCmpList( wxCommandEvent& event )
}
/****************************************************************************/
void WinEDA_ViewlibFrame::ExportToSchematicLibraryPart( wxCommandEvent& event )
/****************************************************************************/
/* Export the current component to schematic and close the library browser
/*
* Export the current component to schematic and close the library browser
*/
void WinEDA_ViewlibFrame::ExportToSchematicLibraryPart( wxCommandEvent& event )
{
int ii = m_CmpList->GetSelection();
......
......@@ -22,13 +22,7 @@
#define PREVIOUS_PART -1
/* Routines locales */
/* Variables locales */
/*************************************************************************/
void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event )
/*************************************************************************/
{
wxString msg;
EDA_LibComponentStruct* LibEntry;
......@@ -63,7 +57,7 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event )
ALIAS );
if( LibEntry && ( !LibEntry->m_DocFile.IsEmpty() ) )
GetAssociatedDocument( this, LibEntry->m_DocFile,
& wxGetApp().GetLibraryPathList());
&wxGetApp().GetLibraryPathList() );
break;
case ID_LIBVIEW_DE_MORGAN_NORMAL_BUTT:
......@@ -96,26 +90,20 @@ void WinEDA_ViewlibFrame::Process_Special_Functions( wxCommandEvent& event )
}
/*************************************************************************/
void WinEDA_ViewlibFrame::OnLeftClick( wxDC* DC, const wxPoint& MousePos )
/*************************************************************************/
{
}
/********************************************************************************/
bool WinEDA_ViewlibFrame::OnRightClick( const wxPoint& MousePos,
wxMenu* PopMenu )
/********************************************************************************/
{
return true;
}
/**********************************************/
void WinEDA_ViewlibFrame::DisplayLibInfos()
/**********************************************/
/* Affiche en Ligne d'info la librairie en cours de visualisation */
void WinEDA_ViewlibFrame::DisplayLibInfos()
{
wxString msg;
LibraryStruct* Lib;
......@@ -162,10 +150,10 @@ void WinEDA_ViewlibFrame::SelectCurrentLibrary()
}
/**************************************************************/
/*
* Routine to select and view library Part (NEW, NEXT or PREVIOUS)
*/
void WinEDA_ViewlibFrame::SelectAndViewLibraryPart( int option )
/**************************************************************/
/* Routine to select and view library Part (NEW, NEXT or PREVIOUS) */
{
LibraryStruct* Lib;
......@@ -209,15 +197,14 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
wxString CmpName;
wxClientDC dc( DrawPanel );
DrawPanel->PrepareGraphicContext( &dc );
if( Lib )
NumOfParts = Lib->m_NumOfParts;
NumOfParts = Lib->GetCount();
if( NumOfParts == 0 )
{
DisplayError( this, wxT( "No Library or Library is empty!" ) );
DisplayError( this, wxT( "No library or library is empty!" ) );
return;
}
......@@ -226,9 +213,7 @@ void WinEDA_ViewlibFrame::ViewOneLibraryContent( LibraryStruct* Lib, int Flag )
if( Flag == NEW_PART )
{
DisplayComponentsNamesInLib( this,
Lib,
CmpName,
DisplayComponentsNamesInLib( this, Lib, CmpName,
g_CurrentViewComponentName );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment