예제 #1
0
  /**
   * traite une RESOURCE en la considérant comme sous-partie d'un FOV
   *
   * @param res
   */
  private SubFootprintBean processResource(SavotResource res) {
    SubFootprintBean subFpBean = new SubFootprintBean();
    subFpBean.setInSphericalCoords(sphericalCoordinates);

    TableSet tables = res.getTables();
    int nbTab = tables.getItemCount();
    SubFootprintBean sub;

    for (int i = 0; i < nbTab; i++) {
      // TODO : prendre en compte couleur éventuelle au niveau de la TABLE (pour les types STRING
      // notamment)
      sub = processTable((SavotTable) tables.getItemAt(i));
      if (sub != null) {
        subFpBean.addSubFootprintBean(sub);
      }
      //			System.out.println("sub : "+sub);
    }

    String id = res.getName();
    subFpBean.setName(id);
    subFpBean.setColor(getColor(res));

    return subFpBean;
  }
예제 #2
0
  private SubFootprintBean processTable(SavotTable table) {
    String type = getRegionType(table);

    // si le type n'est pas un des types supportés ...
    if (type == null
        || !(type.equals("Box")
            || type.equals("Polygon")
            || type.equals("Circle")
            || type.equals("Pickle")
            || type.equals("String"))) {
      return null;
    }

    String id = table.getId();
    SubFootprintBean subFpBean = null;

    if (type.equals("Polygon")) {
      FieldSet fields = table.getFields();
      int nbFields = fields.getItemCount();

      int idxRAOffset = -1;
      int idxDEOffset = -1;
      SavotField field;
      String utype;
      // boucle sur les champs
      for (int i = 0; i < nbFields; i++) {
        field = (SavotField) fields.getItemAt(i);
        field = getField(field);
        utype = field.getUtype();
        if (utype.equals("stc:AstroCoordArea/Region/reg:Polygon/Vertex/Position[1]")
            || utype.equalsIgnoreCase("stc:AstroCoordArea.Polygon.Vertex.Position.C1")) {
          idxRAOffset = i;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Polygon/Vertex/Position[2]")
            || utype.equalsIgnoreCase("stc:AstroCoordArea.Polygon.Vertex.Position.C2")) {
          idxDEOffset = i;

          continue;
        }
      }
      // pas de traitement possible dans un tel cas
      if (idxRAOffset < 0 || idxDEOffset < 0) return null;

      TRSet trs = table.getData().getTableData().getTRs();
      int nbRows = trs.getItemCount();
      double[] raOffset = new double[nbRows];
      double[] deOffset = new double[nbRows];
      SavotTR tr;
      double raOff, deOff;
      raOff = deOff = 0.;
      String tmp;
      TDSet tds;
      counter += nbRows;
      for (int i = 0; i < nbRows; i++) {
        tr = (SavotTR) trs.getItemAt(i);
        tds = tr.getTDs();
        try {

          tmp = tds.getContent(idxRAOffset);
          //					System.out.println(tmp);
          raOff = Double.valueOf(tmp).doubleValue();

          tmp = tds.getContent(idxDEOffset);
          //					System.out.println(tmp+"\n");
          deOff = Double.valueOf(tmp).doubleValue();
        } catch (NumberFormatException e) {
          e.printStackTrace();
        }
        // TODO : vérifier unité et faire conversion en degrés
        raOffset[i] = raOff / 3600.;
        deOffset[i] = deOff / 3600.;
      }

      subFpBean = new SubFootprintBean(raOffset, deOffset, id);
      subFpBean.setInSphericalCoords(sphericalCoordinates);

      return subFpBean;
    }

    // TODO : nouveau format
    else if (type.equals("Box")) {
      ParamSet params = table.getParams();
      int nbParams = params.getItemCount();

      SavotParam ctrRAOffsetParam = null;
      SavotParam ctrDEOffsetParam = null;
      SavotParam sizeRAParam = null;
      SavotParam sizeDEParam = null;
      SavotParam param;
      String utype;
      // boucle sur les params
      for (int i = 0; i < nbParams; i++) {
        param = (SavotParam) params.getItemAt(i);
        param = getParam(param);
        utype = param.getUtype();
        if (utype.equals("stc:AstroCoordArea/Region/reg:Box/Center[1]")) {
          ctrRAOffsetParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Box/Center[2]")) {
          ctrDEOffsetParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Box/Size[1]")) {
          sizeRAParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Box/Size[2]")) {
          sizeDEParam = param;

          continue;
        }
      }
      // pas de traitement possible dans un tel cas
      if (ctrRAOffsetParam == null
          || ctrDEOffsetParam == null
          || sizeRAParam == null
          || sizeDEParam == null) {
        return null;
      }

      double[] raOffset = new double[4];
      double[] deOffset = new double[4];

      counter += 4;

      double ctrRAOffset, ctrDEOffset, sizeRA, sizeDE;
      ctrRAOffset = ctrDEOffset = sizeRA = sizeDE = -1;
      try {
        ctrRAOffset = Double.valueOf(ctrRAOffsetParam.getValue()).doubleValue();
        ctrDEOffset = Double.valueOf(ctrDEOffsetParam.getValue()).doubleValue();
        sizeRA = Double.valueOf(sizeRAParam.getValue()).doubleValue();
        sizeDE = Double.valueOf(sizeDEParam.getValue()).doubleValue();
      } catch (NumberFormatException e) {
        e.printStackTrace();
        return null;
      }

      int signRA, signDE;
      for (int i = 0; i < 4; i++) {
        signRA = (i == 1 || i == 2) ? 1 : -1;
        signDE = (i == 0 || i == 1) ? 1 : -1;

        // TODO : conversion en degrees en tenant compte des unités dans le VOTable!!
        raOffset[i] = (ctrRAOffset + signRA * sizeRA * 0.5) / 3600.;
        deOffset[i] = (ctrDEOffset + signDE * sizeDE * 0.5) / 3600.;
      }

      subFpBean = new SubFootprintBean(raOffset, deOffset, id);
      subFpBean.setInSphericalCoords(sphericalCoordinates);
      return subFpBean;

    } else if (type.equals("Circle")) {
      ParamSet params = table.getParams();
      int nbParams = params.getItemCount();

      SavotParam ctrXOffsetParam = null;
      SavotParam ctrYOffsetParam = null;
      SavotParam radiusParam = null;
      SavotParam param;
      String utype;
      // boucle sur les params
      for (int i = 0; i < nbParams; i++) {
        param = (SavotParam) params.getItemAt(i);
        param = getParam(param);
        utype = param.getUtype();
        //				System.out.println(utype);
        if (utype.equals("stc:AstroCoordArea/Region/reg:Sector/Center[1]")
            || utype.equals("stc:AstroCoordArea.Circle.Center.C1")) {
          ctrXOffsetParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Sector/Center[2]")
            || utype.equals("stc:AstroCoordArea.Circle.Center.C2")) {
          ctrYOffsetParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Circle/radius")
            || utype.equals("stc:AstroCoordArea.Circle.radius")) {
          radiusParam = param;

          continue;
        }
      }
      // pas de traitement possible dans un tel cas
      if (ctrXOffsetParam == null || ctrYOffsetParam == null || radiusParam == null) {
        return null;
      }

      double ctrXOffset, ctrYOffset, radius;

      try {
        ctrXOffset = Double.valueOf(ctrXOffsetParam.getValue()).doubleValue();
        ctrYOffset = Double.valueOf(ctrYOffsetParam.getValue()).doubleValue();
        radius = Double.valueOf(radiusParam.getValue()).doubleValue();
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }

      // TODO : conversion selon l'unité indiqué dans les params!!
      ctrXOffset = ctrXOffset / 3600.0;
      ctrYOffset = ctrYOffset / 3600.0;
      radius = radius / 3600.0;

      subFpBean = new SubFootprintBean(ctrXOffset, ctrYOffset, radius, id);
      subFpBean.setInSphericalCoords(sphericalCoordinates);
      return subFpBean;
    } else if (type.equals("Pickle")) {
      ParamSet params = table.getParams();
      int nbParams = params.getItemCount();

      SavotParam ctrXOffsetParam = null;
      SavotParam ctrYOffsetParam = null;
      SavotParam internalRadParam = null;
      SavotParam externalRadParam = null;
      SavotParam startAngleParam = null;
      SavotParam endAngleParam = null;

      SavotParam param;
      String utype;
      // boucle sur les params
      for (int i = 0; i < nbParams; i++) {
        param = (SavotParam) params.getItemAt(i);
        param = getParam(param);
        utype = param.getUtype();
        if (utype.equals("stc:AstroCoordArea/Region/reg:Sector/Center[1]")) {
          ctrXOffsetParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Sector/Center[2]")) {
          ctrYOffsetParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Sector/angle1")) {
          startAngleParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Sector/angle2")) {
          endAngleParam = param;

          continue;
        }
        // petite subtilité, car on a le meme utype pour internalRad et externalRad !!
        else if (utype.equals("stc:AstroCoordArea/Region/reg:Circle/radius")
            && internalRadParam == null) {
          internalRadParam = param;

          continue;
        } else if (utype.equals("stc:AstroCoordArea/Region/reg:Circle/radius")) {
          externalRadParam = param;

          continue;
        }
      }
      // pas de traitement possible dans un tel cas
      if (ctrXOffsetParam == null
          || ctrYOffsetParam == null
          || startAngleParam == null
          || endAngleParam == null
          || internalRadParam == null
          || externalRadParam == null) {
        return null;
      }

      double ctrXOffset, ctrYOffset, startAngle, endAngle, internalRad, externalRad;

      try {
        ctrXOffset = Double.valueOf(ctrXOffsetParam.getValue()).doubleValue();
        ctrYOffset = Double.valueOf(ctrYOffsetParam.getValue()).doubleValue();
        startAngle = Double.valueOf(startAngleParam.getValue()).doubleValue();
        endAngle = Double.valueOf(endAngleParam.getValue()).doubleValue();
        internalRad = Double.valueOf(internalRadParam.getValue()).doubleValue();
        externalRad = Double.valueOf(externalRadParam.getValue()).doubleValue();
      } catch (Exception e) {
        e.printStackTrace();
        return null;
      }

      // petite subtilité pour que le rayon interne soit le plus petit
      double tmp = internalRad;
      if (internalRad > externalRad) {
        internalRad = externalRad;
        externalRad = tmp;
      }

      // TODO : conversion selon l'unité indiqué dans les params!!
      ctrXOffset = ctrXOffset / 3600.0;
      ctrYOffset = ctrYOffset / 3600.0;
      double angle = endAngle - startAngle;
      internalRad = internalRad / 3600.0;
      externalRad = externalRad / 3600.0;

      subFpBean =
          new SubFootprintBean(
              ctrXOffset, ctrYOffset, startAngle, angle, internalRad, externalRad, id);
      subFpBean.setInSphericalCoords(sphericalCoordinates);
      return subFpBean;
    } else if (type.equals("String")) {
      ParamSet params = table.getParams();
      int nbParams = params.getItemCount();

      SavotParam raParam = null;
      SavotParam decParam = null;
      SavotParam contentParam = null;
      SavotParam param;
      String utype;
      // boucle sur les params
      for (int i = 0; i < nbParams; i++) {
        param = (SavotParam) params.getItemAt(i);
        param = getParam(param);
        utype = param.getUtype();
        if (utype.equals("stc:AstroCoord.Position2D.Value2.C1")) {
          raParam = param;
        } else if (utype.equals("stc:AstroCoord.Position2D.Value2.C2")) {
          decParam = param;
        } else if (utype.equals("app:footprint.render.overlay.string.content")) {
          contentParam = param;
        }
      }

      // pas de traitement possible dans un tel cas
      if (raParam == null || decParam == null || contentParam == null) {
        System.err.println("something is missing");
        return null;
      }

      double ra, dec;

      try {
        ra = Double.valueOf(raParam.getValue()).doubleValue();
        dec = Double.valueOf(decParam.getValue()).doubleValue();
      } catch (NumberFormatException nfe) {
        nfe.printStackTrace();
        return null;
      }

      ra = ra / 3600.0;
      dec = dec / 3600.0;

      subFpBean = new SubFootprintBean(ra, dec, "center", contentParam.getValue());
      subFpBean.setInSphericalCoords(sphericalCoordinates);
      return subFpBean;
    }

    return null;
  }