├── boms_away ├── __init__.py ├── export_plugins │ ├── __init__.py │ ├── _export_base.py │ ├── csv_comma.py │ ├── lcsc.py │ └── quoted_tab_csv.py ├── plugin_loader.py ├── datastore.py ├── kicad_helpers.py └── sch.py ├── .gitignore ├── component_sel.png ├── dup_screenshot.png ├── wrapper.sh ├── Pipfile ├── README.md ├── bomsaway.py └── LICENSE /boms_away/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /.DS_Store 2 | *.pyc 3 | -------------------------------------------------------------------------------- /boms_away/export_plugins/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /component_sel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeff-Ciesielski/Boms-Away/HEAD/component_sel.png -------------------------------------------------------------------------------- /dup_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Jeff-Ciesielski/Boms-Away/HEAD/dup_screenshot.png -------------------------------------------------------------------------------- /wrapper.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Use pyenv provided framework version of python instead of pipenv (virtualenv) copy. 4 | PYTHON=$(pyenv which python) 5 | export PYTHONHOME=$(pipenv --venv) 6 | exec $PYTHON $1 7 | -------------------------------------------------------------------------------- /Pipfile: -------------------------------------------------------------------------------- 1 | [[source]] 2 | url = "https://pypi.org/simple" 3 | verify_ssl = true 4 | name = "pypi" 5 | 6 | [packages] 7 | sqlalchemy = "*" 8 | wxPython = "*" 9 | 10 | [dev-packages] 11 | 12 | [requires] 13 | python_version = "2.7" 14 | -------------------------------------------------------------------------------- /boms_away/export_plugins/_export_base.py: -------------------------------------------------------------------------------- 1 | class BomsAwayExporter: 2 | def __init__(self): 3 | pass 4 | 5 | def validate(self): 6 | classname = self.__class__.__name__ 7 | print("Validating: ", classname) 8 | try: 9 | self.extension 10 | self.wildcard 11 | self.export 12 | return True 13 | except AttributeError as e: 14 | print("{} is invalid: {}".format(classname, str(e))) 15 | -------------------------------------------------------------------------------- /boms_away/export_plugins/csv_comma.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | from . import _export_base 4 | 5 | class CsvExport(_export_base.BomsAwayExporter): 6 | extension = 'csv' 7 | wildcard = 'CSV Files (*.csv)|*.csv' 8 | 9 | def export(self, base_filename, components): 10 | file_path = '{}.{}'.format(base_filename, self.extension) 11 | 12 | with open(file_path, 'w') as csvfile: 13 | wrt = csv.writer(csvfile) 14 | 15 | wrt.writerow(['Refs', 'Value', 'Footprint', 16 | 'Quantity', 'MFR', 'MPN', 'SPR', 'SPN']) 17 | 18 | for fp in sorted(components): 19 | for val in sorted(components[fp]): 20 | ctcont = components[fp][val] 21 | wrt.writerow([ 22 | ctcont.refs, 23 | ctcont.value, 24 | ctcont.footprint, 25 | len(ctcont), 26 | ctcont.manufacturer, 27 | ctcont.manufacturer_pn, 28 | ctcont.supplier, 29 | ctcont.supplier_pn, 30 | ]) 31 | -------------------------------------------------------------------------------- /boms_away/export_plugins/lcsc.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | from . import _export_base 4 | 5 | class LCSCExport(_export_base.BomsAwayExporter): 6 | extension = 'csv' 7 | wildcard = 'lcsc.com CSV (*.csv)|*.csv' 8 | 9 | def export(self, base_filename, components): 10 | file_path = '{}.{}'.format(base_filename, self.extension) 11 | 12 | with open(file_path, 'w') as csvfile: 13 | wrt = csv.writer(csvfile) 14 | 15 | wrt.writerow(['Quantity','Value', 'Refs', 'Footprint', 16 | 'Manufacturer','Manufacture Part Number', 17 | 'LCSC Part Number']) 18 | 19 | for fp in sorted(components): 20 | for val in sorted(components[fp]): 21 | ctcont = components[fp][val] 22 | wrt.writerow([ 23 | len(ctcont), 24 | ctcont.value, 25 | ctcont.refs, 26 | ctcont.footprint, 27 | ctcont.manufacturer, 28 | ctcont.manufacturer_pn, 29 | ctcont.supplier_pn, 30 | ]) 31 | -------------------------------------------------------------------------------- /boms_away/plugin_loader.py: -------------------------------------------------------------------------------- 1 | import pkgutil 2 | import importlib 3 | import inspect 4 | 5 | from . import export_plugins 6 | 7 | def load_export_plugins(): 8 | """ Loads all export plugins stored in boms_away/export_plugins which 9 | adhere to the following rules: 10 | 11 | * Must be a base class of BomsAwayExporter 12 | * Must expose an 'export' function 13 | * Must have class variables: extension, wildcard 14 | """ 15 | results = [] 16 | for loader, name, is_pkg in pkgutil.walk_packages(export_plugins.__path__): 17 | # Skip private modules (i.e. base classes) 18 | if name.startswith('_'): 19 | continue 20 | full_name = export_plugins.__name__ + '.' + name 21 | mod = importlib.import_module(full_name) 22 | for obj_name in dir(mod): 23 | obj = getattr(mod, obj_name) 24 | if not inspect.isclass(obj): 25 | continue 26 | baseclass = obj.__bases__[0] 27 | 28 | if not baseclass.__name__ == 'BomsAwayExporter': 29 | continue 30 | 31 | if not obj().validate(): 32 | continue 33 | 34 | results.append(obj) 35 | 36 | return results 37 | -------------------------------------------------------------------------------- /boms_away/export_plugins/quoted_tab_csv.py: -------------------------------------------------------------------------------- 1 | import csv 2 | 3 | from . import _export_base 4 | 5 | class QuotedTabExport(_export_base.BomsAwayExporter): 6 | extension = 'csv' 7 | wildcard = 'Quoted, tab delimited CSV (*.csv)|*.csv' 8 | 9 | def export(self, base_filename, components): 10 | file_path = '{}.{}'.format(base_filename, self.extension) 11 | 12 | with open(file_path, 'w') as csvfile: 13 | wrt = csv.writer(csvfile, dialect='excel-tab') 14 | 15 | wrt.writerow(['Refs', 'Value', 'Footprint', 16 | 'Quantity', 'MFR', 'MPN', 'SPR', 'SPN']) 17 | 18 | for fp in sorted(components): 19 | for val in sorted(components[fp]): 20 | ctcont = components[fp][val] 21 | commarefs = ctcont.refs.replace(';', ',') 22 | wrt.writerow([ 23 | '"{}"'.format(commarefs), 24 | '"{}"'.format(ctcont.value), 25 | '"{}"'.format(ctcont.footprint), 26 | '"{}"'.format(len(ctcont)), 27 | '"{}"'.format(ctcont.manufacturer), 28 | '"{}"'.format(ctcont.manufacturer_pn), 29 | '"{}"'.format(ctcont.supplier), 30 | '"{}"'.format(ctcont.supplier_pn), 31 | ]) 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BOMs Away! - BOM/Component manager for KiCad 2 | 3 | 4 | IMO, KiCad is one of the best EDA tools out there, with just one major 5 | problem: Bill of Materials management is rough. If you make more than 6 | 1 board a year, you probably know how frustrating it can be to get 7 | everything together for an order. There are multiple ways to export a 8 | BOM (each with their own ups and downs), and the process of selecting 9 | and entering components is excruciatingly manual. 10 | 11 | You can of course create custom components on a per MPN basis, but 12 | this can be time consuming and forces you to maintain a large number 13 | of individual component libraries. 14 | 15 | The goal of this app is to ease the bom management burden on designers 16 | who choose to use Kicad for their layout and schematic capture needs, 17 | allowing for faster, easier data entry, and to provide a part database 18 | for re-use in future designs. 19 | 20 | ## Installation 21 | 22 | With [pyenv](https://github.com/pyenv/pyenv) and [pipenv](https://pipenv.readthedocs.io/en/latest/) installed, cd into the cloned directory and run: 23 | 24 | ``` 25 | PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install . 26 | pipenv install 27 | ``` 28 | 29 | Then run the app with: `./wrapper.sh bomsaway.py` 30 | 31 | ## Requirements 32 | 33 | * python 2.7 34 | * sqlalchemy 35 | * wxPython (pip install should work on most platforms, otherwise, see [wxPython.org](http://wxpython.org/download.php) 36 | 37 | Deprecated: 38 | * [kivy](https://kivy.org) >= 1.9.0 39 | * kivy garden 40 | * navigationdrawer `garden install navigationdrawer` 41 | 42 | ## Features 43 | 44 | ### Self-curated component database 45 | 46 | Simply enter a part's manufacturer, 47 | supplier, manufacturer PN, and supplier PN then click 'save to 48 | datastore'. Information is keyed off of component value and 49 | footprint, so future uses can simply use the part lookup button to 50 | retrieve the information. Multiple suppliers, manufacturers, and 51 | part numbers are supported. 52 | 53 | ### Like-Part consolidation 54 | 55 | Everybody miskeys from time to time, this feature detects (to the best 56 | of its ability) components that are the same, but simply have 57 | mislabeled values. For example: (10K, 10k, 10 K) will be consolidated 58 | into a single value selectable by the user. 59 | 60 | `*Only components that share a footprint are consolidated.` 61 | 62 | ### CSV Bom Export 63 | 64 | Exports PCBNew style component agregate BOMs as CSV. Suitable for 65 | upload to digikey/mouser/octopart/etc 66 | 67 | ### KiCad Backpropagation 68 | 69 | All changes can be saved back to KiCad Schematics 70 | 71 | 72 | ## Screenshots 73 | ![Component Selection](component_sel.png) 74 | 75 | ![Duplicate Component Resolution](dup_screenshot.png) 76 | 77 | ## Notes 78 | 79 | ### This tool is opinionated! 80 | 81 | The tool has to store its information somewhere, so it uses kicad's 82 | custom component fields. Currently, the fields SPN, MPN, SPR, and MFR 83 | are reserved for use. If these fields do not exist, they will be 84 | automatically added to each component as it is accessed. The tool does 85 | not attempt to do any import or translation of other existing fields 86 | (field remapping could be added in a future update). 87 | 88 | ### Schematic saves are not automatic! 89 | 90 | If you would like data propegated back to your kicad schematic, please 91 | select `Save Schematic` from the menu. 92 | 93 | ## Changes 94 | 95 | ### 8/12/16 96 | 97 | * Properly handle multi-unit components. Now components with multiple 98 | 'units' (i.e. a quad op-amp in a single package, with 4 schematic 99 | symbols) will show as a single line-item. 100 | * If no extension is provided on a bom export, a .csv will be 101 | automatically appended to the exported file 102 | 103 | ### 8/11/16 104 | 105 | * Removed old Kivy based version 106 | * Moved datastore/config location to ~/.bomsaway.d (Note: Existing 107 | databases will be automatically migrated) 108 | * Added Recent File Functionality 109 | * Misc bugfixes 110 | 111 | ## TODO 112 | 113 | * Semantic versioning + About page 114 | * Fix outstanding todo items in source 115 | * Add Unit tests 116 | * User Guide 117 | * Clean up user screens 118 | 119 | ## Planned Features 120 | 121 | ### Multi-supplier BOM export 122 | 123 | Allow exporting of _bom.csv on a per vendor basis to allow 124 | ease of uploading/ordering 125 | 126 | ### Octopart integration 127 | 128 | Enable part price lookups and stock amount checking 129 | 130 | ### Bom Price Breakdown View (after octopart) 131 | 132 | View overall prices / quantity ordered 133 | 134 | 135 | ## Feature wishlist 136 | 137 | * Part inventory accounting 138 | * Better UX :) 139 | 140 | ## License 141 | 142 | GPLv3, see LICENSE for details. 143 | 144 | This project uses sch.py from 145 | [kicad library utils](https://github.com/KiCad/kicad-library-utils) 146 | (also GPLv3) 147 | 148 | 149 | ## Contributing 150 | 151 | Contributions welcome (and wanted!), please send a PR. 152 | -------------------------------------------------------------------------------- /boms_away/datastore.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from sqlalchemy import Column, ForeignKey, Integer, String 4 | from sqlalchemy.ext.declarative import declarative_base 5 | from sqlalchemy.orm import relationship 6 | from sqlalchemy import create_engine 7 | from sqlalchemy.orm import sessionmaker 8 | 9 | Base = declarative_base() 10 | 11 | 12 | class ComponentValue(Base): 13 | __tablename__ = 'component_value' 14 | id = Column(Integer, primary_key=True) 15 | value = Column(String(64), nullable=False) 16 | unique_parts = relationship('UniquePart', backref='ComponentValue', lazy='dynamic') 17 | 18 | 19 | class Footprint(Base): 20 | __tablename__ = 'footprint' 21 | id = Column(Integer, primary_key=True) 22 | name = Column(String(64), nullable=False) 23 | unique_parts = relationship('UniquePart', backref='Footprint', lazy='dynamic') 24 | 25 | 26 | class Datasheet(Base): 27 | __tablename__ = 'datasheet' 28 | id = Column(Integer, primary_key=True) 29 | url = Column(String(256), nullable=False) 30 | 31 | class UniquePart(Base): 32 | __tablename__ = 'unique_part' 33 | id = Column(Integer, primary_key=True) 34 | component_value_id = Column(Integer, ForeignKey('component_value.id')) 35 | component_value = relationship('ComponentValue') 36 | footprint_id = Column(Integer, ForeignKey('footprint.id')) 37 | footprint = relationship('Footprint') 38 | manufacturer_pns = relationship('ManufacturerPart', backref='UniquePart', lazy='dynamic') 39 | 40 | 41 | class Manufacturer(Base): 42 | __tablename__ = 'manufacturer' 43 | id = Column(Integer, primary_key=True) 44 | name = Column(String(64), nullable=False) 45 | website = Column(String(128), nullable=True) 46 | parts = relationship('ManufacturerPart') 47 | 48 | 49 | class Supplier(Base): 50 | __tablename__ = 'supplier' 51 | id = Column(Integer, primary_key=True) 52 | name = Column(String(64), nullable=False) 53 | website = Column(String(128), nullable=True) 54 | parts = relationship('SupplierPart') 55 | 56 | 57 | class ManufacturerPart(Base): 58 | __tablename__ = 'manufacturer_part' 59 | id = Column(Integer, primary_key=True) 60 | pn = Column(String(64), nullable=False) 61 | manufacturer_id = Column(Integer, ForeignKey('manufacturer.id')) 62 | manufacturer = relationship('Manufacturer') 63 | unique_part_id = Column(Integer, ForeignKey('unique_part.id')) 64 | unique_part = relationship('UniquePart') 65 | supplier_parts = relationship('SupplierPart') 66 | 67 | class SupplierPart(Base): 68 | __tablename__ = 'supplier_part' 69 | id = Column(Integer, primary_key=True) 70 | pn = Column(String(64), nullable=False) 71 | url = Column(String(1024), nullable=True) 72 | supplier_id = Column(Integer, ForeignKey('supplier.id')) 73 | supplier = relationship('Supplier') 74 | manufacturer_part_id = Column(Integer, ForeignKey('manufacturer_part.id')) 75 | manufacturer_part = relationship('ManufacturerPart') 76 | 77 | 78 | class Datastore(object): 79 | def __init__(self, datastore_path): 80 | self._initialized = False 81 | self._eng = None 82 | 83 | self._eng = create_engine('sqlite:///{}'.format(datastore_path)) 84 | Base.metadata.create_all(self._eng) 85 | self._initialized = True 86 | 87 | def _new_session(self): 88 | if not self._initialized: 89 | raise Exception("Datastore is not initialized!") 90 | 91 | db_session = sessionmaker() 92 | db_session.configure(bind=self._eng) 93 | 94 | return db_session() 95 | 96 | def lookup(self, ct): 97 | 98 | session = self._new_session() 99 | 100 | val = ( 101 | session.query(ComponentValue) 102 | .filter(ComponentValue.value == ct.value) 103 | ).first() 104 | 105 | fp = ( 106 | session.query(Footprint) 107 | .filter(Footprint.name == ct.footprint) 108 | ).first() 109 | 110 | if not val or not fp: 111 | return None 112 | 113 | up = ( 114 | session.query(UniquePart) 115 | .filter(UniquePart.component_value == val, 116 | UniquePart.footprint == fp) 117 | ).first() 118 | 119 | return up 120 | 121 | def update(self, ct): 122 | 123 | # TODO: Implement get_or_create, this shit is bananas 124 | # TODO: Clean up validation 125 | # Check and update each field 126 | 127 | session = self._new_session() 128 | 129 | val = ( 130 | session.query(ComponentValue) 131 | .filter(ComponentValue.value == ct.value) 132 | ).first() 133 | 134 | fp = ( 135 | session.query(Footprint) 136 | .filter(Footprint.name == ct.footprint) 137 | ).first() 138 | 139 | ds = ( 140 | session.query(Datasheet) 141 | .filter(Datasheet.url == ct.datasheet) 142 | ).first() 143 | 144 | mfr = ( 145 | session.query(Manufacturer) 146 | .filter(Manufacturer.name == ct.manufacturer) 147 | ).first() 148 | 149 | mpn = ( 150 | session.query(ManufacturerPart) 151 | .filter(ManufacturerPart.pn == ct.manufacturer_pn) 152 | ).first() 153 | 154 | spr = ( 155 | session.query(Supplier) 156 | .filter(Supplier.name == ct.supplier) 157 | ).first() 158 | 159 | spn = ( 160 | session.query(SupplierPart) 161 | .filter(SupplierPart.pn == ct.supplier_pn) 162 | ).first() 163 | 164 | if not val and len(ct.value.strip()): 165 | val = ComponentValue(value=ct.value) 166 | session.add(val) 167 | 168 | if not fp and len(ct.footprint.strip()): 169 | fp = Footprint(name=ct.footprint) 170 | session.add(fp) 171 | 172 | if not ds and len(ct.datasheet.strip()): 173 | ds = Datasheet(url=ct.datasheet) 174 | session.add(ds) 175 | 176 | if not mfr and len(ct.manufacturer.strip()): 177 | mfr = Manufacturer(name=ct.manufacturer) 178 | session.add(mfr) 179 | 180 | if not mpn and len(ct.manufacturer_pn.strip()): 181 | mpn = ManufacturerPart(pn=ct.manufacturer_pn) 182 | session.add(mpn) 183 | 184 | if not spr and len(ct.supplier.strip()): 185 | spr = Supplier(name=ct.supplier) 186 | session.add(spr) 187 | 188 | if not spn and len(ct.supplier_pn.strip()): 189 | spn = SupplierPart(pn=ct.supplier_pn, url=ct.supplier_url) 190 | session.add(spn) 191 | 192 | # draw up associations 193 | if spr and spn and not spn.supplier: 194 | spn.supplier = spr 195 | 196 | if mfr and mpn and not mpn.manufacturer: 197 | mpn.manufacturer = mfr 198 | 199 | if mpn and spn: 200 | spn.manufacturer_part = mpn 201 | 202 | if val and fp: 203 | # check to see if there is a unique part listing 204 | up = ( 205 | session.query(UniquePart) 206 | .filter(UniquePart.component_value == val, 207 | UniquePart.footprint == fp) 208 | ).first() 209 | 210 | if not up: 211 | up = UniquePart(component_value=val, 212 | footprint=fp) 213 | session.add(up) 214 | 215 | if mpn: 216 | mpn.unique_part = up 217 | 218 | session.commit() 219 | 220 | def test_creation(): 221 | eng = create_engine('sqlite://') 222 | Base.metadata.create_all(eng) 223 | 224 | if __name__ == '__main__': 225 | test_creation() 226 | -------------------------------------------------------------------------------- /boms_away/kicad_helpers.py: -------------------------------------------------------------------------------- 1 | from . import sch 2 | import os 3 | 4 | 5 | def sanitized(f): 6 | """ 7 | Removes newlines/tabs/carriage/returns to prevent breakages in schematics 8 | 9 | Returns: Sanitized string 10 | """ 11 | 12 | for v in ['\n', '\r', '\t']: 13 | f = f.replace(v, '') 14 | 15 | return f 16 | 17 | 18 | # TODO: Enumerate field values 19 | class ComponentWrapper(object): 20 | 21 | _builtin_field_map = { 22 | 'reference': '0', 23 | 'value': '1', 24 | 'footprint': '2', 25 | 'datasheet': '3', 26 | } 27 | 28 | def __init__(self, base_component): 29 | self._cmp = base_component 30 | 31 | def _get_field(self, field_name): 32 | if field_name in self._builtin_field_map: 33 | field = [ 34 | x for x in self._cmp.fields 35 | if 36 | x['id'] == self._builtin_field_map[field_name] 37 | ][0] 38 | else: 39 | field = [ 40 | x for x in self._cmp.fields 41 | if 42 | x['name'].strip('"') == field_name 43 | ][0] 44 | 45 | return field 46 | 47 | def _set_field_value(self, field, value): 48 | f = self._get_field(field) 49 | 50 | f['ref'] = '"{}"'.format(sanitized(value)) 51 | 52 | def _get_field_value(self, field): 53 | return self._get_field(field)['ref'].strip('"') 54 | 55 | def _has_field(self, field): 56 | try: 57 | self._get_field(field) 58 | return True 59 | except: 60 | return False 61 | 62 | def add_bom_fields(self): 63 | 64 | _fields = [ 65 | "MFR", 66 | "MPN", 67 | "SPR", 68 | "SPN", 69 | "SPURL", 70 | ] 71 | 72 | for f in _fields: 73 | 74 | if self._has_field(f): 75 | continue 76 | 77 | f_data = { 78 | 'name': '"{}"'.format(f), 79 | 'ref': '"-"' 80 | } 81 | 82 | self._cmp.addField(f_data) 83 | 84 | def set_field_visibility(self, field, visible=True): 85 | f = self._get_field(field) 86 | if visible: 87 | vis = '0000' 88 | else: 89 | vis = '0001' 90 | 91 | f['attributs'] = vis 92 | 93 | @property 94 | def has_valid_key_fields(self): 95 | if not len(self.footprint.strip()) or not len(self.value.strip()): 96 | return False 97 | 98 | return True 99 | 100 | @property 101 | def typeid(self): 102 | return '{}|{}'.format(self.value, 103 | self.footprint) 104 | 105 | @property 106 | def num_fields(self): 107 | return len(self._cmp.fields) 108 | 109 | @property 110 | def reference(self): 111 | return self._get_field_value('reference') 112 | 113 | @property 114 | def value(self): 115 | return self._get_field_value('value') 116 | 117 | @value.setter 118 | def value(self, val): 119 | self._set_field_value('value', val) 120 | 121 | @property 122 | def footprint(self): 123 | return self._get_field_value('footprint') 124 | 125 | @property 126 | def datasheet(self): 127 | return self._get_field_value('datasheet') 128 | 129 | @datasheet.setter 130 | def datasheet(self, val): 131 | self._set_field_value('datasheet', val) 132 | self.set_field_visibility('datasheet', False) 133 | 134 | @property 135 | def is_virtual(self): 136 | if self._cmp.labels['ref'][0] == '#': 137 | return True 138 | return False 139 | 140 | @property 141 | def manufacturer(self): 142 | return self._get_field_value('MFR') 143 | 144 | @manufacturer.setter 145 | def manufacturer(self, mfr): 146 | self._set_field_value('MFR', mfr) 147 | 148 | @property 149 | def supplier(self): 150 | return self._get_field_value('SPR') 151 | 152 | @supplier.setter 153 | def supplier(self, sup): 154 | self._set_field_value('SPR', sup) 155 | 156 | @property 157 | def manufacturer_pn(self): 158 | return self._get_field_value('MPN') 159 | 160 | @manufacturer_pn.setter 161 | def manufacturer_pn(self, pn): 162 | self._set_field_value('MPN', pn) 163 | 164 | @property 165 | def supplier_pn(self): 166 | return self._get_field_value('SPN') 167 | 168 | @supplier_pn.setter 169 | def supplier_pn(self, pn): 170 | self._set_field_value('SPN', pn) 171 | 172 | @property 173 | def supplier_url(self): 174 | return self._get_field_value('SPURL') 175 | 176 | @supplier_url.setter 177 | def supplier_url(self, url): 178 | self._set_field_value('SPURL', url) 179 | 180 | @property 181 | def unit(self): 182 | return int(self._cmp.unit['unit']) 183 | 184 | def __str__(self): 185 | return '\n'.join([ 186 | '\nComponent: {}'.format(self.reference), 187 | '-' * 20, 188 | 'Value: {}'.format(self.value), 189 | 'Footprint: {}'.format(self.footprint), 190 | ]) 191 | 192 | 193 | class ComponentTypeContainer(object): 194 | def __init__(self): 195 | self._components = [] 196 | 197 | def add(self, component): 198 | # Only allow insertion of like components 199 | if len(self._components): 200 | if ((component.value != self._components[0].value) or 201 | (component.footprint != self._components[0].footprint)): 202 | raise Exception("Attempted to insert unlike " 203 | "component into ComponentTypeContainer") 204 | 205 | self._components.append(component) 206 | 207 | def __len__(self): 208 | return len(self._unique_components) 209 | 210 | @property 211 | def _unique_components(self): 212 | """Returns a list of the unique components. This will group multi-part 213 | components together (i.e. individual units, such as a 4 214 | channel op-amp in a single package, will show as a single unified component) 215 | 216 | """ 217 | return [x for x in self._components if x.unit == 1] 218 | 219 | @property 220 | def has_valid_key_fields(self): 221 | if not len(self.footprint.strip()) or not len(self.value.strip()): 222 | return False 223 | 224 | return True 225 | 226 | def extract_components(self, other): 227 | for c in other._components: 228 | self.add(c) 229 | 230 | @property 231 | def typeid(self): 232 | return '{}|{}'.format(self.value, 233 | self.footprint) 234 | 235 | @property 236 | def refs(self): 237 | return ';'.join([x.reference for x in self._unique_components]) 238 | 239 | @property 240 | def value(self): 241 | return self._components[0].value 242 | 243 | @value.setter 244 | def value(self, val): 245 | for c in self._components: 246 | c.value = val 247 | 248 | @property 249 | def footprint(self): 250 | return self._components[0].footprint 251 | 252 | @property 253 | def datasheet(self): 254 | return self._components[0].datasheet 255 | 256 | @datasheet.setter 257 | def datasheet(self, ds): 258 | for c in self._components: 259 | c.datasheet = ds 260 | 261 | @property 262 | def manufacturer(self): 263 | return self._components[0].manufacturer 264 | 265 | @manufacturer.setter 266 | def manufacturer(self, mfgr): 267 | for c in self._components: 268 | c.manufacturer = mfgr 269 | 270 | @property 271 | def manufacturer_pn(self): 272 | return self._components[0].manufacturer_pn 273 | 274 | @manufacturer_pn.setter 275 | def manufacturer_pn(self, pn): 276 | for c in self._components: 277 | c.manufacturer_pn = pn 278 | 279 | @property 280 | def supplier(self): 281 | return self._components[0].supplier 282 | 283 | @supplier.setter 284 | def supplier(self, sup): 285 | for c in self._components: 286 | c.supplier = sup 287 | 288 | @property 289 | def supplier_pn(self): 290 | return self._components[0].supplier_pn 291 | 292 | @supplier_pn.setter 293 | def supplier_pn(self, pn): 294 | for c in self._components: 295 | c.supplier_pn = pn 296 | 297 | @property 298 | def supplier_url(self): 299 | return self._components[0].supplier_url 300 | 301 | @supplier_url.setter 302 | def supplier_url(self, url): 303 | for c in self._components: 304 | c.supplier_url = url 305 | 306 | def __str__(self): 307 | return '\n'.join([ 308 | '\nComponent Type Container', 309 | '-' * 20, 310 | 'Value: {}'.format(self.value), 311 | 'Footprint: {}'.format(self.footprint), 312 | 'Quantity: {}'.format(len(self)) 313 | ]) 314 | 315 | 316 | def walk_sheets(base_dir, sheets, sch_dict): 317 | for sheet in sheets: 318 | sheet_name = sheet.fields[0]['value'].strip('"') 319 | sheet_sch = sheet.fields[1]['value'].strip('"') 320 | schematic = sch.Schematic(os.path.join(base_dir, sheet_sch)) 321 | sch_dict[sheet_name] = ( 322 | sch.Schematic(os.path.join(base_dir, sheet_sch)) 323 | ) 324 | base_dir = os.path.join(base_dir, os.path.split(sheet_sch)[0]) 325 | 326 | walk_sheets(base_dir, schematic.sheets, sch_dict) 327 | 328 | -------------------------------------------------------------------------------- /boms_away/sch.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import sys, shlex 4 | 5 | class Description(object): 6 | """ 7 | A class to parse description information of Schematic Files Format of the KiCad 8 | TODO: Need to be done, currently just stores the raw data read from file 9 | """ 10 | def __init__(self, data): 11 | self.raw_data = data 12 | 13 | class Component(object): 14 | """ 15 | A class to parse components of Schematic Files Format of the KiCad 16 | """ 17 | _L_KEYS = ['name', 'ref'] 18 | _U_KEYS = ['unit', 'convert', 'time_stamp'] 19 | _P_KEYS = ['posx', 'posy'] 20 | _AR_KEYS = ['path', 'ref', 'part'] 21 | _F_KEYS = ['id', 'ref', 'orient', 'posx', 'posy', 'size', 'attributs', 'hjust', 'props', 'name'] 22 | 23 | _KEYS = {'L':_L_KEYS, 'U':_U_KEYS, 'P':_P_KEYS, 'AR':_AR_KEYS, 'F':_F_KEYS} 24 | def __init__(self, data): 25 | self.labels = {} 26 | self.unit = {} 27 | self.position = {} 28 | self.references = [] 29 | self.fields = [] 30 | self.old_stuff = [] 31 | 32 | for line in data: 33 | if line[0] == '\t': 34 | self.old_stuff.append(line) 35 | continue 36 | 37 | line = line.replace('\n', '') 38 | s = shlex.shlex(line) 39 | s.whitespace_split = True 40 | s.commenters = '' 41 | s.quotes = '"' 42 | line = list(s) 43 | 44 | # select the keys list and default values array 45 | if line[0] in self._KEYS: 46 | key_list = self._KEYS[line[0]] 47 | values = line[1:] + ['' for n in range(len(key_list) - len(line[1:]))] 48 | 49 | if line[0] == 'L': 50 | self.labels = dict(zip(key_list,values)) 51 | elif line[0] == 'U': 52 | self.unit = dict(zip(key_list,values)) 53 | elif line[0] == 'P': 54 | self.position = dict(zip(key_list,values)) 55 | elif line[0] == 'AR': 56 | self.references.append(dict(zip(key_list,values))) 57 | elif line[0] == 'F': 58 | self.fields.append(dict(zip(key_list,values))) 59 | 60 | # TODO: error checking 61 | # * check if field_data is a dictionary 62 | # * check if at least 'ref' and 'name' were passed 63 | # * ignore invalid items of field_data on merging 64 | # TODO: enhancements 65 | # * 'value' could be used instead of 'ref' 66 | def addField(self, field_data): 67 | def_field = {'id':None, 'ref':None, 'orient':'H', 'posx':'0', 'posy':'0', 'size':'50', 68 | 'attributs':'0001', 'hjust':'C', 'props':'CNN', 'name':'~'} 69 | 70 | # merge dictionaries and set the id value 71 | field = dict(list(def_field.items()) + list(field_data.items())) 72 | field['id'] = str(len(self.fields)) 73 | 74 | self.fields.append(field) 75 | return field 76 | 77 | class Sheet(object): 78 | """ 79 | A class to parse sheets of Schematic Files Format of the KiCad 80 | """ 81 | _S_KEYS = ['topLeftPosx', 'topLeftPosy','botRightPosx', 'botRightPosy'] 82 | _U_KEYS = ['uniqID'] 83 | _F_KEYS = ['id', 'value', 'IOState', 'side', 'posx', 'posy', 'size'] 84 | 85 | _KEYS = {'S':_S_KEYS, 'U':_U_KEYS, 'F':_F_KEYS} 86 | def __init__(self, data): 87 | self.shape = {} 88 | self.unit = {} 89 | self.fields = [] 90 | for line in data: 91 | line = line.replace('\n', '') 92 | s = shlex.shlex(line) 93 | s.whitespace_split = True 94 | s.commenters = '' 95 | s.quotes = '"' 96 | line = list(s) 97 | # select the keys list and default values array 98 | if line[0] in self._KEYS: 99 | key_list = self._KEYS[line[0]] 100 | values = line[1:] + ['' for n in range(len(key_list) - len(line[1:]))] 101 | if line[0] == 'S': 102 | self.shape = dict(zip(key_list,values)) 103 | elif line[0] == 'U': 104 | self.unit = dict(zip(key_list,values)) 105 | elif line[0][0] == 'F': 106 | key_list = self._F_KEYS 107 | values = line + ['' for n in range(len(key_list) - len(line))] 108 | self.fields.append(dict(zip(key_list,values))) 109 | 110 | class Bitmap(object): 111 | """ 112 | A class to parse bitmaps of Schematic Files Format of the KiCad 113 | TODO: Need to be done, currently just stores the raw data read from file 114 | """ 115 | def __init__(self, data): 116 | self.raw_data = data 117 | 118 | class Schematic(object): 119 | """ 120 | A class to parse Schematic Files Format of the KiCad 121 | """ 122 | def __init__(self, filename): 123 | f = open(filename) 124 | self.filename = filename 125 | self.header = f.readline() 126 | self.libs = [] 127 | self.eelayer = None 128 | self.description = None 129 | self.components = [] 130 | self.sheets = [] 131 | self.bitmaps = [] 132 | self.texts = [] 133 | self.wires = [] 134 | self.entries = [] 135 | self.conns = [] 136 | self.noconns = [] 137 | 138 | if not 'EESchema Schematic File' in self.header: 139 | self.header = None 140 | sys.stderr.write('The file is not a KiCad Schematic File\n') 141 | return 142 | 143 | building_block = False 144 | 145 | while True: 146 | line = f.readline() 147 | if not line: break 148 | 149 | if line.startswith('LIBS:'): 150 | self.libs.append(line) 151 | 152 | elif line.startswith('EELAYER END'): 153 | pass 154 | elif line.startswith('EELAYER'): 155 | self.eelayer = line 156 | 157 | elif not building_block: 158 | if line.startswith('$'): 159 | building_block = True 160 | block_data = [] 161 | block_data.append(line) 162 | elif line.startswith('Text'): 163 | data = {'desc':line, 'data':f.readline()} 164 | self.texts.append(data) 165 | elif line.startswith('Wire'): 166 | data = {'desc':line, 'data':f.readline()} 167 | self.wires.append(data) 168 | elif line.startswith('Entry'): 169 | data = {'desc':line, 'data':f.readline()} 170 | self.entries.append(data) 171 | elif line.startswith('Connection'): 172 | data = {'desc':line} 173 | self.conns.append(data) 174 | elif line.startswith('NoConn'): 175 | data = {'desc':line} 176 | self.noconns.append(data) 177 | 178 | elif building_block: 179 | block_data.append(line) 180 | if line.startswith('$End'): 181 | building_block = False 182 | 183 | if line.startswith('$EndDescr'): 184 | self.description = Description(block_data) 185 | if line.startswith('$EndComp'): 186 | self.components.append(Component(block_data)) 187 | if line.startswith('$EndSheet'): 188 | self.sheets.append(Sheet(block_data)) 189 | if line.startswith('$EndBitmap'): 190 | self.bitmaps.append(Bitmap(block_data)) 191 | 192 | def save(self, filename=None): 193 | # check whether it has header, what means that sch file was loaded fine 194 | if not self.header: return 195 | 196 | if not filename: filename = self.filename 197 | 198 | # insert the header 199 | to_write = [] 200 | to_write += [self.header] 201 | 202 | # LIBS 203 | to_write += self.libs 204 | 205 | # EELAYER 206 | to_write += [self.eelayer, 'EELAYER END\n'] 207 | 208 | # Description 209 | to_write += self.description.raw_data 210 | 211 | # Sheets 212 | for sheet in self.sheets: 213 | to_write += ['$Sheet\n'] 214 | if sheet.shape: 215 | line = 'S ' 216 | for key in sheet._S_KEYS: 217 | line+= sheet.shape[key] + ' ' 218 | to_write += [line.rstrip() + '\n'] 219 | if sheet.unit: 220 | line = 'U ' 221 | for key in sheet._U_KEYS: 222 | line += sheet.unit[key] + ' ' 223 | to_write += [line.rstrip() + '\n'] 224 | 225 | for field in sheet.fields: 226 | line = '' 227 | for key in sheet._F_KEYS: 228 | line += field[key] + ' ' 229 | to_write += [line.rstrip() + '\n'] 230 | to_write += ['$EndSheet\n'] 231 | 232 | # Components 233 | for component in self.components: 234 | to_write += ['$Comp\n'] 235 | if component.labels: 236 | line = 'L ' 237 | for key in component._L_KEYS: 238 | line += component.labels[key] + ' ' 239 | to_write += [line.rstrip() + '\n'] 240 | 241 | if component.unit: 242 | line = 'U ' 243 | for key in component._U_KEYS: 244 | line += component.unit[key] + ' ' 245 | to_write += [line.rstrip() + '\n'] 246 | 247 | if component.position: 248 | line = 'P ' 249 | for key in component._P_KEYS: 250 | line += component.position[key] + ' ' 251 | to_write += [line.rstrip() + '\n'] 252 | 253 | for reference in component.references: 254 | if component.references: 255 | line = 'AR ' 256 | for key in component._AR_KEYS: 257 | line += reference[key] + ' ' 258 | to_write += [line.rstrip() + '\n'] 259 | 260 | for field in component.fields: 261 | line = 'F ' 262 | for key in component._F_KEYS: 263 | line += field[key] + ' ' 264 | to_write += [line.rstrip() + '\n'] 265 | 266 | if component.old_stuff: 267 | to_write += component.old_stuff 268 | 269 | to_write += ['$EndComp\n'] 270 | 271 | # Bitmaps 272 | for bitmap in self.bitmaps: 273 | to_write += bitmap.raw_data 274 | 275 | # Texts 276 | for text in self.texts: 277 | to_write += [text['desc'], text['data']] 278 | 279 | # Wires 280 | for wire in self.wires: 281 | to_write += [wire['desc'], wire['data']] 282 | 283 | # Entries 284 | for entry in self.entries: 285 | to_write += [entry['desc'], entry['data']] 286 | 287 | # Connections 288 | for conn in self.conns: 289 | to_write += [conn['desc']] 290 | 291 | # No Connetions 292 | for noconn in self.noconns: 293 | to_write += [noconn['desc']] 294 | 295 | to_write += ['$EndSCHEMATC\n'] 296 | 297 | f = open(filename, 'w') 298 | f.writelines(to_write) 299 | -------------------------------------------------------------------------------- /bomsaway.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import os 3 | import csv 4 | import shutil 5 | 6 | import wx 7 | from boms_away import sch, datastore 8 | from boms_away import kicad_helpers as kch 9 | from boms_away import export_plugins as export_plugins 10 | from boms_away import plugin_loader 11 | 12 | class DBPartSelectorDialog(wx.Dialog): 13 | def __init__(self, parent, id, title): 14 | wx.Dialog.__init__(self, parent, id, title) 15 | self.selection_idx = None 16 | self.selection_text = None 17 | 18 | vbox = wx.BoxSizer(wx.VERTICAL) 19 | stline = wx.StaticText(self, 11, 'Please select from the following components') 20 | vbox.Add(stline, 0, wx.ALIGN_CENTER|wx.TOP) 21 | self.comp_list = wx.ListBox(self, 331, style=wx.LB_SINGLE) 22 | 23 | vbox.Add(self.comp_list, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND) 24 | self.SetSizer(vbox) 25 | self.comp_list.Bind(wx.EVT_LISTBOX, self.on_selection, id=wx.ID_ANY) 26 | self.Show(True) 27 | 28 | def on_selection(self, event): 29 | self.selection_text = self.comp_list.GetStringSelection() 30 | self.selection_idx = self.comp_list.GetSelection() 31 | self.Close() 32 | 33 | def attach_data(self, data): 34 | list(map(self.comp_list.Append, data)) 35 | 36 | 37 | class ComponentTypeView(wx.Panel): 38 | def __init__(self, parent, id): 39 | super(ComponentTypeView, self).__init__(parent, id, wx.DefaultPosition) 40 | 41 | vbox = wx.BoxSizer(wx.VERTICAL) 42 | self.parent = parent 43 | self._current_type = None 44 | self.grid = wx.GridSizer(0, 2, 3, 3) 45 | 46 | self.lookup_button = wx.Button(self, 310, 'Part Lookup') 47 | self.save_button = wx.Button(self, 311, 'Save Part to Datastore') 48 | 49 | self.qty_text = wx.TextCtrl(self, 301, '', style=wx.TE_READONLY) 50 | self.refs_text = wx.TextCtrl(self, 302, '', style=wx.TE_READONLY) 51 | self.fp_text = wx.TextCtrl(self, 303, '', style=wx.TE_READONLY) 52 | self.value_text = wx.TextCtrl(self, 304, '') 53 | self.ds_text = wx.TextCtrl(self, 305, '') 54 | self.mfr_text = wx.TextCtrl(self, 306, '') 55 | self.mpn_text = wx.TextCtrl(self, 307, '') 56 | self.spr_text = wx.TextCtrl(self, 308, '') 57 | self.spn_text = wx.TextCtrl(self, 309, '') 58 | 59 | # Bind the save and lookup component buttons 60 | self.save_button.Bind(wx.EVT_BUTTON, self.on_save_to_datastore, id=wx.ID_ANY) 61 | self.lookup_button.Bind(wx.EVT_BUTTON, self.on_lookup_component, id=wx.ID_ANY) 62 | 63 | # Set the background color of the read only controls to 64 | # slightly darker to differentiate them 65 | for ctrl in (self.qty_text, self.refs_text, self.fp_text): 66 | ctrl.SetBackgroundColour(wx.ColourDatabase().Find('Light Grey')) 67 | 68 | self._populate_grid() 69 | 70 | # Create fooprint selector box 71 | fpbox = wx.BoxSizer(wx.VERTICAL) 72 | 73 | fp_label = wx.StaticText(self, -1, 'Footprints', style=wx.ALIGN_CENTER_HORIZONTAL) 74 | self.fp_list = wx.ListBox(self, 330, style=wx.LB_SINGLE) 75 | 76 | fpbox.Add(fp_label, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND) 77 | fpbox.Add(self.fp_list, 1, wx.EXPAND) 78 | 79 | self.fp_list.Bind(wx.EVT_LISTBOX, self.on_fp_list, id=wx.ID_ANY) 80 | 81 | # Create Component selector box 82 | compbox = wx.BoxSizer(wx.VERTICAL) 83 | 84 | comp_label = wx.StaticText(self, -1, 'Components', style=wx.ALIGN_CENTER_HORIZONTAL) 85 | self.comp_list = wx.ListBox(self, 331, style=wx.LB_SINGLE) 86 | 87 | compbox.Add(comp_label, 0, wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND) 88 | compbox.Add(self.comp_list, 1, wx.EXPAND) 89 | self.comp_list.Bind(wx.EVT_LISTBOX, self.on_comp_list, id=wx.ID_ANY) 90 | 91 | # Lay out the fpbox and compbox side by side 92 | selbox = wx.BoxSizer(wx.HORIZONTAL) 93 | 94 | selbox.Add(fpbox, 1, wx.EXPAND) 95 | selbox.Add(compbox, 1, wx.EXPAND) 96 | 97 | # Perform final layout 98 | vbox.Add(self.grid, 1, wx.EXPAND | wx.ALL, 3) 99 | vbox.Add(selbox, 3, wx.EXPAND | wx.ALL, 3) 100 | 101 | self.SetSizer(vbox) 102 | 103 | def _populate_grid(self): 104 | # Create text objects to be stored in grid 105 | 106 | # Create the component detail grid 107 | self.grid.AddMany([ 108 | (wx.StaticText(self, -1, 'Quantity'), 0, wx.EXPAND), 109 | (self.qty_text, 0, wx.EXPAND), 110 | (wx.StaticText(self, -1, 'Refs'), 0, wx.EXPAND), 111 | (self.refs_text, 0, wx.EXPAND), 112 | (wx.StaticText(self, -1, 'Footprint'), 0, wx.EXPAND), 113 | (self.fp_text, 0, wx.EXPAND), 114 | (wx.StaticText(self, -1, 'Value'), 0, wx.EXPAND), 115 | (self.value_text, 0, wx.EXPAND), 116 | (wx.StaticText(self, -1, 'Datasheet'), 0, wx.EXPAND), 117 | (self.ds_text, 0, wx.EXPAND), 118 | (wx.StaticText(self, -1, 'Manufacturer'), 0, wx.EXPAND), 119 | (self.mfr_text, 0, wx.EXPAND), 120 | (wx.StaticText(self, -1, 'Manufacturer PN'), 0, wx.EXPAND), 121 | (self.mpn_text, 0, wx.EXPAND), 122 | (wx.StaticText(self, -1, 'Supplier'), 0, wx.EXPAND), 123 | (self.spr_text, 0, wx.EXPAND), 124 | (wx.StaticText(self, -1, 'Supplier PN'), 0, wx.EXPAND), 125 | (self.spn_text, 0, wx.EXPAND), 126 | (self.lookup_button, 0, wx.EXPAND), 127 | (self.save_button, 0, wx.EXPAND), 128 | ]) 129 | 130 | def save_component_type_changes(self): 131 | 132 | if not self._current_type: 133 | return 134 | 135 | self._current_type.value = self.value_text.GetValue() 136 | self._current_type.datasheet = self.ds_text.GetValue() 137 | self._current_type.manufacturer = self.mfr_text.GetValue() 138 | self._current_type.manufacturer_pn = self.mpn_text.GetValue() 139 | self._current_type.supplier = self.spr_text.GetValue() 140 | self._current_type.supplier_pn = self.spn_text.GetValue() 141 | 142 | def on_lookup_component(self, event): 143 | ct = self._current_type 144 | 145 | if not ct: 146 | return 147 | 148 | if not ct.has_valid_key_fields: 149 | raise Exception("Missing key fields (value / footprint)!") 150 | 151 | up = self.parent.ds.lookup(ct) 152 | 153 | if up is None: 154 | dlg = wx.MessageDialog(self.parent, 155 | "Component does not exist in Datastore", 156 | "No Results Found", 157 | wx.OK | wx.ICON_INFORMATION) 158 | dlg.ShowModal() 159 | dlg.Destroy() 160 | return 161 | 162 | if not up.manufacturer_pns.count(): 163 | dlg = wx.MessageDialog(self.parent, 164 | "No suitable parts found in Datastore", 165 | "No Results Found", 166 | wx.OK | wx.ICON_INFORMATION) 167 | return 168 | 169 | selections = {} 170 | 171 | 172 | for pn in up.manufacturer_pns: 173 | print(pn) 174 | if not pn.supplier_parts: 175 | print("no known suppliers") 176 | sel_txt = '{} (No Known Suppliers)'.format( 177 | pn.pn 178 | ) 179 | selections[sel_txt] = (pn, None) 180 | 181 | else: 182 | for s_pn in pn.supplier_parts: 183 | print("suppliers:", s_pn.supplier.name) 184 | sel_text = '{} {} @ {}[{}]'.format( 185 | pn.manufacturer.name, 186 | pn.pn, 187 | s_pn.supplier.name, 188 | s_pn.pn 189 | ) 190 | selections[sel_text] = (pn, s_pn) 191 | 192 | def _set_pn_values(mpn,spn): 193 | if mpn: 194 | self.mfr_text.SetValue(mpn.manufacturer.name) 195 | self.mpn_text.SetValue(mpn.pn) 196 | if spn: 197 | self.spr_text.SetValue(spn.supplier.name) 198 | self.spn_text.SetValue(spn.pn) 199 | 200 | 201 | if len(selections) == 1: 202 | mpn, spn = list(selections.values()).pop() 203 | _set_pn_values(mpn,spn) 204 | else: 205 | _dbps = DBPartSelectorDialog(self, 206 | wx.ID_ANY, 207 | 'DB Part Selection') 208 | _dbps.attach_data(list(selections.keys())) 209 | _dbps.ShowModal() 210 | 211 | if not _dbps.selection_text: 212 | return 213 | 214 | mpn, spn = selections[_dbps.selection_text] 215 | _set_pn_values(mpn,spn) 216 | 217 | def on_save_to_datastore(self, event): 218 | 219 | self.save_component_type_changes() 220 | if not self._current_type: 221 | return 222 | 223 | # TODO: I don't like parent walking...we should inject this 224 | # dependency somewhere 225 | self.parent.ds.update(self._current_type) 226 | 227 | def on_fp_list(self, event): 228 | self.save_component_type_changes() 229 | self.comp_list.Clear() 230 | self._current_type = None 231 | 232 | list(map(self.comp_list.Append, 233 | [x for x in sorted(set(self.type_data[self.fp_list.GetStringSelection()].keys()))])) 234 | 235 | def on_comp_list(self, event): 236 | self.save_component_type_changes() 237 | fp = self.fp_list.GetStringSelection() 238 | ct = self.comp_list.GetStringSelection() 239 | 240 | comp = self.type_data[fp][ct] 241 | 242 | self.qty_text.SetValue(str(len(comp))) 243 | self.refs_text.SetValue(comp.refs) 244 | self.fp_text.SetValue(comp.footprint) 245 | self.value_text.SetValue(comp.value) 246 | self.ds_text.SetValue(comp.datasheet) 247 | self.mfr_text.SetValue(comp.manufacturer) 248 | self.mpn_text.SetValue(comp.manufacturer_pn) 249 | self.spr_text.SetValue(comp.supplier) 250 | self.spn_text.SetValue(comp.supplier_pn) 251 | 252 | self._current_type = comp 253 | 254 | def _reset(self): 255 | self.comp_list.Clear() 256 | self.fp_list.Clear() 257 | self._current_type = None 258 | 259 | def attach_data(self, type_data): 260 | self.type_data = type_data 261 | 262 | self._reset() 263 | 264 | list(map(self.fp_list.Append, 265 | [x for x in sorted(set(type_data.keys()))])) 266 | 267 | class UniquePartSelectorDialog(wx.Dialog): 268 | def __init__(self, parent, id, title): 269 | wx.Dialog.__init__(self, parent, id, title) 270 | self.selection_idx = None 271 | self.selection_text = None 272 | 273 | vbox = wx.BoxSizer(wx.VERTICAL) 274 | stline = wx.StaticText( 275 | self, 276 | 11, 277 | 'Duplicate Component values found!' 278 | '\n\nPlease select which format to follow:') 279 | vbox.Add(stline, 0, wx.ALIGN_CENTER|wx.TOP) 280 | self.comp_list = wx.ListBox(self, 331, style=wx.LB_SINGLE) 281 | 282 | vbox.Add(self.comp_list, 1, wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND) 283 | self.SetSizer(vbox) 284 | self.comp_list.Bind(wx.EVT_LISTBOX_DCLICK, self.on_selection, id=wx.ID_ANY) 285 | self.Show(True) 286 | 287 | def on_selection(self, event): 288 | self.selection_text = self.comp_list.GetStringSelection() 289 | self.selection_idx = self.comp_list.GetSelection() 290 | self.Close() 291 | 292 | def attach_data(self, data): 293 | list(map(self.comp_list.Append, data)) 294 | 295 | class MainFrame(wx.Frame): 296 | 297 | config_dir = os.path.join( 298 | os.path.expanduser("~"), 299 | '.bomsaway.d', 300 | ) 301 | 302 | _legacy_dir = os.path.join( 303 | os.path.expanduser("~"), 304 | '.kicadbommgr.d', 305 | ) 306 | config_file = os.path.join( 307 | config_dir, 308 | 'BOMSAway.conf' 309 | ) 310 | datastore_file = os.path.join( 311 | config_dir, 312 | 'bommgr.db' 313 | ) 314 | 315 | def __init__(self, parent, id, title): 316 | super(MainFrame, self).__init__(parent, id, title, wx.DefaultPosition, wx.Size(800, 600)) 317 | 318 | self._load_config() 319 | 320 | self._create_menu() 321 | self._do_layout() 322 | self.Centre() 323 | 324 | self._reset() 325 | 326 | self.ds = datastore.Datastore(self.datastore_file) 327 | 328 | def _load_config(self): 329 | # Handle legacy file location 330 | if os.path.exists(self._legacy_dir): 331 | print("Migrating config from legacy location") 332 | shutil.move(self._legacy_dir, self.config_dir) 333 | 334 | # Create the kicad bom manager folder if it doesn't already exist 335 | if not os.path.exists(self.config_dir): 336 | os.makedirs(self.config_dir) 337 | 338 | self.filehistory = wx.FileHistory(8) 339 | self.config = wx.Config("BOMsAway", 340 | localFilename=self.config_file, 341 | style=wx.CONFIG_USE_LOCAL_FILE) 342 | self.filehistory.Load(self.config) 343 | 344 | def _do_layout(self): 345 | vbox = wx.BoxSizer(wx.VERTICAL) 346 | self.ctv = ComponentTypeView(self, -1) 347 | 348 | vbox.Add(self.ctv, 1, wx.EXPAND | wx.ALL, 3) 349 | 350 | self.SetSizer(vbox) 351 | 352 | def _create_menu(self): 353 | menubar = wx.MenuBar() 354 | file = wx.Menu() 355 | edit = wx.Menu() 356 | help = wx.Menu() 357 | 358 | file.Append(wx.ID_OPEN, '&Open', 'Open a schematic') 359 | file.Append(wx.ID_SAVE, '&Save', 'Save the schematic') 360 | file.AppendSeparator() 361 | file.Append(103, '&Export BOM as CSV', 'Export the BOM as CSV') 362 | file.AppendSeparator() 363 | 364 | # Create a new submenu for recent files 365 | recent = wx.Menu() 366 | 367 | file.AppendSubMenu(recent, 'Recent') 368 | self.filehistory.UseMenu(recent) 369 | self.filehistory.AddFilesToMenu() 370 | file.AppendSeparator() 371 | 372 | quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit the Application') 373 | file.AppendItem(quit) 374 | edit.Append(201, 'Consolidate Components', 'Consolidate duplicated components') 375 | menubar.Append(file, '&File') 376 | menubar.Append(edit, '&Edit') 377 | menubar.Append(help, '&Help') 378 | self.SetMenuBar(menubar) 379 | 380 | self.Bind(wx.EVT_MENU, self.on_quit, id=105) 381 | self.Bind(wx.EVT_MENU, self.on_open, id=wx.ID_OPEN) 382 | self.Bind(wx.EVT_MENU, self.on_consolidate, id=201) 383 | self.Bind(wx.EVT_MENU, self.on_export, id=103) 384 | self.Bind(wx.EVT_MENU, self.on_save, id=wx.ID_SAVE) 385 | self.Bind(wx.EVT_MENU_RANGE, self.on_file_history, 386 | id=wx.ID_FILE1, id2=wx.ID_FILE9) 387 | 388 | def _reset(self): 389 | self.schematics = {} 390 | self.component_type_map = {} 391 | 392 | def _consolidate(self): 393 | """ 394 | Performs consolidation 395 | """ 396 | uniq = {} 397 | dups = {} 398 | 399 | # Find all duplicated components and put them into a dups map 400 | for fp in self.component_type_map: 401 | for ct in self.component_type_map[fp]: 402 | cthsh = ct.upper().replace(' ', '') 403 | 404 | if cthsh in uniq: 405 | if cthsh not in dups: 406 | dups[cthsh] = [uniq[cthsh]] 407 | 408 | dups[cthsh].append(self.component_type_map[fp][ct]) 409 | else: 410 | uniq[cthsh] = self.component_type_map[fp][ct] 411 | 412 | for d, cl in list(dups.items()): 413 | 414 | _popup = UniquePartSelectorDialog(self, 415 | wx.ID_ANY, 416 | 'Duplicate part value') 417 | 418 | _popup.attach_data([x.value for x in cl]) 419 | _popup.ShowModal() 420 | 421 | # If the user didn't select anything, just move on 422 | if _popup.selection_idx is None: 423 | continue 424 | 425 | sel = cl.pop(_popup.selection_idx) 426 | 427 | for rem in cl: 428 | old_fp = rem.footprint 429 | old_val = rem.value 430 | 431 | # Set all relevant fields 432 | rem.value = sel.value 433 | rem.manufacturer = sel.manufacturer 434 | rem.manufacturer_pn = sel.manufacturer_pn 435 | rem.supplier_pn = sel.supplier_pn 436 | rem.supplier = sel.supplier 437 | 438 | print(sel) 439 | sel.extract_components(rem) 440 | del self.component_type_map[old_fp][old_val] 441 | 442 | self.ctv.attach_data(self.component_type_map) 443 | 444 | _popup.Destroy() 445 | 446 | 447 | def load(self, path): 448 | if len(path) == 0: 449 | return 450 | 451 | # remove old schematic information 452 | self._reset() 453 | 454 | base_dir = os.path.split(path)[0] 455 | top_sch = os.path.split(path)[-1] 456 | top_name = os.path.splitext(top_sch)[0] 457 | 458 | compmap = {} 459 | 460 | self.schematics[top_name] = ( 461 | sch.Schematic(os.path.join(base_dir, top_sch)) 462 | ) 463 | 464 | # Recursively walks sheets to locate nested subschematics 465 | # TODO: re-work this to return values instead of passing them byref 466 | kch.walk_sheets(base_dir, self.schematics[top_name].sheets, self.schematics) 467 | 468 | for name, schematic in list(self.schematics.items()): 469 | for _cbase in schematic.components: 470 | c = kch.ComponentWrapper(_cbase) 471 | 472 | # Skip virtual components (power, gnd, etc) 473 | if c.is_virtual: 474 | continue 475 | 476 | # Skip anything that is missing either a value or a 477 | # footprint 478 | if not c.has_valid_key_fields: 479 | continue 480 | 481 | c.add_bom_fields() 482 | 483 | if c.footprint not in self.component_type_map: 484 | self.component_type_map[c.footprint] = {} 485 | 486 | if c.value not in self.component_type_map[c.footprint]: 487 | self.component_type_map[c.footprint][c.value] = kch.ComponentTypeContainer() 488 | 489 | self.component_type_map[c.footprint][c.value].add(c) 490 | 491 | self.ctv.attach_data(self.component_type_map) 492 | self._current_type = None 493 | self.ctv.lookup_button.disabled = True 494 | self.ctv.save_button.disabled = True 495 | 496 | def on_consolidate(self, event): 497 | self._consolidate() 498 | 499 | 500 | def on_file_history(self, event): 501 | """ 502 | Handles opening files from the recent file history 503 | """ 504 | fileNum = event.GetId() - wx.ID_FILE1 505 | path = self.filehistory.GetHistoryFile(fileNum) 506 | self.filehistory.AddFileToHistory(path) # move up the list 507 | self.load(path) 508 | 509 | def on_open(self, event): 510 | """ 511 | Recursively loads a KiCad schematic and all subsheets 512 | """ 513 | #self.save_component_type_changes() 514 | open_dialog = wx.FileDialog(self, "Open KiCad Schematic", "", "", 515 | "Kicad Schematics (*.sch)|*.sch", 516 | wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) 517 | 518 | if open_dialog.ShowModal() == wx.ID_CANCEL: 519 | return 520 | 521 | # Load Chosen Schematic 522 | print("opening File:", open_dialog.GetPath()) 523 | 524 | # Store the path to the file history 525 | self.filehistory.AddFileToHistory(open_dialog.GetPath()) 526 | self.filehistory.Save(self.config) 527 | self.config.Flush() 528 | 529 | self.load(open_dialog.GetPath()) 530 | 531 | def on_export(self, event): 532 | """ 533 | Gets a file path via popup, then exports content 534 | """ 535 | 536 | exporters = plugin_loader.load_export_plugins() 537 | 538 | wildcards = '|'.join([x.wildcard for x in exporters]) 539 | 540 | export_dialog = wx.FileDialog(self, "Export BOM", "", "", 541 | wildcards, 542 | wx.FD_SAVE|wx.FD_OVERWRITE_PROMPT) 543 | 544 | if export_dialog.ShowModal() == wx.ID_CANCEL: 545 | return 546 | 547 | base, ext = os.path.splitext(export_dialog.GetPath()) 548 | filt_idx = export_dialog.GetFilterIndex() 549 | 550 | exporters[filt_idx]().export(base, self.component_type_map) 551 | 552 | def on_quit(self, event): 553 | """ 554 | Quits the application 555 | """ 556 | self.ctv.save_component_type_changes() 557 | exit(0) 558 | 559 | def on_save(self, event): 560 | """ 561 | Saves the schematics 562 | """ 563 | self.ctv.save_component_type_changes() 564 | for name, schematic in list(self.schematics.items()): 565 | schematic.save() 566 | 567 | 568 | class BomsAwayApp(wx.App): 569 | def OnInit(self): 570 | frame = MainFrame(None, -1, 'Boms-Away!') 571 | frame.Show(True) 572 | self.SetTopWindow(frame) 573 | return True 574 | 575 | if __name__ == '__main__': 576 | BomsAwayApp(0).MainLoop() 577 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {{ project }} Copyright (C) {{ year }} {{ organization }} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------