OsmAnd
jni/osmand/renderRules.h
Go to the documentation of this file.
00001 #ifndef _OSMAND_RENDER_RULES_H
00002 #define _OSMAND_RENDER_RULES_H
00003 
00004 #include <jni.h>
00005 #include <string>
00006 
00007 class RenderingRuleProperty
00008 {
00009 public:
00010         int type;
00011         bool input;
00012         std::string attrName;
00013         // order in
00014         int id;
00015         RenderingRuleProperty(int type, bool input, std::string& name, int id) :
00016                         type(type), input(input), attrName(name), id(id) {
00017         }
00018 
00019         bool isFloat() {
00020                 return type == FLOAT_TYPE;
00021         }
00022 
00023 
00024 private:
00025         const static int INT_TYPE = 1;
00026         const static int FLOAT_TYPE = 2;
00027         const static int STRING_TYPE = 3;
00028         const static int COLOR_TYPE = 4;
00029         const static int BOOLEAN_TYPE = 5;
00030 
00031 };
00032 
00033 const static int TRUE_VALUE = 1;
00034 const static int FALSE_VALUE = 0;
00035 
00036 
00037 class RenderingRule
00038 {
00039 public:
00040         std::vector<RenderingRuleProperty*> properties;
00041         std::vector<int> intProperties;
00042         std::vector<float> floatProperties;
00043         std::vector<RenderingRule> ifElseChildren;
00044         std::vector<RenderingRule> ifChildren;
00045 
00046 };
00047 
00048 
00049 class RenderingRulesStorage
00050 {
00051 private:
00052         const static int SHIFT_TAG_VAL = 16;
00053         const static int SIZE_STATES = 7;
00054         std::hash_map<std::string, int> dictionaryMap;
00055         std::vector<std::string> dictionary;
00056         std::hash_map<int, RenderingRule>* tagValueGlobalRules;
00057         std::vector<RenderingRuleProperty> properties;
00058         std::hash_map<std::string,  RenderingRuleProperty*> propertyMap;
00059 
00060 
00061         RenderingRule* createRenderingRule(jobject rRule);
00062         void initDictionary();
00063         void initProperties();
00064         void initRules();
00065 
00066 public:
00067         // No rules for multipolygon !!!
00068         const static int MULTI_POLYGON_TYPE = 0;
00069 
00070     const static int POINT_RULES = 1;
00071     const static int LINE_RULES = 2;
00072     const static int POLYGON_RULES = 3;
00073     const static int TEXT_RULES = 4;
00074     const static int ORDER_RULES = 5;
00075         RenderingRulesStorage(jobject storage) :
00076                         javaStorage(storage) {
00077                 tagValueGlobalRules = new std::hash_map<int, RenderingRule >[SIZE_STATES];
00078                 initDictionary();
00079                 initProperties();
00080                 initRules();
00081         }
00082 
00083         ~RenderingRulesStorage() {
00084                 delete[] tagValueGlobalRules;
00085                 // proper
00086         }
00087         jobject javaStorage;
00088 
00089         int getPropertiesSize();
00090 
00091         RenderingRuleProperty* getProperty(int i);
00092 
00093         RenderingRule* getRule(int state, int itag, int ivalue);
00094 
00095         RenderingRuleProperty* getProperty(const char* st);
00096 
00097         std::string getDictionaryValue(int i);
00098 
00099         int getDictionaryValue(std::string s);
00100 
00101 };
00102 
00103 class RenderingRulesStorageProperties
00104 {
00105 public:
00106         RenderingRuleProperty* R_TEXT_LENGTH;
00107         RenderingRuleProperty* R_REF;
00108         RenderingRuleProperty* R_TEXT_SHIELD;
00109         RenderingRuleProperty* R_SHADOW_RADIUS;
00110         RenderingRuleProperty* R_SHADOW_COLOR;
00111         RenderingRuleProperty* R_SHADER;
00112         RenderingRuleProperty* R_CAP_3;
00113         RenderingRuleProperty* R_CAP_2;
00114         RenderingRuleProperty* R_CAP;
00115         RenderingRuleProperty* R_PATH_EFFECT_3;
00116         RenderingRuleProperty* R_PATH_EFFECT_2;
00117         RenderingRuleProperty* R_PATH_EFFECT;
00118         RenderingRuleProperty* R_STROKE_WIDTH_3;
00119         RenderingRuleProperty* R_STROKE_WIDTH_2;
00120         RenderingRuleProperty* R_STROKE_WIDTH;
00121         RenderingRuleProperty* R_COLOR_3;
00122         RenderingRuleProperty* R_COLOR;
00123         RenderingRuleProperty* R_COLOR_2;
00124         RenderingRuleProperty* R_TEXT_BOLD;
00125         RenderingRuleProperty* R_TEXT_ORDER;
00126         RenderingRuleProperty* R_TEXT_MIN_DISTANCE;
00127         RenderingRuleProperty* R_TEXT_ON_PATH;
00128         RenderingRuleProperty* R_ICON;
00129         RenderingRuleProperty* R_LAYER;
00130         RenderingRuleProperty* R_ORDER;
00131         RenderingRuleProperty* R_ORDER_TYPE;
00132         RenderingRuleProperty* R_TAG;
00133         RenderingRuleProperty* R_VALUE;
00134         RenderingRuleProperty* R_MINZOOM;
00135         RenderingRuleProperty* R_SHADOW_LEVEL;
00136         RenderingRuleProperty* R_MAXZOOM;
00137         RenderingRuleProperty* R_NIGHT_MODE;
00138         RenderingRuleProperty* R_TEXT_DY;
00139         RenderingRuleProperty* R_TEXT_SIZE;
00140         RenderingRuleProperty* R_TEXT_COLOR;
00141         RenderingRuleProperty* R_TEXT_HALO_RADIUS;
00142         RenderingRuleProperty* R_TEXT_WRAP_WIDTH;
00143 
00144         RenderingRulesStorageProperties(RenderingRulesStorage* storage)
00145         {
00146                 R_TEXT_LENGTH = storage->getProperty("textLength");
00147                 R_REF = storage->getProperty("ref");
00148                 R_TEXT_SHIELD = storage->getProperty("textShield");
00149                 R_SHADOW_RADIUS = storage->getProperty("shadowRadius");
00150                 R_SHADOW_COLOR = storage->getProperty("shadowColor");
00151                 R_SHADER = storage->getProperty("shader");
00152                 R_CAP_3 = storage->getProperty("cap_3");
00153                 R_CAP_2 = storage->getProperty("cap_2");
00154                 R_CAP = storage->getProperty("cap");
00155                 R_PATH_EFFECT_3 = storage->getProperty("pathEffect_3");
00156                 R_PATH_EFFECT_2 = storage->getProperty("pathEffect_2");
00157                 R_PATH_EFFECT = storage->getProperty("pathEffect");
00158                 R_STROKE_WIDTH_3 = storage->getProperty("strokeWidth_3");
00159                 R_STROKE_WIDTH_2 = storage->getProperty("strokeWidth_2");
00160                 R_STROKE_WIDTH = storage->getProperty("strokeWidth");
00161                 R_COLOR_3 = storage->getProperty("color_3");
00162                 R_COLOR = storage->getProperty("color");
00163                 R_COLOR_2 = storage->getProperty("color_2");
00164                 R_TEXT_BOLD = storage->getProperty("textBold");
00165                 R_TEXT_ORDER = storage->getProperty("textOrder");
00166                 R_TEXT_MIN_DISTANCE = storage->getProperty("textMinDistance");
00167                 R_TEXT_ON_PATH = storage->getProperty("textOnPath");
00168                 R_ICON = storage->getProperty("icon");
00169                 R_LAYER = storage->getProperty("layer");
00170                 R_ORDER = storage->getProperty("order");
00171                 R_ORDER_TYPE = storage->getProperty("orderType");
00172                 R_TAG = storage->getProperty("tag");
00173                 R_VALUE = storage->getProperty("value");
00174                 R_MINZOOM = storage->getProperty("minzoom");
00175                 R_MAXZOOM = storage->getProperty("maxzoom");
00176                 R_NIGHT_MODE = storage->getProperty("nightMode");
00177                 R_TEXT_DY = storage->getProperty("textDy");
00178                 R_TEXT_SIZE = storage->getProperty("textSize");
00179                 R_TEXT_COLOR = storage->getProperty("textColor");
00180                 R_TEXT_HALO_RADIUS = storage->getProperty("textHaloRadius");
00181                 R_TEXT_WRAP_WIDTH = storage->getProperty("textWrapWidth");
00182                 R_SHADOW_LEVEL = storage->getProperty("shadowLevel");
00183 
00184         }
00185 
00186 };
00187 
00188 
00189 class RenderingRuleSearchRequest
00190 {
00191 private :
00192         jobject renderingRuleSearch;
00193         RenderingRulesStorage* storage;
00194         RenderingRulesStorageProperties* PROPS;
00195         int* values;
00196         float* fvalues;
00197         int* savedValues;
00198         float* savedFvalues;
00199         bool searchResult;
00200 
00201         bool searchInternal(int state, int tagKey, int valueKey, bool loadOutput);
00202         void initObject(jobject rrs);
00203         bool visitRule(RenderingRule* rule, bool loadOutput);
00204 public:
00205         RenderingRuleSearchRequest(jobject rrs);
00206 
00207         ~RenderingRuleSearchRequest();
00208 
00209         int getIntPropertyValue(RenderingRuleProperty* prop);
00210 
00211         int getIntPropertyValue(RenderingRuleProperty* prop, int def);
00212 
00213         std::string getStringPropertyValue(RenderingRuleProperty* prop);
00214 
00215         float getFloatPropertyValue(RenderingRuleProperty* prop);
00216 
00217         void setStringFilter(RenderingRuleProperty* p, std::string filter);
00218 
00219         void setIntFilter(RenderingRuleProperty* p, int filter);
00220 
00221         void clearIntvalue(RenderingRuleProperty* p);
00222 
00223         void setBooleanFilter(RenderingRuleProperty* p, bool filter);
00224 
00225         RenderingRulesStorageProperties* props();
00226 
00227         bool searchRule(int state);
00228 
00229         bool search(int state, bool loadOutput);
00230 
00231         void clearState();
00232 
00233         void setInitialTagValueZoom(std::string tag, std::string value, int zoom);
00234 
00235         void setTagValueZoomLayer(std::string tag, std::string val, int zoom, int layer);
00236 
00237 };
00238 
00239 
00240 RenderingRuleSearchRequest* initSearchRequest(jobject renderingRuleSearchRequest);
00241 
00242 void loadJNIRenderingRules();
00243 
00244 void unloadJniRenderRules();
00245 
00246 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines