コード例 #1
0
ファイル: FOVmanip.java プロジェクト: davesahman/ufinder
  public void configWindowPair(WindowPairs win, int nwin, Telescope tel) {

    double PlateScale = tel.plateScale;
    double dir = 1.0;
    if (tel.flipped) dir = -1.0;
    double xoff = tel.delta_x;
    double yoff = tel.delta_y;

    nodelist = this.document.getElementsByTagName("RESOURCE");
    // now - does this window already exist? If it does there's nothing more to do.
    Element elem = null;
    for (int i = 0; i < nodelist.getLength(); i++) {
      elem = (Element) nodelist.item(i);
      String check = "WindowPair" + nwin;
      if (elem.hasAttribute("ID") && elem.getAttribute("ID").equals(check)) break;
    }

    // normally we set the <TD> datatags here to the 4 corners of the window
    double x1, x2, x3, x4, y1, y2;
    try {
      x1 = xoff + dir * (512 - win.getXleft(nwin)) * PlateScale;
      x3 = (x1 - dir * win.getNx(nwin) * PlateScale);
      y1 = yoff + (win.getYstart(nwin) - 512) * PlateScale;
      y2 = y1 + win.getNy(nwin) * PlateScale;
      x2 = xoff + dir * (512 - win.getXright(nwin)) * PlateScale;
      x4 = (x2 - dir * win.getNx(nwin) * PlateScale);
      nodelist = elem.getElementsByTagName("TD");
      nodelist.item(0).setTextContent("" + x1);
      nodelist.item(1).setTextContent("" + y1);
      nodelist.item(2).setTextContent("" + x3);
      nodelist.item(3).setTextContent("" + y1);
      nodelist.item(4).setTextContent("" + x3);
      nodelist.item(5).setTextContent("" + y2);
      nodelist.item(6).setTextContent("" + x1);
      nodelist.item(7).setTextContent("" + y2);
      nodelist.item(8).setTextContent("" + x2);
      nodelist.item(9).setTextContent("" + y1);
      nodelist.item(10).setTextContent("" + x4);
      nodelist.item(11).setTextContent("" + y1);
      nodelist.item(12).setTextContent("" + x4);
      nodelist.item(13).setTextContent("" + y2);
      nodelist.item(14).setTextContent("" + x2);
      nodelist.item(15).setTextContent("" + y2);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #2
0
ファイル: FOVmanip.java プロジェクト: davesahman/ufinder
  public void addWindowPair(WindowPairs win, int nwin, Telescope tel) {

    nodelist = this.document.getElementsByTagName("RESOURCE");

    // if telescope is flipped such that east is left, then take account
    double dir = 1.0;
    if (tel.flipped) dir = -1.0;

    // System.out.println("adding window pair " + nwin);

    // now - does this window already exist? If it does there's nothing more to do.
    for (int i = 0; i < nodelist.getLength(); i++) {
      Element elem = (Element) nodelist.item(i);
      String check = "WindowPair" + nwin;
      if (elem.hasAttribute("ID") && elem.getAttribute("ID").equals(check)) {
        // OK, it exists, let's bail
        // System.out.println("Window Pair " + nwin + " already exists.");
        return;
      }
    }

    // OK - it doesn't exist so let's put it in!
    // get a template for a window descriptor by editing the main window resource

    // Get elements containing the whole FoV resource and the full CCD Resource
    Element ccdRes = null;
    Element fovRes = null;
    for (int i = 0; i < nodelist.getLength(); i++) {
      Element elem = (Element) nodelist.item(i);
      if (elem.hasAttribute("ID") && elem.getAttribute("ID").equals("WCCD"))
        // this is the resource element detailing the main window
        ccdRes = (Element) elem;
      if (elem.hasAttribute("ID") && elem.getAttribute("ID").equals("UCAM_FoV"))
        // this is the resource element detailing the whole FOV
        fovRes = (Element) elem;
    }

    // let's try copying the ccd Resource element to a window resource element.
    Element winRes1 = null;
    winRes1 = (Element) ccdRes.cloneNode(true);

    // change resource name
    String id = "WindowPair" + nwin;
    winRes1.setAttribute("ID", id);
    winRes1.setAttribute("name", id);
    // change rest of attributes
    winRes1.normalize();
    nodelist = winRes1.getChildNodes();
    for (int i = 0; i < nodelist.getLength(); i++) {
      if (nodelist.item(i).getNodeType() == 1) {
        Element elem = (Element) nodelist.item(i);
        // description
        if (elem.getTagName().equals("DESCRIPTION")) elem.setTextContent("An ULTRACAM window");
        // Short Description
        if (elem.hasAttribute("ShortDescription"))
          elem.setAttribute("ShortDescription", "Left Window of Pair");
        if (elem.getTagName().equals("TABLE") && elem.hasAttribute("ID")) {
          elem.setAttribute("ID", "LWin");
          elem.setAttribute("name", "Lwin");
        }
      }
    }

    // The right window of the pair is represented by a second <TABLE> node in the
    // resource, so let's copy the one that's already there
    nodelist = winRes1.getElementsByTagName("TABLE");
    Element TableElem = (Element) nodelist.item(0);
    Element rightWin = (Element) TableElem.cloneNode(true);
    rightWin.setAttribute("ID", "RWin");
    rightWin.setAttribute("name", "RWin");

    winRes1.appendChild(rightWin);

    // normally we set the <TD> datatags here to the 4 corners of the window
    double x1, x2, x3, x4, y1, y2;
    double PlateScale = tel.plateScale;
    double xoff = tel.delta_x;
    double yoff = tel.delta_y;
    try {
      x1 = xoff + dir * (512 - win.getXleft(nwin)) * PlateScale;
      x3 = (x1 - dir * win.getNx(nwin) * PlateScale);
      y1 = yoff + (win.getYstart(nwin) - 512) * PlateScale;
      y2 = y1 + win.getNy(nwin) * PlateScale;
      x2 = xoff + dir * (512 - win.getXright(nwin)) * PlateScale;
      x4 = (x2 - dir * win.getNx(nwin) * PlateScale);
      nodelist = winRes1.getElementsByTagName("TD");
      nodelist.item(0).setTextContent("" + x1);
      nodelist.item(1).setTextContent("" + y1);
      nodelist.item(2).setTextContent("" + x3);
      nodelist.item(3).setTextContent("" + y1);
      nodelist.item(4).setTextContent("" + x3);
      nodelist.item(5).setTextContent("" + y2);
      nodelist.item(6).setTextContent("" + x1);
      nodelist.item(7).setTextContent("" + y2);
      nodelist.item(8).setTextContent("" + x2);
      nodelist.item(9).setTextContent("" + y1);
      nodelist.item(10).setTextContent("" + x4);
      nodelist.item(11).setTextContent("" + y1);
      nodelist.item(12).setTextContent("" + x4);
      nodelist.item(13).setTextContent("" + y2);
      nodelist.item(14).setTextContent("" + x2);
      nodelist.item(15).setTextContent("" + y2);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // set colour to blue
    nodelist = winRes1.getElementsByTagName("PARAM");
    for (int i = 0; i < nodelist.getLength(); i++) {
      Element elem = (Element) nodelist.item(i);
      if (elem.hasAttribute("name") && (elem.getAttribute("name").equals("color")))
        elem.setAttribute("value", "blue");
    }

    // append window to file
    try {
      fovRes.appendChild(winRes1);
    } catch (DOMException e) {
      e.printStackTrace();
    }
  }