forked from bchan/OT2GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartstore.py
More file actions
53 lines (41 loc) · 1.58 KB
/
partstore.py
File metadata and controls
53 lines (41 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import part
import json
from sbol import *
class PartStore:
def __init__(self):
self.parts = []
def addPart(self, name, type, volume):
mypart = part.Part(name, type, volume)
self.parts.append(mypart)
def findPart(self,name):
thepart = None
for part in self.parts:
if part.name == name:
thepart = part
return thepart
def removePart(self, name, type, volume):
removeIndex = -1
for index, partIter in enumerate(self.parts):
if partIter.getName() == name and partIter.getType() == type and partIter.getVolume() == volume:
removeIndex = index
break
del self.parts[removeIndex]
del self.componentDefinitions[removeIndex]
def loadJSON(self, filename):
with open(filename) as json_file:
existingParts = json.load(json_file)
for jsonPart in existingParts['Parts']:
newpart = part.Part(jsonPart['Part Name'],jsonPart['Type'],jsonPart['Volume'])
self.parts.append(newpart)
return self.parts
def saveJSON(self, filename):
partsList = []
for part in self.parts:
partDictionary = {}
partDictionary['Part Name'] = part.getName()
partDictionary['Type'] = part.getType()
partDictionary['Volume'] = part.getVolume()
partsList.append(partDictionary)
jsonDictionary = {'Parts': partsList}
with open(filename, 'w') as json_file:
json.dump(jsonDictionary, json_file, indent=4)