Пример #1
0
/* getArrayElement: puts pointer to array element on stack */
void getArrayElement( Symbol *s )
{
    int         index;
    Array       *array;
    Variant     *v;

    eMemTest( "getArrayElement: symbol", s );
    array = getArray( s );

    /* dynamic or static? */
    if (array->isDynamic) {
        getDynamicValue( array, s );

    } else {
        /* static array */

        index = getStaticIndex( array, s );
        v = array->data.item+index;
        eMemTest( "getArrayElement: array element", v );

        tos++;
        stack[tos].datatype = DATA_REF;
        stack[tos].value.ref = v;

    }

}
Пример #2
0
/*!
 * \brief TextAnnotation::updateTextString
 * Updates the text to display.
 */
void TextAnnotation::updateTextString()
{
  /* optional DynamicSelect of textString attribute */
  QVariant dynamicValue; // isNull() per default
  if (mDynamicTextString.count() > 0) {
    dynamicValue = getDynamicValue(mDynamicTextString.at(0).toString());
  }
  if (!dynamicValue.isNull()) {
    mTextString = dynamicValue.toString();
    if (mTextString.isEmpty()) {
      /* use variable name as default value if result not found */
      mTextString = mDynamicTextString.at(0).toString();
    }
    else if (mDynamicTextString.count() > 1) {
      int digits = mDynamicTextString.at(1).toInt();
      mTextString = QString::number(mTextString.toDouble(), 'g', digits);
    }
    return;
  }
  /* alternatively use model provided value */
  /* From Modelica Spec 32revision2,
   * There are a number of common macros that can be used in the text, and they should be replaced when displaying
   * the text as follows:
   * - %par replaced by the value of the parameter par. The intent is that the text is easily readable, thus if par is
   * of an enumeration type, replace %par by the item name, not by the full name.
   * [Example: if par="Modelica.Blocks.Types.Enumeration.Periodic", then %par should be displayed as "Periodic"]
   * - %% replaced by %
   * - %name replaced by the name of the component (i.e. the identifier for it in in the enclosing class).
   * - %class replaced by the name of the class.
   */
  mTextString = mOriginalTextString;
  if (!mTextString.contains("%")) {
    return;
  }
  if (mOriginalTextString.toLower().contains("%name")) {
    mTextString.replace(QRegExp("%name"), mpComponent->getName());
  }
  if (mOriginalTextString.toLower().contains("%class")) {
    mTextString.replace(QRegExp("%class"), mpComponent->getLibraryTreeItem()->getNameStructure());
  }
  if (!mTextString.contains("%")) {
    return;
  }
  /* handle variables now */
  updateTextStringHelper(QRegExp("(%%|%\\w*)"));
  /* call again with non-word characters so invalid % can be removed. */
  updateTextStringHelper(QRegExp("(%%|%\\W*)"));
  /* handle %% */
  if (mOriginalTextString.toLower().contains("%%")) {
    mTextString.replace(QRegExp("%%"), "%");
  }
}