- draw_logic_network.py
This commit is contained in:
		
							parent
							
								
									b656a5c7dd
								
							
						
					
					
						commit
						72fc9fa202
					
				@ -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 ]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@ -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();
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user