Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_sg_senum 4 #ifndef tools_sg_senum 5 #define tools_sg_senum 5 #define tools_sg_senum 6 6 7 #include "enums" 7 #include "enums" 8 #include "lpat" 8 #include "lpat" 9 9 10 #include <string> 10 #include <string> 11 #include <vector> 11 #include <vector> 12 12 13 namespace tools { 13 namespace tools { 14 namespace sg { 14 namespace sg { 15 15 16 typedef struct {char string[32];hjust value;} 16 typedef struct {char string[32];hjust value;} hjust_rec; 17 inline const hjust_rec* hjust_recs(unsigned in 17 inline const hjust_rec* hjust_recs(unsigned int& a_num){ 18 static const hjust_rec list[] = { //read onl 18 static const hjust_rec list[] = { //read only static, then ok. 19 {"left", left}, 19 {"left", left}, 20 {"center", center}, 20 {"center", center}, 21 {"right", right} 21 {"right", right} 22 }; 22 }; 23 a_num = sizeof(list)/sizeof(list[0]); 23 a_num = sizeof(list)/sizeof(list[0]); 24 return list; 24 return list; 25 } 25 } 26 inline bool shjust(const std::string& a_s,hjus 26 inline bool shjust(const std::string& a_s,hjust& a_v){ 27 unsigned int number; 27 unsigned int number; 28 const hjust_rec* list = hjust_recs(number); 28 const hjust_rec* list = hjust_recs(number); 29 for(unsigned int count=0;count<number;count+ 29 for(unsigned int count=0;count<number;count++) { 30 if(a_s==list[count].string) { 30 if(a_s==list[count].string) { 31 a_v = list[count].value; 31 a_v = list[count].value; 32 return true; 32 return true; 33 } 33 } 34 } 34 } 35 a_v = left; 35 a_v = left; 36 return false; 36 return false; 37 } 37 } 38 inline const char* shjust(hjust a_v){ 38 inline const char* shjust(hjust a_v){ 39 unsigned int number; 39 unsigned int number; 40 const hjust_rec* list = hjust_recs(number); 40 const hjust_rec* list = hjust_recs(number); 41 for(unsigned int count=0;count<number;count+ 41 for(unsigned int count=0;count<number;count++) { 42 if(a_v==list[count].value) return list[cou 42 if(a_v==list[count].value) return list[count].string; 43 } 43 } 44 return 0; 44 return 0; 45 } 45 } 46 46 47 typedef struct {char string[32];vjust value;} 47 typedef struct {char string[32];vjust value;} vjust_rec; 48 inline const vjust_rec* vjust_recs(unsigned in 48 inline const vjust_rec* vjust_recs(unsigned int& a_num){ 49 static const vjust_rec list[] = { //read onl 49 static const vjust_rec list[] = { //read only static, then ok. 50 {"bottom", bottom}, 50 {"bottom", bottom}, 51 {"middle", middle}, 51 {"middle", middle}, 52 {"top", top} 52 {"top", top} 53 }; 53 }; 54 a_num = sizeof(list)/sizeof(list[0]); 54 a_num = sizeof(list)/sizeof(list[0]); 55 return list; 55 return list; 56 } 56 } 57 inline bool svjust(const std::string& a_s,vjus 57 inline bool svjust(const std::string& a_s,vjust& a_v){ 58 unsigned int number; 58 unsigned int number; 59 const vjust_rec* list = vjust_recs(number); 59 const vjust_rec* list = vjust_recs(number); 60 for(unsigned int count=0;count<number;count+ 60 for(unsigned int count=0;count<number;count++) { 61 if(a_s==list[count].string) { 61 if(a_s==list[count].string) { 62 a_v = list[count].value; 62 a_v = list[count].value; 63 return true; 63 return true; 64 } 64 } 65 } 65 } 66 a_v = bottom; 66 a_v = bottom; 67 return false; 67 return false; 68 } 68 } 69 inline const char* svjust(vjust a_v){ 69 inline const char* svjust(vjust a_v){ 70 unsigned int number; 70 unsigned int number; 71 const vjust_rec* list = vjust_recs(number); 71 const vjust_rec* list = vjust_recs(number); 72 for(unsigned int count=0;count<number;count+ 72 for(unsigned int count=0;count<number;count++) { 73 if(a_v==list[count].value) return list[cou 73 if(a_v==list[count].value) return list[count].string; 74 } 74 } 75 return 0; 75 return 0; 76 } 76 } 77 77 78 typedef struct {char string[32];marker_style v 78 typedef struct {char string[32];marker_style value;} marker_style_rec; 79 inline const marker_style_rec* marker_style_re 79 inline const marker_style_rec* marker_style_recs(unsigned int& a_num){ 80 static const marker_style_rec list[] = { //r 80 static const marker_style_rec list[] = { //read only static, then ok. 81 {"dot", marker_dot}, 81 {"dot", marker_dot}, 82 {"plus", marker_plus}, 82 {"plus", marker_plus}, 83 {"asterisk", marker_asterisk}, 83 {"asterisk", marker_asterisk}, 84 {"cross", marker_cross}, 84 {"cross", marker_cross}, 85 {"star", marker_star}, 85 {"star", marker_star}, 86 {"circle_line", marker_circle_line 86 {"circle_line", marker_circle_line}, 87 {"circle_filled", marker_circle_fill 87 {"circle_filled", marker_circle_filled}, 88 {"triangle_up_line", marker_triangle_up 88 {"triangle_up_line", marker_triangle_up_line}, 89 {"triangle_up_filled", marker_triangle_up 89 {"triangle_up_filled", marker_triangle_up_filled}, 90 {"triangle_down_line", marker_triangle_do 90 {"triangle_down_line", marker_triangle_down_line}, 91 {"triangle_down_filled",marker_triangle_do 91 {"triangle_down_filled",marker_triangle_down_filled}, 92 {"david_star_line", marker_david_star_ 92 {"david_star_line", marker_david_star_line}, 93 {"david_star_filled", marker_david_star_ 93 {"david_star_filled", marker_david_star_filled}, 94 {"swiss_cross_line", marker_swiss_cross 94 {"swiss_cross_line", marker_swiss_cross_line}, 95 {"swiss_cross_filled", marker_swiss_cross 95 {"swiss_cross_filled", marker_swiss_cross_filled}, 96 {"diamond_line", marker_diamond_lin 96 {"diamond_line", marker_diamond_line}, 97 {"diamond_filled", marker_diamond_fil 97 {"diamond_filled", marker_diamond_filled}, 98 {"square_line", marker_square_line 98 {"square_line", marker_square_line}, 99 {"square_filled", marker_square_fill 99 {"square_filled", marker_square_filled}, 100 {"penta_star_line", marker_penta_star_ 100 {"penta_star_line", marker_penta_star_line}, 101 {"penta_star_filled", marker_penta_star_ 101 {"penta_star_filled", marker_penta_star_filled}, 102 {"minus", marker_minus} 102 {"minus", marker_minus} 103 }; 103 }; 104 a_num = sizeof(list)/sizeof(list[0]); 104 a_num = sizeof(list)/sizeof(list[0]); 105 return list; 105 return list; 106 } 106 } 107 inline bool smarker_style(const std::string& a 107 inline bool smarker_style(const std::string& a_s,marker_style& a_v){ 108 unsigned int number; 108 unsigned int number; 109 const marker_style_rec* list = marker_style_ 109 const marker_style_rec* list = marker_style_recs(number); 110 for(unsigned int count=0;count<number;count+ 110 for(unsigned int count=0;count<number;count++) { 111 if(a_s==list[count].string) { 111 if(a_s==list[count].string) { 112 a_v = list[count].value; 112 a_v = list[count].value; 113 return true; 113 return true; 114 } 114 } 115 } 115 } 116 a_v = marker_dot; 116 a_v = marker_dot; 117 return false; 117 return false; 118 } 118 } 119 inline const char* smarker_style(marker_style 119 inline const char* smarker_style(marker_style a_v){ 120 unsigned int number; 120 unsigned int number; 121 const marker_style_rec* list = marker_style_ 121 const marker_style_rec* list = marker_style_recs(number); 122 for(unsigned int count=0;count<number;count+ 122 for(unsigned int count=0;count<number;count++) { 123 if(a_v==list[count].value) return list[cou 123 if(a_v==list[count].value) return list[count].string; 124 } 124 } 125 return 0; 125 return 0; 126 } 126 } 127 inline void smarker_styles(std::vector<std::st 127 inline void smarker_styles(std::vector<std::string>& a_v){ 128 a_v.clear(); 128 a_v.clear(); 129 unsigned int number; 129 unsigned int number; 130 const marker_style_rec* list = marker_style_ 130 const marker_style_rec* list = marker_style_recs(number); 131 for(unsigned int count=0;count<number;count+ 131 for(unsigned int count=0;count<number;count++) { 132 a_v.push_back(list[count].string); 132 a_v.push_back(list[count].string); 133 } 133 } 134 } 134 } 135 135 136 typedef struct {char string[16];area_style val 136 typedef struct {char string[16];area_style value;} area_style_rec; 137 inline const area_style_rec* area_style_recsLi 137 inline const area_style_rec* area_style_recsList(unsigned int& a_num){ 138 static const area_style_rec list[] = { //rea 138 static const area_style_rec list[] = { //read only static, then ok. 139 {"solid", area_solid}, 139 {"solid", area_solid}, 140 {"hatched", area_hatched}, 140 {"hatched", area_hatched}, 141 {"checker", area_checker}, 141 {"checker", area_checker}, 142 {"edged", area_edged} 142 {"edged", area_edged} 143 }; 143 }; 144 a_num = sizeof(list)/sizeof(list[0]); 144 a_num = sizeof(list)/sizeof(list[0]); 145 return list; 145 return list; 146 } 146 } 147 inline bool sarea_style(const std::string& a_s 147 inline bool sarea_style(const std::string& a_s,area_style& a_v){ 148 unsigned int number; 148 unsigned int number; 149 const area_style_rec* list = area_style_recs 149 const area_style_rec* list = area_style_recsList(number); 150 for(unsigned int count=0;count<number;count+ 150 for(unsigned int count=0;count<number;count++) { 151 if(a_s==list[count].string) { 151 if(a_s==list[count].string) { 152 a_v = list[count].value; 152 a_v = list[count].value; 153 return true; 153 return true; 154 } 154 } 155 } 155 } 156 a_v = area_solid; 156 a_v = area_solid; 157 return false; 157 return false; 158 } 158 } 159 inline const char* sarea_style(area_style a_v) 159 inline const char* sarea_style(area_style a_v){ 160 unsigned int number; 160 unsigned int number; 161 const area_style_rec* list = area_style_recs 161 const area_style_rec* list = area_style_recsList(number); 162 for(unsigned int count=0;count<number;count+ 162 for(unsigned int count=0;count<number;count++) { 163 if(a_v==list[count].value) return list[cou 163 if(a_v==list[count].value) return list[count].string; 164 } 164 } 165 return 0; 165 return 0; 166 } 166 } 167 167 168 typedef struct {char string[20];painting_polic 168 typedef struct {char string[20];painting_policy value;} painting_policy_rec; 169 inline const painting_policy_rec* painting_pol 169 inline const painting_policy_rec* painting_policy_recsList(unsigned int& a_num){ 170 static const painting_policy_rec list[] = { 170 static const painting_policy_rec list[] = { //read only static, then ok. 171 {"uniform", painting_uniform}, 171 {"uniform", painting_uniform}, 172 {"by_value", painting_by_value}, 172 {"by_value", painting_by_value}, 173 {"by_level", painting_by_level}, 173 {"by_level", painting_by_level}, 174 {"grey_scale", painting_grey_scale}, 174 {"grey_scale", painting_grey_scale}, 175 {"violet_to_red",painting_violet_to_red}, 175 {"violet_to_red",painting_violet_to_red}, 176 {"grey_scale_inverse",painting_grey_scale_ 176 {"grey_scale_inverse",painting_grey_scale_inverse} 177 }; 177 }; 178 a_num = sizeof(list)/sizeof(list[0]); 178 a_num = sizeof(list)/sizeof(list[0]); 179 return list; 179 return list; 180 } 180 } 181 inline void spainting_policies(std::vector<std 181 inline void spainting_policies(std::vector<std::string>& a_v){ 182 a_v.clear(); 182 a_v.clear(); 183 unsigned int number; 183 unsigned int number; 184 const painting_policy_rec* list = painting_p 184 const painting_policy_rec* list = painting_policy_recsList(number); 185 for(unsigned int count=0;count<number;count+ 185 for(unsigned int count=0;count<number;count++) { 186 a_v.push_back(list[count].string); 186 a_v.push_back(list[count].string); 187 } 187 } 188 } 188 } 189 inline bool spainting_policy(const std::string 189 inline bool spainting_policy(const std::string& a_s,painting_policy& a_v){ 190 unsigned int number; 190 unsigned int number; 191 const painting_policy_rec* list = painting_p 191 const painting_policy_rec* list = painting_policy_recsList(number); 192 for(unsigned int count=0;count<number;count+ 192 for(unsigned int count=0;count<number;count++) { 193 if(a_s==list[count].string) { 193 if(a_s==list[count].string) { 194 a_v = list[count].value; 194 a_v = list[count].value; 195 return true; 195 return true; 196 } 196 } 197 } 197 } 198 a_v = painting_uniform; 198 a_v = painting_uniform; 199 return false; 199 return false; 200 } 200 } 201 inline const char* spainting_policy(painting_p 201 inline const char* spainting_policy(painting_policy a_v){ 202 unsigned int number; 202 unsigned int number; 203 const painting_policy_rec* list = painting_p 203 const painting_policy_rec* list = painting_policy_recsList(number); 204 for(unsigned int count=0;count<number;count+ 204 for(unsigned int count=0;count<number;count++) { 205 if(a_v==list[count].value) return list[cou 205 if(a_v==list[count].value) return list[count].string; 206 } 206 } 207 return 0; 207 return 0; 208 } 208 } 209 209 210 210 211 typedef struct {char string[16];hatching_polic 211 typedef struct {char string[16];hatching_policy value;} hatching_policy_rec; 212 inline const hatching_policy_rec* hatching_pol 212 inline const hatching_policy_rec* hatching_policy_recsList(unsigned int& a_num){ 213 static const hatching_policy_rec list[] = { 213 static const hatching_policy_rec list[] = { //read only static, then ok. 214 {"none", hatching_none}, 214 {"none", hatching_none}, 215 {"right", hatching_right}, 215 {"right", hatching_right}, 216 {"left", hatching_left}, 216 {"left", hatching_left}, 217 {"left_and_right", hatching_left_and_right 217 {"left_and_right", hatching_left_and_right} 218 }; 218 }; 219 a_num = sizeof(list)/sizeof(list[0]); 219 a_num = sizeof(list)/sizeof(list[0]); 220 return list; 220 return list; 221 } 221 } 222 inline bool shatching_policy(const std::string 222 inline bool shatching_policy(const std::string& a_s,hatching_policy& a_v){ 223 unsigned int number; 223 unsigned int number; 224 const hatching_policy_rec* list = hatching_p 224 const hatching_policy_rec* list = hatching_policy_recsList(number); 225 for(unsigned int count=0;count<number;count+ 225 for(unsigned int count=0;count<number;count++) { 226 if(a_s==list[count].string) { 226 if(a_s==list[count].string) { 227 a_v = list[count].value; 227 a_v = list[count].value; 228 return true; 228 return true; 229 } 229 } 230 } 230 } 231 a_v = hatching_none; 231 a_v = hatching_none; 232 return false; 232 return false; 233 } 233 } 234 inline const char* shatching_policy(hatching_p 234 inline const char* shatching_policy(hatching_policy a_v){ 235 unsigned int number; 235 unsigned int number; 236 const hatching_policy_rec* list = hatching_p 236 const hatching_policy_rec* list = hatching_policy_recsList(number); 237 for(unsigned int count=0;count<number;count+ 237 for(unsigned int count=0;count<number;count++) { 238 if(a_v==list[count].value) return list[cou 238 if(a_v==list[count].value) return list[count].string; 239 } 239 } 240 return 0; 240 return 0; 241 } 241 } 242 242 243 typedef struct {char string[16];projection_typ 243 typedef struct {char string[16];projection_type value;} projection_type_rec; 244 inline const projection_type_rec* projection_t 244 inline const projection_type_rec* projection_type_recsList(unsigned int& a_num){ 245 static const projection_type_rec list[] = { 245 static const projection_type_rec list[] = { //read only static, then ok. 246 {"none", projection_none}, 246 {"none", projection_none}, 247 {"rz", projection_rz}, 247 {"rz", projection_rz}, 248 {"phiz", projection_phiz}, 248 {"phiz", projection_phiz}, 249 {"zr", projection_zr}, 249 {"zr", projection_zr}, 250 {"zphi", projection_zphi} 250 {"zphi", projection_zphi} 251 }; 251 }; 252 a_num = sizeof(list)/sizeof(list[0]); 252 a_num = sizeof(list)/sizeof(list[0]); 253 return list; 253 return list; 254 } 254 } 255 inline bool sprojection_type(const std::string 255 inline bool sprojection_type(const std::string& a_s,projection_type& a_v){ 256 unsigned int number; 256 unsigned int number; 257 const projection_type_rec* list = projection 257 const projection_type_rec* list = projection_type_recsList(number); 258 for(unsigned int count=0;count<number;count+ 258 for(unsigned int count=0;count<number;count++) { 259 if(a_s==list[count].string) { 259 if(a_s==list[count].string) { 260 a_v = list[count].value; 260 a_v = list[count].value; 261 return true; 261 return true; 262 } 262 } 263 } 263 } 264 a_v = projection_none; 264 a_v = projection_none; 265 return false; 265 return false; 266 } 266 } 267 inline const char* sprojection_type(projection 267 inline const char* sprojection_type(projection_type a_v){ 268 unsigned int number; 268 unsigned int number; 269 const projection_type_rec* list = projection 269 const projection_type_rec* list = projection_type_recsList(number); 270 for(unsigned int count=0;count<number;count+ 270 for(unsigned int count=0;count<number;count++) { 271 if(a_v==list[count].value) return list[cou 271 if(a_v==list[count].value) return list[count].string; 272 } 272 } 273 return 0; 273 return 0; 274 } 274 } 275 275 276 inline bool sline_pattern(const std::string& a 276 inline bool sline_pattern(const std::string& a_s,lpat& aPattern){ 277 if(a_s=="solid") { 277 if(a_s=="solid") { 278 aPattern = line_solid; 278 aPattern = line_solid; 279 } else if(a_s=="dashed") { 279 } else if(a_s=="dashed") { 280 aPattern = line_dashed; 280 aPattern = line_dashed; 281 } else if(a_s=="dotted") { 281 } else if(a_s=="dotted") { 282 aPattern = line_dotted; 282 aPattern = line_dotted; 283 } else if(a_s=="dash_dotted") { 283 } else if(a_s=="dash_dotted") { 284 aPattern = line_dash_dotted; 284 aPattern = line_dash_dotted; 285 } else { 285 } else { 286 aPattern = line_solid; 286 aPattern = line_solid; 287 return false; 287 return false; 288 } 288 } 289 return true; 289 return true; 290 } 290 } 291 291 292 ////////////////////////////////////////////// 292 /////////////////////////////////////////////////////////////// 293 ////////////////////////////////////////////// 293 /////////////////////////////////////////////////////////////// 294 ////////////////////////////////////////////// 294 /////////////////////////////////////////////////////////////// 295 inline bool smove_type(const std::string& a_s, 295 inline bool smove_type(const std::string& a_s,move_type& a_move) { 296 if(a_s=="move_rotate_right") {a_move = move_ 296 if(a_s=="move_rotate_right") {a_move = move_rotate_right;return true;} 297 if(a_s=="move_rotate_left") {a_move = move_r 297 if(a_s=="move_rotate_left") {a_move = move_rotate_left;return true;} 298 if(a_s=="move_rotate_up") {a_move = move_rot 298 if(a_s=="move_rotate_up") {a_move = move_rotate_up;return true;} 299 if(a_s=="move_rotate_down") {a_move = move_r 299 if(a_s=="move_rotate_down") {a_move = move_rotate_down;return true;} 300 if(a_s=="move_roll_plus") {a_move = move_rol 300 if(a_s=="move_roll_plus") {a_move = move_roll_plus;return true;} 301 if(a_s=="move_roll_minus") {a_move = move_ro 301 if(a_s=="move_roll_minus") {a_move = move_roll_minus;return true;} 302 if(a_s=="move_translate_right") {a_move = mo 302 if(a_s=="move_translate_right") {a_move = move_translate_right;return true;} 303 if(a_s=="move_translate_left") {a_move = mov 303 if(a_s=="move_translate_left") {a_move = move_translate_left;return true;} 304 if(a_s=="move_up") {a_move = move_up;return 304 if(a_s=="move_up") {a_move = move_up;return true;} 305 if(a_s=="move_down") {a_move = move_down;ret 305 if(a_s=="move_down") {a_move = move_down;return true;} 306 if(a_s=="move_forward") {a_move = move_forwa 306 if(a_s=="move_forward") {a_move = move_forward;return true;} 307 if(a_s=="move_backward") {a_move = move_back 307 if(a_s=="move_backward") {a_move = move_backward;return true;} 308 if(a_s=="move_zoom_in") {a_move = move_zoom_ 308 if(a_s=="move_zoom_in") {a_move = move_zoom_in;return true;} 309 if(a_s=="move_zoom_out") {a_move = move_zoom 309 if(a_s=="move_zoom_out") {a_move = move_zoom_out;return true;} 310 if(a_s=="move_rotate_around_focal_right") {a 310 if(a_s=="move_rotate_around_focal_right") {a_move = move_rotate_around_focal_right;return true;} 311 if(a_s=="move_rotate_around_focal_left") {a_ 311 if(a_s=="move_rotate_around_focal_left") {a_move = move_rotate_around_focal_left;return true;} 312 if(a_s=="move_rotate_around_focal_up") {a_mo 312 if(a_s=="move_rotate_around_focal_up") {a_move = move_rotate_around_focal_up;return true;} 313 if(a_s=="move_rotate_around_focal_down") {a_ 313 if(a_s=="move_rotate_around_focal_down") {a_move = move_rotate_around_focal_down;return true;} 314 if(a_s=="move_roll_around_focal_plus") {a_mo 314 if(a_s=="move_roll_around_focal_plus") {a_move = move_roll_around_focal_plus;return true;} 315 if(a_s=="move_roll_around_focal_minus") {a_m 315 if(a_s=="move_roll_around_focal_minus") {a_move = move_roll_around_focal_minus;return true;} 316 if(a_s=="move_zoom_in_out") {a_move = move_z 316 if(a_s=="move_zoom_in_out") {a_move = move_zoom_in_out;return true;} 317 if(a_s=="move_zoom_in_out_rot") {a_move = mo 317 if(a_s=="move_zoom_in_out_rot") {a_move = move_zoom_in_out_rot;return true;} 318 if(a_s=="move_curve") {a_move = move_curve;r 318 if(a_s=="move_curve") {a_move = move_curve;return true;} 319 a_move = move_rotate_left; 319 a_move = move_rotate_left; 320 return false; 320 return false; 321 } 321 } 322 322 323 }} 323 }} 324 /* 324 /* 325 #include "../snpf" 325 #include "../snpf" 326 #include "../colorf" 326 #include "../colorf" 327 327 328 namespace tools { 328 namespace tools { 329 namespace sg { 329 namespace sg { 330 330 331 inline bool scolor(const colorf& a_col,std::st 331 inline bool scolor(const colorf& a_col,std::string& a_s){ 332 char _s[256]; << 332 char s[256]; 333 snpf(_s,sizeof(_s),"%g %g %g",a_col[0],a_col << 333 snpf(s,sizeof(s),"%g %g %g",a_col[0],a_col[1],a_col[2]); 334 a_s = _s; << 334 a_s = s; 335 return true; 335 return true; 336 } 336 } 337 337 338 }} 338 }} 339 */ 339 */ 340 340 341 #endif 341 #endif