From 4c6c68e8b14234daf9476026c10ab348b61246c3 Mon Sep 17 00:00:00 2001 From: aFedasenka Date: Thu, 13 Sep 2012 20:52:38 +0200 Subject: [PATCH 1/4] translator to c++ --- .../net.osmand.translator/.classpath | 7 + .../net.osmand.translator/.gitignore | 1 + build-scripts/net.osmand.translator/.project | 28 ++++ .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 15 ++ .../net.osmand.translator/build.properties | 6 + .../net.osmand.translator/icons/sample.gif | Bin 0 -> 983 bytes .../net.osmand.translator/plugin.xml | 62 +++++++++ .../src/net/osmand/translator/Activator.java | 61 ++++++++ .../translator/TranslatorException.java | 13 ++ .../osmand/translator/cpp/model/CppClass.java | 21 +++ .../osmand/translator/cpp/model/CppField.java | 89 ++++++++++++ .../translator/cpp/model/CppMethod.java | 5 + .../cpp/model/FieldAccessModifiers.java | 18 +++ .../osmand/translator/cpp/model/map_utils.cpp | 26 ++++ .../handlers/TranslationHandler.java | 130 ++++++++++++++++++ .../translator/utils/AbstractHandler.java | 65 +++++++++ .../osmand/translator/utils/ClassHandler.java | 8 ++ .../translator/utils/FieldsHandler.java | 42 ++++++ .../translator/utils/MethodHandler.java | 51 +++++++ .../translator/utils/ProjectHandler.java | 42 ++++++ .../utils/TranslationConstants.java | 52 +++++++ .../translator/visitor/ExpressionVisitor.java | 13 ++ .../translator/visitor/FieldVisitor.java | 22 +++ .../translator/visitor/MethodVisitor.java | 21 +++ .../visitor/MethodsBodyVisitor.java | 76 ++++++++++ 26 files changed, 881 insertions(+) create mode 100644 build-scripts/net.osmand.translator/.classpath create mode 100644 build-scripts/net.osmand.translator/.gitignore create mode 100644 build-scripts/net.osmand.translator/.project create mode 100644 build-scripts/net.osmand.translator/.settings/org.eclipse.jdt.core.prefs create mode 100644 build-scripts/net.osmand.translator/META-INF/MANIFEST.MF create mode 100644 build-scripts/net.osmand.translator/build.properties create mode 100644 build-scripts/net.osmand.translator/icons/sample.gif create mode 100644 build-scripts/net.osmand.translator/plugin.xml create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/Activator.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/TranslatorException.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppClass.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppField.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppMethod.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/FieldAccessModifiers.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/map_utils.cpp create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/handlers/TranslationHandler.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/utils/AbstractHandler.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ClassHandler.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/utils/FieldsHandler.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/utils/MethodHandler.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ProjectHandler.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/utils/TranslationConstants.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/ExpressionVisitor.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/FieldVisitor.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodVisitor.java create mode 100644 build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodsBodyVisitor.java diff --git a/build-scripts/net.osmand.translator/.classpath b/build-scripts/net.osmand.translator/.classpath new file mode 100644 index 0000000000..098194ca4b --- /dev/null +++ b/build-scripts/net.osmand.translator/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/build-scripts/net.osmand.translator/.gitignore b/build-scripts/net.osmand.translator/.gitignore new file mode 100644 index 0000000000..ba077a4031 --- /dev/null +++ b/build-scripts/net.osmand.translator/.gitignore @@ -0,0 +1 @@ +bin diff --git a/build-scripts/net.osmand.translator/.project b/build-scripts/net.osmand.translator/.project new file mode 100644 index 0000000000..4bb391ea39 --- /dev/null +++ b/build-scripts/net.osmand.translator/.project @@ -0,0 +1,28 @@ + + + net.osmand.translator + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/build-scripts/net.osmand.translator/.settings/org.eclipse.jdt.core.prefs b/build-scripts/net.osmand.translator/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000..f42de363af --- /dev/null +++ b/build-scripts/net.osmand.translator/.settings/org.eclipse.jdt.core.prefs @@ -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 diff --git a/build-scripts/net.osmand.translator/META-INF/MANIFEST.MF b/build-scripts/net.osmand.translator/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..c1e69ef42f --- /dev/null +++ b/build-scripts/net.osmand.translator/META-INF/MANIFEST.MF @@ -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 diff --git a/build-scripts/net.osmand.translator/build.properties b/build-scripts/net.osmand.translator/build.properties new file mode 100644 index 0000000000..0d3d3a745d --- /dev/null +++ b/build-scripts/net.osmand.translator/build.properties @@ -0,0 +1,6 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/ diff --git a/build-scripts/net.osmand.translator/icons/sample.gif b/build-scripts/net.osmand.translator/icons/sample.gif new file mode 100644 index 0000000000000000000000000000000000000000..34fb3c9d8cb7d489681b7f7aee4bdcd7eaf53610 GIT binary patch literal 983 zcmZ?wbhEHb6krfw_|CxKYUg-n!?izO{@9*?jxd%4aX0yzy`dymabz zw#(eg=y~&N&n)dZv2xzduG}5lraiApo3(c4*{Ylg5#|$JO_EEZ<^|a2`Z*=9ns7DV zy=TR&gYw*7f%auV?ip3tvjRPmcdoho{K?x$_vR?C#t5&<;~V}S*>OMCr>h}%%bLZ9 zmo3`hYEwTICo-TTCZwgTsC&VjZRgJ1eE#fBa^%9R zmmfWS@;bnyJ27HWY}kxYzv(Hl>yu;FCPlAEh+34Muq-8Rb6C)<8qA3{r2e5 z`$vyngh#H=FWlqqvnapfc5%(!sQ4v?r7J61-&eJNEN^;KTK}T7{#i-gJh%G*9vcYdwv_*~xdw!Gz4Va?T!sXyyF@8?w<>X`X=#j%uHV4GRvj@+tE@ zQ%F!a)GKcn^~8abN>4la1UNXVL;{ZWi)lEwyeatDu%Lr6;aASiLrXXW zQm# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/Activator.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/Activator.java new file mode 100644 index 0000000000..635281cae9 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/Activator.java @@ -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); + } +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/TranslatorException.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/TranslatorException.java new file mode 100644 index 0000000000..bb9846d2e8 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/TranslatorException.java @@ -0,0 +1,13 @@ +package net.osmand.translator; + +public class TranslatorException extends Exception { +/** + * + */ + private static final long serialVersionUID = 1L; + + public TranslatorException() { + super(); + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppClass.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppClass.java new file mode 100644 index 0000000000..8d7d786f26 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppClass.java @@ -0,0 +1,21 @@ +package net.osmand.translator.cpp.model; + +import java.util.List; + +public class CppClass { + + private List imports; + + private List fields; + + private List methods; + + private List classes; + + private boolean innerClass = false; + + private boolean staticClass = false; + + public CppClass() { + } +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppField.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppField.java new file mode 100644 index 0000000000..da33306f57 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppField.java @@ -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; + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppMethod.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppMethod.java new file mode 100644 index 0000000000..ffe5ef99ff --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/CppMethod.java @@ -0,0 +1,5 @@ +package net.osmand.translator.cpp.model; + +public class CppMethod { + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/FieldAccessModifiers.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/FieldAccessModifiers.java new file mode 100644 index 0000000000..abcce95ef2 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/FieldAccessModifiers.java @@ -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; + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/map_utils.cpp b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/map_utils.cpp new file mode 100644 index 0000000000..42cf591398 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/cpp/model/map_utils.cpp @@ -0,0 +1,26 @@ +#include +#include + +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; + } +} \ No newline at end of file diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/handlers/TranslationHandler.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/handlers/TranslationHandler.java new file mode 100644 index 0000000000..2a011dd684 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/handlers/TranslationHandler.java @@ -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()); + + } + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/AbstractHandler.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/AbstractHandler.java new file mode 100644 index 0000000000..00faab4099 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/AbstractHandler.java @@ -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(); + } + } +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ClassHandler.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ClassHandler.java new file mode 100644 index 0000000000..678dc03161 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ClassHandler.java @@ -0,0 +1,8 @@ +package net.osmand.translator.utils; + +public class ClassHandler { + + private static void organiseImports(StringBuffer buffer) { +// TODO + } +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/FieldsHandler.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/FieldsHandler.java new file mode 100644 index 0000000000..4363c7807b --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/FieldsHandler.java @@ -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(); + } + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/MethodHandler.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/MethodHandler.java new file mode 100644 index 0000000000..84cf770de1 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/MethodHandler.java @@ -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() { + + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ProjectHandler.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ProjectHandler.java new file mode 100644 index 0000000000..3d6791deb1 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/ProjectHandler.java @@ -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); + + } + + } + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/TranslationConstants.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/TranslationConstants.java new file mode 100644 index 0000000000..c1a2d55492 --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/utils/TranslationConstants.java @@ -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 + + } + +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/ExpressionVisitor.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/ExpressionVisitor.java new file mode 100644 index 0000000000..de0e927c4b --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/ExpressionVisitor.java @@ -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; + } +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/FieldVisitor.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/FieldVisitor.java new file mode 100644 index 0000000000..ae5a86cfac --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/FieldVisitor.java @@ -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 fields = new ArrayList(); + + @Override + public boolean visit(FieldDeclaration node) { + fields.add(node); + return super.visit(node); + } + + public List getFields() { + return fields; + } +} diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodVisitor.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodVisitor.java new file mode 100644 index 0000000000..3c603c91ee --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodVisitor.java @@ -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 methods = new ArrayList(); + + @Override + public boolean visit(MethodDeclaration node) { + methods.add(node); + return super.visit(node); + } + + + public List getMethods() { + return methods; + } +} \ No newline at end of file diff --git a/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodsBodyVisitor.java b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodsBodyVisitor.java new file mode 100644 index 0000000000..0bf6d4cf5f --- /dev/null +++ b/build-scripts/net.osmand.translator/src/net/osmand/translator/visitor/MethodsBodyVisitor.java @@ -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 statements = new ArrayList(); + + @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 getStatements() { + return statements; + } +} From b2668c3429a668e1f0a4e2b7a882688a3376d825 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 13 Sep 2012 21:51:57 +0200 Subject: [PATCH 2/4] Improve native rendering. Sort rendering area based on area --- .../src/net/osmand/plus/PoiFiltersHelper.java | 2 + Osmand-kernel/osmand/src/common.cpp | 2 +- Osmand-kernel/osmand/src/common.h | 6 +- Osmand-kernel/osmand/src/rendering.cpp | 234 ++++++++++-------- Osmand-kernel/osmand/src/rendering.h | 2 + 5 files changed, 139 insertions(+), 107 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/PoiFiltersHelper.java b/OsmAnd/src/net/osmand/plus/PoiFiltersHelper.java index 837b802906..0891ab0fc3 100644 --- a/OsmAnd/src/net/osmand/plus/PoiFiltersHelper.java +++ b/OsmAnd/src/net/osmand/plus/PoiFiltersHelper.java @@ -122,11 +122,13 @@ public class PoiFiltersHelper { } else if(UDF_SIGHTSEEING.equals(key)){ putAll(types, AmenityType.HISTORIC); putAll(types, AmenityType.TOURISM); + putAll(types, AmenityType.OSMWIKI); putValues(types, AmenityType.OTHER, "place_of_worship"); } else if(UDF_FOR_TOURISTS.equals(key)){ putAll(types, AmenityType.HISTORIC); putAll(types, AmenityType.TOURISM); putAll(types, AmenityType.FINANCE); + putAll(types, AmenityType.OSMWIKI); putValues(types, AmenityType.OTHER, "place_of_worship", "internet_access", "embassy","emergency_phone","marketplace", "post_office","telephone", "toilets"); } else if(UDF_FUEL.equals(key)){ diff --git a/Osmand-kernel/osmand/src/common.cpp b/Osmand-kernel/osmand/src/common.cpp index 33773f673e..833ea2be95 100644 --- a/Osmand-kernel/osmand/src/common.cpp +++ b/Osmand-kernel/osmand/src/common.cpp @@ -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){ return 1 << ((int)zoom); } else { diff --git a/Osmand-kernel/osmand/src/common.h b/Osmand-kernel/osmand/src/common.h index 21131f0765..1231f47e9d 100644 --- a/Osmand-kernel/osmand/src/common.h +++ b/Osmand-kernel/osmand/src/common.h @@ -162,8 +162,8 @@ public: int visible; int allObjects; int lastRenderedKey; - class ElapsedTimer textRendering; - class ElapsedTimer nativeOperations; + ElapsedTimer textRendering; + ElapsedTimer nativeOperations; // because they used in 3rd party functions public : @@ -294,6 +294,8 @@ void purgeCachedBitmaps(); int get31TileNumberX(double longitude); int get31TileNumberY( double latitude); +double getPowZoom(float zoom); + double getLongitudeFromTile(float zoom, double x) ; double getLatitudeFromTile(float zoom, double y); diff --git a/Osmand-kernel/osmand/src/rendering.cpp b/Osmand-kernel/osmand/src/rendering.cpp index 7eef978f8e..fda881b132 100644 --- a/Osmand-kernel/osmand/src/rendering.cpp +++ b/Osmand-kernel/osmand/src/rendering.cpp @@ -25,8 +25,18 @@ #include "binaryRead.h" #include "textdraw.cpp" #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 c, RenderingContext* rc) { rc->pointCount++; @@ -360,6 +370,14 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas if (!rendered || !updatePaint(req, paint, 0, 0, rc)) { 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; if (rc->getZoom() >= 16 && pair.first == "highway") { if (mObj->containsAdditional("oneway", "yes")) { @@ -377,6 +395,7 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas float prevx; float prevy; bool intersect = false; + int prevCross = 0; for (; i < length; i++) { calcPoint(mObj->points.at(i), rc); if (i == 0) { @@ -388,22 +407,22 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas path.lineTo(rc->calcX, rc->calcY); } 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; - } - 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; + } else { + int cross = 0; + cross |= (rc->calcX < 0 ? 1 : 0); + cross |= (rc->calcX > rc->getWidth() ? 2 : 0); + cross |= (rc->calcY < 0 ? 4 : 0); + cross |= (rc->calcY > rc->getHeight() ? 8 : 0); + if(i > 0) { + if((prevCross & cross) == 0) { + intersect = true; + } } - + prevCross = cross; } } - prevx = rc->calcX; - prevy = rc->calcY; } if (!intersect) { @@ -412,11 +431,6 @@ void drawPolyline(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas if (i > 0) { 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); } else { if (updatePaint(req, paint, -2, 0, rc)) { @@ -467,9 +481,7 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* rc->visible++; SkPath path; int i = 0; - float prevx; - float prevy; - bool intersect = false; + bool containsPoint = false; int bounds = 0; for (; i < length; i++) { calcPoint(mObj->points.at(i), rc); @@ -478,35 +490,36 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* } else { path.lineTo(rc->calcX, rc->calcY); } - xText += rc->calcX; - yText += rc->calcY; - if (!intersect) { + float tx = rc->calcX; + if (tx < 0) { + 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()) { - intersect = true; + containsPoint = true; } bounds |= (rc->calcX < 0 ? 1 : 0); bounds |= (rc->calcX >= rc->getWidth() ? 2 : 0); bounds |= (rc->calcY < 0 ? 4 : 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) { - 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; yText = rc->getHeight() / 2; } else { @@ -534,7 +547,7 @@ void drawPolygon(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* 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, @@ -579,18 +592,30 @@ void drawPoint(MapDataObject* mObj, RenderingRuleSearchRequest* req, SkCanvas* c } -void drawObject(RenderingContext* rc, MapDataObject* mObj, SkCanvas* cv, RenderingRuleSearchRequest* req, - SkPaint* paint, int l, int renderText, int drawOnlyShadow, int t) { - rc->allObjects++; - tag_value pair = mObj->types.at(l); - if (t == 1 && !drawOnlyShadow) { - // point - drawPoint(mObj, req, cv, paint, rc, pair, renderText); - } else if (t == 2) { - drawPolyline(mObj, req, cv, paint, rc, pair, mObj->getSimpleLayer(), drawOnlyShadow); - } else if (t == 3 && !drawOnlyShadow) { - // polygon - drawPolygon(mObj, req, cv, paint, rc, pair); +void drawObject(RenderingContext* rc, SkCanvas* cv, RenderingRuleSearchRequest* req, + SkPaint* paint, vector& array, int objOrder) { + + double limit = 100; + for (int i = 0; i < array.size(); i++) { + rc->allObjects++; + MapDataObject* mObj = array[i].obj; + tag_value pair = mObj->types.at(array[i].typeInd); + if (objOrder == 0) { + if (array[i].order < limit) { + return; + } + // 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) > sortObjectsByProperOrder(std::vector mapDataObjects, - RenderingRuleSearchRequest* req, RenderingContext* rc) { - UNORDERED(map) > orderMap; +double polygonArea(MapDataObject* obj, float mult) { + double area = 0.; + 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.orderj.order); } + +void sortObjectsByProperOrder(std::vector mapDataObjects, + RenderingRuleSearchRequest* req, RenderingContext* rc, + std::vector& polygonsArray, std::vector& pointsArray, + std::vector& linesArray) { if (req != NULL) { req->clearState(); const int size = mapDataObjects.size(); + float mult = 1. / getPowZoom(max(31 - (rc->getZoom() + 8), 0)); int i = 0; for (; i < size; i++) { uint32_t sh = i << 8; @@ -657,11 +700,22 @@ UNORDERED(map) > sortObjectsByProperOrder(std::vector searchRule(RenderingRulesStorage::ORDER_RULES)) { int objectType = req->getIntPropertyValue(req->props()->R_OBJECT_TYPE); 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 if(objectType == 3) { - // add icon point all the time - orderMap[(128 << 2)|1].push_back(sh + j); + MapDataObjectPrimitive pointObj = mapObj; + 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) { rc->shadowLevelMin = std::min(rc->shadowLevelMin, order); @@ -672,8 +726,10 @@ UNORDERED(map) > sortObjectsByProperOrder(std::vector mapDataObjects, SkCanvas* canvas, @@ -683,53 +739,23 @@ void doRendering(std::vector mapDataObjects, SkCanvas* canvas, SkPaint* paint = new SkPaint; paint->setAntiAlias(true); - // put in order map - UNORDERED(map) > orderMap = sortObjectsByProperOrder(mapDataObjects, req, rc); - std::set keys; - UNORDERED(map) >::iterator it = orderMap.begin(); + std::vector polygonsArray; + std::vector pointsArray; + std::vector linesArray; + sortObjectsByProperOrder(mapDataObjects, req, rc, polygonsArray, pointsArray, linesArray); + rc->lastRenderedKey = 0; - while (it != orderMap.end()) { - keys.insert(it->first); - it++; + drawObject(rc, canvas, req, paint, polygonsArray, 0); + rc->lastRenderedKey = 5; + if (rc->getShadowRenderingMode() > 1) { + drawObject(rc, canvas, req, paint, linesArray, 1); } - bool shadowDrawn = false; - for (std::set::iterator ks = keys.begin(); ks != keys.end(); ks++) { - if (!shadowDrawn && ((*ks)>>2) >= rc->shadowLevelMin && ((*ks)>>2) <= rc->shadowLevelMax && rc->getShadowRenderingMode() > 1) { - for (std::set::iterator ki = ks; ki != keys.end(); ki++) { - if (((*ki)>>2) > rc->shadowLevelMax || rc->interrupted()) { - break; - } - std::vector list = orderMap[*ki]; - for (std::vector::iterator ls = list.begin(); ls != list.end(); ls++) { - int i = *ls; - int ind = i >> 8; - int l = i & 0xff; - MapDataObject* mapObject = mapDataObjects.at(ind); + rc->lastRenderedKey = 40; + drawObject(rc, canvas, req, paint, linesArray, 2); + rc->lastRenderedKey = 60; - // show text only for main type - - drawObject(rc, mapObject, canvas, req, paint, l, l == 0, true, (*ki)&3); - } - } - shadowDrawn = true; - } - - std::vector list = orderMap[*ks]; - for (std::vector::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; - } - - } + drawObject(rc, canvas, req, paint, pointsArray, 3); + rc->lastRenderedKey = 125; drawIconsOverCanvas(rc, canvas); diff --git a/Osmand-kernel/osmand/src/rendering.h b/Osmand-kernel/osmand/src/rendering.h index eacb120566..c2ab8a0e4f 100644 --- a/Osmand-kernel/osmand/src/rendering.h +++ b/Osmand-kernel/osmand/src/rendering.h @@ -9,4 +9,6 @@ void doRendering(std::vector mapDataObjects, SkCanvas* canvas, RenderingRuleSearchRequest* req, RenderingContext* rc); + + #endif From 000c242c384561c9925f1ffd7e36b9ed725744f3 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 14 Sep 2012 00:48:56 +0200 Subject: [PATCH 3/4] Fix blackberry build --- OsmAnd/build.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/OsmAnd/build.xml b/OsmAnd/build.xml index 7627f7472d..ea182799c8 100644 --- a/OsmAnd/build.xml +++ b/OsmAnd/build.xml @@ -113,9 +113,9 @@ Not using native, excluding from build - - - + + + From f004775b4bc32947f44508ff3802bc48d54902ca Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 14 Sep 2012 00:53:25 +0200 Subject: [PATCH 4/4] Fix blackberry build --- OsmAnd/build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/build.xml b/OsmAnd/build.xml index ea182799c8..a51440176f 100644 --- a/OsmAnd/build.xml +++ b/OsmAnd/build.xml @@ -224,7 +224,7 @@ Restoring ${native.libs.absolute.dir} to it's place... - +