#usage  "en:  <h3>Highlights all net with a given CLASS.</h3>\n"
             "This ULPs works from within a board or a schematic.<br>"
             "<p><author>Author: alf@cadsoft.de</author>",
        "de:  <h3>Hebt Signale der gegebenen CLASS hervor.</h3>\n"
             "Dieses ULP arbeitet aus Boards oder Schematics heraus.<br>"
             "<p><author>Author: alf@cadsoft.de</author>"

#require 5.0300

string strTexts[] = {
    "en\v"
    "de\v"
    ,
    ";This ULP requires a board or a schematic.\v"
    ";Dieses Ulp funktioniert nur in Boards und Schematics.\v"
    ,
    "Please type in the CLASS you want to highlight.\v"
    "Geben Sie dei hervorzuhebende CLASS ein.\v"
    ,
    ";No Nets/Signals found with CLASS \"%s\".\v"
    ";Es wurden keine Signale der CLASS \"%s\" gefunden.\v"
};

string strMessage;
string strScript, s;
int nCount;
string strValue;

/*** functions ***/
string Translate(string src) {
  string strLoc = lookup(strTexts, src, strstr(strTexts[0], language()) / 3, '\v');
  return((strLoc != "") ? strLoc : src);
}

string InputBox(string strPrompt, string strTitle, string strDefault) {
  string strReturn = strDefault;
  int nResult = dlgDialog(strTitle) {
    dlgGridLayout {
      dlgCell(1, 0)   dlgStringEdit(strReturn);
      dlgCell(0, 0)   dlgHBoxLayout {
                        dlgLabel(strPrompt);
                        dlgSpacing(20);
                        dlgVBoxLayout {
                          dlgPushButton("+OK") dlgAccept();
                          dlgPushButton("Cancel") dlgReject();
                        }
                     }
    }
  };
  return((nResult > 0) ? strReturn : "");
}


if (argv[1]) {
  strValue = argv[1];
}


if(board) board(B) {
  if (!strValue) {
    strValue = InputBox(Translate("Please type in the CLASS you want to highlight."), filename(argv[0]), B.name);
  }
  if(!strValue) exit(EXIT_SUCCESS);
  sprintf(strScript, "WINDOW;\n SHOW ");  // 2008-11-03
  B.signals(S) {
    if(S.class.number == strtol(strValue)) {
       sprintf(s, " %s ", S.name);
       strScript += s;
       ++nCount;
    }
  }
  strScript +=" ";

  if(!nCount) {
    sprintf(strMessage, Translate(";No Nets/Signals found with CLASS \"%s\"."), strValue);
    dlgMessageBox(strMessage);
    exit(EXIT_FAILURE);
  }
  else {
    exit(strScript);
  }
}

else if(sheet) sheet(S) {
  string strName;
  schematic(SCH) {
    strName = SCH.name;
  }
  if (!strValue) {
    strValue = InputBox(Translate("Please type in the value you want to highlight."), filename(argv[0]), "");
  }
  if(!strValue) exit(EXIT_SUCCESS);

  sprintf(strScript, "WINDOW;\nSHOW ");
  S.nets(N) {
    if(N.class.number == strtol(strValue)) {
      sprintf(s, " %s", N.name);
      strScript += s;
      ++nCount;
    }
  }
  strScript += " ";
  if(!nCount) {
    sprintf(strMessage, Translate(";No Nets/Signals found with CLASS \"%s\"."), strValue);
    dlgMessageBox(strMessage);
    exit(EXIT_FAILURE);
  }
  else {
    exit(strScript);
  }
}
else {
  dlgMessageBox(Translate(";This ULP requires a board or a schematic."));
}

