void TestPython3::testPython3Code() { { Cantor::Expression* e = evalExp(QLatin1String("print 1 + 2")); QVERIFY(e != 0); QVERIFY(!e->errorMessage().isEmpty()); } { Cantor::Expression* e = evalExp(QLatin1String("print(1 + 2)")); QVERIFY(e != 0); QVERIFY(e->result()->data().toString() == QLatin1String("3")); } }
void TestPython3::testCodeWithComments() { { Cantor::Expression* e = evalExp(QLatin1String("#comment\n1+2")); QVERIFY(e != 0); QVERIFY(e->result()->data().toString() == QLatin1String("3")); } { Cantor::Expression* e = evalExp(QLatin1String(" #comment\n1+2")); QVERIFY(e != 0); QVERIFY(e->result()->data().toString() == QLatin1String("3")); } }
void TestPython3::testImportNumpy() { Cantor::Expression* e = evalExp(QLatin1String("import numpy")); QVERIFY(e != 0); QVERIFY(e->result() != 0); }
double EnvWrap::evalDouble( const QString& nm ) { QScriptValue result = evalExp(nm); if (result.isNumber()) return result.toNumber(); else throw ExpressionHasNotThisTypeException("Double",nm); return double(); }
bool EnvWrap::evalBool( const QString& nm ) { QScriptValue result = evalExp(nm); if (result.isBool()) return result.toBool(); else throw ExpressionHasNotThisTypeException("Bool",nm); return false; }
vcg::Shotf EnvWrap::evalShot( const QString& nm ) { QScriptValue result = evalExp(nm); ShotSI* shot = qscriptvalue_cast<ShotSI*>(result); if (shot != NULL) return shot->shot; else throw ExpressionHasNotThisTypeException("Shotf",nm); return vcg::Shotf(); }
vcg::Point3f EnvWrap::evalVec3( const QString& nm ) { QScriptValue result = evalExp(nm); QVariant resVar = result.toVariant(); QVariantList resList = resVar.toList(); if (resList.size() == 3) return vcg::Point3f(resList[0].toReal(),resList[1].toReal(),resList[2].toReal()); else throw ExpressionHasNotThisTypeException("Vec3",nm); return vcg::Point3f(); }
QColor EnvWrap::evalColor( const QString& nm ) { QScriptValue result = evalExp(nm); QVariant resVar = result.toVariant(); QVariantList resList = resVar.toList(); int colorComp = resList.size(); if ((colorComp >= 3) && (colorComp <= 4)) { bool isReal01 = true; bool isInt0255 = true; for(int ii = 0;ii < colorComp;++ii) { bool isScalarReal = false; bool isScalarInt = false; float resFloat = (float) resList[ii].toReal(&isScalarReal); int resInt = resList[ii].toInt(&isScalarInt); if ((!isScalarReal) && (!isScalarInt)) throw ExpressionHasNotThisTypeException("Color",nm); if ((resFloat >= 0.0f) && (resFloat <= 1.0f)) { isReal01 = isReal01 && true; isInt0255 = false; } else if ((resInt >= 0) && (resInt <= 255)) { isInt0255 = isInt0255 && true; isReal01 = false; } } if (isReal01) { if (colorComp == 3) return QColor::fromRgbF(resList[0].toReal(),resList[1].toReal(),resList[2].toReal()); if (colorComp == 4) return QColor::fromRgbF(resList[0].toReal(),resList[1].toReal(),resList[2].toReal(),resList[3].toReal()); } else if (isInt0255) { //if the if (colorComp == 3) return QColor(resList[0].toInt(),resList[1].toInt(),resList[2].toInt()); if (colorComp == 4) return QColor(resList[0].toInt(),resList[1].toInt(),resList[2].toInt(),resList[3].toInt()); } else throw ExpressionHasNotThisTypeException("Color",nm); } else throw ExpressionHasNotThisTypeException("Color",nm); return QColor(); }
QString EnvWrap::evalString( const QString& nm ) { QScriptValue result = evalExp(nm); return result.toString(); }