HPGL to G Translator Source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>HPGL to G-Code Translator</title>
<style type="text/css" media="all">
@import "style1.css";
span.g0 { color: #00b; }
span.g1 { color: #070; }
span.m2 { color: #d00; }
div.text{ width: 6in; }
h1 { font-size: 140%; }
</style>
</head>
<body>
<?php
$uri = $_SERVER["SCRIPT_URI"]; $self = $_SERVER["PHP_SELF"]; $dec = $_POST['dec']; $scale = $_POST['scale']; if ($dec < .1 || $dec > 16) {$dec = 5;} if ($scale < 1) {$scale = 1016; } $uploaded = $_FILES['my_text']['name'];
if (!$uploaded){
echo '
<h1>HPGL to G-Code Translator</h1>
<div class="text">
This script will translate simple HPGL-1 (as exported via CorelDraw) into basic RS274NGC (G-Code). Only pen-up (PU) and pen-down (PD) commands with two numbers separated by a space and then a line break are translated.
<br /><br />
For example:<br /><br />
PU0 0;<br />
PD0 22;<br />
PD-1 44;<br />
PD-3 65; and so on.
<br /><br /></div>
<form enctype="multipart/form-data" action="' . $self . '" method="post">
<div>
input resolution: <input type="text" maxlength="5" size="5" name="scale" value="' . $scale . '" />
<br />
number of decimals: <input type="text" maxlength="2" size="3" name="dec" value="' . $dec . '" />
<br /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="40000" />
<input name="my_text" type="file" />
<br />
<input type="submit" value="Translate" />
</div>
</form>';
}
else
{
echo "<div>( Simple RS274NGC translated from HPGL by $uri )
<br />
( Direct any complaints and suggestions to Hal Eckhart at gff5o6j02@sneakemail.com )
<pre>
";
$dec = "%01." . $dec . "f"; $my_text = @file_get_contents($_FILES['my_text']['tmp_name']) ; $my_text = str_replace ( array ("p", "P"),
array ("\np", "\nP"), $my_text );
$my_text2 = explode ("\n", $my_text); while (!is_null($key = key($my_text2) ) ) {
if (preg_match ("/pu *(-?\d+)[ ,]+(-?\d+)/i", $my_text2[$key], $match)) {
echo "\n<span class=\"g0\">G00 x".sprintf("$dec", $match[1]/$scale)." y".sprintf("$dec", $match[2]/$scale)."</span>\n";
}
elseif (preg_match ("/pd *(-?\d+)[ ,]+(-?\d+)/i", $my_text2[$key], $match)) {
echo "<span class=\"g1\">G01 x".sprintf("$dec", $match[1]/$scale)." y".sprintf("$dec", $match[2]/$scale)."</span>\n";
}
next($my_text2);
}
echo "\n\n<span class=\"m2\">M02</span> </pre></div>";
}
?>
</body>
</html>
Posted by Hal Eckhart at June 3, 2004 06:02 PM
| TrackBack