diff --git a/class/LogicFunction.php b/class/LogicFunction.php index fbf912c..ed8eea5 100644 --- a/class/LogicFunction.php +++ b/class/LogicFunction.php @@ -247,8 +247,8 @@ class LogicFunction implements JsonSerializable return join(" | ", $minterms); } - public function drawNetwork(string $fn, string $outvar = "f"): void { - PythonUtils::execPy("draw_logic_network.py", [ $this->getExpression(), $outvar, $fn ]); + public function drawNetwork(string $outvar = "f"): string { + return PythonUtils::execPy("draw_logic_network.py", [ $this->getExpression(), $outvar ]); } } diff --git a/class/PythonUtils.php b/class/PythonUtils.php index f2ffa17..b10b782 100644 --- a/class/PythonUtils.php +++ b/class/PythonUtils.php @@ -6,7 +6,7 @@ class PythonUtils { private const VENV = Utils::WORKSPACE_DIR . DIRECTORY_SEPARATOR . "venv"; - public static function execPy(string $script, array $args): void + public static function execPy(string $script, array $args): string { $venv = getcwd() . DIRECTORY_SEPARATOR . self::VENV; // compose full venv path $ws = getcwd() . DIRECTORY_SEPARATOR . Utils::WORKSPACE_DIR; // compose full workspace path @@ -14,6 +14,6 @@ class PythonUtils //$source_cmd = "source " . $venv . DIRECTORY_SEPARATOR . "bin" . DIRECTORY_SEPARATOR . "activate"; $flattened_args = join(" ", array_map(fn($arg) => "'$arg'", $args)); // prepare arguments for use on command line $python_cmd = "bash $ws" . DIRECTORY_SEPARATOR . "py_exec.sh \"$ws" . DIRECTORY_SEPARATOR . $script . "\" " . $flattened_args . " 2>&1"; - $ret = shell_exec($python_cmd); // execute python script + return shell_exec($python_cmd); // execute python script } } \ No newline at end of file diff --git a/class/Tasks/TruthTableTask.php b/class/Tasks/TruthTableTask.php index d313cd2..c0a43a5 100644 --- a/class/Tasks/TruthTableTask.php +++ b/class/Tasks/TruthTableTask.php @@ -81,11 +81,10 @@ class TruthTableTask extends PicturedTask public function randomize(): void { if ($this->hasFlag("drawnetwork")) { - $svg_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid("truthtable_") . ".svg"; - $this->lf->drawNetwork($svg_file); - $this->setImageData(file_get_contents($svg_file) ?? ""); + ///$svg_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid("truthtable_") . ".svg"; + $this->setImageData($this->lf->drawNetwork($this->output_variable)); $this->setImageType("svg"); - @unlink($svg_file); + //@unlink($svg_file); } parent::randomize(); diff --git a/workspace/draw_logic_network.py b/workspace/draw_logic_network.py index 8bb066b..b2bb53e 100644 --- a/workspace/draw_logic_network.py +++ b/workspace/draw_logic_network.py @@ -2,8 +2,10 @@ import sys from schemdraw import logic from schemdraw.parsing import logicparse -if len(sys.argv) < 4: +if len(sys.argv) < 3: exit(0) network = logicparse(sys.argv[1], outlabel=sys.argv[2], gateH=1.2) -network.save(sys.argv[3]) +#network.save(sys.argv[3]) +svg = network.get_imagedata() +print(svg)