2011-10-25 15:33:05 +02:00
|
|
|
#ifndef _OSMAND_RENDER_RULES
|
|
|
|
#define _OSMAND_RENDER_RULES
|
|
|
|
|
2011-10-23 22:28:07 +02:00
|
|
|
#include <jni.h>
|
2012-04-30 11:30:04 +02:00
|
|
|
#include "osmand_log.h"
|
2011-10-24 12:57:01 +02:00
|
|
|
#include <iterator>
|
|
|
|
#include <string>
|
2011-10-23 22:28:07 +02:00
|
|
|
#include <vector>
|
2012-04-30 13:33:05 +02:00
|
|
|
#ifdef LINUX_BUILD
|
|
|
|
#include <ext/hash_map>
|
|
|
|
using namespace __gnu_cxx;
|
|
|
|
#else
|
2011-10-24 12:57:01 +02:00
|
|
|
#include <hash_map>
|
2012-04-30 13:33:05 +02:00
|
|
|
#endif
|
2011-10-28 16:56:27 +02:00
|
|
|
#include "renderRules.h"
|
2011-10-28 16:01:00 +02:00
|
|
|
#include "common.h"
|
2011-10-28 16:56:27 +02:00
|
|
|
|
2011-10-24 12:57:01 +02:00
|
|
|
jclass ListClass;
|
|
|
|
jmethodID List_size;
|
|
|
|
jmethodID List_get;
|
|
|
|
|
|
|
|
jclass RenderingRuleClass;
|
|
|
|
jfieldID RenderingRule_properties;
|
|
|
|
jfieldID RenderingRule_intProperties;
|
|
|
|
jfieldID RenderingRule_floatProperties;
|
|
|
|
jfieldID RenderingRule_ifElseChildren;
|
|
|
|
jfieldID RenderingRule_ifChildren;
|
|
|
|
|
2011-10-23 22:28:07 +02:00
|
|
|
jclass RenderingRuleStoragePropertiesClass;
|
2011-10-24 12:57:01 +02:00
|
|
|
jfieldID RenderingRuleStorageProperties_rules;
|
|
|
|
|
2011-10-23 22:28:07 +02:00
|
|
|
jclass RenderingRulePropertyClass;
|
2011-10-24 12:57:01 +02:00
|
|
|
jfieldID RenderingRuleProperty_type;
|
|
|
|
jfieldID RenderingRuleProperty_input;
|
|
|
|
jfieldID RenderingRuleProperty_attrName;
|
|
|
|
|
|
|
|
jclass RenderingRulesStorageClass;
|
|
|
|
jfieldID RenderingRulesStorageClass_dictionary;
|
|
|
|
jfieldID RenderingRulesStorage_PROPS;
|
|
|
|
jmethodID RenderingRulesStorage_getRules;
|
2011-10-23 22:28:07 +02:00
|
|
|
|
|
|
|
jclass RenderingRuleSearchRequestClass;
|
2011-10-24 12:57:01 +02:00
|
|
|
jfieldID RenderingRuleSearchRequest_storage;
|
|
|
|
jfieldID RenderingRuleSearchRequest_props;
|
|
|
|
jfieldID RenderingRuleSearchRequest_values;
|
|
|
|
jfieldID RenderingRuleSearchRequest_fvalues;
|
|
|
|
jfieldID RenderingRuleSearchRequest_savedValues;
|
|
|
|
jfieldID RenderingRuleSearchRequest_savedFvalues;
|
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
int RenderingRulesStorage::getPropertiesSize() {
|
|
|
|
return properties.size();
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRuleProperty* RenderingRulesStorage::getProperty(int i) {
|
|
|
|
return &properties.at(i);
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRule* RenderingRulesStorage::getRule(int state, int itag, int ivalue) {
|
2012-04-30 13:33:05 +02:00
|
|
|
hash_map<int, RenderingRule>::iterator it = (tagValueGlobalRules[state]).find(
|
2011-10-28 16:56:27 +02:00
|
|
|
(itag << SHIFT_TAG_VAL) | ivalue);
|
|
|
|
if (it == tagValueGlobalRules[state].end()) {
|
|
|
|
return NULL;
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return &(*it).second;
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRuleProperty* RenderingRulesStorage::getProperty(const char* st) {
|
2012-04-30 13:33:05 +02:00
|
|
|
hash_map<std::string, RenderingRuleProperty*>::iterator i = propertyMap.find(st);
|
2011-10-28 16:56:27 +02:00
|
|
|
if (i == propertyMap.end()) {
|
|
|
|
return NULL;
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return (*i).second;
|
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
std::string RenderingRulesStorage::getDictionaryValue(int i) {
|
|
|
|
if (i < 0) {
|
2012-03-02 17:24:06 +01:00
|
|
|
return std::string();
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return dictionary.at(i);
|
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
int RenderingRulesStorage::getDictionaryValue(std::string s) {
|
|
|
|
return dictionaryMap[s];
|
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
void RenderingRulesStorage::initDictionary(JNIEnv* env) {
|
|
|
|
jobject listDictionary = env->GetObjectField(javaStorage, RenderingRulesStorageClass_dictionary);
|
|
|
|
uint sz = env->CallIntMethod(listDictionary, List_size);
|
2011-10-28 16:56:27 +02:00
|
|
|
uint i = 0;
|
|
|
|
for (; i < sz; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jstring st = (jstring) env->CallObjectMethod(listDictionary, List_get, i);
|
2011-10-28 16:56:27 +02:00
|
|
|
// if(st != NULL)
|
|
|
|
// {
|
2012-04-28 14:22:56 +02:00
|
|
|
const char* utf = env->GetStringUTFChars(st, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
std::string d = std::string(utf);
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseStringUTFChars(st, utf);
|
|
|
|
env->DeleteLocalRef(st);
|
2011-10-28 16:56:27 +02:00
|
|
|
dictionary.push_back(d);
|
|
|
|
dictionaryMap[d] = i;
|
|
|
|
// }
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(listDictionary);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
void RenderingRulesStorage::initProperties(JNIEnv* env) {
|
|
|
|
jobject props = env->GetObjectField(javaStorage, RenderingRulesStorage_PROPS);
|
|
|
|
jobject listProps = env->GetObjectField(props, RenderingRuleStorageProperties_rules);
|
|
|
|
uint sz = env->CallIntMethod(listProps, List_size);
|
2011-10-28 16:56:27 +02:00
|
|
|
uint i = 0;
|
|
|
|
for (; i < sz; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject rulePrope = env->CallObjectMethod(listProps, List_get, i);
|
|
|
|
bool input = (env->GetBooleanField(rulePrope, RenderingRuleProperty_input) == JNI_TRUE);
|
|
|
|
int type = env->GetIntField(rulePrope, RenderingRuleProperty_type);
|
|
|
|
std::string name = getStringField(env, rulePrope, RenderingRuleProperty_attrName);
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRuleProperty* prop = new RenderingRuleProperty(type, input, name, i);
|
|
|
|
properties.push_back(*prop);
|
|
|
|
propertyMap[name] = prop;
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(rulePrope);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(props);
|
|
|
|
env->DeleteLocalRef(listProps);
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 16:33:19 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
void RenderingRulesStorage::initRules(JNIEnv* env) {
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int i = 1; i < SIZE_STATES; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobjectArray rules = (jobjectArray) env->CallObjectMethod(javaStorage, RenderingRulesStorage_getRules,
|
2011-10-28 16:56:27 +02:00
|
|
|
i);
|
2012-04-28 14:22:56 +02:00
|
|
|
jsize len = env->GetArrayLength(rules);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (jsize j = 0; j < len; j++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject rRule = env->GetObjectArrayElement(rules, j);
|
|
|
|
RenderingRule* rule = createRenderingRule(env, rRule);
|
|
|
|
env->DeleteLocalRef(rRule);
|
2011-10-28 16:56:27 +02:00
|
|
|
if (rule != NULL) {
|
|
|
|
|
|
|
|
jsize psz = rule->properties.size();
|
|
|
|
int tag = -1;
|
|
|
|
int value = -1;
|
|
|
|
for (int p = 0; p < psz; p++) {
|
|
|
|
if (rule->properties.at(p)->attrName == "tag") {
|
|
|
|
tag = rule->intProperties.at(p);
|
|
|
|
} else if (rule->properties.at(p)->attrName == "value") {
|
|
|
|
value = rule->intProperties.at(p);
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
if (tag != -1 && value != -1) {
|
|
|
|
int key = (tag << SHIFT_TAG_VAL) + value;
|
|
|
|
tagValueGlobalRules[i][key] = *rule;
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(rules);
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRule* RenderingRulesStorage::createRenderingRule(JNIEnv* env, jobject rRule) {
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRule* rule = new RenderingRule;
|
2012-04-28 14:22:56 +02:00
|
|
|
jobjectArray props = (jobjectArray) env->GetObjectField(rRule, RenderingRule_properties);
|
|
|
|
jintArray intProps = (jintArray) env->GetObjectField(rRule, RenderingRule_intProperties);
|
|
|
|
jfloatArray floatProps = (jfloatArray) env->GetObjectField(rRule, RenderingRule_floatProperties);
|
|
|
|
jobject ifChildren = env->GetObjectField(rRule, RenderingRule_ifChildren);
|
|
|
|
jobject ifElseChildren = env->GetObjectField(rRule, RenderingRule_ifElseChildren);
|
2011-10-24 16:33:19 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
jsize sz = env->GetArrayLength(props);
|
2011-10-28 16:56:27 +02:00
|
|
|
|
|
|
|
if (floatProps != NULL) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jfloat* fe = env->GetFloatArrayElements(floatProps, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int j = 0; j < sz; j++) {
|
|
|
|
rule->floatProperties.push_back(fe[j]);
|
2011-10-24 16:33:19 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseFloatArrayElements(floatProps, fe, JNI_ABORT);
|
|
|
|
env->DeleteLocalRef(floatProps);
|
2011-10-28 16:56:27 +02:00
|
|
|
} else {
|
|
|
|
rule->floatProperties.assign(sz, 0);
|
|
|
|
}
|
2011-10-24 16:33:19 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
if (intProps != NULL) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jint* ie = env->GetIntArrayElements(intProps, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int j = 0; j < sz; j++) {
|
|
|
|
rule->intProperties.push_back(ie[j]);
|
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseIntArrayElements(intProps, ie, JNI_ABORT);
|
|
|
|
env->DeleteLocalRef(intProps);
|
2011-10-28 16:56:27 +02:00
|
|
|
} else {
|
|
|
|
rule->intProperties.assign(sz, -1);
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
for (jsize i = 0; i < sz; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject prop = env->GetObjectArrayElement(props, i);
|
|
|
|
std::string attr = getStringField(env, prop, RenderingRuleProperty_attrName);
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRuleProperty* p = getProperty(attr.c_str());
|
|
|
|
rule->properties.push_back(p);
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(prop);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(props);
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
if (ifChildren != NULL) {
|
2012-04-28 14:22:56 +02:00
|
|
|
sz = env->CallIntMethod(ifChildren, List_size);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (jsize i = 0; i < sz; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject o = env->CallObjectMethod(ifChildren, List_get, i);
|
|
|
|
rule->ifChildren.push_back(*createRenderingRule(env, o));
|
|
|
|
env->DeleteLocalRef(o);
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(ifChildren);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
if (ifElseChildren != NULL) {
|
2012-04-28 14:22:56 +02:00
|
|
|
sz = env->CallIntMethod(ifElseChildren, List_size);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (jsize i = 0; i < sz; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject o = env->CallObjectMethod(ifElseChildren, List_get, i);
|
|
|
|
rule->ifElseChildren.push_back(*createRenderingRule(env, o));
|
|
|
|
env->DeleteLocalRef(o);
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(ifElseChildren);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
return rule;
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
|
|
|
// Global object
|
|
|
|
RenderingRulesStorage* defaultStorage = NULL;
|
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
void RenderingRuleSearchRequest::initObject(JNIEnv* env, jobject rrs) {
|
2011-10-28 16:56:27 +02:00
|
|
|
jsize sz;
|
2012-04-28 14:22:56 +02:00
|
|
|
jobjectArray oa = (jobjectArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_props);
|
|
|
|
sz = env->GetArrayLength(oa);
|
2011-10-28 16:56:27 +02:00
|
|
|
std::vector<RenderingRuleProperty*> requestProps;
|
|
|
|
for (jsize i = 0; i < sz; i++) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject prop = env->GetObjectArrayElement(oa, i);
|
|
|
|
std::string attr = getStringField(env, prop, RenderingRuleProperty_attrName);
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRuleProperty* p = storage->getProperty(attr.c_str());
|
|
|
|
requestProps.push_back(p);
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(prop);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(oa);
|
2011-10-28 16:56:27 +02:00
|
|
|
sz = storage->getPropertiesSize();
|
2011-10-24 12:57:01 +02:00
|
|
|
{
|
2011-10-28 16:56:27 +02:00
|
|
|
values = new int[sz];
|
2012-04-28 14:22:56 +02:00
|
|
|
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values);
|
|
|
|
jint* ie = env->GetIntArrayElements(ia, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
values[requestProps.at(i)->id] = ie[i];
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
|
|
|
|
env->DeleteLocalRef(ia);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
{
|
|
|
|
fvalues = new float[sz];
|
2012-04-28 14:22:56 +02:00
|
|
|
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
|
|
|
|
jfloat* ie = env->GetFloatArrayElements(ia, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
fvalues[requestProps.at(i)->id] = ie[i];
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
|
|
|
|
env->DeleteLocalRef(ia);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
{
|
|
|
|
savedValues = new int[sz];
|
2012-04-28 14:22:56 +02:00
|
|
|
jintArray ia = (jintArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_values);
|
|
|
|
jint* ie = env->GetIntArrayElements(ia, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
savedValues[requestProps.at(i)->id] = ie[i];
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseIntArrayElements(ia, ie, JNI_ABORT);
|
|
|
|
env->DeleteLocalRef(ia);
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
{
|
|
|
|
savedFvalues = new float[sz];
|
2012-04-28 14:22:56 +02:00
|
|
|
jfloatArray ia = (jfloatArray) env->GetObjectField(rrs, RenderingRuleSearchRequest_fvalues);
|
|
|
|
jfloat* ie = env->GetFloatArrayElements(ia, NULL);
|
2011-10-28 16:56:27 +02:00
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
savedFvalues[requestProps.at(i)->id] = ie[i];
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->ReleaseFloatArrayElements(ia, ie, JNI_ABORT);
|
|
|
|
env->DeleteLocalRef(ia);
|
2011-10-24 12:57:01 +02:00
|
|
|
}
|
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-11-22 02:31:01 +01:00
|
|
|
extern "C" JNIEXPORT void JNICALL Java_net_osmand_plus_render_NativeOsmandLibrary_initRenderingRulesStorage(JNIEnv* ienv,
|
|
|
|
jobject obj, jobject storage) {
|
|
|
|
if (defaultStorage == NULL || defaultStorage->javaStorage != storage) {
|
|
|
|
// multi thread will not work?
|
|
|
|
if (defaultStorage != NULL) {
|
|
|
|
delete defaultStorage;
|
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
defaultStorage = new RenderingRulesStorage(ienv, storage);
|
2011-11-22 02:31:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleSearchRequest::RenderingRuleSearchRequest(JNIEnv* env, jobject rrs) :
|
2011-10-28 16:56:27 +02:00
|
|
|
renderingRuleSearch(rrs) {
|
2012-04-28 14:22:56 +02:00
|
|
|
jobject storage = env->GetObjectField(rrs, RenderingRuleSearchRequest_storage);
|
2011-10-28 16:56:27 +02:00
|
|
|
if (defaultStorage == NULL || defaultStorage->javaStorage != storage) {
|
2011-11-22 02:31:01 +01:00
|
|
|
// multi thread will not work?
|
2011-10-28 16:56:27 +02:00
|
|
|
if (defaultStorage != NULL) {
|
|
|
|
delete defaultStorage;
|
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
defaultStorage = new RenderingRulesStorage(env, storage);
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2012-04-28 14:22:56 +02:00
|
|
|
env->DeleteLocalRef(storage);
|
2011-10-28 16:56:27 +02:00
|
|
|
this->storage = defaultStorage;
|
|
|
|
PROPS = new RenderingRulesStorageProperties(this->storage);
|
2012-04-28 14:22:56 +02:00
|
|
|
initObject(env, rrs);
|
2011-10-28 16:56:27 +02:00
|
|
|
clearState();
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-30 00:57:40 +02:00
|
|
|
RenderingRuleSearchRequest::~RenderingRuleSearchRequest() {
|
|
|
|
delete PROPS;
|
|
|
|
delete[] fvalues;
|
|
|
|
delete[] values;
|
|
|
|
delete[] savedFvalues;
|
|
|
|
delete[] savedValues;
|
|
|
|
}
|
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
int RenderingRuleSearchRequest::getIntPropertyValue(RenderingRuleProperty* prop) {
|
|
|
|
if (prop == NULL) {
|
|
|
|
return 0;
|
2011-10-25 15:33:05 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return values[prop->id];
|
|
|
|
}
|
2011-10-25 15:33:05 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
int RenderingRuleSearchRequest::getIntPropertyValue(RenderingRuleProperty* prop, int def) {
|
|
|
|
if (prop == NULL || values[prop->id] == -1) {
|
|
|
|
return def;
|
2011-10-23 22:59:36 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return values[prop->id];
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
std::string RenderingRuleSearchRequest::getStringPropertyValue(RenderingRuleProperty* prop) {
|
|
|
|
if (prop == NULL) {
|
2012-03-02 17:24:06 +01:00
|
|
|
return std::string();
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
|
|
|
int s = values[prop->id];
|
|
|
|
return storage->getDictionaryValue(s);
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
float RenderingRuleSearchRequest::getFloatPropertyValue(RenderingRuleProperty* prop) {
|
|
|
|
if (prop == NULL) {
|
|
|
|
return 0;
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return fvalues[prop->id];
|
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
void RenderingRuleSearchRequest::setStringFilter(RenderingRuleProperty* p, std::string filter) {
|
|
|
|
if (p != NULL) {
|
|
|
|
// assert p->input;
|
|
|
|
values[p->id] = storage->getDictionaryValue(filter);
|
2011-10-23 22:59:36 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
|
|
|
void RenderingRuleSearchRequest::setIntFilter(RenderingRuleProperty* p, int filter) {
|
|
|
|
if (p != NULL) {
|
|
|
|
// assert p->input;
|
|
|
|
values[p->id] = filter;
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 18:09:03 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
void RenderingRuleSearchRequest::clearIntvalue(RenderingRuleProperty* p) {
|
|
|
|
if (p != NULL) {
|
|
|
|
// assert !p->input;
|
|
|
|
values[p->id] = -1;
|
2011-10-24 18:09:03 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 18:09:03 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
void RenderingRuleSearchRequest::setBooleanFilter(RenderingRuleProperty* p, bool filter) {
|
|
|
|
if (p != NULL) {
|
|
|
|
// assert p->input;
|
|
|
|
values[p->id] = filter ? TRUE_VALUE : FALSE_VALUE;
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
RenderingRulesStorageProperties* RenderingRuleSearchRequest::props() {
|
|
|
|
return PROPS;
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
bool RenderingRuleSearchRequest::searchRule(int state) {
|
|
|
|
return search(state, true);
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
bool RenderingRuleSearchRequest::search(int state, bool loadOutput) {
|
|
|
|
searchResult = false;
|
|
|
|
int tagKey = values[PROPS->R_TAG->id];
|
|
|
|
int valueKey = values[PROPS->R_VALUE->id];
|
|
|
|
bool result = searchInternal(state, tagKey, valueKey, loadOutput);
|
|
|
|
if (result) {
|
|
|
|
searchResult = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
result = searchInternal(state, tagKey, 0, loadOutput);
|
|
|
|
if (result) {
|
|
|
|
searchResult = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
result = searchInternal(state, 0, 0, loadOutput);
|
|
|
|
if (result) {
|
|
|
|
searchResult = true;
|
|
|
|
return true;
|
2011-10-23 22:59:36 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
bool RenderingRuleSearchRequest::searchInternal(int state, int tagKey, int valueKey, bool loadOutput) {
|
|
|
|
values[PROPS->R_TAG->id] = tagKey;
|
|
|
|
values[PROPS->R_VALUE->id] = valueKey;
|
|
|
|
RenderingRule* accept = storage->getRule(state, tagKey, valueKey);
|
|
|
|
if (accept == NULL) {
|
2011-10-24 13:43:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
bool match = visitRule(accept, loadOutput);
|
|
|
|
return match;
|
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
bool RenderingRuleSearchRequest::visitRule(RenderingRule* rule, bool loadOutput) {
|
|
|
|
std::vector<RenderingRuleProperty*> properties = rule->properties;
|
|
|
|
int propLen = rule->properties.size();
|
|
|
|
for (int i = 0; i < propLen; i++) {
|
|
|
|
RenderingRuleProperty* rp = properties[i];
|
|
|
|
if (rp != NULL && rp->input) {
|
|
|
|
bool match;
|
|
|
|
if (rp->isFloat()) {
|
|
|
|
match = rule->floatProperties[i] == fvalues[rp->id];
|
|
|
|
} else if (rp == PROPS->R_MINZOOM) {
|
|
|
|
match = rule->intProperties[i] <= values[rp->id];
|
|
|
|
} else if (rp == PROPS->R_MAXZOOM) {
|
|
|
|
match = rule->intProperties[i] >= values[rp->id];
|
2012-04-17 23:56:41 +02:00
|
|
|
} else if (rp == PROPS->R_ADDITIONAL) {
|
|
|
|
if(obj == NULL){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
std::string val = storage->getDictionaryValue(rule->intProperties[i]);
|
|
|
|
int i = val.find('=');
|
|
|
|
if(i >= 0) {
|
|
|
|
return obj->containsAdditional(val.substr(0, i), val.substr(i+1));
|
|
|
|
}
|
|
|
|
return false;
|
2011-10-28 16:56:27 +02:00
|
|
|
} else {
|
|
|
|
match = rule->intProperties[i] == values[rp->id];
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
if (!match) {
|
|
|
|
return false;
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
|
|
|
if (!loadOutput) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// accept it
|
|
|
|
for (int i = 0; i < propLen; i++) {
|
|
|
|
RenderingRuleProperty* rp = properties[i];
|
|
|
|
if (rp != NULL && !rp->input) {
|
|
|
|
searchResult = true;
|
|
|
|
if (rp->isFloat()) {
|
|
|
|
fvalues[rp->id] = rule->floatProperties[i];
|
|
|
|
} else {
|
|
|
|
values[rp->id] = rule->intProperties[i];
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
|
|
|
size_t j;
|
|
|
|
for (j = 0; j < rule->ifElseChildren.size(); j++) {
|
|
|
|
bool match = visitRule(&rule->ifElseChildren.at(j), loadOutput);
|
|
|
|
if (match) {
|
|
|
|
break;
|
2011-10-24 13:43:31 +02:00
|
|
|
}
|
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
for (j = 0; j < rule->ifChildren.size(); j++) {
|
|
|
|
visitRule(&rule->ifChildren.at(j), loadOutput);
|
2011-10-23 22:59:36 +02:00
|
|
|
}
|
2011-10-28 16:56:27 +02:00
|
|
|
return true;
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
}
|
2011-10-24 13:43:31 +02:00
|
|
|
|
2011-10-28 16:56:27 +02:00
|
|
|
void RenderingRuleSearchRequest::clearState() {
|
2012-04-17 23:56:41 +02:00
|
|
|
obj = NULL;
|
2011-10-28 16:56:27 +02:00
|
|
|
memcpy(values, savedValues, storage->getPropertiesSize() * sizeof(int));
|
|
|
|
memcpy(fvalues, savedFvalues, storage->getPropertiesSize() * sizeof(float));
|
|
|
|
}
|
2011-10-23 22:59:36 +02:00
|
|
|
|
2012-04-17 23:56:41 +02:00
|
|
|
void RenderingRuleSearchRequest::setInitialTagValueZoom(std::string tag, std::string value, int zoom, MapDataObject* obj) {
|
2011-10-28 16:56:27 +02:00
|
|
|
clearState();
|
2012-04-17 23:56:41 +02:00
|
|
|
this->obj = obj;
|
2011-10-28 16:56:27 +02:00
|
|
|
setIntFilter(PROPS->R_MINZOOM, zoom);
|
|
|
|
setIntFilter(PROPS->R_MAXZOOM, zoom);
|
|
|
|
setStringFilter(PROPS->R_TAG, tag);
|
|
|
|
setStringFilter(PROPS->R_VALUE, value);
|
|
|
|
}
|
2011-10-23 22:28:07 +02:00
|
|
|
|
2012-04-17 23:56:41 +02:00
|
|
|
void RenderingRuleSearchRequest::setTagValueZoomLayer(std::string tag, std::string val, int zoom, int layer, MapDataObject* obj) {
|
|
|
|
this->obj = obj;
|
2011-10-28 16:56:27 +02:00
|
|
|
setIntFilter(PROPS->R_MINZOOM, zoom);
|
|
|
|
setIntFilter(PROPS->R_MAXZOOM, zoom);
|
|
|
|
setIntFilter(PROPS->R_LAYER, layer);
|
|
|
|
setStringFilter(PROPS->R_TAG, tag);
|
|
|
|
setStringFilter(PROPS->R_VALUE, val);
|
|
|
|
}
|
2011-10-23 22:28:07 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleSearchRequest* initSearchRequest(JNIEnv* env, jobject renderingRuleSearchRequest) {
|
|
|
|
return new RenderingRuleSearchRequest(env, renderingRuleSearchRequest);
|
2011-10-23 22:59:36 +02:00
|
|
|
}
|
2011-10-23 22:28:07 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
void loadJniRenderingRules(JNIEnv* env) {
|
|
|
|
RenderingRuleClass = findClass(env, "net/osmand/render/RenderingRule");
|
|
|
|
RenderingRule_properties = env->GetFieldID(RenderingRuleClass, "properties",
|
2011-10-28 16:56:27 +02:00
|
|
|
"[Lnet/osmand/render/RenderingRuleProperty;");
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRule_intProperties = env->GetFieldID(RenderingRuleClass, "intProperties", "[I");
|
|
|
|
RenderingRule_floatProperties = env->GetFieldID(RenderingRuleClass, "floatProperties", "[F");
|
|
|
|
RenderingRule_ifElseChildren = env->GetFieldID(RenderingRuleClass, "ifElseChildren", "Ljava/util/List;");
|
|
|
|
RenderingRule_ifChildren = env->GetFieldID(RenderingRuleClass, "ifChildren", "Ljava/util/List;");
|
2012-03-02 17:24:06 +01:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleStoragePropertiesClass = findClass(env, "net/osmand/render/RenderingRuleStorageProperties");
|
|
|
|
RenderingRuleStorageProperties_rules = env->GetFieldID(RenderingRuleStoragePropertiesClass, "rules",
|
2011-10-28 16:56:27 +02:00
|
|
|
"Ljava/util/List;");
|
2011-10-28 16:01:18 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRulePropertyClass = findClass(env, "net/osmand/render/RenderingRuleProperty");
|
|
|
|
RenderingRuleProperty_type = env->GetFieldID(RenderingRulePropertyClass, "type", "I");
|
|
|
|
RenderingRuleProperty_input = env->GetFieldID(RenderingRulePropertyClass, "input", "Z");
|
|
|
|
RenderingRuleProperty_attrName = env->GetFieldID(RenderingRulePropertyClass, "attrName",
|
2011-10-28 16:56:27 +02:00
|
|
|
"Ljava/lang/String;");
|
2011-10-28 16:01:18 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRulesStorageClass = findClass(env, "net/osmand/render/RenderingRulesStorage");
|
|
|
|
RenderingRulesStorageClass_dictionary = env->GetFieldID(RenderingRulesStorageClass, "dictionary",
|
2011-10-28 16:56:27 +02:00
|
|
|
"Ljava/util/List;");
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRulesStorage_PROPS = env->GetFieldID(RenderingRulesStorageClass, "PROPS",
|
2011-10-24 12:57:01 +02:00
|
|
|
"Lnet/osmand/render/RenderingRuleStorageProperties;");
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRulesStorage_getRules = env->GetMethodID(RenderingRulesStorageClass, "getRules",
|
2011-10-24 12:57:01 +02:00
|
|
|
"(I)[Lnet/osmand/render/RenderingRule;");
|
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
ListClass = findClass(env, "java/util/List");
|
|
|
|
List_size = env->GetMethodID(ListClass, "size", "()I");
|
|
|
|
List_get = env->GetMethodID(ListClass, "get", "(I)Ljava/lang/Object;");
|
2011-10-23 22:28:07 +02:00
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleSearchRequestClass = findClass(env, "net/osmand/render/RenderingRuleSearchRequest");
|
|
|
|
RenderingRuleSearchRequest_storage = env->GetFieldID(RenderingRuleSearchRequestClass, "storage",
|
2011-10-28 16:56:27 +02:00
|
|
|
"Lnet/osmand/render/RenderingRulesStorage;");
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleSearchRequest_props = env->GetFieldID(RenderingRuleSearchRequestClass, "props",
|
2011-10-28 16:56:27 +02:00
|
|
|
"[Lnet/osmand/render/RenderingRuleProperty;");
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleSearchRequest_values = env->GetFieldID(RenderingRuleSearchRequestClass, "values", "[I");
|
|
|
|
RenderingRuleSearchRequest_fvalues = env->GetFieldID(RenderingRuleSearchRequestClass, "fvalues", "[F");
|
|
|
|
RenderingRuleSearchRequest_savedValues = env->GetFieldID(RenderingRuleSearchRequestClass, "savedValues",
|
2011-10-28 16:56:27 +02:00
|
|
|
"[I");
|
2012-04-28 14:22:56 +02:00
|
|
|
RenderingRuleSearchRequest_savedFvalues = env->GetFieldID(RenderingRuleSearchRequestClass, "savedFvalues",
|
2011-10-28 16:56:27 +02:00
|
|
|
"[F");
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-23 22:28:07 +02:00
|
|
|
}
|
|
|
|
|
2012-04-28 14:22:56 +02:00
|
|
|
void unloadJniRenderRules(JNIEnv* env) {
|
|
|
|
env->DeleteGlobalRef(RenderingRuleSearchRequestClass);
|
|
|
|
env->DeleteGlobalRef(RenderingRuleClass);
|
|
|
|
env->DeleteGlobalRef(RenderingRulePropertyClass);
|
|
|
|
env->DeleteGlobalRef(RenderingRuleStoragePropertiesClass);
|
|
|
|
env->DeleteGlobalRef(RenderingRulesStorageClass);
|
|
|
|
env->DeleteGlobalRef(ListClass);
|
2011-10-23 22:28:07 +02:00
|
|
|
|
|
|
|
}
|
2011-10-24 12:57:01 +02:00
|
|
|
|
2011-10-25 15:33:05 +02:00
|
|
|
#endif
|