diff --git a/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java b/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java index 32ceab8a72..e55b93a348 100644 --- a/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java +++ b/DataExtractionOSM/src/net/osmand/swing/NativeSwingRendering.java @@ -1,6 +1,15 @@ package net.osmand.swing; +import java.io.IOException; + +import org.xml.sax.SAXException; + import net.osmand.NativeLibrary; +import net.osmand.RenderingContext; +import net.osmand.osm.MapUtils; +import net.osmand.render.RenderingRuleSearchRequest; +import net.osmand.render.RenderingRulesStorage; +import net.osmand.render.RenderingRulesStorage.RenderingRulesStorageResolver; public class NativeSwingRendering extends NativeLibrary { @@ -8,12 +17,48 @@ public class NativeSwingRendering extends NativeLibrary { System.load("/home/victor/projects/OsmAnd/git/Osmand-kernel/jni-prebuilt/linux-x86/osmand.lib"); } - public static void main(String[] args) { + private static RenderingRulesStorage getDefault() throws SAXException, IOException{ + RenderingRulesStorage storage = new RenderingRulesStorage(); + final RenderingRulesStorageResolver resolver = new RenderingRulesStorageResolver() { + @Override + public RenderingRulesStorage resolve(String name, RenderingRulesStorageResolver ref) throws SAXException { + RenderingRulesStorage depends = new RenderingRulesStorage(); + try { + depends.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream(name+".render.xml"), + ref); + } catch (IOException e) { + throw new SAXException(e); + } + return depends; + } + }; + storage.parseRulesFromXmlInputStream(RenderingRulesStorage.class.getResourceAsStream("default.render.xml"), resolver); + return storage; + } + + public static void main(String[] args) throws SAXException, IOException { // ByteBuffer buff = java.nio.ByteBuffer.wrap(new byte[10]); // new ByteBufferI // ImageIO.read(new ByteInputStream()); System.out.println("Native!"); - NativeLibrary.initBinaryMapFile("/home/victor/projects/OsmAnd/data/osm-gen/Cuba2.obf"); - NativeLibrary.initBinaryMapFile("/home/victor/projects/OsmAnd/data/osm-gen/basemap_2.obf"); + NativeSwingRendering lib = new NativeSwingRendering(); + lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/Cuba2.obf"); + lib.initMapFile("/home/victor/projects/OsmAnd/data/osm-gen/basemap_2.obf"); + RenderingContext ctx = new RenderingContext(); + RenderingRulesStorage df = getDefault(); + lib.initRenderingRulesStorage(df); + + RenderingRuleSearchRequest request = new RenderingRuleSearchRequest(df); + double latTop = 23.5; + double lonLeft = -80; + double latBottom = 23; + double lonRight = -79; + int sleft = MapUtils.get31TileNumberX(lonLeft); + int sright = MapUtils.get31TileNumberX(lonRight); + int stop = MapUtils.get31TileNumberY(latTop); + int sbottom = MapUtils.get31TileNumberY(latBottom); + + NativeSearchResult res = lib.searchObjectsForRendering(sleft, sright, stop, sbottom, 11, request, true, + ctx, "Nothing found"); } } diff --git a/Osmand-kernel/osmand/Makefile b/Osmand-kernel/osmand/Makefile index 098ec6885d..d02b139f89 100644 --- a/Osmand-kernel/osmand/Makefile +++ b/Osmand-kernel/osmand/Makefile @@ -25,7 +25,8 @@ CPPFLAGS := \ $(C_INCLUDES) #target : ../$(RUNFILE) -target : $(PREBUILT_DIR)/$(LIBNAME) ../$(RUNFILE) +target : $(PREBUILT_DIR)/$(LIBNAME) +#target : $(PREBUILT_DIR)/$(LIBNAME) ../$(RUNFILE) ../$(RUNFILE) : $(OBJECTS) $(PREBUILT_DIR)/libskia.a $(PREBUILT_DIR)/libproto.a diff --git a/Osmand-kernel/osmand/src/binaryRead.cpp b/Osmand-kernel/osmand/src/binaryRead.cpp index 74b63e27cf..f08f81fe23 100644 --- a/Osmand-kernel/osmand/src/binaryRead.cpp +++ b/Osmand-kernel/osmand/src/binaryRead.cpp @@ -702,8 +702,7 @@ void searchMapData(CodedInputStream* input, MapRoot* root, MapIndex* ind, Search -ResultPublisher* searchObjectsForRendering(SearchQuery* q, - bool skipDuplicates, std::string msgNothingFound) { +ResultPublisher* searchObjectsForRendering(SearchQuery* q, bool skipDuplicates, std::string msgNothingFound) { map::iterator i = openFiles.begin(); HMAP::hash_set ids; int count = 0; diff --git a/Osmand-kernel/osmand/src/java_renderRules.h b/Osmand-kernel/osmand/src/java_renderRules.h index 8f25acee62..f3828842c5 100644 --- a/Osmand-kernel/osmand/src/java_renderRules.h +++ b/Osmand-kernel/osmand/src/java_renderRules.h @@ -139,13 +139,14 @@ void initProperties(JNIEnv* env, RenderingRulesStorage* st, jobject javaStorage) st->PROPS.registerRuleInternal(prop); env->DeleteLocalRef(rulePrope); } + st->PROPS.createDefaultProperties(); env->DeleteLocalRef(props); env->DeleteLocalRef(listProps); } void initRules(JNIEnv* env, RenderingRulesStorage* st, jobject javaStorage) { - for (int i = 1; i < st->tagValueGlobalRules->size(); i++) { + for (int i = 1; i < RenderingRulesStorage::SIZE_STATES; i++) { jobjectArray rules = (jobjectArray) env->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i); jsize len = env->GetArrayLength(rules); for (jsize j = 0; j < len; j++) { diff --git a/Osmand-kernel/osmand/src/java_wrap.cpp b/Osmand-kernel/osmand/src/java_wrap.cpp index 538a22e339..462a702d5f 100644 --- a/Osmand-kernel/osmand/src/java_wrap.cpp +++ b/Osmand-kernel/osmand/src/java_wrap.cpp @@ -11,6 +11,7 @@ #include "binaryRead.h" #include "rendering.h" + JavaVM* globalJVM = NULL; void loadJniRenderingContext(JNIEnv* env); void loadJniRenderingRules(JNIEnv* env); @@ -71,12 +72,13 @@ RenderingRulesStorage* getStorage(JNIEnv* env, jobject storage) { } return cachedStorages[storage]; } + + extern "C" JNIEXPORT void JNICALL Java_net_osmand_NativeLibrary_initRenderingRulesStorage(JNIEnv* ienv, jobject obj, jobject storage) { getStorage(ienv, storage); } - RenderingRuleSearchRequest* initSearchRequest(JNIEnv* env, jobject renderingRuleSearchRequest) { jobject storage = env->GetObjectField(renderingRuleSearchRequest, RenderingRuleSearchRequest_storage); RenderingRulesStorage* st = getStorage(env, storage); @@ -102,9 +104,10 @@ extern "C" JNIEXPORT jint JNICALL Java_net_osmand_NativeLibrary_searchNativeObje SearchQuery q(sleft, sright, stop, sbottom, req, j); q.zoom = zoom; + ResultPublisher* res = searchObjectsForRendering(&q, skipDuplicates, getString(ienv, msgNothingFound)); delete req; - return (jint) res; + return (jint) j; } diff --git a/Osmand-kernel/osmand/src/renderRules.cpp b/Osmand-kernel/osmand/src/renderRules.cpp index a1e09dff97..d3b105cd09 100644 --- a/Osmand-kernel/osmand/src/renderRules.cpp +++ b/Osmand-kernel/osmand/src/renderRules.cpp @@ -98,6 +98,7 @@ string RenderingRule::getColorPropertyValue(string property) { return ""; } + int RenderingRule::getIntPropertyValue(string property) { int i = getPropertyIndex(property); if (i >= 0) { @@ -117,7 +118,6 @@ RenderingRule* RenderingRulesStorage::getRule(int state, int itag, int ivalue) { void RenderingRulesStorage::registerGlobalRule(RenderingRule* rr, int state) { - int tag = rr->getIntPropertyValue(this->PROPS.R_TAG->attrName); if (tag == -1) { osmand_log_print(LOG_ERROR, "Attribute tag should be specified for root filter "); @@ -130,6 +130,7 @@ void RenderingRulesStorage::registerGlobalRule(RenderingRule* rr, int state) { int key = (tag << SHIFT_TAG_VAL) + value; RenderingRule* toInsert = rr; RenderingRule* previous = tagValueGlobalRules[state][key]; + if (previous != NULL) { // all root rules should have at least tag/value toInsert = createTagValueRootWrapperRule(key, previous); diff --git a/Osmand-kernel/osmand/src/renderRules.h b/Osmand-kernel/osmand/src/renderRules.h index ae3c8c32ff..dfd572bd22 100644 --- a/Osmand-kernel/osmand/src/renderRules.h +++ b/Osmand-kernel/osmand/src/renderRules.h @@ -2,6 +2,7 @@ #define _OSMAND_RENDER_RULES_H #include +#include #include #include "common.h" #include "mapObjects.h" @@ -276,7 +277,6 @@ public: return getProperty(p->attrName); } -private: void createDefaultProperties() { R_TAG = registerRuleInternal(RenderingRuleProperty::createInputStringProperty("tag")); R_VALUE = registerRuleInternal(RenderingRuleProperty::createInputStringProperty("value")); @@ -351,10 +351,9 @@ private: HMAP::hash_map dictionaryMap; std::vector dictionary; const static int SHIFT_TAG_VAL = 16; - const static int SIZE_STATES = 7; - // TODO make private public: + const static int SIZE_STATES = 7; HMAP::hash_map* tagValueGlobalRules; map renderingAttributes; public: