- draw_logic_network.py
This commit is contained in:
parent
b656a5c7dd
commit
72fc9fa202
@ -247,8 +247,8 @@ class LogicFunction implements JsonSerializable
|
|||||||
return join(" | ", $minterms);
|
return join(" | ", $minterms);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function drawNetwork(string $fn, string $outvar = "f"): void {
|
public function drawNetwork(string $outvar = "f"): string {
|
||||||
PythonUtils::execPy("draw_logic_network.py", [ $this->getExpression(), $outvar, $fn ]);
|
return PythonUtils::execPy("draw_logic_network.py", [ $this->getExpression(), $outvar ]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,7 @@ class PythonUtils
|
|||||||
{
|
{
|
||||||
private const VENV = Utils::WORKSPACE_DIR . DIRECTORY_SEPARATOR . "venv";
|
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
|
$venv = getcwd() . DIRECTORY_SEPARATOR . self::VENV; // compose full venv path
|
||||||
$ws = getcwd() . DIRECTORY_SEPARATOR . Utils::WORKSPACE_DIR; // compose full workspace 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";
|
//$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
|
$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";
|
$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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,11 +81,10 @@ class TruthTableTask extends PicturedTask
|
|||||||
public function randomize(): void
|
public function randomize(): void
|
||||||
{
|
{
|
||||||
if ($this->hasFlag("drawnetwork")) {
|
if ($this->hasFlag("drawnetwork")) {
|
||||||
$svg_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid("truthtable_") . ".svg";
|
///$svg_file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid("truthtable_") . ".svg";
|
||||||
$this->lf->drawNetwork($svg_file);
|
$this->setImageData($this->lf->drawNetwork($this->output_variable));
|
||||||
$this->setImageData(file_get_contents($svg_file) ?? "");
|
|
||||||
$this->setImageType("svg");
|
$this->setImageType("svg");
|
||||||
@unlink($svg_file);
|
//@unlink($svg_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
parent::randomize();
|
parent::randomize();
|
||||||
|
|||||||
@ -2,8 +2,10 @@ import sys
|
|||||||
from schemdraw import logic
|
from schemdraw import logic
|
||||||
from schemdraw.parsing import logicparse
|
from schemdraw.parsing import logicparse
|
||||||
|
|
||||||
if len(sys.argv) < 4:
|
if len(sys.argv) < 3:
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
network = logicparse(sys.argv[1], outlabel=sys.argv[2], gateH=1.2)
|
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)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user