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
#define CLASS_LIBENTRY_H
......@@ -12,6 +37,7 @@
#include <map>
class LINE_READER;
class CMP_LIBRARY;
class LIB_ALIAS;
class LIB_COMPONENT;
......@@ -45,8 +71,11 @@ enum LibrEntryOptions
/**
* Component library alias object definition.
*
* Component aliases are not really components. They are references
* to an actual component object.
* Component aliases are not really components. An alias uses the component definition
* (graphic, pins...) but has its own name, keywords and documentation. Therefore, when
* the component is modified, alias of this component are modified. This is a simple
* method to create components that have the same physical layout with different names
* such as 74LS00, 74HC00 ... and many op amps.
*/
class LIB_ALIAS : public EDA_ITEM
{
......@@ -144,7 +173,8 @@ extern int LibraryEntryCompare( const LIB_ALIAS* aItem1, const LIB_ALIAS* aItem2
/**
* Library component object definition.
* Class LIB_COMPONENT
* defines a library component object.
*
* A library component object is typically saved and loaded in a component library file (.lib).
* Library components are different from schematic components.
......@@ -207,7 +237,7 @@ public:
* Add an alias \a aName to the component.
*
* Duplicate alias names are not added to the alias list. Debug builds will raise an
* assertion. Release builds will fail silenetly.
* assertion. Release builds will fail silently.
*
* @param aName - Name of alias to add.
*/
......@@ -255,7 +285,16 @@ public:
**/
EDA_RECT GetBodyBoundingBox( int aUnit, int aConvert ) const;
/**
* Function SaveDateAndTime
* write the date and time of component to \a aFile in the format:
* "Ti yy/mm/jj hh:mm:ss"
*
* @param aFile A point to a FILE object containing the file to write to.
* @return True if the date and time were successfully written to \a aFile.
*/
bool SaveDateAndTime( FILE* aFile );
bool LoadDateAndTime( char* aLine );
/**
......@@ -267,19 +306,17 @@ public:
bool Save( FILE* aFile );
/**
* Load component definition from \a aFile.
* Load component definition from \a aReader.
*
* @param aFile - File descriptor of file to load form.
* @param aLine - The first line of the component definition.
* @param aLineNum - The current line number in the file.
* @param aReader A LINE_READER object to load file from.
* @param aErrorMsg - Description of error on load failure.
* @return True if the load was successful, false if there was an error.
*/
bool Load( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool LoadField( char* aLine, wxString& aErrorMsg );
bool LoadDrawEntries( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool Load( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadField( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadDrawEntries( LINE_READER& aReader, wxString& aErrorMsg );
bool LoadAliases( char* aLine, wxString& aErrorMsg );
bool LoadFootprints( FILE* aFile, char* aLine, int* aLineNum, wxString& aErrorMsg );
bool LoadFootprints( LINE_READER& aReader, wxString& aErrorMsg );
bool IsPower() { return m_options == ENTRY_POWER; }
bool IsNormal() { return m_options == ENTRY_NORMAL; }
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file class_library.cpp
*/
......@@ -10,6 +35,7 @@
#include "gestfich.h"
#include "eda_doc.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -129,6 +155,7 @@ void CMP_LIBRARY::SearchEntryNames( wxArrayString& aNames,
{
if( !aKeySearch.IsEmpty() && KeyWordOk( aKeySearch, (*it).second->GetKeyWords() ) )
aNames.Add( (*it).first );
if( !aNameSearch.IsEmpty() && WildCompareString( aNameSearch,
(*it).second->GetName(), false ) )
aNames.Add( (*it).first );
......@@ -186,10 +213,6 @@ LIB_ALIAS* CMP_LIBRARY::FindEntry( const wxChar* aName )
}
/**
* Return the first entry in the library.
* @return The first entry or NULL if the library has no entries.
*/
LIB_ALIAS* CMP_LIBRARY::GetFirstEntry()
{
if( aliases.size() )
......@@ -198,6 +221,7 @@ LIB_ALIAS* CMP_LIBRARY::GetFirstEntry()
return NULL;
}
LIB_COMPONENT* CMP_LIBRARY::FindComponent( const wxChar* aName )
{
LIB_COMPONENT* component = NULL;
......@@ -279,7 +303,7 @@ LIB_ALIAS* CMP_LIBRARY::RemoveEntry( LIB_ALIAS* aEntry )
return NULL;
// If the entry pointer doesn't match the name it is mapped to in the library, we
// have done someething terribly wrong.
// have done something terribly wrong.
wxCHECK_MSG( (*it).second == aEntry, NULL,
wxT( "Pointer mismatch while attempting to remove entry <" ) +
aEntry->GetName() + wxT( "> from library <" ) + GetName() + wxT( ">." ) );
......@@ -380,8 +404,7 @@ LIB_ALIAS* CMP_LIBRARY::GetPreviousEntry( const wxChar* aName )
bool CMP_LIBRARY::Load( wxString& aErrorMsg )
{
FILE* file;
int lineNumber = 0;
char line[LINE_BUFFER_LEN_LARGE]; // Use a very large buffer to load data
char* line;
LIB_COMPONENT* libEntry;
wxString msg;
......@@ -399,10 +422,11 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
return false;
}
if( GetLine( file, line, &lineNumber, sizeof( line ) ) == NULL )
FILE_LINE_READER reader( file, fileName.GetFullPath() );
if( !reader.ReadLine() )
{
aErrorMsg = _( "The file is empty!" );
fclose( file );
return false;
}
......@@ -411,6 +435,8 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
{
wxString tmp;
line = reader.Line();
header = FROM_UTF8( line );
wxStringTokenizer tkn( header );
......@@ -426,21 +452,18 @@ bool CMP_LIBRARY::Load( wxString& aErrorMsg )
|| !tkn.GetNextToken().Upper().StartsWith(wxT( "EESCHEMA-LIB" ) ) )
{
aErrorMsg = _( "The file is NOT an Eeschema library!" );
fclose( file );
return false;
}
if( !tkn.HasMoreTokens() )
{
aErrorMsg = _( "The file header is missing version and time stamp information." );
fclose( file );
return false;
}
if( tkn.GetNextToken() != wxT( "Version" ) || !tkn.HasMoreTokens() )
{
aErrorMsg = wxT( "The file header version information is invalid." );
fclose( file );
return false;
}
......@@ -466,19 +489,18 @@ the current schematic." ),
{
versionMajor = (int) major;
versionMinor = (int) minor;
// wxLogDebug( wxT( "Component library <%s> is version %d.%d." ),
// GetChars( GetName() ), versionMajor, versionMinor );
}
}
while( GetLine( file, line, &lineNumber, sizeof( line ) ) )
while( reader.ReadLine() )
{
line = reader.Line();
if( type == LIBRARY_TYPE_EESCHEMA && strnicmp( line, "$HEADER", 7 ) == 0 )
{
if( !LoadHeader( file, &lineNumber ) )
if( !LoadHeader( reader ) )
{
aErrorMsg = _( "An error occurred attempting to read the header." );
fclose( file );
return false;
}
......@@ -490,7 +512,7 @@ the current schematic." ),
/* Read one DEF/ENDDEF part entry from library: */
libEntry = new LIB_COMPONENT( wxEmptyString, this );
if( libEntry->Load( file, line, &lineNumber, msg ) )
if( libEntry->Load( reader, msg ) )
{
/* Check for duplicate entry names and warn the user about
* the potential conflict.
......@@ -516,8 +538,6 @@ the current schematic." ),
}
}
fclose( file );
return true;
}
......@@ -542,13 +562,15 @@ void CMP_LIBRARY::LoadAliases( LIB_COMPONENT* component )
}
bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum )
bool CMP_LIBRARY::LoadHeader( LINE_READER& aLineReader )
{
char Line[LINE_BUFFER_LEN], * text, * data;
char* line, * text, * data;
while( GetLine( libfile, Line, LineNum, sizeof(Line) ) )
while( aLineReader.ReadLine() )
{
text = strtok( Line, " \t\r\n" );
line = (char*) aLineReader;
text = strtok( line, " \t\r\n" );
data = strtok( NULL, " \t\r\n" );
if( stricmp( text, "TimeStamp" ) == 0 )
......@@ -558,7 +580,7 @@ bool CMP_LIBRARY::LoadHeader( FILE* libfile, int* LineNum )
return true;
}
return FALSE;
return false;
}
......@@ -618,6 +640,7 @@ bool CMP_LIBRARY::LoadDocs( wxString& aErrorMsg )
{
if( strncmp( line, "$ENDCMP", 7 ) == 0 )
break;
text = strtok( line + 2, "\n\r" );
if( entry )
......@@ -662,7 +685,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
{
libFileName.MakeAbsolute();
msg = wxT( "Failed to rename old component library file " ) +
backupFileName.GetFullPath();
backupFileName.GetFullPath();
DisplayError( NULL, msg );
}
}
......@@ -680,6 +703,7 @@ bool CMP_LIBRARY::Save( const wxString& aFullFileName, bool aOldDocFormat )
isModified = false;
timeStamp = GetTimeStamp();
if( !SaveHeader( libfile ) )
{
fclose( libfile );
......@@ -728,7 +752,7 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
if( !wxRenameFile( docFileName.GetFullPath(), backupFileName.GetFullPath() ) )
{
msg = wxT( "Failed to save old library document file " ) +
backupFileName.GetFullPath();
backupFileName.GetFullPath();
DisplayError( NULL, msg );
}
}
......@@ -739,12 +763,13 @@ bool CMP_LIBRARY::SaveDocFile( const wxString& aFullFileName )
{
docFileName.MakeAbsolute();
msg = wxT( "Failed to create component document library file " ) +
docFileName.GetFullPath();
docFileName.GetFullPath();
DisplayError( NULL, msg );
return false;
}
char line[256];
if( fprintf( docfile, "%s Date: %s\n", DOCFILE_IDENT, DateAndTime( line ) ) < 0 )
{
fclose( docfile );
......@@ -774,6 +799,7 @@ bool CMP_LIBRARY::SaveHeader( FILE* aFile )
bool succes = true;
DateAndTime( BufLine );
if( fprintf( aFile, "%s %d.%d Date: %s\n", LIBFILE_IDENT,
LIB_VERSION_MAJOR, LIB_VERSION_MINOR, BufLine ) < 0 )
succes = false;
......@@ -884,11 +910,6 @@ void CMP_LIBRARY::RemoveLibrary( const wxString& aName )
}
/**
* Test for an existing library.
* @param aLibptr - aLibptr.
* @return true found. false if not found.
*/
bool CMP_LIBRARY::LibraryExists( const CMP_LIBRARY* aLibptr )
{
BOOST_FOREACH( CMP_LIBRARY& lib, libraryList )
......
......@@ -6,12 +6,14 @@
#ifndef CLASS_LIBRARY_H
#define CLASS_LIBRARY_H
#include <wx/filename.h>
#include "class_libentry.h"
class LINE_READER;
/*
* Component Library version and file header macros.
*/
......@@ -130,7 +132,7 @@ public:
private:
bool SaveHeader( FILE* aFile );
bool LoadHeader( FILE* aFile, int* aLineNum );
bool LoadHeader( LINE_READER& aLineReader );
void LoadAliases( LIB_COMPONENT* aComponent );
public:
......
/*******************/
/** class LIB_ARC **/
/*******************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_arc.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -9,6 +34,7 @@
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -79,11 +105,6 @@ LIB_ARC::LIB_ARC( const LIB_ARC& aArc ) : LIB_ITEM( aArc )
}
/**
* format:
* A centre_posx centre_posy rayon start_angle end_angle unit convert
* fill('N', 'F' ou 'f') startx starty endx endy
*/
bool LIB_ARC::Save( FILE* aFile )
{
int x1 = m_t1;
......@@ -106,12 +127,13 @@ bool LIB_ARC::Save( FILE* aFile )
}
bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg )
bool LIB_ARC::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int startx, starty, endx, endy, cnt;
int startx, starty, endx, endy, cnt;
char tmp[256];
char* line = (char*) aLineReader;
cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %d %d %s %d %d %d %d",
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %d %s %d %d %d %d",
&m_Pos.x, &m_Pos.y, &m_Radius, &m_t1, &m_t2, &m_Unit,
&m_Convert, &m_Width, tmp, &startx, &starty, &endx, &endy );
if( cnt < 8 )
......@@ -122,6 +144,7 @@ bool LIB_ARC::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
......@@ -326,10 +349,6 @@ void LIB_ARC::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_ARC::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
......@@ -383,6 +402,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
int pt1 = m_t1;
int pt2 = m_t2;
bool swap = aTransform.MapAngles( &pt1, &pt2 );
if( swap )
{
EXCHG( pos1.x, pos2.x );
......@@ -392,6 +412,7 @@ void LIB_ARC::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOf
GRSetDrawMode( aDC, aDrawMode );
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -470,10 +491,13 @@ start(%d, %d), end(%d, %d), radius %d" ),
if( angleStart <= 900 && angleEnd >= 900 ) /* 90 deg */
maxY = centerPos.y + m_Radius;
if( angleStart <= 1800 && angleEnd >= 1800 ) /* 180 deg */
minX = centerPos.x - m_Radius;
if( angleStart <= 2700 && angleEnd >= 2700 ) /* 270 deg */
minY = centerPos.y - m_Radius;
if( angleStart <= 3600 && angleEnd >= 3600 ) /* 0 deg */
maxX = centerPos.x + m_Radius;
......@@ -552,7 +576,9 @@ void LIB_ARC::BeginEdit( int aEditMode, const wxPoint aPosition )
m_editSelectPoint = END;
}
else
{
m_editSelectPoint = OUTLINE;
}
m_editState = 0;
SetEraseLastDrawItem();
......
/**************************/
/* Graphic Body Item: Arc */
/**************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_arc.h
*/
#ifndef _LIB_ARC_H_
#define _LIB_ARC_H_
......@@ -10,6 +35,7 @@
class TRANSFORM;
class LINE_READER;
class LIB_ARC : public LIB_ITEM
......@@ -77,7 +103,8 @@ public:
* @return - True if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Tests if the given wxPoint is within the bounds of this object.
......@@ -100,6 +127,7 @@ public:
virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/**********************/
/** class LIB_BEZIER **/
/**********************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_bezier.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -10,6 +35,7 @@
#include "trigo.h"
#include "wxstruct.h"
#include "bezier_curves.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -56,26 +82,28 @@ bool LIB_BEZIER::Save( FILE* aFile )
}
bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
bool LIB_BEZIER::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* p;
int i, ccount = 0;
wxPoint pt;
char* line = (char*) aLineReader;
i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
i = sscanf( line + 2, "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
if( i !=4 )
{
aErrorMsg.Printf( _( "Bezier only had %d parameters of the required 4" ), i );
return false;
}
if( ccount <= 0 )
{
aErrorMsg.Printf( _( "Bezier count parameter %d is invalid" ), ccount );
return false;
}
p = strtok( &aLine[2], " \t\n" );
p = strtok( line + 2, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
......@@ -84,17 +112,21 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
{
wxPoint point;
p = strtok( NULL, " \t\n" );
if( sscanf( p, "%d", &pt.x ) != 1 )
{
aErrorMsg.Printf( _( "Bezier point %d X position not defined" ), i );
return false;
}
p = strtok( NULL, " \t\n" );
if( sscanf( p, "%d", &pt.y ) != 1 )
{
aErrorMsg.Printf( _( "Bezier point %d Y position not defined" ), i );
return false;
}
m_BezierPoints.push_back( pt );
}
......@@ -104,6 +136,7 @@ bool LIB_BEZIER::Load( char* aLine, wxString& aErrorMsg )
{
if( p[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( p[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
}
......@@ -131,6 +164,7 @@ int LIB_BEZIER::DoCompare( const LIB_ITEM& aOther ) const
{
if( m_BezierPoints[i].x != tmp->m_BezierPoints[i].x )
return m_BezierPoints[i].x - tmp->m_BezierPoints[i].x;
if( m_BezierPoints[i].y != tmp->m_BezierPoints[i].y )
return m_BezierPoints[i].y - tmp->m_BezierPoints[i].y;
}
......@@ -181,6 +215,7 @@ void LIB_BEZIER::DoMirrorHorizontal( const wxPoint& aCenter )
}
imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ )
{
m_BezierPoints[i].x -= aCenter.x;
......@@ -201,6 +236,7 @@ void LIB_BEZIER::DoMirrorVertical( const wxPoint& aCenter )
}
imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ )
{
m_BezierPoints[i].y -= aCenter.y;
......@@ -214,12 +250,14 @@ void LIB_BEZIER::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
int rot_angle = aRotateCCW ? -900 : 900;
size_t i, imax = m_PolyPoints.size();
for( i = 0; i < imax; i++ )
{
RotatePoint( &m_PolyPoints[i], aCenter, rot_angle );
}
imax = m_BezierPoints.size();
for( i = 0; i < imax; i++ )
{
RotatePoint( &m_BezierPoints[i], aCenter, rot_angle );
......@@ -254,15 +292,12 @@ void LIB_BEZIER::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_BEZIER::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
}
void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform )
{
......@@ -288,9 +323,12 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -319,28 +357,18 @@ void LIB_BEZIER::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param aRefPos A wxPoint to test
* @return true if a hit, else false
*/
bool LIB_BEZIER::HitTest( const wxPoint& aRefPos )
{
int mindist = GetPenSize() / 2;
// Have a minimal tolerance for hit test
if ( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aRefPos, mindist, DefaultTransform );
}
/**
* Function HitTest
* @return if the point aPosRef is near a segment
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to a segment
* @param aTransform = the transform matrix
*/
bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform )
{
wxPoint ref, start, end;
......@@ -361,10 +389,6 @@ bool LIB_BEZIER::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTra
}
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
EDA_RECT LIB_BEZIER::GetBoundingBox() const
{
EDA_RECT rect;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_bezier.h
*/
#ifndef _LIB_BEZIER_H_
#define _LIB_BEZIER_H_
#include "lib_draw_item.h"
class LINE_READER;
/**************************************************/
/* Graphic Body Item: Bezier Curve (set of lines) */
/**************************************************/
......@@ -39,7 +69,8 @@ public:
* @return true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
......@@ -65,11 +96,13 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
virtual EDA_RECT GetBoundingBox() const;
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_circle.cpp
* @brief LIB_CIRCLE class definition
* @brief LIB_CIRCLE class implementation.
*/
#include "fctsys.h"
......@@ -10,6 +35,7 @@
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -48,11 +74,12 @@ bool LIB_CIRCLE::Save( FILE* aFile )
}
bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
bool LIB_CIRCLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char tmp[256];
char* line = (char*) aLineReader;
int cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
int cnt = sscanf( line + 2, "%d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
&m_Radius, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 6 )
......@@ -63,6 +90,7 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
......@@ -70,12 +98,6 @@ bool LIB_CIRCLE::Load( char* aLine, wxString& aErrorMsg )
}
/**
* Function HitTest
* tests if the given wxPoint is within the bounds of this object.
* @param aPosRef A wxPoint to test in Eeschema space
* @return - true if a hit, else false
*/
bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
{
int mindist = GetPenSize() / 2;
......@@ -88,13 +110,6 @@ bool LIB_CIRCLE::HitTest( const wxPoint& aPosRef )
}
/**
* Function HitTest
* @return true if the point aPosRef is near this object
* @param aPosRef = a wxPoint to test
* @param aThreshold = max distance to this object (usually the half thickness of a line)
* @param aTransform = the transform matrix
*/
bool LIB_CIRCLE::HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform )
{
if( aThreshold < 0 )
......@@ -165,6 +180,7 @@ void LIB_CIRCLE::DoMirrorHorizontal( const wxPoint& aCenter )
m_Pos.x += aCenter.x;
}
void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter )
{
m_Pos.y -= aCenter.y;
......@@ -172,6 +188,7 @@ void LIB_CIRCLE::DoMirrorVertical( const wxPoint& aCenter )
m_Pos.y += aCenter.y;
}
void LIB_CIRCLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
{
int rot_angle = aRotateCCW ? -900 : 900;
......@@ -197,10 +214,6 @@ void LIB_CIRCLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_CIRCLE::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
......@@ -220,7 +233,9 @@ void LIB_CIRCLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint&
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
GRSetDrawMode( aDC, aDrawMode );
......
/*****************************/
/* Graphic Body Item: Circle */
/*****************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_circle.h
*/
#ifndef _LIB_CIRCLE_H_
#define _LIB_CIRCLE_H_
#include "lib_draw_item.h"
class LINE_READER;
class LIB_CIRCLE : public LIB_ITEM
{
int m_Radius;
......@@ -32,6 +59,7 @@ public:
LIB_CIRCLE( LIB_COMPONENT * aParent );
LIB_CIRCLE( const LIB_CIRCLE& aCircle );
~LIB_CIRCLE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_CIRCLE" );
......@@ -45,7 +73,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
......@@ -65,11 +94,13 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
virtual EDA_RECT GetBoundingBox() const;
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
......
/*********************/
/* lib_draw_item.cpp */
/*********************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_draw_item.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -16,7 +41,6 @@ const int fill_tab[3] = { 'N', 'F', 'f' };
//#define DRAW_ARC_WITH_ANGLE // Used to draw arcs
/* Base class (abstract) for components bodies items */
LIB_ITEM::LIB_ITEM( KICAD_T aType,
LIB_COMPONENT* aComponent,
int aUnit,
......@@ -46,13 +70,6 @@ LIB_ITEM::LIB_ITEM( const LIB_ITEM& aItem ) :
}
/**
* Update the message panel information with the drawing information.
*
* This base function is used to display the information common to the
* all library items. Call the base class from the derived class or the
* common information will not be updated in the message panel.
*/
void LIB_ITEM::DisplayInfo( EDA_DRAW_FRAME* aFrame )
{
wxString msg;
......
/****************************************************************/
/* Headers for library definition and lib component definitions */
/****************************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/* Definitions of graphic items used to create shapes in component libraries.
/**
* @file class_libentry.h
* @brief Class LIB_ITEM definition.
*/
#ifndef _LIB_ITEM_H_
#define _LIB_ITEM_H_
......@@ -13,6 +37,7 @@
#include <boost/ptr_container/ptr_vector.hpp>
class LINE_READER;
class LIB_COMPONENT;
class PLOTTER;
class LIB_ITEM;
......@@ -35,7 +60,7 @@ typedef boost::ptr_vector< LIB_ITEM > LIB_ITEMS;
/**
* Helper for defining a list of pin object pointers. The list does not
* use a Boost pointer class so the object pointers do not accidently get
* use a Boost pointer class so the object pointers do not accidentally get
* deleted when the container is deleted.
*/
typedef std::vector< LIB_PIN* > LIB_PINS;
......@@ -194,7 +219,7 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile ) = 0;
virtual bool Load( char* aLine, wxString& aErrorMsg ) = 0;
virtual bool Load( LINE_READER& aLine, wxString& aErrorMsg ) = 0;
LIB_COMPONENT* GetParent()
{
......@@ -232,9 +257,15 @@ public:
virtual EDA_RECT GetBoundingBox() const { return EDA_ITEM::GetBoundingBox(); }
/**
* Displays basic info (type, part and convert) about item
* in msg panel
* @param aFrame = main frame where the message manel info is.
* Function DisplayInfo
* displays basic info (type, part and convert) about the current item
* in message panel.
* <p>
* This base function is used to display the information common to the
* all library items. Call the base class from the derived class or the
* common information will not be updated in the message panel.
* </p>
* @param aFrame A pointer to EDA_DRAW_FRAME window where the message panel resides.
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
......
/**********************************************************/
/* libclass.cpp */
/**********************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_field.cpp
*/
#include "fctsys.h"
#include "appl_wxstruct.h"
......@@ -21,24 +46,6 @@
#include "template_fieldnames.h"
/*******************/
/* class LIB_FIELD */
/*******************/
/**
* a Field is a string linked to a component.
* Unlike a pure graphic text, fields can be used in netlist generation
* and other tools (BOM).
*
* The first 4 fields have a special meaning:
*
* 0 = REFERENCE
* 1 = VALUE
* 2 = FOOTPRINT (default Footprint)
* 3 = DOCUMENTATION (user doc link)
*
* others = free fields
*/
LIB_FIELD::LIB_FIELD(LIB_COMPONENT * aParent, int idfield ) :
LIB_ITEM( LIB_FIELD_T, aParent )
{
......@@ -143,13 +150,14 @@ bool LIB_FIELD::Save( FILE* ExportFile )
}
bool LIB_FIELD::Load( char* line, wxString& errorMsg )
bool LIB_FIELD::Load( LINE_READER& aLineReader, wxString& errorMsg )
{
int cnt;
char textOrient;
char textVisible;
char textHJustify;
char textVJustify[256];
char* line = (char*) aLineReader;
if( sscanf( line + 1, "%d", &m_id ) != 1 || m_id < 0 )
{
......@@ -267,20 +275,12 @@ bool LIB_FIELD::Load( char* line, wxString& errorMsg )
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_FIELD::GetPenSize() const
{
return ( m_Thickness == 0 ) ? g_DrawDefaultLineThickness : m_Thickness;
}
/*
* if aData not NULL, aData must point a wxString which is used instead of
* the m_Text
*/
void LIB_FIELD::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform )
{
......@@ -458,7 +458,7 @@ void LIB_FIELD::DoOffset( const wxPoint& offset )
bool LIB_FIELD::DoTestInside( EDA_RECT& rect ) const
{
/*
* FIXME: This fails to take into acount the size and/or orientation of
* FIXME: This fails to take into account the size and/or orientation of
* the text.
*/
return rect.Contains( m_Pos.x, -m_Pos.y );
......@@ -499,12 +499,6 @@ void LIB_FIELD::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
}
/*
* If the field is the reference, return reference like schematic,
* i.e U -> U? or U?A or the field text for others
*
* @fixme This should be handled by the field object.
*/
wxString LIB_FIELD::GetFullText( int unit )
{
if( m_id != REFERENCE )
......
/*************************************************************/
/* Lib component definitions (libentry) definition of fields */
/*************************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_field.h
*/
#ifndef CLASS_LIBENTRY_FIELDS_H
#define CLASS_LIBENTRY_FIELDS_H
......@@ -13,6 +38,20 @@
* is used in symbol libraries. At least MANDATORY_FIELDS are always present
* in a ram resident library symbol. All constructors must ensure this because
* the component property editor assumes it.
* <p>
* A field is a string linked to a component. Unlike purely graphical text, fields can
* be used in netlist generation and other tools (BOM).
*
* The first 4 fields have a special meaning:
*
* 0 = REFERENCE
* 1 = VALUE
* 2 = FOOTPRINT (default Footprint)
* 3 = DOCUMENTATION (user doc link)
*
* others = free fields
* </p>
*
* @see enum NumFieldType
*/
class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
......@@ -26,6 +65,10 @@ class LIB_FIELD : public LIB_ITEM, public EDA_TEXT
/**
* Draw the field.
* <p>
* If \a aData not NULL, \a aData must point a wxString which is used instead of
* the m_Text
* </p>
*/
void drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aOffset,
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
......@@ -63,7 +106,7 @@ public:
*
* @param aTranslate = true to return translated field name (default)
* false to return the english name
* (usefull when the name is used as keyword in netlists ...)
* (useful when the name is used as keyword in netlists ...)
* @return Name of the field.
*/
wxString GetName(bool aTranslate = true) const;
......@@ -98,16 +141,17 @@ public:
* @return True if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* line, wxString& errorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& errorMsg );
/**
* Copy parameters of this field to another field. Pointers are not copied.
*
* @param aTarget = Target field to copy values to.
*/
void Copy( LIB_FIELD* aTarget ) const;
void Copy( LIB_FIELD* aTarget ) const;
void SetFields( const std::vector <LIB_FIELD> aFields );
void SetFields( const std::vector <LIB_FIELD> aFields );
/**
* Function IsVoid
......@@ -136,7 +180,7 @@ public:
/**
* Displays info (type, part convert filed name and value)
* in msg panel
* @param aFrame = main frame where the message manel info is.
* @param aFrame = main frame where the message panel info is.
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
......@@ -182,6 +226,8 @@ public:
* create a pseudo reference text. If the base reference field is U,
* the string U?A will be returned for unit = 1.
*
* @todo This should be handled by the field object.
*
* @param unit - The package unit number. Only effects reference field.
* @return Field text.
*/
......@@ -209,7 +255,7 @@ public:
/**
* Sets the field text to \a aText.
*
* This method does more than juat set the set the field text. There are special
* This method does more than just set the set the field text. There are special
* cases when changing the text string alone is not enough. If the field is the
* value field, the parent component's name is changed as well. If the field is
* being moved, the name change must be delayed until the next redraw to prevent
......
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
#define CLASS_PIN_H
......@@ -10,9 +33,10 @@
#include "lib_draw_item.h"
class SCH_COMPONENT;
class LINE_READER;
#define TARGET_PIN_RADIUS 12 /* Circle diameter drawn at the active end of pins */
#define TARGET_PIN_RADIUS 12 /* Circle diameter drawn at the active end of pins */
#define DEFAULT_TEXT_SIZE 50 /* Default size for field texts */
#define PART_NAME_LEN 15 /* Maximum length of part name. */
......@@ -126,7 +150,6 @@ public:
void Show( int nestLevel, std::ostream& os ); // virtual override
#endif
/**
* Write pin object to a FILE in "*.lib" format.
*
......@@ -134,7 +157,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Function HitTest
......@@ -157,10 +181,25 @@ public:
*/
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
virtual void DisplayInfo( EDA_DRAW_FRAME* frame );
/**
* Function DisplayInfo
* displays the pin information in the message panel attached to \a aFrame.
*/
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
* Function GetBoundingBox
* @return the boundary box for the pin in schematic coordinates.
*
* Uses DefaultTransform as transform matrix
*/
virtual EDA_RECT GetBoundingBox() const;
/**
* Function ReturnPinEndPoint
*
* @return The pin end position for a component in the normal orientation.
*/
wxPoint ReturnPinEndPoint() const;
/**
......@@ -194,6 +233,10 @@ public:
*/
static wxString ReturnPinStringNum( long aPinNum );
/**
* Function SetPinNumFromString
* fill the pin number buffer with \a aBuffer.
*/
void SetPinNumFromString( wxString& aBuffer );
wxString GetName() const { return m_name; }
......@@ -332,7 +375,7 @@ public:
* Enable or clear pin editing mode.
*
* The pin editing mode marks or unmarks all pins common to this
* pin object for further editing. If any of the pin modifcation
* pin object for further editing. If any of the pin modification
* methods are called after enabling the editing mode, all pins
* marked for editing will have the same attribute changed. The
* only case were this is not true making this pin common to all
......@@ -353,17 +396,42 @@ public:
bool IsVisible() { return ( m_attributes & PIN_INVISIBLE ) == 0; }
/**
* @return the size of the "pen" that be used to draw or plot this item.
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize() const;
/**
* Function DrawPinSymbol
* Draw the pin symbol without text.
* If \a aColor != 0, draw with \a aColor, else with the normal pin color.
*/
void DrawPinSymbol( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aPosition,
int aOrientation, int aDrawMode, int aColor = -1 );
/**
* Function DrawPinTexts
* puts the pin number and pin text info, given the pin line coordinates.
* The line must be vertical or horizontal. If PinText == NULL nothing is printed.
* If PinNum = 0 no number is printed. The current zoom factor is taken into account.
* If TextInside then the text is been put inside,otherwise all is drawn outside.
* Pin Name: substring between '~' is negated
* DrawMode = GR_OR, XOR ...
*/
void DrawPinTexts( EDA_DRAW_PANEL* aPanel, wxDC* aDC, wxPoint& aPosition,
int aOrientation, int TextInside, bool DrawPinNum, bool DrawPinName,
int aColor, int aDrawMode );
/**
* Function PlotPinTexts
* plots the pin number and pin text info, given the pin line coordinates.
* Same as DrawPinTexts((), but output is the plotter
* The line must be vertical or horizontal.
* If PinNext == NULL nothing is printed.
* Current Zoom factor is taken into account.
* If TextInside then the text is been put inside (moving from x1, y1 in
* the opposite direction to x2,y2), otherwise all is drawn outside.
*/
void PlotPinTexts( PLOTTER *aPlotter,
wxPoint& aPosition,
int aOrientation,
......
/************************/
/** class LIB_POLYLINE **/
/************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_polyline.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
#include "macros.h"
#include "class_drawpanel.h"
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -57,13 +82,14 @@ bool LIB_POLYLINE::Save( FILE* aFile )
}
bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
bool LIB_POLYLINE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
char* p;
int i, ccount = 0;
wxPoint pt;
char* line = (char*) aLineReader;
i = sscanf( &aLine[2], "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
i = sscanf( line + 2, "%d %d %d %d", &ccount, &m_Unit, &m_Convert, &m_Width );
m_Fill = NO_FILL;
......@@ -72,13 +98,14 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
aErrorMsg.Printf( _( "polyline only had %d parameters of the required 4" ), i );
return false;
}
if( ccount <= 0 )
{
aErrorMsg.Printf( _( "polyline count parameter %d is invalid" ), ccount );
return false;
}
p = strtok( &aLine[2], " \t\n" );
p = strtok( line + 2, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
p = strtok( NULL, " \t\n" );
......@@ -87,17 +114,21 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
{
wxPoint point;
p = strtok( NULL, " \t\n" );
if( p == NULL || sscanf( p, "%d", &pt.x ) != 1 )
{
aErrorMsg.Printf( _( "polyline point %d X position not defined" ), i );
return false;
}
p = strtok( NULL, " \t\n" );
if( p == NULL || sscanf( p, "%d", &pt.y ) != 1 )
{
aErrorMsg.Printf( _( "polyline point %d Y position not defined" ), i );
return false;
}
AddPoint( pt );
}
......@@ -105,6 +136,7 @@ bool LIB_POLYLINE::Load( char* aLine, wxString& aErrorMsg )
{
if( p[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( p[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
}
......@@ -132,6 +164,7 @@ int LIB_POLYLINE::DoCompare( const LIB_ITEM& aOther ) const
{
if( m_PolyPoints[i].x != tmp->m_PolyPoints[i].x )
return m_PolyPoints[i].x - tmp->m_PolyPoints[i].x;
if( m_PolyPoints[i].y != tmp->m_PolyPoints[i].y )
return m_PolyPoints[i].y - tmp->m_PolyPoints[i].y;
}
......@@ -236,10 +269,6 @@ void LIB_POLYLINE::AddPoint( const wxPoint& point )
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_POLYLINE::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
......@@ -263,7 +292,9 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
// Set the size of the buffer of coordinates
if( Buf_Poly_Drawings == NULL )
......@@ -291,6 +322,7 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
}
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -298,9 +330,9 @@ void LIB_POLYLINE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint
if( fill == FILLED_WITH_BG_BODYCOLOR )
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
Buf_Poly_Drawings, 1, GetPenSize(),
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
Buf_Poly_Drawings, 1, GetPenSize(),
(m_Flags & IS_MOVED) ? color : ReturnLayerColor( LAYER_DEVICE_BACKGROUND ),
ReturnLayerColor( LAYER_DEVICE_BACKGROUND ) );
else if( fill == FILLED_SHAPE )
GRPoly( &aPanel->m_ClipBox, aDC, m_PolyPoints.size(),
Buf_Poly_Drawings, 1, GetPenSize(), color, color );
......@@ -326,6 +358,7 @@ bool LIB_POLYLINE::HitTest( const wxPoint& aPosition )
// Have a minimal tolerance for hit test
if( mindist < MINIMUM_SELECTION_DISTANCE )
mindist = MINIMUM_SELECTION_DISTANCE;
return HitTest( aPosition, mindist, DefaultTransform );
}
......@@ -350,10 +383,6 @@ bool LIB_POLYLINE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
}
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
EDA_RECT LIB_POLYLINE::GetBoundingBox() const
{
EDA_RECT rect;
......@@ -426,7 +455,7 @@ wxString LIB_POLYLINE::GetSelectMenuText() const
void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
{
wxCHECK_RET( ( aEditMode & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0,
wxT( "Invalid edit mode for LIB_POLYLINE object." ) );
wxT( "Invalid edit mode for LIB_POLYLINE object." ) );
if( aEditMode == IS_NEW )
{
......@@ -451,7 +480,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
wxPoint prevPoint = startPoint;
// Find the right index of the point to be dragged
BOOST_FOREACH( wxPoint point, m_PolyPoints ) {
BOOST_FOREACH( wxPoint point, m_PolyPoints )
{
int distancePoint = (aPosition - point).x * (aPosition - point).x +
(aPosition - point).y * (aPosition - point).y;
......@@ -466,6 +496,7 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
// check middle of an edge
wxPoint offset = ( aPosition + aPosition - point - prevPoint );
distancePoint = ( offset.x * offset.x + offset.y * offset.y ) / 4 + 1;
if( distancePoint < distanceMin )
{
// Save point.
......@@ -473,8 +504,8 @@ void LIB_POLYLINE::BeginEdit( int aEditMode, const wxPoint aPosition )
m_ModifyIndex = -index; // negative indicates new vertex is to be inserted
distanceMin = distancePoint;
}
prevPoint = point;
prevPoint = point;
index++;
}
......@@ -501,6 +532,7 @@ bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition )
// do not add zero length segments
if( m_PolyPoints[m_PolyPoints.size() - 2] != m_PolyPoints.back() )
m_PolyPoints.push_back( aPosition );
return true;
}
......@@ -511,7 +543,7 @@ bool LIB_POLYLINE::ContinueEdit( const wxPoint aPosition )
void LIB_POLYLINE::EndEdit( const wxPoint& aPosition, bool aAbort )
{
wxCHECK_RET( ( m_Flags & ( IS_NEW | IS_MOVED | IS_RESIZED ) ) != 0,
wxT( "Bad call to EndEdit(). LIB_POLYLINE is not being edited." ) );
wxT( "Bad call to EndEdit(). LIB_POLYLINE is not being edited." ) );
// do not include last point twice
if( m_Flags == IS_NEW && 2 < m_PolyPoints.size() )
......@@ -519,17 +551,18 @@ void LIB_POLYLINE::EndEdit( const wxPoint& aPosition, bool aAbort )
if( m_PolyPoints[ m_PolyPoints.size() - 2 ] == m_PolyPoints.back() )
m_PolyPoints.pop_back();
}
if( (m_Flags == IS_RESIZED) && (m_PolyPoints.size() > 2) ) // do not delete last two points... keep it alive
{
if( ( m_ModifyIndex > 0 && m_PolyPoints[ m_ModifyIndex ] ==
m_PolyPoints[ m_ModifyIndex - 1 ] )
||
( m_ModifyIndex < (int) m_PolyPoints.size() - 1
|| ( m_ModifyIndex < (int) m_PolyPoints.size() - 1
&& m_PolyPoints[ m_ModifyIndex ] == m_PolyPoints[ m_ModifyIndex + 1 ] ) )
{
m_PolyPoints.erase( m_PolyPoints.begin() + m_ModifyIndex ); // delete a point on this
}
}
m_Flags = 0;
SetEraseLastDrawItem( false );
}
......@@ -549,6 +582,7 @@ void LIB_POLYLINE::calcEdit( const wxPoint& aPosition )
m_ModifyIndex = -m_ModifyIndex;
m_PolyPoints.insert( m_PolyPoints.begin() + m_ModifyIndex, aPosition );
}
m_PolyPoints[ m_ModifyIndex ] = aPosition;
}
else if( m_Flags == IS_MOVED )
......
/**********************************************************/
/* Graphic Body Item: Polygon and polyline (set of lines) */
/**********************************************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_polyline.h
*/
#ifndef _LIB_POLYLINE_H_
#define _LIB_POLYLINE_H_
#include "lib_draw_item.h"
class LINE_READER;
class LIB_POLYLINE : public LIB_ITEM
{
......@@ -29,7 +55,6 @@ class LIB_POLYLINE : public LIB_ITEM
*/
void calcEdit( const wxPoint& aPosition );
public:
public:
LIB_POLYLINE( LIB_COMPONENT * aParent );
LIB_POLYLINE( const LIB_POLYLINE& aPolyline );
......@@ -48,7 +73,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
void AddPoint( const wxPoint& aPoint );
......@@ -79,11 +105,13 @@ public:
virtual bool HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetBoundingBox
* @return the boundary box for this, in library coordinates
*/
virtual EDA_RECT GetBoundingBox() const;
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/*************************/
/** class LIB_RECTANGLE **/
/*************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_rectangle.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -9,6 +34,7 @@
#include "plot_common.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "general.h"
#include "protos.h"
......@@ -49,12 +75,13 @@ bool LIB_RECTANGLE::Save( FILE* aFile )
}
bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg )
bool LIB_RECTANGLE::Load( LINE_READER& aLineReader, wxString& aErrorMsg )
{
int cnt;
char tmp[256];
char* line = (char*)aLineReader;
cnt = sscanf( &aLine[2], "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %s", &m_Pos.x, &m_Pos.y,
&m_End.x, &m_End.y, &m_Unit, &m_Convert, &m_Width, tmp );
if( cnt < 7 )
......@@ -65,6 +92,7 @@ bool LIB_RECTANGLE::Load( char* aLine, wxString& aErrorMsg )
if( tmp[0] == 'F' )
m_Fill = FILLED_SHAPE;
if( tmp[0] == 'f' )
m_Fill = FILLED_WITH_BG_BODYCOLOR;
......@@ -131,6 +159,7 @@ void LIB_RECTANGLE::DoMirrorHorizontal( const wxPoint& aCenter )
m_End.x += aCenter.x;
}
void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter )
{
m_Pos.y -= aCenter.y;
......@@ -141,6 +170,7 @@ void LIB_RECTANGLE::DoMirrorVertical( const wxPoint& aCenter )
m_End.y += aCenter.y;
}
void LIB_RECTANGLE::DoRotate( const wxPoint& aCenter, bool aRotateCCW )
{
int rot_angle = aRotateCCW ? -900 : 900;
......@@ -169,15 +199,12 @@ void LIB_RECTANGLE::DoPlot( PLOTTER* aPlotter, const wxPoint& aOffset, bool aFil
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_RECTANGLE::GetPenSize() const
{
return ( m_Width == 0 ) ? g_DrawDefaultLineThickness : m_Width;
}
void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
const wxPoint& aOffset, int aColor, int aDrawMode,
void* aData, const TRANSFORM& aTransform )
......@@ -192,12 +219,15 @@ void LIB_RECTANGLE::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC,
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
pos2 = aTransform.TransformCoordinate( m_End ) + aOffset;
FILL_T fill = aData ? NO_FILL : m_Fill;
if( aColor >= 0 )
fill = NO_FILL;
......@@ -273,18 +303,21 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
start = actualStart;
end.x = actualEnd.x;
end.y = actualStart.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
// locate right segment
start.x = actualEnd.x;
end.y = actualEnd.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
// locate upper segment
start.y = actualEnd.y;
end.x = actualStart.x;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
......@@ -292,6 +325,7 @@ bool LIB_RECTANGLE::HitTest( wxPoint aPosition, int aThreshold, const TRANSFORM&
start = actualStart;
end.x = actualStart.x;
end.y = actualEnd.y;
if( TestSegmentHit( aPosition, start, end, aThreshold ) )
return true;
......
/********************************/
/* Graphic Body Item: Rectangle */
/********************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_rectangle.h
*/
#ifndef _LIB_RECTANGLE_H_
#define _LIB_RECTANGLE_H_
#include "lib_draw_item.h"
class LINE_READER;
class LIB_RECTANGLE : public LIB_ITEM
{
wxPoint m_End; // Rectangle end point.
......@@ -36,6 +63,7 @@ public:
LIB_RECTANGLE( LIB_COMPONENT * aParent );
LIB_RECTANGLE( const LIB_RECTANGLE& aRect );
~LIB_RECTANGLE() { }
virtual wxString GetClass() const
{
return wxT( "LIB_RECTANGLE" );
......@@ -50,7 +78,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
......@@ -70,6 +99,7 @@ public:
virtual bool HitTest( wxPoint aPosRef, int aThreshold, const TRANSFORM& aTransform );
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
......
/***************************/
/* lib_text.cpp */
/***************************/
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* class LIB_TEXT : describes a graphic text used to draw component shapes
* This is only a graphic item
*/
* @file lib_text.cpp
*/
#include "fctsys.h"
#include "gr_basic.h"
......@@ -15,6 +35,7 @@
#include "drawtxt.h"
#include "trigo.h"
#include "wxstruct.h"
#include "richio.h"
#include "lib_draw_item.h"
#include "general.h"
......@@ -54,17 +75,20 @@ bool LIB_TEXT::Save( FILE* ExportFile )
if( fprintf( ExportFile, "T %d %d %d %d %d %d %d %s ", m_Orient, m_Pos.x, m_Pos.y,
m_Size.x, m_Attributs, m_Unit, m_Convert, TO_UTF8( text ) ) < 0 )
return false;
if( fprintf( ExportFile, " %s %d", m_Italic ? "Italic" : "Normal",
( m_Bold > 0 ) ? 1 : 0 ) < 0 )
return false;
char hjustify = 'C';
if( m_HJustify == GR_TEXT_HJUSTIFY_LEFT )
hjustify = 'L';
else if( m_HJustify == GR_TEXT_HJUSTIFY_RIGHT )
hjustify = 'R';
char vjustify = 'C';
if( m_VJustify == GR_TEXT_VJUSTIFY_BOTTOM )
vjustify = 'B';
else if( m_VJustify == GR_TEXT_VJUSTIFY_TOP )
......@@ -77,34 +101,35 @@ bool LIB_TEXT::Save( FILE* ExportFile )
}
bool LIB_TEXT::Load( char* line, wxString& errorMsg )
bool LIB_TEXT::Load( LINE_READER& aLineReader, wxString& errorMsg )
{
int cnt, thickness;
char hjustify = 'C', vjustify = 'C';
char buf[256];
char tmp[256];
char* line = (char*) aLineReader;
buf[0] = 0;
tmp[0] = 0; // For italic option, Not in old versions
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d \"%[^\"]\" %s %d %c %c",
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d \"%[^\"]\" %s %d %c %c",
&m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify );
if( cnt >= 8 ) // if quoted loadng failed, load as not quoted
if( cnt >= 8 ) // if quoted loading failed, load as not quoted
{
m_Text = FROM_UTF8( buf );
// convert two apostrophes back to double quote
m_Text.Replace( wxT( "''" ), wxT( "\"" ) );
}
else
{
cnt = sscanf( &line[2], "%d %d %d %d %d %d %d %s %s %d %c %c",
&m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify );
cnt = sscanf( line + 2, "%d %d %d %d %d %d %d %s %s %d %c %c",
&m_Orient, &m_Pos.x, &m_Pos.y, &m_Size.x, &m_Attributs,
&m_Unit, &m_Convert, buf, tmp, &thickness, &hjustify,
&vjustify );
if( cnt < 8 )
{
......@@ -116,10 +141,12 @@ bool LIB_TEXT::Load( char* line, wxString& errorMsg )
m_Text = FROM_UTF8( buf );
m_Text.Replace( wxT( "~" ), wxT( " " ) );
}
m_Size.y = m_Size.x;
if( strnicmp( tmp, "Italic", 6 ) == 0 )
m_Italic = true;
if( thickness > 0 )
{
m_Bold = true;
......@@ -247,7 +274,7 @@ bool LIB_TEXT::DoTestInside( EDA_RECT& rect ) const
{
/*
* FIXME: This should calculate the text size and justification and
* use rectangle instect.
* use rectangle intersect.
*/
return rect.Contains( m_Pos.x, -m_Pos.y );
}
......@@ -299,11 +326,7 @@ void LIB_TEXT::DoPlot( PLOTTER* plotter, const wxPoint& offset, bool fill,
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
int LIB_TEXT::GetPenSize( ) const
int LIB_TEXT::GetPenSize() const
{
int pensize = m_Thickness;
......@@ -314,6 +337,7 @@ int LIB_TEXT::GetPenSize( ) const
else
pensize = g_DrawDefaultLineThickness;
}
// Clip pen size for small texts:
pensize = Clamp_Text_PenSize( pensize, m_Size, m_Bold );
return pensize;
......@@ -333,7 +357,9 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
color = g_ItemSelectetColor;
}
else
{
color = aColor;
}
pos1 = aTransform.TransformCoordinate( m_Pos ) + aOffset;
......@@ -343,6 +369,7 @@ void LIB_TEXT::drawGraphic( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wxPoint& aO
* orientation/mirror (needed when draw text in schematic)
*/
int orient = m_Orient;
if( aTransform.y1 ) // Rotate component 90 degrees.
{
if( orient == TEXT_ORIENT_HORIZ )
......@@ -404,9 +431,6 @@ void LIB_TEXT::DisplayInfo( EDA_DRAW_FRAME* frame )
}
/**
* @return the boundary box for this, in schematic coordinates
*/
EDA_RECT LIB_TEXT::GetBoundingBox() const
{
/* Y coordinates for LIB_ITEMS are bottom to top, so we must invert the Y position when
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008-2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004-2011 KiCad Developers, see change_log.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you may find one here:
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* or you may search the http://www.gnu.org website for the version 2 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
/**
* @file lib_text.h
*/
#ifndef _LIB_TEXT_H_
#define _LIB_TEXT_H_
#include "lib_draw_item.h"
class LINE_READER;
/*********************************************/
/* Graphic Body Item: Text */
/* This is only a graphic text. */
......@@ -25,7 +55,7 @@ class LIB_TEXT : public LIB_ITEM, public EDA_TEXT
int aColor, int aDrawMode, void* aData, const TRANSFORM& aTransform );
/**
* Calculate the text attributes ralative to \a aPosition while editing.
* Calculate the text attributes relative to \a aPosition while editing.
*
* @param aPosition - Edit position in drawing units.
*/
......@@ -44,7 +74,7 @@ public:
/**
* Sets the text item string to \a aText.
*
* This method does more than juat set the set the text string. There are special
* This method does more than just set the set the text string. There are special
* cases when changing the text string alone is not enough. If the text item is
* being moved, the name change must be delayed until the next redraw to prevent
* drawing artifacts.
......@@ -60,7 +90,8 @@ public:
* @return - true if success writing else false.
*/
virtual bool Save( FILE* aFile );
virtual bool Load( char* aLine, wxString& aErrorMsg );
virtual bool Load( LINE_READER& aLineReader, wxString& aErrorMsg );
/**
* Test if the given point is within the bounds of this object.
......@@ -92,12 +123,16 @@ public:
}
/**
* Function GetPenSize
* @return the size of the "pen" that be used to draw or plot this item
*/
virtual int GetPenSize( ) const;
virtual void DisplayInfo( EDA_DRAW_FRAME* aFrame );
/**
* @return the boundary box for this, in schematic coordinates
*/
virtual EDA_RECT GetBoundingBox() const;
void Rotate();
......
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2009 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2011 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 2004 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
* Copyright (C) 2008 Wayne Stambaugh <stambaughw@verizon.net>
* Copyright (C) 1992-2011 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
......@@ -94,7 +94,8 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
PrintMsg( MsgDiag );
if( !reader.ReadLine()
|| strncmp( (char*)reader + 9, SCHEMATIC_HEAD_STRING, sizeof(SCHEMATIC_HEAD_STRING) - 1 ) != 0 )
|| strncmp( (char*)reader + 9, SCHEMATIC_HEAD_STRING,
sizeof( SCHEMATIC_HEAD_STRING ) - 1 ) != 0 )
{
MsgDiag = aFullFileName + _( " is NOT an Eeschema file!" );
DisplayError( this, MsgDiag );
......@@ -104,13 +105,13 @@ bool SCH_EDIT_FRAME::LoadOneEEFile( SCH_SCREEN* aScreen, const wxString& aFullFi
line = reader.Line();
// get the file version here.
char *strversion = line + 9 + sizeof(SCHEMATIC_HEAD_STRING);
char *strversion = line + 9 + sizeof( SCHEMATIC_HEAD_STRING );
// Skip blanks
while( *strversion && *strversion < '0' )
strversion++;
int version = atoi(strversion);
int version = atoi( strversion );
if( version > EESCHEMA_VERSION )
{
......@@ -147,6 +148,7 @@ again." );
item = NULL;
char* sline = line;
while( (*sline != ' ' ) && *sline )
sline++;
......@@ -274,6 +276,7 @@ static void LoadLayers( LINE_READER* aLine )
aLine->ReadLine();
sscanf( *aLine, "%s %d %d", Name, &Number, &g_LayerDescr.CurrentLayer );
if( strcmp( Name, "EELAYER" ) !=0 )
{
/* error : init par default */
......@@ -282,6 +285,7 @@ static void LoadLayers( LINE_READER* aLine )
if( Number <= 0 )
Number = MAX_LAYER;
if( Number > MAX_LAYER )
Number = MAX_LAYER;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment