Implement swing native search
This commit is contained in:
parent
9d3c625421
commit
5abab74cda
7 changed files with 62 additions and 13 deletions
|
@ -1,6 +1,15 @@
|
||||||
package net.osmand.swing;
|
package net.osmand.swing;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import net.osmand.NativeLibrary;
|
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 {
|
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");
|
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]);
|
// ByteBuffer buff = java.nio.ByteBuffer.wrap(new byte[10]);
|
||||||
// new ByteBufferI
|
// new ByteBufferI
|
||||||
// ImageIO.read(new ByteInputStream());
|
// ImageIO.read(new ByteInputStream());
|
||||||
System.out.println("Native!");
|
System.out.println("Native!");
|
||||||
NativeLibrary.initBinaryMapFile("/home/victor/projects/OsmAnd/data/osm-gen/Cuba2.obf");
|
NativeSwingRendering lib = new NativeSwingRendering();
|
||||||
NativeLibrary.initBinaryMapFile("/home/victor/projects/OsmAnd/data/osm-gen/basemap_2.obf");
|
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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,8 @@ CPPFLAGS := \
|
||||||
$(C_INCLUDES)
|
$(C_INCLUDES)
|
||||||
|
|
||||||
#target : ../$(RUNFILE)
|
#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
|
../$(RUNFILE) : $(OBJECTS) $(PREBUILT_DIR)/libskia.a $(PREBUILT_DIR)/libproto.a
|
||||||
|
|
|
@ -702,8 +702,7 @@ void searchMapData(CodedInputStream* input, MapRoot* root, MapIndex* ind, Search
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ResultPublisher* searchObjectsForRendering(SearchQuery* q,
|
ResultPublisher* searchObjectsForRendering(SearchQuery* q, bool skipDuplicates, std::string msgNothingFound) {
|
||||||
bool skipDuplicates, std::string msgNothingFound) {
|
|
||||||
map<std::string, BinaryMapFile*>::iterator i = openFiles.begin();
|
map<std::string, BinaryMapFile*>::iterator i = openFiles.begin();
|
||||||
HMAP::hash_set<long long> ids;
|
HMAP::hash_set<long long> ids;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
@ -139,13 +139,14 @@ void initProperties(JNIEnv* env, RenderingRulesStorage* st, jobject javaStorage)
|
||||||
st->PROPS.registerRuleInternal(prop);
|
st->PROPS.registerRuleInternal(prop);
|
||||||
env->DeleteLocalRef(rulePrope);
|
env->DeleteLocalRef(rulePrope);
|
||||||
}
|
}
|
||||||
|
st->PROPS.createDefaultProperties();
|
||||||
env->DeleteLocalRef(props);
|
env->DeleteLocalRef(props);
|
||||||
env->DeleteLocalRef(listProps);
|
env->DeleteLocalRef(listProps);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void initRules(JNIEnv* env, RenderingRulesStorage* st, jobject javaStorage) {
|
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);
|
jobjectArray rules = (jobjectArray) env->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules, i);
|
||||||
jsize len = env->GetArrayLength(rules);
|
jsize len = env->GetArrayLength(rules);
|
||||||
for (jsize j = 0; j < len; j++) {
|
for (jsize j = 0; j < len; j++) {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "binaryRead.h"
|
#include "binaryRead.h"
|
||||||
#include "rendering.h"
|
#include "rendering.h"
|
||||||
|
|
||||||
|
|
||||||
JavaVM* globalJVM = NULL;
|
JavaVM* globalJVM = NULL;
|
||||||
void loadJniRenderingContext(JNIEnv* env);
|
void loadJniRenderingContext(JNIEnv* env);
|
||||||
void loadJniRenderingRules(JNIEnv* env);
|
void loadJniRenderingRules(JNIEnv* env);
|
||||||
|
@ -71,12 +72,13 @@ RenderingRulesStorage* getStorage(JNIEnv* env, jobject storage) {
|
||||||
}
|
}
|
||||||
return cachedStorages[storage];
|
return cachedStorages[storage];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL Java_net_osmand_NativeLibrary_initRenderingRulesStorage(JNIEnv* ienv,
|
extern "C" JNIEXPORT void JNICALL Java_net_osmand_NativeLibrary_initRenderingRulesStorage(JNIEnv* ienv,
|
||||||
jobject obj, jobject storage) {
|
jobject obj, jobject storage) {
|
||||||
getStorage(ienv, storage);
|
getStorage(ienv, storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
RenderingRuleSearchRequest* initSearchRequest(JNIEnv* env, jobject renderingRuleSearchRequest) {
|
RenderingRuleSearchRequest* initSearchRequest(JNIEnv* env, jobject renderingRuleSearchRequest) {
|
||||||
jobject storage = env->GetObjectField(renderingRuleSearchRequest, RenderingRuleSearchRequest_storage);
|
jobject storage = env->GetObjectField(renderingRuleSearchRequest, RenderingRuleSearchRequest_storage);
|
||||||
RenderingRulesStorage* st = getStorage(env, 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);
|
SearchQuery q(sleft, sright, stop, sbottom, req, j);
|
||||||
q.zoom = zoom;
|
q.zoom = zoom;
|
||||||
|
|
||||||
|
|
||||||
ResultPublisher* res = searchObjectsForRendering(&q, skipDuplicates, getString(ienv, msgNothingFound));
|
ResultPublisher* res = searchObjectsForRendering(&q, skipDuplicates, getString(ienv, msgNothingFound));
|
||||||
delete req;
|
delete req;
|
||||||
return (jint) res;
|
return (jint) j;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,6 +98,7 @@ string RenderingRule::getColorPropertyValue(string property) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int RenderingRule::getIntPropertyValue(string property) {
|
int RenderingRule::getIntPropertyValue(string property) {
|
||||||
int i = getPropertyIndex(property);
|
int i = getPropertyIndex(property);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
|
@ -117,7 +118,6 @@ RenderingRule* RenderingRulesStorage::getRule(int state, int itag, int ivalue) {
|
||||||
|
|
||||||
|
|
||||||
void RenderingRulesStorage::registerGlobalRule(RenderingRule* rr, int state) {
|
void RenderingRulesStorage::registerGlobalRule(RenderingRule* rr, int state) {
|
||||||
|
|
||||||
int tag = rr->getIntPropertyValue(this->PROPS.R_TAG->attrName);
|
int tag = rr->getIntPropertyValue(this->PROPS.R_TAG->attrName);
|
||||||
if (tag == -1) {
|
if (tag == -1) {
|
||||||
osmand_log_print(LOG_ERROR, "Attribute tag should be specified for root filter ");
|
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;
|
int key = (tag << SHIFT_TAG_VAL) + value;
|
||||||
RenderingRule* toInsert = rr;
|
RenderingRule* toInsert = rr;
|
||||||
RenderingRule* previous = tagValueGlobalRules[state][key];
|
RenderingRule* previous = tagValueGlobalRules[state][key];
|
||||||
|
|
||||||
if (previous != NULL) {
|
if (previous != NULL) {
|
||||||
// all root rules should have at least tag/value
|
// all root rules should have at least tag/value
|
||||||
toInsert = createTagValueRootWrapperRule(key, previous);
|
toInsert = createTagValueRootWrapperRule(key, previous);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _OSMAND_RENDER_RULES_H
|
#define _OSMAND_RENDER_RULES_H
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "mapObjects.h"
|
#include "mapObjects.h"
|
||||||
|
@ -276,7 +277,6 @@ public:
|
||||||
return getProperty(p->attrName);
|
return getProperty(p->attrName);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
void createDefaultProperties() {
|
void createDefaultProperties() {
|
||||||
R_TAG = registerRuleInternal(RenderingRuleProperty::createInputStringProperty("tag"));
|
R_TAG = registerRuleInternal(RenderingRuleProperty::createInputStringProperty("tag"));
|
||||||
R_VALUE = registerRuleInternal(RenderingRuleProperty::createInputStringProperty("value"));
|
R_VALUE = registerRuleInternal(RenderingRuleProperty::createInputStringProperty("value"));
|
||||||
|
@ -351,10 +351,9 @@ private:
|
||||||
HMAP::hash_map<std::string, int> dictionaryMap;
|
HMAP::hash_map<std::string, int> dictionaryMap;
|
||||||
std::vector<std::string> dictionary;
|
std::vector<std::string> dictionary;
|
||||||
const static int SHIFT_TAG_VAL = 16;
|
const static int SHIFT_TAG_VAL = 16;
|
||||||
const static int SIZE_STATES = 7;
|
|
||||||
|
|
||||||
// TODO make private
|
// TODO make private
|
||||||
public:
|
public:
|
||||||
|
const static int SIZE_STATES = 7;
|
||||||
HMAP::hash_map<int, RenderingRule*>* tagValueGlobalRules;
|
HMAP::hash_map<int, RenderingRule*>* tagValueGlobalRules;
|
||||||
map<std::string, RenderingRule*> renderingAttributes;
|
map<std::string, RenderingRule*> renderingAttributes;
|
||||||
public:
|
public:
|
||||||
|
|
Loading…
Reference in a new issue