Skip to content

Commit

Permalink
Slight renamings for better clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
mitaa committed Sep 13, 2024
1 parent c418352 commit 715ec8d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
auxiliary/
*.html
*.stackdump

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
27 changes: 16 additions & 11 deletions src/production_planner/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,12 +628,12 @@ def ingredient_constructor(loader, data):
class SummaryNode(Node):
def __init__(self, nodes):
self.row_idx = 0
super().__init__(SUMMARY_PRODUCER, self.update_recipe(nodes), is_dummy=True)
super().__init__(SUMMARY_PRODUCER, self.update_summary(nodes), is_dummy=True)

def producer_reset(self):
...

def update_recipe(self, nodes: [Node]) -> Recipe:
def update_summary(self, nodes: [Node]) -> Recipe:
# TODO: also handle power consumption
power = 0
sums = {}
Expand Down Expand Up @@ -665,12 +665,15 @@ def summary_constructor(loader, data):


class NodeInstance:
# FIXME: this is shared between all instances but this must not be true for unrelated NodeTrees
row_to_node_index = []
session_modules = set()

def __init__(self, node:Node, children:[Self]=None, parent:[Self]=None, shown=True, expanded=True, row_idx=None, level=0):
def __init__(self, node: Node, children: [Self] = None, parent: [Self] = None, shown=True, expanded=True, row_idx=None, level=0):
self.tree_modules = set()

self.parent = parent
self.node_main = node

if children is None:
children = []

Expand Down Expand Up @@ -764,7 +767,7 @@ def get_nodes(self, level=0) -> [Self]:
if isinstance(self.node_main, SummaryNode):
# Note: the innermost nodes get their recipe updated before the outer nodes
# because of the `get_nodes` calls above
self.node_main.update_recipe([cinstance.node_main for cinstance in self.node_children])
self.node_main.update_summary([cinstance.node_main for cinstance in self.node_children])

if level < 2:
NodeInstance.row_to_node_index += [self] * len(nodes)
Expand All @@ -778,7 +781,7 @@ def update_summaries(self):
if not isinstance(self.node_main, SummaryNode):
return

self.node_main.update_recipe([cinstance.node_main for cinstance in self.node_children])
self.node_main.update_summary([cinstance.node_main for cinstance in self.node_children])

def update_parents(self):
for child in self.node_children:
Expand All @@ -789,6 +792,7 @@ def set_module(self, module_file: ModuleFile):
if not self.node_main.is_module:
return

# FIXME: guard against recursive modules here..
if module_file:
self.node_children.clear()
tree = MODULE_PRODUCER.update_module(module_file)
Expand All @@ -797,15 +801,16 @@ def set_module(self, module_file: ModuleFile):

self.add_children([tree])

if self.node_children:
self.node_main.energy_module = self.node_children[0].node_main.energy
if self.node_children:
# FIXME: sum with nested modules isn't always correct
self.node_main.energy_module = self.node_children[0].node_main.energy

def collect_modules(self, level=0):
if level == 0:
self.session_modules.clear()
self.tree_modules.clear()

if self.node_main.is_module:
self.session_modules.add(self.node_main.recipe.name)
self.tree_modules.add(self.node_main.recipe.name)

for child in self.node_children:
child.collect_modules(level + 1)
Expand Down Expand Up @@ -860,7 +865,7 @@ def reload_module(instance) -> str | bool | None:
if instance.node_main.is_module:
module = instance.node_main.recipe.name
log(f"reloading module: {module}")
self.session_modules.add(module)
self.tree_modules.add(module)
if module in module_stack:
log("Error: Recursive Modules!")
APP.notify(f"Error; Resursive Modules: ({'>'.join(module_stack)})",
Expand Down
6 changes: 3 additions & 3 deletions src/production_planner/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ def save_file(subpath: Path) -> None:
return
self.nodetree.collect_modules()
# TODO: create a test
if ModuleFile(subpath).id in self.nodetree.session_modules:
if ModuleFile(subpath).id in self.nodetree.tree_modules:
self.notify(f"Saving to `{subpath}` would create recursive modules",
severity="error",
timeout=10)
self.notify(f"Modules included: {repr(self.nodetree.session_modules)}",
self.notify(f"Modules included: {repr(self.nodetree.tree_modules)}",
severity="warning",
timeout=10)
return
Expand Down Expand Up @@ -418,7 +418,7 @@ def update(self, selected: SelectionContext = None):
node.update()
is_summary = isinstance(node, SummaryNode)
if is_summary:
node.update_recipe(inst.node_main for inst in node_instance.node_children)
node.update_summary(inst.node_main for inst in node_instance.node_children)
row = [Column(node_instance) for Column in self.edit_columns]

for ingredient in ingredients:
Expand Down

0 comments on commit 715ec8d

Please sign in to comment.