Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
eb7e211ff2
32 changed files with 1024 additions and 111 deletions
|
@ -113,9 +113,9 @@
|
||||||
</condition>
|
</condition>
|
||||||
<then>
|
<then>
|
||||||
<echo>Not using native, excluding from build</echo>
|
<echo>Not using native, excluding from build</echo>
|
||||||
<move file="${native.libs.absolute.dir}/armeabi" tofile="${native.libs.absolute.dir}.skipped/armeabi" />
|
<move file="${native.libs.absolute.dir}/armeabi" tofile="${native.libs.absolute.dir}.skipped/armeabi" failonerror="no"/>
|
||||||
<move file="${native.libs.absolute.dir}/armeabi-v7a" tofile="${native.libs.absolute.dir}.skipped/armeabi-v7a" />
|
<move file="${native.libs.absolute.dir}/armeabi-v7a" tofile="${native.libs.absolute.dir}.skipped/armeabi-v7a" failonerror="no"/>
|
||||||
<move file="${native.libs.absolute.dir}/x86" tofile="${native.libs.absolute.dir}.skipped/x86" />
|
<move file="${native.libs.absolute.dir}/x86" tofile="${native.libs.absolute.dir}.skipped/x86" failonerror="no"/>
|
||||||
</then>
|
</then>
|
||||||
<else>
|
<else>
|
||||||
<fail message="ndk.dir is missing. Make sure to generate local.properties or to inject it through an env var" unless="ndk.dir"/>
|
<fail message="ndk.dir is missing. Make sure to generate local.properties or to inject it through an env var" unless="ndk.dir"/>
|
||||||
|
@ -224,7 +224,7 @@
|
||||||
|
|
||||||
<target name="-post-package" if="nativeoff">
|
<target name="-post-package" if="nativeoff">
|
||||||
<echo>Restoring ${native.libs.absolute.dir} to it's place...</echo>
|
<echo>Restoring ${native.libs.absolute.dir} to it's place...</echo>
|
||||||
<move file="${native.libs.absolute.dir}.skipped" tofile="${native.libs.absolute.dir}" />
|
<move file="${native.libs.absolute.dir}.skipped" tofile="${native.libs.absolute.dir}" failonerror="no"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<!-- Import the actual build file.
|
<!-- Import the actual build file.
|
||||||
|
|
|
@ -122,11 +122,13 @@ public class PoiFiltersHelper {
|
||||||
} else if(UDF_SIGHTSEEING.equals(key)){
|
} else if(UDF_SIGHTSEEING.equals(key)){
|
||||||
putAll(types, AmenityType.HISTORIC);
|
putAll(types, AmenityType.HISTORIC);
|
||||||
putAll(types, AmenityType.TOURISM);
|
putAll(types, AmenityType.TOURISM);
|
||||||
|
putAll(types, AmenityType.OSMWIKI);
|
||||||
putValues(types, AmenityType.OTHER, "place_of_worship");
|
putValues(types, AmenityType.OTHER, "place_of_worship");
|
||||||
} else if(UDF_FOR_TOURISTS.equals(key)){
|
} else if(UDF_FOR_TOURISTS.equals(key)){
|
||||||
putAll(types, AmenityType.HISTORIC);
|
putAll(types, AmenityType.HISTORIC);
|
||||||
putAll(types, AmenityType.TOURISM);
|
putAll(types, AmenityType.TOURISM);
|
||||||
putAll(types, AmenityType.FINANCE);
|
putAll(types, AmenityType.FINANCE);
|
||||||
|
putAll(types, AmenityType.OSMWIKI);
|
||||||
putValues(types, AmenityType.OTHER, "place_of_worship", "internet_access", "embassy","emergency_phone","marketplace",
|
putValues(types, AmenityType.OTHER, "place_of_worship", "internet_access", "embassy","emergency_phone","marketplace",
|
||||||
"post_office","telephone", "toilets");
|
"post_office","telephone", "toilets");
|
||||||
} else if(UDF_FUEL.equals(key)){
|
} else if(UDF_FUEL.equals(key)){
|
||||||
|
|
|
@ -172,7 +172,7 @@ std::string RenderingContext::getReshapedString(const std::string& src) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
inline double getPowZoom(float zoom){
|
double getPowZoom(float zoom){
|
||||||
if(zoom >= 0 && zoom - floor(zoom) < 0.05f){
|
if(zoom >= 0 && zoom - floor(zoom) < 0.05f){
|
||||||
return 1 << ((int)zoom);
|
return 1 << ((int)zoom);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -162,8 +162,8 @@ public:
|
||||||
int visible;
|
int visible;
|
||||||
int allObjects;
|
int allObjects;
|
||||||
int lastRenderedKey;
|
int lastRenderedKey;
|
||||||
class ElapsedTimer textRendering;
|
ElapsedTimer textRendering;
|
||||||
class ElapsedTimer nativeOperations;
|
ElapsedTimer nativeOperations;
|
||||||
|
|
||||||
// because they used in 3rd party functions
|
// because they used in 3rd party functions
|
||||||
public :
|
public :
|
||||||
|
@ -294,6 +294,8 @@ void purgeCachedBitmaps();
|
||||||
int get31TileNumberX(double longitude);
|
int get31TileNumberX(double longitude);
|
||||||
int get31TileNumberY( double latitude);
|
int get31TileNumberY( double latitude);
|
||||||
|
|
||||||
|
double getPowZoom(float zoom);
|
||||||
|
|
||||||
double getLongitudeFromTile(float zoom, double x) ;
|
double getLongitudeFromTile(float zoom, double x) ;
|
||||||
double getLatitudeFromTile(float zoom, double y);
|
double getLatitudeFromTile(float zoom, double y);
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,18 @@
|
||||||
#include "binaryRead.h"
|
#include "binaryRead.h"
|
||||||
#include "textdraw.cpp"
|
#include "textdraw.cpp"
|
||||||
#include "mapObjects.h"
|
#include "mapObjects.h"
|
||||||
|
#include "rendering.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct MapDataObjectPrimitive {
|
||||||
|
MapDataObject* obj;
|
||||||
|
int typeInd;
|
||||||
|
float order;
|
||||||
|
int objectType;
|
||||||
|
};
|
||||||
|
|
||||||
|
const int MAX_V = 32;
|
||||||
void calcPoint(std::pair<int, int> c, RenderingContext* rc)
|
void calcPoint(std::pair<int, int> c, RenderingContext* rc)
|
||||||
{
|
{
|
||||||
rc->pointCount++;
|
rc->pointCount++;
|
||||||
|
@ -360,6 +370,14 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas
|
||||||
if (!rendered || !updatePaint(req, paint, 0, 0, rc)) {
|
if (!rendered || !updatePaint(req, paint, 0, 0, rc)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
int shadowColor = req->getIntPropertyValue(req->props()->R_SHADOW_COLOR);
|
||||||
|
int shadowRadius = req->getIntPropertyValue(req->props()->R_SHADOW_RADIUS);
|
||||||
|
if(drawOnlyShadow && shadowRadius == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(shadowColor == 0) {
|
||||||
|
shadowColor = rc->getShadowRenderingColor();
|
||||||
|
}
|
||||||
int oneway = 0;
|
int oneway = 0;
|
||||||
if (rc->getZoom() >= 16 && pair.first == "highway") {
|
if (rc->getZoom() >= 16 && pair.first == "highway") {
|
||||||
if (mObj->containsAdditional("oneway", "yes")) {
|
if (mObj->containsAdditional("oneway", "yes")) {
|
||||||
|
@ -377,6 +395,7 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas
|
||||||
float prevx;
|
float prevx;
|
||||||
float prevy;
|
float prevy;
|
||||||
bool intersect = false;
|
bool intersect = false;
|
||||||
|
int prevCross = 0;
|
||||||
for (; i < length; i++) {
|
for (; i < length; i++) {
|
||||||
calcPoint(mObj->points.at(i), rc);
|
calcPoint(mObj->points.at(i), rc);
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
|
@ -388,22 +407,22 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas
|
||||||
path.lineTo(rc->calcX, rc->calcY);
|
path.lineTo(rc->calcX, rc->calcY);
|
||||||
}
|
}
|
||||||
if (!intersect) {
|
if (!intersect) {
|
||||||
if (rc->calcX >= 0 && rc->calcY >= 0 && rc->calcX < rc->getWidth()&& rc->calcY < rc->getHeight()) {
|
if (rc->calcX >= 0 && rc->calcY >= 0 && rc->calcX < rc->getWidth() && rc->calcY < rc->getHeight()) {
|
||||||
intersect = true;
|
intersect = true;
|
||||||
}
|
} else {
|
||||||
if (!intersect && i > 0) {
|
int cross = 0;
|
||||||
if ((rc->calcX < 0 && prevx < 0) || (rc->calcY < 0 && prevy < 0) ||
|
cross |= (rc->calcX < 0 ? 1 : 0);
|
||||||
(rc->calcX> rc->getWidth() && prevx > rc->getWidth())
|
cross |= (rc->calcX > rc->getWidth() ? 2 : 0);
|
||||||
|| (rc->calcY > rc->getHeight() && prevy > rc->getHeight())) {
|
cross |= (rc->calcY < 0 ? 4 : 0);
|
||||||
intersect = false;
|
cross |= (rc->calcY > rc->getHeight() ? 8 : 0);
|
||||||
} else {
|
if(i > 0) {
|
||||||
intersect = true;
|
if((prevCross & cross) == 0) {
|
||||||
|
intersect = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
prevCross = cross;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
prevx = rc->calcX;
|
|
||||||
prevy = rc->calcY;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!intersect) {
|
if (!intersect) {
|
||||||
|
@ -412,11 +431,6 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas
|
||||||
|
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
if (drawOnlyShadow) {
|
if (drawOnlyShadow) {
|
||||||
int shadowColor = req->getIntPropertyValue(req->props()->R_SHADOW_COLOR);
|
|
||||||
int shadowRadius = req->getIntPropertyValue(req->props()->R_SHADOW_RADIUS);
|
|
||||||
if(shadowColor == 0) {
|
|
||||||
shadowColor = rc->getShadowRenderingColor();
|
|
||||||
}
|
|
||||||
drawPolylineShadow(cv, paint, rc, &path, shadowColor, shadowRadius);
|
drawPolylineShadow(cv, paint, rc, &path, shadowColor, shadowRadius);
|
||||||
} else {
|
} else {
|
||||||
if (updatePaint(req, paint, -2, 0, rc)) {
|
if (updatePaint(req, paint, -2, 0, rc)) {
|
||||||
|
@ -467,9 +481,7 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas*
|
||||||
rc->visible++;
|
rc->visible++;
|
||||||
SkPath path;
|
SkPath path;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
float prevx;
|
bool containsPoint = false;
|
||||||
float prevy;
|
|
||||||
bool intersect = false;
|
|
||||||
int bounds = 0;
|
int bounds = 0;
|
||||||
for (; i < length; i++) {
|
for (; i < length; i++) {
|
||||||
calcPoint(mObj->points.at(i), rc);
|
calcPoint(mObj->points.at(i), rc);
|
||||||
|
@ -478,35 +490,36 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas*
|
||||||
} else {
|
} else {
|
||||||
path.lineTo(rc->calcX, rc->calcY);
|
path.lineTo(rc->calcX, rc->calcY);
|
||||||
}
|
}
|
||||||
xText += rc->calcX;
|
float tx = rc->calcX;
|
||||||
yText += rc->calcY;
|
if (tx < 0) {
|
||||||
if (!intersect) {
|
tx = 0;
|
||||||
|
}
|
||||||
|
if (tx > rc->getWidth()) {
|
||||||
|
tx = rc->getWidth();
|
||||||
|
}
|
||||||
|
float ty = rc->calcX;
|
||||||
|
if (ty < 0) {
|
||||||
|
ty = 0;
|
||||||
|
}
|
||||||
|
if (ty > rc->getHeight()) {
|
||||||
|
ty = rc->getHeight();
|
||||||
|
}
|
||||||
|
xText += tx;
|
||||||
|
yText += ty;
|
||||||
|
if (!containsPoint) {
|
||||||
if (rc->calcX >= 0 && rc->calcY >= 0 && rc->calcX < rc->getWidth() && rc->calcY < rc->getHeight()) {
|
if (rc->calcX >= 0 && rc->calcY >= 0 && rc->calcX < rc->getWidth() && rc->calcY < rc->getHeight()) {
|
||||||
intersect = true;
|
containsPoint = true;
|
||||||
}
|
}
|
||||||
bounds |= (rc->calcX < 0 ? 1 : 0);
|
bounds |= (rc->calcX < 0 ? 1 : 0);
|
||||||
bounds |= (rc->calcX >= rc->getWidth() ? 2 : 0);
|
bounds |= (rc->calcX >= rc->getWidth() ? 2 : 0);
|
||||||
bounds |= (rc->calcY < 0 ? 4 : 0);
|
bounds |= (rc->calcY < 0 ? 4 : 0);
|
||||||
bounds |= (rc->calcY >= rc->getHeight() ? 8 : 0);
|
bounds |= (rc->calcY >= rc->getHeight() ? 8 : 0);
|
||||||
if (!intersect && i > 0) {
|
|
||||||
if ((rc->calcX < 0 && prevx < 0) || (rc->calcY < 0 && prevy < 0)
|
|
||||||
|| (rc->calcX > rc->getWidth() && prevx > rc->getWidth())
|
|
||||||
|| (rc->calcY > rc->getHeight() && prevy > rc->getHeight())) {
|
|
||||||
intersect = false;
|
|
||||||
} else {
|
|
||||||
intersect = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!intersect){
|
xText /= length;
|
||||||
|
yText /= length;
|
||||||
|
if(!containsPoint){
|
||||||
if(bounds == 15) {
|
if(bounds == 15) {
|
||||||
path.reset();
|
|
||||||
path.moveTo(0, 0);
|
|
||||||
path.lineTo(0, rc->getWidth());
|
|
||||||
path.lineTo(rc->getHeight(), rc->getWidth());
|
|
||||||
path.lineTo(rc->getHeight(), 0);
|
|
||||||
path.close();
|
|
||||||
xText = rc->getWidth() / 2;
|
xText = rc->getWidth() / 2;
|
||||||
yText = rc->getHeight() / 2;
|
yText = rc->getHeight() / 2;
|
||||||
} else {
|
} else {
|
||||||
|
@ -534,7 +547,7 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas*
|
||||||
PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint));
|
PROFILE_NATIVE_OPERATION(rc, cv->drawPath(path, *paint));
|
||||||
}
|
}
|
||||||
|
|
||||||
renderText(mObj, req, rc, pair.first, pair.second, xText / length, yText / length, NULL);
|
renderText(mObj, req, rc, pair.first, pair.second, xText, yText, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint,
|
void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* cv, SkPaint* paint,
|
||||||
|
@ -579,18 +592,30 @@ void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* c
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawObject(RenderingContext* rc, MapDataObject* mObj, SkCanvas* cv, RenderingRuleSearchRequest* req,
|
void drawObject(RenderingContext* rc, SkCanvas* cv, RenderingRuleSearchRequest* req,
|
||||||
SkPaint* paint, int l, int renderText, int drawOnlyShadow, int t) {
|
SkPaint* paint, vector<MapDataObjectPrimitive>& array, int objOrder) {
|
||||||
rc->allObjects++;
|
|
||||||
tag_value pair = mObj->types.at(l);
|
double limit = 100;
|
||||||
if (t == 1 && !drawOnlyShadow) {
|
for (int i = 0; i < array.size(); i++) {
|
||||||
// point
|
rc->allObjects++;
|
||||||
drawPoint(mObj, req, cv, paint, rc, pair, renderText);
|
MapDataObject* mObj = array[i].obj;
|
||||||
} else if (t == 2) {
|
tag_value pair = mObj->types.at(array[i].typeInd);
|
||||||
drawPolyline(mObj, req, cv, paint, rc, pair, mObj->getSimpleLayer(), drawOnlyShadow);
|
if (objOrder == 0) {
|
||||||
} else if (t == 3 && !drawOnlyShadow) {
|
if (array[i].order < limit) {
|
||||||
// polygon
|
return;
|
||||||
drawPolygon(mObj, req, cv, paint, rc, pair);
|
}
|
||||||
|
// polygon
|
||||||
|
drawPolygon(mObj, req, cv, paint, rc, pair);
|
||||||
|
} else if (objOrder == 1) {
|
||||||
|
drawPolyline(mObj, req, cv, paint, rc, pair, mObj->getSimpleLayer(), true);
|
||||||
|
} else if (objOrder == 2) {
|
||||||
|
drawPolyline(mObj, req, cv, paint, rc, pair, mObj->getSimpleLayer(), false);
|
||||||
|
} else if (objOrder == 3) {
|
||||||
|
drawPoint(mObj, req, cv, paint, rc, pair, array[i].typeInd == 0);
|
||||||
|
}
|
||||||
|
if (i % 25 == 0 && rc->interrupted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -635,12 +660,30 @@ void drawIconsOverCanvas(RenderingContext* rc, SkCanvas* canvas)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UNORDERED(map)<int, std::vector<int> > sortObjectsByProperOrder(std::vector <MapDataObject* > mapDataObjects,
|
double polygonArea(MapDataObject* obj, float mult) {
|
||||||
RenderingRuleSearchRequest* req, RenderingContext* rc) {
|
double area = 0.;
|
||||||
UNORDERED(map)<int, std::vector<int> > orderMap;
|
int j = obj->points.size() - 1;
|
||||||
|
for (int i = 0; i < obj->points.size(); i++) {
|
||||||
|
int_pair x = obj->points[i] ;
|
||||||
|
int_pair y = obj->points[j];
|
||||||
|
area += (y.first + ((float) x.first) )* (y.second- ((float)x.second));
|
||||||
|
j = i;
|
||||||
|
}
|
||||||
|
return std::abs(area) * mult * mult * .5;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool sortByOrder(const MapDataObjectPrimitive& i,const MapDataObjectPrimitive& j) { return (i.order<j.order); }
|
||||||
|
bool sortByRevOrder(const MapDataObjectPrimitive& i,const MapDataObjectPrimitive& j) { return (i.order>j.order); }
|
||||||
|
|
||||||
|
void sortObjectsByProperOrder(std::vector <MapDataObject* > mapDataObjects,
|
||||||
|
RenderingRuleSearchRequest* req, RenderingContext* rc,
|
||||||
|
std::vector<MapDataObjectPrimitive>& polygonsArray, std::vector<MapDataObjectPrimitive>& pointsArray,
|
||||||
|
std::vector<MapDataObjectPrimitive>& linesArray) {
|
||||||
if (req != NULL) {
|
if (req != NULL) {
|
||||||
req->clearState();
|
req->clearState();
|
||||||
const int size = mapDataObjects.size();
|
const int size = mapDataObjects.size();
|
||||||
|
float mult = 1. / getPowZoom(max(31 - (rc->getZoom() + 8), 0));
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < size; i++) {
|
for (; i < size; i++) {
|
||||||
uint32_t sh = i << 8;
|
uint32_t sh = i << 8;
|
||||||
|
@ -657,11 +700,22 @@ UNORDERED(map)<int, std::vector<int> > sortObjectsByProperOrder(std::vector <Map
|
||||||
if (req->searchRule(RenderingRulesStorage::ORDER_RULES)) {
|
if (req->searchRule(RenderingRulesStorage::ORDER_RULES)) {
|
||||||
int objectType = req->getIntPropertyValue(req->props()->R_OBJECT_TYPE);
|
int objectType = req->getIntPropertyValue(req->props()->R_OBJECT_TYPE);
|
||||||
int order = req->getIntPropertyValue(req->props()->R_ORDER);
|
int order = req->getIntPropertyValue(req->props()->R_ORDER);
|
||||||
orderMap[(order << 2)|objectType].push_back(sh + j);
|
MapDataObjectPrimitive mapObj;
|
||||||
|
mapObj.objectType = objectType;
|
||||||
|
mapObj.order = order;
|
||||||
|
mapObj.typeInd = j;
|
||||||
|
mapObj.obj = mobj;
|
||||||
// polygon
|
// polygon
|
||||||
if(objectType == 3) {
|
if(objectType == 3) {
|
||||||
// add icon point all the time
|
MapDataObjectPrimitive pointObj = mapObj;
|
||||||
orderMap[(128 << 2)|1].push_back(sh + j);
|
pointObj.objectType = 1;
|
||||||
|
mapObj.order = polygonArea(mobj, mult);
|
||||||
|
polygonsArray.push_back(mapObj);
|
||||||
|
pointsArray.push_back(pointObj);
|
||||||
|
} else if(objectType == 1) {
|
||||||
|
pointsArray.push_back(mapObj);
|
||||||
|
} else {
|
||||||
|
linesArray.push_back(mapObj);
|
||||||
}
|
}
|
||||||
if (req->getIntPropertyValue(req->props()->R_SHADOW_LEVEL) > 0) {
|
if (req->getIntPropertyValue(req->props()->R_SHADOW_LEVEL) > 0) {
|
||||||
rc->shadowLevelMin = std::min(rc->shadowLevelMin, order);
|
rc->shadowLevelMin = std::min(rc->shadowLevelMin, order);
|
||||||
|
@ -672,8 +726,10 @@ UNORDERED(map)<int, std::vector<int> > sortObjectsByProperOrder(std::vector <Map
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort(polygonsArray.begin(), polygonsArray.end(), sortByRevOrder);
|
||||||
|
sort(pointsArray.begin(), pointsArray.end(), sortByOrder);
|
||||||
|
sort(linesArray.begin(), linesArray.end(), sortByOrder);
|
||||||
}
|
}
|
||||||
return orderMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void doRendering(std::vector <MapDataObject* > mapDataObjects, SkCanvas* canvas,
|
void doRendering(std::vector <MapDataObject* > mapDataObjects, SkCanvas* canvas,
|
||||||
|
@ -683,53 +739,23 @@ void doRendering(std::vector <MapDataObject* > mapDataObjects, SkCanvas* canvas,
|
||||||
SkPaint* paint = new SkPaint;
|
SkPaint* paint = new SkPaint;
|
||||||
paint->setAntiAlias(true);
|
paint->setAntiAlias(true);
|
||||||
|
|
||||||
// put in order map
|
std::vector<MapDataObjectPrimitive> polygonsArray;
|
||||||
UNORDERED(map)<int, std::vector<int> > orderMap = sortObjectsByProperOrder(mapDataObjects, req, rc);
|
std::vector<MapDataObjectPrimitive> pointsArray;
|
||||||
std::set<int> keys;
|
std::vector<MapDataObjectPrimitive> linesArray;
|
||||||
UNORDERED(map)<int, std::vector<int> >::iterator it = orderMap.begin();
|
sortObjectsByProperOrder(mapDataObjects, req, rc, polygonsArray, pointsArray, linesArray);
|
||||||
|
rc->lastRenderedKey = 0;
|
||||||
|
|
||||||
while (it != orderMap.end()) {
|
drawObject(rc, canvas, req, paint, polygonsArray, 0);
|
||||||
keys.insert(it->first);
|
rc->lastRenderedKey = 5;
|
||||||
it++;
|
if (rc->getShadowRenderingMode() > 1) {
|
||||||
|
drawObject(rc, canvas, req, paint, linesArray, 1);
|
||||||
}
|
}
|
||||||
bool shadowDrawn = false;
|
rc->lastRenderedKey = 40;
|
||||||
for (std::set<int>::iterator ks = keys.begin(); ks != keys.end(); ks++) {
|
drawObject(rc, canvas, req, paint, linesArray, 2);
|
||||||
if (!shadowDrawn && ((*ks)>>2) >= rc->shadowLevelMin && ((*ks)>>2) <= rc->shadowLevelMax && rc->getShadowRenderingMode() > 1) {
|
rc->lastRenderedKey = 60;
|
||||||
for (std::set<int>::iterator ki = ks; ki != keys.end(); ki++) {
|
|
||||||
if (((*ki)>>2) > rc->shadowLevelMax || rc->interrupted()) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::vector<int> list = orderMap[*ki];
|
|
||||||
for (std::vector<int>::iterator ls = list.begin(); ls != list.end(); ls++) {
|
|
||||||
int i = *ls;
|
|
||||||
int ind = i >> 8;
|
|
||||||
int l = i & 0xff;
|
|
||||||
MapDataObject* mapObject = mapDataObjects.at(ind);
|
|
||||||
|
|
||||||
// show text only for main type
|
drawObject(rc, canvas, req, paint, pointsArray, 3);
|
||||||
|
rc->lastRenderedKey = 125;
|
||||||
drawObject(rc, mapObject, canvas, req, paint, l, l == 0, true, (*ki)&3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
shadowDrawn = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<int> list = orderMap[*ks];
|
|
||||||
for (std::vector<int>::iterator ls = list.begin(); ls != list.end(); ls++) {
|
|
||||||
int i = *ls;
|
|
||||||
int ind = i >> 8;
|
|
||||||
int l = i & 0xff;
|
|
||||||
|
|
||||||
MapDataObject* mapObject = mapDataObjects.at(ind);
|
|
||||||
// show text only for main type
|
|
||||||
drawObject(rc, mapObject, canvas, req, paint, l, l == 0, false, (*ks)&3);
|
|
||||||
}
|
|
||||||
rc->lastRenderedKey = (*ks) >>2;
|
|
||||||
if (rc->interrupted()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
drawIconsOverCanvas(rc, canvas);
|
drawIconsOverCanvas(rc, canvas);
|
||||||
|
|
||||||
|
|
|
@ -9,4 +9,6 @@
|
||||||
|
|
||||||
void doRendering(std::vector <MapDataObject* > mapDataObjects, SkCanvas* canvas,
|
void doRendering(std::vector <MapDataObject* > mapDataObjects, SkCanvas* canvas,
|
||||||
RenderingRuleSearchRequest* req, RenderingContext* rc);
|
RenderingRuleSearchRequest* req, RenderingContext* rc);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
7
build-scripts/net.osmand.translator/.classpath
Normal file
7
build-scripts/net.osmand.translator/.classpath
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="output" path="bin"/>
|
||||||
|
</classpath>
|
1
build-scripts/net.osmand.translator/.gitignore
vendored
Normal file
1
build-scripts/net.osmand.translator/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bin
|
28
build-scripts/net.osmand.translator/.project
Normal file
28
build-scripts/net.osmand.translator/.project
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>net.osmand.translator</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.pde.PluginNature</nature>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
|
@ -0,0 +1,7 @@
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||||
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.7
|
15
build-scripts/net.osmand.translator/META-INF/MANIFEST.MF
Normal file
15
build-scripts/net.osmand.translator/META-INF/MANIFEST.MF
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
Manifest-Version: 1.0
|
||||||
|
Bundle-ManifestVersion: 2
|
||||||
|
Bundle-Name: Translator
|
||||||
|
Bundle-SymbolicName: net.osmand.translator;singleton:=true
|
||||||
|
Bundle-Version: 1.0.0.qualifier
|
||||||
|
Bundle-Activator: net.osmand.translator.Activator
|
||||||
|
Require-Bundle: org.eclipse.ui,
|
||||||
|
org.eclipse.core.runtime,
|
||||||
|
org.eclipse.jdt;bundle-version="3.7.2",
|
||||||
|
org.eclipse.jdt.core;bundle-version="3.7.3",
|
||||||
|
org.eclipse.jdt.ui;bundle-version="3.7.2",
|
||||||
|
org.eclipse.jface.text;bundle-version="3.7.2",
|
||||||
|
org.eclipse.core.resources;bundle-version="3.7.101"
|
||||||
|
Bundle-ActivationPolicy: lazy
|
||||||
|
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
|
6
build-scripts/net.osmand.translator/build.properties
Normal file
6
build-scripts/net.osmand.translator/build.properties
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
source.. = src/
|
||||||
|
output.. = bin/
|
||||||
|
bin.includes = plugin.xml,\
|
||||||
|
META-INF/,\
|
||||||
|
.,\
|
||||||
|
icons/
|
BIN
build-scripts/net.osmand.translator/icons/sample.gif
Normal file
BIN
build-scripts/net.osmand.translator/icons/sample.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 983 B |
62
build-scripts/net.osmand.translator/plugin.xml
Normal file
62
build-scripts/net.osmand.translator/plugin.xml
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<?eclipse version="3.4"?>
|
||||||
|
<plugin>
|
||||||
|
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.commands">
|
||||||
|
<category
|
||||||
|
name="Sample Category"
|
||||||
|
id="net.osmand.translator.commands.category">
|
||||||
|
</category>
|
||||||
|
<command
|
||||||
|
name="Sample Command"
|
||||||
|
categoryId="net.osmand.translator.commands.category"
|
||||||
|
id="net.osmand.translator.commands.sampleCommand">
|
||||||
|
</command>
|
||||||
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.handlers">
|
||||||
|
<handler
|
||||||
|
commandId="net.osmand.translator.commands.sampleCommand"
|
||||||
|
class="net.osmand.translator.handlers.TranslationHandler">
|
||||||
|
</handler>
|
||||||
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.bindings">
|
||||||
|
<key
|
||||||
|
commandId="net.osmand.translator.commands.sampleCommand"
|
||||||
|
contextId="org.eclipse.ui.contexts.window"
|
||||||
|
sequence="M1+6"
|
||||||
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||||
|
</key>
|
||||||
|
</extension>
|
||||||
|
<extension
|
||||||
|
point="org.eclipse.ui.menus">
|
||||||
|
<menuContribution
|
||||||
|
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
|
||||||
|
<menu
|
||||||
|
label="Translate To C++"
|
||||||
|
mnemonic="M"
|
||||||
|
id="net.osmand.translator.menus.sampleMenu">
|
||||||
|
<command
|
||||||
|
commandId="net.osmand.translator.commands.sampleCommand"
|
||||||
|
mnemonic="S"
|
||||||
|
id="net.osmand.translator.menus.sampleCommand">
|
||||||
|
</command>
|
||||||
|
</menu>
|
||||||
|
</menuContribution>
|
||||||
|
<menuContribution
|
||||||
|
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
|
||||||
|
<toolbar
|
||||||
|
id="net.osmand.translator.toolbars.sampleToolbar">
|
||||||
|
<command
|
||||||
|
commandId="net.osmand.translator.commands.sampleCommand"
|
||||||
|
icon="icons/sample.gif"
|
||||||
|
tooltip="Say hello world"
|
||||||
|
id="net.osmand.translator.toolbars.sampleCommand">
|
||||||
|
</command>
|
||||||
|
</toolbar>
|
||||||
|
</menuContribution>
|
||||||
|
</extension>
|
||||||
|
|
||||||
|
</plugin>
|
|
@ -0,0 +1,61 @@
|
||||||
|
package net.osmand.translator;
|
||||||
|
|
||||||
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activator class controls the plug-in life cycle
|
||||||
|
*/
|
||||||
|
public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
|
// The plug-in ID
|
||||||
|
public static final String PLUGIN_ID = "net.osmand.translator"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
// The shared instance
|
||||||
|
private static Activator plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor
|
||||||
|
*/
|
||||||
|
public Activator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||||
|
*/
|
||||||
|
public void start(BundleContext context) throws Exception {
|
||||||
|
super.start(context);
|
||||||
|
plugin = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||||
|
*/
|
||||||
|
public void stop(BundleContext context) throws Exception {
|
||||||
|
plugin = null;
|
||||||
|
super.stop(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the shared instance
|
||||||
|
*
|
||||||
|
* @return the shared instance
|
||||||
|
*/
|
||||||
|
public static Activator getDefault() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an image descriptor for the image file at the given
|
||||||
|
* plug-in relative path
|
||||||
|
*
|
||||||
|
* @param path the path
|
||||||
|
* @return the image descriptor
|
||||||
|
*/
|
||||||
|
public static ImageDescriptor getImageDescriptor(String path) {
|
||||||
|
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package net.osmand.translator;
|
||||||
|
|
||||||
|
public class TranslatorException extends Exception {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public TranslatorException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package net.osmand.translator.cpp.model;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CppClass {
|
||||||
|
|
||||||
|
private List<String> imports;
|
||||||
|
|
||||||
|
private List<CppField> fields;
|
||||||
|
|
||||||
|
private List<CppMethod> methods;
|
||||||
|
|
||||||
|
private List<CppClass> classes;
|
||||||
|
|
||||||
|
private boolean innerClass = false;
|
||||||
|
|
||||||
|
private boolean staticClass = false;
|
||||||
|
|
||||||
|
public CppClass() {
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,89 @@
|
||||||
|
package net.osmand.translator.cpp.model;
|
||||||
|
|
||||||
|
import static net.osmand.translator.utils.TranslationConstants.FINAL_MODIFIER;
|
||||||
|
import static net.osmand.translator.utils.TranslationConstants.STATIC_MODIFIER;
|
||||||
|
|
||||||
|
public class CppField {
|
||||||
|
|
||||||
|
private FieldAccessModifiers accessModifier;
|
||||||
|
|
||||||
|
private boolean statick;
|
||||||
|
|
||||||
|
private boolean constant;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
|
||||||
|
public CppField() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
buffer.append(accessModifier.getValue());
|
||||||
|
if (statick) {
|
||||||
|
buffer.append(STATIC_MODIFIER);
|
||||||
|
}
|
||||||
|
if (constant) {
|
||||||
|
buffer.append(FINAL_MODIFIER);
|
||||||
|
}
|
||||||
|
buffer.append(type).append(name);
|
||||||
|
if (value != null) {
|
||||||
|
buffer.append(" = ").append(value).append(";");
|
||||||
|
}
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldAccessModifiers getAccessModifier() {
|
||||||
|
return accessModifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessModifier(FieldAccessModifiers accessModifier) {
|
||||||
|
this.accessModifier = accessModifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isStatick() {
|
||||||
|
return statick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatick(boolean statick) {
|
||||||
|
this.statick = statick;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isConstant() {
|
||||||
|
return constant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConstant(boolean constant) {
|
||||||
|
this.constant = constant;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package net.osmand.translator.cpp.model;
|
||||||
|
|
||||||
|
public class CppMethod {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package net.osmand.translator.cpp.model;
|
||||||
|
|
||||||
|
public enum FieldAccessModifiers {
|
||||||
|
|
||||||
|
|
||||||
|
PUBLIC ("public"), PROTECTED ("protected "), PRIVATE ("private "), DEFAULT ("");
|
||||||
|
|
||||||
|
private final String value;
|
||||||
|
|
||||||
|
private FieldAccessModifiers(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
#include <math.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
const double PI = 3.141592653589793238462;
|
||||||
|
|
||||||
|
class MapUtils {
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const wchar_t intToBase64[64]= {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','_','@'};
|
||||||
|
static const string BASE_SHORT_OSM_URL = "http://osm.org/go/";
|
||||||
|
|
||||||
|
double toRadians(double a) {
|
||||||
|
return a / 180.0 * PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
double getDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||||
|
double R = 6371;
|
||||||
|
double dLat = toRadians(lat2-lat1);
|
||||||
|
double dLon = toRadians(lon2-lon1);
|
||||||
|
double a = sin(dLat/2) * sin(dLat/2) +
|
||||||
|
cos(toRadians(lat1)) * cos(toRadians(lat2)) *
|
||||||
|
sin(dLon/2) * sin(dLon/2);
|
||||||
|
double c = 2 * atan2(sqrt(a), sqrt(1-a));
|
||||||
|
return R * c * 1000;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,130 @@
|
||||||
|
package net.osmand.translator.handlers;
|
||||||
|
|
||||||
|
import net.osmand.translator.utils.FieldsHandler;
|
||||||
|
import net.osmand.translator.utils.MethodHandler;
|
||||||
|
|
||||||
|
import org.eclipse.core.commands.AbstractHandler;
|
||||||
|
import org.eclipse.core.commands.ExecutionEvent;
|
||||||
|
import org.eclipse.core.commands.ExecutionException;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
|
import org.eclipse.core.resources.IWorkspaceRoot;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IPath;
|
||||||
|
import org.eclipse.core.runtime.Path;
|
||||||
|
import org.eclipse.jdt.core.ICompilationUnit;
|
||||||
|
import org.eclipse.jdt.core.IJavaProject;
|
||||||
|
import org.eclipse.jdt.core.IMethod;
|
||||||
|
import org.eclipse.jdt.core.IPackageFragment;
|
||||||
|
import org.eclipse.jdt.core.IPackageFragmentRoot;
|
||||||
|
import org.eclipse.jdt.core.IType;
|
||||||
|
import org.eclipse.jdt.core.JavaCore;
|
||||||
|
import org.eclipse.jdt.core.JavaModelException;
|
||||||
|
import org.eclipse.jdt.core.dom.AST;
|
||||||
|
import org.eclipse.jdt.core.dom.ASTParser;
|
||||||
|
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||||
|
import org.eclipse.jface.text.Document;
|
||||||
|
//import org.eclipse.jface.text.Document;
|
||||||
|
|
||||||
|
public class TranslationHandler extends AbstractHandler {
|
||||||
|
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||||
|
IWorkspace workspace = ResourcesPlugin.getWorkspace();
|
||||||
|
IWorkspaceRoot root = workspace.getRoot();
|
||||||
|
IPath path = root.getProject("DataExtactionOSM").getFile("src/net/osmand/osm/MapUtils.java").getFullPath();
|
||||||
|
// parse "MapUtils.java"
|
||||||
|
// IPath path = Path.fromOSString("/DataExtractionOSM/src/net/osmand/osm/MapUtils.java");
|
||||||
|
IFile iFile = root.getFileForLocation(path);
|
||||||
|
ICompilationUnit unit = (ICompilationUnit)JavaCore.create(iFile);
|
||||||
|
CompilationUnit parse = parse(unit);
|
||||||
|
FieldsHandler.printFieldsInfo(parse);
|
||||||
|
System.out.println();
|
||||||
|
MethodHandler.printMethodsInfo(parse);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CompilationUnit parse(ICompilationUnit unit) {
|
||||||
|
ASTParser parser = ASTParser.newParser(AST.JLS3);
|
||||||
|
parser.setKind(ASTParser.K_COMPILATION_UNIT);
|
||||||
|
parser.setSource(unit);
|
||||||
|
parser.setResolveBindings(true);
|
||||||
|
return (CompilationUnit) parser.createAST(null); // parse
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
private void getProjects(IWorkspaceRoot root) {
|
||||||
|
IProject[] projects = root.getProjects();
|
||||||
|
for (IProject project : projects) {
|
||||||
|
try {
|
||||||
|
printProjectInfo(project);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printProjectInfo(IProject project) throws CoreException,
|
||||||
|
JavaModelException {
|
||||||
|
System.out.println("Working in project " + project.getName());
|
||||||
|
// Check if we have a Java project
|
||||||
|
if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
|
||||||
|
IJavaProject javaProject = JavaCore.create(project);
|
||||||
|
printPackageInfos(javaProject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printPackageInfos(IJavaProject javaProject)
|
||||||
|
throws JavaModelException {
|
||||||
|
IPackageFragment[] packages = javaProject.getPackageFragments();
|
||||||
|
for (IPackageFragment mypackage : packages) {
|
||||||
|
// Package fragments include all packages in the
|
||||||
|
// classpath
|
||||||
|
// We will only look at the package from the source
|
||||||
|
// folder
|
||||||
|
// K_BINARY would include also included JARS, e.g.
|
||||||
|
// rt.jar
|
||||||
|
if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
|
||||||
|
System.out.println("Package " + mypackage.getElementName());
|
||||||
|
printICompilationUnitInfo(mypackage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printICompilationUnitInfo(IPackageFragment mypackage)
|
||||||
|
throws JavaModelException {
|
||||||
|
for (ICompilationUnit unit : mypackage.getCompilationUnits()) {
|
||||||
|
printCompilationUnitDetails(unit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printCompilationUnitDetails(ICompilationUnit unit)
|
||||||
|
throws JavaModelException {
|
||||||
|
System.out.println("Source file " + unit.getElementName());
|
||||||
|
Document doc = new Document(unit.getSource());
|
||||||
|
System.out.println("Has number of lines: " + doc.getNumberOfLines());
|
||||||
|
printIMethods(unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printIMethods(ICompilationUnit unit) throws JavaModelException {
|
||||||
|
IType[] allTypes = unit.getAllTypes();
|
||||||
|
for (IType type : allTypes) {
|
||||||
|
printIMethodDetails(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printIMethodDetails(IType type) throws JavaModelException {
|
||||||
|
IMethod[] methods = type.getMethods();
|
||||||
|
for (IMethod method : methods) {
|
||||||
|
|
||||||
|
System.out.println("Method name " + method.getElementName());
|
||||||
|
System.out.println("Signature " + method.getSignature());
|
||||||
|
System.out.println("Return Type " + method.getReturnType());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,65 @@
|
||||||
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
import static net.osmand.translator.utils.TranslationConstants.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
import net.osmand.translator.TranslatorException;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.Type;
|
||||||
|
|
||||||
|
public abstract class AbstractHandler {
|
||||||
|
|
||||||
|
protected static void applyType(Type type, StringBuffer buffer) {
|
||||||
|
if (type.isPrimitiveType()) {
|
||||||
|
try {
|
||||||
|
applyPrimitiveType(type, buffer);
|
||||||
|
} catch (TranslatorException e) {
|
||||||
|
// TODO
|
||||||
|
System.out.println("Primitive type is undefined.");;
|
||||||
|
}
|
||||||
|
} else if (type.toString().equals("String")) {
|
||||||
|
buffer.append(NOT_PRIMITIVE_TYPE_STRING);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// private static void buildCppField(StringBuffer buffer) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
protected static void applyModifiers(int mod, StringBuffer buffer) {
|
||||||
|
if (Modifier.isPublic(mod)) {
|
||||||
|
buffer.append(PUBLIC_MODIFIER);
|
||||||
|
} else if (Modifier.isProtected(mod)) {
|
||||||
|
buffer.append(PROTECTED_MODIFIER);
|
||||||
|
} else if (Modifier.isPrivate(mod)) {
|
||||||
|
buffer.append(PRIVATE_MODIFIER);
|
||||||
|
}
|
||||||
|
if (Modifier.isFinal(mod)) {
|
||||||
|
buffer.append(FINAL_MODIFIER);
|
||||||
|
}
|
||||||
|
if (Modifier.isStatic(mod)) {
|
||||||
|
buffer.append(STATIC_MODIFIER);
|
||||||
|
}
|
||||||
|
// if (Modifier.isVolatile(mod)) {}
|
||||||
|
// if (Modifier.isTransient(mod)) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void applyPrimitiveType (Type type, StringBuffer buffer) throws TranslatorException {
|
||||||
|
if (type.toString().equals("boolean")) {
|
||||||
|
buffer.append(PRIMITIVE_TYPE_BOOLEAN);
|
||||||
|
} else if (type.toString().equals("char")) {
|
||||||
|
buffer.append(PRIMITIVE_TYPE_CHAR);
|
||||||
|
} else if (type.toString().equals("short")) {
|
||||||
|
buffer.append(PRIMITIVE_TYPE_SHORT);
|
||||||
|
} else if (type.toString().equals("int")) {
|
||||||
|
buffer.append(PRIMITIVE_TYPE_INT);
|
||||||
|
} else if (type.toString().equals("float")) {
|
||||||
|
buffer.append(PRIMITIVE_TYPE_FLOAT);
|
||||||
|
} else if (type.toString().equals("double")) {
|
||||||
|
buffer.append(PRIMITIVE_TYPE_DOUBLE);
|
||||||
|
} else {
|
||||||
|
throw new TranslatorException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
public class ClassHandler {
|
||||||
|
|
||||||
|
private static void organiseImports(StringBuffer buffer) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
import net.osmand.translator.visitor.FieldVisitor;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||||
|
import org.eclipse.jdt.core.dom.Expression;
|
||||||
|
import org.eclipse.jdt.core.dom.FieldDeclaration;
|
||||||
|
import org.eclipse.jdt.core.dom.IVariableBinding;
|
||||||
|
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
|
||||||
|
|
||||||
|
public class FieldsHandler extends AbstractHandler{
|
||||||
|
|
||||||
|
public static void printFieldsInfo(CompilationUnit parse) {
|
||||||
|
FieldVisitor fVisitor = new FieldVisitor();
|
||||||
|
parse.accept(fVisitor);
|
||||||
|
for (FieldDeclaration field : fVisitor.getFields()) {
|
||||||
|
VariableDeclarationFragment fragment = (VariableDeclarationFragment)field.fragments().get(0);
|
||||||
|
IVariableBinding binding = fragment.resolveBinding();
|
||||||
|
Expression initializer = fragment.getInitializer();
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
// modifiers
|
||||||
|
applyModifiers(field.getModifiers(), buffer);
|
||||||
|
// type
|
||||||
|
applyType(field.getType(), buffer);
|
||||||
|
// name
|
||||||
|
buffer.append(binding.getJavaElement().getElementName());
|
||||||
|
// array brackets
|
||||||
|
if (binding.getType().isArray()) {
|
||||||
|
buffer.append("[]");
|
||||||
|
}
|
||||||
|
// value
|
||||||
|
if (initializer != null) {
|
||||||
|
buffer.append(" = ").append(initializer);
|
||||||
|
}
|
||||||
|
// end of string
|
||||||
|
buffer.append(";");
|
||||||
|
System.out.println(buffer);
|
||||||
|
// System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
import net.osmand.translator.visitor.MethodVisitor;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.Block;
|
||||||
|
import org.eclipse.jdt.core.dom.CompilationUnit;
|
||||||
|
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
||||||
|
import org.eclipse.jdt.core.dom.Type;
|
||||||
|
|
||||||
|
public class MethodHandler extends AbstractHandler{
|
||||||
|
|
||||||
|
public static void printMethodsInfo(CompilationUnit parse) {
|
||||||
|
MethodVisitor mVisitor = new MethodVisitor();
|
||||||
|
parse.accept(mVisitor);
|
||||||
|
for (MethodDeclaration method : mVisitor.getMethods()) {
|
||||||
|
StringBuffer buffer = new StringBuffer();
|
||||||
|
// modifiers
|
||||||
|
applyModifiers(method.getModifiers(), buffer);
|
||||||
|
Type returnType = method.getReturnType2();
|
||||||
|
if (returnType.toString().equals("void")) {
|
||||||
|
buffer.append("void ");
|
||||||
|
} else {
|
||||||
|
applyType(returnType, buffer);
|
||||||
|
}
|
||||||
|
buffer.append(method.getName());
|
||||||
|
buffer.append("(");
|
||||||
|
applyParameters(method, buffer);
|
||||||
|
buffer.append(")");
|
||||||
|
buffer.append("{");
|
||||||
|
fillBody(method, buffer);
|
||||||
|
buffer.append("}");
|
||||||
|
System.out.println(buffer);
|
||||||
|
System.out.println();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void applyParameters(MethodDeclaration method, StringBuffer buffer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void fillBody(MethodDeclaration method, StringBuffer buffer) {
|
||||||
|
Block body = method.getBody();
|
||||||
|
|
||||||
|
System.out.println(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseSimpleForStatement() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.jdt.core.IJavaProject;
|
||||||
|
import org.eclipse.jdt.core.IPackageFragment;
|
||||||
|
import org.eclipse.jdt.core.IPackageFragmentRoot;
|
||||||
|
import org.eclipse.jdt.core.JavaCore;
|
||||||
|
import org.eclipse.jdt.core.JavaModelException;
|
||||||
|
|
||||||
|
public class ProjectHandler {
|
||||||
|
|
||||||
|
public void printProjectInfo(IProject project) throws CoreException,
|
||||||
|
JavaModelException {
|
||||||
|
System.out.println("Working in project " + project.getName());
|
||||||
|
// Check if we have a Java project
|
||||||
|
if (project.isNatureEnabled("org.eclipse.jdt.core.javanature")) {
|
||||||
|
IJavaProject javaProject = JavaCore.create(project);
|
||||||
|
printPackageInfos(javaProject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printPackageInfos(IJavaProject javaProject)
|
||||||
|
throws JavaModelException {
|
||||||
|
IPackageFragment[] packages = javaProject.getPackageFragments();
|
||||||
|
for (IPackageFragment mypackage : packages) {
|
||||||
|
// Package fragments include all packages in the
|
||||||
|
// classpath
|
||||||
|
// We will only look at the package from the source
|
||||||
|
// folder
|
||||||
|
// K_BINARY would include also included JARS, e.g.
|
||||||
|
// rt.jar
|
||||||
|
if (mypackage.getKind() == IPackageFragmentRoot.K_SOURCE) {
|
||||||
|
System.out.println("Package " + mypackage.getElementName());
|
||||||
|
// printICompilationUnitInfo(mypackage);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
package net.osmand.translator.utils;
|
||||||
|
|
||||||
|
public class TranslationConstants {
|
||||||
|
|
||||||
|
public static final String FINAL_MODIFIER = "const ";
|
||||||
|
public static final String STATIC_MODIFIER = "static ";
|
||||||
|
public static final String PRIVATE_MODIFIER = "private ";
|
||||||
|
public static final String PROTECTED_MODIFIER = "protected ";
|
||||||
|
public static final String PUBLIC_MODIFIER = "public ";
|
||||||
|
public static final String VOLATILE_MODIFIER = "volatile ";
|
||||||
|
public static final String TRANSIENT_MODIFIER = "transient ";
|
||||||
|
|
||||||
|
|
||||||
|
public static final String PRIMITIVE_TYPE_BOOLEAN = "bool ";
|
||||||
|
public static final String PRIMITIVE_TYPE_CHAR = "wchar_t ";
|
||||||
|
public static final String PRIMITIVE_TYPE_SHORT = "signed short ";
|
||||||
|
public static final String PRIMITIVE_TYPE_INT = "signed long ";
|
||||||
|
public static final String PRIMITIVE_TYPE_FLOAT = "float ";
|
||||||
|
public static final String PRIMITIVE_TYPE_DOUBLE = "double ";
|
||||||
|
|
||||||
|
public static final String NOT_PRIMITIVE_TYPE_STRING = "string ";
|
||||||
|
|
||||||
|
public static final String ARRAY_TYPE = "[] ";
|
||||||
|
|
||||||
|
|
||||||
|
public void initMethods(){
|
||||||
|
register("Math", "sin", "sin");
|
||||||
|
register("Math", "cos", "cos");
|
||||||
|
register("Math", "toRadians", "toRadians");
|
||||||
|
|
||||||
|
registerType("boolean", "bool", true);
|
||||||
|
registerType("float", "float", true);
|
||||||
|
/// TODO
|
||||||
|
registerType("String", "String", true);
|
||||||
|
|
||||||
|
registerType("LatLon", "LatLon", true);
|
||||||
|
registerType("net.osmand.plus.Node", "Node", false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void registerType(String javaType, String cppType, boolean primitive) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void register(String javaClass, String javaMethod, String cppReplacement) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
package net.osmand.translator.visitor;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.ASTVisitor;
|
||||||
|
import org.eclipse.jdt.core.dom.ExpressionStatement;
|
||||||
|
|
||||||
|
public class ExpressionVisitor extends ASTVisitor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(ExpressionStatement node) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package net.osmand.translator.visitor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.ASTVisitor;
|
||||||
|
import org.eclipse.jdt.core.dom.FieldDeclaration;
|
||||||
|
|
||||||
|
public class FieldVisitor extends ASTVisitor {
|
||||||
|
|
||||||
|
private List<FieldDeclaration> fields = new ArrayList<FieldDeclaration>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(FieldDeclaration node) {
|
||||||
|
fields.add(node);
|
||||||
|
return super.visit(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<FieldDeclaration> getFields() {
|
||||||
|
return fields;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package net.osmand.translator.visitor;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.ASTVisitor;
|
||||||
|
import org.eclipse.jdt.core.dom.MethodDeclaration;
|
||||||
|
|
||||||
|
public class MethodVisitor extends ASTVisitor {
|
||||||
|
private List<MethodDeclaration> methods = new ArrayList<MethodDeclaration>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(MethodDeclaration node) {
|
||||||
|
methods.add(node);
|
||||||
|
return super.visit(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<MethodDeclaration> getMethods() {
|
||||||
|
return methods;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
package net.osmand.translator.visitor;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.jdt.core.dom.ASTVisitor;
|
||||||
|
import org.eclipse.jdt.core.dom.DoStatement;
|
||||||
|
import org.eclipse.jdt.core.dom.ForStatement;
|
||||||
|
import org.eclipse.jdt.core.dom.IfStatement;
|
||||||
|
import org.eclipse.jdt.core.dom.Statement;
|
||||||
|
import org.eclipse.jdt.core.dom.SwitchStatement;
|
||||||
|
import org.eclipse.jdt.core.dom.SynchronizedStatement;
|
||||||
|
import org.eclipse.jdt.core.dom.TryStatement;
|
||||||
|
import org.eclipse.jdt.core.dom.WhileStatement;
|
||||||
|
|
||||||
|
public class MethodsBodyVisitor extends ASTVisitor {
|
||||||
|
private List<Statement> statements = new ArrayList<Statement>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(ForStatement node) {
|
||||||
|
node.getStartPosition();
|
||||||
|
System.out.println("ForStatement:" + node.toString());
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(IfStatement node) {
|
||||||
|
System.out.println("IfStatement:" + node.toString());
|
||||||
|
Statement elseStatement = node.getElseStatement();
|
||||||
|
if (elseStatement != null) {
|
||||||
|
System.out.println("ElseStatement:" + elseStatement.toString());
|
||||||
|
}
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(WhileStatement node) {
|
||||||
|
System.out.println("WhileStatement:" + node.toString());
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(DoStatement node) {
|
||||||
|
System.out.println("DoStatement:" + node.toString());
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(SwitchStatement node) {
|
||||||
|
System.out.println("SwitchStatement:" + node.toString());
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(TryStatement node) {
|
||||||
|
System.out.println("TryStatement:" + node.toString());
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean visit(SynchronizedStatement node) {
|
||||||
|
System.out.println("SynchronizedStatement:" + node.toString());
|
||||||
|
statements.add(node);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Statement> getStatements() {
|
||||||
|
return statements;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue