2010-12-27 16:49:39 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KICAD, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SCH_PART_H_
|
|
|
|
#define SCH_PART_H_
|
|
|
|
|
|
|
|
#include <sch_lib.h>
|
|
|
|
|
2010-12-30 01:47:14 +00:00
|
|
|
class SWEET_LEXER;
|
2011-01-01 22:56:43 +00:00
|
|
|
class PART_PARSER;
|
|
|
|
|
2010-12-27 16:49:39 +00:00
|
|
|
|
|
|
|
namespace SCH {
|
|
|
|
|
2011-01-01 22:56:43 +00:00
|
|
|
class LPID;
|
|
|
|
|
2010-12-30 01:47:14 +00:00
|
|
|
/**
|
|
|
|
* Enum PartBit
|
|
|
|
* is a set of bit positions that can be used to create flag bits within
|
|
|
|
* PART::contains to indicate what state the PART is in and what it contains, i.e.
|
|
|
|
* whether the PART has been parsed, and what the PART contains, categorically.
|
|
|
|
*/
|
|
|
|
enum PartBit
|
|
|
|
{
|
|
|
|
PARSED, ///< have parsed this part already, otherwise 'body' text must be parsed
|
2011-01-03 17:47:08 +00:00
|
|
|
EXTENDS, ///< saw "extends" keyword, inheriting from another PART
|
2011-01-01 22:56:43 +00:00
|
|
|
VALUE,
|
|
|
|
ANCHOR,
|
|
|
|
REFERENCE,
|
|
|
|
FOOTPRINT,
|
|
|
|
DATASHEET,
|
|
|
|
MODEL,
|
|
|
|
KEYWORDS,
|
2010-12-30 01:47:14 +00:00
|
|
|
};
|
|
|
|
|
2011-01-03 17:47:08 +00:00
|
|
|
|
2010-12-30 01:47:14 +00:00
|
|
|
/// Function PB
|
|
|
|
/// is a PartBit shifter for PART::contains field.
|
|
|
|
static inline const int PB( PartBit oneBitOnly )
|
|
|
|
{
|
|
|
|
return ( 1 << oneBitOnly );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-27 16:49:39 +00:00
|
|
|
/**
|
|
|
|
* Class PART
|
|
|
|
* will have to be unified with what Wayne is doing. I want a separate copy
|
|
|
|
|
|
|
|
* here until I can get the state management correct. Since a PART only lives
|
|
|
|
* within a cache called a LIB, its constructor is private (only a LIB
|
|
|
|
* can instantiate one), and it exists in various states of freshness and
|
|
|
|
* completeness relative to the LIB_SOURCE within the LIB.
|
|
|
|
*/
|
|
|
|
class PART
|
|
|
|
{
|
2011-01-01 22:56:43 +00:00
|
|
|
friend class LIB; // is the owner of all PARTS, afterall
|
|
|
|
friend class ::PART_PARSER;
|
2010-12-27 16:49:39 +00:00
|
|
|
|
|
|
|
protected: // not likely to have C++ descendants, but protected none-the-less.
|
|
|
|
|
2011-01-01 22:56:43 +00:00
|
|
|
/// a protected constructor, only a LIB can instantiate a PART.
|
2011-01-03 17:47:08 +00:00
|
|
|
PART( LIB* aOwner, const STRING& aPartNameAndRev );
|
2011-01-01 22:56:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function inherit
|
|
|
|
* is a specialized assignment function that copies a specific subset, enough
|
|
|
|
* to fulfill the requirements of the Sweet s-expression language.
|
|
|
|
*/
|
|
|
|
void inherit( const PART& aBasePart );
|
|
|
|
|
|
|
|
|
|
|
|
//PART( LIB* aOwner );
|
|
|
|
|
2010-12-27 16:49:39 +00:00
|
|
|
LIB* owner; ///< which LIB am I a part of (pun if you want)
|
2010-12-30 01:47:14 +00:00
|
|
|
int contains; ///< has bits from Enum PartParts
|
|
|
|
|
2011-01-03 17:47:08 +00:00
|
|
|
STRING partNameAndRev; ///< example "passives/R[/revN..]", immutable.
|
2010-12-27 16:49:39 +00:00
|
|
|
|
2011-01-01 22:56:43 +00:00
|
|
|
LPID* extends; ///< of base part, NULL if none, otherwise I own it.
|
2011-01-03 17:47:08 +00:00
|
|
|
PART* base; ///< which PART am I extending, if any. no ownership.
|
2011-01-01 22:56:43 +00:00
|
|
|
|
|
|
|
/// encapsulate the old version deletion, take ownership of @a aLPID
|
|
|
|
void setExtends( LPID* aLPID );
|
|
|
|
|
2010-12-27 16:49:39 +00:00
|
|
|
/// s-expression text for the part, initially empty, and read in as this part
|
|
|
|
/// actually becomes cached in RAM.
|
|
|
|
STRING body;
|
|
|
|
|
2011-01-03 17:47:08 +00:00
|
|
|
// bool cachedRevisions; ///< allows lazy loading of revision of this same part name
|
2011-01-01 22:56:43 +00:00
|
|
|
|
2010-12-27 16:49:39 +00:00
|
|
|
// 3 separate lists for speed:
|
|
|
|
|
|
|
|
/// A property list.
|
|
|
|
//PROPERTIES properties;
|
|
|
|
|
|
|
|
/// A drawing list for graphics
|
|
|
|
//DRAWINGS drawings;
|
|
|
|
|
|
|
|
/// A pin list
|
|
|
|
//PINS pins;
|
|
|
|
|
|
|
|
/// Alternate body forms.
|
|
|
|
//ALTERNATES alternates;
|
|
|
|
|
2011-01-01 22:56:43 +00:00
|
|
|
// lots of other stuff, like the mandatory properties, but no units, since we went with dimensionless
|
2010-12-27 16:49:39 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2011-01-01 22:56:43 +00:00
|
|
|
~PART();
|
|
|
|
|
|
|
|
PART& operator=( const PART& other );
|
2010-12-27 16:49:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Owner
|
|
|
|
* returns the LIB* owner of this part.
|
|
|
|
*/
|
|
|
|
LIB* Owner() { return owner; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function Parse
|
2010-12-30 01:47:14 +00:00
|
|
|
* translates a Sweet string into a binary form that is represented
|
2010-12-27 16:49:39 +00:00
|
|
|
* by the normal fields of this class. Parse is expected to call Inherit()
|
|
|
|
* if this part extends any other.
|
2010-12-30 01:47:14 +00:00
|
|
|
*
|
|
|
|
* @param aLexer is an instance of SWEET_LEXER, rewound at the first line.
|
|
|
|
*
|
2011-01-04 18:53:11 +00:00
|
|
|
* @param aLibTable is the LIB_TABLE "view" that is in effect for inheritance,
|
2010-12-30 01:47:14 +00:00
|
|
|
* and comes from the big containing SCHEMATIC object.
|
2010-12-27 16:49:39 +00:00
|
|
|
*/
|
2011-01-04 18:53:11 +00:00
|
|
|
void Parse( SWEET_LEXER* aLexer, LIB_TABLE* aLibTable ) throw( IO_ERROR );
|
2010-12-27 16:49:39 +00:00
|
|
|
|
2010-12-30 01:47:14 +00:00
|
|
|
/*
|
|
|
|
void SetBody( const STR_UTF& aSExpression )
|
|
|
|
{
|
|
|
|
body = aSExpression;
|
|
|
|
}
|
|
|
|
*/
|
2010-12-27 16:49:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace PART
|
|
|
|
|
|
|
|
#endif // SCH_PART_
|