Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_style_parser 5 #define tools_sg_style_parser 6 7 #include "senum" 8 #include "strings" 9 #include "style_colormap" 10 11 #include "../mathf" 12 #include "../lina/vec3f" 13 #include "../sout" 14 #include "../colorfs" 15 #include "../get_lines" 16 17 namespace tools { 18 namespace sg { 19 20 class style_parser { 21 #ifdef TOOLS_MEM 22 TOOLS_SCLASS(tools::sg::style_parser) 23 #endif 24 public: 25 style_parser() 26 :m_color(0,0,0) 27 ,m_highlight_color(0,0,0) 28 ,m_back_color(1,1,1) 29 ,m_width(1) 30 ,m_line_width(1) 31 ,m_marker_size(1) 32 ,m_point_size(1) 33 ,m_font_size(10) 34 ,m_font_modeling(font_filled) 35 ,m_pattern(line_solid) 36 ,m_line_pattern(line_solid) 37 ,m_marker_style(marker_dot) 38 ,m_area_style(area_solid) 39 ,m_modeling(modeling_boxes()) 40 ,m_light_model(light_model_phong()) 41 ,m_tick_modeling(tick_modeling_hippo()) 42 ,m_encoding(encoding_none()) 43 ,m_smoothing(false) 44 ,m_hinting(false) 45 ,m_cut() 46 ,m_painting(painting_uniform) 47 ,m_hatching(hatching_none) 48 ,m_projection(projection_none) 49 ,m_font("default") 50 ,m_multi_node_limit(no_limit()) 51 ,m_divisions(510) //Same as CERN-ROOT/TAttAx 52 ,m_rotation_steps(24) //Same as SbPolyhedron 53 ,m_back_shadow(0) 54 ,m_spacing(0.05F) 55 ,m_angle(fpi()/4.0F) 56 ,m_scale(1) 57 ,m_offset(0) 58 ,m_strip_width(0) 59 ,m_visible(true) 60 ,m_bar_offset(0.25F) 61 ,m_bar_width(0.5F) 62 ,m_editable(false) 63 ,m_automated(true) 64 ,m_options() 65 ,m_color_mapping() 66 ,m_enforced(false) 67 ,m_translation(0,0,0) 68 ,m_front_face(winding_ccw) 69 ,m_hjust(left) 70 ,m_vjust(bottom) 71 ,m_coloring() 72 ,m_title() 73 ,m_pickable(false) 74 { 75 #ifdef TOOLS_MEM 76 mem::increment(s_class().c_str()); 77 #endif 78 } 79 80 virtual ~style_parser(){ 81 #ifdef TOOLS_MEM 82 mem::decrement(s_class().c_str()); 83 #endif 84 } 85 public: 86 style_parser(const style_parser& a_from) 87 :m_color(a_from.m_color) 88 ,m_highlight_color(a_from.m_highlight_color) 89 ,m_back_color(a_from.m_back_color) 90 ,m_width(a_from.m_width) 91 ,m_line_width(a_from.m_line_width) 92 ,m_marker_size(a_from.m_marker_size) 93 ,m_point_size(a_from.m_point_size) 94 ,m_font_size(a_from.m_font_size) 95 ,m_font_modeling(a_from.m_font_modeling) 96 ,m_pattern(a_from.m_pattern) 97 ,m_line_pattern(a_from.m_line_pattern) 98 ,m_marker_style(a_from.m_marker_style) 99 ,m_area_style(a_from.m_area_style) 100 ,m_modeling (a_from.m_modeling ) 101 ,m_light_model(a_from.m_light_model) 102 ,m_tick_modeling(a_from.m_tick_modeling) 103 ,m_encoding(a_from.m_encoding) 104 ,m_smoothing(a_from.m_smoothing) 105 ,m_hinting(a_from.m_hinting) 106 ,m_cut(a_from.m_cut) 107 ,m_painting(a_from.m_painting) 108 ,m_hatching(a_from.m_hatching) 109 ,m_projection(a_from.m_projection) 110 ,m_font(a_from.m_font) 111 ,m_multi_node_limit(a_from.m_multi_node_limi 112 ,m_divisions(a_from.m_divisions) 113 ,m_rotation_steps(a_from.m_rotation_steps) 114 ,m_back_shadow(a_from.m_back_shadow) 115 ,m_spacing(a_from.m_spacing) 116 ,m_angle(a_from.m_angle) 117 ,m_scale(a_from.m_scale) 118 ,m_offset(a_from.m_offset) 119 ,m_strip_width(a_from.m_strip_width) 120 ,m_visible(a_from.m_visible) 121 ,m_bar_offset(a_from.m_bar_offset) 122 ,m_bar_width(a_from.m_bar_width) 123 ,m_editable(a_from.m_editable) 124 ,m_automated(a_from.m_automated) 125 ,m_options(a_from.m_options) 126 ,m_color_mapping(a_from.m_color_mapping) 127 ,m_enforced(a_from.m_enforced) 128 ,m_translation(a_from.m_translation) 129 ,m_front_face(a_from.m_front_face) 130 ,m_hjust(a_from.m_hjust) 131 ,m_vjust(a_from.m_vjust) 132 ,m_coloring(a_from.m_coloring) 133 ,m_title(a_from.m_title) 134 ,m_pickable(a_from.m_pickable) 135 { 136 #ifdef TOOLS_MEM 137 mem::increment(s_class().c_str()); 138 #endif 139 } 140 141 style_parser& operator=(const style_parser& 142 copy(a_from); 143 return *this; 144 } 145 public: 146 static int no_limit() {return (-1);} 147 public: 148 void copy(const style_parser& a_from){ 149 m_color = a_from.m_color; 150 m_highlight_color = a_from.m_highlight_col 151 m_back_color = a_from.m_back_color; 152 m_width = a_from.m_width; 153 m_line_width = a_from.m_line_width; 154 m_marker_size = a_from.m_marker_size; 155 m_point_size = a_from.m_point_size; 156 m_font_size = a_from.m_font_size; 157 m_font_modeling = a_from.m_font_modeling; 158 m_pattern = a_from.m_pattern; 159 m_line_pattern = a_from.m_line_pattern; 160 m_marker_style = a_from.m_marker_style; 161 m_area_style = a_from.m_area_style; 162 m_modeling = a_from.m_modeling; 163 m_light_model = a_from.m_light_model; 164 m_tick_modeling = a_from.m_tick_modeling; 165 m_encoding = a_from.m_encoding; 166 m_smoothing = a_from.m_smoothing; 167 m_hinting = a_from.m_hinting; 168 m_cut = a_from.m_cut; 169 m_painting = a_from.m_painting; 170 m_hatching = a_from.m_hatching; 171 m_projection = a_from.m_projection; 172 m_font = a_from.m_font; 173 m_multi_node_limit = a_from.m_multi_node_l 174 m_divisions = a_from.m_divisions; 175 m_rotation_steps = a_from.m_rotation_steps 176 m_back_shadow = a_from.m_back_shadow; 177 m_spacing = a_from.m_spacing; 178 m_angle = a_from.m_angle; 179 m_scale = a_from.m_scale; 180 m_offset = a_from.m_offset; 181 m_strip_width = a_from.m_strip_width; 182 m_visible = a_from.m_visible; 183 m_bar_offset = a_from.m_bar_offset; 184 m_bar_width = a_from.m_bar_width; 185 m_editable = a_from.m_editable; 186 m_automated = a_from.m_automated; 187 m_options = a_from.m_options; 188 m_color_mapping = a_from.m_color_mapping; 189 m_enforced = a_from.m_enforced; 190 m_translation = a_from.m_translation; 191 m_front_face = a_from.m_front_face; 192 m_hjust = a_from.m_hjust; 193 m_vjust = a_from.m_vjust; 194 m_coloring = a_from.m_coloring; 195 m_title = a_from.m_title; 196 m_pickable = a_from.m_pickable; 197 } 198 199 bool equal(const style_parser& a_from){ 200 if(m_width!=a_from.m_width) return false; 201 if(m_line_width!=a_from.m_line_width) retu 202 if(m_marker_size!=a_from.m_marker_size) re 203 if(m_point_size!=a_from.m_point_size) retu 204 if(m_font_size!=a_from.m_font_size) return 205 if(m_font_modeling!=a_from.m_font_modeling 206 if(m_pattern!=a_from.m_pattern) return fal 207 if(m_line_pattern!=a_from.m_line_pattern) 208 if(m_marker_style!=a_from.m_marker_style) 209 if(m_area_style!=a_from.m_area_style) retu 210 if(m_smoothing!=a_from.m_smoothing) return 211 if(m_hinting!=a_from.m_hinting) return fal 212 if(m_painting!=a_from.m_painting) return f 213 if(m_hatching!=a_from.m_hatching) return f 214 if(m_projection!=a_from.m_projection) retu 215 if(m_multi_node_limit!=a_from.m_multi_node 216 if(m_divisions!=a_from.m_divisions) return 217 if(m_rotation_steps!=a_from.m_rotation_ste 218 if(m_back_shadow!=a_from.m_back_shadow) re 219 if(m_spacing!=a_from.m_spacing) return fal 220 if(m_angle!=a_from.m_angle) return false; 221 if(m_scale!=a_from.m_scale) return false; 222 if(m_offset!=a_from.m_offset) return false 223 if(m_strip_width!=a_from.m_strip_width) re 224 if(m_visible!=a_from.m_visible) return fal 225 if(m_bar_offset!=a_from.m_bar_offset) retu 226 if(m_bar_width!=a_from.m_bar_width) return 227 if(m_editable!=a_from.m_editable) return f 228 if(m_automated!=a_from.m_automated) return 229 if(m_enforced!=a_from.m_enforced) return f 230 231 //color 232 if(m_color!=a_from.m_color) return false; 233 if(m_highlight_color!=a_from.m_highlight_c 234 if(m_back_color!=a_from.m_back_color) retu 235 236 //std::string 237 if(m_modeling!=a_from.m_modeling) return f 238 if(m_light_model!=a_from.m_light_model) re 239 if(m_tick_modeling!=a_from.m_tick_modeling 240 if(m_encoding!=a_from.m_encoding) return f 241 if(m_cut!=a_from.m_cut) return false; 242 if(m_font!=a_from.m_font) return false; 243 if(m_options!=a_from.m_options) return fal 244 if(m_color_mapping!=a_from.m_color_mapping 245 246 if(m_translation!=a_from.m_translation) re 247 248 if(m_front_face!=a_from.m_front_face) retu 249 250 if(m_hjust!=a_from.m_hjust) return false; 251 if(m_vjust!=a_from.m_vjust) return false; 252 253 if(m_coloring!=a_from.m_coloring) return f 254 if(m_title!=a_from.m_title) return false; 255 if(m_pickable!=a_from.m_pickable) return f 256 257 return true; 258 } 259 260 virtual void reset(){ //virtual because of S 261 m_color = colorf_black(); 262 m_highlight_color = colorf_lightgrey(); 263 m_back_color = colorf_white(); 264 m_width = 1; 265 m_line_width = 1; 266 m_marker_size = 1; 267 m_point_size = 1; 268 m_font_size = 10; 269 m_font_modeling = font_filled; 270 m_pattern = line_solid; 271 m_line_pattern = line_solid; 272 m_marker_style = marker_dot; 273 m_area_style = area_solid; 274 m_modeling = modeling_boxes(); 275 m_light_model = light_model_phong(); 276 m_tick_modeling = tick_modeling_hippo(); 277 m_encoding = encoding_none(); 278 m_smoothing = false; 279 m_hinting = false; 280 m_cut = ""; 281 m_painting = painting_uniform; 282 m_hatching = hatching_none; 283 m_projection = projection_none; 284 m_font = "default"; 285 m_multi_node_limit = no_limit(); 286 m_back_shadow = 0; 287 m_divisions = 510; 288 m_rotation_steps = 24; 289 m_spacing = 0.05F; 290 m_angle = fpi()/4; 291 m_scale = 1; 292 m_offset = 0; 293 m_strip_width = 0; 294 m_visible = true; 295 m_bar_offset = 0.25F; 296 m_bar_width = 0.5F; 297 m_editable = false; 298 m_automated = true; 299 m_options = ""; 300 m_color_mapping = ""; 301 m_enforced = false; 302 m_translation = vec3f(0,0,0); 303 m_front_face = winding_ccw; 304 m_hjust = left; 305 m_vjust = bottom; 306 m_coloring = ""; 307 m_title = ""; 308 m_pickable = false; 309 } 310 311 std::string tos() const{ 312 char ss[40 * 32]; 313 snpf(ss,sizeof(ss), 314 "color %g %g %g\n\ 315 highlight_color %g %g %g\n\ 316 back_color %g %g %g\n\ 317 width %g\n\ 318 line_width %g\n\ 319 marker_size %g\n\ 320 point_size %g\n\ 321 font_size %g\n\ 322 pattern %x\n\ 323 line_pattern %x\n\ 324 multi_node_limit %d\n\ 325 back_shadow %g\n\ 326 divisions %d\n\ 327 rotation_steps %d\n\ 328 angle %g\n\ 329 scale %g\n\ 330 offset %g\n\ 331 strip_width %g\n\ 332 spacing %g\n\ 333 bar_offset %g\n\ 334 bar_width %g\n\ 335 translation %g %g %g" 336 ,m_color[0],m_color[1],m_color[2] 337 ,m_highlight_color[0],m_highlight_color[1] 338 ,m_back_color[0],m_back_color[1],m_back_co 339 ,m_width 340 ,m_line_width 341 ,m_marker_size 342 ,m_point_size 343 ,m_font_size 344 ,m_pattern 345 ,m_line_pattern 346 ,m_multi_node_limit 347 ,m_back_shadow 348 ,m_divisions 349 ,m_rotation_steps 350 ,m_angle 351 ,m_scale 352 ,m_offset 353 ,m_strip_width 354 ,m_spacing 355 ,m_bar_offset 356 ,m_bar_width 357 ,m_translation[0],m_translation[1],m_trans 358 359 std::string lf("\n"); 360 std::string _s(ss); 361 362 _s += lf; 363 _s += "smoothing "; 364 _s += (m_smoothing?"true":"false"); 365 366 _s += lf; 367 _s += "hinting "; 368 _s += (m_hinting?"true":"false"); 369 370 _s += lf; 371 _s += "enforced "; 372 _s += (m_enforced?"true":"false"); 373 374 _s += lf; 375 _s += "visible "; 376 _s += (m_visible?"true":"false"); 377 378 _s += lf; 379 _s += "editable "; 380 _s += (m_editable?"true":"false"); 381 382 _s += lf; 383 _s += "automated "; 384 _s += (m_automated?"true":"false"); 385 386 _s += lf; 387 _s += "pickable "; 388 _s += (m_pickable?"true":"false"); 389 390 _s += lf; 391 _s += "marker_style "; 392 _s += smarker_style(m_marker_style); 393 394 _s += lf; 395 _s += "area_style "; 396 _s += sarea_style(m_area_style); 397 398 _s += lf; 399 _s += "modeling "; 400 _s += m_modeling; 401 402 _s += lf; 403 _s += "coloring "; 404 _s += m_coloring; 405 406 _s += lf; 407 _s += "title "; 408 _s += m_title; 409 410 _s += lf; 411 _s += "light_model "; 412 _s += m_light_model; 413 414 _s += lf; 415 _s += "tick_modeling "; 416 _s += m_tick_modeling; 417 418 _s += lf; 419 _s += "encoding "; 420 _s += m_encoding; 421 422 _s += lf; 423 _s += "cut "; 424 _s += m_cut; 425 426 _s += lf; 427 _s += "painting "; 428 _s += spainting_policy(m_painting); 429 430 _s += lf; 431 _s += "hatching "; 432 _s += shatching_policy(m_hatching); 433 434 _s += lf; 435 _s += "projection "; 436 _s += sprojection_type(m_projection); 437 438 _s += lf; 439 _s += "font "; 440 _s += m_font; 441 442 if(m_font_modeling==font_outline) { 443 _s += lf; 444 _s += "font_modeling "; 445 _s += s_font_outline(); 446 } else if(m_font_modeling==font_filled) { 447 _s += lf; 448 _s += "font_modeling "; 449 _s += s_font_filled(); 450 } else if(m_font_modeling==font_pixmap) { 451 _s += lf; 452 _s += "font_modeling "; 453 _s += s_font_pixmap(); 454 } 455 456 _s += lf; 457 _s += "options "; 458 _s += m_options; 459 460 _s += lf; 461 _s += "color_mapping "; 462 _s += m_color_mapping; 463 464 _s += lf; 465 _s += "front_face "; 466 _s += (m_front_face==winding_ccw?"ccw":"cw 467 468 _s += lf; 469 _s += "hjust "; 470 _s += shjust(m_hjust); 471 472 _s += lf; 473 _s += "vjust "; 474 _s += svjust(m_vjust); 475 476 return _s; 477 } 478 479 void color(const colorf& a_v){m_color = a_v; 480 colorf color() const {return m_color;} 481 482 void highlight_color(const colorf& a_v){m_hi 483 colorf highlight_color() const {return m_hig 484 485 void back_color(const colorf& a_v){m_back_co 486 colorf back_color() const {return m_back_col 487 488 void width(float a_v){m_width = a_v;} 489 float width() const {return m_width;} 490 491 void line_width(float a_v){m_line_width = a_ 492 float line_width() const {return m_line_widt 493 494 float back_shadow() const {return m_back_sha 495 void back_shadow(float a_v) {m_back_shadow = 496 497 void marker_style(sg::marker_style a_v){m_ma 498 sg::marker_style marker_style() const {retur 499 500 void marker_size(float a_v){m_marker_size = 501 float marker_size() const {return m_marker_s 502 503 void point_size(float a_v){m_point_size = a_ 504 float point_size() const {return m_point_siz 505 506 void font_size(float a_v){m_font_size = a_v; 507 float font_size() const {return m_font_size; 508 509 void font_modeling(sg::font_modeling a_v){m_ 510 sg::font_modeling font_modeling() const {ret 511 512 void area_style(sg::area_style a_v){m_area_s 513 sg::area_style area_style() const {return m_ 514 515 void modeling(const std::string& a_v){m_mode 516 const std::string& modeling() const {return 517 518 void light_model(const std::string& a_v){m_l 519 const std::string& light_model() const {retu 520 521 void tick_modeling(const std::string& a_v){m 522 const std::string& tick_modeling() const {re 523 524 void encoding(const std::string& a_v){m_enco 525 const std::string& encoding() const {return 526 527 void smoothing(bool a_v){m_smoothing = a_v;} 528 bool smoothing() const {return m_smoothing;} 529 530 void hinting(bool a_v){m_hinting = a_v;} 531 bool hinting() const {return m_hinting;} 532 533 sg::painting_policy painting() const {return 534 void painting(sg::painting_policy a_v){m_pai 535 536 sg::hatching_policy hatching() const {return 537 void hatching(sg::hatching_policy a_v) {m_ha 538 539 sg::projection_type projection() const {retu 540 void projection(sg::projection_type a_v){m_p 541 542 void pattern(lpat a_v){m_pattern = a_v;} 543 lpat pattern() const {return m_pattern;} 544 545 void line_pattern(lpat a_v){m_line_pattern = 546 lpat line_pattern() const {return m_line_pat 547 548 void font(const std::string& a_v){m_font = a 549 const std::string& font() const {return m_fo 550 551 void divisions(int a_v){m_divisions = a_v;} 552 int divisions() const {return m_divisions;} 553 554 void rotation_steps(unsigned int a_v){m_rota 555 unsigned int rotation_steps() const {return 556 557 void offset(float a_v){m_offset = a_v;} 558 float offset() const {return m_offset;} 559 560 void strip_width(float a_v){m_strip_width = 561 float strip_width() const {return m_strip_wi 562 563 void angle(float a_v){m_angle = a_v;} 564 float angle() const {return m_angle;} 565 566 void scale(float a_v){m_scale = a_v;} 567 float scale() const {return m_scale;} 568 569 void bar_offset(float a_v){m_bar_offset = a_ 570 float bar_offset() const {return m_bar_offse 571 572 void bar_width(float a_v){m_bar_width = a_v; 573 float bar_width() const {return m_bar_width; 574 575 void multi_node_limit(int a_v){m_multi_node_ 576 int multi_node_limit() const {return m_multi 577 578 void spacing(float a_v){m_spacing = a_v;} 579 float spacing() const {return m_spacing;} 580 581 void visible(bool a_v){m_visible = a_v;} 582 bool visible() const{return m_visible;} 583 584 void editable(bool a_v){m_editable = a_v;} 585 bool editable() const{return m_editable;} 586 587 void automated(bool a_v){m_automated = a_v;} 588 bool automated() const{return m_automated;} 589 590 void cut(const std::string& a_v){m_cut = a_v 591 const std::string& cut() const {return m_cut 592 593 void options(const std::string& a_v){m_optio 594 const std::string& options() const{return m_ 595 596 void color_mapping(const std::string& a_v){m 597 const std::string& color_mapping() const{ret 598 599 void enforced(bool a_v){m_enforced = a_v;} 600 bool enforced() const{return m_enforced;} 601 602 void translation(const vec3f& a_v){m_transla 603 vec3f translation() const {return m_translat 604 605 void front_face(winding_type a_v){m_front_fa 606 winding_type front_face() const {return m_fr 607 608 void hjust(sg::hjust a_v){m_hjust = a_v;} 609 sg::hjust hjust() const {return m_hjust;} 610 611 void vjust(sg::vjust a_v){m_vjust = a_v;} 612 sg::vjust vjust() const {return m_vjust;} 613 614 void coloring(const std::string& a_v){m_colo 615 const std::string& coloring() const {return 616 617 void title(const std::string& a_v){m_title 618 const std::string& title() const {return m_t 619 620 void pickable(bool a_v){m_pickable = a_v;} 621 bool pickable() const {return m_pickable;} 622 623 public: 624 bool parse(std::ostream& a_out,const cmaps_t 625 // a_s = list of "name value" separated by 626 //::printf("debug : style_parser::parse : 627 std::vector<std::string> lines; 628 get_lines(a_s,lines); 629 630 tools_vforcit(std::string,lines,it) { 631 const std::string& line = *it; 632 if(line.empty()) continue; 633 if(line=="reset") { 634 reset(); 635 continue; 636 } 637 std::vector<std::string> ws; 638 words(line," ",false,ws); 639 size_t wordn = ws.size(); 640 if(!wordn) { 641 a_out << "style_parser::parse :" 642 << " in " << sout(a_s) 643 << " : " << sout(line) 644 << " has a bad word count (at le 645 << std::endl; 646 return false; 647 } 648 const std::string& word0 = ws[0]; 649 if(word0=="color") { 650 if(wordn==2) { 651 const std::string& word1 = ws[1]; 652 if(!find_color(a_cmaps,word1,m_color 653 a_out << "style_parser::parse :" 654 << " in " << sout(a_s) 655 << " : " << sout(word1) 656 << " not a color." 657 << std::endl; 658 return false; 659 } 660 } else if (wordn==4) { 661 const std::string& rs = ws[1]; 662 float r; 663 if(!to<float>(rs,r)) { 664 a_out << "style_parser::parse :" 665 << " in " << sout(a_s) 666 << " : " << sout(rs) 667 << " not a number." 668 << std::endl; 669 return false; 670 } 671 const std::string& gs = ws[2]; 672 float g; 673 if(!to<float>(gs,g)) { 674 a_out << "style_parser::parse :" 675 << " in " << sout(a_s) 676 << " : " << sout(gs) 677 << " not a number." 678 << std::endl; 679 return false; 680 } 681 const std::string& bs = ws[3]; 682 float b; 683 if(!to<float>(bs,b)) { 684 a_out << "style_parser::parse :" 685 << " in " << sout(a_s) 686 << " : " << sout(bs) 687 << " not a number." 688 << std::endl; 689 return false; 690 } 691 m_color.set_value(r,g,b,1); 692 693 } else if (wordn==5) { 694 const std::string& rs = ws[1]; 695 float r; 696 if(!to<float>(rs,r)) { 697 a_out << "style_parser::parse :" 698 << " in " << sout(a_s) 699 << " : " << sout(rs) 700 << " not a number." 701 << std::endl; 702 return false; 703 } 704 const std::string& gs = ws[2]; 705 float g; 706 if(!to<float>(gs,g)) { 707 a_out << "style_parser::parse :" 708 << " in " << sout(a_s) 709 << " : " << sout(gs) 710 << " not a number." 711 << std::endl; 712 return false; 713 } 714 const std::string& bs = ws[3]; 715 float b; 716 if(!to<float>(bs,b)) { 717 a_out << "style_parser::parse :" 718 << " in " << sout(a_s) 719 << " : " << sout(bs) 720 << " not a number." 721 << std::endl; 722 return false; 723 } 724 const std::string& as = ws[4]; 725 float a; 726 if(!to<float>(as,a)) { 727 a_out << "style_parser::parse :" 728 << " in " << sout(a_s) 729 << " : " << sout(as) 730 << " not a number." 731 << std::endl; 732 return false; 733 } 734 m_color.set_value(r,g,b,a); 735 736 } else { 737 a_out << "style_parser::parse :" 738 << " in " << sout(a_s) 739 << " : " << sout(line) 740 << " has a bad word count (two 741 << std::endl; 742 return false; 743 } 744 745 } else if(word0=="highlight_color") { 746 if(wordn==2) { 747 const std::string& word1 = ws[1]; 748 if(!find_color(a_cmaps,word1,m_highl 749 a_out << "style_parser::parse :" 750 << " in " << sout(a_s) 751 << " : " << sout(word1) 752 << " not a color." 753 << std::endl; 754 return false; 755 } 756 } else if (wordn==4) { 757 const std::string& rs = ws[1]; 758 float r; 759 if(!to<float>(rs,r)) { 760 a_out << "style_parser::parse :" 761 << " in " << sout(a_s) 762 << " : " << sout(rs) 763 << " not a number." 764 << std::endl; 765 return false; 766 } 767 const std::string& gs = ws[2]; 768 float g; 769 if(!to<float>(gs,g)) { 770 a_out << "style_parser::parse :" 771 << " in " << sout(a_s) 772 << " : " << sout(gs) 773 << " not a number." 774 << std::endl; 775 return false; 776 } 777 const std::string& bs = ws[3]; 778 float b; 779 if(!to<float>(bs,b)) { 780 a_out << "style_parser::parse :" 781 << " in " << sout(a_s) 782 << " : " << sout(bs) 783 << " not a number." 784 << std::endl; 785 return false; 786 } 787 m_highlight_color.set_value(r,g,b,1) 788 789 } else if (wordn==5) { 790 const std::string& rs = ws[1]; 791 float r; 792 if(!to<float>(rs,r)) { 793 a_out << "style_parser::parse :" 794 << " in " << sout(a_s) 795 << " : " << sout(rs) 796 << " not a number." 797 << std::endl; 798 return false; 799 } 800 const std::string& gs = ws[2]; 801 float g; 802 if(!to<float>(gs,g)) { 803 a_out << "style_parser::parse :" 804 << " in " << sout(a_s) 805 << " : " << sout(gs) 806 << " not a number." 807 << std::endl; 808 return false; 809 } 810 const std::string& bs = ws[3]; 811 float b; 812 if(!to<float>(bs,b)) { 813 a_out << "style_parser::parse :" 814 << " in " << sout(a_s) 815 << " : " << sout(bs) 816 << " not a number." 817 << std::endl; 818 return false; 819 } 820 const std::string& as = ws[4]; 821 float a; 822 if(!to<float>(as,a)) { 823 a_out << "style_parser::parse :" 824 << " in " << sout(a_s) 825 << " : " << sout(as) 826 << " not a number." 827 << std::endl; 828 return false; 829 } 830 m_highlight_color.set_value(r,g,b,a) 831 832 } else { 833 a_out << "style_parser::parse :" 834 << " in " << sout(a_s) 835 << " : " << sout(line) 836 << " has a bad word count (two 837 << std::endl; 838 return false; 839 } 840 841 } else if(word0=="back_color") { 842 if(wordn==2) { 843 const std::string& word1 = ws[1]; 844 if(!find_color(a_cmaps,word1,m_back_ 845 a_out << "style_parser::parse :" 846 << " in " << sout(a_s) 847 << " : " << sout(word1) 848 << " not a color." 849 << std::endl; 850 return false; 851 } 852 } else if (wordn==4) { 853 const std::string& rs = ws[1]; 854 float r; 855 if(!to<float>(rs,r)) { 856 a_out << "style_parser::parse :" 857 << " in " << sout(a_s) 858 << " : " << sout(rs) 859 << " not a number." 860 << std::endl; 861 return false; 862 } 863 const std::string& gs = ws[2]; 864 float g; 865 if(!to<float>(gs,g)) { 866 a_out << "style_parser::parse :" 867 << " in " << sout(a_s) 868 << " : " << sout(gs) 869 << " not a number." 870 << std::endl; 871 return false; 872 } 873 const std::string& bs = ws[3]; 874 float b; 875 if(!to<float>(bs,b)) { 876 a_out << "style_parser::parse :" 877 << " in " << sout(a_s) 878 << " : " << sout(bs) 879 << " not a number." 880 << std::endl; 881 return false; 882 } 883 m_back_color.set_value(r,g,b,1); 884 885 } else if (wordn==5) { 886 const std::string& rs = ws[1]; 887 float r; 888 if(!to<float>(rs,r)) { 889 a_out << "style_parser::parse :" 890 << " in " << sout(a_s) 891 << " : " << sout(rs) 892 << " not a number." 893 << std::endl; 894 return false; 895 } 896 const std::string& gs = ws[2]; 897 float g; 898 if(!to<float>(gs,g)) { 899 a_out << "style_parser::parse :" 900 << " in " << sout(a_s) 901 << " : " << sout(gs) 902 << " not a number." 903 << std::endl; 904 return false; 905 } 906 const std::string& bs = ws[3]; 907 float b; 908 if(!to<float>(bs,b)) { 909 a_out << "style_parser::parse :" 910 << " in " << sout(a_s) 911 << " : " << sout(bs) 912 << " not a number." 913 << std::endl; 914 return false; 915 } 916 const std::string& as = ws[4]; 917 float a; 918 if(!to<float>(as,a)) { 919 a_out << "style_parser::parse :" 920 << " in " << sout(a_s) 921 << " : " << sout(as) 922 << " not a number." 923 << std::endl; 924 return false; 925 } 926 m_back_color.set_value(r,g,b,a); 927 928 } else { 929 a_out << "style_parser::parse :" 930 << " in " << sout(a_s) 931 << " : " << sout(line) 932 << " has a bad word count (two 933 << std::endl; 934 return false; 935 } 936 937 } else if(word0=="pattern") { 938 if(!check_2(wordn,a_s,line,a_out)) ret 939 const std::string& word1 = ws[1]; 940 unsigned long ul; 941 if(!sline_pattern(word1,m_pattern)) { 942 if(!to_ulong(word1,ul)) { 943 a_out << "style_parser::parse :" 944 << " in " << sout(a_s) 945 << " : " << sout(word1) 946 << " not a line pattern." 947 << std::endl; 948 return false; 949 } 950 m_pattern = (lpat)ul; 951 } 952 953 } else if(word0=="line_pattern") { 954 if(!check_2(wordn,a_s,line,a_out)) ret 955 const std::string& word1 = ws[1]; 956 unsigned long ul; 957 if(!sline_pattern(word1,m_line_pattern 958 if(!to_ulong(word1,ul)) { 959 a_out << "style_parser::parse :" 960 << " in " << sout(a_s) 961 << " : " << sout(word1) 962 << " not a line pattern." 963 << std::endl; 964 return false; 965 } 966 m_line_pattern = (lpat)ul; 967 } 968 } else if(word0=="marker_style") { 969 if(!check_2(wordn,a_s,line,a_out)) ret 970 const std::string& word1 = ws[1]; 971 if(!smarker_style(word1,m_marker_style 972 a_out << "style_parser::parse :" 973 << " in " << sout(a_s) 974 << " : " << sout(word1) 975 << " not a marker_style." 976 << std::endl; 977 return false; 978 } 979 } else if(word0=="area_style") { 980 if(!check_2(wordn,a_s,line,a_out)) ret 981 const std::string& word1 = ws[1]; 982 if(!sarea_style(word1,m_area_style)) { 983 a_out << "style_parser::parse :" 984 << " in " << sout(a_s) 985 << " : " << sout(word1) 986 << " not a area_style." 987 << std::endl; 988 return false; 989 } 990 } else if(word0=="modeling") { 991 if(!check_2(wordn,a_s,line,a_out)) ret 992 m_modeling = ws[1]; 993 } else if(word0=="light_model") { 994 if(!check_2(wordn,a_s,line,a_out)) ret 995 m_light_model = ws[1]; 996 } else if(word0=="tick_modeling") { 997 if(!check_2(wordn,a_s,line,a_out)) ret 998 m_tick_modeling = ws[1]; 999 } else if(word0=="encoding") { 1000 if(!check_2(wordn,a_s,line,a_out)) re 1001 m_encoding = ws[1]; 1002 } else if(word0=="smoothing") { 1003 if(!check_2(wordn,a_s,line,a_out)) re 1004 bool value; 1005 if(!check_bool(ws[1],a_s,a_out,value) 1006 m_smoothing = value; 1007 } else if(word0=="hinting") { 1008 if(!check_2(wordn,a_s,line,a_out)) re 1009 bool value; 1010 if(!check_bool(ws[1],a_s,a_out,value) 1011 m_hinting = value; 1012 } else if(word0=="enforced") { 1013 if(!check_2(wordn,a_s,line,a_out)) re 1014 bool value; 1015 if(!check_bool(ws[1],a_s,a_out,value) 1016 m_enforced = value; 1017 } else if(word0=="cut") { 1018 m_cut = ""; 1019 for(unsigned int wordi=1;wordi<wordn; 1020 if(wordi!=1) m_cut += " "; 1021 m_cut += ws[wordi]; 1022 } 1023 } else if(word0=="options") { 1024 m_options = ""; 1025 for(unsigned int wordi=1;wordi<wordn; 1026 if(wordi!=1) m_options += " "; 1027 m_options += ws[wordi]; 1028 } 1029 } else if(word0=="color_mapping") { 1030 m_color_mapping = ""; 1031 for(unsigned int wordi=1;wordi<wordn; 1032 if(wordi!=1) m_color_mapping += " " 1033 m_color_mapping += ws[wordi]; 1034 } 1035 } else if(word0=="painting") { 1036 if(!check_2(wordn,a_s,line,a_out)) re 1037 if(!spainting_policy(ws[1],m_painting 1038 a_out << "style_parser::parse :" 1039 << " in " << sout(a_s) 1040 << " : " << sout(ws[1]) 1041 << " not a painting_policy." 1042 << std::endl; 1043 return false; 1044 } 1045 } else if(word0=="hatching") { 1046 if(!check_2(wordn,a_s,line,a_out)) re 1047 if(!shatching_policy(ws[1],m_hatching 1048 a_out << "style_parser::parse :" 1049 << " in " << sout(a_s) 1050 << " : " << sout(ws[1]) 1051 << " not a hatching_policy." 1052 << std::endl; 1053 return false; 1054 } 1055 } else if(word0=="projection") { 1056 if(!check_2(wordn,a_s,line,a_out)) re 1057 if(!sprojection_type(ws[1],m_projecti 1058 a_out << "style_parser::parse :" 1059 << " in " << sout(a_s) 1060 << " : " << sout(ws[1]) 1061 << " not a projection_type." 1062 << std::endl; 1063 return false; 1064 } 1065 } else if(word0=="font") { 1066 if(!check_2(wordn,a_s,line,a_out)) re 1067 font(ws[1]); 1068 } else if(word0=="width") { 1069 if(!check_2(wordn,a_s,line,a_out)) re 1070 float value; 1071 if(!check_float(ws[1],a_s,a_out,value 1072 m_width = value; 1073 } else if(word0=="line_width") { 1074 if(!check_2(wordn,a_s,line,a_out)) re 1075 float value; 1076 if(!check_float(ws[1],a_s,a_out,value 1077 m_line_width = value; 1078 } else if(word0=="marker_size") { 1079 if(!check_2(wordn,a_s,line,a_out)) re 1080 float value; 1081 if(!check_float(ws[1],a_s,a_out,value 1082 m_marker_size = value; 1083 } else if(word0=="point_size") { 1084 if(!check_2(wordn,a_s,line,a_out)) re 1085 float value; 1086 if(!check_float(ws[1],a_s,a_out,value 1087 m_point_size = value; 1088 } else if(word0=="font_size") { 1089 if(!check_2(wordn,a_s,line,a_out)) re 1090 float value; 1091 if(!check_float(ws[1],a_s,a_out,value 1092 m_font_size = value; 1093 } else if(word0=="font_modeling") { 1094 if(!check_2(wordn,a_s,line,a_out)) re 1095 if(ws[1]==s_font_outline()) m_fo 1096 else if(ws[1]==s_font_filled()) m_fo 1097 else if(ws[1]==s_font_pixmap()) m_fo 1098 else { 1099 a_out << "style_parser::parse :" 1100 << " in " << sout(a_s) 1101 << " : " << sout(ws[1]) 1102 << " not a font_modeling." 1103 << std::endl; 1104 return false; 1105 } 1106 } else if(word0=="back_shadow") { 1107 if(!check_2(wordn,a_s,line,a_out)) re 1108 float value; 1109 if(!check_float(ws[1],a_s,a_out,value 1110 if(value<0.F) value = 0.F; 1111 m_back_shadow = value; 1112 } else if(word0=="multi_node_limit") { 1113 if(!check_2(wordn,a_s,line,a_out)) re 1114 int value = 0; 1115 if(!check_int(ws[1],a_s,a_out,value)) 1116 m_multi_node_limit = value; 1117 } else if(word0=="divisions") { 1118 if(!check_2(wordn,a_s,line,a_out)) re 1119 int value = 0; 1120 if(!check_int(ws[1],a_s,a_out,value)) 1121 m_divisions = value; 1122 } else if(word0=="rotation_steps") { 1123 if(!check_2(wordn,a_s,line,a_out)) re 1124 unsigned int value; 1125 if(!check_uint(ws[1],a_s,a_out,value) 1126 m_rotation_steps = value; 1127 } else if(word0=="angle") { 1128 if(!check_2(wordn,a_s,line,a_out)) re 1129 float value; 1130 if(!check_float(ws[1],a_s,a_out,value 1131 m_angle = value; 1132 } else if(word0=="scale") { 1133 if(!check_2(wordn,a_s,line,a_out)) re 1134 float value; 1135 if(!check_float(ws[1],a_s,a_out,value 1136 m_scale = value; 1137 } else if(word0=="offset") { 1138 if(!check_2(wordn,a_s,line,a_out)) re 1139 float value; 1140 if(!check_float(ws[1],a_s,a_out,value 1141 m_offset = value; 1142 } else if(word0=="strip_width") { 1143 if(!check_2(wordn,a_s,line,a_out)) re 1144 float value; 1145 if(!check_float(ws[1],a_s,a_out,value 1146 m_strip_width = value; 1147 } else if(word0=="spacing") { 1148 if(!check_2(wordn,a_s,line,a_out)) re 1149 float value; 1150 if(!check_float(ws[1],a_s,a_out,value 1151 m_spacing = value; 1152 } else if(word0=="visible") { 1153 if(!check_2(wordn,a_s,line,a_out)) re 1154 bool value; 1155 if(!check_bool(ws[1],a_s,a_out,value) 1156 m_visible = value; 1157 } else if(word0=="editable") { 1158 if(!check_2(wordn,a_s,line,a_out)) re 1159 bool value; 1160 if(!check_bool(ws[1],a_s,a_out,value) 1161 m_editable = value; 1162 } else if(word0=="pickable") { 1163 if(!check_2(wordn,a_s,line,a_out)) re 1164 bool value; 1165 if(!check_bool(ws[1],a_s,a_out,value) 1166 m_pickable = value; 1167 } else if(word0=="automated") { 1168 if(!check_2(wordn,a_s,line,a_out)) re 1169 bool value; 1170 if(!check_bool(ws[1],a_s,a_out,value) 1171 m_automated = value; 1172 } else if(word0=="bar_offset") { 1173 if(!check_2(wordn,a_s,line,a_out)) re 1174 float value; 1175 if(!check_float(ws[1],a_s,a_out,value 1176 m_bar_offset = value; 1177 } else if(word0=="bar_width") { 1178 if(!check_2(wordn,a_s,line,a_out)) re 1179 float value; 1180 if(!check_float(ws[1],a_s,a_out,value 1181 m_bar_width = value; 1182 1183 } else if(word0=="translation") { 1184 if (wordn==4) { 1185 const std::string& sx = ws[1]; 1186 float x; 1187 if(!to<float>(sx,x)) { 1188 a_out << "style_parser::parse :" 1189 << " in " << sout(a_s) 1190 << " : " << sout(sx) 1191 << " not a number." 1192 << std::endl; 1193 return false; 1194 } 1195 const std::string& sy = ws[2]; 1196 float y; 1197 if(!to<float>(sy,y)) { 1198 a_out << "style_parser::parse :" 1199 << " in " << sout(a_s) 1200 << " : " << sout(sy) 1201 << " not a number." 1202 << std::endl; 1203 return false; 1204 } 1205 const std::string& sz = ws[3]; 1206 float z; 1207 if(!to<float>(sz,z)) { 1208 a_out << "style_parser::parse :" 1209 << " in " << sout(a_s) 1210 << " : " << sout(sz) 1211 << " not a number." 1212 << std::endl; 1213 return false; 1214 } 1215 m_translation.set_value(x,y,z); 1216 } else { 1217 a_out << "style_parser::parse :" 1218 << " in " << sout(a_s) 1219 << " has a bad word count (fo 1220 << std::endl; 1221 return false; 1222 } 1223 1224 } else if(word0=="front_face") { 1225 if(!check_2(wordn,a_s,line,a_out)) re 1226 const std::string& word1 = ws[1]; 1227 if(word1=="ccw") { 1228 m_front_face = winding_ccw; 1229 } else if(word1=="cw") { 1230 m_front_face = winding_cw; 1231 } else { //ccw 1232 a_out << "style_parser::parse :" 1233 << " in " << sout(a_s) 1234 << " : " << sout(word1) 1235 << " not a winding type." 1236 << std::endl; 1237 return false; 1238 } 1239 1240 } else if(word0=="hjust") { 1241 if(!check_2(wordn,a_s,line,a_out)) re 1242 const std::string& word1 = ws[1]; 1243 if(!shjust(word1,m_hjust)) { 1244 a_out << "style_parser::parse :" 1245 << " in " << sout(a_s) 1246 << " : " << sout(word1) 1247 << " not a hjust." 1248 << std::endl; 1249 return false; 1250 } 1251 1252 } else if(word0=="vjust") { 1253 if(!check_2(wordn,a_s,line,a_out)) re 1254 const std::string& word1 = ws[1]; 1255 if(!svjust(word1,m_vjust)) { 1256 a_out << "style_parser::parse :" 1257 << " in " << sout(a_s) 1258 << " : " << sout(word1) 1259 << " not a vjust." 1260 << std::endl; 1261 return false; 1262 } 1263 1264 } else if(word0=="coloring") { 1265 if(!check_2(wordn,a_s,line,a_out)) re 1266 m_coloring = ws[1]; 1267 1268 } else if(word0=="title") { 1269 if(!check_2(wordn,a_s,line,a_out)) re 1270 m_title = ws[1]; 1271 1272 } else { 1273 a_out << "style_parser::parse :" 1274 << " in " << sout(a_s) 1275 << " : " << sout(word0) 1276 << " bad option." 1277 << std::endl; 1278 return false; 1279 } 1280 } 1281 return true; 1282 } 1283 1284 protected: 1285 static bool check_2(size_t a_n, 1286 const std::string& a_s, 1287 const std::string& a_li 1288 if(a_n!=2) { 1289 a_out << "style_parser::parse :" 1290 << " in " << sout(a_s) 1291 << " : " << sout(a_line) 1292 << " has a bad word count (two ex 1293 << std::endl; 1294 return false; 1295 } 1296 return true; 1297 } 1298 1299 static bool check_bool(const std::string& a 1300 const std::string& a 1301 if(!to(a_w,a_v)){ 1302 a_out << "style_parser::parse :" 1303 << " in " << sout(a_s) 1304 << " : " << sout(a_w) 1305 << " not a boolean." 1306 << std::endl; 1307 return false; 1308 } 1309 return true; 1310 } 1311 1312 static bool check_int(const std::string& a_ 1313 const std::string& a_ 1314 if(!to<int>(a_w,a_v)){ 1315 a_out << "style_parser::parse :" 1316 << " in " << sout(a_s) 1317 << " : " << sout(a_w) 1318 << " not an int." 1319 << std::endl; 1320 return false; 1321 } 1322 return true; 1323 } 1324 1325 static bool check_uint(const std::string& a 1326 const std::string& a_s,std::o 1327 if(!to<unsigned int>(a_w,a_v)){ 1328 a_out << "style_parser::parse :" 1329 << " in " << sout(a_s) 1330 << " : " << sout(a_w) 1331 << " not an unsigned int." 1332 << std::endl; 1333 return false; 1334 } 1335 return true; 1336 } 1337 1338 static bool check_float(const std::string& 1339 const std::string& a_s,std::o 1340 if(!to<float>(a_w,a_v)){ 1341 a_out << "style_parser::parse :" 1342 << " in " << sout(a_s) 1343 << " : " << sout(a_w) 1344 << " not a float." 1345 << std::endl; 1346 return false; 1347 } 1348 return true; 1349 } 1350 1351 protected: 1352 colorf m_color; 1353 colorf m_highlight_color; 1354 colorf m_back_color; 1355 float m_width; 1356 float m_line_width; 1357 float m_marker_size; 1358 float m_point_size; 1359 float m_font_size; 1360 sg::font_modeling m_font_modeling; 1361 lpat m_pattern; 1362 lpat m_line_pattern; 1363 sg::marker_style m_marker_style; 1364 sg::area_style m_area_style; 1365 std::string m_modeling; 1366 std::string m_light_model; 1367 std::string m_tick_modeling; 1368 std::string m_encoding; 1369 bool m_smoothing; 1370 bool m_hinting; 1371 std::string m_cut; 1372 sg::painting_policy m_painting; 1373 sg::hatching_policy m_hatching; 1374 sg::projection_type m_projection; 1375 std::string m_font; 1376 int m_multi_node_limit; //could be no_limit 1377 int m_divisions; 1378 unsigned int m_rotation_steps; 1379 float m_back_shadow; 1380 float m_spacing; 1381 float m_angle; 1382 float m_scale; 1383 float m_offset; 1384 float m_strip_width; 1385 bool m_visible; 1386 float m_bar_offset; 1387 float m_bar_width; 1388 bool m_editable; 1389 bool m_automated; 1390 std::string m_options; 1391 std::string m_color_mapping; 1392 bool m_enforced; 1393 vec3f m_translation; 1394 winding_type m_front_face; 1395 sg::hjust m_hjust; 1396 sg::vjust m_vjust; 1397 std::string m_coloring; 1398 std::string m_title; 1399 bool m_pickable; 1400 }; 1401 1402 }} 1403 1404 #endif