/**
   * Send a routed value from this node to the given destination node. The route should use the
   * appropriate setValue() method of the destination node. It should not attempt to cast the node
   * up to a higher level. Routing should also follow the standard rules for the loop breaking and
   * other appropriate rules for the specification.
   *
   * @param time The time that this route occurred (not necessarily epoch time. Should be treated as
   *     a relative value only)
   * @param srcIndex The index of the field in this node that the value should be sent from
   * @param destNode The node reference that we will be sending the value to
   * @param destIndex The index of the field in the destination node that the value should be sent
   *     to.
   */
  public void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) {

    // Simple impl for now.  ignores time and looping

    try {
      switch (srcIndex) {
        case FIELD_PICKING_GEOMETRY:
          destNode.setValue(destIndex, vfPickingGeometry);
          break;

        case FIELD_PICK_TARGET:
          destNode.setValue(destIndex, vfPickTarget, vfPickTarget.length);
          break;

        case FIELD_PICKED_GEOMETRY:
          destNode.setValue(destIndex, vfPickedGeometry, numPickedGeometry);
          break;

        case FIELD_OBJECT_TYPE:
          destNode.setValue(destIndex, vfObjectType, vfObjectType.length);
          break;

        default:
          super.sendRoute(time, srcIndex, destNode, destIndex);
      }
    } catch (InvalidFieldException ife) {
      System.err.println("BasePickingNode.sendRoute: No field! " + srcIndex);
      ife.printStackTrace();
    } catch (InvalidFieldValueException ifve) {
      System.err.println("BasePickingNode.sendRoute: Invalid field value: " + ifve.getMessage());
    }
  }
  /**
   * Copies all of the field values from the passed nodes into our own node.
   *
   * @param node The node to copy
   * @throws IllegalArgumentException The node is not a compatible node
   */
  public void copy(VRMLNodeType node) {
    checkNodeType(node);

    try {
      int index;
      VRMLFieldData field;

      super.copy((VRMLTimeControlledNodeType) node);

      index = node.getFieldIndex("loop");
      field = node.getFieldValue(index);
      setLoop(field.booleanValue);

      index = node.getFieldIndex("repeatS");
      field = node.getFieldValue(index);
      vfRepeatS = field.booleanValue;

      index = node.getFieldIndex("repeatT");
      field = node.getFieldValue(index);
      vfRepeatT = field.booleanValue;

      index = node.getFieldIndex("speed");
      field = node.getFieldValue(index);
      setSpeed(field.floatValue);

      index = node.getFieldIndex("url");
      field = node.getFieldValue(index);
      setUrl(field.stringArrayValue, field.numElements);

    } catch (VRMLException ve) {
      throw new IllegalArgumentException(ve.getMessage());
    }
  }
  /**
   * Send a routed value from this node to the given destination node. The route should use the
   * appropriate setValue() method of the destination node. It should not attempt to cast the node
   * up to a higher level. Routing should also follow the standard rules for the loop breaking and
   * other appropriate rules for the specification.
   *
   * @param time The time that this route occurred (not necessarily epoch time. Should be treated as
   *     a relative value only)
   * @param srcIndex The index of the field in this node that the value should be sent from
   * @param destNode The node reference that we will be sending the value to
   * @param destIndex The index of the field in the destination node that the value should be sent
   *     to.
   */
  public void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) {

    // Simple impl for now.  ignores time and looping. Note that for a
    // couple of the fields, if the array size is greater than the number
    // of components in it, we create a temporary array to send. This is
    // a negative hit, but it is very rare that someone will route out of
    // these fields, so we don't consider it to be a major impact compared
    // to the performance of having to reallocate the arrays every time
    // someone sets the values, which will happen much, much more often.

    try {
      switch (srcIndex) {
        case FIELD_BOUNDARY_COLOR:
          destNode.setValue(destIndex, vfBoundaryColor, 4);
          break;

        case FIELD_BOUNDARY_WIDTH:
          destNode.setValue(destIndex, vfBoundaryWidth);
          break;

        case FIELD_BOUNDARY_MODE_S:
          destNode.setValue(destIndex, vfBoundaryModeS);
          break;

        case FIELD_BOUNDARY_MODE_T:
          destNode.setValue(destIndex, vfBoundaryModeT);
          break;

        case FIELD_MAGNIFICATION_FILTER:
          destNode.setValue(destIndex, vfMagnificationFilter);
          break;

        case FIELD_MINIFICATION_FILTER:
          destNode.setValue(destIndex, vfMinificationFilter);
          break;

        case FIELD_GENERATE_MIPMAPS:
          destNode.setValue(destIndex, vfGenerateMipMaps);
          break;

        case FIELD_ANISOTROPIC_MODE:
          destNode.setValue(destIndex, vfAnisotropicMode);
          break;

        case FIELD_ANISOTROPIC_FILTER_DEGREE:
          destNode.setValue(destIndex, vfAnisotropicFilterDegree);
          break;

        default:
          super.sendRoute(time, srcIndex, destNode, destIndex);
      }
    } catch (InvalidFieldException ife) {
      System.err.println("sendRoute: No field!" + ife.getFieldName());
    } catch (InvalidFieldValueException ifve) {
      System.err.println("sendRoute: Invalid field Value: " + ifve.getMessage());
    }
  }
  /**
   * Set node content as replacement for the pickingGeometry field. This checks only for basic
   * geometry handling. If a concrete node needs a specific set of nodes, it should override this
   * method to check.
   *
   * @param app The new appearance. null will act like delete
   * @throws InvalidFieldValueException The node does not match the required type.
   */
  public void setPickingGeometry(VRMLNodeType child) throws InvalidFieldValueException {

    VRMLGeometryNodeType node;
    VRMLNodeType old_node;

    if (pPickingGeometry != null) old_node = pPickingGeometry;
    else old_node = vfPickingGeometry;

    if (child instanceof VRMLProtoInstance) {
      VRMLNodeType impl = ((VRMLProtoInstance) child).getImplementationNode();

      pPickingGeometry = (VRMLProtoInstance) child;

      while ((impl != null) && (impl instanceof VRMLProtoInstance))
        impl = ((VRMLProtoInstance) impl).getImplementationNode();

      if ((impl != null) && !(impl instanceof VRMLGeometryNodeType))
        throw new InvalidFieldValueException(GEOMETRY_PROTO_MSG);

      String name = impl.getVRMLNodeName();
      if (!validGeometryNodeNames.contains(name))
        throw new InvalidFieldValueException(PICK_GEOM_TYPE_MSG);

      node = (VRMLGeometryNodeType) impl;
    } else if (child instanceof VRMLGeometryNodeType) {
      String name = child.getVRMLNodeName();
      if (!validGeometryNodeNames.contains(name))
        throw new InvalidFieldValueException(PICK_GEOM_TYPE_MSG);

      pPickingGeometry = null;
      node = (VRMLGeometryNodeType) child;
    } else {
      throw new InvalidFieldValueException(GEOMETRY_NODE_MSG);
    }

    vfPickingGeometry = (VRMLGeometryNodeType) node;

    if (child != null) updateRefs(child, true);

    if (old_node != null) updateRefs(old_node, false);

    if (!inSetup) {
      if (old_node != null) stateManager.registerRemovedNode(old_node);

      if (child != null) stateManager.registerAddedNode(child);

      hasChanged[FIELD_PICKING_GEOMETRY] = true;
      fireFieldChanged(FIELD_PICKING_GEOMETRY);
    }
  }
  /**
   * Notification that the construction phase of this node has finished. If the node would like to
   * do any internal processing, such as setting up geometry, then go for it now.
   */
  public void setupFinished() {
    if (!inSetup) return;

    super.setupFinished();

    childCount = vfChildren.size();
    VRMLNodeType kid;

    for (int i = 0; i < childCount; i++) {
      kid = (VRMLNodeType) vfChildren.get(i);

      // Make sure the child is finished first.
      kid.setupFinished();
    }
  }
Example #6
0
  /**
   * Construct a new instance of this node based on the details from the given node. If the node is
   * not a group node, an exception will be thrown.
   *
   * @param node The node to copy
   * @throws IllegalArgumentException The node is not a Group node
   */
  public BaseCADFace(VRMLNodeType node) {
    this();

    checkNodeType(node);

    try {

      int index = node.getFieldIndex("name");
      VRMLFieldData field = node.getFieldValue(index);

      field = node.getFieldValue(index);
      vfName = field.stringValue;
    } catch (VRMLException ve) {
      throw new IllegalArgumentException(ve.getMessage());
    }
  }
Example #7
0
  /**
   * Notification that the construction phase of this node has finished. If the node would like to
   * do any internal processing, such as setting up geometry, then go for it now.
   */
  public void setupFinished() {
    if (!inSetup) return;

    super.setupFinished();

    if (pShape != null) pShape.setupFinished();

    if (vfShape != null) vfShape.setupFinished();
  }
  /**
   * Check to make sure the picking target node being added is of the correct type. If not, issue an
   * error.
   *
   * @param target The node to check that it follows the requirements
   * @throws InvalidFieldValueException The node is not a grouping or shape node
   */
  protected void checkPickTargetType(VRMLNodeType target) throws InvalidFieldValueException {

    if ((target instanceof VRMLGroupingNodeType) || (target instanceof VRMLShapeNodeType)) return;

    if (!(target instanceof VRMLProtoInstance))
      throw new InvalidFieldValueException(
          "pickTarget node not a group or shape node type: " + target.getVRMLNodeName());

    VRMLProtoInstance proto = (VRMLProtoInstance) target;
    VRMLNodeType node = proto.getImplementationNode();

    while ((node != null) && (node instanceof VRMLProtoInstance))
      node = ((VRMLProtoInstance) node).getImplementationNode();

    if ((node != null)
        && (!(node instanceof VRMLGroupingNodeType) && !(node instanceof VRMLShapeNodeType)))
      throw new InvalidFieldValueException(
          "pickTarget proto instance not a group or shape node type: " + target.getVRMLNodeName());
  }
  /**
   * Notification that the construction phase of this node has finished. If the node would like to
   * do any internal processing, such as setting up geometry, then go for it now.
   */
  public void setupFinished() {
    if (!inSetup) return;

    super.setupFinished();

    if (pPickingGeometry != null) pPickingGeometry.setupFinished();
    if (vfPickingGeometry != null) vfPickingGeometry.setupFinished();

    numPickTarget = targetList.size();
    vfPickTarget = new VRMLNodeType[numPickTarget];
    for (int i = 0; i < numPickTarget; i++) {
      VRMLNodeType p = (VRMLNodeType) targetList.get(i);
      p.setupFinished();
      vfPickTarget[i] = p;
    }

    targetList = null;

    updateChildren(vfPickTarget, numPickTarget);
  }
  /**
   * Send a routed value from this node to the given destination node. The route should use the
   * appropriate setValue() method of the destination node. It should not attempt to cast the node
   * up to a higher level. Routing should also follow the standard rules for the loop breaking and
   * other appropriate rules for the specification.
   *
   * @param time The time that this route occurred (not necessarily epoch time. Should be treated as
   *     a relative value only)
   * @param srcIndex The index of the field in this node that the value should be sent from
   * @param destNode The node reference that we will be sending the value to
   * @param destIndex The index of the field in the destination node that the value should be sent
   *     to.
   */
  public void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) {

    // Simple impl for now.  ignores time and looping

    try {
      switch (srcIndex) {
        case FIELD_TEXTURE_PROPERTIES:
          if (pTextureProperties != null) destNode.setValue(destIndex, pTextureProperties);
          else destNode.setValue(destIndex, vfTextureProperties);
          break;

        default:
          super.sendRoute(time, srcIndex, destNode, destIndex);
      }
    } catch (InvalidFieldException ife) {
      System.err.println("sendRoute: No field!" + ife.getFieldName());
    } catch (InvalidFieldValueException ifve) {
      System.err.println("sendRoute: Invalid field Value: " + ifve.getMessage());
    }
  }
  /**
   * Construct a new instance of this node based on the details from the given node. If the node is
   * not the same type, an exception will be thrown.
   *
   * @param node The node to copy
   * @throws IllegalArgumentException Incorrect Node Type
   */
  protected BaseMultiTexture(VRMLNodeType node) {
    this();

    checkNodeType(node);

    try {
      int index = node.getFieldIndex("mode");
      VRMLFieldData field = node.getFieldValue(index);
      if (field.numElements != 0) {
        vfMode = new String[field.numElements];
        System.arraycopy(field.stringArrayValue, 0, vfMode, 0, field.numElements);
      }

      index = node.getFieldIndex("function");
      field = node.getFieldValue(index);
      if (field.numElements != 0) {
        vfFunction = new String[field.numElements];
        System.arraycopy(field.stringArrayValue, 0, vfFunction, 0, field.numElements);
      }

      index = node.getFieldIndex("source");
      field = node.getFieldValue(index);
      if (field.numElements != 0) {
        vfSource = new String[field.numElements];
        System.arraycopy(field.stringArrayValue, 0, vfSource, 0, field.numElements);
      }

      index = node.getFieldIndex("color");
      field = node.getFieldValue(index);
      vfColor[0] = field.floatArrayValue[0];
      vfColor[1] = field.floatArrayValue[1];
      vfColor[2] = field.floatArrayValue[2];

      index = node.getFieldIndex("alpha");
      field = node.getFieldValue(index);
      vfAlpha = field.floatValue;

    } catch (VRMLException ve) {
      throw new IllegalArgumentException(ve.getMessage());
    }
  }
Example #12
0
  /**
   * Send a routed value from this node to the given destination node. The route should use the
   * appropriate setValue() method of the destination node. It should not attempt to cast the node
   * up to a higher level. Routing should also follow the standard rules for the loop breaking and
   * other appropriate rules for the specification.
   *
   * @param time The time that this route occurred (not necessarily epoch time. Should be treated as
   *     a relative value only)
   * @param srcIndex The index of the field in this node that the value should be sent from
   * @param destNode The node reference that we will be sending the value to
   * @param destIndex The index of the field in the destination node that the value should be sent
   *     to.
   */
  public void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) {

    // Simple impl for now.  ignores time and looping

    try {
      switch (srcIndex) {
        case FIELD_NAME:
          destNode.setValue(destIndex, vfName);
          break;
        case FIELD_SHAPE:
          if (pShape != null) destNode.setValue(destIndex, pShape);
          else destNode.setValue(destIndex, vfShape);
          break;

        default:
          super.sendRoute(time, srcIndex, destNode, destIndex);
      }
    } catch (InvalidFieldException ife) {
      System.err.println("sendRoute: No field!" + ife.getFieldName());
    } catch (InvalidFieldValueException ifve) {
      System.err.println("sendRoute: Invalid fieldValue: " + ifve.getMessage());
    }
  }
  /**
   * Add a single child node to the list of available children. Override to
   * provide.renderer-specific behaviour, but remember to also call this implementation too.
   *
   * @param node The node to add
   */
  protected void addChildNode(VRMLNodeType node) {

    if (node instanceof VRMLProtoInstance) {
      VRMLNodeType impl = ((VRMLProtoInstance) node).getImplementationNode();

      // Walk down the proto impl looking for the real node to check it
      // is the right type.
      while ((impl != null) && (impl instanceof VRMLProtoInstance))
        impl = ((VRMLProtoInstance) impl).getImplementationNode();

      if ((impl != null) && !(impl instanceof VRMLWorldRootChildNodeType))
        throw new InvalidFieldValueException(NON_CHILD_PROTO_MSG + node.getVRMLNodeName());

    } else if (node != null && !(node instanceof VRMLWorldRootChildNodeType)) {
      throw new InvalidFieldValueException(NON_CHILD_NODE_MSG + node.getVRMLNodeName());
    }

    if (node != null) updateRefs(node, true);

    vfChildren.add(node);
    childCount++;

    if (!inSetup) stateManager.registerAddedNode(node);
  }
  /**
   * Send a routed value from this node to the given destination node. The route should use the
   * appropriate setValue() method of the destination node. It should not attempt to cast the node
   * up to a higher level. Routing should also follow the standard rules for the loop breaking and
   * other appropriate rules for the specification.
   *
   * @param time The time that this route occurred (not necessarily epoch time. Should be treated as
   *     a relative value only)
   * @param srcIndex The index of the field in this node that the value should be sent from
   * @param destNode The node reference that we will be sending the value to
   * @param destIndex The index of the field in the destination node that the value should be sent
   *     to.
   */
  public void sendRoute(double time, int srcIndex, VRMLNodeType destNode, int destIndex) {

    // Simple impl for now.  ignores time and looping

    try {
      switch (srcIndex) {
        case FIELD_MODE:
          destNode.setValue(destIndex, vfMode, vfMode.length);
          break;

        case FIELD_FUNCTION:
          destNode.setValue(destIndex, vfFunction, vfFunction.length);
          break;

        case FIELD_SOURCE:
          destNode.setValue(destIndex, vfSource, vfSource.length);
          break;

        case FIELD_COLOR:
          destNode.setValue(destIndex, vfColor, 3);
          break;

        case FIELD_TEXTURE:
          VRMLNodeType kids[] = new VRMLNodeType[vfTexture.size()];
          vfTexture.toArray(kids);
          destNode.setValue(destIndex, kids, kids.length);
          break;

        case FIELD_ALPHA:
          destNode.setValue(destIndex, vfAlpha);
          break;

        default:
          super.sendRoute(time, srcIndex, destNode, destIndex);
      }
    } catch (InvalidFieldException ife) {
      System.err.println("sendRoute: No field!" + ife.getFieldName());
    } catch (InvalidFieldValueException ifve) {
      System.err.println("sendRoute: Invalid field Value: " + ifve.getMessage());
    }
  }
  /**
   * Construct a new instance of this node based on the details from the given node. If the node is
   * not the same type, an exception will be thrown.
   *
   * @param node The node to copy
   * @throws IllegalArgumentException Incorrect Node Type
   */
  protected BaseTextureProperties(VRMLNodeType node) {
    this();

    checkNodeType(node);

    try {
      int index = node.getFieldIndex("boundaryColor");
      VRMLFieldData field = node.getFieldValue(index);

      vfBoundaryColor[0] = field.floatArrayValue[0];
      vfBoundaryColor[1] = field.floatArrayValue[1];
      vfBoundaryColor[2] = field.floatArrayValue[2];
      vfBoundaryColor[3] = field.floatArrayValue[3];

      index = node.getFieldIndex("boundaryWidth");
      field = node.getFieldValue(index);
      vfBoundaryWidth = field.intValue;

      index = node.getFieldIndex("boundaryModeS");
      field = node.getFieldValue(index);
      vfBoundaryModeS = field.stringValue;

      index = node.getFieldIndex("boundaryModeT");
      field = node.getFieldValue(index);
      vfBoundaryModeT = field.stringValue;

      index = node.getFieldIndex("minificationFilter");
      field = node.getFieldValue(index);
      vfMinificationFilter = field.stringValue;

      index = node.getFieldIndex("maxificationFilter");
      field = node.getFieldValue(index);
      vfMinificationFilter = field.stringValue;

      index = node.getFieldIndex("generateMipMaps");
      field = node.getFieldValue(index);
      vfGenerateMipMaps = field.booleanValue;

      index = node.getFieldIndex("anisotropicMode");
      field = node.getFieldValue(index);
      vfAnisotropicMode = field.stringValue;

      index = node.getFieldIndex("anisotropicFilterDegree");
      field = node.getFieldValue(index);
      vfAnisotropicFilterDegree = field.floatValue;

    } catch (VRMLException ve) {
      throw new IllegalArgumentException(ve.getMessage());
    }
  }