Permalink
Fetching contributors…
Cannot retrieve contributors at this time
1002 lines (791 sloc) 31.1 KB
/***************************************************************
* (c) 2014 SKAARHOJ K/S, www.skaarhoj.com
* Author: Kasper Skårhøj <kasper@skaarhoj.com>
*
* This script is Open Source under GNU/GPL license.
* See bottom for more details.
*
* Licensed to Schaeffer AG for inclusion with Front Panel Designer.
***************************************************************/
/*************************************************************
* This is a JavaScript program written for a software called
* Front Panel Designer made by Schaeffer AG.
* Front Panel Designer is a CAD application for design and
* online ordering of aluminum panels and this script will create
* several such panels based on input parameters. The panels will
* form a full enclosure when assembled.
*
* The enclosures generated with this script is based on two front panels where one is
* being bend (by hand) in four directions to form a 5 sided box where the other panel (bottom) is then
* mount on to.
*
* See http://skaarhoj.com/schaeffer/ for latest version, other
* tools and training resources published by SKAARHOJ K/S.
*
* - kasper
**************************************************************/
// Set this to "false" if you want to manually adjust parameters below:
var C_UI = true;
/***************************************
* Global Settings for enclosure creation.
* Adapt to your needs for full flexibility
*
* All measures in mm. (25.4 mm = 1 inch)
***************************************/
// WIDTH, HEIGHT, DEPTH of enclosure (outer measures):
var C_width = 120; // From left to right
var C_height = 40; // From bottom to top
var C_depth = 80; // From front to back plane
// Thickness of plates: 2, 2.5, 3, 4 mm possible
var C_thickness = new Array(
2.5, // Top piece
6 // Bottom piece
);
// Colors: These are constants from Schaeffers Scripting API manual
var C_color = new Array(
elox_natural, // Top piece
elox_natural // Bottom piece
);
// Housing Brackets:
var C_numberOfHousingBracketsToBottom = new Array(3,1,2,2); // (Front, Left, Back, Right). Defines the number of housing brackets used on the front for each side panel. -1 will automatically place them pr. 100 mm.
// Ordering
var C_createOrder = false; // If true, will create an order and add the accessories (profiles, assembly kits etc.)
var C_addGuideEngravings = true; // This will add thin, orange engraved lines for preview of where adjacent components (panels, profiles and brackets) are located on each side. Can be useful for positioning other elements after which they should be removed before ordering.
var C_panelNamesPrefix = ""; // A panel name prefix
var C_panelNamesSuffix = ""; // A panel name suffix
var C_internalBottom = false; // If set, the bottom panel is placed inside of the top-cover.
var C_addEdgeGrinding = true;
var C_roundedCorners = true;
if (C_UI) {
if (typeof C_FourFoldHousings_UI_width === 'undefined') {
var C_FourFoldHousings_UI_width = C_width;
}
if (typeof C_FourFoldHousings_UI_height === 'undefined') {
var C_FourFoldHousings_UI_height = C_height;
}
if (typeof C_FourFoldHousings_UI_depth === 'undefined') {
var C_FourFoldHousings_UI_depth = C_depth;
}
if (typeof C_FourFoldHousings_UI_thickness === 'undefined') {
var C_FourFoldHousings_UI_thickness = 0;
}
if (typeof C_FourFoldHousings_UI_color === 'undefined') {
var C_FourFoldHousings_UI_color = 0;
}
if (typeof C_FourFoldHousings_UI_guideObjects === 'undefined') {
var C_FourFoldHousings_UI_guideObjects = 1;
}
if (typeof C_FourFoldHousings_UI_createOrder === 'undefined') {
var C_FourFoldHousings_UI_createOrder = 0;
}
showUI();
C_FourFoldHousings_UI_width = C_width;
C_FourFoldHousings_UI_height = C_height;
C_FourFoldHousings_UI_depth = C_depth;
}
// ###MARKER_POSTCONFIG###
/**********************************************************************
* NO USER SETTING BELOW!
**********************************************************************/
function showUI() {
var d = new Dialog("Four Fold-box - a housing based on a top panel with bends and a bottom",500,100); // create the dialog window
d.Newline().VSpacer(0).NewlineC();
var height = new Param(C_FourFoldHousings_UI_height.toString());
d.Spacer(25).Text("Height:");
d.Spacer(10).TextEntry(1, height).Spacer(5).Text("mm").Spacer(0).NewlineC();
var width = new Param(C_FourFoldHousings_UI_width.toString());
d.Spacer(25).Text("Width:");
d.Spacer(13).TextEntry(1, width).Spacer(5).Text("mm").Spacer(0).NewlineC();
var depth = new Param(C_FourFoldHousings_UI_depth.toString());
d.Spacer(25).Text("Depth:");
d.Spacer(10).TextEntry(1, depth).Spacer(5).Text("mm").Spacer(0).NewlineC();
d.VSpacer(10).Newline();
var thickness = new Param(C_FourFoldHousings_UI_thickness);
d.Spacer(25).Text("Thickness of panels:").NewlineC();
d.Spacer(25).RadioBox(thickness," \n2 mm\n2.5 mm\n3 mm\n4 mm").Spacer(0).NewlineC();
var thicknessCodes = new Array(2,2.5,3,4);
d.VSpacer(20).Newline();
var color = new Param(C_FourFoldHousings_UI_color);
d.Spacer(25).Text("Color of panels:").NewlineC();
d.Spacer(25).RadioBox(color, " \nNatural\nGold\nRed\nBlue\nGreen\nBlack").Spacer(25).NewlineC();
var colorCodes = new Array(elox_natural,elox_gold,elox_red,elox_blue,elox_green,elox_black);
d.VSpacer(20).Newline();
var guideObjects = new Param(C_FourFoldHousings_UI_guideObjects);
d.Spacer(25).CheckBox(guideObjects, "Add guide engravings?").NewlineC();
var createOrder = new Param(C_FourFoldHousings_UI_createOrder);
d.Spacer(25).CheckBox(createOrder, "Create order with housing brackets?").NewlineC();
d.Divider().NewlineC();
// And an "Ok" button, which, when pressed, will close
// the dialog, returning 1 from Show().
d.Spacer(0).DlgButton(1, "Create!").Spacer(0);
// Show dialog, pressed button is returned but not used
// in this example.
var b = d.Show();
C_FourFoldHousings_UI_thickness = thickness.get();
C_FourFoldHousings_UI_color = color.get();
C_FourFoldHousings_UI_guideObjects = guideObjects.get();
C_FourFoldHousings_UI_createOrder = createOrder.get();
// Transferring values from UI to global variables:
Print("\n\nConfiguration values:\n")
C_height = parseFloat(height.get());
C_width = parseFloat(width.get());
C_depth = parseFloat(depth.get());
Print("C_height="+C_height+"\n")
Print("C_width="+C_width+"\n")
Print("C_depth="+C_depth+"\n")
C_thickness = new Array(
thicknessCodes[thickness.get()],
thicknessCodes[thickness.get()]
);
Print("C_thickness=["+C_thickness+"]\n")
C_color = new Array(
colorCodes[color.get()],
colorCodes[color.get()]
);
Print("C_color=["+C_color+"]\n")
C_addGuideEngravings = guideObjects.get() ? true : false;
Print("C_addGuideEngravings="+(C_addGuideEngravings?"Yes":"No")+"\n")
C_createOrder = createOrder.get() ? true : false;
Print("C_createOrder="+(C_createOrder?"Yes":"No")+"\n")
}
/**************************
* Various computations and
* initializations and constants:
**************************/
var globalHousingBracketCount = 0;
var bendCompensation = 0.4; // Assumed bending radius, forward
var housingBracketAutoInterval = 100; // The minimal interval between automatically placed housing brackets
/***************************************************************************
* Configuration value getter-methods and helper functions
* panelNum = {1,2} = {top , bottom} panels
***************************************************************************/
function getThickness(panelNum) {
return C_thickness[panelNum-1];
}
function getColor(panelNum) {
return C_color[panelNum-1];
}
/**
* Returns the width of the panel
*/
function getPanelWidth(panelNum) { // panelNum = {1,2}
switch(panelNum) {
case 1:
return (C_height - (!C_internalBottom ? C_thickness[1] : 0) - bendCompensation)*2 +
C_width-2*bendCompensation;
break;
case 2:
return C_width - (C_internalBottom ? C_thickness[0]*2 : 0);
break;
}
}
/**
* Returns the height of the panel
*/
function getPanelHeight(panelNum) { // panelNum = {1,2}
switch(panelNum) {
case 1:
return (C_height - (!C_internalBottom ? C_thickness[1] : 0) - bendCompensation)*2 +
C_depth-2*bendCompensation;
break;
case 2:
return C_depth - (C_internalBottom ? C_thickness[0]*2 : 0);
break;
}
}
/**
* Get center coordinates of any of the box faces.
* See also getFaceBoxDimensions() for more information.
*/
function getFaceCenterCoordinates(sideNum) {
var result = new Array(0,0);
// X:
switch(sideNum) {
case 1: // Front
case 2: // Top
case 3: // Back
result[0] = getPanelWidth(1)/2; // The panel is symmetric in case extra width is added
break;
case 4: // Bottom
result[0] = getPanelWidth(2)/2;
break;
case 5: // Left
result[0] = C_height/2 - (!C_internalBottom ? C_thickness[1] : 0);
break;
case 6: // Right
result[0] = getPanelWidth(1)-(C_height/2 - (!C_internalBottom ? C_thickness[1] : 0));
break;
}
// Y:
switch(sideNum) {
case 1: // Front (lowest section, top panel)
result[1] = C_height/2 - (!C_internalBottom ? C_thickness[1] : 0);
break;
case 2: // Top (Middle section, top panel)
result[1] = getPanelHeight(1)/2;
break;
case 3: // Back (highest section, top panel)
result[1] = getPanelHeight(1) - (C_height/2 - (!C_internalBottom ? C_thickness[1] : 0));
break;
case 4: // Bottom (Middle section, bottom panel)
result[1] = getPanelHeight(2)/2;
break;
case 5: // Left (Highest section, bottom panel)
case 6: // Right (Lowest section, bottom panel)
result[1] = getPanelHeight(1)/2;
break;
}
return result;
}
/**
* Get dimensions of any of the box faces.
* A box face is the area on the side which corresponds to the actual box dimensions as they are given in the input parameters.
*/
function getFaceBoxDimensions(sideNum) {
switch(sideNum) {
case 1: // Front
return new Array(C_width,C_height);
break;
case 2: // Top
return new Array(C_width,C_depth);
break;
case 3: // Back
return new Array(C_width,C_height);
break;
case 4: // Bottom
return new Array(C_width, C_depth);
break;
case 5: // Left
return new Array(C_height, C_depth);
break;
case 6: // Right
return new Array(C_height, C_depth);
break;
}
}
/**
* This will optimize the radius for cavities to the max and select the largest tool possible (to save costs)
*/
function setRadiusAndToolForCavity(cv) {
var width = cv.Width();
var height = cv.Height();
var min = width<height ? width : height;
var rad = min/2>1.5 ? 1.5 : min/2;
cv.SetCornerRadius(rad);
if (rad==1.5) {
cv.SetTool(cutter_3_0mm);
}
}
/**
* This will add a bending cavity
*/
function addBendingCavity(fp, x, y, w, rotated) {
var el = new Cavity("el");
var panel = 1;
el.SetDepth(1); // Temporary depth, necessary for scripting engine (v4.4)
fp.AddElement(el, x, y);
el.MakeRectangular(w, 3, getThickness(panel)-0.5, 0.5);
el.SetHeight(1);
el.Rotate(rotated?90:0);
setRadiusAndToolForCavity(el);
el.SetEdgeMachining(bevel_45, getThickness(panel)-0.5-0.2, 0, 0);
el.PutOnReverseSide();
}
/**
* Adding a number of housing brackets to a panel
* Orientation: 0=normal, 90= turned 90 CW, -90=turned 90 CCW, 180 = 180
*/
function addHousingBrackets(fp, baselineX, baselineY, orientation, number, distibutionWidth, useStuds, reverseNumbering, noNumbering) {
var housingBrackets = number==-1 ? (parseInt(distibutionWidth/housingBracketAutoInterval)<=0 ? 1 : parseInt(distibutionWidth/housingBracketAutoInterval)) : number;
if (housingBrackets>0) {
var housingBracketDist = housingBrackets>1 ? (distibutionWidth-10) / (housingBrackets-1) : 0;
var housingBracketStartOffset = housingBrackets>1 ? housingBracketDist*(housingBrackets-1)/2 : 0;
for(var a=0;a<housingBrackets;a++) {
if (useStuds) {
var el = new Bolt("el", "GU30", 8);
} else {
var el = new DrillHole("el", 3.00);
el.SetCountersink(sink_74A_M3);
}
globalHousingBracketCount+=1;
switch(orientation) {
case 90:
var oSet = baselineY-(housingBracketStartOffset-housingBracketDist*a)*(reverseNumbering?-1:1);
fp.AddElement(el, baselineX+6.5, oSet);
if (C_addGuideEngravings) {
fp.AddElement(new Rectangle("el", 10, 10).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
baselineX+5, oSet);
if (!noNumbering) {
fp.AddElement(new TextEngraving("el", globalHousingBracketCount).SetTextHeight(1.5).SetHelpElement(true),
baselineX+1, oSet-4);
}
}
break;
case -90:
var oSet = baselineY-(housingBracketStartOffset-housingBracketDist*a)*(reverseNumbering?-1:1);
fp.AddElement(el, baselineX-6.5, oSet);
if (C_addGuideEngravings) {
fp.AddElement(new Rectangle("el", 10, 10).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
baselineX-5, oSet);
if (!noNumbering) {
fp.AddElement(new TextEngraving("el", globalHousingBracketCount).SetTextHeight(1.5).SetHelpElement(true),
baselineX-9, oSet-4);
}
}
break;
case 180:
var oSet = baselineX-(housingBracketStartOffset-housingBracketDist*a)*(reverseNumbering?-1:1);
fp.AddElement(el, oSet, baselineY-6.5);
if (C_addGuideEngravings) {
fp.AddElement(new Rectangle("el", 10, 10).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
oSet, baselineY-5);
if (!noNumbering) {
fp.AddElement(new TextEngraving("el", globalHousingBracketCount).SetTextHeight(1.5).SetHelpElement(true),
oSet-4, baselineY-9);
}
}
break;
default:
var oSet = baselineX-(housingBracketStartOffset-housingBracketDist*a)*(reverseNumbering?-1:1);
fp.AddElement(el, oSet, baselineY+6.5);
if (C_addGuideEngravings) {
fp.AddElement(new Rectangle("el", 10, 10).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
oSet, baselineY+5);
if (!noNumbering) {
fp.AddElement(new TextEngraving("el", globalHousingBracketCount).SetTextHeight(1.5).SetHelpElement(true),
oSet-4, baselineY+1);
}
}
break;
}
}
}
}
/**
* Creates a DXF shape from input set of coordinates/radii
*/
function shapeFromCoordinates(coordinateSet) {
var dxf = new DxfContour("dxf-canvas1", "", 5, 100, 0);
var len = coordinateSet.length;
for(var i=0; i<=len; i++) {
if (i==0) {
if (coordinateSet[0][2]) { // there is a radius
var cornerCoordinates = roundedCorner(coordinateSet[0][0],coordinateSet[0][1], coordinateSet[len-1][0],coordinateSet[len-1][1], coordinateSet[1][0],coordinateSet[1][1], coordinateSet[0][2]);
dxf.Start(cornerCoordinates[4],cornerCoordinates[5]);
} else { // none
dxf.Start(coordinateSet[0][0],coordinateSet[0][1]);
}
} else {
if (coordinateSet[(i%len)][2]) { // there is a radius
var cornerCoordinates = roundedCorner(coordinateSet[(i%len)][0],coordinateSet[(i%len)][1], coordinateSet[(i-1)%len][0],coordinateSet[(i-1)%len][1], coordinateSet[(i+1)%len][0],coordinateSet[(i+1)%len][1], coordinateSet[(i%len)][2]);
dxf.LineTo(cornerCoordinates[2],cornerCoordinates[3]);
dxf.ArcToMP(cornerCoordinates[4],cornerCoordinates[5],cornerCoordinates[0],cornerCoordinates[1], cornerCoordinates[6]);
} else { // none
dxf.LineTo(coordinateSet[(i%len)][0],coordinateSet[(i%len)][1]);
}
}
}
dxf.Finish();
return dxf;
}
/**
* Calculates necessary coordinates for a rounded corner
*/
function roundedCorner(x,y, srcX,srcY, destX,destY, radius) {
var result = new Array(0,0,0,0,0,0,1); // centerX, centerY, srcAttachX, srcAttachY, destAttachX, destAttachY, rotationDirection
var alpha1 = getAngleOfLine(x,srcX,y,srcY);
var alpha2 = getAngleOfLine(x,destX,y,destY);
// Print("alpha1="+alpha1/Math.PI*180+"\n");
// Print("alpha2="+alpha2/Math.PI*180+"\n");
var angleDiff = alpha2-alpha1;
if (angleDiff < -Math.PI) {
angleDiff+= 2*Math.PI;
} else if (angleDiff > Math.PI) {
angleDiff-= 2*Math.PI;
}
var halfAngle = angleDiff/2;
// Print("halfAngle="+halfAngle/Math.PI*180+"\n");
var distFromXYpoint = Math.abs(radius / Math.sin(halfAngle));
// Print("distFromXYpoint="+distFromXYpoint+"\n");
var travelUpOnEachLine = Math.cos(halfAngle)*distFromXYpoint;
// Print("travelUpOnEachLine="+travelUpOnEachLine+"\n");
var angleOfCenterLine = alpha1+halfAngle;
result[0] = translateXByAngle(x,angleOfCenterLine,distFromXYpoint);
result[1] = translateYByAngle(y,angleOfCenterLine,distFromXYpoint);
result[2] = translateXByAngle(x,alpha1,travelUpOnEachLine);
result[3] = translateYByAngle(y,alpha1,travelUpOnEachLine);
result[4] = translateXByAngle(x,alpha2,travelUpOnEachLine);
result[5] = translateYByAngle(y,alpha2,travelUpOnEachLine);
result[6] = halfAngle < 0 ? 1 : -1;
return result;
}
/**
* Returns the angle of a line given by it's x/y coordinates (two points)
*/
function getAngleOfLine(x1,x2,y1,y2) {
return (x2-x1)==0 ? (y2-y1 < 0?-1:1)*Math.PI/2 : Math.atan((y2-y1)/(x2-x1))+(x2-x1 < 0 ? Math.PI: 0);
}
/**
* Translates an X value in 2D a certain distance at a certain angle
*/
function translateXByAngle(x,alpha,dist) {
return rounding(x+Math.cos(alpha)*dist);
}
/**
* Translates a Y value in 2D a certain distance at a certain angle
*/
function translateYByAngle(y,alpha,dist) {
return rounding(y+Math.sin(alpha)*dist);
}
/**
* Rounding to 5 digits
*/
function rounding(input) {
return Math.round(input*100000)/100000;
}
function translateAllElementsOnPanel(fp,x,y) {
var els = fp.Elements();
els.forEach(function(el){
el.MoveTo(el.X()+x,el.Y()+y);
});
}
/************************
* Creator functions
* (Creates panels and orders)
*************************/
/**
* Create top panel
*
* @param string Name of panel
* @return Frontpanel Front panel object
*/
function createTop(name) {
// Create panel:
var fp = new Frontpanel(C_panelNamesPrefix+name+C_panelNamesSuffix, getThickness(1), getPanelWidth(1), getPanelHeight(1), alu_elox);
fp.SetMaterialColor(getColor(1));
var coordinates = new Array();
var center = getFaceCenterCoordinates(2); // Top
var dims = getFaceBoxDimensions(2); // Top
var offset = (dims[1]/2-getThickness(1));
// Start:
coordinates.push(new Array(center[0]-dims[0]/2, 0, C_roundedCorners?0.5:0));
// Left side:
coordinates.push(new Array(center[0]-dims[0]/2, center[1]-offset, 0));
coordinates.push(new Array(0, center[1]-offset, C_roundedCorners?0.5:0));
coordinates.push(new Array(0, center[1]+offset, C_roundedCorners?0.5:0));
coordinates.push(new Array(center[0]-dims[0]/2, center[1]+offset, 0));
fp.AddElement(new RectHole("el", 3, 3, 0.5), center[0]-dims[0]/2-1.5, center[1]-offset-1.5);
fp.AddElement(new RectHole("el", 3, 3, 0.5), center[0]-dims[0]/2-1.5, center[1]+offset+1.5);
// Top:
coordinates.push(new Array(center[0]-dims[0]/2, getPanelHeight(1), C_roundedCorners?0.5:0));
coordinates.push(new Array(center[0]+dims[0]/2, getPanelHeight(1), C_roundedCorners?0.5:0));
// Right side:
coordinates.push(new Array(center[0]+dims[0]/2, center[1]+offset, 0));
coordinates.push(new Array(getPanelWidth(1), center[1]+offset, C_roundedCorners?0.5:0));
coordinates.push(new Array(getPanelWidth(1), center[1]-offset, C_roundedCorners?0.5:0));
coordinates.push(new Array(center[0]+dims[0]/2, center[1]-offset, 0));
fp.AddElement(new RectHole("el", 3, 3, 0.5), center[0]+dims[0]/2+1.5, center[1]+offset+1.5);
fp.AddElement(new RectHole("el", 3, 3, 0.5), center[0]+dims[0]/2+1.5, center[1]-offset-1.5);
// End:
coordinates.push(new Array(center[0]+dims[0]/2, 0, C_roundedCorners?0.5:0));
var dxf = shapeFromCoordinates(coordinates);
fp.SetBorderContour(dxf);
// BENDING CAVITIES:
var center = getFaceCenterCoordinates(2); // Top
var dims = getFaceBoxDimensions(2); // Top
addBendingCavity(fp, center[0], center[1]+(dims[1]/2-bendCompensation), dims[0]+2, false);
addBendingCavity(fp, center[0], center[1]-(dims[1]/2-bendCompensation), dims[0]+2, false);
addBendingCavity(fp, center[0]+(dims[0]/2-bendCompensation), center[1], dims[1]-0.5, true);
addBendingCavity(fp, center[0]-(dims[0]/2-bendCompensation), center[1], dims[1]-0.5, true);
// HOUSING BRACKETS, to bottom:
globalHousingBracketCount = 0; // Resetting for top panel
var center = getFaceCenterCoordinates(1); // Front
var dims = getFaceBoxDimensions(1); // Front
addHousingBrackets(fp, center[0],center[1]-dims[1]/2+C_thickness[1],0,C_numberOfHousingBracketsToBottom[0],dims[0]-30,false);
var center = getFaceCenterCoordinates(3); // Back
var dims = getFaceBoxDimensions(3); // Back
addHousingBrackets(fp, center[0],center[1]+dims[1]/2-C_thickness[1],180,C_numberOfHousingBracketsToBottom[2],dims[0]-30,false);
var center = getFaceCenterCoordinates(5); // Left
var dims = getFaceBoxDimensions(5); // Left
addHousingBrackets(fp, center[0]-dims[0]/2+C_thickness[1],center[1],90,C_numberOfHousingBracketsToBottom[1],dims[1]-30,false);
var center = getFaceCenterCoordinates(6); // Right
var dims = getFaceBoxDimensions(6); // Right
addHousingBrackets(fp, center[0]+dims[0]/2-C_thickness[1],center[1],-90,C_numberOfHousingBracketsToBottom[3],dims[1]-30,false);
// HOUSING BRACKETS, between sides:
var center = getFaceCenterCoordinates(1); // Front
var dims = getFaceBoxDimensions(1); // Front
// Front, left
addHousingBrackets(fp, center[0]-dims[0]/2+C_thickness[0],center[1],90,1,dims[1]-30,false,false,true);
// Front, right
addHousingBrackets(fp, center[0]+dims[0]/2-C_thickness[0],center[1],-90,1,dims[1]-30,false,false,true);
var center = getFaceCenterCoordinates(3); // Back
var dims = getFaceBoxDimensions(3); // Back
// Back, left
addHousingBrackets(fp, center[0]-dims[0]/2+C_thickness[0],center[1],90,1,dims[1]-30,false,false,true);
// Back, right
addHousingBrackets(fp, center[0]+dims[0]/2-C_thickness[0],center[1],-90,1,dims[1]-30,false,false,true);
var center = getFaceCenterCoordinates(5); // Left
var dims = getFaceBoxDimensions(5); // Left
// Left, left
addHousingBrackets(fp, center[0],center[1]+dims[1]/2-C_thickness[0],180,1,dims[0],false,false,true);
// Left, right
addHousingBrackets(fp, center[0],center[1]-dims[1]/2+C_thickness[0],0,1,dims[0],false,false,true);
var center = getFaceCenterCoordinates(6); // Right
var dims = getFaceBoxDimensions(6); // Right
// Right, left
addHousingBrackets(fp, center[0],center[1]+dims[1]/2-C_thickness[0],180,1,dims[0],false,false,true);
// Right, right
addHousingBrackets(fp, center[0],center[1]-dims[1]/2+C_thickness[0],0,1,dims[0],false,false,true);
// Guide engravings:
if (C_addGuideEngravings) {
// Front face
var center = getFaceCenterCoordinates(1); // Front
var dims = getFaceBoxDimensions(1); // Front
fp.AddElement( // "Box" outer area
new Rectangle("el", dims[0], dims[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement( // Inner free area (mounting)
new Rectangle("el", dims[0]-C_thickness[0]*2, dims[1]-C_thickness[0]-C_thickness[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]-(C_thickness[0]-C_thickness[1])/2
);
fp.AddElement(
new TextEngraving("el", "Front mounting area").SetAlignment(align_center).SetTextHeight(1.5).SetHelpElement(true),
center[0],
center[1]
);
// Top face
var center = getFaceCenterCoordinates(2); // Top
var dims = getFaceBoxDimensions(2); // Top
fp.AddElement( // "Box" outer area
new Rectangle("el", dims[0], dims[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement( // Inner free area (mounting)
new Rectangle("el", dims[0]-C_thickness[0]*2, dims[1]-C_thickness[0]*2).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement(
new TextEngraving("el", "Top mounting area").SetAlignment(align_center).SetTextHeight(1.5).SetHelpElement(true),
center[0],
center[1]
);
// Back face
var center = getFaceCenterCoordinates(3); // Back
var dims = getFaceBoxDimensions(3); // Back
fp.AddElement( // "Box" outer area
new Rectangle("el", dims[0], dims[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement( // Inner free area (mounting)
new Rectangle("el", dims[0]-C_thickness[0]*2, dims[1]-C_thickness[0]-C_thickness[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]+(C_thickness[0]-C_thickness[1])/2
);
fp.AddElement(
new TextEngraving("el", "Back mounting area").SetAlignment(align_center).SetAngle(180).SetTextHeight(1.5).SetHelpElement(true),
center[0],
center[1]
);
// Left face
var center = getFaceCenterCoordinates(5); // Left
var dims = getFaceBoxDimensions(5); // Left
fp.AddElement( // "Box" outer area
new Rectangle("el", dims[0], dims[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement( // Inner free area (mounting)
new Rectangle("el", dims[0]-C_thickness[0]-C_thickness[1], dims[1]-C_thickness[0]*2).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0]-(C_thickness[0]-C_thickness[1])/2,
center[1]
);
fp.AddElement(
new TextEngraving("el", "Left\nmounting\narea").SetAlignment(align_center).SetTextHeight(1.5).SetHelpElement(true),
center[0],
center[1]
);
// Right face
var center = getFaceCenterCoordinates(6); // Right
var dims = getFaceBoxDimensions(6); // Right
fp.AddElement( // "Box" outer area
new Rectangle("el", dims[0], dims[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement( // Inner free area (mounting)
new Rectangle("el", dims[0]-C_thickness[0]-C_thickness[1], dims[1]-C_thickness[0]*2).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0]+(C_thickness[0]-C_thickness[1])/2,
center[1]
);
fp.AddElement(
new TextEngraving("el", "Right\nmounting\narea").SetAlignment(align_center).SetTextHeight(1.5).SetHelpElement(true),
center[0],
center[1]
);
}
// Edge grinding
if (C_addEdgeGrinding) {
fp.SetRemark("Please grind the edges.");
}
fp.UnsetModified().GridOff();
return fp;
}
/**
* Create bottom panel
*
* @param string Name of panel
* @return Frontpanel Front panel object
*/
function createBottom(name) {
// Create panel:
var fp = new Frontpanel(C_panelNamesPrefix+name+C_panelNamesSuffix, getThickness(2), getPanelWidth(2), getPanelHeight(2), alu_elox);
fp.SetMaterialColor(getColor(2));
// HOUSING BRACKETS:
// NOTICE: Order below is important for correct numbering of housing brackets.
// Front, bottom
var center = getFaceCenterCoordinates(4);
var dims = getFaceBoxDimensions(4);
globalHousingBracketCount = 0; // Resetting for top panel
addHousingBrackets(fp, center[0],center[1]+dims[1]/2-C_thickness[0],180,C_numberOfHousingBracketsToBottom[0],dims[0]-30,false);
// Back, bottom
addHousingBrackets(fp, center[0],center[1]-dims[1]/2+C_thickness[0],0,C_numberOfHousingBracketsToBottom[2],dims[0]-30,false);
// Left, bottom
addHousingBrackets(fp, center[0]-dims[0]/2+C_thickness[0],center[1],90,C_numberOfHousingBracketsToBottom[1],dims[1]-30,false,true);
// Right, bottom
addHousingBrackets(fp, center[0]+dims[0]/2-C_thickness[0],center[1],-90,C_numberOfHousingBracketsToBottom[3],dims[1]-30,false,true);
// Housing brackets for corners:
globalHousingBracketCount+=4;
// Guide engravings:
if (C_addGuideEngravings) {
// Bottom face
var center = getFaceCenterCoordinates(4); // Bottom
var dims = getFaceBoxDimensions(4); // Bottom
fp.AddElement( // "Box" outer area
new Rectangle("el", dims[0], dims[1]).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement( // Inner free area (mounting)
new Rectangle("el", dims[0]-C_thickness[0]*2, dims[1]-C_thickness[0]*2).SetCornerRadius(0).SetTool(engraver_0_2mm).SetHelpElement(true),
center[0],
center[1]
);
fp.AddElement(
new TextEngraving("el", "Bottom mounting area").SetAlignment(align_center).SetAngle(-90).SetTextHeight(1.5).SetHelpElement(true),
center[0],
center[1]
);
// Labeling sides:
fp.AddElement(
new TextEngraving("el", "Back").SetAlignment(align_center).SetAngle(180).SetTextHeight(1.5).SetHelpElement(true),
getPanelWidth(2)/2,
-C_thickness[0]/2*(!C_internalBottom?-1:1)
);
// Labeling sides:
fp.AddElement(
new TextEngraving("el", "Front").SetAlignment(align_center).SetAngle(0).SetTextHeight(1.5).SetHelpElement(true),
getPanelWidth(2)/2,
getPanelHeight(2)+C_thickness[0]/2*(!C_internalBottom?-1:1)
);
// Labeling sides:
fp.AddElement(
new TextEngraving("el", "Left").SetAlignment(align_center).SetAngle(90).SetTextHeight(1.5).SetHelpElement(true),
-C_thickness[0]/2*(!C_internalBottom?-1:1),
getPanelHeight(2)/2
);
// Labeling sides:
fp.AddElement(
new TextEngraving("el", "Right").SetAlignment(align_center).SetAngle(-90).SetTextHeight(1.5).SetHelpElement(true),
getPanelWidth(2)+C_thickness[0]/2*(!C_internalBottom?-1:1),
getPanelHeight(2)/2
);
}
// Edge grinding
if (C_addEdgeGrinding) {
fp.SetRemark("Please grind the edges.");
}
fp.UnsetModified().GridOff();
return fp;
}
/**
* Create order
*/
function createOrder() {
// Housing brackets:
if (globalHousingBracketCount>0) {
if (globalHousingBracketCount<=4) {
OrderAddItem("GGWS0111",1); // Housing brackets x4
} else if (globalHousingBracketCount<=8) {
OrderAddItem("GGWS0112",1); // Housing brackets x8
} else if (globalHousingBracketCount<=12) {
OrderAddItem("GGWS0113",1); // Housing brackets x12
} else {
OrderAddItem("GGWS0114",Math.ceil(globalHousingBracketCount/25)); // Housing brackets x25
}
}
}
// Rotation 90 degress both ways:
function rotatePanel(fp,rotation) {
var width = fp.Width();
var height = fp.Height();
var els = fp.Elements();
switch(rotation) {
case 90:
fp.SetWidth(height);
fp.SetHeight(width);
els.forEach(function(el){
el.MoveTo(height-el.Y(),el.X());
el.Rotate(90);
});
break;
case -90:
case 270:
fp.SetWidth(height);
fp.SetHeight(width);
els.forEach(function(el){
el.MoveTo(el.Y(),width-el.X());
el.Rotate(-90);
});
break;
}
}
// ###MARKER_PREMAKE###
/**************************
* Execute...
**************************/
// Front-Top-Back (1)
var fp1 = createTop("Top");
AddFrontpanel(fp1);
// Right-Back-Left (2)
var fp2 = createBottom("Bottom");
AddFrontpanel(fp2);
// Create order with accessories:
if (C_createOrder) {
createOrder();
}
/***************************************************************
* (c) 2013-2014 SKAARHOJ K/S, www.skaarhoj.com
* Author: Kasper Skårhøj <kasper@skaarhoj.com>
* All rights reserved
*
* This script is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/