Commit 8cad403d authored by Wayne Stambaugh's avatar Wayne Stambaugh

Use line reader to load component library files and objects.

parent d5ea4750
/*************************/
/* class_libentry.cpp */
/*************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file class_libentry.cpp
*/
#include "fctsys.h"
#include "macros.h"
......@@ -9,6 +34,7 @@
#include "plot_common.h"
#include "gr_basic.h"
#include "class_sch_screen.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -27,7 +53,7 @@
#include <boost/foreach.hpp>
// Set this to 1 to print debugging ouput in alias and component destructors to verify
// Set this to 1 to print debugging output in alias and component destructors to verify
// objects get cleaned up properly.
#if defined( TRACE_DESTRUCTOR )
#undef TRACE_DESTRUCTOR
......@@ -36,19 +62,6 @@
#define TRACE_DESTRUCTOR 0
/*******************************/
/* class LIB_ALIAS */
/*******************************/
/* Class to define an alias of a component
* An alias uses the component definition (graphic, pins...)
* but has its own name, keywords and documentation.
* Therefore, when the component is modified, alias of this component are
* modified.
* This is a simple method to create components with differs very few
* (like 74LS00, 74HC00 ... and many op amps )
*/
LIB_ALIAS::LIB_ALIAS( const wxString& aName, LIB_COMPONENT* aRootComponent ):
EDA_ITEM( LIB_ALIAS_T )
{
......@@ -71,7 +84,7 @@ LIB_ALIAS::LIB_ALIAS( const LIB_ALIAS& aAlias, LIB_COMPONENT* aRootComponent ) :
LIB_ALIAS::~LIB_ALIAS()
{
#if TRACE_DESTRUCTOR
wxLogDebug( wxT( "Destroying alias \"%s\" of component \"%s\" with alais list count %d." ),
wxLogDebug( wxT( "Destroying alias \"%s\" of component \"%s\" with alias list count %d." ),
GetChars( name ), GetChars( root->GetName() ), root->m_aliases.size() );
#endif
}
......@@ -97,14 +110,6 @@ CMP_LIBRARY* LIB_ALIAS::GetLibrary()
}
/**
* Function SaveDoc
* writes the doc info out to a FILE in "*.dcm" format.
* Only non empty fields are written.
* If all fields are empty, does not write anything
* @param aFile The FILE to write to.
* @return bool - true if success writing else false.
*/
bool LIB_ALIAS::SaveDoc( FILE* aFile )
{
if( description.IsEmpty() && keyWords.IsEmpty() && docFileName.IsEmpty() )
......@@ -150,17 +155,6 @@ int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 )
}
/***********************/
/* class LIB_COMPONENT */
/***********************/
/**
* Library component object definition.
*
* A library component object is typically saved and loaded
* in a component library file (.lib).
* Library components are different from schematic components.
*/
LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
EDA_ITEM( LIB_COMPONENT_T )
{
......@@ -174,7 +168,7 @@ LIB_COMPONENT::LIB_COMPONENT( const wxString& aName, CMP_LIBRARY* aLibrary ) :
m_showPinNumbers = true;
m_showPinNames = true;
// Create the default alias if the name paremeter is not empty.
// Create the default alias if the name parameter is not empty.
if( !aName.IsEmpty() )
m_aliases.push_back( new LIB_ALIAS( aName, this ) );
......@@ -256,12 +250,6 @@ wxString LIB_COMPONENT::GetLibraryName()
}
/**
* Function ReturnSubReference
* @return the sub reference for component having multiple parts per package.
* The sub reference identify the part (or unit)
* @param aUnit = the part identifier ( 1 to 26)
*/
wxString LIB_COMPONENT::ReturnSubReference( int aUnit )
{
wxString subRef;
......@@ -397,6 +385,7 @@ void LIB_COMPONENT::Plot( PLOTTER* aPlotter, int aUnit, int aConvert,
{
if( aUnit && item.m_Unit && ( item.m_Unit != aUnit ) )
continue;
if( aConvert && item.m_Convert && ( item.m_Convert != aConvert ) )
continue;
......@@ -467,6 +456,7 @@ LIB_ITEM* LIB_COMPONENT::GetNextDrawItem( LIB_ITEM* aItem, KICAD_T aType )
// Search for last item
size_t idx = 0;
if( aItem )
{
for( ; idx < drawings.size(); idx++ )
......@@ -612,6 +602,7 @@ bool LIB_COMPONENT::Save( FILE* aFile )
if( !fields[i].m_Text.IsEmpty() )
{
fields[i].SetId( fieldId++ );
if( !fields[i].Save( aFile ) )
return false;
}
......@@ -681,21 +672,25 @@ bool LIB_COMPONENT::Save( FILE* aFile )
}
bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg )
bool LIB_COMPONENT::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int unused;
char* p;
char* componentName;
char* prefix = NULL;
char* line;
bool Res;
wxString Msg;
p = strtok( aLine, " \t\r\n" );
line = aLineReader.Line();
p = strtok( line, " \t\r\n" );
if( strcmp( p, "DEF" ) != 0 )
{
aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ), *aLineNum );
aErrorMsg.Printf( wxT( "DEF command expected in line %d, aborted." ),
aLineReader.LineNumber() );
return false;
}
......@@ -716,10 +711,15 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aEr
|| ( p = strtok( NULL, " \t\n" ) ) == NULL /* m_unitCount: */
|| sscanf( p, "%d", &m_unitCount ) != 1 )
{
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ), *aLineNum );
while( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) )
aErrorMsg.Printf( wxT( "Wrong DEF format in line %d, skipped." ),
aLineReader.LineNumber() );
while( aLineReader.ReadLine() )
{
p = strtok( aLine, " \t\n" );
line = aLineReader.Line();
p = strtok( line, " \t\n" );
if( stricmp( p, "ENDDEF" ) == 0 )
break;
}
......@@ -738,6 +738,7 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aEr
LIB_FIELD& value = GetValueField();
strupper( componentName );
if( componentName[0] != '~' )
{
m_name = value.m_Text = FROM_UTF8( componentName );
......@@ -766,41 +767,45 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aEr
// Copy optional infos
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'L' )
m_unitsLocked = true;
if( ( p = strtok( NULL, " \t\n" ) ) != NULL && *p == 'P' )
m_options = ENTRY_POWER;
/* Read next lines */
while( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) )
while( aLineReader.ReadLine() )
{
p = strtok( aLine, " \t\n" );
line = aLineReader.Line();
p = strtok( line, " \t\r\n" );
/* This is the error flag ( if an error occurs, Res = FALSE) */
Res = true;
if( (aLine[0] == 'T') && (aLine[1] == 'i') )
Res = LoadDateAndTime( aLine );
else if( aLine[0] == 'F' )
Res = LoadField( aLine, Msg );
if( (*line == 'T') && (*(line + 1) == 'i') )
Res = LoadDateAndTime( aLineReader );
else if( *line == 'F' )
Res = LoadField( aLineReader, Msg );
else if( strcmp( p, "ENDDEF" ) == 0 )
break;
else if( strcmp( p, "DRAW" ) == 0 )
Res = LoadDrawEntries( aFile, aLine, aLineNum, Msg );
Res = LoadDrawEntries( aLineReader, Msg );
else if( strncmp( p, "ALIAS", 5 ) == 0 )
{
p = strtok( NULL, "\r\n" );
Res = LoadAliases( p, aErrorMsg );
}
else if( strncmp( p, "$FPLIST", 5 ) == 0 )
Res = LoadFootprints( aFile, aLine, aLineNum, Msg );
Res = LoadFootprints( aLineReader, Msg );
/* End line or block analysis: test for an error */
if( !Res )
{
if( Msg.IsEmpty() )
aErrorMsg.Printf( wxT( "error occurred at line %d " ), *aLineNum );
aErrorMsg.Printf( wxT( "error occurred at line %d " ), aLineReader.LineNumber() );
else
aErrorMsg.Printf( wxT( "error <%s> occurred at line %d " ),
GetChars( Msg ), *aLineNum );
GetChars( Msg ), aLineReader.LineNumber() );
return false;
}
}
......@@ -812,25 +817,27 @@ bool LIB_COMPONENT::Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aEr
}
bool LIB_COMPONENT::LoadDrawEntries( FILE* aFile, char* aLine,
int* aLineNum, wxString& aErrorMsg )
bool LIB_COMPONENT::LoadDrawEntries( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* line;
LIB_ITEM* newEntry = NULL;
while( true )
{
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
if( !aLineReader.ReadLine() )
{
aErrorMsg = wxT( "file ended prematurely loading component draw element" );
return false;
}
if( strncmp( aLine, "ENDDRAW", 7 ) == 0 )
line = aLineReader.Line();
if( strncmp( line, "ENDDRAW", 7 ) == 0 )
break;
newEntry = NULL;
switch( aLine[0] )
switch( line[0] )
{
case 'A': /* Arc */
newEntry = ( LIB_ITEM* ) new LIB_ARC( this );
......@@ -861,26 +868,26 @@ bool LIB_COMPONENT::LoadDrawEntries( FILE* aFile, char* aLine,
break;
default:
aErrorMsg.Printf( wxT( "undefined DRAW command %c" ), aLine[0] );
aErrorMsg.Printf( wxT( "undefined DRAW command %c" ), line[0] );
return false;
}
if( !newEntry->Load( aLine, aErrorMsg ) )
if( !newEntry->Load( aLineReader, aErrorMsg ) )
{
aErrorMsg.Printf( wxT( "error <%s> in DRAW command %c" ),
GetChars( aErrorMsg ), aLine[0] );
GetChars( aErrorMsg ), line[0] );
SAFE_DELETE( newEntry );
/* Flush till end of draw section */
do
{
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
if( !aLineReader.ReadLine() )
{
aErrorMsg = wxT( "file ended prematurely while attempting \
to flush to end of drawing section." );
return false;
}
} while( strncmp( aLine, "ENDDRAW", 7 ) != 0 );
} while( strncmp( line, "ENDDRAW", 7 ) != 0 );
return false;
}
......@@ -908,11 +915,11 @@ bool LIB_COMPONENT::LoadAliases( char* aLine, wxString& aErrorMsg )
}
bool LIB_COMPONENT::LoadField( char* aLine, wxString& aErrorMsg )
bool LIB_COMPONENT::LoadField( LINE_READER& aLineReader, wxString& aErrorMsg )
{
LIB_FIELD* field = new LIB_FIELD( this );
if( !field->Load( aLine, aErrorMsg ) )
if( !field->Load( aLineReader, aErrorMsg ) )
{
SAFE_DELETE( field );
return false;
......@@ -943,33 +950,32 @@ bool LIB_COMPONENT::LoadField( char* aLine, wxString& aErrorMsg )
}
bool LIB_COMPONENT::LoadFootprints( FILE* aFile, char* aLine,
int* aLineNum, wxString& aErrorMsg )
bool LIB_COMPONENT::LoadFootprints( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* line;
char* p;
while( true )
{
if( GetLine( aFile, aLine, aLineNum, LINE_BUFFER_LEN_LARGE ) == NULL )
if( !aLineReader.ReadLine() )
{
aErrorMsg = wxT( "file ended prematurely while loading footprints" );
return false;
}
if( stricmp( aLine, "$ENDFPLIST" ) == 0 )
line = aLineReader.Line();
p = strtok( line, " \t\r\n" );
if( stricmp( p, "$ENDFPLIST" ) == 0 )
break;
m_FootprintList.Add( FROM_UTF8( aLine + 1 ) );
m_FootprintList.Add( FROM_UTF8( p ) );
}
return true;
}
/* Return the component boundary box ( in user coordinates )
* aUnit = unit selection = 0, or 1..n
* aConvert = 0, 1 or 2
* If aUnit == 0, unit is not used
* if aConvert == 0 Convert is non used
* Invisible fields are not taken in account
**/
EDA_RECT LIB_COMPONENT::GetBoundingBox( int aUnit, int aConvert ) const
{
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
......@@ -993,13 +999,6 @@ EDA_RECT LIB_COMPONENT::GetBoundingBox( int aUnit, int aConvert ) const
}
/* Return the component boundary box ( in user coordinates )
* aUnit = unit selection = 0, or 1..n
* aConvert = 0, 1 or 2
* If aUnit == 0, unit is not used
* if aConvert == 0 Convert is non used
* Fields are not take in account
**/
EDA_RECT LIB_COMPONENT::GetBodyBoundingBox( int aUnit, int aConvert ) const
{
EDA_RECT bBox( wxPoint( 0, 0 ), wxSize( 0, 0 ) );
......@@ -1085,6 +1084,7 @@ void LIB_COMPONENT::GetFields( LIB_FIELDS& aList )
continue;
field = ( LIB_FIELD* ) &item;
if( (unsigned) field->GetId() < MANDATORY_FIELDS )
continue; // was added above
......@@ -1143,10 +1143,6 @@ LIB_FIELD& LIB_COMPONENT::GetReferenceField()
}
/*
* Read date and time of component in the format:
* "Ti yy/mm/jj hh:mm:ss"
*/
bool LIB_COMPONENT::SaveDateAndTime( FILE* aFile )
{
int year, mon, day, hour, min, sec;
......@@ -1167,9 +1163,6 @@ bool LIB_COMPONENT::SaveDateAndTime( FILE* aFile )
return true;
}
/* lit date et time de modif composant sous le format:
* "Ti yy/mm/jj hh:mm:ss"
*/
bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
{
int year, mon, day, hour, min, sec;
......@@ -1178,12 +1171,12 @@ bool LIB_COMPONENT::LoadDateAndTime( char* aLine )
strtok( aLine, " \r\t\n" );
strtok( NULL, " \r\t\n" );
if (sscanf( aLine, "%d/%d/%d %d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) != 6 )
if( sscanf( aLine, "%d/%d/%d %d:%d:%d", &year, &mon, &day, &hour, &min, &sec ) != 6 )
return false;
m_dateModified = ( sec & 63 ) + ( ( min & 63 ) << 6 ) +
( ( hour & 31 ) << 12 ) + ( ( day & 31 ) << 17 ) +
( ( mon & 15 ) << 22 ) + ( ( year - 1990 ) << 26 );
( ( hour & 31 ) << 12 ) + ( ( day & 31 ) << 17 ) +
( ( mon & 15 ) << 22 ) + ( ( year - 1990 ) << 26 );
return true;
}
......@@ -1316,6 +1309,7 @@ void LIB_COMPONENT::CopySelectedItems( const wxPoint& aOffset )
* a memory reallocation can happen and will break pointers
*/
unsigned icnt = drawings.size();
for( unsigned ii = 0; ii < icnt; ii++ )
{
LIB_ITEM& item = drawings[ii];
......@@ -1448,6 +1442,7 @@ void LIB_COMPONENT::SetPartCount( int aCount )
// the buffer can be reallocated, that change the previous value of
// .begin() and .end() iterators and invalidate others iterators
unsigned imax = drawings.size();
for( unsigned ii = 0; ii < imax; ii++ )
{
if( drawings[ii].m_Unit != 1 )
......@@ -1476,12 +1471,12 @@ void LIB_COMPONENT::SetConversion( bool aSetConvert )
// Duplicate items to create the converted shape
if( aSetConvert )
{
BOOST_FOREACH( LIB_ITEM& item, drawings )
{
/* Only pins are duplicated. */
if( item.Type() != LIB_PIN_T )
continue;
if( item.m_Convert == 1 )
{
LIB_ITEM* newItem = (LIB_ITEM*) item.Clone();
......
/******************************************/
/* Library component object definitions. */
/******************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file class_libentry.h
*/
#ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H
......@@ -12,6 +37,7 @@
#include <map>
class LINE_READER;
class CMP_LIBRARY;
class LIB_ALIAS;
class LIB_COMPONENT;
......@@ -45,8 +71,11 @@ enum LibrEntryOptions
/**
* Component library alias object definition.
*
* Component aliases are not really components. They are references
* to an actual component object.
* Component aliases are not really components. An alias uses the component definition
* (graphic, pins...) but has its own name, keywords and documentation. Therefore, when
* the component is modified, alias of this component are modified. This is a simple
* method to create components that have the same physical layout with different names
* such as 74LS00, 74HC00 ... and many op amps.
*/
class LIB_ALIAS : public EDA_ITEM
{
......@@ -144,7 +173,8 @@ extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2
/**
* Library component object definition.
* Class LIB_COMPONENT
* defines a library component object.
*
* A library component object is typically saved and loaded in a component library file (.lib).
* Library components are different from schematic components.
......@@ -207,7 +237,7 @@ public:
* Add an alias \a aName to the component.
*
* Duplicate alias names are not added to the alias list. Debug builds will raise an
* assertion. Release builds will fail silenetly.
* assertion. Release builds will fail silently.
*
* @param aName - Name of alias to add.
*/
......@@ -255,7 +285,16 @@ public:
**/
EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
/**
* Function SaveDateAndTime
* write the date and time of component to \a aFile in the format:
* "Ti yy/mm/jj hh:mm:ss"
*
* @param aFile A point to a FILE object containing the file to write to.
* @return True if the date and time were successfully written to \a aFile.
*/
bool SaveDateAndTime( FILE* aFile );
bool LoadDateAndTime( char* aLine );
/**
......@@ -267,19 +306,17 @@ public:
bool Save( FILE* aFile );
/**
* Load component definition from \a aFile.
* Load component definition from \a aReader.
*
* @param aFile - File descriptor of file to load form.
* @param aLine - The first line of the component definition.
* @param aLineNum - The current line number in the file.
* @param aReader A LINE_READER object to load file from.
* @param aErrorMsg - Description of error on load failure.
* @return True if the load was successful, false if there was an error.
*/
bool Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool LoadField( char* aLine, wxString& aErrorMsg );
bool LoadDrawEntries( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool Load( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadField( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadDrawEntries( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadAliases( char* aLine, wxString& aErrorMsg );
bool LoadFootprints( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool LoadFootprints( LINE_READER& aReader, wxString& aErrorMsg );
bool IsPower() { return m_options == ENTRY_POWER; }
bool IsNormal() { return m_options == ENTRY_NORMAL; }
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file class_library.cpp
*/
......@@ -10,6 +35,7 @@
#include "gestfich.h"
#include "eda_doc.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -129,6 +155,7 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames,
{
if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) )
aNames.Add( (*it).first );
if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch,
(*it).second->GetName(), false ) )
aNames.Add( (*it).first );
......@@ -186,10 +213,6 @@ LIB_ALIAS* CMP_LIBRARY::FindEntry( const wxChar* aName )
}
/**
* Return the first entry in the library.
* @return The first entry or NULL if the library has no entries.
*/
LIB_ALIAS* CMP_LIBRARY::GetFirstEntry()
{
if( aliases.size() )
......@@ -198,6 +221,7 @@ LIB_ALIAS* CMP_LIBRARY::GetFirstEntry()
return NULL;
}
LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* aName )
{
LIB_COMPONENT* component = NULL;
......@@ -279,7 +303,7 @@ LIB_ALIAS* CMP_LIBRARY::RemoveEntry( LIB_ALIAS* aEntry )
return NULL;
// If the entry pointer doesn't match the name it is mapped to in the library, we
// have done someething terribly wrong.
// have done something terribly wrong.
wxCHECK_MSG( (*it).second == aEntry, NULL,
wxT( "Pointer mismatch while attempting to remove entry <" ) +
aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) );
......@@ -380,8 +404,7 @@ LIB_ALIAS* CMP_LIBRARY::GetPreviousEntry( const wxChar* aName )
bool CMP_LIBRARY::Load( wxString& aErrorMsg )
{
FILE* file;
int lineNumber = 0;
char line[LINE_BUFFER_LEN_LARGE]; // Use a very large buffer to load data
char* line;
LIB_COMPONENT* libEntry;
wxString msg;
......@@ -399,10 +422,11 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
return false;
}
if( GetLine( file, line, &lineNumber, sizeof( line ) ) == NULL )
FILE_LINE_READER reader( file, fileName.GetFullPath() );
if( !reader.ReadLine() )
{
aErrorMsg = _( "The file is empty!" );
fclose( file );
return false;
}
......@@ -411,6 +435,8 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
{
wxString tmp;
line = reader.Line();
header = FROM_UTF8( line );
wxStringTokenizer tkn( header );
......@@ -426,21 +452,18 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
|| !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) )
{
aErrorMsg = _( "The file is NOT an Eeschema library!" );
fclose( file );
return false;
}
if( !tkn.HasMoreTokens() )
{
aErrorMsg = _( "The file header is missing version and time stamp information." );
fclose( file );
return false;
}
if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() )
{
aErrorMsg = wxT( "The file header version information is invalid." );
fclose( file );
return false;
}
......@@ -466,19 +489,18 @@ the current schematic." ),
{
versionMajor = (int) major;
versionMinor = (int) minor;
// wxLogDebug( wxT( "Component library <%s> is version %d.%d." ),
// GetChars( GetName() ), versionMajor, versionMinor );
}
}
while( GetLine( file, line, &lineNumber, sizeof( line ) ) )
while( reader.ReadLine() )
{
line = reader.Line();
if( type == LIBRARY_TYPE_EESCHEMA && strnicmp( line, "$HEADER", 7 ) == 0 )
{
if( !LoadHeader( file, &lineNumber ) )
if( !LoadHeader( reader ) )
{
aErrorMsg = _( "An error occurred attempting to read the header." );
fclose( file );
return false;
}
......@@ -490,7 +512,7 @@ the current schematic." ),
/* Read one DEF/ENDDEF part entry from library: */
libEntry = new LIB_COMPONENT( wxEmptyString, this );
if( libEntry->Load( file, line, &lineNumber, msg ) )
if( libEntry->Load( reader, msg ) )
{
/* Check for duplicate entry names and warn the user about
* the potential conflict.
......@@ -516,8 +538,6 @@ the current schematic." ),
}
}
fclose( file );
return true;
}
......@@ -542,13 +562,15 @@ void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component )
}
bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum )
bool CMP_LIBRARY::LoadHeader( LINE_READER& aLineReader )
{
char Line[LINE_BUFFER_LEN], * text, * data;
char* line, * text, * data;
while( GetLine( libfile, Line, LineNum, sizeof(Line) ) )
while( aLineReader.ReadLine() )
{
text = strtok( Line, " \t\r\n" );
line = (char*) aLineReader;
text = strtok( line, " \t\r\n" );
data = strtok( NULL, " \t\r\n" );
if( stricmp( text, "TimeStamp" ) == 0 )
......@@ -558,7 +580,7 @@ bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum )
return true;
}
return FALSE;
return false;
}
......@@ -618,6 +640,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg )
{
if( strncmp( line, "$ENDCMP", 7 ) == 0 )
break;
text = strtok( line + 2, "\n\r" );
if( entry )
......@@ -662,7 +685,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
{
libFileName.MakeAbsolute();
msg = wxT( "Failed to rename old component library file " ) +
backupFileName.GetFullPath();
backupFileName.GetFullPath();
DisplayError( NULL, msg );
}
}
......@@ -680,6 +703,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
isModified = false;
timeStamp = GetTimeStamp();
if( !SaveHeader( libfile ) )
{
fclose( libfile );
......@@ -728,7 +752,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
msg = wxT( "Failed to save old library document file " ) +
backupFileName.GetFullPath();
backupFileName.GetFullPath();
DisplayError( NULL, msg );
}
}
......@@ -739,12 +763,13 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
{
docFileName.MakeAbsolute();
msg = wxT( "Failed to create component document library file " ) +
docFileName.GetFullPath();
docFileName.GetFullPath();
DisplayError( NULL, msg );
return false;
}
char line[256];
if( fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT, DateAndTime( line ) ) < 0 )
{
fclose( docfile );
......@@ -774,6 +799,7 @@ bool CMP_LIBRARY::SaveHeader( FILE* aFile )
bool succes = true;
DateAndTime( BufLine );
if( fprintf( aFile, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
succes = false;
......@@ -884,11 +910,6 @@ void CMP_LIBRARY::RemoveLibrary( const wxString& aName )
}
/**
* Test for an existing library.
* @param aLibptr - aLibptr.
* @return true found. false if not found.
*/
bool CMP_LIBRARY::LibraryExists( const CMP_LIBRARY* aLibptr )
{
BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
......
......@@ -6,12 +6,14 @@
#ifndef CLASS_LIBRARY_H
#define CLASS_LIBRARY_H
#include <wx/filename.h>
#include "class_libentry.h"
class LINE_READER;
/*
* Component Library version and file header macros.
*/
......@@ -130,7 +132,7 @@ public:
private:
bool SaveHeader( FILE* aFile );
bool LoadHeader( FILE* aFile, int* aLineNum );
bool LoadHeader( LINE_READER& aLineReader );
void LoadAliases( LIB_COMPONENT* aComponent );
public:
......
/*******************/
/** class LIB_ARC **/
/*******************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_arc.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -9,6 +34,7 @@
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -79,11 +105,6 @@ LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_ITEM( aArc )
}
/**
* format:
* A centre_posx centre_posy rayon start_angle end_angle unit convert
* fill('N', 'F' ou 'f') startx starty endx endy
*/
bool LIB_ARC::Save( FILE* aFile )
{
int x1 = m_t1;
......@@ -106,12 +127,13 @@ bool LIB_ARC::Save( FILE* aFile )
}
bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg )
bool LIB_ARC::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int startx, starty, endx, endy, cnt;
int startx, starty, endx, endy, cnt;
char tmp[256];
char* line = (char*) aLineReader;
cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %d %d %s %d %d %d %d",
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %d %s %d %d %d %d",
&m_Pos.x, &m_Pos.y, &m_Radius, &m_t1, &m_t2, &m_Unit,
&m_Convert, &m_Width, tmp, &startx, &starty, &endx, &endy );
if( cnt < 8 )
......@@ -122,6 +144,7 @@ bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
......@@ -326,10 +349,6 @@ void LIB_ARC::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_ARC::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
......@@ -383,6 +402,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
int pt1 = m_t1;
int pt2 = m_t2;
bool swap = aTransform.MapAngles( &pt1, &pt2 );
if( swap )
{
EXCHG( pos1.x, pos2.x );
......@@ -392,6 +412,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
GRSetDrawMode( aDC, aDrawMode );
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -470,10 +491,13 @@ start(%d, %d), end(%d, %d), radius %d" ),
if( angleStart <= 900 && angleEnd >= 900 ) /* 90 deg */
maxY = centerPos.y + m_Radius;
if( angleStart <= 1800 && angleEnd >= 1800 ) /* 180 deg */
minX = centerPos.x - m_Radius;
if( angleStart <= 2700 && angleEnd >= 2700 ) /* 270 deg */
minY = centerPos.y - m_Radius;
if( angleStart <= 3600 && angleEnd >= 3600 ) /* 0 deg */
maxX = centerPos.x + m_Radius;
......@@ -552,7 +576,9 @@ void LIB_ARC::BeginEdit( int aEditMode, const wxPoint aPosition )
m_editSelectPoint = END;
}
else
{
m_editSelectPoint = OUTLINE;
}
m_editState = 0;
SetEraseLastDrawItem();
......
/**************************/
/* Graphic Body Item: Arc */
/**************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_arc.h
*/
#ifndef _LIB_ARC_H_
#define _LIB_ARC_H_
......@@ -10,6 +35,7 @@
class TRANSFORM;
class LINE_READER;
class LIB_ARC : public LIB_ITEM
......@@ -77,7 +103,8 @@ public:
* @return - True if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Tests if the given wxPoint is within the bounds of this object.
......@@ -100,6 +127,7 @@ public:
virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/**********************/
/** class LIB_BEZIER **/
/**********************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_bezier.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -10,6 +35,7 @@
#include "trigo.h"
#include "wxstruct.h"
#include "bezier_curves.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -56,26 +82,28 @@ bool LIB_BEZIER::Save( FILE* aFile )
}
bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
bool LIB_BEZIER::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* p;
int i, ccount = 0;
wxPoint pt;
char* line = (char*) aLineReader;
i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
i = sscanf( line + 2, "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
if( i !=4 )
{
aErrorMsg.Printf( _( "Bezier only had %d parameters of the required 4" ), i );
return false;
}
if( ccount <= 0 )
{
aErrorMsg.Printf( _( "Bezier count parameter %d is invalid" ), ccount );
return false;
}
p = strtok( &aLine[2], " \t\n" );
p = strtok( line + 2, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
......@@ -84,17 +112,21 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
{
wxPoint point;
p = strtok( NULL, " \t\n" );
if( sscanf( p, "%d", &pt.x ) != 1 )
{
aErrorMsg.Printf( _( "Bezier point %d X position not defined" ), i );
return false;
}
p = strtok( NULL, " \t\n" );
if( sscanf( p, "%d", &pt.y ) != 1 )
{
aErrorMsg.Printf( _( "Bezier point %d Y position not defined" ), i );
return false;
}
m_BezierPoints.push_back( pt );
}
......@@ -104,6 +136,7 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
{
if( p[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( p[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
}
......@@ -131,6 +164,7 @@ int LIB_BEZIER::DoCompare( const LIB_ITEM& aOther ) const
{
if( m_BezierPoints[i].x != tmp->m_BezierPoints[i].x )
return m_BezierPoints[i].x - tmp->m_BezierPoints[i].x;
if( m_BezierPoints[i].y != tmp->m_BezierPoints[i].y )
return m_BezierPoints[i].y - tmp->m_BezierPoints[i].y;
}
......@@ -181,6 +215,7 @@ void LIB_BEZIER::DoMirrorHorizontal( const wxPoint& aCenter )
}
imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ )
{
m_BezierPoints[i].x -= aCenter.x;
......@@ -201,6 +236,7 @@ void LIB_BEZIER::DoMirrorVertical( const wxPoint& aCenter )
}
imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ )
{
m_BezierPoints[i].y -= aCenter.y;
......@@ -214,12 +250,14 @@ void LIB_BEZIER::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
int rot_angle = aRotateCCW ? -900 : 900;
size_t i, imax = m_PolyPoints.size();
for( i = 0; i < imax; i++ )
{
RotatePoint( &m_PolyPoints[i], aCenter, rot_angle );
}
imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ )
{
RotatePoint( &m_BezierPoints[i], aCenter, rot_angle );
......@@ -254,15 +292,12 @@ void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_BEZIER::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
}
void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform )
{
......@@ -288,9 +323,12 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -319,28 +357,18 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param aRefPos A wxPoint to test
* @return true if a hit, else false
*/
bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
{
int mindist = GetPenSize() / 2;
// Have a minimal tolerance for hit test
if ( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aRefPos, mindist, DefaultTransform );
}
/**
* Function HitTest
* @return if the point aPosRef is near a segment
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to a segment
* @param aTransform = the transform matrix
*/
bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform )
{
wxPoint ref, start, end;
......@@ -361,10 +389,6 @@ bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra
}
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
EDA_RECT LIB_BEZIER::GetBoundingBox() const
{
EDA_RECT rect;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_bezier.h
*/
#ifndef _LIB_BEZIER_H_
#define _LIB_BEZIER_H_
#include "lib_draw_item.h"
class LINE_READER;
/**************************************************/
/* Graphic Body Item: Bezier Curve (set of lines) */
/**************************************************/
......@@ -39,7 +69,8 @@ public:
* @return true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
......@@ -65,11 +96,13 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
virtual EDA_RECT GetBoundingBox() const;
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_circle.cpp
* @brief LIB_CIRCLE class definition
* @brief LIB_CIRCLE class implementation.
*/
#include "fctsys.h"
......@@ -10,6 +35,7 @@
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -48,11 +74,12 @@ bool LIB_CIRCLE::Save( FILE* aFile )
}
bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
bool LIB_CIRCLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char tmp[256];
char* line = (char*) aLineReader;
int cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
int cnt = sscanf( line + 2, "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
&m_Radius, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 6 )
......@@ -63,6 +90,7 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
......@@ -70,12 +98,6 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param aPosRef A wxPoint to test in Eeschema space
* @return - true if a hit, else false
*/
bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
{
int mindist = GetPenSize() / 2;
......@@ -88,13 +110,6 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
}
/**
* 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 aTransform = the transform matrix
*/
bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform )
{
if( aThreshold < 0 )
......@@ -165,6 +180,7 @@ void LIB_CIRCLE::DoMirrorHorizontal( const wxPoint& aCenter )
m_Pos.x += aCenter.x;
}
void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter )
{
m_Pos.y -= aCenter.y;
......@@ -172,6 +188,7 @@ void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter )
m_Pos.y += aCenter.y;
}
void LIB_CIRCLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
{
int rot_angle = aRotateCCW ? -900 : 900;
......@@ -197,10 +214,6 @@ void LIB_CIRCLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_CIRCLE::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
......@@ -220,7 +233,9 @@ void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
GRSetDrawMode( aDC, aDrawMode );
......
/*****************************/
/* Graphic Body Item: Circle */
/*****************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_circle.h
*/
#ifndef _LIB_CIRCLE_H_
#define _LIB_CIRCLE_H_
#include "lib_draw_item.h"
class LINE_READER;
class LIB_CIRCLE : public LIB_ITEM
{
int m_Radius;
......@@ -32,6 +59,7 @@ public:
LIB_CIRCLE( LIB_COMPONENT * aParent );
LIB_CIRCLE( const LIB_CIRCLE& aCircle );
~LIB_CIRCLE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_CIRCLE" );
......@@ -45,7 +73,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
......@@ -65,11 +94,13 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
virtual EDA_RECT GetBoundingBox() const;
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
......
/*********************/
/* lib_draw_item.cpp */
/*********************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_draw_item.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -16,7 +41,6 @@ const int fill_tab[3] = { 'N', 'F', 'f' };
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
/* Base class (abstract) for components bodies items */
LIB_ITEM::LIB_ITEM( KICAD_T aType,
LIB_COMPONENT* aComponent,
int aUnit,
......@@ -46,13 +70,6 @@ LIB_ITEM::LIB_ITEM( const LIB_ITEM& aItem ) :
}
/**
* Update the message panel information with the drawing information.
*
* This base function is used to display the information common to the
* all library items. Call the base class from the derived class or the
* common information will not be updated in the message panel.
*/
void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame )
{
wxString msg;
......
/****************************************************************/
/* Headers for library definition and lib component definitions */
/****************************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Definitions of graphic items used to create shapes in component libraries.
/**
* @file class_libentry.h
* @brief Class LIB_ITEM definition.
*/
#ifndef _LIB_ITEM_H_
#define _LIB_ITEM_H_
......@@ -13,6 +37,7 @@
#include <boost/ptr_container/ptr_vector.hpp>
class LINE_READER;
class LIB_COMPONENT;
class PLOTTER;
class LIB_ITEM;
......@@ -35,7 +60,7 @@ typedef boost::ptr_vector< LIB_ITEM > LIB_ITEMS;
/**
* Helper for defining a list of pin object pointers. The list does not
* use a Boost pointer class so the object pointers do not accidently get
* use a Boost pointer class so the object pointers do not accidentally get
* deleted when the container is deleted.
*/
typedef std::vector< LIB_PIN* > LIB_PINS;
......@@ -194,7 +219,7 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) = 0;
virtual bool Load( char* aLine, wxString& aErrorMsg ) = 0;
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0;
LIB_COMPONENT* GetParent()
{
......@@ -232,9 +257,15 @@ public:
virtual EDA_RECT GetBoundingBox() const { return EDA_ITEM::GetBoundingBox(); }
/**
* Displays basic info (type, part and convert) about item
* in msg panel
* @param aFrame = main frame where the message manel info is.
* Function DisplayInfo
* displays basic info (type, part and convert) about the current item
* in message panel.
* <p>
* This base function is used to display the information common to the
* all library items. Call the base class from the derived class or the
* common information will not be updated in the message panel.
* </p>
* @param aFrame A pointer to EDA_DRAW_FRAME window where the message panel resides.
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
......
/**********************************************************/
/* libclass.cpp */
/**********************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_field.cpp
*/
#include "fctsys.h"
#include "appl_wxstruct.h"
......@@ -21,24 +46,6 @@
#include "template_fieldnames.h"
/*******************/
/* class LIB_FIELD */
/*******************/
/**
* a Field is a string linked to a component.
* Unlike a pure graphic text, fields can be used in netlist generation
* and other tools (BOM).
*
* The first 4 fields have a special meaning:
*
* 0 = REFERENCE
* 1 = VALUE
* 2 = FOOTPRINT (default Footprint)
* 3 = DOCUMENTATION (user doc link)
*
* others = free fields
*/
LIB_FIELD::LIB_FIELD(LIB_COMPONENT * aParent, int idfield ) :
LIB_ITEM( LIB_FIELD_T, aParent )
{
......@@ -143,13 +150,14 @@ bool LIB_FIELD::Save( FILE* ExportFile )
}
bool LIB_FIELD::Load( char* line, wxString& errorMsg )
bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
{
int cnt;
char textOrient;
char textVisible;
char textHJustify;
char textVJustify[256];
char* line = (char*) aLineReader;
if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
{
......@@ -267,20 +275,12 @@ bool LIB_FIELD::Load( char* line, wxString& errorMsg )
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_FIELD::GetPenSize() const
{
return ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
}
/*
* if aData not NULL, aData must point a wxString which is used instead of
* the m_Text
*/
void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform )
{
......@@ -458,7 +458,7 @@ void LIB_FIELD::DoOffset( const wxPoint& offset )
bool LIB_FIELD::DoTestInside( EDA_RECT& rect ) const
{
/*
* FIXME: This fails to take into acount the size and/or orientation of
* FIXME: This fails to take into account the size and/or orientation of
* the text.
*/
return rect.Contains( m_Pos.x, -m_Pos.y );
......@@ -499,12 +499,6 @@ void LIB_FIELD::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
}
/*
* If the field is the reference, return reference like schematic,
* i.e U -> U? or U?A or the field text for others
*
* @fixme This should be handled by the field object.
*/
wxString LIB_FIELD::GetFullText( int unit )
{
if( m_id != REFERENCE )
......
/*************************************************************/
/* Lib component definitions (libentry) definition of fields */
/*************************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_field.h
*/
#ifndef CLASS_LIBENTRY_FIELDS_H
#define CLASS_LIBENTRY_FIELDS_H
......@@ -13,6 +38,20 @@
* is used in symbol libraries. At least MANDATORY_FIELDS are always present
* in a ram resident library symbol. All constructors must ensure this because
* the component property editor assumes it.
* <p>
* A field is a string linked to a component. Unlike purely graphical text, fields can
* be used in netlist generation and other tools (BOM).
*
* The first 4 fields have a special meaning:
*
* 0 = REFERENCE
* 1 = VALUE
* 2 = FOOTPRINT (default Footprint)
* 3 = DOCUMENTATION (user doc link)
*
* others = free fields
* </p>
*
* @see enum NumFieldType
*/
class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
......@@ -26,6 +65,10 @@ class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
/**
* Draw the field.
* <p>
* If \a aData not NULL, \a aData must point a wxString which is used instead of
* the m_Text
* </p>
*/
void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
......@@ -63,7 +106,7 @@ public:
*
* @param aTranslate = true to return translated field name (default)
* false to return the english name
* (usefull when the name is used as keyword in netlists ...)
* (useful when the name is used as keyword in netlists ...)
* @return Name of the field.
*/
wxString GetName(bool aTranslate = true) const;
......@@ -98,16 +141,17 @@ public:
* @return True if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* line, wxString& errorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& errorMsg );
/**
* Copy parameters of this field to another field. Pointers are not copied.
*
* @param aTarget = Target field to copy values to.
*/
void Copy( LIB_FIELD* aTarget ) const;
void Copy( LIB_FIELD* aTarget ) const;
void SetFields( const std::vector <LIB_FIELD> aFields );
void SetFields( const std::vector <LIB_FIELD> aFields );
/**
* Function IsVoid
......@@ -136,7 +180,7 @@ public:
/**
* Displays info (type, part convert filed name and value)
* in msg panel
* @param aFrame = main frame where the message manel info is.
* @param aFrame = main frame where the message panel info is.
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
......@@ -182,6 +226,8 @@ public:
* create a pseudo reference text. If the base reference field is U,
* the string U?A will be returned for unit = 1.
*
* @todo This should be handled by the field object.
*
* @param unit - The package unit number. Only effects reference field.
* @return Field text.
*/
......@@ -209,7 +255,7 @@ public:
/**
* Sets the field text to \a aText.
*
* This method does more than juat set the set the field text. There are special
* This method does more than just set the set the field text. There are special
* cases when changing the text string alone is not enough. If the field is the
* value field, the parent component's name is changed as well. If the field is
* being moved, the name change must be delayed until the next redraw to prevent
......
......@@ -36,6 +36,7 @@
#include "drawtxt.h"
#include "plot_common.h"
#include "wxEeschemaStruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -677,7 +678,7 @@ bool LIB_PIN::Save( FILE* ExportFile )
}
bool LIB_PIN::Load( char* line, wxString& errorMsg )
bool LIB_PIN::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int i, j;
char pinAttrs[64];
......@@ -685,6 +686,7 @@ bool LIB_PIN::Load( char* line, wxString& errorMsg )
char pinNum[64];
char pinOrient[64];
char pinType[64];
char* line = (char*) aLineReader;
*pinAttrs = 0;
......@@ -694,7 +696,7 @@ bool LIB_PIN::Load( char* line, wxString& errorMsg )
if( i < 11 )
{
errorMsg.Printf( wxT( "pin only had %d parameters of the required 11 or 12" ), i );
aErrorMsg.Printf( wxT( "pin only had %d parameters of the required 11 or 12" ), i );
return false;
}
......@@ -749,7 +751,7 @@ bool LIB_PIN::Load( char* line, wxString& errorMsg )
break;
default:
errorMsg.Printf( wxT( "unknown pin type [%c]" ), *pinType & 255 );
aErrorMsg.Printf( wxT( "unknown pin type [%c]" ), *pinType & 255 );
return false;
}
......@@ -791,7 +793,7 @@ bool LIB_PIN::Load( char* line, wxString& errorMsg )
break;
default:
errorMsg.Printf( wxT( "unknown pin attribute [%c]" ), pinAttrs[j] );
aErrorMsg.Printf( wxT( "unknown pin attribute [%c]" ), pinAttrs[j] );
return false;
}
}
......@@ -801,10 +803,6 @@ bool LIB_PIN::Load( char* line, wxString& errorMsg )
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_PIN::GetPenSize() const
{
return ( m_width == 0 ) ? g_DrawDefaultLineThickness : m_width;
......@@ -873,11 +871,6 @@ void LIB_PIN::drawGraphic( EDA_DRAW_PANEL* aPanel,
}
/**
* Function DrawPinSymbol
* Draw the pin symbol (without texts)
* if Color != 0 draw with Color, else with the normal pin color
*/
void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
wxDC* aDC,
const wxPoint& aPinPos,
......@@ -1068,10 +1061,10 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
color );
}
/* Draw the pin end target (active end of the pin)
*/
// Draw the pin end target (active end of the pin)
BASE_SCREEN* screen = aPanel ? aPanel->GetScreen() : NULL;
#define NCSYMB_PIN_DIM TARGET_PIN_RADIUS
if( m_type == PIN_NC ) // Draw a N.C. symbol
{
GRLine( clipbox, aDC,
......@@ -1083,8 +1076,7 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
posX - NCSYMB_PIN_DIM, posY + NCSYMB_PIN_DIM,
width, color );
}
/* Draw but do not print the pin end target 1 pixel width
*/
// Draw but do not print the pin end target 1 pixel width
else if( screen == NULL || !screen->m_IsPrinting )
{
GRCircle( clipbox, aDC, posX, posY, TARGET_PIN_RADIUS, 0, color );
......@@ -1092,15 +1084,6 @@ void LIB_PIN::DrawPinSymbol( EDA_DRAW_PANEL* aPanel,
}
/*****************************************************************************
* Put out pin number and pin text info, given the pin line coordinates.
* The line must be vertical or horizontal.
* If PinText == NULL nothing is printed. If PinNum = 0 no number is printed.
* Current Zoom factor is taken into account.
* If TextInside then the text is been put inside,otherwise all is drawn outside.
* Pin Name: substring beteween '~' is negated
* DrawMode = GR_OR, XOR ...
*****************************************************************************/
void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
wxDC* DC,
wxPoint& pin_pos,
......@@ -1129,6 +1112,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
/* Get the num and name colors */
if( (Color < 0) && (m_Selected & IS_SELECTED) )
Color = g_ItemSelectetColor;
NameColor = (EDA_Colors) ( Color == -1 ? ReturnLayerColor( LAYER_PINNAM ) : Color );
NumColor = (EDA_Colors) ( Color == -1 ? ReturnLayerColor( LAYER_PINNUM ) : Color );
......@@ -1217,6 +1201,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
GR_TEXT_HJUSTIFY_RIGHT,
GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
false, false );
if( DrawPinNum )
DrawGraphicText( panel, DC,
wxPoint( x1 - TXTMARGE,
......@@ -1238,6 +1223,7 @@ void LIB_PIN::DrawPinTexts( EDA_DRAW_PANEL* panel,
GR_TEXT_HJUSTIFY_LEFT,
GR_TEXT_VJUSTIFY_CENTER, nameLineWidth,
false, false );
if( DrawPinNum )
DrawGraphicText( panel, DC,
wxPoint( x1 - TXTMARGE,
......@@ -1408,15 +1394,6 @@ void LIB_PIN::PlotSymbol( PLOTTER* aPlotter, const wxPoint& aPosition, int aOrie
}
/*****************************************************************************
* Plot pin number and pin text info, given the pin line coordinates. *
* Same as DrawPinTexts((), but output is the plotter
* The line must be vertical or horizontal. *
* If PinNext == NULL nothing is printed. *
* Current Zoom factor is taken into account. *
* If TextInside then the text is been put inside (moving from x1, y1 in *
* the opposite direction to x2,y2), otherwise all is drawn outside. *
*****************************************************************************/
void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
wxPoint& pin_pos,
int orient,
......@@ -1495,8 +1472,7 @@ void LIB_PIN::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,
......@@ -1517,6 +1493,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
GR_TEXT_HJUSTIFY_RIGHT,
GR_TEXT_VJUSTIFY_CENTER,
aWidth, false, false );
if( DrawPinNum )
{
plotter->text( wxPoint( x1 - TXTMARGE, (y1 + pin_pos.y) / 2 ),
......@@ -1538,6 +1515,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
GR_TEXT_HJUSTIFY_LEFT,
GR_TEXT_VJUSTIFY_CENTER,
aWidth, false, false );
if( DrawPinNum )
{
plotter->text( wxPoint( x1 - TXTMARGE, (y1 + pin_pos.y) / 2 ),
......@@ -1565,6 +1543,7 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
GR_TEXT_VJUSTIFY_BOTTOM,
aWidth, false, false );
}
if( DrawPinNum )
{
x = ( x1 + pin_pos.x ) / 2;
......@@ -1603,7 +1582,6 @@ void LIB_PIN::PlotPinTexts( PLOTTER* plotter,
}
/* return the pin end position, for a component in normal orient */
wxPoint LIB_PIN::ReturnPinEndPoint() const
{
wxPoint pos = m_position;
......@@ -1676,25 +1654,12 @@ int LIB_PIN::ReturnPinDrawOrient( const TRANSFORM& aTransform ) const
}
/**
* Function ReturnPinStringNum
* fill a buffer with pin num as a wxString
* 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
*/
void LIB_PIN::ReturnPinStringNum( wxString& aStringBuffer ) const
{
aStringBuffer = ReturnPinStringNum( m_number );
}
/**
* 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
*/
wxString LIB_PIN::ReturnPinStringNum( long aPinNum )
{
char ascii_buf[5];
......@@ -1708,12 +1673,6 @@ wxString LIB_PIN::ReturnPinStringNum( long aPinNum )
}
/**
* Function SetPinNumFromString
* fill the buffer with pin num as a wxString
* Pin num is coded as a long
* Used to print/draw the pin num
*/
void LIB_PIN::SetPinNumFromString( wxString& buffer )
{
char ascii_buf[4];
......@@ -1889,51 +1848,43 @@ void LIB_PIN::DoSetWidth( int aWidth )
}
/**
* Function DisplayInfo
* Displays info (pin num and name, orientation ...
* on the Info window
*/
void LIB_PIN::DisplayInfo( EDA_DRAW_FRAME* frame )
void LIB_PIN::DisplayInfo( EDA_DRAW_FRAME* aFrame )
{
wxString Text;
LIB_ITEM::DisplayInfo( frame );
LIB_ITEM::DisplayInfo( aFrame );
frame->AppendMsgPanel( _( "Name" ), m_name, DARKCYAN );
aFrame->AppendMsgPanel( _( "Name" ), m_name, DARKCYAN );
if( m_number == 0 )
Text = wxT( "?" );
else
ReturnPinStringNum( Text );
frame->AppendMsgPanel( _( "Number" ), Text, DARKCYAN );
aFrame->AppendMsgPanel( _( "Number" ), Text, DARKCYAN );
frame->AppendMsgPanel( _( "Type" ),
aFrame->AppendMsgPanel( _( "Type" ),
wxGetTranslation( pin_electrical_type_names[ m_type ] ),
RED );
Text = wxGetTranslation( pin_style_names[ GetStyleCodeIndex( m_shape ) ] );
frame->AppendMsgPanel( _( "Style" ), Text, BLUE );
aFrame->AppendMsgPanel( _( "Style" ), Text, BLUE );
if( IsVisible() )
Text = _( "Yes" );
else
Text = _( "No" );
frame->AppendMsgPanel( _( "Visible" ), Text, DARKGREEN );
aFrame->AppendMsgPanel( _( "Visible" ), Text, DARKGREEN );
/* Display pin length */
Text = ReturnStringFromValue( g_UserUnit, m_length, EESCHEMA_INTERNAL_UNIT, true );
frame->AppendMsgPanel( _( "Length" ), Text, MAGENTA );
aFrame->AppendMsgPanel( _( "Length" ), Text, MAGENTA );
Text = wxGetTranslation( pin_orientation_names[ GetOrientationCodeIndex( m_orientation ) ] );
frame->AppendMsgPanel( _( "Orientation" ), Text, DARKMAGENTA );
aFrame->AppendMsgPanel( _( "Orientation" ), Text, DARKMAGENTA );
}
/**
* Function GetBoundingBox
* @return the boundary box for this, in schematic coordinates
* Uses DefaultTransform as transform matrix
*/
EDA_RECT LIB_PIN::GetBoundingBox() const
{
LIB_COMPONENT* entry = (LIB_COMPONENT*) m_Parent;
......@@ -1993,7 +1944,7 @@ EDA_RECT LIB_PIN::GetBoundingBox() const
end.y = MIN( -minsizeV, -nameTextHeight / 2 );
}
else // if value == 0:
// pin name is ouside the body, and above the pin line
// pin name is outside the body, and above the pin line
// pin num is below the pin line
{
end.x = MAX(m_length, nameTextLength);
......@@ -2198,9 +2149,7 @@ void LIB_PIN::Show( int nestLevel, std::ostream& os )
<< " num=\"" << GetNumberString().mb_str()
<< '"' << "/>\n";
// NestedSpace( nestLevel, os ) << "</" << GetClass().Lower().mb_str() << ">\n";
}
#endif
/****************************************************************/
/* Headers for pins in lib component definitions */
/****************************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Definitions of class LIB_PIN used in component libraries.
/**
* @file class_libentry.h
* @brief Class LIB_PIN definition.
*/
#ifndef CLASS_PIN_H
#define CLASS_PIN_H
......@@ -10,9 +33,10 @@
#include "lib_draw_item.h"
class SCH_COMPONENT;
class LINE_READER;
#define TARGET_PIN_RADIUS 12 /* Circle diameter drawn at the active end of pins */
#define TARGET_PIN_RADIUS 12 /* Circle diameter drawn at the active end of pins */
#define DEFAULT_TEXT_SIZE 50 /* Default size for field texts */
#define PART_NAME_LEN 15 /* Maximum length of part name. */
......@@ -126,7 +150,6 @@ public:
void Show( int nestLevel, std::ostream& os ); // virtual override
#endif
/**
* Write pin object to a FILE in "*.lib" format.
*
......@@ -134,7 +157,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Function HitTest
......@@ -157,10 +181,25 @@ public:
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
/**
* Function DisplayInfo
* displays the pin information in the message panel attached to \a aFrame.
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
* Function GetBoundingBox
* @return the boundary box for the pin in schematic coordinates.
*
* Uses DefaultTransform as transform matrix
*/
virtual EDA_RECT GetBoundingBox() const;
/**
* Function ReturnPinEndPoint
*
* @return The pin end position for a component in the normal orientation.
*/
wxPoint ReturnPinEndPoint() const;
/**
......@@ -194,6 +233,10 @@ public:
*/
static wxString ReturnPinStringNum( long aPinNum );
/**
* Function SetPinNumFromString
* fill the pin number buffer with \a aBuffer.
*/
void SetPinNumFromString( wxString& aBuffer );
wxString GetName() const { return m_name; }
......@@ -332,7 +375,7 @@ public:
* Enable or clear pin editing mode.
*
* The pin editing mode marks or unmarks all pins common to this
* pin object for further editing. If any of the pin modifcation
* pin object for further editing. If any of the pin modification
* methods are called after enabling the editing mode, all pins
* marked for editing will have the same attribute changed. The
* only case were this is not true making this pin common to all
......@@ -353,17 +396,42 @@ public:
bool IsVisible() { return ( m_attributes & PIN_INVISIBLE ) == 0; }
/**
* @return the size of the "pen" that be used to draw or plot this item.
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize() const;
/**
* Function DrawPinSymbol
* Draw the pin symbol without text.
* If \a aColor != 0, draw with \a aColor, else with the normal pin color.
*/
void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
int aOrientation, int aDrawMode, int aColor = -1 );
/**
* Function DrawPinTexts
* puts the pin number and pin text info, given the pin line coordinates.
* The line must be vertical or horizontal. If PinText == NULL nothing is printed.
* If PinNum = 0 no number is printed. The current zoom factor is taken into account.
* If TextInside then the text is been put inside,otherwise all is drawn outside.
* Pin Name: substring between '~' is negated
* DrawMode = GR_OR, XOR ...
*/
void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
int aColor, int aDrawMode );
/**
* Function PlotPinTexts
* plots the pin number and pin text info, given the pin line coordinates.
* Same as DrawPinTexts((), but output is the plotter
* The line must be vertical or horizontal.
* If PinNext == NULL nothing is printed.
* Current Zoom factor is taken into account.
* If TextInside then the text is been put inside (moving from x1, y1 in
* the opposite direction to x2,y2), otherwise all is drawn outside.
*/
void PlotPinTexts( PLOTTER *aPlotter,
wxPoint& aPosition,
int aOrientation,
......
/************************/
/** class LIB_POLYLINE **/
/************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_polyline.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
#include "macros.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -57,13 +82,14 @@ bool LIB_POLYLINE::Save( FILE* aFile )
}
bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
bool LIB_POLYLINE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* p;
int i, ccount = 0;
wxPoint pt;
char* line = (char*) aLineReader;
i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
i = sscanf( line + 2, "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
m_Fill = NO_FILL;
......@@ -72,13 +98,14 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
aErrorMsg.Printf( _( "polyline only had %d parameters of the required 4" ), i );
return false;
}
if( ccount <= 0 )
{
aErrorMsg.Printf( _( "polyline count parameter %d is invalid" ), ccount );
return false;
}
p = strtok( &aLine[2], " \t\n" );
p = strtok( line + 2, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
......@@ -87,17 +114,21 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
{
wxPoint point;
p = strtok( NULL, " \t\n" );
if( p == NULL || sscanf( p, "%d", &pt.x ) != 1 )
{
aErrorMsg.Printf( _( "polyline point %d X position not defined" ), i );
return false;
}
p = strtok( NULL, " \t\n" );
if( p == NULL || sscanf( p, "%d", &pt.y ) != 1 )
{
aErrorMsg.Printf( _( "polyline point %d Y position not defined" ), i );
return false;
}
AddPoint( pt );
}
......@@ -105,6 +136,7 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
{
if( p[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( p[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
}
......@@ -132,6 +164,7 @@ int LIB_POLYLINE::DoCompare( const LIB_ITEM& aOther ) const
{
if( m_PolyPoints[i].x != tmp->m_PolyPoints[i].x )
return m_PolyPoints[i].x - tmp->m_PolyPoints[i].x;
if( m_PolyPoints[i].y != tmp->m_PolyPoints[i].y )
return m_PolyPoints[i].y - tmp->m_PolyPoints[i].y;
}
......@@ -236,10 +269,6 @@ void LIB_POLYLINE::AddPoint( const wxPoint& point )
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_POLYLINE::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
......@@ -263,7 +292,9 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
// Set the size of the buffer of coordinates
if( Buf_Poly_Drawings == NULL )
......@@ -291,6 +322,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
}
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -298,9 +330,9 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
Buf_Poly_Drawings, 1, GetPenSize(),
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
Buf_Poly_Drawings, 1, GetPenSize(),
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE )
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
Buf_Poly_Drawings, 1, GetPenSize(), color, color );
......@@ -326,6 +358,7 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aPosition )
// Have a minimal tolerance for hit test
if( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aPosition, mindist, DefaultTransform );
}
......@@ -350,10 +383,6 @@ bool LIB_POLYLINE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
}
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
EDA_RECT LIB_POLYLINE::GetBoundingBox() const
{
EDA_RECT rect;
......@@ -426,7 +455,7 @@ wxString LIB_POLYLINE::GetSelectMenuText() const
void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
{
wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0,
wxT( "Invalid edit mode for LIB_POLYLINE object." ) );
wxT( "Invalid edit mode for LIB_POLYLINE object." ) );
if( aEditMode == IS_NEW )
{
......@@ -451,7 +480,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
wxPoint prevPoint = startPoint;
// Find the right index of the point to be dragged
BOOST_FOREACH( wxPoint point, m_PolyPoints ) {
BOOST_FOREACH( wxPoint point, m_PolyPoints )
{
int distancePoint = (aPosition - point).x * (aPosition - point).x +
(aPosition - point).y * (aPosition - point).y;
......@@ -466,6 +496,7 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
// check middle of an edge
wxPoint offset = ( aPosition + aPosition - point - prevPoint );
distancePoint = ( offset.x * offset.x + offset.y * offset.y ) / 4 + 1;
if( distancePoint < distanceMin )
{
// Save point.
......@@ -473,8 +504,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
m_ModifyIndex = -index; // negative indicates new vertex is to be inserted
distanceMin = distancePoint;
}
prevPoint = point;
prevPoint = point;
index++;
}
......@@ -501,6 +532,7 @@ bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition )
// do not add zero length segments
if( m_PolyPoints[m_PolyPoints.size() - 2] != m_PolyPoints.back() )
m_PolyPoints.push_back( aPosition );
return true;
}
......@@ -511,7 +543,7 @@ bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition )
void LIB_POLYLINE::EndEdit( const wxPoint& aPosition, bool aAbort )
{
wxCHECK_RET( ( m_Flags & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0,
wxT( "Bad call to EndEdit(). LIB_POLYLINE is not being edited." ) );
wxT( "Bad call to EndEdit(). LIB_POLYLINE is not being edited." ) );
// do not include last point twice
if( m_Flags == IS_NEW && 2 < m_PolyPoints.size() )
......@@ -519,17 +551,18 @@ void LIB_POLYLINE::EndEdit( const wxPoint& aPosition, bool aAbort )
if( m_PolyPoints[ m_PolyPoints.size() - 2 ] == m_PolyPoints.back() )
m_PolyPoints.pop_back();
}
if( (m_Flags == IS_RESIZED) && (m_PolyPoints.size() > 2) ) // do not delete last two points... keep it alive
{
if( ( m_ModifyIndex > 0 && m_PolyPoints[ m_ModifyIndex ] ==
m_PolyPoints[ m_ModifyIndex - 1 ] )
||
( m_ModifyIndex < (int) m_PolyPoints.size() - 1
|| ( m_ModifyIndex < (int) m_PolyPoints.size() - 1
&& m_PolyPoints[ m_ModifyIndex ] == m_PolyPoints[ m_ModifyIndex + 1 ] ) )
{
m_PolyPoints.erase( m_PolyPoints.begin() + m_ModifyIndex ); // delete a point on this
}
}
m_Flags = 0;
SetEraseLastDrawItem( false );
}
......@@ -549,6 +582,7 @@ void LIB_POLYLINE::calcEdit( const wxPoint& aPosition )
m_ModifyIndex = -m_ModifyIndex;
m_PolyPoints.insert( m_PolyPoints.begin() + m_ModifyIndex, aPosition );
}
m_PolyPoints[ m_ModifyIndex ] = aPosition;
}
else if( m_Flags == IS_MOVED )
......
/**********************************************************/
/* Graphic Body Item: Polygon and polyline (set of lines) */
/**********************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_polyline.h
*/
#ifndef _LIB_POLYLINE_H_
#define _LIB_POLYLINE_H_
#include "lib_draw_item.h"
class LINE_READER;
class LIB_POLYLINE : public LIB_ITEM
{
......@@ -29,7 +55,6 @@ class LIB_POLYLINE : public LIB_ITEM
*/
void calcEdit( const wxPoint& aPosition );
public:
public:
LIB_POLYLINE( LIB_COMPONENT * aParent );
LIB_POLYLINE( const LIB_POLYLINE& aPolyline );
......@@ -48,7 +73,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
......@@ -79,11 +105,13 @@ public:
virtual bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
virtual EDA_RECT GetBoundingBox() const;
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/*************************/
/** class LIB_RECTANGLE **/
/*************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_rectangle.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -9,6 +34,7 @@
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -49,12 +75,13 @@ bool LIB_RECTANGLE::Save( FILE* aFile )
}
bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg )
bool LIB_RECTANGLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int cnt;
char tmp[256];
char* line = (char*)aLineReader;
cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
&m_End.x, &m_End.y, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 7 )
......@@ -65,6 +92,7 @@ bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
......@@ -131,6 +159,7 @@ void LIB_RECTANGLE::DoMirrorHorizontal( const wxPoint& aCenter )
m_End.x += aCenter.x;
}
void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter )
{
m_Pos.y -= aCenter.y;
......@@ -141,6 +170,7 @@ void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter )
m_End.y += aCenter.y;
}
void LIB_RECTANGLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
{
int rot_angle = aRotateCCW ? -900 : 900;
......@@ -169,15 +199,12 @@ void LIB_RECTANGLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFil
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_RECTANGLE::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
}
void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aOffset, int aColor, int aDrawMode,
void* aData, const TRANSFORM& aTransform )
......@@ -192,12 +219,15 @@ void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
pos2 = aTransform.TransformCoordinate( m_End ) + aOffset;
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -273,18 +303,21 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
start = actualStart;
end.x = actualEnd.x;
end.y = actualStart.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
// locate right segment
start.x = actualEnd.x;
end.y = actualEnd.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
// locate upper segment
start.y = actualEnd.y;
end.x = actualStart.x;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
......@@ -292,6 +325,7 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
start = actualStart;
end.x = actualStart.x;
end.y = actualEnd.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
......
/********************************/
/* Graphic Body Item: Rectangle */
/********************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_rectangle.h
*/
#ifndef _LIB_RECTANGLE_H_
#define _LIB_RECTANGLE_H_
#include "lib_draw_item.h"
class LINE_READER;
class LIB_RECTANGLE : public LIB_ITEM
{
wxPoint m_End; // Rectangle end point.
......@@ -36,6 +63,7 @@ public:
LIB_RECTANGLE( LIB_COMPONENT * aParent );
LIB_RECTANGLE( const LIB_RECTANGLE& aRect );
~LIB_RECTANGLE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_RECTANGLE" );
......@@ -50,7 +78,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
......@@ -70,6 +99,7 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/***************************/
/* lib_text.cpp */
/***************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* class LIB_TEXT : describes a graphic text used to draw component shapes
* This is only a graphic item
*/
* @file lib_text.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -15,6 +35,7 @@
#include "drawtxt.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "lib_draw_item.h"
#include "general.h"
......@@ -54,17 +75,20 @@ bool LIB_TEXT::Save( FILE* ExportFile )
if( fprintf( ExportFile, "T %d %d %d %d %d %d %d %s ", m_Orient, m_Pos.x, m_Pos.y,
m_Size.x, m_Attributs, m_Unit, m_Convert, TO_UTF8( text ) ) < 0 )
return false;
if( fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal",
( m_Bold > 0 ) ? 1 : 0 ) < 0 )
return false;
char hjustify = 'C';
if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
hjustify = 'L';
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
hjustify = 'R';
char vjustify = 'C';
if( m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM )
vjustify = 'B';
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
......@@ -77,34 +101,35 @@ bool LIB_TEXT::Save( FILE* ExportFile )
}
bool LIB_TEXT::Load( char* line, wxString& errorMsg )
bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg )
{
int cnt, thickness;
char hjustify = 'C', vjustify = 'C';
char buf[256];
char tmp[256];
char* line = (char*) aLineReader;
buf[0] = 0;
tmp[0] = 0; // For italic option, Not in old versions
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d \"%[^\"]\" %s %d %c %c",
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d \"%[^\"]\" %s %d %c %c",
&m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify );
if( cnt >= 8 ) // if quoted loadng failed, load as not quoted
if( cnt >= 8 ) // if quoted loading failed, load as not quoted
{
m_Text = FROM_UTF8( buf );
// convert two apostrophes back to double quote
m_Text.Replace( wxT( "''" ), wxT( "\"" ) );
}
else
{
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %s %s %d %c %c",
&m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify );
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %s %s %d %c %c",
&m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify );
if( cnt < 8 )
{
......@@ -116,10 +141,12 @@ bool LIB_TEXT::Load( char* line, wxString& errorMsg )
m_Text = FROM_UTF8( buf );
m_Text.Replace( wxT( "~" ), wxT( " " ) );
}
m_Size.y = m_Size.x;
if( strnicmp( tmp, "Italic", 6 ) == 0 )
m_Italic = true;
if( thickness > 0 )
{
m_Bold = true;
......@@ -247,7 +274,7 @@ bool LIB_TEXT::DoTestInside( EDA_RECT& rect ) const
{
/*
* FIXME: This should calculate the text size and justification and
* use rectangle instect.
* use rectangle intersect.
*/
return rect.Contains( m_Pos.x, -m_Pos.y );
}
......@@ -299,11 +326,7 @@ void LIB_TEXT::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_TEXT::GetPenSize( ) const
int LIB_TEXT::GetPenSize() const
{
int pensize = m_Thickness;
......@@ -314,6 +337,7 @@ int LIB_TEXT::GetPenSize( ) const
else
pensize = g_DrawDefaultLineThickness;
}
// Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
return pensize;
......@@ -333,7 +357,9 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
......@@ -343,6 +369,7 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
* orientation/mirror (needed when draw text in schematic)
*/
int orient = m_Orient;
if( aTransform.y1 ) // Rotate component 90 degrees.
{
if( orient == TEXT_ORIENT_HORIZ )
......@@ -404,9 +431,6 @@ void LIB_TEXT::DisplayInfo( EDA_DRAW_FRAME* frame )
}
/**
* @return the boundary box for this, in schematic coordinates
*/
EDA_RECT LIB_TEXT::GetBoundingBox() const
{
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_text.h
*/
#ifndef _LIB_TEXT_H_
#define _LIB_TEXT_H_
#include "lib_draw_item.h"
class LINE_READER;
/*********************************************/
/* Graphic Body Item: Text */
/* This is only a graphic text. */
......@@ -25,7 +55,7 @@ class LIB_TEXT : public LIB_ITEM, public EDA_TEXT
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
/**
* Calculate the text attributes ralative to \a aPosition while editing.
* Calculate the text attributes relative to \a aPosition while editing.
*
* @param aPosition - Edit position in drawing units.
*/
......@@ -44,7 +74,7 @@ public:
/**
* Sets the text item string to \a aText.
*
* This method does more than juat set the set the text string. There are special
* This method does more than just set the set the text string. There are special
* cases when changing the text string alone is not enough. If the text item is
* being moved, the name change must be delayed until the next redraw to prevent
* drawing artifacts.
......@@ -60,7 +90,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
......@@ -92,12 +123,16 @@ public:
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
* @return the boundary box for this, in schematic coordinates
*/
virtual EDA_RECT GetBoundingBox() const;
void Rotate();
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
......@@ -94,7 +94,8 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
PrintMsg( MsgDiag );
if( !reader.ReadLine()
|| strncmp( (char*)reader + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 )
|| strncmp( (char*)reader + 9, SCHEMATIC_HEAD_STRING,
sizeof( SCHEMATIC_HEAD_STRING ) - 1 ) != 0 )
{
MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" );
DisplayError( this, MsgDiag );
......@@ -104,13 +105,13 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
line = reader.Line();
// get the file version here.
char *strversion = line + 9 + sizeof(SCHEMATIC_HEAD_STRING);
char *strversion = line + 9 + sizeof( SCHEMATIC_HEAD_STRING );
// Skip blanks
while( *strversion && *strversion < '0' )
strversion++;
int version = atoi(strversion);
int version = atoi( strversion );
if( version > EESCHEMA_VERSION )
{
......@@ -147,6 +148,7 @@ again." );
item = NULL;
char* sline = line;
while( (*sline != ' ' ) && *sline )
sline++;
......@@ -274,6 +276,7 @@ static void LoadLayers( LINE_READER* aLine )
aLine->ReadLine();
sscanf( *aLine, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
if( strcmp( Name, "EELAYER" ) !=0 )
{
/* error : init par default */
......@@ -282,6 +285,7 @@ static void LoadLayers( LINE_READER* aLine )
if( Number <= 0 )
Number = MAX_LAYER;
if( Number > MAX_LAYER )
Number = MAX_LAYER;
......
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