-
Notifications
You must be signed in to change notification settings - Fork 1
/
holes.js
92 lines (83 loc) · 4.06 KB
/
holes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
var mGlob = pfcCreate("MpfcCOMGlobal");
var objSession = mGlob.GetProESession();
var objCurrentModel = objSession.CurrentModel;
var arrModelHoles = objCurrentModel.ListFeaturesByType (false, pfcCreate ("pfcFeatureType").FEATTYPE_HOLE);
var objCurrentWindow = objSession.CurrentWindow;
function Main() {
var featStatusActive = pfcCreate("pfcFeatureStatus").FEAT_ACTIVE;
var UI = document.getElementById("UI");
var holesTable = document.getElementById("holesTable");
objCurrentModel.RetrieveView("Default");
if (objCurrentModel.Descr.Type == pfcCreate("pfcModelType").MDL_PART && objCurrentModel.GetParam("SE_MATERIAL_1").Value.StringValue.substring(0, 8) == "HUA17334" ) {
UI.innerHTML = objCurrentModel.InstanceName + " is a PCB<br />Material " + objCurrentModel.GetParam("SE_MATERIAL_1").Value.StringValue + "<br />" + arrModelHoles.Count + " holes found in the model to process<br />";
var outputTable = "<table><thead><tr><th>ID</th><th>State</th><th>Ecad hole type</th></tr></thead><tbody>";
for (var i = 0; i < arrModelHoles.Count; i++) {
if (arrModelHoles.Item(i).Status == featStatusActive){
if (arrModelHoles.Item(i).GetParam("ECAD_HOLE_TYPE") == void null) {
var holeState = "New Hole";
arrModelHoles.Item(i).CreateParam("ECAD_HOLE_TYPE", createParamValueFromString("NPTH"));
} else {
if (arrModelHoles.Item(i).GetParam("ECAD_HOLE_TYPE").Value.StringValue != "PTH" && arrModelHoles.Item(i).GetParam("ECAD_HOLE_TYPE").Value.StringValue != "NPTH" ) {
var holeState = "Not a valid value";
arrModelHoles.Item(i).GetParam("ECAD_HOLE_TYPE").Value = pfcCreate("MpfcModelItem").CreateStringParamValue("NPTH");
} else {
var holeState = "";
}
}
var holeType = arrModelHoles.Item(i).GetParam("ECAD_HOLE_TYPE").Value.StringValue;
outputTable += "<tr class='" + ( i % 2 > 0 ? "odd" : "even") + "'>";
outputTable += "<td class='theID'>" + arrModelHoles.Item(i).Id + "</td>";
outputTable += "<td>" + holeState + "</td>";
outputTable += "<td><select onmouseover='highlightHole (" + i + ")' id='" + i + "' onchange='updateValue(this)' ><option value='NPTH' " + (holeType == "NPTH" ? "selected" : "") + ">NPTH</option><option value='PTH' " + (holeType == "PTH" ? "selected" : "") + ">PTH</option></select>";
outputTable += "</tr>";
}
}
holesTable.innerHTML = outputTable + "</tbody></table>";
} else {
UI.innerHTML = "The model you are trying to process is not a PCB.";
}
}
function highlightHole (holeID) {
objCurrentWindow.Repaint();
pfcCreate ("MpfcSelect").CreateModelItemSelection(objCurrentModel.GetItemById(pfcCreate("pfcModelItemType").ITEM_FEATURE, arrModelHoles.Item(holeID).Id), null).Highlight(pfcCreate ("pfcStdColor").COLOR_QUILT);
}
function updateValue (element) {
arrModelHoles.Item(parseInt(element.id)).GetParam("ECAD_HOLE_TYPE").Value = pfcCreate("MpfcModelItem").CreateStringParamValue(element.value);
objSession.GetModelWindow(Model).Refresh();
}
function pfcIsWindows () {
if (navigator.appName.indexOf ("Microsoft") != -1) {
return true;
} else {
return false;
}
}
function pfcCreate (className) {
if (!pfcIsWindows()) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
if (pfcIsWindows()) {
return new ActiveXObject ("pfc."+className);
} else {
ret = Components.classes ["@ptc.com/pfc/" + className + ";1"].createInstance();
return ret;
}
}
function createParamValueFromString (s /* string */){
if (s.indexOf (".") == -1) {
var i = parseInt (s);
if (!isNaN(i))
return pfcCreate ("MpfcModelItem").CreateIntParamValue(i);
}
else
{
var d = parseFloat (s);
if (!isNaN(d))
return pfcCreate ("MpfcModelItem").CreateDoubleParamValue(d);
}
if (s.toUpperCase() == "Y" || s.toUpperCase ()== "TRUE")
return pfcCreate ("MpfcModelItem").CreateBoolParamValue(true);
if (s.toUpperCase() == "N" || s.toUpperCase ()== "FALSE")
return pfcCreate ("MpfcModelItem").CreateBoolParamValue(false);
return pfcCreate ("MpfcModelItem").CreateStringParamValue(s);
}