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 # import functions.lego_classes as lego_classes
from functions.lego_classes import LegoItem from functions.lego_classes import *
from functions.lego_classes import LegoComponent import json
import pprint
# Test manually creating some item and components # Test manually creating some item and components
item1 = LegoItem(1,0.10,10) battery = LegoComponent("nice battery", ComponentCategory.BATTERY, "bat42", 1, 2, 3)
item2 = LegoItem(3,0.30,30) motor = LegoComponent("motor goes brrr", ComponentCategory.MOTOR, "motor", 1, 2, 3)
item3 = LegoItem(2, 0.2,20) 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() print_assembly_tree(car)
# component1.add_item(item1)
component2 = LegoComponent(item2)
componentall = LegoComponent([item1,item2],[]) # Some combinations might result in errors # Dump to json file
# component3 = LegoComponent(item3,component1) with open("car.json", "w") as fp:
# component3.add(item2) # Can't really use an item twice json.dump(car.to_dict(), fp, cls=KPIEncoder)
# component3.add(component2)
print(componentall.items)
x = componentall.children()
print(x)
print(type(x)) pprint.pprint(car.to_dict())
alist = ["abc","def"] 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