1 /*************************************************************************** 2 * 3 * Copyright 2012 BMW Car IT GmbH 4 * 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 ****************************************************************************/ 19 20 #ifndef __LMCONTROL_H__ 21 #define __LMCONTROL_H__ 22 23 #include <map> 24 using std::map; 25 26 #include <vector> 27 using std::vector; 28 29 #include <set> 30 using std::set; 31 32 #include <string> 33 using std::string; 34 35 #include "ilm_common.h" 36 37 /* 38 * Datastructure that contains all information about a scene 39 */ 40 struct t_scene_data 41 { 42 map<t_ilm_display, vector<t_ilm_layer> > screenLayers; 43 map<t_ilm_layer, vector<t_ilm_surface> > layerSurfaces; 44 45 map<t_ilm_surface, ilmSurfaceProperties> surfaceProperties; 46 map<t_ilm_layer, ilmLayerProperties> layerProperties; 47 48 map<t_ilm_layer, t_ilm_display> layerScreen; 49 map<t_ilm_surface, t_ilm_layer> surfaceLayer; 50 51 vector<t_ilm_surface> surfaces; 52 vector<t_ilm_surface> layers; 53 vector<t_ilm_display> screens; 54 55 t_ilm_layer extraLayer; 56 t_ilm_uint screenWidth; 57 t_ilm_uint screenHeight; 58 }; 59 60 /* 61 * Vector of four integers <x y z w> 62 */ 63 struct tuple4 64 { 65 public: 66 int x; 67 int y; 68 int z; 69 int w; 70 tuple4tuple471 tuple4(int _x, int _y, int _z, int _w) : 72 x(_x), y(_y), z(_z), w(_w) 73 { 74 } 75 tuple4tuple476 tuple4() : 77 x(0), y(0), z(0), w(0) 78 { 79 } 80 tuple4tuple481 tuple4(const tuple4& other) 82 { 83 x = other.x; 84 y = other.y; 85 z = other.z; 86 w = other.w; 87 } 88 scaletuple489 void scale(float s) 90 { 91 x = static_cast<int>(x * s); 92 y = static_cast<int>(y * s); 93 z = static_cast<int>(z * s); 94 w = static_cast<int>(w * s); 95 } 96 97 const tuple4& operator=(const tuple4& other) 98 { 99 x = other.x; 100 y = other.y; 101 z = other.z; 102 w = other.w; 103 return *this; 104 } 105 }; 106 107 108 109 //============================================================================= 110 //common.cpp 111 //============================================================================= 112 /* 113 * Captures all information about the rendered scene into an object of type t_scene_data 114 */ 115 void captureSceneData(t_scene_data* pScene); 116 117 /* 118 * Calculates the final coordinates of a surface on the screen in the scene 119 */ 120 tuple4 getSurfaceScreenCoordinates(t_scene_data* pScene, t_ilm_surface surface); 121 122 /* 123 * Gets render order of surfaces in a scene. A surface is execluded from the render order 124 * if it does not belong to a layer or if it belongs to a layer that does not belong to a screen 125 * 126 * The surface at index 0 is the deepest surface in the scene, and surface at size()-1 is 127 * the topmost surface 128 */ 129 vector<t_ilm_surface> getSceneRenderOrder(t_scene_data* pScene); 130 131 //============================================================================= 132 //util.cpp 133 //============================================================================= 134 135 /* 136 * Returns true if the rectangle A is inside (or typical with) rectangle B 137 * (each tuple represents a rectangle in 2-D coordinates as <x1 y1 x2 y2>) 138 */ 139 t_ilm_bool inside(tuple4 A, tuple4 B); 140 141 /* 142 * Returns true if a is in the interval between b1 and b2 (inclusive) 143 */ 144 t_ilm_bool between(int b1, int a, int b2); 145 146 147 /* 148 * Returns true if the rectangle A intersects (or touches) rectangle B 149 * (each tuple represents a rectangle in 2-D coordinates as <x1 y1 x2 y2>) 150 */ 151 t_ilm_bool intersect(tuple4 A, tuple4 B); 152 153 /* 154 * Trim white space characters from the beginning of the string 155 */ 156 string rtrim(string s); 157 158 /* 159 * Replace all occurances of a in s by b 160 */ 161 string replaceAll(string s, string a, string b); 162 string replaceAll(string s, char a, char b); 163 164 /* 165 * For every pair (a,b) in the map: replace all occurances of a in the string by b 166 */ 167 string replaceAll(string s, map<string, string> replacements); 168 169 /* 170 * Split the string using the giving delimiter 171 */ 172 set<string> split(string s, char d); 173 174 175 //============================================================================= 176 //print.cpp 177 //============================================================================= 178 179 /* 180 * Functions for printing arrays, vector and maps 181 */ 182 void printArray(const char* text, unsigned int* array, int count); 183 184 template<typename T> 185 void printArray(const char* text, T* array, int count); 186 187 template<typename T> 188 void printVector(const char* text, vector<T> v); 189 190 template<typename K, typename V> 191 void printMap(const char* text, std::map<K, V> m); 192 193 /* 194 * Prints information about the specified screen 195 */ 196 void printScreenProperties(unsigned int screenid, const char* prefix = ""); 197 198 /* 199 * Prints information about the specified layer 200 */ 201 void printLayerProperties(unsigned int layerid, const char* prefix = ""); 202 203 /* 204 * Prints information about the specified surface 205 */ 206 void printSurfaceProperties(unsigned int surfaceid, const char* prefix = ""); 207 208 /* 209 * Prints information about rendered scene 210 * (All screens, all rendered layers, all rendered surfaces) 211 */ 212 void printScene(); 213 214 215 //============================================================================= 216 //control.cpp 217 //============================================================================= 218 void testNotificationLayer(t_ilm_layer layerid); 219 void watchLayer(unsigned int* layerids, unsigned int layeridCount); 220 void watchSurface(unsigned int* surfaceids, unsigned int surfaceidCount); 221 222 223 //============================================================================= 224 //analyze.cpp 225 //============================================================================= 226 227 /* 228 * Runs and prints the results for a set of analysis procedures to check if there are any potential problems that 229 * might lead to the surface being not rendered or not visible 230 */ 231 t_ilm_bool analyzeSurface(t_ilm_surface targetSurfaceId); 232 233 /* 234 * Returns a scattered version of the scene 235 */ 236 t_scene_data getScatteredScene(t_scene_data* pInitialScene); 237 238 //============================================================================= 239 //sceneio.cpp 240 //============================================================================= 241 242 /* 243 * Saves a representation of the current rendered scene to a file 244 */ 245 void exportSceneToFile(string filename); 246 247 /* 248 * Saves an xtext representation of the grammar of the scene 249 */ 250 void exportXtext(string fileName, string grammar, string url); 251 252 #endif 253