Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Amanda Ghassaei
DMDesign
Commits
e52de847
Commit
e52de847
authored
Aug 21, 2015
by
Amanda Ghassaei
Browse files
runtime check for custom functions
parent
420a3874
Changes
2
Hide whitespace changes
Inline
Side-by-side
js/cam/assemblers/AssemblerPost.js
View file @
e52de847
...
@@ -27,23 +27,23 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -27,23 +27,23 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
blOvershoot
:
1.0
blOvershoot
:
1.0
};
};
this
.
customHeader
=
function
(
exporter
,
settings
,
context
){
this
.
customHeader
=
function
(
exporter
,
settings
,
context
,
self
){
var
data
=
""
;
var
data
=
""
;
data
+=
exporter
.
setUnits
(
settings
.
units
);
data
+=
exporter
.
setUnits
(
settings
.
units
);
data
+=
this
.
customHome
(
exporter
,
settings
,
context
);
data
+=
self
.
customHome
(
exporter
,
settings
,
context
);
return
data
;
return
data
;
};
};
this
.
_loadFunction
(
json
.
customPost
,
"
customHeader
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customHeader
"
);
this
.
customFooter
=
function
(
exporter
,
settings
,
context
){
this
.
customFooter
=
function
(
exporter
,
settings
,
context
,
self
){
var
data
=
""
;
var
data
=
""
;
data
+=
this
.
customHome
(
exporter
,
settings
,
context
);
data
+=
self
.
customHome
(
exporter
,
settings
,
context
);
return
data
;
return
data
;
};
};
this
.
_loadFunction
(
json
.
customPost
,
"
customFooter
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customFooter
"
);
this
.
customHome
=
function
(
exporter
,
settings
,
context
){
this
.
customHome
=
function
(
exporter
,
settings
,
context
,
self
){
var
data
=
""
;
var
data
=
""
;
data
+=
exporter
.
goHome
(
settings
);
data
+=
exporter
.
goHome
(
settings
);
return
data
;
return
data
;
...
@@ -51,14 +51,14 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -51,14 +51,14 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
this
.
_loadFunction
(
json
.
customPost
,
"
customHome
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customHome
"
);
this
.
customPickUpStock
=
function
(
exporter
,
settings
,
context
){
//not relevant for your assembler
this
.
customPickUpStock
=
function
(
exporter
,
settings
,
context
,
self
){
//not relevant for your assembler
var
data
=
""
;
var
data
=
""
;
return
data
;
return
data
;
};
};
this
.
_loadFunction
(
json
.
customPost
,
"
customPickUpStock
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customPickUpStock
"
);
this
.
customChangeZLayer
=
function
(
currentIndex
,
lastIndex
,
exporter
,
settings
,
context
){
this
.
customChangeZLayer
=
function
(
currentIndex
,
lastIndex
,
exporter
,
settings
,
context
,
self
){
var
data
=
""
;
var
data
=
""
;
if
(
lastIndex
===
null
||
(
currentIndex
.
z
-
lastIndex
.
z
)
%
2
!=
0
){
if
(
lastIndex
===
null
||
(
currentIndex
.
z
-
lastIndex
.
z
)
%
2
!=
0
){
data
+=
exporter
.
addLine
(
"
G0
"
,
[
"
A
"
+
(
currentIndex
.
z
%
2
*
0.3125
).
toFixed
(
4
)],
"
new layer
"
);
data
+=
exporter
.
addLine
(
"
G0
"
,
[
"
A
"
+
(
currentIndex
.
z
%
2
*
0.3125
).
toFixed
(
4
)],
"
new layer
"
);
...
@@ -69,7 +69,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -69,7 +69,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
this
.
_loadFunction
(
json
.
customPost
,
"
customChangeZLayer
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customChangeZLayer
"
);
this
.
customMoveXY
=
function
(
position
,
lastPosition
,
index
,
exporter
,
settings
,
context
){
//already offset for dual heads
this
.
customMoveXY
=
function
(
position
,
lastPosition
,
index
,
exporter
,
settings
,
context
,
self
){
//already offset for dual heads
var
data
=
""
;
var
data
=
""
;
var
overshoot
=
false
;
var
overshoot
=
false
;
...
@@ -94,7 +94,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -94,7 +94,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
this
.
_loadFunction
(
json
.
customPost
,
"
customMoveXY
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customMoveXY
"
);
this
.
customPlacePart
=
function
(
position
,
index
,
material
,
exporter
,
settings
,
context
){
//already offset for dual heads
this
.
customPlacePart
=
function
(
position
,
index
,
material
,
exporter
,
settings
,
context
,
self
){
//already offset for dual heads
var
data
=
""
;
var
data
=
""
;
data
+=
exporter
.
rapidZ
(
position
.
z
+
settings
.
safeHeight
,
settings
);
data
+=
exporter
.
rapidZ
(
position
.
z
+
settings
.
safeHeight
,
settings
);
data
+=
exporter
.
moveZ
(
position
.
z
-
context
.
zPreload
,
settings
);
data
+=
exporter
.
moveZ
(
position
.
z
-
context
.
zPreload
,
settings
);
...
@@ -116,19 +116,19 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -116,19 +116,19 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
this
.
_loadFunction
(
json
.
customPost
,
"
customPlacePart
"
);
this
.
_loadFunction
(
json
.
customPost
,
"
customPlacePart
"
);
this
.
customCalcPositionOffsets
=
function
(
index
,
position
,
material
,
settings
,
context
){
this
.
customCalcPositionOffsets
=
function
(
index
,
position
,
material
,
settings
,
context
,
self
){
//this feeds into moveXY and placePart functions
//this feeds into moveXY and placePart functions
position
.
sub
(
settings
.
originPosition
);
position
.
sub
(
settings
.
originPosition
);
if
(
index
.
z
%
2
!=
0
){
if
(
index
.
z
%
2
!=
0
){
//offset for rotation
//offset for rotation
var
offset
=
this
.
components
.
substrate
.
centerOfRotation
.
clone
().
multiplyScalar
(
settings
.
scale
);
//offset in mm
var
offset
=
self
.
components
.
substrate
.
centerOfRotation
.
clone
().
multiplyScalar
(
settings
.
scale
);
//offset in mm
var
dist
=
position
.
clone
().
sub
(
offset
);
var
dist
=
position
.
clone
().
sub
(
offset
);
position
=
offset
.
add
(
new
THREE
.
Vector3
(
dist
.
y
,
-
dist
.
x
,
position
.
z
));
position
=
offset
.
add
(
new
THREE
.
Vector3
(
dist
.
y
,
-
dist
.
x
,
position
.
z
));
}
}
var
stock
=
_
.
find
(
this
.
stock
,
function
(
thisStock
){
var
stock
=
_
.
find
(
self
.
stock
,
function
(
thisStock
){
return
thisStock
.
getMaterial
()
==
material
return
thisStock
.
getMaterial
()
==
material
});
});
if
(
stock
===
undefined
)
{
if
(
stock
===
undefined
)
{
...
@@ -168,10 +168,21 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -168,10 +168,21 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
//post process
//post process
AssemblerPost
.
prototype
.
_tryCustomFunction
=
function
(
name
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
){
try
{
var
data
=
this
[
name
](
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
);
return
data
;
}
catch
(
error
){
console
.
warn
(
"
runtime error in your custom post processing function
"
+
name
+
"
:
"
+
error
.
message
+
"
\n
"
+
"
skipping this function, gcode will be missing something
"
);
}
return
""
;
};
AssemblerPost
.
prototype
.
postProcess
=
function
(
settings
,
exporter
){
//called from outside);
AssemblerPost
.
prototype
.
postProcess
=
function
(
settings
,
exporter
){
//called from outside);
var
data
=
""
;
var
data
=
""
;
data
+=
this
.
customHeader
(
exporter
,
settings
,
this
.
customFunctionsContext
);
data
+=
this
.
_tryCustomFunction
(
"
customHeader
"
,
exporter
,
settings
,
this
.
customFunctionsContext
,
this
);
data
+=
exporter
.
newLine
();
data
+=
exporter
.
newLine
();
data
+=
exporter
.
newLine
();
data
+=
exporter
.
newLine
();
...
@@ -189,7 +200,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -189,7 +200,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
data
+=
exporter
.
newLine
();
data
+=
exporter
.
newLine
();
data
+=
this
.
customFooter
(
exporter
,
settings
,
this
.
customFunctionsContext
);
data
+=
this
.
_tryCustomFunction
(
"
customFooter
"
,
exporter
,
settings
,
this
.
customFunctionsContext
,
this
);
return
data
;
return
data
;
};
};
...
@@ -240,7 +251,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -240,7 +251,7 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
AssemblerPost
.
prototype
.
_postGetStock
=
function
(
index
,
lastIndex
,
position
,
material
,
settings
,
exporter
,
context
){
AssemblerPost
.
prototype
.
_postGetStock
=
function
(
index
,
lastIndex
,
position
,
material
,
settings
,
exporter
,
context
){
var
data
=
""
;
var
data
=
""
;
if
(
lastIndex
===
null
||
lastIndex
.
z
!=
index
.
z
){
if
(
lastIndex
===
null
||
lastIndex
.
z
!=
index
.
z
){
data
+=
this
.
customChangeZLayer
(
index
,
lastIndex
,
exporter
,
settings
,
context
)
data
+=
this
.
_tryCustomFunction
(
"
customChangeZLayer
"
,
index
,
lastIndex
,
exporter
,
settings
,
context
,
this
)
}
}
data
+=
exporter
.
addComment
(
"
get stock
"
+
JSON
.
stringify
(
index
));
data
+=
exporter
.
addComment
(
"
get stock
"
+
JSON
.
stringify
(
index
));
return
data
;
return
data
;
...
@@ -251,17 +262,17 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
...
@@ -251,17 +262,17 @@ define(['underscore', 'appState', 'lattice', 'cam'], function(_, appState, latti
// position.add(new THREE.Vector3(18.23*((index.z)%2), 0.3*((index.z)%2), 0));
// position.add(new THREE.Vector3(18.23*((index.z)%2), 0.3*((index.z)%2), 0));
var
position
=
this
.
customCalcPositionOffsets
(
index
,
position
,
material
,
settings
,
context
);
var
position
=
this
.
_tryCustomFunction
(
"
customCalcPositionOffsets
"
,
index
,
position
,
material
,
settings
,
context
,
this
);
if
(
position
===
null
)
return
data
;
if
(
position
===
null
||
position
==
""
)
return
data
;
// (5.08mm, 5.715mm)
// (5.08mm, 5.715mm)
// x = part_pos[0]*1.27 + 18.23*((layer+1)%2)
// x = part_pos[0]*1.27 + 18.23*((layer+1)%2)
// y = part_pos[1]*1.27 + 0.3*((layer+1)%2)
// y = part_pos[1]*1.27 + 0.3*((layer+1)%2)
data
+=
this
.
customMoveXY
(
position
.
clone
(),
exporter
.
getPostPosition
(),
index
.
clone
(),
exporter
,
settings
,
context
);
data
+=
this
.
_tryCustomFunction
(
"
customMoveXY
"
,
position
.
clone
(),
exporter
.
getPostPosition
(),
index
.
clone
(),
exporter
,
settings
,
context
,
this
);
data
+=
this
.
customPlacePart
(
position
.
clone
(),
index
.
clone
(),
material
,
exporter
,
settings
,
context
);
data
+=
this
.
_tryCustomFunction
(
"
customPlacePart
"
,
position
.
clone
(),
index
.
clone
(),
material
,
exporter
,
settings
,
context
,
this
);
return
data
;
return
data
;
};
};
...
...
js/menus/ScriptView.js
View file @
e52de847
...
@@ -65,6 +65,7 @@ define(['jquery', 'underscore', 'backbone', 'appState', 'codeMirror', 'globals',
...
@@ -65,6 +65,7 @@ define(['jquery', 'underscore', 'backbone', 'appState', 'codeMirror', 'globals',
try
{
try
{
eval
(
js
);
eval
(
js
);
this
.
saveCallback
(
js
);
this
.
saveCallback
(
js
);
this
.
_hide
();
}
catch
(
error
){
}
catch
(
error
){
this
.
render
(
error
.
message
);
this
.
render
(
error
.
message
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment