Changeset 13724


Ignore:
Timestamp:
Oct 10, 2019 4:41:32 PM (6 weeks ago)
Author:
randersson
Message:

#5819 Added new method to convert jobject to strings. Also replaced previous test of "toPyUnicode" with this method since the test was wrong. Note that one toString() is still in place and it should be since it is the original toString function. At this point modelicacasadiinterface is building.

Location:
branches/dev-5819/ModelicaCasADiInterface/src
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/dev-5819/ModelicaCasADiInterface/src/CMakeLists.txt

    r9932 r13724  
    5959  FlatEquations.cpp
    6060  BLT.cpp
     61  utils.cpp
    6162  ${TYPES_CPP}
    6263  jcc/initjcc.cpp
     
    9293  FlatEquations.hpp
    9394  BLT.hpp
     95  utils.hpp
    9496  ${TYPES_HPP}
    9597  jcc/initjcc.h
  • branches/dev-5819/ModelicaCasADiInterface/src/CompilerOptionsWrapper.cpp

    r13706 r13724  
    2323#include "java/lang/String.h"
    2424#include <string>
    25 #define PYTHON
    2625#include "JCCEnv.h"
    2726
    2827#include "CompilerOptionsWrapper.hpp"
     28#include "utils.hpp"
    2929
    3030
     
    7070        while(iter.hasNext()){
    7171            java::lang::String key(iter.next().this$);
    72             out <<"\033[31m"<<env->toPyUnicode(key.this$) <<"\033[0m"<< ": ";
    73             out << env->toPyUnicode(optr.getDescription(key).this$);
     72            out <<"\033[31m"<<jobjectoToString(key.this$) <<"\033[0m"<< ": ";
     73            out << jobjectoToString(optr.getDescription(key).this$);
    7474            out << "\n";
    7575        }
     
    9090}
    9191
    92 void ModelicaOptionsWrapper::print(std::ostream& os) const { os << "ModelicaOptionsWrapper(" << env->toPyUnicode(optr.this$) << ")"; }
     92void ModelicaOptionsWrapper::print(std::ostream& os) const { os << "ModelicaOptionsWrapper(" << jobjectoToString(optr.this$) << ")"; }
    9393
    9494void OptimicaOptionsWrapper::setStringOption(std::string opt, std::string val) {
     
    131131        while(iter.hasNext()){
    132132            java::lang::String key(iter.next().this$);
    133             out <<"\033[31m"<<env->toPyUnicode(key.this$) <<"\033[0m"<< ": ";
    134             out << env->toPyUnicode(optr.getDescription(key).this$);
     133            out <<"\033[31m"<<jobjectoToString(key.this$) <<"\033[0m"<< ": ";
     134            out << jobjectoToString(optr.getDescription(key).this$);
    135135            out << "\n";
    136136        }
     
    150150    return roption;
    151151}
    152 
    153 void OptimicaOptionsWrapper::print(std::ostream& os) const { os << "OptimicaOptionsWrapper(" << env->toPyUnicode(optr.this$) << ")"; }
     152void OptimicaOptionsWrapper::print(std::ostream& os) const { os << "OptimicaOptionsWrapper(" << jobjectoToString(optr.this$) << ")"; }
    154153}; // End namespace
  • branches/dev-5819/ModelicaCasADiInterface/src/sharedTransferFunctionality.hpp

    r13698 r13724  
    4949#include "FlatEquations.hpp"
    5050#include "BLT.hpp"
    51 
     51#include "utils.hpp"
    5252#include "initjcc.h" // for env
    5353#include "JCCEnv.h"
     
    314314        AbstractEquation eq = AbstractEquation(equationList.get(i).this$);
    315315        if (eq.isIgnoredForCasADi()) {
    316             char *str = env->toPyUnicode(eq.this$);
     316            char *str = jobjectoToString(eq.this$);
    317317            std::cerr << "Warning: Ignored equation:\n" << str << std::endl;
    318318            delete[] str;
     
    448448    if(fv.hasFStringComment()) {
    449449        Comment comment = Comment(fv.getFStringComment().this$);
    450         var->setAttribute("comment", casadi::MX::sym(env->toPyUnicode(comment.getComment().this$)));
     450        var->setAttribute("comment", casadi::MX::sym(jobjectoToString(comment.getComment().this$)));
    451451    }
    452452}
     
    466466    for (int i = 0; i < attributeList.getNumChild(); ++i) {
    467467        attr = Attribute(attributeList.getChild(i).this$);
    468         std::string name = env->toPyUnicode(attr.name().this$);
     468        std::string name = jobjectoToString(attr.name().this$);
    469469        if (name != "stateSelect" && name.find("__") != 0) {
    470470            // Don't transfer stateSelect attribute, since enumerations are not supported
     
    561561    List attributeList = derivedType.getFAttributes();
    562562    Attribute  attr;
    563     std::string typeName = env->toPyUnicode(derivedType.getName().this$);
    564     std::string baseTypeName = env->toPyUnicode((Type(derivedType.getBaseType().this$)).toPyUnicode().this$);
     563    std::string typeName = jobjectoToString(derivedType.getName().this$);
     564    std::string baseTypeName = jobjectoToString((Type(derivedType.getBaseType().this$)).toString().this$);
    565565    ModelicaCasADi::Ref<ModelicaCasADi::UserType> userType = new ModelicaCasADi::UserType(typeName, getBaseTypeForDerivedType(m, baseTypeName));
    566566    for (int i = 0; i < attributeList.getNumChild(); ++i) {
    567567        attr = Attribute(attributeList.getChild(i).this$);
    568         userType->setAttribute(env->toPyUnicode(attr.name().this$), toMX(attr.getValue()));
     568        userType->setAttribute(jobjectoToString(attr.name().this$), toMX(attr.getValue()));
    569569    }
    570570    m->addNewVariableType(userType);
     
    607607{
    608608    ModelicaCasADi::Ref<ModelicaCasADi::UserType> userType;
    609     if (!std::string(env->toPyUnicode(fv.getDerivedType().this$)).empty()) {
    610         userType = (ModelicaCasADi::UserType*) m->getVariableType(env->toPyUnicode(fv.getDerivedType().this$)).getNode();
     609    if (!std::string(jobjectoToString(fv.getDerivedType().this$)).empty()) {
     610        userType = (ModelicaCasADi::UserType*) m->getVariableType(jobjectoToString(fv.getDerivedType().this$)).getNode();
    611611        if(userType.getNode() == NULL) {
    612612            throw std::runtime_error("Variable's derived type not present in Model when Variable transferred");
     
    693693    }
    694694   
    695     std::string aliasName = env->toPyUnicode(fv.alias().name().this$);
     695    std::string aliasName = jobjectoToString(fv.alias().name().this$);
    696696    ModelicaCasADi::Ref<ModelicaCasADi::Variable> aliasVariable = m->getVariable(aliasName);
    697697    if (aliasVariable == NULL) {
     
    725725        FVar var = FVar(vars.get(i).this$);
    726726        if (var.type().isEnum()) {
    727             char *str = env->toPyUnicode(var.this$);
     727            char *str = jobjectoToString(var.this$);
    728728            std::cerr << "Warning: Ignored enumeration typed variable:\n" << str << std::endl;
    729729            delete[] str;
  • branches/dev-5819/ModelicaCasADiInterface/src/transferModelica.cpp

    r13698 r13724  
    9696#include "FlatEquations.hpp"
    9797#include "BLT.hpp"
     98#include "utils.hpp"
    9899
    99100// For transforming output from JCC-wrapped classes to CasADi objects.
     
    174175            StringFromUTF(modelName.c_str()));
    175176
    176         std::string identfier = env->toPyUnicode(fclass.nameUnderscore().this$);
     177        std::string identfier = jobjectoToString(fclass.nameUnderscore().this$);
    177178        // Initialize the model with the model identfier.
    178179        m->initializeModel(identfier);
  • branches/dev-5819/ModelicaCasADiInterface/src/transferOptimica.cpp

    r13698 r13724  
    7777#include "mxvectorwrap.hpp"
    7878#include "mxfunctionwrap.hpp"
     79#include "utils.hpp"
    7980
    8081namespace oc = org::jmodelica::optimica::compiler;
     
    172173                StringFromUTF(modelName.c_str())).this$);
    173174
    174             std::string identfier = env->toPyUnicode(fclass.nameUnderscore().this$);
     175            std::string identfier = jobjectoToString(fclass.nameUnderscore().this$);
    175176            std::string option = "normalize_minimum_time_problems";
    176177            bool normalizedTime = fclass.myOptions().getBooleanOption(StringFromUTF(option.c_str()));
Note: See TracChangeset for help on using the changeset viewer.