/**
   * Fill the port with the parameters from the model structure.
   *
   * @param port the target instance
   */
  private void decodeModel(InputPort port) {
    ScilabDouble dataLines = (ScilabDouble) model.get(MODEL_IN_DATALINE_INDEX);
    ScilabDouble dataColumns = (ScilabDouble) model.get(MODEL_IN_DATACOL_INDEX);
    ScilabDouble dataType = (ScilabDouble) model.get(MODEL_IN_DATATYPE_INDEX);

    // The number of row of the port
    int nbLines;
    if (dataLines.getRealPart() != null) {
      nbLines = (int) dataLines.getRealPart()[alreadyDecodedCount][0];
    } else {
      nbLines = 1;
    }

    // The number of column of the port
    int nbColumns;
    if (dataColumns.getRealPart() != null) {
      try {
        nbColumns = (int) dataColumns.getRealPart()[alreadyDecodedCount][0];
      } catch (ArrayIndexOutOfBoundsException e) {
        nbColumns = 1;
      }
    } else {
      nbColumns = 1;
    }

    // port scilab type
    int type;
    if (dataType.getRealPart() != null) {
      try {
        type = (int) dataType.getRealPart()[alreadyDecodedCount][0];
      } catch (ArrayIndexOutOfBoundsException e) {
        type = 1;
      }
    } else {
      type = 1;
    }

    VectorOfInt v = new VectorOfInt(3);
    v.set(0, nbLines);
    v.set(1, nbColumns);
    v.set(2, type);
    controller.setObjectProperty(port.getUID(), port.getKind(), ObjectProperties.DATATYPE, v);
  }
  /**
   * Change the label of the port according to the integer parameters property.
   *
   * @param source the source of the block
   */
  public void updateLabel(final BasicBlock source) {
    /** Get the input port children */
    final List<InputPort> ports = new ArrayList<InputPort>();
    for (int i = 0; i < source.getChildCount(); i++) {
      final mxICell port = source.getChildAt(i);

      if (port instanceof InputPort) {
        ports.add((InputPort) port);
      }
    }

    /** Set the ports labels */
    JavaController controller = new JavaController();
    VectorOfInt ipar = new VectorOfInt();
    controller.getObjectProperty(source.getUID(), Kind.BLOCK, ObjectProperties.IPAR, ipar);

    for (int i = 0; i < ports.size(); i++) {
      final int gain;

      if (i < ipar.size()) {
        gain = ipar.get(i);
      } else {
        gain = 1;
      }

      ports.get(i).setValue(getLabel(gain));
    }

    /** Check if all the values are equal to the default one. */
    if (!hasDefaultValue(ports)) {
      return;
    }

    /** When all values are equal to the default one, set it to the block and hide the children. */
    source.setValue(NOT_PRINTED_LABEL);
    for (InputPort port : ports) {
      port.setValue("");
    }
  }
Exemple #3
0
 /**
  * Utility to display a vec on debug
  *
  * @param vec the vector to convert
  * @return a representative string
  */
 public static String toString(VectorOfInt vec) {
   int len = vec.size();
   int[] copy = new int[len];
   IntBuffer.wrap(copy).put(vec.asByteBuffer(0, len).asIntBuffer());
   return Arrays.toString(copy);
 }