예제 #1
0
  /**
   * Determine and set the {@link Path} highlight attributes from the KML <i>Feature</i> fields.
   *
   * @param attrType the type of attributes, either {@link KMLConstants#NORMAL} or {@link
   *     KMLConstants#HIGHLIGHT}.
   * @return the new attributes.
   */
  protected ShapeAttributes makeAttributesCurrent(String attrType) {
    ShapeAttributes attrs =
        this.getInitialAttributes(
            this.isHighlighted() ? KMLConstants.HIGHLIGHT : KMLConstants.NORMAL);

    // Get the KML sub-style for Line attributes. Map them to Shape attributes.

    KMLAbstractSubStyle lineSubStyle = this.parent.getSubStyle(new KMLLineStyle(null), attrType);
    if (!this.isHighlighted() || KMLUtil.isHighlightStyleState(lineSubStyle)) {
      KMLUtil.assembleLineAttributes(attrs, (KMLLineStyle) lineSubStyle);
      if (lineSubStyle.hasField(AVKey.UNRESOLVED)) attrs.setUnresolved(true);
    }

    // Get the KML sub-style for interior attributes. Map them to Shape attributes.

    KMLAbstractSubStyle fillSubStyle = this.parent.getSubStyle(new KMLPolyStyle(null), attrType);
    if (!this.isHighlighted() || KMLUtil.isHighlightStyleState(lineSubStyle)) {
      KMLUtil.assembleInteriorAttributes(attrs, (KMLPolyStyle) fillSubStyle);
      if (fillSubStyle.hasField(AVKey.UNRESOLVED)) attrs.setUnresolved(true);
    }

    attrs.setDrawInterior(((KMLPolyStyle) fillSubStyle).isFill());
    attrs.setDrawOutline(((KMLPolyStyle) fillSubStyle).isOutline());

    return attrs;
  }
  /**
   * Apply the model's position, orientation, and scale to a COLLADA root.
   *
   * @param root COLLADA root to configure.
   */
  protected void configureColladaRoot(ColladaRoot root) {
    root.setResourceResolver(this);

    Position refPosition = this.model.getLocation().getPosition();
    root.setPosition(refPosition);
    root.setAltitudeMode(KMLUtil.convertAltitudeMode(this.model.getAltitudeMode()));

    KMLOrientation orientation = this.model.getOrientation();
    if (orientation != null) {
      Double d = orientation.getHeading();
      if (d != null) root.setHeading(Angle.fromDegrees(d));

      d = orientation.getTilt();
      if (d != null) root.setPitch(Angle.fromDegrees(-d));

      d = orientation.getRoll();
      if (d != null) root.setRoll(Angle.fromDegrees(-d));
    }

    KMLScale scale = this.model.getScale();
    if (scale != null) {
      Double x = scale.getX();
      Double y = scale.getY();
      Double z = scale.getZ();

      Vec4 modelScale = new Vec4(x != null ? x : 1.0, y != null ? y : 1.0, z != null ? z : 1.0);

      root.setModelScale(modelScale);
    }
  }
  /**
   * Create an screen image.
   *
   * @param tc the current {@link KMLTraversalContext}.
   * @param overlay the <i>Overlay</i> element containing.
   * @throws NullPointerException if the traversal context is null.
   * @throws IllegalArgumentException if the parent overlay or the traversal context is null.
   */
  public KMLScreenImageImpl(KMLTraversalContext tc, KMLScreenOverlay overlay) {
    this.parent = overlay;

    if (tc == null) {
      String msg = Logging.getMessage("nullValue.TraversalContextIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    if (overlay == null) {
      String msg = Logging.getMessage("nullValue.ParentIsNull");
      Logging.logger().severe(msg);
      throw new IllegalArgumentException(msg);
    }

    KMLVec2 xy = this.parent.getScreenXY();
    if (xy != null) {
      this.screenOffset =
          new Offset(
              xy.getX(),
              xy.getY(),
              KMLUtil.kmlUnitsToWWUnits(xy.getXunits()),
              KMLUtil.kmlUnitsToWWUnits(xy.getYunits()));
    }

    xy = this.parent.getOverlayXY();
    if (xy != null) {
      this.imageOffset =
          new Offset(
              xy.getX(),
              xy.getY(),
              KMLUtil.kmlUnitsToWWUnits(xy.getXunits()),
              KMLUtil.kmlUnitsToWWUnits(xy.getYunits()));
    }

    this.setRotation(overlay.getRotation());

    xy = this.parent.getRotationXY();
    if (xy != null) {
      setRotationOffset(
          new Offset(
              xy.getX(),
              xy.getY(),
              KMLUtil.kmlUnitsToWWUnits(xy.getXunits()),
              KMLUtil.kmlUnitsToWWUnits(xy.getYunits())));
    }

    String colorStr = overlay.getColor();
    if (colorStr != null) {
      Color color = WWUtil.decodeColorABGR(colorStr);
      this.setColor(color);
    }

    // Compute desired image size, and the scale factor that will make it that size
    KMLVec2 kmlSize = this.parent.getSize();
    if (kmlSize != null) {
      Size size = new Size();
      size.setWidth(
          getSizeMode(kmlSize.getX()),
          kmlSize.getX(),
          KMLUtil.kmlUnitsToWWUnits(kmlSize.getXunits()));
      size.setHeight(
          getSizeMode(kmlSize.getY()),
          kmlSize.getY(),
          KMLUtil.kmlUnitsToWWUnits(kmlSize.getYunits()));
      this.setSize(size);
    }
  }