You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

476 lines
23 KiB

15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. namespace SCH {
  2. /** @mainpage
  3. This file describes the design of a new Distributed Library System for KiCad's
  4. EESCHEMA. Many of the concepts can be adapted with modest modification to PCBNEW
  5. also, in the future.
  6. @author Dick Hollenbeck <dick@softplc.com>
  7. @date October 2010 - January 2011
  8. @section intr_sec Introduction
  9. Schematic <b>parts</b> are frequently needed to complete a circuit design
  10. schematic. Computer data entry of parts can be a rate limiting step in the
  11. design of an overall PCB. Having ready made access to all needed parts in a
  12. design significantly improves the productivity of a circuit designer. Sharing
  13. parts within an organization is one step in the right direction, but there is
  14. opportunity to share across organizational boundaries to improve productivity
  15. even more. Using a part that someone else in another organization has already
  16. entered into the computer can eliminate the first data input process for that
  17. part. The more complicated the part and the board, the larger the positive
  18. impact on productivity because the larger the time savings.
  19. <p> Sharing parts within an organization is best done by directly accessing a
  20. known internal source for those parts, say on a company network. Sharing parts
  21. across organizational boundaries is best done using the Internet in real-time.
  22. Having the ability to search for a part based on arbitrary search criteria can
  23. speed up the pace at which new parts are found and used.
  24. <p> Electronic component manufacturers need and look for ways to differentiate
  25. their products from their competitors. With this Distributed Library System
  26. facility in KiCad, one way for manufacturers to differentiate themselves and
  27. their parts is to publish a part library on the Internet and save their
  28. customers the work of doing the data entry of the part into the KiCad design
  29. system.
  30. <p> Maintaining a comprehensive part library is a fairly labor intensive
  31. activity. New parts come into the market everyday. By being able to publish a
  32. superior library on the Internet, it may be possible to make a for profit
  33. business out of doing this. The KiCad eco-system would benefit should this
  34. happen, and there could even be competition between such businesses. Or there
  35. can be library specializations or niches.
  36. <p> Often a found part is close to what is needed but not exactly what is
  37. needed. This Distributed Library System design incorporates the concept of part
  38. inheritance using a part description language called <b>Sweet</b>. Sweet is
  39. based on s-expression syntax. Inheritance is the ability to incrementally change
  40. an existing part without completely re-designing it. It is sometimes easier to
  41. modify an existing part than it is to create the new part entirely from scratch.
  42. <p> This Distributed Library System design will have the capability to
  43. significantly benefit the KiCad eco-system, and that should mean expanding the
  44. numbers of users and contributors to the project, and hopefully making for a
  45. better KiCad tool-set for all.
  46. @section definitions Definitions
  47. Only new terms or changes in the definition of terms are given here.
  48. <dl>
  49. <dt>S-Expression</dt><dd>This is a syntactical textual envelop in the same vain as
  50. XML. It may be used to express any number of domain specific grammars. It uses
  51. parentheses to indicate the start and end of an element. A domain specific
  52. grammar is a set of rules that dictate what keywords may be used, and in what
  53. context. A grammar also establishes the allowed places and types of constants.
  54. There can be any number of grammars which all use s-expressions to hold the
  55. individual elements within the grammar. A grammar is at a higher level than
  56. s-expressions, in the same way that a sentence will have grammatical rules which
  57. are at a higher level than the rules used to spell words. Technically, grammars
  58. nest within grammars. So once you are inside a grammatical element, it will have
  59. its own set of rules as to which nested elements it may hold, and once you enter
  60. one of those nested elements, then that nested element's grammar pertains,
  61. etc.<p> In the case of the grammar for a part, the grammar itself is being given
  62. the name Sweet. The name does not extend to the grammar for the schematic,
  63. only the part grammar.</dd>
  64. <dt>Schematic</dt><dd>This consists of one or more sheets and will be different
  65. in three ways from existing schematics. <ul>
  66. <li>All sheets will be in one file, thus the entire schematic is in one file.
  67. <li>The schematic file will have its own s-expression grammar.
  68. <li> There will be a <b>parts list</b> within the schematic, and within the
  69. parts list will be <b>all</b> the parts for the schematic. yes <b>all</b> of
  70. them. See class PARTS_LIST.</ul>
  71. Within the sheets of the schematic will be components.</dd>
  72. <dt>Component</dt><dd>A component is an instantiated part. The keyword for
  73. component is (comp). A component does not have any of its own properties other
  74. than: <ul> <li>rerence designator <li>part pointer or reference into the parts
  75. list <li>location <li>rotation <li>stuff i.e. DNS or do stuff the part
  76. <li>visual textual effect overrides </ul> Note that the (comp) may not have any
  77. properties or fields of its own, and that it may not exist without a
  78. corresponding part in the parts_list. A reason for this is to ensure that a
  79. BOM can be made simply from the parts_list.</dd>
  80. <dt>Component, again for good measure.</dt><dd>A component is an instantiation
  81. of a part. A component exists within a schematic which has a parts list
  82. containing the part from which the component is instantiated. A component has a
  83. unique reference designator, part ref, its own location, orientation,
  84. stuff/DNS, and text attributes but <b>not</b> its own text fields/strings (other
  85. than reference designator). The part which is instantiated must exist in the
  86. parts list of the same schematic.</dd>
  87. <dt>Inheritance</dt><dd>Is the ability to mimic form and function from another
  88. entity. In our case we use it only for parts. One part may "inherit from" or
  89. "extend" another single part.</dd>
  90. <dt>Part</dt><dd>A part is a symbolic schematic circuit element found within an
  91. EESCHEMA library (or within a parts list). It is re-usable and may be
  92. instantiated more than once within a schematic. For it to be instantiated, it
  93. must be copied or inherited into the parts list of the instantiating schematic.
  94. If inherited into the parts list, then only a concise reference is needed into
  95. the originating library. If instead it is copied into the parts list, then the
  96. part is fully autonomous and need have no reference to its original copy.</dd>
  97. <dt>Parts List</dt><dd>A parts list, keyword (parts_list), is an entirely new
  98. construct. It exists within a schematic and is the complete set of parts used
  99. within a particular schematic. Each schematic has exactly one parts list
  100. contained within it. A parts list is also a library source and a library sink
  101. for the current schematic. A parts list in any schematic may also be a library
  102. source for any other schematic, but not a library sink. The parts list construct
  103. makes it almost wholly unnecessary to write to other types of library
  104. sinks.</dd>
  105. <dt>Library</dt><dd>A library is no longer a file. It is a memory cache of
  106. parts, consistent with the normal definition of memory cache. Each library is
  107. backed up with a <b>library source</b>. In rare cases, some libraries may also
  108. have a <b>library sink</b>.</dd>
  109. <dt>Library Source</dt><dd>A library source is an abstract read only repository
  110. of parts. The repository itself might exist on the moon. The difference between
  111. a library source and a library sink is that a source is a readable entity.</dd>
  112. <dt>Library Sink</dt><dd>A library sink is an abstract place that parts can be
  113. written to for future reading. The difference between a library source and a
  114. library sink is that a library sink is a writable entity.</dd>
  115. <dt>Symbol</dt><dd>The term "symbol" is not used in a specific way in this
  116. document. There is no symbol in any of the grammars, so use of it on the
  117. developers list will not be understood without explanation. Of course it is
  118. possible to have multiple parts all extend a common base part, and you can think
  119. of the base part as having most if not all the graphical lines for any
  120. derivatives. But we do not need to use the term symbol to describe that
  121. relationship, the term "part" is sufficient.</dd>
  122. <dt>LPID</dt><dd>This stands for "Logical Part ID", and is a reference to any
  123. part within any known library. The term "logical" is used because the contained
  124. library name is logical, not a full library name. The LPID consists of 3 main
  125. portions: logical library name, part name, and revision number.</dd>
  126. <dt>Library Table</dt><dd>This is a lookup table that maps a logical library
  127. name (i.e. a short name) into a fully specified library name and library type.
  128. An applicable library table consists of rows from (at least) two sources:<ol>
  129. <li>A schematic resident library table.
  130. <li>A personal library table.
  131. </ol>
  132. These rows from the two sources are conceptually concatonated (although they may
  133. not be physically concatonated in the implementation, TBD). The schematic
  134. resident rows take presedence over the personal library table if there are
  135. logical library names duplicately defined. (Or we will simply ask that any remote
  136. (i.e. public) libraries use uppercase first letters in logical names, TBD.)
  137. <p> Eventually there will be an external publicly available internet based
  138. logical library table also, but this will need to be glued down at a hard coded
  139. URL that we have control over. The internet based library table allows us to
  140. advertise remote libraries without having to issue an update to KiCad.</dd>
  141. <dt>Query Language</dt><dd>This is a means of searching for something that is
  142. contained within a container. Since some library sources are remote, it is
  143. important to be able to ask the library source for a part that matches some
  144. criteria, for performance reasons.</dd>
  145. </dl>
  146. @section changes Required Changes
  147. In order fulfill the vision embodied by this Distributed Library System design,
  148. it will be necessary to change many APIs and file formats within EESCHEMA. In
  149. fact, the entire schematic file format will be new, based on s-expressions,
  150. the schematic grammar, and the Sweet language for parts.
  151. Here are some of the changes required: <ul>
  152. <li> All sheets which make up a schematic will go into a single s-expression
  153. file. The multiple sheet support will still exist, but all the sheets for a
  154. single schematic are all in a single file.
  155. <li> A "library" is a collection of "parts". The unit of retrieval from a
  156. library is a part as a textual string in the Sweet language. Sweet is a
  157. particular "grammar" expressed in s-expression form, and can be used to fully
  158. describe parts. Because EESCHEMA does not actually see a "library file",
  159. (remember, EESCHEMA can only ask for a part), the actual file format for a
  160. library is no longer pertinent nor visible to the core of EESCHEMA. The unit of
  161. retrieval from the API is the part, so EESCHEMA gets an entire part s-expression
  162. and must then parse it as a RAM resident Sweet string.
  163. <li>EESCHEMA knows of no library files, instead there is a library API which
  164. abstracts the actual part storage strategy used within any library
  165. implementation. The API can be implemented by anyone wanting to provide a
  166. library under a given storage strategy. The API provides a storage strategy
  167. abstraction in classes LIB_SOURCE and LIB_SINK. The actual storage strategy used
  168. in any particular library implementation is not technically part of the
  169. conceptual core of EESCHEMA. This is an important concept to grasp. Eventually
  170. the library implementations may be jetisoned into a plug-in structure, but
  171. initially they are statically linked into EESCHEMA. Should the plug-in strategy
  172. ever get done, the boundary of the plug-in interface will remain the C++ library
  173. API as given here (mostly in class LIB_SOURCE). The only reason to introduce a
  174. plug-in design is to allow proprietary closed source library implementations,
  175. and this could eventually come about if a part vendor wanted to provide one for
  176. the KiCad project. If a Texas Instruments type of company wants to maintain a
  177. KiCad library, we will be positioned to accommodate them. Until then, the
  178. LIB_SOURCE implementations can be statically linked into EESCHEMA and there is
  179. no conceptual disruption either way.
  180. <li> Most library implementations are read only. There are only two library
  181. types that are writable, the "dir" type, and the "parts list". All other types
  182. are read only from the perspective of the API. Stuffing those read only
  183. libraries and maintaining them will be done using the normal update mechanisms
  184. pertinent to the library's respective type of repository. The most common place
  185. to do incremental enhancements to a part before using it is not in the external
  186. library, but now in the parts list with this new design.
  187. <li> The design will support classical clipboard usage. The part in the Sweet
  188. language can be placed onto the clipboard for use by other applications and
  189. instances of EESCHEMA. Eventually larger blocks of components may also be
  190. supported on the clipboard, since the Sweet language allows these blocks to be
  191. descributed textually in a very readable fashion. (Clipboard support beyond part
  192. manipulation is not currently in this revision of the design however, it can be
  193. a future separate enhancement. Perhaps someday complete sheets may be passed
  194. through the clipboard.)
  195. <li> The cumulative set of required changes are significant, and are tantamount
  196. to saying that EESCHEMA will need its part handling foundations re-written. A
  197. conversion program will convert everything over to the new architecture. The
  198. conversion program can simplify things by simply putting all schematic parts
  199. into a parts list within each schematic.
  200. <li> An Internet connection is required to use some of the library sources. It
  201. will be possible to omit these library sources and run KiCad by doing a
  202. configuration change. Eventually, some library sources will spring up and will
  203. not technically be part of the KiCad project, so they will remain remote, but
  204. fully usable to those with an internet connection and permission from the
  205. library source's owner.
  206. <li>By far, even as radical as the distributed library concept is, complete with
  207. remote access, the most significant conceptual change is the introduction of the
  208. <b>parts list</b>. This is a special library that exists in a schematic, and is
  209. the complete record of all parts used within that same schematic. It is
  210. impossible to put a component into a schematic without that component's part
  211. first existing within the parts list of that schematic.
  212. <li> Because of inheritance, multi-body-form parts, alternate body styles, see
  213. also references, and other needs, it is necessary to have a <b>part reference
  214. mechanism</b>. A component has to reference a part, the one it "is". A part has
  215. to be able to reference another part, either in the same library or elsewhere.
  216. Enter the Logical Part ID, or LPID to serve this need. An LPID consists of a
  217. logical library name, a part name, and an optional revision. It is used to
  218. reference parts, from anywhere. If the reference is from a sheet's component,
  219. then the logical library name of the LPID is not needed. Why? Well if you've
  220. been paying attention you know. A comp can only be based on a part that exists
  221. within the parts_list of the same schematic in which it resides. Likewise, a
  222. part within any library that references another part in that <b>same</b> library
  223. will also omit the logical library name from the LPID, and it must omit it. Why?
  224. Well because it makes renaming the library easier, for one. Two, the logical
  225. library name is only a lookup key into a "library table". The library table maps
  226. the logical library name into an actual library source [and sink, iff writable].
  227. See LIB_SOURCE and LIB_SINK.
  228. <p> In the case of the component referencing the part that it "is", there is no
  229. revision number allowed in the LPID. This is because that reference is to the
  230. part in the parts list, and the parts list only holds a single revision of any
  231. part (where "revision" is what you understand from version control systems).
  232. <li> There needs to be a new query language designed and each library source
  233. needs to support it. See LIB_SOURCE::FindParts() for a brief description of one.
  234. </ul>
  235. @section philosophy Design Philosophies
  236. <p> Class names are chosen to be as concise as possible. Separate namespaces can be
  237. used should these same class names be needed in both EESCHEMA and PCBNEW (later).
  238. However, this design does not yet address PCBNEW. Suggested namespaces are
  239. SCH for EESCHEMA, and PCB for PCBNEW.
  240. <p> Since most if not all the APIs deal with file or non-volatile storage, only
  241. 8 bit string types are used. For international strings, UTF-8 is used, and
  242. that is what is currently in use within the KiCad file storage formats.
  243. <p> The typedef <b>STRINGS</b> is used frequently as a holder for multiple
  244. std::strings. After some research, I chose std::dequeue<STRING> to hold a list of
  245. STRINGs. I thought it best when considering overall speed, memory
  246. fragmentation, memory efficiency, and speed of insertion and expansion.
  247. <p> A part description language is introduced called <b>(Sweet)</b>. It supports
  248. inheritance and its syntax is based on s-expressions.
  249. <p> Since a part can be based on another part using inheritance, it is important
  250. to understand the idea of library dependencies. A part in one library can be
  251. dependent on another part in another library, or on another part in the same
  252. library as itself. There are several library sources, some far away and some
  253. very close to the schematic. The closest library to the schematic is the
  254. <b>(parts list)</b> class PARTS_LIST. Circular dependencies are not allowed. All
  255. dependencies must be resolvable in a straight forward way. This means that a
  256. part in a remote library cannot be dependent on any part which is not always
  257. resolvable.
  258. <p> NRVO described:
  259. http://msdn.microsoft.com/en-us/library/ms364057%28VS.80%29.aspx
  260. Even with NRVO provided by most C++ compilers, I don't see it being as lean as
  261. having class LIB keep expanded members STRING fetch and STRINGS vfetch for the
  262. aResults values. But at the topmost API, client convenience is worth a minor
  263. sacrifice in speed, so the topmost API does return these complex string objects
  264. for convenience. So there is a different strategy underneath the hood than what
  265. is used on the hood ornament. When aResults pointer is passed as an argument, I
  266. won't refer to this as 'returning' a value, but rather 'fetching' a result to
  267. distinguish between the two strategies.
  268. <p> Functions named as lookupSomething() or LookupSomething() are to be understood
  269. as "find and load if needed". This is different than a simple find operation only, in
  270. that an implied load operation is also done, but only if needed.
  271. @section architecture Architecture
  272. This document set later shows some <b>library sources</b> derived from class
  273. LIB_SOURCE. A library source is the backing to a library. The class name for a
  274. library in the new design is LIB.
  275. <p>
  276. <IMG SRC="../drawing.png" ALT="You should see design architecture here">
  277. */
  278. /**
  279. * @defgroup string_types STRING Types
  280. * Provide some string types for use within the API.
  281. */
  282. /**
  283. * @defgroup exception_types Exception Types
  284. * Provide some exception types for use within the API.
  285. */
  286. /**
  287. * Class HTTP_LIB_SOURCE
  288. * implements a LIB_SOURCE to access a remote document root repository using http protocol.
  289. */
  290. class HTTP_LIB_SOURCE : public LIB_SOURCE
  291. {
  292. friend class LIB_TABLE; ///< constructor the LIB uses these functions.
  293. protected:
  294. /**
  295. * Constructor ( const STRING& aHttpURL )
  296. * sets up a LIB_SOURCE using aHttpURI which points to a subversion
  297. * repository.
  298. * @see LIB_TABLE::LookupPart()
  299. *
  300. * @param aHttpURL is a full URL of a document root repo directory. Example might
  301. * be "http://kicad.org/libs"
  302. *
  303. * @param aOptions is the options string from the library table. It can be any
  304. * string that the LIB_SOURCE can parse and understand, perhaps using comma separation
  305. * between options. Options and their syntax is LIB_SOURCE implementation specific.
  306. */
  307. HTTP_LIB_SOURCE( const STRING& aHttpURL, const STRING& aOptions ) throws( IO_ERROR );
  308. };
  309. /**
  310. * Class SVN_LIB_SOURCE
  311. * implements a LIB_SOURCE to access a [remote or local] subversion repository
  312. * using subversion client protocol.
  313. */
  314. class SVN_LIB_SOURCE : public LIB_SOURCE
  315. {
  316. friend class LIB_TABLE; ///< constructor the LIB uses these functions.
  317. protected:
  318. /**
  319. * Constructor SVN_LIB_SOURCE( const STRING& aSvnURL )
  320. * sets up a LIB_SOURCE using aSvnURI which points to a subversion
  321. * repository.
  322. * @see LIB_TABLE::LookupPart().
  323. *
  324. * @param aSvnURL is a full URL of a subversion repo directory. Example might
  325. * be "svn://kicad.org/repos/library/trunk"
  326. *
  327. * @param aOptions is the options string from the library table. It can be any
  328. * string that the LIB_SOURCE can parse and understand, perhaps using comma separation
  329. * between options. Options and their syntax is LIB_SOURCE implementation specific.
  330. */
  331. SVN_LIB_SOURCE( const STRING& aSvnURL, const STRING& aOptions ) throws( IO_ERROR );
  332. };
  333. /**
  334. * Class SCHEMATIC_LIB_SOURCE
  335. * implements a LIB_SOURCE in by reading a parts list from schematic file
  336. * unrelated to the schematic currently being edited.
  337. */
  338. class SCHEMATIC_LIB_SOURCE : public LIB_SOURCE
  339. {
  340. friend class LIB_TABLE; ///< constructor the LIB uses these functions.
  341. protected:
  342. /**
  343. * Constructor SCHEMATIC_LIB_SOURCE( const STRING& aSchematicFile )
  344. * sets up a LIB_SOURCE using aSchematicFile which is a full path and filename
  345. * for a schematic not related to the schematic being editing in
  346. * this EESCHEMA session.
  347. * @see LIB_TABLE::LookupPart().
  348. *
  349. * @param aSchematicFile is a full path and filename. Example:
  350. * "/home/user/kicadproject/design.sch"
  351. *
  352. * @param aOptions is the options string from the library table. It can be any
  353. * string that the LIB_SOURCE can parse and understand, perhaps using comma separation
  354. * between options. Options and their syntax is LIB_SOURCE implementation specific.
  355. */
  356. SCHEMATIC_LIB_SOURCE( const STRING& aSchematicFile, const STRING& aOptions ) throws( IO_ERROR );
  357. };
  358. /**
  359. * Class PARTS_LIST
  360. * is a LIB which resides in a SCHEMATIC, and it is a table model for a
  361. * spread sheet both. When columns are added or removed to/from the spreadsheet,
  362. * this is adding or removing fields/properties to/from ALL the contained PARTS.
  363. */
  364. class PARTS_LIST : public LIB
  365. {
  366. public:
  367. /**
  368. * Function GetModel
  369. * returns a spreadsheet table model that allows both reading and writing to
  370. * rows in a spreadsheet. The UI holds the actual screen widgets, but
  371. * this is the table model, i.e. the PARTS_LIST is.
  372. */
  373. SPREADSHEET_TABLE_MODEL* GetModel();
  374. };
  375. } // namespace SCH
  376. /// @todo remove endsWithRev() in favor of EndsWithRev(), find home for it.
  377. /// @todo add simple unit test infrastructure.
  378. /// @todo review: http://www.sfml-dev.org/tutorials/1.2/graphics-wxwidgets.php
  379. // EOF