bool wxLuaDebugTarget::EvaluateExpr(int exprRef, const wxString &strExpr) // FIXME - check this code { wxString strResult(wxT("Error")); int nReference = LUA_NOREF; EnterLuaCriticalSection(); { lua_State* L = m_wxlState.GetLuaState(); if (wxStrpbrk(strExpr.c_str(), wxT(" ~=<>+-*/%(){}[]:;,.\"'")) != NULL) { // an expression int nOldTop = lua_gettop(L); wxLuaCharBuffer charbuf(strExpr); int nResult = luaL_loadbuffer(L, charbuf.GetData(), charbuf.Length(), "debug"); if (nResult == 0) nResult = lua_pcall(L, 0, LUA_MULTRET, 0); // call main if (nResult != 0) wxlua_pushwxString(L, wxlua_LUA_ERR_msg(nResult)); else if (lua_gettop(L) == nOldTop) lua_pushliteral(L, "OK"); nReference = m_wxlState.wxluaR_Ref(-1, &wxlua_lreg_refs_key); lua_settop(L, nOldTop); // throw out all return values } else { lua_Debug ar = INIT_LUA_DEBUG; int iLevel = 0; bool fFound = false; while (lua_getstack(L, iLevel++, &ar) != 0) { int iIndex = 0; wxString name = lua2wx(lua_getlocal(L, &ar, ++iIndex)); if (!name.IsEmpty()) { if (strExpr == name) { nReference = m_wxlState.wxluaR_Ref(-1, &wxlua_lreg_refs_key); fFound = true; break; } lua_pop(L, 1); } if (fFound) break; name = lua2wx(lua_getlocal(L, &ar, ++iIndex)); } if (!fFound) { int nOldTop = lua_gettop(L); lua_pushvalue(L, LUA_GLOBALSINDEX); lua_pushnil(L); while (lua_next(L, -2) != 0) { if (lua_type(L, -2) == LUA_TSTRING) { wxString name = lua2wx(lua_tostring(L, -2)); if (strExpr == name) { nReference = m_wxlState.wxluaR_Ref(-1, &wxlua_lreg_refs_key); // reference value lua_pop(L, 2); // pop key and value fFound = true; break; } } lua_pop(L, 1); // removes 'value'; } lua_settop(L, nOldTop); // the table of globals. } } if (m_wxlState.wxluaR_GetRef(nReference, &wxlua_lreg_refs_key)) { m_wxlState.wxluaR_Unref(nReference, &wxlua_lreg_refs_key); int wxl_type = 0; wxString value; wxLuaDebugData::GetTypeValue(L, -1, &wxl_type, value); strResult.Printf(wxT("%s : %s"), wxluaT_typename(L, wxl_type).c_str(), value.c_str()); lua_pop(L, 1); } } LeaveLuaCriticalSection(); return NotifyEvaluateExpr(exprRef, strResult); }
CMapRmap::CMapRmap(const QString &key, const QString &fn, CCanvas *parent) : IMap(eRaster,key,parent) , zoomFactor(0.0) , needsRedrawOvl(true) { filename = fn; quadraticZoom = theMainWindow->getCheckBoxQuadraticZoom(); QFileInfo fi(fn); name = fi.baseName(); QFile file(filename); file.open(QIODevice::ReadOnly); QDataStream stream(&file); stream.setByteOrder(QDataStream::LittleEndian); QByteArray charbuf(20,0); stream.readRawData(charbuf.data(), 19); if("CompeGPSRasterImage" != QString(charbuf)) { QMessageBox::warning(0, tr("Error..."), tr("This is not a TwoNav RMAP file."), QMessageBox::Abort, QMessageBox::Abort); return; } quint32 tag1, tag2, tmp32; stream >> tag1 >> tag2 >> tmp32; if(tag1 != 10 || tag2 != 7) { QMessageBox::warning(0, tr("Error..."), tr("Unknown sub-format."), QMessageBox::Abort, QMessageBox::Abort); return; } stream >> xsize_px >> ysize_px; stream >> tmp32 >> tmp32; stream >> blockSizeX >> blockSizeY; ysize_px = -ysize_px; quint64 mapDataOffset; stream >> mapDataOffset; stream >> tmp32; qint32 nZoomLevels; stream >> nZoomLevels; for(int i=0; i < nZoomLevels; i++) { level_t level; stream >> level.offsetLevel; levels << level; } for(int i=0; i<levels.size(); i++) { level_t& level = levels[i]; file.seek(level.offsetLevel); stream >> level.width; stream >> level.height; stream >> level.xTiles; stream >> level.yTiles; for(int j=0; j<(level.xTiles * level.yTiles); j++) { quint64 offset; stream >> offset; level.offsetJpegs << offset; } } file.seek(mapDataOffset); stream >> tmp32 >> tmp32; charbuf.resize(tmp32 + 1); charbuf.fill(0); stream.readRawData(charbuf.data(), tmp32); QPoint p0; QPoint p1; QPoint p2; QPoint p3; projXY c0; projXY c1; projXY c2; projXY c3; bool pointsAreLongLat = true; QString projection; QString datum; QStringList lines = QString(charbuf).split("\r\n"); foreach(const QString& line, lines) { if(line.startsWith("Version=")) { if(line.split("=")[1] != "2") { QMessageBox::warning(0, tr("Error..."), tr("Unknown version."), QMessageBox::Abort, QMessageBox::Abort); return; } } else if(line.startsWith("Projection=")) { projection = line.split("=")[1]; } else if(line.startsWith("Datum=")) { datum = line.split("=")[1]; } else if(line.startsWith("P0=")) { QStringList vals = line.split("=")[1].split(","); if(vals.size() < 5) { QMessageBox::warning(0, tr("Error..."), tr("Failed to read reference point."), QMessageBox::Abort, QMessageBox::Abort); return; } p0 = QPoint(vals[0].toInt(), vals[1].toInt()); if(vals[2] == "A") { c0.u = vals[3].toDouble() * DEG_TO_RAD; c0.v = vals[4].toDouble() * DEG_TO_RAD; } else { c0.u = vals[3].toDouble(); c0.v = vals[4].toDouble(); } } else if(line.startsWith("P1=")) { QStringList vals = line.split("=")[1].split(","); if(vals.size() < 5) { QMessageBox::warning(0, tr("Error..."), tr("Failed to read reference point."), QMessageBox::Abort, QMessageBox::Abort); return; } p1 = QPoint(vals[0].toInt(), vals[1].toInt()); if(vals[2] == "A") { c1.u = vals[3].toDouble() * DEG_TO_RAD; c1.v = vals[4].toDouble() * DEG_TO_RAD; } else { pointsAreLongLat = false; c1.u = vals[3].toDouble(); c1.v = vals[4].toDouble(); } } else if(line.startsWith("P2=")) { QStringList vals = line.split("=")[1].split(","); if(vals.size() < 5) { QMessageBox::warning(0, tr("Error..."), tr("Failed to read reference point."), QMessageBox::Abort, QMessageBox::Abort); return; } p2 = QPoint(vals[0].toInt(), vals[1].toInt()); if(vals[2] == "A") { c2.u = vals[3].toDouble() * DEG_TO_RAD; c2.v = vals[4].toDouble() * DEG_TO_RAD; } else { pointsAreLongLat = false; c2.u = vals[3].toDouble(); c2.v = vals[4].toDouble(); } } else if(line.startsWith("P3=")) { QStringList vals = line.split("=")[1].split(","); if(vals.size() < 5) { QMessageBox::warning(0, tr("Error..."), tr("Failed to read reference point."), QMessageBox::Abort, QMessageBox::Abort); return; } p3 = QPoint(vals[0].toInt(), vals[1].toInt()); if(vals[2] == "A") { c3.u = vals[3].toDouble() * DEG_TO_RAD; c3.v = vals[4].toDouble() * DEG_TO_RAD; } else { pointsAreLongLat = false; c3.u = vals[3].toDouble(); c3.v = vals[4].toDouble(); } } else { // qDebug() << line; } qDebug() << line; } if(!projection.isEmpty() && !datum.isEmpty()) { if(!setProjection(projection, datum)) { QMessageBox::warning(0, tr("Error..."), tr("Unknown projection and datum (%1%2).").arg(projection).arg(datum), QMessageBox::Abort, QMessageBox::Abort); return; } } if(!pj_is_latlong(pjsrc)) { if(pointsAreLongLat) { pj_transform(pjtar, pjsrc, 1, 0, &c0.u, &c0.v, 0); pj_transform(pjtar, pjsrc, 1, 0, &c1.u, &c1.v, 0); pj_transform(pjtar, pjsrc, 1, 0, &c2.u, &c2.v, 0); pj_transform(pjtar, pjsrc, 1, 0, &c3.u, &c3.v, 0); } qDebug() << c0.u << c0.v; qDebug() << c1.u << c1.v; qDebug() << c2.u << c2.v; qDebug() << c3.u << c3.v; xref1 = 1e25; yref1 = -1e25; xref2 = -1e25; yref2 = 1e25; } else { xref1 = 180 * DEG_TO_RAD; yref1 = -90 * DEG_TO_RAD; xref2 = -180 * DEG_TO_RAD; yref2 = 90 * DEG_TO_RAD; } if(c0.u < xref1) xref1 = c0.u; if(c0.u > xref2) xref2 = c0.u; if(c1.u < xref1) xref1 = c1.u; if(c1.u > xref2) xref2 = c1.u; if(c2.u < xref1) xref1 = c2.u; if(c2.u > xref2) xref2 = c2.u; if(c0.v > yref1) yref1 = c0.v; if(c0.v < yref2) yref2 = c0.v; if(c1.v > yref1) yref1 = c1.v; if(c1.v < yref2) yref2 = c1.v; if(c2.v > yref1) yref1 = c2.v; if(c2.v < yref2) yref2 = c2.v; xscale = (xref2 - xref1) / xsize_px; yscale = (yref2 - yref1) / ysize_px; double widthL0 = levels[0].width; double heightL0 = levels[0].height; for(int i=0; i<levels.size(); i++) { level_t& level = levels[i]; level.xscale = xscale * widthL0 / level.width; level.yscale = yscale * heightL0 / level.height; qDebug() << i << level.xscale << level.yscale; } qDebug() << "xref1:" << xref1 << "yref1:" << yref1; qDebug() << "xref2:" << xref2 << "yref2:" << yref2; qDebug() << "map width:" << xsize_px << "height:" << ysize_px; qDebug() << "tile width:" << blockSizeX << "height:" << blockSizeY; qDebug() << "scale x: " << xscale << "y:" << yscale; x = xref1 + (xref2 - xref1); y = yref1 + (yref2 - yref1); SETTINGS; cfg.beginGroup("rmap/maps"); cfg.beginGroup(getKey()); x = cfg.value("lon", x).toDouble(); y = cfg.value("lat", y).toDouble(); zoomidx = cfg.value("zoomidx", zoomidx).toInt(); cfg.endGroup(); cfg.endGroup(); zoom(zoomidx); }