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

Use line reader to load component library files and objects.

parent d5ea4750
This diff is collapsed.
/******************************************/ /*
/* 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 #ifndef CLASS_LIBENTRY_H
#define CLASS_LIBENTRY_H #define CLASS_LIBENTRY_H
...@@ -12,6 +37,7 @@ ...@@ -12,6 +37,7 @@
#include <map> #include <map>
class LINE_READER;
class CMP_LIBRARY; class CMP_LIBRARY;
class LIB_ALIAS; class LIB_ALIAS;
class LIB_COMPONENT; class LIB_COMPONENT;
...@@ -45,8 +71,11 @@ enum LibrEntryOptions ...@@ -45,8 +71,11 @@ enum LibrEntryOptions
/** /**
* Component library alias object definition. * Component library alias object definition.
* *
* Component aliases are not really components. They are references * Component aliases are not really components. An alias uses the component definition
* to an actual component object. * (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 class LIB_ALIAS : public EDA_ITEM
{ {
...@@ -144,7 +173,8 @@ extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2 ...@@ -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). * A library component object is typically saved and loaded in a component library file (.lib).
* Library components are different from schematic components. * Library components are different from schematic components.
...@@ -207,7 +237,7 @@ public: ...@@ -207,7 +237,7 @@ public:
* Add an alias \a aName to the component. * Add an alias \a aName to the component.
* *
* Duplicate alias names are not added to the alias list. Debug builds will raise an * 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. * @param aName - Name of alias to add.
*/ */
...@@ -255,7 +285,16 @@ public: ...@@ -255,7 +285,16 @@ public:
**/ **/
EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const; 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 SaveDateAndTime( FILE* aFile );
bool LoadDateAndTime( char* aLine ); bool LoadDateAndTime( char* aLine );
/** /**
...@@ -267,19 +306,17 @@ public: ...@@ -267,19 +306,17 @@ public:
bool Save( FILE* aFile ); 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 aReader A LINE_READER object to load file from.
* @param aLine - The first line of the component definition.
* @param aLineNum - The current line number in the file.
* @param aErrorMsg - Description of error on load failure. * @param aErrorMsg - Description of error on load failure.
* @return True if the load was successful, false if there was an error. * @return True if the load was successful, false if there was an error.
*/ */
bool Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg ); bool Load( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadField( char* aLine, wxString& aErrorMsg ); bool LoadField( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadDrawEntries( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg ); bool LoadDrawEntries( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadAliases( char* aLine, 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 IsPower() { return m_options == ENTRY_POWER; }
bool IsNormal() { return m_options == ENTRY_NORMAL; } 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 * @file class_library.cpp
*/ */
...@@ -10,6 +35,7 @@ ...@@ -10,6 +35,7 @@
#include "gestfich.h" #include "gestfich.h"
#include "eda_doc.h" #include "eda_doc.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "richio.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
...@@ -129,6 +155,7 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames, ...@@ -129,6 +155,7 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames,
{ {
if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) ) if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) )
aNames.Add( (*it).first ); aNames.Add( (*it).first );
if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch, if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch,
(*it).second->GetName(), false ) ) (*it).second->GetName(), false ) )
aNames.Add( (*it).first ); aNames.Add( (*it).first );
...@@ -186,10 +213,6 @@ LIB_ALIAS* CMP_LIBRARY::FindEntry( const wxChar* aName ) ...@@ -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() LIB_ALIAS* CMP_LIBRARY::GetFirstEntry()
{ {
if( aliases.size() ) if( aliases.size() )
...@@ -198,6 +221,7 @@ LIB_ALIAS* CMP_LIBRARY::GetFirstEntry() ...@@ -198,6 +221,7 @@ LIB_ALIAS* CMP_LIBRARY::GetFirstEntry()
return NULL; return NULL;
} }
LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* aName ) LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* aName )
{ {
LIB_COMPONENT* component = NULL; LIB_COMPONENT* component = NULL;
...@@ -279,7 +303,7 @@ LIB_ALIAS* CMP_LIBRARY::RemoveEntry( LIB_ALIAS* aEntry ) ...@@ -279,7 +303,7 @@ LIB_ALIAS* CMP_LIBRARY::RemoveEntry( LIB_ALIAS* aEntry )
return NULL; return NULL;
// If the entry pointer doesn't match the name it is mapped to in the library, we // 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, wxCHECK_MSG( (*it).second == aEntry, NULL,
wxT( "Pointer mismatch while attempting to remove entry <" ) + wxT( "Pointer mismatch while attempting to remove entry <" ) +
aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) ); aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) );
...@@ -380,8 +404,7 @@ LIB_ALIAS* CMP_LIBRARY::GetPreviousEntry( const wxChar* aName ) ...@@ -380,8 +404,7 @@ LIB_ALIAS* CMP_LIBRARY::GetPreviousEntry( const wxChar* aName )
bool CMP_LIBRARY::Load( wxString& aErrorMsg ) bool CMP_LIBRARY::Load( wxString& aErrorMsg )
{ {
FILE* file; FILE* file;
int lineNumber = 0; char* line;
char line[LINE_BUFFER_LEN_LARGE]; // Use a very large buffer to load data
LIB_COMPONENT* libEntry; LIB_COMPONENT* libEntry;
wxString msg; wxString msg;
...@@ -399,10 +422,11 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg ) ...@@ -399,10 +422,11 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
return false; 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!" ); aErrorMsg = _( "The file is empty!" );
fclose( file );
return false; return false;
} }
...@@ -411,6 +435,8 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg ) ...@@ -411,6 +435,8 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
{ {
wxString tmp; wxString tmp;
line = reader.Line();
header = FROM_UTF8( line ); header = FROM_UTF8( line );
wxStringTokenizer tkn( header ); wxStringTokenizer tkn( header );
...@@ -426,21 +452,18 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg ) ...@@ -426,21 +452,18 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
|| !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) ) || !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) )
{ {
aErrorMsg = _( "The file is NOT an Eeschema library!" ); aErrorMsg = _( "The file is NOT an Eeschema library!" );
fclose( file );
return false; return false;
} }
if( !tkn.HasMoreTokens() ) if( !tkn.HasMoreTokens() )
{ {
aErrorMsg = _( "The file header is missing version and time stamp information." ); aErrorMsg = _( "The file header is missing version and time stamp information." );
fclose( file );
return false; return false;
} }
if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() ) if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() )
{ {
aErrorMsg = wxT( "The file header version information is invalid." ); aErrorMsg = wxT( "The file header version information is invalid." );
fclose( file );
return false; return false;
} }
...@@ -466,19 +489,18 @@ the current schematic." ), ...@@ -466,19 +489,18 @@ the current schematic." ),
{ {
versionMajor = (int) major; versionMajor = (int) major;
versionMinor = (int) minor; 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( 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." ); aErrorMsg = _( "An error occurred attempting to read the header." );
fclose( file );
return false; return false;
} }
...@@ -490,7 +512,7 @@ the current schematic." ), ...@@ -490,7 +512,7 @@ the current schematic." ),
/* Read one DEF/ENDDEF part entry from library: */ /* Read one DEF/ENDDEF part entry from library: */
libEntry = new LIB_COMPONENT( wxEmptyString, this ); 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 /* Check for duplicate entry names and warn the user about
* the potential conflict. * the potential conflict.
...@@ -516,8 +538,6 @@ the current schematic." ), ...@@ -516,8 +538,6 @@ the current schematic." ),
} }
} }
fclose( file );
return true; return true;
} }
...@@ -542,13 +562,15 @@ void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component ) ...@@ -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" ); data = strtok( NULL, " \t\r\n" );
if( stricmp( text, "TimeStamp" ) == 0 ) if( stricmp( text, "TimeStamp" ) == 0 )
...@@ -558,7 +580,7 @@ bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum ) ...@@ -558,7 +580,7 @@ bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum )
return true; return true;
} }
return FALSE; return false;
} }
...@@ -618,6 +640,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg ) ...@@ -618,6 +640,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg )
{ {
if( strncmp( line, "$ENDCMP", 7 ) == 0 ) if( strncmp( line, "$ENDCMP", 7 ) == 0 )
break; break;
text = strtok( line + 2, "\n\r" ); text = strtok( line + 2, "\n\r" );
if( entry ) if( entry )
...@@ -680,6 +703,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat ) ...@@ -680,6 +703,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
isModified = false; isModified = false;
timeStamp = GetTimeStamp(); timeStamp = GetTimeStamp();
if( !SaveHeader( libfile ) ) if( !SaveHeader( libfile ) )
{ {
fclose( libfile ); fclose( libfile );
...@@ -745,6 +769,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName ) ...@@ -745,6 +769,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
} }
char line[256]; char line[256];
if( fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT, DateAndTime( line ) ) < 0 ) if( fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT, DateAndTime( line ) ) < 0 )
{ {
fclose( docfile ); fclose( docfile );
...@@ -774,6 +799,7 @@ bool CMP_LIBRARY::SaveHeader( FILE* aFile ) ...@@ -774,6 +799,7 @@ bool CMP_LIBRARY::SaveHeader( FILE* aFile )
bool succes = true; bool succes = true;
DateAndTime( BufLine ); DateAndTime( BufLine );
if( fprintf( aFile, "%s %d.%d Date: %s\n", LIBFILE_IDENT, if( fprintf( aFile, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 ) LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
succes = false; succes = false;
...@@ -884,11 +910,6 @@ void CMP_LIBRARY::RemoveLibrary( const wxString& aName ) ...@@ -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 ) bool CMP_LIBRARY::LibraryExists( const CMP_LIBRARY* aLibptr )
{ {
BOOST_FOREACH( CMP_LIBRARY& lib, libraryList ) BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
......
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
#ifndef CLASS_LIBRARY_H #ifndef CLASS_LIBRARY_H
#define CLASS_LIBRARY_H #define CLASS_LIBRARY_H
#include <wx/filename.h> #include <wx/filename.h>
#include "class_libentry.h" #include "class_libentry.h"
class LINE_READER;
/* /*
* Component Library version and file header macros. * Component Library version and file header macros.
*/ */
...@@ -130,7 +132,7 @@ public: ...@@ -130,7 +132,7 @@ public:
private: private:
bool SaveHeader( FILE* aFile ); bool SaveHeader( FILE* aFile );
bool LoadHeader( FILE* aFile, int* aLineNum ); bool LoadHeader( LINE_READER& aLineReader );
void LoadAliases( LIB_COMPONENT* aComponent ); void LoadAliases( LIB_COMPONENT* aComponent );
public: 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 "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -9,6 +34,7 @@ ...@@ -9,6 +34,7 @@
#include "plot_common.h" #include "plot_common.h"
#include "trigo.h" #include "trigo.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "richio.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
...@@ -79,11 +105,6 @@ LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_ITEM( aArc ) ...@@ -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 ) bool LIB_ARC::Save( FILE* aFile )
{ {
int x1 = m_t1; int x1 = m_t1;
...@@ -106,12 +127,13 @@ bool LIB_ARC::Save( FILE* aFile ) ...@@ -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 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_Pos.x, &m_Pos.y, &m_Radius, &m_t1, &m_t2, &m_Unit,
&m_Convert, &m_Width, tmp, &startx, &starty, &endx, &endy ); &m_Convert, &m_Width, tmp, &startx, &starty, &endx, &endy );
if( cnt < 8 ) if( cnt < 8 )
...@@ -122,6 +144,7 @@ bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg ) ...@@ -122,6 +144,7 @@ bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' ) if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE; m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' ) if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR; m_Fill = FILLED_WITH_BG_BODYCOLOR;
...@@ -326,10 +349,6 @@ void LIB_ARC::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, ...@@ -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 int LIB_ARC::GetPenSize() const
{ {
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; 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 ...@@ -383,6 +402,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
int pt1 = m_t1; int pt1 = m_t1;
int pt2 = m_t2; int pt2 = m_t2;
bool swap = aTransform.MapAngles( &pt1, &pt2 ); bool swap = aTransform.MapAngles( &pt1, &pt2 );
if( swap ) if( swap )
{ {
EXCHG( pos1.x, pos2.x ); EXCHG( pos1.x, pos2.x );
...@@ -392,6 +412,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf ...@@ -392,6 +412,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
GRSetDrawMode( aDC, aDrawMode ); GRSetDrawMode( aDC, aDrawMode );
FILL_T fill = aData ? NO_FILL : m_Fill; FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 ) if( aColor >= 0 )
fill = NO_FILL; fill = NO_FILL;
...@@ -470,10 +491,13 @@ start(%d, %d), end(%d, %d), radius %d" ), ...@@ -470,10 +491,13 @@ start(%d, %d), end(%d, %d), radius %d" ),
if( angleStart <= 900 && angleEnd >= 900 ) /* 90 deg */ if( angleStart <= 900 && angleEnd >= 900 ) /* 90 deg */
maxY = centerPos.y + m_Radius; maxY = centerPos.y + m_Radius;
if( angleStart <= 1800 && angleEnd >= 1800 ) /* 180 deg */ if( angleStart <= 1800 && angleEnd >= 1800 ) /* 180 deg */
minX = centerPos.x - m_Radius; minX = centerPos.x - m_Radius;
if( angleStart <= 2700 && angleEnd >= 2700 ) /* 270 deg */ if( angleStart <= 2700 && angleEnd >= 2700 ) /* 270 deg */
minY = centerPos.y - m_Radius; minY = centerPos.y - m_Radius;
if( angleStart <= 3600 && angleEnd >= 3600 ) /* 0 deg */ if( angleStart <= 3600 && angleEnd >= 3600 ) /* 0 deg */
maxX = centerPos.x + m_Radius; maxX = centerPos.x + m_Radius;
...@@ -552,7 +576,9 @@ void LIB_ARC::BeginEdit( int aEditMode, const wxPoint aPosition ) ...@@ -552,7 +576,9 @@ void LIB_ARC::BeginEdit( int aEditMode, const wxPoint aPosition )
m_editSelectPoint = END; m_editSelectPoint = END;
} }
else else
{
m_editSelectPoint = OUTLINE; m_editSelectPoint = OUTLINE;
}
m_editState = 0; m_editState = 0;
SetEraseLastDrawItem(); 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_ #ifndef _LIB_ARC_H_
#define _LIB_ARC_H_ #define _LIB_ARC_H_
...@@ -10,6 +35,7 @@ ...@@ -10,6 +35,7 @@
class TRANSFORM; class TRANSFORM;
class LINE_READER;
class LIB_ARC : public LIB_ITEM class LIB_ARC : public LIB_ITEM
...@@ -77,7 +103,8 @@ public: ...@@ -77,7 +103,8 @@ public:
* @return - True if success writing else false. * @return - True if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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. * Tests if the given wxPoint is within the bounds of this object.
...@@ -100,6 +127,7 @@ public: ...@@ -100,6 +127,7 @@ public:
virtual void DisplayInfo( EDA_DRAW_FRAME* frame ); virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
/** /**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item * @return the size of the "pen" that be used to draw or plot this item
*/ */
virtual int GetPenSize( ) const; 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 "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -10,6 +35,7 @@ ...@@ -10,6 +35,7 @@
#include "trigo.h" #include "trigo.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "bezier_curves.h" #include "bezier_curves.h"
#include "richio.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
...@@ -56,26 +82,28 @@ bool LIB_BEZIER::Save( FILE* aFile ) ...@@ -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; char* p;
int i, ccount = 0; int i, ccount = 0;
wxPoint pt; 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 ) if( i !=4 )
{ {
aErrorMsg.Printf( _( "Bezier only had %d parameters of the required 4" ), i ); aErrorMsg.Printf( _( "Bezier only had %d parameters of the required 4" ), i );
return false; return false;
} }
if( ccount <= 0 ) if( ccount <= 0 )
{ {
aErrorMsg.Printf( _( "Bezier count parameter %d is invalid" ), ccount ); aErrorMsg.Printf( _( "Bezier count parameter %d is invalid" ), ccount );
return false; 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" ); 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 ) ...@@ -84,17 +112,21 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
{ {
wxPoint point; wxPoint point;
p = strtok( NULL, " \t\n" ); p = strtok( NULL, " \t\n" );
if( sscanf( p, "%d", &pt.x ) != 1 ) if( sscanf( p, "%d", &pt.x ) != 1 )
{ {
aErrorMsg.Printf( _( "Bezier point %d X position not defined" ), i ); aErrorMsg.Printf( _( "Bezier point %d X position not defined" ), i );
return false; return false;
} }
p = strtok( NULL, " \t\n" ); p = strtok( NULL, " \t\n" );
if( sscanf( p, "%d", &pt.y ) != 1 ) if( sscanf( p, "%d", &pt.y ) != 1 )
{ {
aErrorMsg.Printf( _( "Bezier point %d Y position not defined" ), i ); aErrorMsg.Printf( _( "Bezier point %d Y position not defined" ), i );
return false; return false;
} }
m_BezierPoints.push_back( pt ); m_BezierPoints.push_back( pt );
} }
...@@ -104,6 +136,7 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg ) ...@@ -104,6 +136,7 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
{ {
if( p[0] == 'F' ) if( p[0] == 'F' )
m_Fill = FILLED_SHAPE; m_Fill = FILLED_SHAPE;
if( p[0] == 'f' ) if( p[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR; m_Fill = FILLED_WITH_BG_BODYCOLOR;
} }
...@@ -131,6 +164,7 @@ int LIB_BEZIER::DoCompare( const LIB_ITEM& aOther ) const ...@@ -131,6 +164,7 @@ int LIB_BEZIER::DoCompare( const LIB_ITEM& aOther ) const
{ {
if( m_BezierPoints[i].x != tmp->m_BezierPoints[i].x ) if( m_BezierPoints[i].x != tmp->m_BezierPoints[i].x )
return 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 ) if( m_BezierPoints[i].y != tmp->m_BezierPoints[i].y )
return 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 ) ...@@ -181,6 +215,7 @@ void LIB_BEZIER::DoMirrorHorizontal( const wxPoint& aCenter )
} }
imax = m_BezierPoints.size(); imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ ) for( i = 0; i < imax; i++ )
{ {
m_BezierPoints[i].x -= aCenter.x; m_BezierPoints[i].x -= aCenter.x;
...@@ -201,6 +236,7 @@ void LIB_BEZIER::DoMirrorVertical( const wxPoint& aCenter ) ...@@ -201,6 +236,7 @@ void LIB_BEZIER::DoMirrorVertical( const wxPoint& aCenter )
} }
imax = m_BezierPoints.size(); imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ ) for( i = 0; i < imax; i++ )
{ {
m_BezierPoints[i].y -= aCenter.y; m_BezierPoints[i].y -= aCenter.y;
...@@ -214,12 +250,14 @@ void LIB_BEZIER::DoRotate( const wxPoint& aCenter, bool aRotateCCW ) ...@@ -214,12 +250,14 @@ void LIB_BEZIER::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
int rot_angle = aRotateCCW ? -900 : 900; int rot_angle = aRotateCCW ? -900 : 900;
size_t i, imax = m_PolyPoints.size(); size_t i, imax = m_PolyPoints.size();
for( i = 0; i < imax; i++ ) for( i = 0; i < imax; i++ )
{ {
RotatePoint( &m_PolyPoints[i], aCenter, rot_angle ); RotatePoint( &m_PolyPoints[i], aCenter, rot_angle );
} }
imax = m_BezierPoints.size(); imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ ) for( i = 0; i < imax; i++ )
{ {
RotatePoint( &m_BezierPoints[i], aCenter, rot_angle ); RotatePoint( &m_BezierPoints[i], aCenter, rot_angle );
...@@ -254,15 +292,12 @@ void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, ...@@ -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 int LIB_BEZIER::GetPenSize() const
{ {
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
} }
void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset, void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ) 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& ...@@ -288,9 +323,12 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
color = g_ItemSelectetColor; color = g_ItemSelectetColor;
} }
else else
{
color = aColor; color = aColor;
}
FILL_T fill = aData ? NO_FILL : m_Fill; FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 ) if( aColor >= 0 )
fill = NO_FILL; fill = NO_FILL;
...@@ -319,28 +357,18 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& ...@@ -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 ) bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
{ {
int mindist = GetPenSize() / 2; int mindist = GetPenSize() / 2;
// Have a minimal tolerance for hit test // Have a minimal tolerance for hit test
if ( mindist < MINIMUM_SELECTION_DISTANCE ) if ( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE; mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aRefPos, mindist, DefaultTransform ); 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 ) bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform )
{ {
wxPoint ref, start, end; wxPoint ref, start, end;
...@@ -361,10 +389,6 @@ bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra ...@@ -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 LIB_BEZIER::GetBoundingBox() const
{ {
EDA_RECT rect; 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_ #ifndef _LIB_BEZIER_H_
#define _LIB_BEZIER_H_ #define _LIB_BEZIER_H_
#include "lib_draw_item.h" #include "lib_draw_item.h"
class LINE_READER;
/**************************************************/ /**************************************************/
/* Graphic Body Item: Bezier Curve (set of lines) */ /* Graphic Body Item: Bezier Curve (set of lines) */
/**************************************************/ /**************************************************/
...@@ -39,7 +69,8 @@ public: ...@@ -39,7 +69,8 @@ public:
* @return true if success writing else false. * @return true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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 ); void AddPoint( const wxPoint& aPoint );
...@@ -65,11 +96,13 @@ public: ...@@ -65,11 +96,13 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/** /**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates * @return the boundary box for this, in library coordinates
*/ */
virtual EDA_RECT GetBoundingBox() const; virtual EDA_RECT GetBoundingBox() const;
/** /**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item * @return the size of the "pen" that be used to draw or plot this item
*/ */
virtual int GetPenSize( ) const; 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 * @file lib_circle.cpp
* @brief LIB_CIRCLE class definition * @brief LIB_CIRCLE class implementation.
*/ */
#include "fctsys.h" #include "fctsys.h"
...@@ -10,6 +35,7 @@ ...@@ -10,6 +35,7 @@
#include "plot_common.h" #include "plot_common.h"
#include "trigo.h" #include "trigo.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "richio.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
...@@ -48,11 +74,12 @@ bool LIB_CIRCLE::Save( FILE* aFile ) ...@@ -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 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 ); &m_Radius, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 6 ) if( cnt < 6 )
...@@ -63,6 +90,7 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg ) ...@@ -63,6 +90,7 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' ) if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE; m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' ) if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR; m_Fill = FILLED_WITH_BG_BODYCOLOR;
...@@ -70,12 +98,6 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg ) ...@@ -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 ) bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
{ {
int mindist = GetPenSize() / 2; int mindist = GetPenSize() / 2;
...@@ -88,13 +110,6 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef ) ...@@ -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 ) bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform )
{ {
if( aThreshold < 0 ) if( aThreshold < 0 )
...@@ -165,6 +180,7 @@ void LIB_CIRCLE::DoMirrorHorizontal( const wxPoint& aCenter ) ...@@ -165,6 +180,7 @@ void LIB_CIRCLE::DoMirrorHorizontal( const wxPoint& aCenter )
m_Pos.x += aCenter.x; m_Pos.x += aCenter.x;
} }
void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter ) void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter )
{ {
m_Pos.y -= aCenter.y; m_Pos.y -= aCenter.y;
...@@ -172,6 +188,7 @@ void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter ) ...@@ -172,6 +188,7 @@ void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter )
m_Pos.y += aCenter.y; m_Pos.y += aCenter.y;
} }
void LIB_CIRCLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW ) void LIB_CIRCLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
{ {
int rot_angle = aRotateCCW ? -900 : 900; int rot_angle = aRotateCCW ? -900 : 900;
...@@ -197,10 +214,6 @@ void LIB_CIRCLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill, ...@@ -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 int LIB_CIRCLE::GetPenSize() const
{ {
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
...@@ -220,7 +233,9 @@ void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& ...@@ -220,7 +233,9 @@ void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
color = g_ItemSelectetColor; color = g_ItemSelectetColor;
} }
else else
{
color = aColor; color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
GRSetDrawMode( aDC, aDrawMode ); 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_ #ifndef _LIB_CIRCLE_H_
#define _LIB_CIRCLE_H_ #define _LIB_CIRCLE_H_
#include "lib_draw_item.h" #include "lib_draw_item.h"
class LINE_READER;
class LIB_CIRCLE : public LIB_ITEM class LIB_CIRCLE : public LIB_ITEM
{ {
int m_Radius; int m_Radius;
...@@ -32,6 +59,7 @@ public: ...@@ -32,6 +59,7 @@ public:
LIB_CIRCLE( LIB_COMPONENT * aParent ); LIB_CIRCLE( LIB_COMPONENT * aParent );
LIB_CIRCLE( const LIB_CIRCLE& aCircle ); LIB_CIRCLE( const LIB_CIRCLE& aCircle );
~LIB_CIRCLE() { } ~LIB_CIRCLE() { }
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
return wxT( "LIB_CIRCLE" ); return wxT( "LIB_CIRCLE" );
...@@ -45,7 +73,8 @@ public: ...@@ -45,7 +73,8 @@ public:
* @return - true if success writing else false. * @return - true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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. * Test if the given point is within the bounds of this object.
...@@ -65,11 +94,13 @@ public: ...@@ -65,11 +94,13 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); 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 * @return the size of the "pen" that be used to draw or plot this item
*/ */
virtual int GetPenSize( ) const; virtual int GetPenSize( ) const;
virtual EDA_RECT GetBoundingBox() const; virtual EDA_RECT GetBoundingBox() const;
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); 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 "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -16,7 +41,6 @@ const int fill_tab[3] = { 'N', 'F', 'f' }; ...@@ -16,7 +41,6 @@ const int fill_tab[3] = { 'N', 'F', 'f' };
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs //#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
/* Base class (abstract) for components bodies items */
LIB_ITEM::LIB_ITEM( KICAD_T aType, LIB_ITEM::LIB_ITEM( KICAD_T aType,
LIB_COMPONENT* aComponent, LIB_COMPONENT* aComponent,
int aUnit, int aUnit,
...@@ -46,13 +70,6 @@ LIB_ITEM::LIB_ITEM( const LIB_ITEM& aItem ) : ...@@ -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 ) void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame )
{ {
wxString msg; 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_ #ifndef _LIB_ITEM_H_
#define _LIB_ITEM_H_ #define _LIB_ITEM_H_
...@@ -13,6 +37,7 @@ ...@@ -13,6 +37,7 @@
#include <boost/ptr_container/ptr_vector.hpp> #include <boost/ptr_container/ptr_vector.hpp>
class LINE_READER;
class LIB_COMPONENT; class LIB_COMPONENT;
class PLOTTER; class PLOTTER;
class LIB_ITEM; class LIB_ITEM;
...@@ -35,7 +60,7 @@ typedef boost::ptr_vector< LIB_ITEM > LIB_ITEMS; ...@@ -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 * 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. * deleted when the container is deleted.
*/ */
typedef std::vector< LIB_PIN* > LIB_PINS; typedef std::vector< LIB_PIN* > LIB_PINS;
...@@ -194,7 +219,7 @@ public: ...@@ -194,7 +219,7 @@ public:
* @return - true if success writing else false. * @return - true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ) = 0; 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() LIB_COMPONENT* GetParent()
{ {
...@@ -232,9 +257,15 @@ public: ...@@ -232,9 +257,15 @@ public:
virtual EDA_RECT GetBoundingBox() const { return EDA_ITEM::GetBoundingBox(); } virtual EDA_RECT GetBoundingBox() const { return EDA_ITEM::GetBoundingBox(); }
/** /**
* Displays basic info (type, part and convert) about item * Function DisplayInfo
* in msg panel * displays basic info (type, part and convert) about the current item
* @param aFrame = main frame where the message manel info is. * 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 ); 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 "fctsys.h"
#include "appl_wxstruct.h" #include "appl_wxstruct.h"
...@@ -21,24 +46,6 @@ ...@@ -21,24 +46,6 @@
#include "template_fieldnames.h" #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_FIELD::LIB_FIELD(LIB_COMPONENT * aParent, int idfield ) :
LIB_ITEM( LIB_FIELD_T, aParent ) LIB_ITEM( LIB_FIELD_T, aParent )
{ {
...@@ -143,13 +150,14 @@ bool LIB_FIELD::Save( FILE* ExportFile ) ...@@ -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; int cnt;
char textOrient; char textOrient;
char textVisible; char textVisible;
char textHJustify; char textHJustify;
char textVJustify[256]; char textVJustify[256];
char* line = (char*) aLineReader;
if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 ) if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
{ {
...@@ -267,20 +275,12 @@ bool LIB_FIELD::Load( char* line, wxString& errorMsg ) ...@@ -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 int LIB_FIELD::GetPenSize() const
{ {
return ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness; 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, void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ) int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform )
{ {
...@@ -458,7 +458,7 @@ void LIB_FIELD::DoOffset( const wxPoint& offset ) ...@@ -458,7 +458,7 @@ void LIB_FIELD::DoOffset( const wxPoint& offset )
bool LIB_FIELD::DoTestInside( EDA_RECT& rect ) const 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. * the text.
*/ */
return rect.Contains( m_Pos.x, -m_Pos.y ); return rect.Contains( m_Pos.x, -m_Pos.y );
...@@ -499,12 +499,6 @@ void LIB_FIELD::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill, ...@@ -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 ) wxString LIB_FIELD::GetFullText( int unit )
{ {
if( m_id != REFERENCE ) 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 #ifndef CLASS_LIBENTRY_FIELDS_H
#define CLASS_LIBENTRY_FIELDS_H #define CLASS_LIBENTRY_FIELDS_H
...@@ -13,6 +38,20 @@ ...@@ -13,6 +38,20 @@
* is used in symbol libraries. At least MANDATORY_FIELDS are always present * is used in symbol libraries. At least MANDATORY_FIELDS are always present
* in a ram resident library symbol. All constructors must ensure this because * in a ram resident library symbol. All constructors must ensure this because
* the component property editor assumes it. * 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 * @see enum NumFieldType
*/ */
class LIB_FIELD : public LIB_ITEM, public EDA_TEXT class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
...@@ -26,6 +65,10 @@ 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. * 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, void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ); int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
...@@ -63,7 +106,7 @@ public: ...@@ -63,7 +106,7 @@ public:
* *
* @param aTranslate = true to return translated field name (default) * @param aTranslate = true to return translated field name (default)
* false to return the english name * 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. * @return Name of the field.
*/ */
wxString GetName(bool aTranslate = true) const; wxString GetName(bool aTranslate = true) const;
...@@ -98,7 +141,8 @@ public: ...@@ -98,7 +141,8 @@ public:
* @return True if success writing else false. * @return True if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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. * Copy parameters of this field to another field. Pointers are not copied.
...@@ -136,7 +180,7 @@ public: ...@@ -136,7 +180,7 @@ public:
/** /**
* Displays info (type, part convert filed name and value) * Displays info (type, part convert filed name and value)
* in msg panel * 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 ); virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
...@@ -182,6 +226,8 @@ public: ...@@ -182,6 +226,8 @@ public:
* create a pseudo reference text. If the base reference field is U, * create a pseudo reference text. If the base reference field is U,
* the string U?A will be returned for unit = 1. * 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. * @param unit - The package unit number. Only effects reference field.
* @return Field text. * @return Field text.
*/ */
...@@ -209,7 +255,7 @@ public: ...@@ -209,7 +255,7 @@ public:
/** /**
* Sets the field text to \a aText. * 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 * 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 * 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 * being moved, the name change must be delayed until the next redraw to prevent
......
This diff is collapsed.
/****************************************************************/ /*
/* 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 #ifndef CLASS_PIN_H
#define CLASS_PIN_H #define CLASS_PIN_H
...@@ -10,6 +33,7 @@ ...@@ -10,6 +33,7 @@
#include "lib_draw_item.h" #include "lib_draw_item.h"
class SCH_COMPONENT; 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 */
...@@ -126,7 +150,6 @@ public: ...@@ -126,7 +150,6 @@ public:
void Show( int nestLevel, std::ostream& os ); // virtual override void Show( int nestLevel, std::ostream& os ); // virtual override
#endif #endif
/** /**
* Write pin object to a FILE in "*.lib" format. * Write pin object to a FILE in "*.lib" format.
* *
...@@ -134,7 +157,8 @@ public: ...@@ -134,7 +157,8 @@ public:
* @return - true if success writing else false. * @return - true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/** /**
* Function HitTest * Function HitTest
...@@ -157,10 +181,25 @@ public: ...@@ -157,10 +181,25 @@ public:
*/ */
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); 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; virtual EDA_RECT GetBoundingBox() const;
/**
* Function ReturnPinEndPoint
*
* @return The pin end position for a component in the normal orientation.
*/
wxPoint ReturnPinEndPoint() const; wxPoint ReturnPinEndPoint() const;
/** /**
...@@ -194,6 +233,10 @@ public: ...@@ -194,6 +233,10 @@ public:
*/ */
static wxString ReturnPinStringNum( long aPinNum ); static wxString ReturnPinStringNum( long aPinNum );
/**
* Function SetPinNumFromString
* fill the pin number buffer with \a aBuffer.
*/
void SetPinNumFromString( wxString& aBuffer ); void SetPinNumFromString( wxString& aBuffer );
wxString GetName() const { return m_name; } wxString GetName() const { return m_name; }
...@@ -332,7 +375,7 @@ public: ...@@ -332,7 +375,7 @@ public:
* Enable or clear pin editing mode. * Enable or clear pin editing mode.
* *
* The pin editing mode marks or unmarks all pins common to this * 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 * methods are called after enabling the editing mode, all pins
* marked for editing will have the same attribute changed. The * marked for editing will have the same attribute changed. The
* only case were this is not true making this pin common to all * only case were this is not true making this pin common to all
...@@ -353,17 +396,42 @@ public: ...@@ -353,17 +396,42 @@ public:
bool IsVisible() { return ( m_attributes & PIN_INVISIBLE ) == 0; } 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; 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, void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
int aOrientation, int aDrawMode, int aColor = -1 ); 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, void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName, int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
int aColor, int aDrawMode ); 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, void PlotPinTexts( PLOTTER *aPlotter,
wxPoint& aPosition, wxPoint& aPosition,
int aOrientation, 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 "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
#include "macros.h" #include "macros.h"
#include "class_drawpanel.h" #include "class_drawpanel.h"
#include "plot_common.h" #include "plot_common.h"
#include "trigo.h" #include "trigo.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "richio.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
...@@ -57,13 +82,14 @@ bool LIB_POLYLINE::Save( FILE* aFile ) ...@@ -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; char* p;
int i, ccount = 0; int i, ccount = 0;
wxPoint pt; 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; m_Fill = NO_FILL;
...@@ -72,13 +98,14 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg ) ...@@ -72,13 +98,14 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
aErrorMsg.Printf( _( "polyline only had %d parameters of the required 4" ), i ); aErrorMsg.Printf( _( "polyline only had %d parameters of the required 4" ), i );
return false; return false;
} }
if( ccount <= 0 ) if( ccount <= 0 )
{ {
aErrorMsg.Printf( _( "polyline count parameter %d is invalid" ), ccount ); aErrorMsg.Printf( _( "polyline count parameter %d is invalid" ), ccount );
return false; 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" ); 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 ) ...@@ -87,17 +114,21 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
{ {
wxPoint point; wxPoint point;
p = strtok( NULL, " \t\n" ); p = strtok( NULL, " \t\n" );
if( p == NULL || sscanf( p, "%d", &pt.x ) != 1 ) if( p == NULL || sscanf( p, "%d", &pt.x ) != 1 )
{ {
aErrorMsg.Printf( _( "polyline point %d X position not defined" ), i ); aErrorMsg.Printf( _( "polyline point %d X position not defined" ), i );
return false; return false;
} }
p = strtok( NULL, " \t\n" ); p = strtok( NULL, " \t\n" );
if( p == NULL || sscanf( p, "%d", &pt.y ) != 1 ) if( p == NULL || sscanf( p, "%d", &pt.y ) != 1 )
{ {
aErrorMsg.Printf( _( "polyline point %d Y position not defined" ), i ); aErrorMsg.Printf( _( "polyline point %d Y position not defined" ), i );
return false; return false;
} }
AddPoint( pt ); AddPoint( pt );
} }
...@@ -105,6 +136,7 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg ) ...@@ -105,6 +136,7 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
{ {
if( p[0] == 'F' ) if( p[0] == 'F' )
m_Fill = FILLED_SHAPE; m_Fill = FILLED_SHAPE;
if( p[0] == 'f' ) if( p[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR; m_Fill = FILLED_WITH_BG_BODYCOLOR;
} }
...@@ -132,6 +164,7 @@ int LIB_POLYLINE::DoCompare( const LIB_ITEM& aOther ) const ...@@ -132,6 +164,7 @@ int LIB_POLYLINE::DoCompare( const LIB_ITEM& aOther ) const
{ {
if( m_PolyPoints[i].x != tmp->m_PolyPoints[i].x ) if( m_PolyPoints[i].x != tmp->m_PolyPoints[i].x )
return 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 ) if( m_PolyPoints[i].y != tmp->m_PolyPoints[i].y )
return 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 ) ...@@ -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 int LIB_POLYLINE::GetPenSize() const
{ {
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
...@@ -263,7 +292,9 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint ...@@ -263,7 +292,9 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
color = g_ItemSelectetColor; color = g_ItemSelectetColor;
} }
else else
{
color = aColor; color = aColor;
}
// Set the size of the buffer of coordinates // Set the size of the buffer of coordinates
if( Buf_Poly_Drawings == NULL ) if( Buf_Poly_Drawings == NULL )
...@@ -291,6 +322,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint ...@@ -291,6 +322,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
} }
FILL_T fill = aData ? NO_FILL : m_Fill; FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 ) if( aColor >= 0 )
fill = NO_FILL; fill = NO_FILL;
...@@ -326,6 +358,7 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aPosition ) ...@@ -326,6 +358,7 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aPosition )
// Have a minimal tolerance for hit test // Have a minimal tolerance for hit test
if( mindist < MINIMUM_SELECTION_DISTANCE ) if( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE; mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aPosition, mindist, DefaultTransform ); return HitTest( aPosition, mindist, DefaultTransform );
} }
...@@ -350,10 +383,6 @@ bool LIB_POLYLINE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& ...@@ -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 LIB_POLYLINE::GetBoundingBox() const
{ {
EDA_RECT rect; EDA_RECT rect;
...@@ -451,7 +480,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition ) ...@@ -451,7 +480,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
wxPoint prevPoint = startPoint; wxPoint prevPoint = startPoint;
// Find the right index of the point to be dragged // 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 + int distancePoint = (aPosition - point).x * (aPosition - point).x +
(aPosition - point).y * (aPosition - point).y; (aPosition - point).y * (aPosition - point).y;
...@@ -466,6 +496,7 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition ) ...@@ -466,6 +496,7 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
// check middle of an edge // check middle of an edge
wxPoint offset = ( aPosition + aPosition - point - prevPoint ); wxPoint offset = ( aPosition + aPosition - point - prevPoint );
distancePoint = ( offset.x * offset.x + offset.y * offset.y ) / 4 + 1; distancePoint = ( offset.x * offset.x + offset.y * offset.y ) / 4 + 1;
if( distancePoint < distanceMin ) if( distancePoint < distanceMin )
{ {
// Save point. // Save point.
...@@ -473,8 +504,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition ) ...@@ -473,8 +504,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
m_ModifyIndex = -index; // negative indicates new vertex is to be inserted m_ModifyIndex = -index; // negative indicates new vertex is to be inserted
distanceMin = distancePoint; distanceMin = distancePoint;
} }
prevPoint = point;
prevPoint = point;
index++; index++;
} }
...@@ -501,6 +532,7 @@ bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition ) ...@@ -501,6 +532,7 @@ bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition )
// do not add zero length segments // do not add zero length segments
if( m_PolyPoints[m_PolyPoints.size() - 2] != m_PolyPoints.back() ) if( m_PolyPoints[m_PolyPoints.size() - 2] != m_PolyPoints.back() )
m_PolyPoints.push_back( aPosition ); m_PolyPoints.push_back( aPosition );
return true; return true;
} }
...@@ -519,17 +551,18 @@ void LIB_POLYLINE::EndEdit( const wxPoint& aPosition, bool aAbort ) ...@@ -519,17 +551,18 @@ void LIB_POLYLINE::EndEdit( const wxPoint& aPosition, bool aAbort )
if( m_PolyPoints[ m_PolyPoints.size() - 2 ] == m_PolyPoints.back() ) if( m_PolyPoints[ m_PolyPoints.size() - 2 ] == m_PolyPoints.back() )
m_PolyPoints.pop_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_Flags == IS_RESIZED) && (m_PolyPoints.size() > 2) ) // do not delete last two points... keep it alive
{ {
if( ( m_ModifyIndex > 0 && m_PolyPoints[ m_ModifyIndex ] == if( ( m_ModifyIndex > 0 && m_PolyPoints[ m_ModifyIndex ] ==
m_PolyPoints[ m_ModifyIndex - 1 ] ) 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[ m_ModifyIndex ] == m_PolyPoints[ m_ModifyIndex + 1 ] ) )
{ {
m_PolyPoints.erase( m_PolyPoints.begin() + m_ModifyIndex ); // delete a point on this m_PolyPoints.erase( m_PolyPoints.begin() + m_ModifyIndex ); // delete a point on this
} }
} }
m_Flags = 0; m_Flags = 0;
SetEraseLastDrawItem( false ); SetEraseLastDrawItem( false );
} }
...@@ -549,6 +582,7 @@ void LIB_POLYLINE::calcEdit( const wxPoint& aPosition ) ...@@ -549,6 +582,7 @@ void LIB_POLYLINE::calcEdit( const wxPoint& aPosition )
m_ModifyIndex = -m_ModifyIndex; m_ModifyIndex = -m_ModifyIndex;
m_PolyPoints.insert( m_PolyPoints.begin() + m_ModifyIndex, aPosition ); m_PolyPoints.insert( m_PolyPoints.begin() + m_ModifyIndex, aPosition );
} }
m_PolyPoints[ m_ModifyIndex ] = aPosition; m_PolyPoints[ m_ModifyIndex ] = aPosition;
} }
else if( m_Flags == IS_MOVED ) 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_ #ifndef _LIB_POLYLINE_H_
#define _LIB_POLYLINE_H_ #define _LIB_POLYLINE_H_
#include "lib_draw_item.h" #include "lib_draw_item.h"
class LINE_READER;
class LIB_POLYLINE : public LIB_ITEM class LIB_POLYLINE : public LIB_ITEM
{ {
...@@ -29,7 +55,6 @@ class LIB_POLYLINE : public LIB_ITEM ...@@ -29,7 +55,6 @@ class LIB_POLYLINE : public LIB_ITEM
*/ */
void calcEdit( const wxPoint& aPosition ); void calcEdit( const wxPoint& aPosition );
public:
public: public:
LIB_POLYLINE( LIB_COMPONENT * aParent ); LIB_POLYLINE( LIB_COMPONENT * aParent );
LIB_POLYLINE( const LIB_POLYLINE& aPolyline ); LIB_POLYLINE( const LIB_POLYLINE& aPolyline );
...@@ -48,7 +73,8 @@ public: ...@@ -48,7 +73,8 @@ public:
* @return - true if success writing else false. * @return - true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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 ); void AddPoint( const wxPoint& aPoint );
...@@ -79,11 +105,13 @@ public: ...@@ -79,11 +105,13 @@ public:
virtual bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform ); virtual bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform );
/** /**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates * @return the boundary box for this, in library coordinates
*/ */
virtual EDA_RECT GetBoundingBox() const; virtual EDA_RECT GetBoundingBox() const;
/** /**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item * @return the size of the "pen" that be used to draw or plot this item
*/ */
virtual int GetPenSize( ) const; 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 "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -9,6 +34,7 @@ ...@@ -9,6 +34,7 @@
#include "plot_common.h" #include "plot_common.h"
#include "trigo.h" #include "trigo.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "richio.h"
#include "general.h" #include "general.h"
#include "protos.h" #include "protos.h"
...@@ -49,12 +75,13 @@ bool LIB_RECTANGLE::Save( FILE* aFile ) ...@@ -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; int cnt;
char tmp[256]; 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 ); &m_End.x, &m_End.y, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 7 ) if( cnt < 7 )
...@@ -65,6 +92,7 @@ bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg ) ...@@ -65,6 +92,7 @@ bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' ) if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE; m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' ) if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR; m_Fill = FILLED_WITH_BG_BODYCOLOR;
...@@ -131,6 +159,7 @@ void LIB_RECTANGLE::DoMirrorHorizontal( const wxPoint& aCenter ) ...@@ -131,6 +159,7 @@ void LIB_RECTANGLE::DoMirrorHorizontal( const wxPoint& aCenter )
m_End.x += aCenter.x; m_End.x += aCenter.x;
} }
void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter ) void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter )
{ {
m_Pos.y -= aCenter.y; m_Pos.y -= aCenter.y;
...@@ -141,6 +170,7 @@ void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter ) ...@@ -141,6 +170,7 @@ void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter )
m_End.y += aCenter.y; m_End.y += aCenter.y;
} }
void LIB_RECTANGLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW ) void LIB_RECTANGLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
{ {
int rot_angle = aRotateCCW ? -900 : 900; int rot_angle = aRotateCCW ? -900 : 900;
...@@ -169,15 +199,12 @@ void LIB_RECTANGLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFil ...@@ -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 int LIB_RECTANGLE::GetPenSize() const
{ {
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width; return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
} }
void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aOffset, int aColor, int aDrawMode, const wxPoint& aOffset, int aColor, int aDrawMode,
void* aData, const TRANSFORM& aTransform ) void* aData, const TRANSFORM& aTransform )
...@@ -192,12 +219,15 @@ void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, ...@@ -192,12 +219,15 @@ void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
color = g_ItemSelectetColor; color = g_ItemSelectetColor;
} }
else else
{
color = aColor; color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
pos2 = aTransform.TransformCoordinate( m_End ) + aOffset; pos2 = aTransform.TransformCoordinate( m_End ) + aOffset;
FILL_T fill = aData ? NO_FILL : m_Fill; FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 ) if( aColor >= 0 )
fill = NO_FILL; fill = NO_FILL;
...@@ -273,18 +303,21 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& ...@@ -273,18 +303,21 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
start = actualStart; start = actualStart;
end.x = actualEnd.x; end.x = actualEnd.x;
end.y = actualStart.y; end.y = actualStart.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) ) if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true; return true;
// locate right segment // locate right segment
start.x = actualEnd.x; start.x = actualEnd.x;
end.y = actualEnd.y; end.y = actualEnd.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) ) if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true; return true;
// locate upper segment // locate upper segment
start.y = actualEnd.y; start.y = actualEnd.y;
end.x = actualStart.x; end.x = actualStart.x;
if( TestSegmentHit( aPosition, start, end, aThreshold ) ) if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true; return true;
...@@ -292,6 +325,7 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& ...@@ -292,6 +325,7 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
start = actualStart; start = actualStart;
end.x = actualStart.x; end.x = actualStart.x;
end.y = actualEnd.y; end.y = actualEnd.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) ) if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true; 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_ #ifndef _LIB_RECTANGLE_H_
#define _LIB_RECTANGLE_H_ #define _LIB_RECTANGLE_H_
#include "lib_draw_item.h" #include "lib_draw_item.h"
class LINE_READER;
class LIB_RECTANGLE : public LIB_ITEM class LIB_RECTANGLE : public LIB_ITEM
{ {
wxPoint m_End; // Rectangle end point. wxPoint m_End; // Rectangle end point.
...@@ -36,6 +63,7 @@ public: ...@@ -36,6 +63,7 @@ public:
LIB_RECTANGLE( LIB_COMPONENT * aParent ); LIB_RECTANGLE( LIB_COMPONENT * aParent );
LIB_RECTANGLE( const LIB_RECTANGLE& aRect ); LIB_RECTANGLE( const LIB_RECTANGLE& aRect );
~LIB_RECTANGLE() { } ~LIB_RECTANGLE() { }
virtual wxString GetClass() const virtual wxString GetClass() const
{ {
return wxT( "LIB_RECTANGLE" ); return wxT( "LIB_RECTANGLE" );
...@@ -50,7 +78,8 @@ public: ...@@ -50,7 +78,8 @@ public:
* @return - true if success writing else false. * @return - true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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. * Test if the given point is within the bounds of this object.
...@@ -70,6 +99,7 @@ public: ...@@ -70,6 +99,7 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform ); 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 * @return the size of the "pen" that be used to draw or plot this item
*/ */
virtual int GetPenSize( ) const; 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 * @file lib_text.cpp
* This is only a graphic item */
*/
#include "fctsys.h" #include "fctsys.h"
#include "gr_basic.h" #include "gr_basic.h"
...@@ -15,6 +35,7 @@ ...@@ -15,6 +35,7 @@
#include "drawtxt.h" #include "drawtxt.h"
#include "trigo.h" #include "trigo.h"
#include "wxstruct.h" #include "wxstruct.h"
#include "richio.h"
#include "lib_draw_item.h" #include "lib_draw_item.h"
#include "general.h" #include "general.h"
...@@ -54,17 +75,20 @@ bool LIB_TEXT::Save( FILE* ExportFile ) ...@@ -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, 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 ) m_Size.x, m_Attributs, m_Unit, m_Convert, TO_UTF8( text ) ) < 0 )
return false; return false;
if( fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal", if( fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal",
( m_Bold > 0 ) ? 1 : 0 ) < 0 ) ( m_Bold > 0 ) ? 1 : 0 ) < 0 )
return false; return false;
char hjustify = 'C'; char hjustify = 'C';
if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT ) if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
hjustify = 'L'; hjustify = 'L';
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT ) else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
hjustify = 'R'; hjustify = 'R';
char vjustify = 'C'; char vjustify = 'C';
if( m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM ) if( m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM )
vjustify = 'B'; vjustify = 'B';
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP ) else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
...@@ -77,31 +101,32 @@ bool LIB_TEXT::Save( FILE* ExportFile ) ...@@ -77,31 +101,32 @@ 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; int cnt, thickness;
char hjustify = 'C', vjustify = 'C'; char hjustify = 'C', vjustify = 'C';
char buf[256]; char buf[256];
char tmp[256]; char tmp[256];
char* line = (char*) aLineReader;
buf[0] = 0; buf[0] = 0;
tmp[0] = 0; // For italic option, Not in old versions 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_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify, &m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify ); &vjustify );
if( cnt >= 8 ) // if quoted loading failed, load as not quoted
if( cnt >= 8 ) // if quoted loadng failed, load as not quoted
{ {
m_Text = FROM_UTF8( buf ); m_Text = FROM_UTF8( buf );
// convert two apostrophes back to double quote // convert two apostrophes back to double quote
m_Text.Replace( wxT( "''" ), wxT( "\"" ) ); m_Text.Replace( wxT( "''" ), wxT( "\"" ) );
} }
else else
{ {
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %s %s %d %c %c", 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_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify, &m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify ); &vjustify );
...@@ -116,10 +141,12 @@ bool LIB_TEXT::Load( char* line, wxString& errorMsg ) ...@@ -116,10 +141,12 @@ bool LIB_TEXT::Load( char* line, wxString& errorMsg )
m_Text = FROM_UTF8( buf ); m_Text = FROM_UTF8( buf );
m_Text.Replace( wxT( "~" ), wxT( " " ) ); m_Text.Replace( wxT( "~" ), wxT( " " ) );
} }
m_Size.y = m_Size.x; m_Size.y = m_Size.x;
if( strnicmp( tmp, "Italic", 6 ) == 0 ) if( strnicmp( tmp, "Italic", 6 ) == 0 )
m_Italic = true; m_Italic = true;
if( thickness > 0 ) if( thickness > 0 )
{ {
m_Bold = true; m_Bold = true;
...@@ -247,7 +274,7 @@ bool LIB_TEXT::DoTestInside( EDA_RECT& rect ) const ...@@ -247,7 +274,7 @@ bool LIB_TEXT::DoTestInside( EDA_RECT& rect ) const
{ {
/* /*
* FIXME: This should calculate the text size and justification and * 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 ); return rect.Contains( m_Pos.x, -m_Pos.y );
} }
...@@ -299,11 +326,7 @@ void LIB_TEXT::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill, ...@@ -299,11 +326,7 @@ void LIB_TEXT::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
} }
/** int LIB_TEXT::GetPenSize() const
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_TEXT::GetPenSize( ) const
{ {
int pensize = m_Thickness; int pensize = m_Thickness;
...@@ -314,6 +337,7 @@ int LIB_TEXT::GetPenSize( ) const ...@@ -314,6 +337,7 @@ int LIB_TEXT::GetPenSize( ) const
else else
pensize = g_DrawDefaultLineThickness; pensize = g_DrawDefaultLineThickness;
} }
// Clip pen size for small texts: // Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold ); pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
return pensize; return pensize;
...@@ -333,7 +357,9 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO ...@@ -333,7 +357,9 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
color = g_ItemSelectetColor; color = g_ItemSelectetColor;
} }
else else
{
color = aColor; color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset; pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
...@@ -343,6 +369,7 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO ...@@ -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) * orientation/mirror (needed when draw text in schematic)
*/ */
int orient = m_Orient; int orient = m_Orient;
if( aTransform.y1 ) // Rotate component 90 degrees. if( aTransform.y1 ) // Rotate component 90 degrees.
{ {
if( orient == TEXT_ORIENT_HORIZ ) if( orient == TEXT_ORIENT_HORIZ )
...@@ -404,9 +431,6 @@ void LIB_TEXT::DisplayInfo( EDA_DRAW_FRAME* frame ) ...@@ -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 EDA_RECT LIB_TEXT::GetBoundingBox() const
{ {
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when /* 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_ #ifndef _LIB_TEXT_H_
#define _LIB_TEXT_H_ #define _LIB_TEXT_H_
#include "lib_draw_item.h" #include "lib_draw_item.h"
class LINE_READER;
/*********************************************/ /*********************************************/
/* Graphic Body Item: Text */ /* Graphic Body Item: Text */
/* This is only a graphic text. */ /* This is only a graphic text. */
...@@ -25,7 +55,7 @@ class LIB_TEXT : public LIB_ITEM, public EDA_TEXT ...@@ -25,7 +55,7 @@ class LIB_TEXT : public LIB_ITEM, public EDA_TEXT
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform ); 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. * @param aPosition - Edit position in drawing units.
*/ */
...@@ -44,7 +74,7 @@ public: ...@@ -44,7 +74,7 @@ public:
/** /**
* Sets the text item string to \a aText. * 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 * 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 * being moved, the name change must be delayed until the next redraw to prevent
* drawing artifacts. * drawing artifacts.
...@@ -60,7 +90,8 @@ public: ...@@ -60,7 +90,8 @@ public:
* @return - true if success writing else false. * @return - true if success writing else false.
*/ */
virtual bool Save( FILE* aFile ); 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. * Test if the given point is within the bounds of this object.
...@@ -92,12 +123,16 @@ public: ...@@ -92,12 +123,16 @@ public:
} }
/** /**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item * @return the size of the "pen" that be used to draw or plot this item
*/ */
virtual int GetPenSize( ) const; virtual int GetPenSize( ) const;
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame ); virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
* @return the boundary box for this, in schematic coordinates
*/
virtual EDA_RECT GetBoundingBox() const; virtual EDA_RECT GetBoundingBox() const;
void Rotate(); void Rotate();
......
/* /*
* This program source code file is part of KiCad, a free EDA CAD application. * 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) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net> * Copyright (C) 2008 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors. * Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
* *
* This program is free software; you can redistribute it and/or * 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 ...@@ -94,7 +94,8 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
PrintMsg( MsgDiag ); PrintMsg( MsgDiag );
if( !reader.ReadLine() 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!" ); MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" );
DisplayError( this, MsgDiag ); DisplayError( this, MsgDiag );
...@@ -104,13 +105,13 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi ...@@ -104,13 +105,13 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
line = reader.Line(); line = reader.Line();
// get the file version here. // get the file version here.
char *strversion = line + 9 + sizeof(SCHEMATIC_HEAD_STRING); char *strversion = line + 9 + sizeof( SCHEMATIC_HEAD_STRING );
// Skip blanks // Skip blanks
while( *strversion && *strversion < '0' ) while( *strversion && *strversion < '0' )
strversion++; strversion++;
int version = atoi(strversion); int version = atoi( strversion );
if( version > EESCHEMA_VERSION ) if( version > EESCHEMA_VERSION )
{ {
...@@ -147,6 +148,7 @@ again." ); ...@@ -147,6 +148,7 @@ again." );
item = NULL; item = NULL;
char* sline = line; char* sline = line;
while( (*sline != ' ' ) && *sline ) while( (*sline != ' ' ) && *sline )
sline++; sline++;
...@@ -274,6 +276,7 @@ static void LoadLayers( LINE_READER* aLine ) ...@@ -274,6 +276,7 @@ static void LoadLayers( LINE_READER* aLine )
aLine->ReadLine(); aLine->ReadLine();
sscanf( *aLine, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer ); sscanf( *aLine, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
if( strcmp( Name, "EELAYER" ) !=0 ) if( strcmp( Name, "EELAYER" ) !=0 )
{ {
/* error : init par default */ /* error : init par default */
...@@ -282,6 +285,7 @@ static void LoadLayers( LINE_READER* aLine ) ...@@ -282,6 +285,7 @@ static void LoadLayers( LINE_READER* aLine )
if( Number <= 0 ) if( Number <= 0 )
Number = MAX_LAYER; Number = MAX_LAYER;
if( Number > MAX_LAYER ) if( Number > MAX_LAYER )
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