Pads

by d1wang

HTML

<div id="appWindow">
  <nav id="appHeader">
    <a href="#">Libraries</a>
    <a class="active" href="#">QFN-28</a>
    <select style="margin:0.25em;float:right;" onchange="switchMode()" id="viewMode">
      <option value="dark" selected="selected">Dark mode</option>
      <option value="natural">Natural mode</option>
    </select>
  </nav>

  <section id="appMain">
    <aside id="appSidebar">
      <div class="propEditor">
        <form>
          <select>
            <option>E-pad ts315</option>
            <option>Pad D d100_28</option>
          </select>
          <div class="field">
            <label for="fPadLength"><span class="sym">D<sub>2</sub> </span>E-pad length</label>
            <input  id="fPadLength" type="number" min="1" step="0.01" value="3.15"
                   onfocus="dim_highlight('RePG_d_D2')" onblur="dim_unhighlight('RePG_d_D2')">
          </div>
          <div class="field">
            <label for="fPadWidth"><span class="sym">E<sub>2</sub> </span>E-pad width</label>
            <input  id="fPadWidth" type="number" min="1" step="0.01" value="3.15"
                   onfocus="dim_highlight('RePG_d_E2')" onblur="dim_unhighlight('RePG_d_E2')">
          </div>
          <div class="field">
            <label for="fViaDiameter"><span class="sym">ϕV<sub></sub> </span>Via hole diameter</label>
            <input  id="fViaDiameter" type="number" step="0.01" min="0.1" max="0.5" value="0.3"
                   onfocus="dim_highlight('RePG_d_ϕV')" onblur="dim_unhighlight('RePG_d_ϕV')">
          </div>
          <div class="field">
            <label for="fViaPitchH"><span class="sym">d<sub>V</sub> </span>Via horizontal pitch</label>
            <input  id="fViaPitchH" type="number" step="0.1" min="0.1" value="1"
                   onfocus="dim_highlight('RePG_d_dV')" onblur="dim_unhighlight('RePG_d_dV')">
          </div>
          <div class="field">
            <label for="fViaPitchV"><span class="sym">e<sub>V</sub> </span>Via vertical...

CSS

html, body, #appWindow { height: 100%; }

body {
  margin: 0;
  font-family: Helvetica, Arial, Sans-Serif;
  font-size: 10pt;
}

/*
  appWindow
  - appHeader
  - appMain
    - appSidebar
    - appContent
*/

#appHeader {
  font-size: 12pt;
  height: 2em;
  padding: 0;
  background: #333;
  overflow: hidden;
}
#appMain {
  display: flex;
  height: calc(100% - 2em);
}
#appSidebar {
  overflow-y: auto;
  height: 100%;
  min-width: 300px;
  width: 26em;
}
#appContent {
  height: 100%;
  width: 100%;
  padding: 0;
  margin: 0;
  overflow: hidden;
}

#appHeader a {
  height: 2em;
  float: left;
  color: #f2f2f2;
  text-align: center;
  padding: 0.2em 0.5em;
  text-decoration: none;
}
#appHeader a:hover {
  background-color: #ddd;
  color: black;
}
#appHeader a.active {
  background: #4CAF50;
  color: white;
}

.propEditor {
  background-color:#4CAF50;
  margin: 0;
  padding: 0;
}


#pad {
  display:block;
  margin:0;
  width:100%;
  height: 100%;
}

#info {
  padding: 0.5em;
  border: 1px solid #909090;
  background-color: #f9f966;
}

#layers {
  padding: 0.5em;
  margin-bottom:0.25em;
  border: 1px solid #909090;
  background-color: #e0e0e0;
}

.field {
  display: block;
  padding: 0.2em;
}

.field label {
  display: inline-block;
  width: 15em;
}

.field label .sym {
  display: inline-block;
  width: 2em;
}

.field input[type='number'],
.field input[type='text'],
.field select {
  width: 5em;
  height: 1.2em;
  line-height: 1.2em;
  padding: 0 0.1em;
}

.field input,
.field select {
  vertical-align:middle;
}

.field input:focus,
.field select:focus {
  background-color:#ffa;
}

.field select {
  -webkit-appearance: menulist-button;
  height: 1.5em;
  background: #fff;
  font: inherit;
}

.field input:invalid:not(:focus) {
  background: pink;
}

.field:focus-within {
  background-color: #71c174;
}


.propEditor .action {
  display: block;
  padding: 0.2em;
  text-align: right;
}

.propEditor .action button {
  width: 8em;
  height: 2em;
}

.propEditor .action...

JavaScript

/* xported ARC_RES, CORNER_RAD */
/* xported calcArea */
/* xported rotateSegment180, reflectSegment45 */
/* xported mirrorSegmentV, mirrorSegmentH */
/* xported offsetSegment */
/* xported createArcSegment */

/**
 * Create an arc segment
 * @nosideeffects
 * @param {Number} cx X position of center
 * @param {Number} cy Y position of center
 * @param {Number} r Radius
 * @param {Number} startAngle Starting angle
 * @param {Number} stepAngle Angle increament
 * @param {Number} nSteps Number of steps
 * @return {Array.<Number>}
 */
function createArcSegment(cx, cy, r, startAngle, stepAngle, nSteps) {
  /*
  console.log('cx:' + cx + ',cy:'+ cx + ',r:'+ r
      + ',from:'+ (startAngle*180/Math.PI) + ',step:'+ (stepAngle*180/Math.PI)+
      ',n:'+ nSteps);
  */
  const ROUNDING_F = 10000; // Round all points to 0.0001
  const newArc = new Array(nSteps * 2);
  let i = 0;
  let alpha = startAngle;
  for (let n = nSteps; n > 0; n--) {
    const x = cx + r * Math.cos(alpha);
    const y = cy + r * Math.sin(alpha);
    newArc[i] = Math.round( x * ROUNDING_F ) / ROUNDING_F;
    newArc[i+1] = Math.round( y * ROUNDING_F ) / ROUNDING_F;
    alpha += stepAngle;
    i+=2;
  }
  return newArc;
}

/**
 * Horizontally mirror a segment (with respect to local origin)
 * [x1, y1, x2, y2, ..., xn, yn] => [-xn, yn, ..., -x2, y2, -x1, y1]
 * @nosideeffects
 * @param {Array.<Number>} srcSeg
 * @return {Array.<Number>}
 */
function mirrorSegmentH(srcSeg) {
  const len = srcSeg.length;
  const newSeg = new Array(len);
  let j = len-1;
  for (let i = 0; i < len; i += 2) {
    newSeg[i] = -srcSeg[j-1]; // x1 = -xn
    newSeg[i+1] = srcSeg[j]; // y1 = yn
    j -= 2;
  }
  return newSeg;
}

/**
 * Vertically mirror a segment (with respect to local origin)
 * [x1, y1, x2, y2, ..., xn, yn] => [xn, -yn, ..., x2, -y2, x1, -y1]
 * @nosideeffects
 * @param {Array.<Number>} srcSeg
 * @return {Array.<Number>}
 */
function mirrorSegmentV(srcSeg) {
  const len = srcSeg.length;
  const newSeg = new...