implemented generation of multiples NSDs and spelling
This commit is contained in:
@@ -10,7 +10,7 @@ import draw.code_to_image as cti
|
||||
class NassiShneidermanDiagram:
|
||||
|
||||
def __init__(self, do_debug: bool):
|
||||
self.instructions: List[Iinstruction] = []
|
||||
self.scopes: List[List[Iinstruction]] = []
|
||||
self.init_logging(do_debug)
|
||||
|
||||
def init_logging(self, debug: bool):
|
||||
@@ -23,21 +23,24 @@ class NassiShneidermanDiagram:
|
||||
def set_font(self, font_filepath: str):
|
||||
cti.set_font(font_filepath)
|
||||
|
||||
def _get_image_height(self) -> int:
|
||||
def _get_image_height(self, scope_index: int) -> int:
|
||||
h = 0
|
||||
for inst in self.instructions:
|
||||
for inst in self.scopes[scope_index]:
|
||||
h += inst.getblksize()
|
||||
return int(h)
|
||||
|
||||
def convert_to_image(self, filepath: str, x_size: int=200):
|
||||
image_y_sz = self._get_image_height()
|
||||
logging.info(f"Saving NSD to {filepath}.png...")
|
||||
with NSD_writer(filepath, x_size, image_y_sz):
|
||||
x, y = 0, 0
|
||||
def convert_to_image(self, output_path: str, filename: str, x_size: int=200):
|
||||
for i in range(len(self.scopes)):
|
||||
filepath = f"{output_path}/{filename}#{i}"
|
||||
logging.info(f"Saving NSD to {filepath}.png...")
|
||||
|
||||
for instruction in self.instructions:
|
||||
x, y = instruction.to_image(x, y, x_size)
|
||||
logging.info("Done!")
|
||||
image_y_sz = self._get_image_height(i)
|
||||
with NSD_writer(filepath, x_size, image_y_sz):
|
||||
scope = self.scopes[i]
|
||||
x, y = 0, 0
|
||||
for instruction in scope:
|
||||
x, y = instruction.to_image(x, y, x_size)
|
||||
logging.info("Done!")
|
||||
|
||||
def load_from_file(self, filepath:str):
|
||||
self.instructions = itp.load_instructions(filepath)
|
||||
self.scopes = itp.load_instructions(filepath)
|
||||
@@ -3,7 +3,7 @@ from os import remove
|
||||
import re
|
||||
from typing import List, Tuple
|
||||
|
||||
from errors.custom import JavaSyntaxError, ScopeNotFoundException
|
||||
from errors.custom import InterpreterException, JavaSyntaxError, ScopeNotFoundException
|
||||
from draw.Iinstruction import *
|
||||
|
||||
COMMENT_PATTERN = re.compile(r"""^//|^/\*\*|^\*|^--""")
|
||||
@@ -20,7 +20,7 @@ remove_pattern = re.compile("|".join(REPLACE.keys()))
|
||||
variable_regex = "^("
|
||||
for kw in FUNCTION_IDENTIFIERS:
|
||||
variable_regex += fr"""{kw}|"""
|
||||
variable_pattern = re.compile(variable_regex[0:-1]+"$(.*)")
|
||||
variable_pattern = re.compile(variable_regex[0:-1]+")$(.*)")
|
||||
|
||||
function_regex = "^("
|
||||
for kw in FUNCTION_IDENTIFIERS:
|
||||
|
||||
Reference in New Issue
Block a user