Skip to content
Snippets Groups Projects
Commit 84927c3a authored by Hock, Benedikt's avatar Hock, Benedikt
Browse files

minimal example for a car

parent 41cbe8fd
No related branches found
No related tags found
No related merge requests found
# import functions.lego_classes as lego_classes
from functions.lego_classes import LegoItem
from functions.lego_classes import LegoComponent
from functions.lego_classes import *
import json
import pprint
# Test manually creating some item and components
item1 = LegoItem(1,0.10,10)
item2 = LegoItem(3,0.30,30)
item3 = LegoItem(2, 0.2,20)
battery = LegoComponent("nice battery", ComponentCategory.BATTERY, "bat42", 1, 2, 3)
motor = LegoComponent("motor goes brrr", ComponentCategory.MOTOR, "motor", 1, 2, 3)
wheel = LegoComponent("much round wheel", ComponentCategory.WHEEL, "round", 1, 2, 3)
car = LegoAssembly("Car", AggregationLayer.SYSTEM)
chassis = LegoAssembly("Chassis", AggregationLayer.ASSEMBLY)
door1 = LegoAssembly("Door 1", AggregationLayer.SUBASSEMBLY)
door2 = LegoAssembly("Door 2", AggregationLayer.SUBASSEMBLY)
chassis.add_assembly(door1)
chassis.add_assembly(door2)
engine = LegoAssembly("Engine", AggregationLayer.ASSEMBLY)
engine.add_component(motor.clone())
fuel_tank = LegoAssembly("Fuel Tank", AggregationLayer.ASSEMBLY)
fuel_tank.add_component(battery.clone())
wheels = LegoAssembly("Wheels", AggregationLayer.ASSEMBLY)
for _ in range(4):
wheels.add_component(wheel.clone())
car.add_assembly(chassis)
car.add_assembly(engine)
car.add_assembly(fuel_tank)
car.add_assembly(wheels)
component1 = LegoComponent()
# component1.add_item(item1)
component2 = LegoComponent(item2)
print_assembly_tree(car)
componentall = LegoComponent([item1,item2],[]) # Some combinations might result in errors
# component3 = LegoComponent(item3,component1)
# component3.add(item2) # Can't really use an item twice
# component3.add(component2)
print(componentall.items)
x = componentall.children()
print(x)
# Dump to json file
with open("car.json", "w") as fp:
json.dump(car.to_dict(), fp, cls=KPIEncoder)
print(type(x))
alist = ["abc","def"]
pprint.pprint(car.to_dict())
pass
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment