⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mill-outlines.ulp

📁 老外的PCB设计软件,是免费的.可以上网更新.
💻 ULP
📖 第 1 页 / 共 5 页
字号:
      case devHPGL:
         printf("\nPU;\nSP0;");
         break;
   }
}

// TRUE OUTLINE ***
void trueOutlineDraw(string SignalName) {
   board(B) {
      B.signals(S) {
         if (S.name == SignalName) {
            S.polygons(P) {
               int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN;
               int x0, y0, first = 1;
               int FrameWire;
               string s;

               P.wires(W) {
                  x1 = min(x1, W.x1);
                  x2 = max(x2, W.x1);
                  y1 = min(y1, W.y1);
                  y2 = max(y2, W.y1);
               }
               string lasts;
               P.contours(W) {
                  if (first) {
                     // a new partial polygon is starting
                     x0 = W.x1;
                     y0 = W.y1;
                     FrameWire = (x1 == x0 || x2 == x0) && (y1 == y0 || y2 == y0);
                     sprintf(s, " (%.4f %.4f)", u2mm(W.x1), u2mm(W.y1) );
                     trueOutline_coordinate = s;
                     lasts = s;
                     first = 0;
                  }
                  else if (W.x2 == x0 && W.y2 == y0) {
                     // this was the last wire of the partial polygon,
                     // so the next wire (if any) will be the first wire
                     // of the next partial polygon
                     sprintf(s, " (%.4f %.4f)", u2mm(W.x2), u2mm(W.y2) );
                     if (lasts != s) trueOutline_coordinate += s;
                     lasts = s;
                     first = 1;
                  }
                  else ;
                  if (!FrameWire) {
                     sprintf(s, " (%.4f %.4f)", u2mm(W.x2), u2mm(W.y2) );
                     if (lasts != s) trueOutline_coordinate += s;
                     lasts = s;
                  }
               }
            }
         }
      }
      return ;
   }
}


// *** the return string to start rekursiv ***
string RUN_pass(string run_Pass) {
   string s;
   sprintf(s, "RUN '%s' '%s' '%.4f' '%.4f' '%.4f' '%d' '%s' '%s' '%s' '%.1f' '%.2f' '%.2f' '%.2f' '%d' '%d' '%.2f' '%.4f' '%d' '%.4f' '%d' '%d' '%s';\n",
                argv[0], Device, MillToolOutl, MillToolIsolate, MillToolFree, Layer, FileName, DrillFile, run_Pass,
                Mirror, DrillPad, DrillVia, DrillHole, OverlapOutlPercent, OverlapRubOut, Distance_Copper_Dimension,
                DimensionMillTool, millfreeyes, Holder_Spacing, onlydrill, generatedrills, trueOutline_coordinate);
   return s;
}



// place a VIA outside the board with the same signal name
// for used polygon to calculate the filling with orpahns off
// and get no more polygon contours

void generateTruePolygonOutlines() { // the true outlines of board
   board(B) {
      real x1 = u2mm(B.area.x1) - DimensionMillTool, y1 = u2mm(B.area.y1) - DimensionMillTool,
           x2 = u2mm(B.area.x2) + DimensionMillTool, y2 = u2mm(B.area.y2) + DimensionMillTool;
      real distanceDimension = (DimensionMillTool / 2 - Distance_Copper_Dimension) * 2;
      if (distanceDimension < 0) distanceDimension = 0.001;
      string Cmd;
      sprintf(Cmd, "GRID mm FINEST;\n"
                   "CHANGE DRILL 0.3;\nCHANGE DIAMETER 0.5;\nCHANGE SHAPE ROUND;\n"
                   "SET POLYGON_RATSNEST ON;\n"
                   "SET WIRE_BEND 0;\n"
                   "CHANGE RANK 6;\n"
                   "CHANGE POUR SOLID;\n"
                   "CHANGE THERMAL OFF;\n"
                   "CHANGE LAYER %d;\n"
                   "DISPLAY NONE 17 %d;\n",
                    Layer, Layer);

      // make the 1st virtual Net for Normal Polygon Orphens OFF
      // to generate the true outline for place the spacial polygon
      // make a partial WIA for generate Polygon with orphans off
      string millout;
      sprintf(millout, "VIA '%s' (%.4f %.4f);\n", OutlineMillSignal, x1 - Distance_Copper_Dimension - 1, y1 - Distance_Copper_Dimension - 1);
      Cmd += millout;

      // Width = MillFree-Diameter/2 minus "Distance Copper/Dimension"
      sprintf(millout, "CHANGE ISOLATE 0;\n");
      Cmd += millout;
      sprintf(millout, "CHANGE ORPHANS OFF;\n");
      Cmd += millout;
      sprintf(millout, "POLYGON '%s' %.4f (%.4f %.4f) (%.4f %.4f)(%.4f %.4f);\nRATSNEST;\n",
                                OutlineMillSignal, distanceDimension,
                                x1 - DimensionMillTool - Distance_Copper_Dimension - 2,
                                y1 - DimensionMillTool - Distance_Copper_Dimension - 2,
                                x2 + DimensionMillTool + Distance_Copper_Dimension,
                                y2 + DimensionMillTool + Distance_Copper_Dimension,
                                x1 - DimensionMillTool - Distance_Copper_Dimension - 2,
                                y1 - DimensionMillTool - Distance_Copper_Dimension - 2);
      Cmd += millout;
      Cmd += "WINDOW FIT;\n";
      Cmd += RUN_pass(PassDimensionPoly);
      if (test) output(filesetext(B.name, "-cmd.txt"), "wt") printf("%s", Cmd);
      exit (Cmd);
   }
}


//
// The actual outlines generator

void GenerateOutlines(void) {
   board(B) {
      trueOutlineDraw(OutlineMillSignal);
      string s;
      real x1 = u2mm(B.area.x1) - MillToolFree, y1 = u2mm(B.area.y1) - MillToolFree,
           x2 = u2mm(B.area.x2) + MillToolFree, y2 = u2mm(B.area.y2) + MillToolFree;
      real distanceDimension = MillToolFree / 2 - Distance_Copper_Dimension;
      if (distanceDimension < 0) distanceDimension = 0.001;

      //  delete virtual Polygon and VIA
      sprintf( s, "DELETE (%.4f %.4f) (%.4f %.4f) (%.4f %.4f);\n",
                      x1 - MillToolFree - Distance_Copper_Dimension,
                      y1 - MillToolFree - Distance_Copper_Dimension,
                      x2 + MillToolFree + Distance_Copper_Dimension,
                      y2 + MillToolFree + Distance_Copper_Dimension,
                      x1 - distanceDimension, y1 - distanceDimension);

      string Cmd = s + "SET WIRE_BEND 2;\n";
      sprintf(s, "CHANGE ISOLATE %.3f;\n", MillToolIsolate);
      Cmd += s;
      sprintf(s, "POLYGOn %s %.3f %s;\nRATSNEST;\n",
                     OutlinesSignalName, MillToolOutl, trueOutline_coordinate);
      Cmd += s;
      Cmd += RUN_pass(Pass2);
      if (test) output(filesetext(B.name, "-cmd.txt"), "at") printf("%s", Cmd);
      if (test) viewtest(Cmd);
      exit(Cmd);
   }
}

string WriteOutlines(string SignalName) { // OutlinesSignalName
   board(B) {
      if (InPassPour && MillToolFree == 0) return "";
      if (InPassOutmill && !DimensionMillTool) return "";  // 0 = generate no Dimension with spacing

      string Cmd;
      B.signals(S) {
         if (S.name == SignalName && !onlydrill) {
            S.polygons(P) {
               int x1 = INT_MAX, y1 = INT_MAX, x2 = INT_MIN, y2 = INT_MIN;
               int x0, y0, first = 1;
               int FrameWire;
               int State;

               P.wires(W) {
                  x1 = min(x1, W.x1);
                  x2 = max(x2, W.x1);
                  y1 = min(y1, W.y1);
                  y2 = max(y2, W.y1);
               }
               if (InPass2) {
                  DeviceReInit(Contour);
               }
               if (InPassPour) DeviceReInit(BlowUp_RubOut);
               if (InPassOutmill) DeviceReInit(DimensionLine);
               P.contours(W) {
                  if (first) {
                     // a new partial polygon is starting
                     x0 = W.x1;
                     y0 = W.y1;
                     FrameWire = (x1 == x0 || x2 == x0) && (y1 == y0 || y2 == y0);
                     State = 0;
                     first = 0;
                  }
                  else if (W.x2 == x0 && W.y2 == y0) {
                     // this was the last wire of the partial polygon,
                     // so the next wire (if any) will be the first wire
                     // of the next partial polygon
                     State = 2;
                     first = 1;
                  }
                  else State = 1;
                  if (!FrameWire) {
                     DeviceDraw(W.x1, W.y1, W.x2, W.y2, State);
                  }
               }
               if (InPassPour && millfreeyes) {
                  if (SelectedDevice == devScript) {
                     printf("# pouring\n");
                  }
                  DeviceReInit(BlowUp_RubOut);
                  State = 4;
                  int fx1[], fy1[], fx2[], fy2[];
                  int fcnt = 0;
                  P.fillings(F) {
                     fx1[fcnt] = F.x1;
                     fy1[fcnt] = F.y1;
                     fx2[fcnt] = F.x2;
                     fy2[fcnt] = F.y2;
                     fcnt++;
                  }
                  int diry = fy1[0];
                  for (int m = 0; m <= fcnt; m++) {
                     if (diry == fy1[m]) {
                        DeviceDraw(fx1[m], fy1[m], fx2[m], fy2[m], State);
                     }
                     else {
                        // ****** milling reverse ******
                        diry = fy1[m];  // next y_line
                        for (int mb = m; mb <= fcnt; mb++) {
                           if (diry == fy1[mb]);
                           else break;
                        }
                        for(int mback = mb -1 ; mback >= m; mback--) {
                           DeviceDraw(fx2[mback], fy2[mback], fx1[mback], fy1[mback], State);
                           // reverse milling 08.05.2002 alf@cadsoft.de
                        }
                        m = mb;
                        diry = fy1[m];  // next y_line
                        m--;
                     }
                  }
               }
            DeviceEnd();
            }
         break;
         }
      }
      return Cmd;
   }
}


void Pad(UL_PAD P) {
  DeviceDraw(0, 0, P.x, P.y, 3);
}

void Package(UL_PACKAGE P) {
  P.contacts(C) {
    if (C.pad) Pad(C.pad);
    }
}

void Element(UL_ELEMENT E) {
  Package(E.package);
}

void PackageHole(UL_PACKAGE P) {
   P.holes(H) {
      if (u2mm(H.drill) > DrillHole) {
         CircleDraw(H.x, H.y, H.drill, DrillHole);
      }
      else DeviceDraw(0, 0, H.x, H.y, 3);
   }
}

void ElementHole(UL_ELEMENT E) {
   PackageHole(E.package);
}

void WriteDrills(void) {
   board(B) {
      DeviceReInit(PadDrill);
      B.elements(E) Element(E);
      DeviceReInit(ViaDrill);
      B.signals(S) {
         S.vias(V) {
            DeviceDraw(0, 0, V.x, V.y, 3);
         }
      }
   }
   return;
}

void WriteHoles(void) {
   board(B) {
      DeviceReInit(HoleDrill);
      B.elements(E) ElementHole(E);
      B.holes(H) {
         if (u2mm(H.drill) > DrillHole) {
             CircleDraw(H.x, H.y, H.drill, DrillHole*10000); // internal unit
         }
         else DeviceDraw(0, 0, H.x, H.y, 3);
      }
   }
   return;
}

// *** Pen assaign
void penAssign(void) {
   dlgDialog("Mill outlines: HPGL Pen Assignment") {
      string pen_assign = "<table>\n";
      string t;

PenList[PadDrill]      = "PadDrill";
PenList[ViaDrill]      = "ViaDrill";
PenList[Contour]       = "Contour";
PenList[BlowUp_RubOut] = "Blow-Up/Rub-Out";
//PenList[RubOut]        = "Rub-Out";
PenList[HoleDrill]     = "HoleDrill";
PenList[DimensionLine] = "DimensionLine";

      sprintf(t, "<tr><td>PadDrill:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", PadDrill, DrillPad);
      pen_assign += t;
      sprintf(t, "<tr><td>ViaDrill:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", ViaDrill, DrillVia);
      pen_assign += t;
      sprintf(t, "<tr><td>Contour:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", Contour, MillToolOutl);
      pen_assign += t;
      sprintf(t, "<tr><td>BlowUp/RubOut:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", BlowUp_RubOut, MillToolFree);
      pen_assign += t;
//      sprintf(t, "<tr><td>RubOut:</td><td>PEN %d</td><td>%.1f mm</td><tr>\n", RubOut, MillToolFree);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -