freecad-cam/Mod/cam-dev/ref-hsmworks/posts/interactive.hta

310 lines
7.7 KiB
HTML

<!-- Copyright (c) by Autodesk 2012-2014. -->
<!-- http://cam.autodesk.com -->
<html>
<head><title>Autodesk CAM Post Processor User Interface Example</title>
<HTA:APPLICATION ID="oHTA";
applicationName="Autodesk CAM - Post Processor";
border="dialog";
singleInstance="no";
sysMenu="no";
innerBorder="no"
/>
<style>
body {
background-color:#ffffff;
font:13px "Century Gothic";
color:black;
width:640px;
};
.page {
margin: 25px;
};
hr {
color:black;
};
.title {
font-weight:700;
};
.error {
font-weight:700;
color:red;
};
</style>
</head>
<body leftmargin="0px" topmargin="0px" marginwidth="0px" marginheight="0px" onLoad="onLoad()">
<a href="http://hsmworks.com"><img src="hsmworks_banner.png" border="0" alt="HSMWorks - The CAM Solution for SolidWorks"/></a>
<br/>
<div class="page">
<p>This HTML application demonstrates how to make a simple user interface which allows user interaction during post processing.</p>
<br>
<p><div style="display:inline" id="pcomment">Comment:</div> <input type="text" size="40" name="comment"></p>
<div>
<input type="radio" name="arc" value="r"/><div style="display:inline" id="puse_r">Use radius for G2/G3</div>
<input type="radio" name="arc" value="ijk"/><div style="display:inline" id="puse_ijk">Use IJK for G2/G3</div>
</div>
<br/>
<div><input type="checkbox" name="showblocknumbers"/><div style="display:inline" id="pshowblocknumbers">Show block numbers</div></div>
<p><div style="display:inline" id="pblocknumberincrement">Block number increment:</div>
<select name="blocknumberincrement">
<option value="1">1</option>
<option value="5">5</option>
<option value="10">10</option>
<option value="20">20</option>
</select>
</p>
<p><div style="display:inline" id="ptolerance">Tolerance:</div><input type="value" name="tolerance" value="0.001"/></p>
<div style="color='red'"><p id="error"></p></div>
<p><input type="button" name="cancel" value="Cancel" onClick="Cancel_onClick()"/> <input type="button" name="accept" value="Accept" onClick="Accept_onClick()"/></p>
</div>
</body>
</html>
<script language="javascript">
var shell = new ActiveXObject("WScript.Shell");
var subkey = "HSMWorks\\HSMWorks\\options\\";
var product = "HSMWorks";
var localeDocument;
/** Loads the specified translation file. */
function loadLocale(localePath) {
try {
var document = new ActiveXObject("Microsoft.XMLDOM");
document.load(localePath);
document.setProperty("SelectionLanguage", "XPath");
document.setProperty("SelectionNamespaces", "xmlns:locale='http://www.hsmworks.com/xml/2008/locale'");
pattern = ".//locale:locale/locale:message";
if (!document.selectSingleNode(pattern)) {
return;
}
localeDocument = document;
} catch (e) {
}
}
/** Returns the translation for the specified text. */
function localize(text) {
if (localeDocument) {
pattern = ".//locale:locale/locale:message[@name='" + text + "']";
try {
localized = localeDocument.selectSingleNode(pattern).text;
return localized;
} catch (e) {
}
}
return text;
}
/** Returns the translation for the specified text with substitution of the extra arguments. */
function localize2(text) {
var result = localize(text);
for (var i = 0; i < arguments.length; ++i) {
result = result.split("%" + (i + 1)).join(arguments[i + 1]);
}
return result;
}
function onLoad() {
window.resizeTo(640, 500);
try {
var localePath = shell.RegRead("HKCU\\Software\\HSMWorks\\HSMWorks\\locale path");
loadLocale(localePath);
} catch (e) {
}
pcomment.innerHTML = localize("Comment") + ": ";
puse_r.innerHTML = localize("Use radius for G2/G3");
puse_ijk.innerHTML = localize("Use IJK for G2/G3");
pshowblocknumbers.innerHTML = localize("Show block numbers");
pblocknumberincrement.innerHTML = localize("Block number increment") + ": ";
ptolerance.innerHTML = localize("Tolerance") + ": ";
cancel.value = localize("Cancel");
accept.value = localize("Accept");
// TAG: we could load settings from file if required
comment.value = "";
setCheckValue(arc, "ijk");
showblocknumbers.checked = true;
blocknumberincrement.value = 5;
}
/** Returns the value of the specified radio object. */
function getCheckedValue(object) {
if (!object) {
return "";
}
var length = object.length;
if (length == undefined) {
if (object.checked) {
return object.value;
} else {
return "";
}
}
for (var i = 0; i < length; ++i) {
if (object[i].checked) {
return object[i].value;
}
}
return "";
}
/** Sets the value for the specified radio group. */
function setCheckValue(object, value) {
if (!object) {
return;
}
var length = object.length;
if (length == undefined) {
object.checked = (object.value == value.toString());
return;
}
for (var i = 0; i < length; ++i) {
object[i].checked = false;
if (object[i].value == value.toString()) {
object[i].checked = true;
}
}
}
/** Cancel settings. */
function Cancel_onClick() {
var shell = new ActiveXObject("WScript.Shell");
var arguments = getArguments();
if (arguments.length != 2) {
window.close();
return;
}
// store settings
var path = arguments[1];
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.CreateTextFile(path, true);
f.Close();
window.close();
}
/** Sets the specified error. */
function setError(text) {
error.innerHTML = localize("Error") + ": " + text;
}
/** Returns the arguments as an array. */
function getArguments() {
var result = [];
var text = oHTA.commandLine;
var argument = "";
var i = 0;
while (true) {
while (text.charAt(i) == " ") { // skip spaces
++i;
}
if (i >= text.length) { // no more
break;
}
argument = "";
if (text.charAt(i) == "\"") { // begin quote
++i; // skip quote
var done = false;
while ((i < text.length) && !done) {
var ch = text.charAt(i);
++i;
switch (ch) {
case '"': // end quote
done = true;
break;
case '\\':
if ((i < text.length) && (text.charAt(i) == '"')) {
argument = argument + '"';
} else if ((i < text.length) && (text.charAt(i) == '\\')) {
argument = argument + '\\';
} else {
argument = argument + ch;
}
break;
default:
argument = argument + ch;
}
}
if (!done) { // error
return [];
}
} else {
while ((i < text.length) && (text.charAt(i) != " ")) {
argument = argument + text.charAt(i);
++i;
}
}
result.push(argument);
}
return result;
}
/** Accept settings. */
function Accept_onClick() {
var shell = new ActiveXObject("WScript.Shell");
if (tolerance.value <= 0) {
setError(localize("The tolerance must be positive."));
return;
}
var arguments = getArguments();
if (arguments.length != 2) {
setError(localize("Output path not specified."));
// do not close
return;
}
// store settings
var path = arguments[1];
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.CreateTextFile(path, true);
f.WriteLine("comment=" + comment.value);
f.WriteLine("arc=" + getCheckedValue(arc));
f.WriteLine("showblocknumbers=" + showblocknumbers.checked);
f.WriteLine("blocknumberincrement=" + blocknumberincrement.value);
f.WriteLine("tolerance=" + tolerance.value);
f.Close();
window.close();
}
</script>