Implement swing native search

This commit is contained in:
Victor Shcherb 2012-05-09 13:31:58 +02:00
parent 9d3c625421
commit 5abab74cda
7 changed files with 62 additions and 13 deletions

View file

@ -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");
}
}

View file

@ -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

View file

@ -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<std::string, BinaryMapFile*>::iterator i = openFiles.begin();
HMAP::hash_set<long long> ids;
int count = 0;

View file

@ -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++) {

View file

@ -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;
}

View file

@ -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);

View file

@ -2,6 +2,7 @@
#define _OSMAND_RENDER_RULES_H
#include <string>
#include <vector>
#include <map>
#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<std::string, int> dictionaryMap;
std::vector<std::string> 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<int, RenderingRule*>* tagValueGlobalRules;
map<std::string, RenderingRule*> renderingAttributes;
public: