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

📄 exp-project-lbr.ulp

📁 老外的PCB设计软件,是免费的.可以上网更新.
💻 ULP
📖 第 1 页 / 共 2 页
字号:
  cmd  += "DESCRIPTION "+replacenewline(D.description)+";\n";
  cmd  += "PREFIX '"+D.prefix+"';\n";
  cmd  += "VALUE "+D.value+";\n";
  D.gates(G) {
    switch (G.addlevel) {
      case GATE_ADDLEVEL_NEXT    : GateAddlevel = "Next";    break;
      case GATE_ADDLEVEL_MUST    : GateAddlevel = "Must";    break;
      case GATE_ADDLEVEL_CAN     : GateAddlevel = "Can";     break;
      case GATE_ADDLEVEL_REQUEST : GateAddlevel = "Request"; break;
      case GATE_ADDLEVEL_ALWAYS  : GateAddlevel = "Always";
    };
    h = ""; sprintf(h, "CHANGE Addlevel  %s;\n", GateAddlevel); cmd += h;
    h = ""; sprintf(h, "CHANGE Swaplevel %d;\n", G.swaplevel); cmd += h;

    if (onelib && generate_lbrname)
      symname = strip_at_num(LBR.name) + "_" + strip_at_num(G.symbol.name);

    else
      symname = strip_at_num(G.symbol.name);
    h = ""; sprintf(h, "ADD %s '%s' (%f %f);\n", symname, checkGateName(G.name), u2mic(G.x), u2mic(G.y)); cmd += h;
  }
  D.devices(DV) {
    if (DV.package) {
      if (onelib && generate_lbrname)
          cmd += "PACKAGE '" + strip_at_num(LBR.name) + "_"+ strip_at_num(DV.package.name) + "' " + strip_at_num(DV.name) + ";\n";

      else
        cmd += "PACKAGE '" + strip_at_num(DV.package.name) + "' " + strip_at_num(DV.name) + ";\n";
      cmd += "TECHNOLOGY "+DV.technologies+";\n";
    }
    DV.gates(G) {
      G.symbol.pins(P) {
        if (DV.package) {
          if (P.contact) {
            h = ""; sprintf(h, "CONNECT '%s.%s' '%s';\n", checkGateName(G.name), P.name, P.contact.name); cmd += h;
          }
        }
      }
    }
  }
  return;
}

//----------------
void OutputUnmistakablePackages(UL_LIBRARY LBR) {
  PrevName = "";
  if (exist_file(WorkPath+CurrentLbrName+".lbr")) {
    h = ""; sprintf(h, "REMOVE '%s';\n", WorkPath+CurrentLbrName+".lbr"); cmd += h; // delete exitsting lbr
  }
  h = ""; sprintf(h, "OPEN '%s.lbr';\n", WorkPath+CurrentLbrName); cmd += h;
  CreateHeader(LBR);
  LBR.packages(P) {
    if (PrevName != strip_at_num(P.name)) {
      logf += "   PAC: "+ strip_at_num(P.name) + "\n"; Status = "   PAC: " + strip_at_num(P.name);  dlgRedisplay();
      NameIndex = 0;
      h = ""; sprintf(h, "Edit %s.PAC;\n", strip_at_num(P.name)); cmd += h;
      DrawPackage(P);
    }
    else {
      NameIndex++;
      h = ""; sprintf(h, "Edit %s$%02d.PAC;\n", strip_at_num(P.name), NameIndex); cmd += h;
      //logfile
      h = ""; sprintf(h, "   PAC: %s renamed to %s$%02d\n", strip_at_num(P.name), strip_at_num(P.name), NameIndex); logf += h; Status = h;  dlgRedisplay();
      // end logfile
      DrawPackage(P);
      // cmd  += "WIN FIT;\n";
    }
    PrevName = P.name;
    cmd  += "DESCRIPTION "+replacenewline(P.description)+";\n";
  }
  return;
}

// ----------------------------------------------------------------------------------------
int is_new(void) { // n = nr of entries
  int i;
  if (n == 0) return 1;
  for (i = 0; i < n; i++) {
    if (x[n] == x[i]) {
       return(0);
    }
  }
  return 1;
}

// ---------
void CreateOneLibHeader(UL_LIBRARY LBR, string project_name) {
  if (exist_file(WorkPath+CurrentLbrName+".lbr")) {
    h = ""; sprintf(h, "REMOVE '%s';\n", WorkPath+CurrentLbrName+".lbr"); cmd += h; // delete exitsting lbr
  }
  h = ""; sprintf(h, "OPEN '%s.lbr';\n", WorkPath+CurrentLbrName); cmd += h;
  CreateHeader(LBR);
  CreateLBRdescription(project_name);
}

// ---------
void OutputPackages(UL_LIBRARY LBR) {
  string pacname;
  LBR.packages(P) {
    if (!generate_lbrname && at_num(P.name) ) ;
    else {
      if (onelib && generate_lbrname)
        pacname = strip_at_num(LBR.name) + "_" + strip_at_num(P.name);

      else
        pacname = strip_at_num(P.name);

      n++;
      x[n] = pacname;
      if (is_new()) {
        logf += "   PAC: "+pacname+"\n"; Status = "   PAC: "+P.name; dlgRedisplay();
        h = ""; sprintf(h, "Edit %s.PAC;\n", strip_at_num(pacname)); cmd += h;
        DrawPackage(P);
        cmd  += "DESCRIPTION "+replacenewline(P.description)+";\n";
        // cmd += "WIN FIT;\n";
      }
    }
  }
  return;
}

void OutputSymbols(UL_LIBRARY LBR) {
  string symname;
  LBR.symbols(S) {
    if (!generate_lbrname && at_num(S.name) ) ;
    else {
      if (onelib && generate_lbrname)
        symname = strip_at_num(LBR.name) + "_" + S.name;

      else
        symname = strip_at_num(S.name);

      n++;
      x[n] = symname;
      if (is_new()) {
        logf += "   SYM: " + symname + "\n"; Status = "   SYM: " + S.name;  dlgRedisplay();
        h = ""; sprintf(h, "Edit %s.SYM;\n", symname); cmd += h;
        DrawSymbol(S);
        // cmd += "WIN FIT;\n";
      }
    }
  }
  return;
}

void OutputDevices(UL_LIBRARY LBR) {
  string dname;
  LBR.devicesets(D) {
    if (!generate_lbrname && at_num(D.name) ) ;
    else {
      if (onelib && generate_lbrname)
        dname = strip_at_num(LBR.name) + "_" + strip_at_num(D.name);

      else
        dname = strip_at_num(D.name);

      n++;
      x[n] = dname;
      if (is_new()) {
        logf += "   DEV: " + dname+"\n"; Status = "   DEV: " + strip_at_num(D.name);  dlgRedisplay();
        NameIndex = 0;
        h = ""; sprintf(h, "Edit %s.DEV;\n", dname); cmd += h;
        DrawDevice(D, LBR);
        // cmd  += "WIN FIT;\n";
      }
    }
  }
  return;
}

// ------------
void createMechanical(void) {
  if (dlgMessageBox("Eport also only mechanicle packages from board?", "Yes", "No") != 0) return;

  if (project.board) {
    project.board(B) { // extract also ONLY mechanical packages (without pads/smds)

      B.libraries(LBR) {
        CurrentLbrName = strip_at_num(LBR.name);
        LBR.packages(PAC) {

          int k;
          PAC.contacts(C) {
            k++;
          }
          if (!k) {

            logf += "LIBRARY: "+CurrentLbrName+".lbr\n";

            PrevName = "";
            h = ""; sprintf(h, "OPEN '%s.lbr';\n", WorkPath+CurrentLbrName); cmd += h;

            LBR.packages(P) {


              int kontakt;
              P.contacts(C) {
                kontakt++;
              }
              if (!kontakt) {
                if (PrevName != strip_at_num(P.name)) {
                  logf += "   PAC: "+ strip_at_num(P.name) + "\n"; Status = "   PAC: " + strip_at_num(P.name); dlgRedisplay();
                  NameIndex = 0;
                  h = ""; sprintf(h, "Edit %s.PAC;\n", strip_at_num(P.name)); cmd += h;
                  cmd += "SET WIRE_BEND 2;\n";
                  DrawPackage(P);
                }
                else {
                  NameIndex++;
                  h = ""; sprintf(h, "Edit %s$%02d.PAC;\n", strip_at_num(P.name), NameIndex); cmd += h;
                  //logfile
                  h = ""; sprintf(h, "   PAC: %s renamed to %s$%02d\n", strip_at_num(P.name), strip_at_num(P.name), NameIndex); logf += h; Status = h; dlgRedisplay();
                  // end logfile
                  cmd += "SET WIRE_BEND 2;\n";
                  DrawPackage(P);
                  // cmd  += "WIN FIT;\n";
                }
                PrevName = P.name;
                cmd  += "DESCRIPTION "+replacenewline(P.description)+";\n";
              }
            }
          }
          cmd += "WRITE;\n";
          break;
        }
      }
    }
  }
  return;
}


void make_lbr(void) {
  if (board) board(B) {
    in_board = 1;
    B.libraries(LBR) {
      CurrentLbrName = strip_at_num(LBR.name);
      LBR.packages(PAC) {
        logf += "LIBRARY: "+CurrentLbrName+".lbr\n";
        OutputUnmistakablePackages(LBR);
        cmd += "WRITE;\n";
        break;
      };
    }
  }
  if (schematic) schematic(SCH) {
    in_board = 0;
    SCH.libraries(LBR) {
      CurrentLbrName = strip_at_num(LBR.name);
      LBR.devices(DEV) {
        logf += "LIBRARY: "+CurrentLbrName+".lbr\n";
        OutputUnmistakablePackages(LBR);
        n=0;
        OutputSymbols(LBR);
        n=0;
        OutputDevices(LBR);
        cmd += "WRITE;\n";
        break;
      };
    }
    createMechanical();
  }
  CreateTrailer();
}

//-------------------
void make_one_lbr(void) {
  if (board) board(B) {
    in_board = 1;
    B.libraries(LBR) {
      CurrentLbrName = strip_at_num(filesetext(EditName, ""));
      logf += "LIBRARY: "+CurrentLbrName+".lbr\n";
      CreateOneLibHeader(LBR, B.name);
      break;
    }
    n = 0;
    B.libraries(LBR) {
      OutputPackages(LBR);
    }
    cmd += "WRITE;\n";
    CreateTrailer();
  }

  if (schematic) schematic(SCH) {
    in_board = 0;
    SCH.libraries(LBR) {
      CurrentLbrName = strip_at_num(filesetext(EditName, ""));
      logf += "LIBRARY: "+CurrentLbrName+".lbr\n";
      CreateOneLibHeader(LBR, SCH.name);
      break;
    }
    n = 0;
    SCH.libraries(LBR) {
      OutputPackages(LBR);
    }
    n = 0;
    SCH.libraries(LBR) {
      LBR.devices(DEV) {
        OutputSymbols(LBR);
      }
    }
    n = 0;
    SCH.libraries(LBR) {
      LBR.devices(DEV) {
        OutputDevices(LBR);
      }
    }
    cmd += "WRITE;\n";
    CreateTrailer();
  }
  return;
}

// -----------
void show_save_log_file(string cm) {
  if(show_script) {
    int R = dlgDialog("Save Log File") {
      dlgVBoxLayout {
        dlgLabel("Edit only if you are sure what you do!");
        dlgTextEdit(cm);
        dlgHBoxLayout {
          dlgPushButton("+Ok") dlgAccept();
          dlgPushButton("-Cancel") dlgReject();
        }
      }
    };
    if (R) {
      LogName = dlgFileSave("Save Script File", WorkPath+PureLogName, "*.log");
      if (LogName != "") output(LogName, "wtD") printf("%s", cm);
    }
  }
  else {
    output(WorkPath+PureLogName, "wtD") printf("%s", cm);
  }
  return;
}

// -----------

void show_save_script_file(string cm) {
  if (show_script) {
    int R = dlgDialog("Save Script File") {
      dlgVBoxLayout {
        dlgLabel("Edit only if you are sure what you do!");
        dlgTextEdit(cm);
        dlgHBoxLayout {
          dlgPushButton("+Ok") dlgAccept();
          dlgPushButton("-Cancel") dlgReject();
        }
      }
    };
    if (R) {
      ScriptName = dlgFileSave("Save Script File", WorkPath+PureScriptName, "*.scr");
      if (ScriptName != "") output(ScriptName, "wtD") printf("%s", cm);
    }
  }
  else {
    ScriptName = WorkPath+PureScriptName;
    output(ScriptName, "wtD") printf("%s", cm);
  }
  return;
}

//------------ main ----------------------------------------

if (library) {
  dlgMessageBox(usage + "<b>ERROR</b><hr>This program can only work in the schematic or board editor.");
  exit(1);
}
else {
  if (board) board(B)         EditName = filename(B.name);  // name of loaded board/schematic w/o path
  if (schematic) schematic(S) EditName = filename(S.name);
}

PureScriptName = filesetext(EditName, ".scr");               // name of generated script w/o path
PureLogName    = filesetext(EditName, ".log");               // name of generated log msgs w/o path
WorkPath = get_project_path();

Status = "Version " + Version;

int Result = dlgDialog("Create Project Library") {
    string globList[];
    int globListIndex = -1;
    int globCnt = 0;
    dlgHBoxLayout {
      dlgStretch(1);
      dlgSpacing(500);
      dlgStretch(1);
    }
    dlgHBoxLayout {
      dlgVBoxLayout {
        dlgGroup("Creation Mode") {
          dlgRadioButton("&Multiple libraries", onelib);
          dlgRadioButton("&One library", onelib);
          dlgHBoxLayout {
            dlgSpacing(16);
            dlgCheckBox("&Generate LBR-Name_/PAC/SYM/DEV", generate_lbrname);

          }
          dlgHBoxLayout {
            dlgSpacing(34);
            dlgLabel("if One library selected");
          }
        }
        dlgGroup("User Interface") {
          dlgCheckBox("Show scripts and file dialogs", show_script);
          dlgCheckBox("Save log file", save_log);
        }
        dlgStretch(1);
      }
      dlgVBoxLayout {
        dlgLabel("Log file");
        dlgTextView(logf);
      }
    }
    dlgHBoxLayout {
      dlgSpacing(60);
      dlgLabel("&Working path:");
      dlgStringEdit(WorkPath);
      dlgPushButton("Bro&wse") {
        if (cmd) {
          cmd = "";
          logf = "";
        }

        h = WorkPath;
        WorkPath = dlgDirectory("Select a directory", WorkPath);
        if (WorkPath == "") WorkPath = h;
        else WorkPath += "/";     // 29.03.2005 support@cadsoft.de
      }
    }
    dlgSpacing(10);
    dlgHBoxLayout {
      dlgLabel(Status, 1);
      dlgStretch(1);
      dlgPushButton("+&Collect data") { logf = "Project Library Creation Log File "+t2string(time())+"\n"
                                                         +EAGLE_SIGNATURE+"\nCreated from: "+EditName+"\n\n";
                                        if (onelib) { cmd = ""; make_one_lbr(); }
                                        else        { cmd = ""; make_lbr(); }
                                        show_save_script_file(cmd);
                                        Status = "Collect finish";
                                        dlgRedisplay();
                                        if (save_log)  show_save_log_file(logf);
                                      }
      dlgPushButton("Create &library") { if (cmd == "") dlgMessageBox("Use 'Collect data' first!","&OK");
                                         else           exit("SCRIPT '"+ScriptName+"';\n");
                                       }
      dlgPushButton("-&Quit")          dlgReject();
      dlgSpacing(23);
      dlgPushButton("&Help")           DisplayHelp();
    }
};

⌨️ 快捷键说明

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