inlib
1.2.0
|
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved. 00002 // See the file inlib.license for terms. 00003 00004 #ifndef inlib_sg_style_parser 00005 #define inlib_sg_style_parser 00006 00007 #include "styles" 00008 #include "enums" 00009 #include "style_colormap" 00010 00011 #include "../smanip" //words 00012 #include "../cstr" //for get_lines 00013 #include "../fmath" 00014 00015 #include <string> 00016 #include <cstdio> //::sscanf 00017 00018 namespace inlib { 00019 namespace sg { 00020 00021 class style_parser { 00022 public: 00023 style_parser() 00024 :m_color(0,0,0) 00025 ,m_highlight_color(0,0,0) 00026 ,m_back_color(1,1,1) 00027 ,m_line_width(1) 00028 ,m_marker_size(1) 00029 ,m_font_size(10) 00030 ,m_line_pattern(line_solid) 00031 ,m_marker_style(marker_dot) 00032 ,m_area_style(area_solid) 00033 ,m_modeling(modeling_boxes()) 00034 ,m_light_model(light_model_phong()) 00035 ,m_tick_modeling(tick_modeling_hippo()) 00036 ,m_encoding(encoding_none()) 00037 ,m_smoothing(false) 00038 ,m_hinting(false) 00039 ,m_cut("") 00040 ,m_painting(painting_uniform) 00041 ,m_hatching(hatching_none) 00042 ,m_projection(projection_none) 00043 ,m_font("default") 00044 ,m_multi_node_limit(no_limit()) 00045 ,m_divisions(510) //Same as ROOT/TAttAxis 00046 ,m_rotation_steps(24) //Same as SbPolyhedron default. 00047 ,m_transparency(0) 00048 ,m_back_transparency(0) 00049 ,m_back_shadow(0) 00050 ,m_spacing(0.05F) 00051 ,m_angle(fpi()/4.0F) 00052 ,m_scale(1) 00053 ,m_offset(0) 00054 ,m_strip_width(0) 00055 ,m_visible(true) 00056 ,m_bar_offset(0.25F) 00057 ,m_bar_width(0.5F) 00058 ,m_editable(false) 00059 ,m_automated(true) 00060 ,m_options("") 00061 ,m_color_mapping("") 00062 ,m_enforced(false) 00063 ,m_translation(0,0,0) 00064 ,m_front_face(winding_ccw) 00065 ,m_hjust(left) 00066 ,m_vjust(bottom) 00067 {} 00068 00069 virtual ~style_parser(){} 00070 public: 00071 style_parser(const style_parser& a_from) 00072 :m_color(a_from.m_color) 00073 ,m_highlight_color(a_from.m_highlight_color) 00074 ,m_back_color(a_from.m_back_color) 00075 ,m_line_width(a_from.m_line_width) 00076 ,m_marker_size(a_from.m_marker_size) 00077 ,m_font_size(a_from.m_font_size) 00078 ,m_line_pattern(a_from.m_line_pattern) 00079 ,m_marker_style(a_from.m_marker_style) 00080 ,m_area_style(a_from.m_area_style) 00081 ,m_modeling (a_from.m_modeling ) 00082 ,m_light_model(a_from.m_light_model) 00083 ,m_tick_modeling(a_from.m_tick_modeling) 00084 ,m_encoding(a_from.m_encoding) 00085 ,m_smoothing(a_from.m_smoothing) 00086 ,m_hinting(a_from.m_hinting) 00087 ,m_cut(a_from.m_cut) 00088 ,m_painting(a_from.m_painting) 00089 ,m_hatching(a_from.m_hatching) 00090 ,m_projection(a_from.m_projection) 00091 ,m_font(a_from.m_font) 00092 ,m_multi_node_limit(a_from.m_multi_node_limit) 00093 ,m_divisions(a_from.m_divisions) 00094 ,m_rotation_steps(a_from.m_rotation_steps) 00095 ,m_transparency(a_from.m_transparency) 00096 ,m_back_transparency(a_from.m_back_transparency) 00097 ,m_back_shadow(a_from.m_back_shadow) 00098 ,m_spacing(a_from.m_spacing) 00099 ,m_angle(a_from.m_angle) 00100 ,m_scale(a_from.m_scale) 00101 ,m_offset(a_from.m_offset) 00102 ,m_strip_width(a_from.m_strip_width) 00103 ,m_visible(a_from.m_visible) 00104 ,m_bar_offset(a_from.m_bar_offset) 00105 ,m_bar_width(a_from.m_bar_width) 00106 ,m_editable(a_from.m_editable) 00107 ,m_automated(a_from.m_automated) 00108 ,m_options(a_from.m_options) 00109 ,m_color_mapping(a_from.m_color_mapping) 00110 ,m_enforced(a_from.m_enforced) 00111 ,m_translation(a_from.m_translation) 00112 ,m_front_face(a_from.m_front_face) 00113 ,m_hjust(a_from.m_hjust) 00114 ,m_vjust(a_from.m_vjust) 00115 {} 00116 00117 style_parser& operator=(const style_parser& a_from){copy(a_from);return *this;} 00118 public: 00119 static int no_limit() {return (-1);} 00120 public: 00121 void copy(const style_parser& a_from){ 00122 m_color = a_from.m_color; 00123 m_highlight_color = a_from.m_highlight_color; 00124 m_back_color = a_from.m_back_color; 00125 m_line_width = a_from.m_line_width; 00126 m_marker_size = a_from.m_marker_size; 00127 m_font_size = a_from.m_font_size; 00128 m_line_pattern = a_from.m_line_pattern; 00129 m_marker_style = a_from.m_marker_style; 00130 m_area_style = a_from.m_area_style; 00131 m_modeling = a_from.m_modeling ; 00132 m_light_model = a_from.m_light_model; 00133 m_tick_modeling = a_from.m_tick_modeling; 00134 m_encoding = a_from.m_encoding; 00135 m_smoothing = a_from.m_smoothing; 00136 m_hinting = a_from.m_hinting; 00137 m_cut = a_from.m_cut; 00138 m_painting = a_from.m_painting; 00139 m_hatching = a_from.m_hatching; 00140 m_projection = a_from.m_projection; 00141 m_font = a_from.m_font; 00142 m_multi_node_limit = a_from.m_multi_node_limit; 00143 m_divisions = a_from.m_divisions; 00144 m_rotation_steps = a_from.m_rotation_steps; 00145 m_transparency = a_from.m_transparency; 00146 m_back_transparency = a_from.m_back_transparency; 00147 m_back_shadow = a_from.m_back_shadow; 00148 m_spacing = a_from.m_spacing; 00149 m_angle = a_from.m_angle; 00150 m_scale = a_from.m_scale; 00151 m_offset = a_from.m_offset; 00152 m_strip_width = a_from.m_strip_width; 00153 m_visible = a_from.m_visible; 00154 m_bar_offset = a_from.m_bar_offset; 00155 m_bar_width = a_from.m_bar_width; 00156 m_editable = a_from.m_editable; 00157 m_automated = a_from.m_automated; 00158 m_options = a_from.m_options; 00159 m_color_mapping = a_from.m_color_mapping; 00160 m_enforced = a_from.m_enforced; 00161 m_translation = a_from.m_translation; 00162 m_front_face = a_from.m_front_face; 00163 m_hjust = a_from.m_hjust; 00164 m_vjust = a_from.m_vjust; 00165 } 00166 00167 bool equal(const style_parser& a_from){ 00168 if(m_line_width!=a_from.m_line_width) return false; 00169 if(m_marker_size!=a_from.m_marker_size) return false; 00170 if(m_font_size!=a_from.m_font_size) return false; 00171 if(m_line_pattern!=a_from.m_line_pattern) return false; 00172 if(m_marker_style!=a_from.m_marker_style) return false; 00173 if(m_area_style!=a_from.m_area_style) return false; 00174 if(m_smoothing!=a_from.m_smoothing) return false; 00175 if(m_hinting!=a_from.m_hinting) return false; 00176 if(m_painting!=a_from.m_painting) return false; 00177 if(m_hatching!=a_from.m_hatching) return false; 00178 if(m_projection!=a_from.m_projection) return false; 00179 if(m_multi_node_limit!=a_from.m_multi_node_limit) return false; 00180 if(m_divisions!=a_from.m_divisions) return false; 00181 if(m_rotation_steps!=a_from.m_rotation_steps) return false; 00182 if(m_transparency!=a_from.m_transparency) return false; 00183 if(m_back_transparency!=a_from.m_back_transparency) return false; 00184 if(m_back_shadow!=a_from.m_back_shadow) return false; 00185 if(m_spacing!=a_from.m_spacing) return false; 00186 if(m_angle!=a_from.m_angle) return false; 00187 if(m_scale!=a_from.m_scale) return false; 00188 if(m_offset!=a_from.m_offset) return false; 00189 if(m_strip_width!=a_from.m_strip_width) return false; 00190 if(m_visible!=a_from.m_visible) return false; 00191 if(m_bar_offset!=a_from.m_bar_offset) return false; 00192 if(m_bar_width!=a_from.m_bar_width) return false; 00193 if(m_editable!=a_from.m_editable) return false; 00194 if(m_automated!=a_from.m_automated) return false; 00195 if(m_enforced!=a_from.m_enforced) return false; 00196 00197 //color 00198 if(m_color!=a_from.m_color) return false; 00199 if(m_highlight_color!=a_from.m_highlight_color) return false; 00200 if(m_back_color!=a_from.m_back_color) return false; 00201 00202 //std::string 00203 if(m_modeling !=a_from.m_modeling ) return false; 00204 if(m_light_model!=a_from.m_light_model) return false; 00205 if(m_tick_modeling!=a_from.m_tick_modeling) return false; 00206 if(m_encoding!=a_from.m_encoding) return false; 00207 if(m_cut!=a_from.m_cut) return false; 00208 if(m_font!=a_from.m_font) return false; 00209 if(m_options!=a_from.m_options) return false; 00210 if(m_color_mapping!=a_from.m_color_mapping) return false; 00211 00212 if(m_translation!=a_from.m_translation) return false; 00213 00214 if(m_front_face!=a_from.m_front_face) return false; 00215 00216 if(m_hjust!=a_from.m_hjust) return false; 00217 if(m_vjust!=a_from.m_vjust) return false; 00218 00219 return true; 00220 } 00221 00222 virtual void reset(){ //virtual because of SoGC 00223 m_color = colorf::black(); 00224 m_highlight_color = colorf::lightgrey(); 00225 m_back_color = colorf::white(); 00226 m_line_width = 1; 00227 m_marker_size = 1; 00228 m_font_size = 10; 00229 m_line_pattern = line_solid; 00230 m_marker_style = marker_dot; 00231 m_area_style = area_solid; 00232 m_modeling = modeling_boxes(); 00233 m_light_model = light_model_phong(); 00234 m_tick_modeling = tick_modeling_hippo(); 00235 m_encoding = encoding_none(); 00236 m_smoothing = false; 00237 m_hinting = false; 00238 m_cut = ""; 00239 m_painting = painting_uniform; 00240 m_hatching = hatching_none; 00241 m_projection = projection_none; 00242 m_font = "default"; 00243 m_multi_node_limit = no_limit(); 00244 m_transparency = 0; 00245 m_back_transparency = 0; 00246 m_back_shadow = 0; 00247 m_divisions = 510; 00248 m_rotation_steps = 24; 00249 m_spacing = 0.05F; 00250 m_angle = fpi()/4; 00251 m_scale = 1; 00252 m_offset = 0; 00253 m_strip_width = 0; 00254 m_visible = true; 00255 m_bar_offset = 0.25F; 00256 m_bar_width = 0.5F; 00257 m_editable = false; 00258 m_automated = true; 00259 m_options = ""; 00260 m_color_mapping = ""; 00261 m_enforced = false; 00262 m_translation = vec3f(0,0,0); 00263 m_front_face = winding_ccw; 00264 m_hjust = left; 00265 m_vjust = bottom; 00266 } 00267 00268 std::string tos() const{ 00269 char ss[23 * 32]; 00270 #ifdef WIN32 00271 _snprintf(ss,sizeof(ss), 00272 #else 00273 ::snprintf(ss,sizeof(ss), 00274 #endif 00275 "color %g %g %g\n\ 00276 highlight_color %g %g %g\n\ 00277 back_color %g %g %g\n\ 00278 line_width %g\n\ 00279 marker_size %g\n\ 00280 font_size %g\n\ 00281 line_pattern %x\n\ 00282 multi_node_limit %d\n\ 00283 transparency %g\n\ 00284 back_transparency %g\n\ 00285 back_shadow %g\n\ 00286 divisions %d\n\ 00287 rotation_steps %d\n\ 00288 angle %g\n\ 00289 scale %g\n\ 00290 offset %g\n\ 00291 strip_width %g\n\ 00292 spacing %g\n\ 00293 bar_offset %g\n\ 00294 bar_width %g\n\ 00295 translation %g %g %g" 00296 ,m_color[0],m_color[1],m_color[2] 00297 ,m_highlight_color[0],m_highlight_color[1],m_highlight_color[2] 00298 ,m_back_color[0],m_back_color[1],m_back_color[2] 00299 ,m_line_width 00300 ,m_marker_size 00301 ,m_font_size 00302 ,m_line_pattern 00303 ,m_multi_node_limit 00304 ,m_transparency 00305 ,m_back_transparency 00306 ,m_back_shadow 00307 ,m_divisions 00308 ,m_rotation_steps 00309 ,m_angle 00310 ,m_scale 00311 ,m_offset 00312 ,m_strip_width 00313 ,m_spacing 00314 ,m_bar_offset 00315 ,m_bar_width 00316 ,m_translation[0],m_translation[1],m_translation[2]); 00317 00318 std::string lf("\n"); 00319 std::string s(ss); 00320 00321 s += lf; 00322 s += "smoothing "; 00323 s += (m_smoothing?"true":"false"); 00324 00325 s += lf; 00326 s += "hinting "; 00327 s += (m_hinting?"true":"false"); 00328 00329 s += lf; 00330 s += "enforced "; 00331 s += (m_enforced?"true":"false"); 00332 00333 s += lf; 00334 s += "visible "; 00335 s += (m_visible?"true":"false"); 00336 00337 s += lf; 00338 s += "editable "; 00339 s += (m_editable?"true":"false"); 00340 00341 s += lf; 00342 s += "automated "; 00343 s += (m_automated?"true":"false"); 00344 00345 s += lf; 00346 s += "marker_style "; 00347 s += smarker_style(m_marker_style); 00348 00349 s += lf; 00350 s += "area_style "; 00351 s += sarea_style(m_area_style); 00352 00353 s += lf; 00354 s += "modeling "; 00355 s += m_modeling ; 00356 00357 s += lf; 00358 s += "light_model "; 00359 s += m_light_model; 00360 00361 s += lf; 00362 s += "tick_modeling "; 00363 s += m_tick_modeling; 00364 00365 s += lf; 00366 s += "encoding "; 00367 s += m_encoding; 00368 00369 s += lf; 00370 s += "cut "; 00371 s += m_cut; 00372 00373 s += lf; 00374 s += "painting "; 00375 s += spainting_policy(m_painting); 00376 00377 s += lf; 00378 s += "hatching "; 00379 s += shatching_policy(m_hatching); 00380 00381 s += lf; 00382 s += "projection "; 00383 s += sprojection_type(m_projection); 00384 00385 s += lf; 00386 s += "font "; 00387 s += m_font; 00388 00389 s += lf; 00390 s += "options "; 00391 s += m_options; 00392 00393 s += lf; 00394 s += "color_mapping "; 00395 s += m_color_mapping; 00396 00397 s += lf; 00398 s += "front_face "; 00399 s += (m_front_face==winding_ccw?"ccw":"cw"); 00400 00401 s += lf; 00402 s += "hjust "; 00403 s += shjust(m_hjust); 00404 00405 s += lf; 00406 s += "vjust "; 00407 s += svjust(m_vjust); 00408 00409 return s; 00410 } 00411 00412 void color(const colorf& a_v){m_color = a_v;} 00413 colorf color() const {return m_color;} 00414 00415 void highlight_color(const colorf& a_v){m_highlight_color = a_v;} 00416 colorf highlight_color() const {return m_highlight_color;} 00417 00418 void back_color(const colorf& a_v){m_back_color = a_v;} 00419 colorf back_color() const {return m_back_color;} 00420 00421 void line_width(float a_v){m_line_width = a_v;} 00422 float line_width() const {return m_line_width;} 00423 00424 float transparency() const {return m_transparency;} 00425 void transparency(float a_v) {m_transparency = a_v;} 00426 00427 float back_transparency() const {return m_back_transparency;} 00428 void back_transparency(float a_v) {m_back_transparency = a_v;} 00429 00430 float back_shadow() const {return m_back_shadow;} 00431 void back_shadow(float a_v) {m_back_shadow = a_v;} 00432 00433 void marker_style(sg::marker_style a_v){m_marker_style = a_v;} 00434 sg::marker_style marker_style() const {return m_marker_style;} 00435 00436 void marker_size(float a_v){m_marker_size = a_v;} 00437 float marker_size() const {return m_marker_size;} 00438 00439 void font_size(float a_v){m_font_size = a_v;} 00440 float font_size() const {return m_font_size;} 00441 00442 void area_style(sg::area_style a_v){m_area_style = a_v;} 00443 sg::area_style area_style() const {return m_area_style;} 00444 00445 void modeling(const std::string& a_v){m_modeling = a_v;} 00446 const std::string& modeling() const {return m_modeling ;} 00447 00448 void light_model(const std::string& a_v){m_light_model = a_v;} 00449 const std::string& light_model() const {return m_light_model;} 00450 00451 void tick_modeling(const std::string& a_v){m_tick_modeling = a_v;} 00452 const std::string& tick_modeling() const {return m_tick_modeling;} 00453 00454 void encoding(const std::string& a_v){m_encoding = a_v;} 00455 const std::string& encoding() const {return m_encoding;} 00456 00457 void smoothing(bool a_v){m_smoothing = a_v;} 00458 bool smoothing() const {return m_smoothing;} 00459 00460 void hinting(bool a_v){m_hinting = a_v;} 00461 bool hinting() const {return m_hinting;} 00462 00463 sg::painting_policy painting() const {return m_painting;} 00464 void painting(sg::painting_policy a_v){m_painting = a_v;} 00465 00466 sg::hatching_policy hatching() const {return m_hatching;} 00467 void hatching(sg::hatching_policy a_v) {m_hatching = a_v;} 00468 00469 sg::projection_type projection() const {return m_projection;} 00470 void projection(sg::projection_type a_v){m_projection = a_v;} 00471 00472 void line_pattern(lpat a_v){m_line_pattern = a_v;} 00473 lpat line_pattern() const {return m_line_pattern;} 00474 00475 void font(const std::string& a_v){m_font = a_v;} 00476 const std::string& font() const {return m_font;} 00477 00478 void divisions(int a_v){m_divisions = a_v;} 00479 int divisions() const {return m_divisions;} 00480 00481 void rotation_steps(unsigned int a_v){m_rotation_steps = a_v;} 00482 unsigned int rotation_steps() const {return m_rotation_steps;} 00483 00484 void offset(float a_v){m_offset = a_v;} 00485 float offset() const {return m_offset;} 00486 00487 void strip_width(float a_v){m_strip_width = a_v;} 00488 float strip_width() const {return m_strip_width;} 00489 00490 void angle(float a_v){m_angle = a_v;} 00491 float angle() const {return m_angle;} 00492 00493 void scale(float a_v){m_scale = a_v;} 00494 float scale() const {return m_scale;} 00495 00496 void bar_offset(float a_v){m_bar_offset = a_v;} 00497 float bar_offset() const {return m_bar_offset;} 00498 00499 void bar_width(float a_v){m_bar_width = a_v;} 00500 float bar_width() const {return m_bar_width;} 00501 00502 void multi_node_limit(int a_v){m_multi_node_limit = a_v;} 00503 int multi_node_limit() const {return m_multi_node_limit;} 00504 00505 void spacing(float a_v){m_spacing = a_v;} 00506 float spacing() const {return m_spacing;} 00507 00508 void visible(bool a_v){m_visible = a_v;} 00509 bool visible() const{return m_visible;} 00510 00511 void editable(bool a_v){m_editable = a_v;} 00512 bool editable() const{return m_editable;} 00513 00514 void automated(bool a_v){m_automated = a_v;} 00515 bool automated() const{return m_automated;} 00516 00517 void cut(const std::string& a_v){m_cut = a_v;} 00518 const std::string& cut() const {return m_cut;} 00519 00520 void options(const std::string& a_v){m_options = a_v;} 00521 const std::string& options() const{return m_options;} 00522 00523 void color_mapping(const std::string& a_v){m_color_mapping = a_v;} 00524 const std::string& color_mapping() const{return m_color_mapping;} 00525 00526 void enforced(bool a_v){m_enforced = a_v;} 00527 bool enforced() const{return m_enforced;} 00528 00529 void translation(const vec3f& a_v){m_translation = a_v;} 00530 vec3f translation() const {return m_translation;} 00531 00532 void front_face(winding_type a_v){m_front_face = a_v;} 00533 winding_type front_face() const {return m_front_face;} 00534 00535 void hjust(sg::hjust a_v){m_hjust = a_v;} 00536 sg::hjust hjust() const {return m_hjust;} 00537 00538 void vjust(sg::vjust a_v){m_vjust = a_v;} 00539 sg::vjust vjust() const {return m_vjust;} 00540 public: 00541 static void hls_to_rgb(float hue, float light, float satur, 00542 float &r, float &g, float &b){ 00543 // taken from ROOT/TColor. 00544 // Static method to compute RGB from HLS. The l and s are between [0,1] 00545 // and h is between [0,360]. The returned r,g,b triplet is between [0,1]. 00546 00547 float rh, rl, rs, rm1, rm2; 00548 rh = rl = rs = 0; 00549 if (hue > 0) rh = hue; if (rh > 360) rh = 360; 00550 if (light > 0) rl = light; if (rl > 1) rl = 1; 00551 if (satur > 0) rs = satur; if (rs > 1) rs = 1; 00552 00553 if (rl <= 0.5F) { 00554 rm2 = rl*(1 + rs); 00555 } else { 00556 rm2 = rl + rs - rl*rs; 00557 } 00558 rm1 = 2*rl - rm2; 00559 00560 if (!rs) { r = rl; g = rl; b = rl; return; } 00561 r = hls_to_rgb2(rm1, rm2, rh+120); 00562 g = hls_to_rgb2(rm1, rm2, rh); 00563 b = hls_to_rgb2(rm1, rm2, rh-120); 00564 } 00565 00566 static bool scolor(const cmaps_t& a_cmaps, 00567 const std::string& a_s,colorf& a_col){ 00568 //NOTE : if ret false, we do not set a_col to something. 00569 00570 std::string::size_type pos_slash = a_s.rfind('/'); 00571 if(pos_slash!=std::string::npos) { //<cmap>/<color name> 00572 std::string cmap = a_s.substr(0,pos_slash); 00573 std::string cnam = a_s.substr(pos_slash+1,a_s.size()-(pos_slash+1)); 00574 typedef inlib::sg::style_colormap cmap_t; 00575 cmaps_t::const_iterator it = a_cmaps.find(cmap); 00576 if(it==a_cmaps.end()) return false; 00577 return (*it).second.get_color(cnam,a_col); 00578 00579 } else { 00580 00581 if( (a_s.size()==7) && (a_s[0]=='#') ) { 00582 // #RRGGBB format : 00583 // 1 3 5 00584 unsigned long rr,gg,bb; 00585 00586 {std::string s("0x"); 00587 s += a_s.substr(1,2); 00588 if(!to_ulong(s,rr)) return false;} 00589 00590 {std::string s("0x"); 00591 s += a_s.substr(3,2); 00592 if(!to_ulong(s,gg)) return false;} 00593 00594 {std::string s("0x"); 00595 s += a_s.substr(5,2); 00596 if(!to_ulong(s,bb)) return false;} 00597 00598 a_col = colorf(((float)rr)/255,((float)gg)/255,((float)bb)/255); 00599 return true; 00600 } 00601 00602 // Look if three floats : 00603 {std::vector<std::string> words; 00604 inlib::words(a_s," ",false,words); 00605 if(words.size()==3) { 00606 std::string& word_0 = words[0]; 00607 std::string& word_1 = words[1]; 00608 std::string& word_2 = words[2]; 00609 float r,g,b; 00610 if( inlib::to<float>(word_0,r) && 00611 inlib::to<float>(word_1,g) && 00612 inlib::to<float>(word_2,b) ){ 00613 a_col = colorf(r,g,b); 00614 return true; 00615 } 00616 }} 00617 00618 {float r,g,b; 00619 if(inlib::colorf::to(a_s,r,g,b)) { //still use that ? cmap "default" ? 00620 a_col = colorf(r,g,b); 00621 return true; 00622 }} 00623 00624 } 00625 00626 return false; 00627 } 00628 00629 static bool scolor(const colorf& a_col,std::string& a_s){ 00630 char s[256]; 00631 #ifdef WIN32 00632 _snprintf(s,sizeof(s),"%g %g %g",a_col[0],a_col[1],a_col[2]); 00633 #else 00634 ::snprintf(s,sizeof(s),"%g %g %g",a_col[0],a_col[1],a_col[2]); 00635 #endif 00636 a_s = s; 00637 return true; 00638 } 00639 00643 private: 00644 typedef struct {char string[32];sg::hjust value;} hjust_rec; 00645 static const hjust_rec* hjust_recs(unsigned int& a_num){ 00646 static const hjust_rec list[] = { //read only static, then ok. 00647 {"left", sg::left}, 00648 {"center", sg::center}, 00649 {"right", sg::right} 00650 }; 00651 a_num = sizeof(list)/sizeof(list[0]); 00652 return list; 00653 } 00654 public: 00655 static bool shjust(const std::string& a_s,sg::hjust& a_v){ 00656 unsigned int number; 00657 const hjust_rec* list = hjust_recs(number); 00658 for(unsigned int count=0;count<number;count++) { 00659 if(a_s==list[count].string) { 00660 a_v = list[count].value; 00661 return true; 00662 } 00663 } 00664 a_v = sg::left; 00665 return false; 00666 } 00667 static const char* shjust(sg::hjust a_v){ 00668 unsigned int number; 00669 const hjust_rec* list = hjust_recs(number); 00670 for(unsigned int count=0;count<number;count++) { 00671 if(a_v==list[count].value) return list[count].string; 00672 } 00673 return 0; 00674 } 00675 00679 private: 00680 typedef struct {char string[32];sg::vjust value;} vjust_rec; 00681 static const vjust_rec* vjust_recs(unsigned int& a_num){ 00682 static const vjust_rec list[] = { //read only static, then ok. 00683 {"bottom", sg::bottom}, 00684 {"middle", sg::middle}, 00685 {"top", sg::top} 00686 }; 00687 a_num = sizeof(list)/sizeof(list[0]); 00688 return list; 00689 } 00690 public: 00691 static bool svjust(const std::string& a_s,sg::vjust& a_v){ 00692 unsigned int number; 00693 const vjust_rec* list = vjust_recs(number); 00694 for(unsigned int count=0;count<number;count++) { 00695 if(a_s==list[count].string) { 00696 a_v = list[count].value; 00697 return true; 00698 } 00699 } 00700 a_v = sg::bottom; 00701 return false; 00702 } 00703 static const char* svjust(sg::vjust a_v){ 00704 unsigned int number; 00705 const vjust_rec* list = vjust_recs(number); 00706 for(unsigned int count=0;count<number;count++) { 00707 if(a_v==list[count].value) return list[count].string; 00708 } 00709 return 0; 00710 } 00711 00715 private: 00716 typedef struct {char string[32];sg::marker_style value;} MarkerStyle; 00717 static const MarkerStyle* getMarkerStyleList(unsigned int& a_num){ 00718 static const MarkerStyle list[] = { //read only static, then ok. 00719 {"dot", marker_dot}, 00720 {"plus", marker_plus}, 00721 {"asterisk", marker_asterisk}, 00722 {"cross", marker_cross}, 00723 {"star", marker_star}, 00724 {"circle_line", marker_circle_line}, 00725 {"circle_filled", marker_circle_filled}, 00726 {"triangle_up_line", marker_triangle_up_line}, 00727 {"triangle_up_filled", marker_triangle_up_filled}, 00728 {"triangle_down_line", marker_triangle_down_line}, 00729 {"triangle_down_filled",marker_triangle_down_filled}, 00730 {"david_star_line", marker_david_star_line}, 00731 {"david_star_filled", marker_david_star_filled}, 00732 {"swiss_cross_line", marker_swiss_cross_line}, 00733 {"swiss_cross_filled", marker_swiss_cross_filled}, 00734 {"diamond_line", marker_diamond_line}, 00735 {"diamond_filled", marker_diamond_filled}, 00736 {"square_line", marker_square_line}, 00737 {"square_filled", marker_square_filled}, 00738 {"penta_star_line", marker_penta_star_line}, 00739 {"penta_star_filled", marker_penta_star_filled}, 00740 }; 00741 a_num = sizeof(list)/sizeof(list[0]); 00742 return list; 00743 } 00744 public: 00745 static bool smarker_style(const std::string& a_s, 00746 sg::marker_style& a_v){ 00747 unsigned int number; 00748 const MarkerStyle* list = getMarkerStyleList(number); 00749 for(unsigned int count=0;count<number;count++) { 00750 if(a_s==list[count].string) { 00751 a_v = list[count].value; 00752 return true; 00753 } 00754 } 00755 a_v = marker_dot; 00756 return false; 00757 } 00758 static const char* smarker_style(sg::marker_style a_v){ 00759 unsigned int number; 00760 const MarkerStyle* list = getMarkerStyleList(number); 00761 for(unsigned int count=0;count<number;count++) { 00762 if(a_v==list[count].value) return list[count].string; 00763 } 00764 return 0; 00765 } 00766 00770 private: 00771 typedef struct {char string[16];sg::area_style value;} AreaStyle; 00772 static const AreaStyle* getAreaStyleList(unsigned int& a_num){ 00773 static const AreaStyle list[] = { //read only static, then ok. 00774 {"solid", area_solid}, 00775 {"hatched", area_hatched}, 00776 {"checker", area_checker}, 00777 {"edged", area_edged} 00778 }; 00779 a_num = sizeof(list)/sizeof(list[0]); 00780 return list; 00781 } 00782 public: 00783 static bool sarea_style(const std::string& a_s,sg::area_style& a_v){ 00784 unsigned int number; 00785 const AreaStyle* list = getAreaStyleList(number); 00786 for(unsigned int count=0;count<number;count++) { 00787 if(a_s==list[count].string) { 00788 a_v = list[count].value; 00789 return true; 00790 } 00791 } 00792 a_v = area_solid; 00793 return false; 00794 } 00795 static const char* sarea_style(sg::area_style a_v){ 00796 unsigned int number; 00797 const AreaStyle* list = getAreaStyleList(number); 00798 for(unsigned int count=0;count<number;count++) { 00799 if(a_v==list[count].value) return list[count].string; 00800 } 00801 return 0; 00802 } 00803 00807 private: 00808 typedef struct {char string[20];sg::painting_policy value;} PaintingPolicy; 00809 static const PaintingPolicy* getPaintingPolicyList(unsigned int& a_num){ 00810 static const PaintingPolicy list[] = { //read only static, then ok. 00811 {"uniform", painting_uniform}, 00812 {"by_value", painting_by_value}, 00813 {"by_level", painting_by_level}, 00814 {"grey_scale", painting_grey_scale}, 00815 {"violet_to_red",painting_violet_to_red}, 00816 {"grey_scale_inverse",painting_grey_scale_inverse} 00817 }; 00818 a_num = sizeof(list)/sizeof(list[0]); 00819 return list; 00820 } 00821 public: 00822 static bool spainting_policy(const std::string& a_s, 00823 sg::painting_policy& a_v){ 00824 unsigned int number; 00825 const PaintingPolicy* list = getPaintingPolicyList(number); 00826 for(unsigned int count=0;count<number;count++) { 00827 if(a_s==list[count].string) { 00828 a_v = list[count].value; 00829 return true; 00830 } 00831 } 00832 a_v = painting_uniform; 00833 return false; 00834 } 00835 static const char* spainting_policy(sg::painting_policy a_v){ 00836 unsigned int number; 00837 const PaintingPolicy* list = getPaintingPolicyList(number); 00838 for(unsigned int count=0;count<number;count++) { 00839 if(a_v==list[count].value) return list[count].string; 00840 } 00841 return 0; 00842 } 00843 00844 00848 private: 00849 typedef struct {char string[16];sg::hatching_policy value;} HatchingPolicy; 00850 static const HatchingPolicy* getHatchingPolicyList(unsigned int& a_num){ 00851 static const HatchingPolicy list[] = { //read only static, then ok. 00852 {"none", hatching_none}, 00853 {"right", hatching_right}, 00854 {"left", hatching_left}, 00855 {"left_and_right", hatching_left_and_right} 00856 }; 00857 a_num = sizeof(list)/sizeof(list[0]); 00858 return list; 00859 } 00860 public: 00861 static bool shatching_policy(const std::string& a_s, 00862 sg::hatching_policy& a_v){ 00863 unsigned int number; 00864 const HatchingPolicy* list = getHatchingPolicyList(number); 00865 for(unsigned int count=0;count<number;count++) { 00866 if(a_s==list[count].string) { 00867 a_v = list[count].value; 00868 return true; 00869 } 00870 } 00871 a_v = hatching_none; 00872 return false; 00873 } 00874 00875 static const char* shatching_policy(sg::hatching_policy a_v){ 00876 unsigned int number; 00877 const HatchingPolicy* list = getHatchingPolicyList(number); 00878 for(unsigned int count=0;count<number;count++) { 00879 if(a_v==list[count].value) return list[count].string; 00880 } 00881 return 0; 00882 } 00883 00887 private: 00888 typedef struct {char string[16];sg::projection_type value;} ProjectionType; 00889 static const ProjectionType* getProjectionTypeList(unsigned int& a_num){ 00890 static const ProjectionType list[] = { //read only static, then ok. 00891 {"none", projection_none}, 00892 {"rz", projection_rz}, 00893 {"phiz", projection_phiz}, 00894 {"zr", projection_zr}, 00895 {"zphi", projection_zphi} 00896 }; 00897 a_num = sizeof(list)/sizeof(list[0]); 00898 return list; 00899 } 00900 public: 00901 static bool sprojection_type(const std::string& a_s, 00902 sg::projection_type& a_v){ 00903 unsigned int number; 00904 const ProjectionType* list = getProjectionTypeList(number); 00905 for(unsigned int count=0;count<number;count++) { 00906 if(a_s==list[count].string) { 00907 a_v = list[count].value; 00908 return true; 00909 } 00910 } 00911 a_v = projection_none; 00912 return false; 00913 } 00914 static const char* sprojection_type(sg::projection_type a_v){ 00915 unsigned int number; 00916 const ProjectionType* list = getProjectionTypeList(number); 00917 for(unsigned int count=0;count<number;count++) { 00918 if(a_v==list[count].value) return list[count].string; 00919 } 00920 return 0; 00921 } 00922 00926 static bool sline_pattern(const std::string& a_s,lpat& aPattern){ 00927 if(a_s=="solid") { 00928 aPattern = line_solid; 00929 } else if(a_s=="dashed") { 00930 aPattern = line_dashed; 00931 } else if(a_s=="dotted") { 00932 aPattern = line_dotted; 00933 } else if(a_s=="dash_dotted") { 00934 aPattern = line_dash_dotted; 00935 } else { 00936 aPattern = line_solid; 00937 return false; 00938 } 00939 return true; 00940 } 00941 00942 00946 bool parse(std::ostream& a_out,const cmaps_t& a_cmaps, 00947 const std::string& a_s){ 00948 // a_s = list of "name value" separated by \n 00949 //::printf("debug : style_parser::parse : \"%s\"\n",a_s.c_str()); 00950 std::vector<std::string> lines; 00951 get_lines(a_s,lines); 00952 00953 std::vector<std::string>::const_iterator it; 00954 for(it=lines.begin();it!=lines.end();++it) { 00955 const std::string& line = *it; 00956 if(line.empty()) continue; 00957 if(line=="reset") { 00958 reset(); 00959 continue; 00960 } 00961 std::vector<std::string> words; 00962 inlib::words(line," ",false,words); 00963 unsigned int wordn = words.size(); 00964 if(!wordn) { 00965 a_out << "style_parser::parse :" 00966 << " in " << inlib::sout(a_s) 00967 << " : " << inlib::sout(line) 00968 << " has a bad word count (at least two expected)." 00969 << std::endl; 00970 return false; 00971 } 00972 const std::string& word0 = words[0]; 00973 if(word0=="color") { 00974 if(wordn==2) { 00975 const std::string& word1 = words[1]; 00976 if(!scolor(a_cmaps,word1,m_color)) { 00977 a_out << "style_parser::parse :" 00978 << " in " << inlib::sout(a_s) 00979 << " : " << inlib::sout(word1) 00980 << " not a color." 00981 << std::endl; 00982 return false; 00983 } 00984 } else if (wordn==4) { 00985 const std::string& rs = words[1]; 00986 float r; 00987 if(!inlib::to<float>(rs,r)) { 00988 a_out << "style_parser::parse :" 00989 << " in " << inlib::sout(a_s) 00990 << " : " << inlib::sout(rs) 00991 << " not a number." 00992 << std::endl; 00993 return false; 00994 } 00995 const std::string& gs = words[2]; 00996 float g; 00997 if(!inlib::to<float>(gs,g)) { 00998 a_out << "style_parser::parse :" 00999 << " in " << inlib::sout(a_s) 01000 << " : " << inlib::sout(gs) 01001 << " not a number." 01002 << std::endl; 01003 return false; 01004 } 01005 const std::string& bs = words[3]; 01006 float b; 01007 if(!inlib::to<float>(bs,b)) { 01008 a_out << "style_parser::parse :" 01009 << " in " << inlib::sout(a_s) 01010 << " : " << inlib::sout(bs) 01011 << " not a number." 01012 << std::endl; 01013 return false; 01014 } 01015 m_color.set_value(r,g,b); 01016 } else { 01017 a_out << "style_parser::parse :" 01018 << " in " << inlib::sout(a_s) 01019 << " : " << inlib::sout(line) 01020 << " has a bad word count (two or four expected)." 01021 << std::endl; 01022 return false; 01023 } 01024 01025 } else if(word0=="highlight_color") { 01026 if(wordn==2) { 01027 const std::string& word1 = words[1]; 01028 if(!scolor(a_cmaps,word1,m_highlight_color)) { 01029 a_out << "style_parser::parse :" 01030 << " in " << inlib::sout(a_s) 01031 << " : " << inlib::sout(word1) 01032 << " not a color." 01033 << std::endl; 01034 return false; 01035 } 01036 } else if (wordn==4) { 01037 const std::string& rs = words[1]; 01038 float r; 01039 if(!inlib::to<float>(rs,r)) { 01040 a_out << "style_parser::parse :" 01041 << " in " << inlib::sout(a_s) 01042 << " : " << inlib::sout(rs) 01043 << " not a number." 01044 << std::endl; 01045 return false; 01046 } 01047 const std::string& gs = words[2]; 01048 float g; 01049 if(!inlib::to<float>(gs,g)) { 01050 a_out << "style_parser::parse :" 01051 << " in " << inlib::sout(a_s) 01052 << " : " << inlib::sout(gs) 01053 << " not a number." 01054 << std::endl; 01055 return false; 01056 } 01057 const std::string& bs = words[3]; 01058 float b; 01059 if(!inlib::to<float>(bs,b)) { 01060 a_out << "style_parser::parse :" 01061 << " in " << inlib::sout(a_s) 01062 << " : " << inlib::sout(bs) 01063 << " not a number." 01064 << std::endl; 01065 return false; 01066 } 01067 m_highlight_color.set_value(r,g,b); 01068 } else { 01069 a_out << "style_parser::parse :" 01070 << " in " << inlib::sout(a_s) 01071 << " : " << inlib::sout(line) 01072 << " has a bad word count (two or four expected)." 01073 << std::endl; 01074 return false; 01075 } 01076 01077 } else if(word0=="back_color") { 01078 if(wordn==2) { 01079 const std::string& word1 = words[1]; 01080 if(!scolor(a_cmaps,word1,m_back_color)) { 01081 a_out << "style_parser::parse :" 01082 << " in " << inlib::sout(a_s) 01083 << " : " << inlib::sout(word1) 01084 << " not a color." 01085 << std::endl; 01086 return false; 01087 } 01088 } else if (wordn==4) { 01089 const std::string& rs = words[1]; 01090 float r; 01091 if(!inlib::to<float>(rs,r)) { 01092 a_out << "style_parser::parse :" 01093 << " in " << inlib::sout(a_s) 01094 << " : " << inlib::sout(rs) 01095 << " not a number." 01096 << std::endl; 01097 return false; 01098 } 01099 const std::string& gs = words[2]; 01100 float g; 01101 if(!inlib::to<float>(gs,g)) { 01102 a_out << "style_parser::parse :" 01103 << " in " << inlib::sout(a_s) 01104 << " : " << inlib::sout(gs) 01105 << " not a number." 01106 << std::endl; 01107 return false; 01108 } 01109 const std::string& bs = words[3]; 01110 float b; 01111 if(!inlib::to<float>(bs,b)) { 01112 a_out << "style_parser::parse :" 01113 << " in " << inlib::sout(a_s) 01114 << " : " << inlib::sout(bs) 01115 << " not a number." 01116 << std::endl; 01117 return false; 01118 } 01119 m_back_color.set_value(r,g,b); 01120 } else { 01121 a_out << "style_parser::parse :" 01122 << " in " << inlib::sout(a_s) 01123 << " : " << inlib::sout(line) 01124 << " has a bad word count (two or four expected)." 01125 << std::endl; 01126 return false; 01127 } 01128 01129 } else if( (word0=="line_pattern") || (word0=="line_pattern") ) { 01130 if(!check_2(wordn,a_s,line,a_out)) return false; 01131 const std::string& word1 = words[1]; 01132 unsigned long ul; 01133 if(!sline_pattern(word1,m_line_pattern)) { 01134 if(!to_ulong(word1,ul)) { 01135 a_out << "style_parser::parse :" 01136 << " in " << inlib::sout(a_s) 01137 << " : " << inlib::sout(word1) 01138 << " not a line pattern." 01139 << std::endl; 01140 return false; 01141 } 01142 m_line_pattern = (lpat)ul; 01143 } 01144 } else if(word0=="marker_style") { 01145 if(!check_2(wordn,a_s,line,a_out)) return false; 01146 const std::string& word1 = words[1]; 01147 if(!smarker_style(word1,m_marker_style)) { 01148 a_out << "style_parser::parse :" 01149 << " in " << inlib::sout(a_s) 01150 << " : " << inlib::sout(word1) 01151 << " not a marker_style." 01152 << std::endl; 01153 return false; 01154 } 01155 } else if(word0=="area_style") { 01156 if(!check_2(wordn,a_s,line,a_out)) return false; 01157 const std::string& word1 = words[1]; 01158 if(!sarea_style(word1,m_area_style)) { 01159 a_out << "style_parser::parse :" 01160 << " in " << inlib::sout(a_s) 01161 << " : " << inlib::sout(word1) 01162 << " not a area_style." 01163 << std::endl; 01164 return false; 01165 } 01166 } else if(word0=="modeling") { 01167 if(!check_2(wordn,a_s,line,a_out)) return false; 01168 m_modeling = words[1]; 01169 } else if(word0=="light_model") { 01170 if(!check_2(wordn,a_s,line,a_out)) return false; 01171 m_light_model = words[1]; 01172 } else if(word0=="tick_modeling") { 01173 if(!check_2(wordn,a_s,line,a_out)) return false; 01174 m_tick_modeling = words[1]; 01175 } else if(word0=="encoding") { 01176 if(!check_2(wordn,a_s,line,a_out)) return false; 01177 m_encoding = words[1]; 01178 } else if(word0=="smoothing") { 01179 if(!check_2(wordn,a_s,line,a_out)) return false; 01180 bool value; 01181 if(!check_bool(words[1],a_s,a_out,value)) return false; 01182 m_smoothing = value; 01183 } else if(word0=="hinting") { 01184 if(!check_2(wordn,a_s,line,a_out)) return false; 01185 bool value; 01186 if(!check_bool(words[1],a_s,a_out,value)) return false; 01187 m_hinting = value; 01188 } else if(word0=="enforced") { 01189 if(!check_2(wordn,a_s,line,a_out)) return false; 01190 bool value; 01191 if(!check_bool(words[1],a_s,a_out,value)) return false; 01192 m_enforced = value; 01193 } else if(word0=="cut") { 01194 m_cut = ""; 01195 for(unsigned int wordi=1;wordi<wordn;wordi++) { 01196 if(wordi!=1) m_cut += " "; 01197 m_cut += words[wordi]; 01198 } 01199 } else if(word0=="options") { 01200 m_options = ""; 01201 for(unsigned int wordi=1;wordi<wordn;wordi++) { 01202 if(wordi!=1) m_options += " "; 01203 m_options += words[wordi]; 01204 } 01205 } else if(word0=="color_mapping") { 01206 m_color_mapping = ""; 01207 for(unsigned int wordi=1;wordi<wordn;wordi++) { 01208 if(wordi!=1) m_color_mapping += " "; 01209 m_color_mapping += words[wordi]; 01210 } 01211 } else if(word0=="painting") { 01212 if(!check_2(wordn,a_s,line,a_out)) return false; 01213 if(!spainting_policy(words[1],m_painting)) { 01214 a_out << "style_parser::parse :" 01215 << " in " << inlib::sout(a_s) 01216 << " : " << inlib::sout(words[1]) 01217 << " not a painting_policy." 01218 << std::endl; 01219 return false; 01220 } 01221 } else if(word0=="hatching") { 01222 if(!check_2(wordn,a_s,line,a_out)) return false; 01223 if(!shatching_policy(words[1],m_hatching)) { 01224 a_out << "style_parser::parse :" 01225 << " in " << inlib::sout(a_s) 01226 << " : " << inlib::sout(words[1]) 01227 << " not a hatching_policy." 01228 << std::endl; 01229 return false; 01230 } 01231 } else if(word0=="projection") { 01232 if(!check_2(wordn,a_s,line,a_out)) return false; 01233 if(!sprojection_type(words[1],m_projection)) { 01234 a_out << "style_parser::parse :" 01235 << " in " << inlib::sout(a_s) 01236 << " : " << inlib::sout(words[1]) 01237 << " not a projection_type." 01238 << std::endl; 01239 return false; 01240 } 01241 } else if(word0=="font") { 01242 if(!check_2(wordn,a_s,line,a_out)) return false; 01243 font(words[1]); 01244 } else if(word0=="line_width") { 01245 if(!check_2(wordn,a_s,line,a_out)) return false; 01246 float value; 01247 if(!check_float(words[1],a_s,a_out,value)) return false; 01248 m_line_width = value; 01249 } else if(word0=="marker_size") { 01250 if(!check_2(wordn,a_s,line,a_out)) return false; 01251 float value; 01252 if(!check_float(words[1],a_s,a_out,value)) return false; 01253 m_marker_size = value; 01254 } else if(word0=="font_size") { 01255 if(!check_2(wordn,a_s,line,a_out)) return false; 01256 float value; 01257 if(!check_float(words[1],a_s,a_out,value)) return false; 01258 m_font_size = value; 01259 } else if(word0=="transparency") { 01260 if(!check_2(wordn,a_s,line,a_out)) return false; 01261 float value; 01262 if(!check_float(words[1],a_s,a_out,value)) return false; 01263 if(value<0.F) value = 0.F; 01264 m_transparency = value; 01265 } else if(word0=="back_transparency") { 01266 if(!check_2(wordn,a_s,line,a_out)) return false; 01267 float value; 01268 if(!check_float(words[1],a_s,a_out,value)) return false; 01269 if(value<0.F) value = 0.F; 01270 m_back_transparency = value; 01271 } else if(word0=="back_shadow") { 01272 if(!check_2(wordn,a_s,line,a_out)) return false; 01273 float value; 01274 if(!check_float(words[1],a_s,a_out,value)) return false; 01275 if(value<0.F) value = 0.F; 01276 m_back_shadow = value; 01277 } else if(word0=="multi_node_limit") { 01278 if(!check_2(wordn,a_s,line,a_out)) return false; 01279 int value; 01280 if(!check_int(words[1],a_s,a_out,value)) return false; 01281 m_multi_node_limit = value; 01282 } else if(word0=="divisions") { 01283 if(!check_2(wordn,a_s,line,a_out)) return false; 01284 int value; 01285 if(!check_int(words[1],a_s,a_out,value)) return false; 01286 m_divisions = value; 01287 } else if(word0=="rotation_steps") { 01288 if(!check_2(wordn,a_s,line,a_out)) return false; 01289 unsigned int value; 01290 if(!check_uint(words[1],a_s,a_out,value)) return false; 01291 m_rotation_steps = value; 01292 } else if(word0=="angle") { 01293 if(!check_2(wordn,a_s,line,a_out)) return false; 01294 float value; 01295 if(!check_float(words[1],a_s,a_out,value)) return false; 01296 m_angle = value; 01297 } else if(word0=="scale") { 01298 if(!check_2(wordn,a_s,line,a_out)) return false; 01299 float value; 01300 if(!check_float(words[1],a_s,a_out,value)) return false; 01301 m_scale = value; 01302 } else if(word0=="offset") { 01303 if(!check_2(wordn,a_s,line,a_out)) return false; 01304 float value; 01305 if(!check_float(words[1],a_s,a_out,value)) return false; 01306 m_offset = value; 01307 } else if(word0=="strip_width") { 01308 if(!check_2(wordn,a_s,line,a_out)) return false; 01309 float value; 01310 if(!check_float(words[1],a_s,a_out,value)) return false; 01311 m_strip_width = value; 01312 } else if(word0=="spacing") { 01313 if(!check_2(wordn,a_s,line,a_out)) return false; 01314 float value; 01315 if(!check_float(words[1],a_s,a_out,value)) return false; 01316 m_spacing = value; 01317 } else if(word0=="visible") { 01318 if(!check_2(wordn,a_s,line,a_out)) return false; 01319 bool value; 01320 if(!check_bool(words[1],a_s,a_out,value)) return false; 01321 m_visible = value; 01322 } else if(word0=="editable") { 01323 if(!check_2(wordn,a_s,line,a_out)) return false; 01324 bool value; 01325 if(!check_bool(words[1],a_s,a_out,value)) return false; 01326 m_editable = value; 01327 } else if(word0=="automated") { 01328 if(!check_2(wordn,a_s,line,a_out)) return false; 01329 bool value; 01330 if(!check_bool(words[1],a_s,a_out,value)) return false; 01331 m_automated = value; 01332 } else if(word0=="bar_offset") { 01333 if(!check_2(wordn,a_s,line,a_out)) return false; 01334 float value; 01335 if(!check_float(words[1],a_s,a_out,value)) return false; 01336 m_bar_offset = value; 01337 } else if(word0=="bar_width") { 01338 if(!check_2(wordn,a_s,line,a_out)) return false; 01339 float value; 01340 if(!check_float(words[1],a_s,a_out,value)) return false; 01341 m_bar_width = value; 01342 01343 } else if(word0=="translation") { 01344 if (wordn==4) { 01345 const std::string& sx = words[1]; 01346 float x; 01347 if(!inlib::to<float>(sx,x)) { 01348 a_out << "style_parser::parse :" 01349 << " in " << inlib::sout(a_s) 01350 << " : " << inlib::sout(sx) 01351 << " not a number." 01352 << std::endl; 01353 return false; 01354 } 01355 const std::string& sy = words[2]; 01356 float y; 01357 if(!inlib::to<float>(sy,y)) { 01358 a_out << "style_parser::parse :" 01359 << " in " << inlib::sout(a_s) 01360 << " : " << inlib::sout(sy) 01361 << " not a number." 01362 << std::endl; 01363 return false; 01364 } 01365 const std::string& sz = words[3]; 01366 float z; 01367 if(!inlib::to<float>(sz,z)) { 01368 a_out << "style_parser::parse :" 01369 << " in " << inlib::sout(a_s) 01370 << " : " << inlib::sout(sz) 01371 << " not a number." 01372 << std::endl; 01373 return false; 01374 } 01375 m_translation.set_value(x,y,z); 01376 } else { 01377 a_out << "style_parser::parse :" 01378 << " in " << inlib::sout(a_s) 01379 << " has a bad word count (four expected)." 01380 << std::endl; 01381 return false; 01382 } 01383 01384 } else if(word0=="front_face") { 01385 if(!check_2(wordn,a_s,line,a_out)) return false; 01386 const std::string& word1 = words[1]; 01387 if(word1=="ccw") { 01388 m_front_face = winding_ccw; 01389 } else if(word1=="cw") { 01390 m_front_face = winding_cw; 01391 } else { //ccw 01392 a_out << "style_parser::parse :" 01393 << " in " << inlib::sout(a_s) 01394 << " : " << inlib::sout(word1) 01395 << " not a winding type." 01396 << std::endl; 01397 return false; 01398 } 01399 01400 } else if(word0=="hjust") { 01401 if(!check_2(wordn,a_s,line,a_out)) return false; 01402 const std::string& word1 = words[1]; 01403 if(!shjust(word1,m_hjust)) { 01404 a_out << "style_parser::parse :" 01405 << " in " << inlib::sout(a_s) 01406 << " : " << inlib::sout(word1) 01407 << " not a hjust." 01408 << std::endl; 01409 return false; 01410 } 01411 01412 } else if(word0=="vjust") { 01413 if(!check_2(wordn,a_s,line,a_out)) return false; 01414 const std::string& word1 = words[1]; 01415 if(!svjust(word1,m_vjust)) { 01416 a_out << "style_parser::parse :" 01417 << " in " << inlib::sout(a_s) 01418 << " : " << inlib::sout(word1) 01419 << " not a vjust." 01420 << std::endl; 01421 return false; 01422 } 01423 01424 } else { 01425 a_out << "style_parser::parse :" 01426 << " in " << inlib::sout(a_s) 01427 << " : " << inlib::sout(word0) 01428 << " bad option." 01429 << std::endl; 01430 return false; 01431 } 01432 } 01433 return true; 01434 } 01435 01436 private: 01437 bool check_2(unsigned int a_n,const std::string& a_s,const std::string& a_line,std::ostream& a_out) { 01438 if(a_n!=2) { 01439 a_out << "style_parser::parse :" 01440 << " in " << inlib::sout(a_s) 01441 << " : " << inlib::sout(a_line) 01442 << " has a bad word count (two expected)." 01443 << std::endl; 01444 return false; 01445 } 01446 return true; 01447 } 01448 01449 bool check_bool(const std::string& a_w,const std::string& a_s,std::ostream& a_out,bool& a_v) { 01450 if(!inlib::to(a_w,a_v)){ 01451 a_out << "style_parser::parse :" 01452 << " in " << inlib::sout(a_s) 01453 << " : " << inlib::sout(a_w) 01454 << " not a boolean." 01455 << std::endl; 01456 return false; 01457 } 01458 return true; 01459 } 01460 01461 bool check_int(const std::string& a_w,const std::string& a_s,std::ostream& a_out,int& a_v) { 01462 if(!inlib::to<int>(a_w,a_v)){ 01463 a_out << "style_parser::parse :" 01464 << " in " << inlib::sout(a_s) 01465 << " : " << inlib::sout(a_w) 01466 << " not an int." 01467 << std::endl; 01468 return false; 01469 } 01470 return true; 01471 } 01472 bool check_uint(const std::string& a_w,const std::string& a_s,std::ostream& a_out,unsigned int& a_v) { 01473 if(!inlib::to<unsigned int>(a_w,a_v)){ 01474 a_out << "style_parser::parse :" 01475 << " in " << inlib::sout(a_s) 01476 << " : " << inlib::sout(a_w) 01477 << " not an unsigned int." 01478 << std::endl; 01479 return false; 01480 } 01481 return true; 01482 } 01483 bool check_float(const std::string& a_w,const std::string& a_s,std::ostream& a_out,float& a_v) { 01484 if(!inlib::to<float>(a_w,a_v)){ 01485 a_out << "style_parser::parse :" 01486 << " in " << inlib::sout(a_s) 01487 << " : " << inlib::sout(a_w) 01488 << " not a float." 01489 << std::endl; 01490 return false; 01491 } 01492 return true; 01493 } 01494 01495 static float hls_to_rgb2(float rn1, float rn2, float huei) { 01496 // taken from ROOT/TColor. 01497 float hue = huei; 01498 if (hue > 360) hue = hue - 360; 01499 if (hue < 0) hue = hue + 360; 01500 if (hue < 60 ) return rn1 + (rn2-rn1)*hue/60; 01501 if (hue < 180) return rn2; 01502 if (hue < 240) return rn1 + (rn2-rn1)*(240-hue)/60; 01503 return rn1; 01504 } 01505 static bool to_ulong(const std::string& a_s,unsigned long& a_v){ 01506 a_v = 0L; 01507 if(::sscanf(a_s.c_str(),"%lx",&a_v)!=1) { 01508 if(::sscanf(a_s.c_str(),"%lu",&a_v)!=1) { 01509 a_v = 0L; 01510 return false; 01511 } 01512 } 01513 return true; 01514 } 01515 static void get_lines(const std::string& a_string, 01516 std::vector<std::string>& a_lines){ 01517 // a_string is a list separated by "\n" or "\\n". 01518 // For "xxx\n\nxxx", {"xxx","","xxx"} will be created. 01519 // WARNING : if a_string is a Windows file name, it may 01520 // contains a \n which is not a delimiter ; like ..\data\ntuples.hbook. 01521 a_lines.clear(); 01522 int length = a_string.length(); 01523 if(length<=0) return; 01524 char* cstring = inlib::str_dup(a_string.c_str()); 01525 if(!cstring) return; 01526 int pos = 0; 01527 length++; 01528 for(int count=0;count<length;count++) { 01529 if( (cstring[count]=='\n') || 01530 (cstring[count]=='\0') || 01531 ( (cstring[count]=='\\') && (cstring[count+1]=='n') ) ) { 01532 char shift_one = (cstring[count]=='\n' ? 1 : 0); 01533 cstring[count] = '\0'; 01534 a_lines.push_back(cstring+pos); 01535 if(shift_one==1) { 01536 pos = count+1; 01537 } else { 01538 pos = count+2; 01539 count++; 01540 } 01541 } 01542 } 01543 inlib::str_del(cstring); 01544 } 01545 private: 01546 colorf m_color; 01547 colorf m_highlight_color; 01548 colorf m_back_color; 01549 float m_line_width; 01550 float m_marker_size; 01551 float m_font_size; 01552 lpat m_line_pattern; 01553 sg::marker_style m_marker_style; 01554 sg::area_style m_area_style; 01555 std::string m_modeling ; 01556 std::string m_light_model; 01557 std::string m_tick_modeling; 01558 std::string m_encoding; 01559 bool m_smoothing; 01560 bool m_hinting; 01561 std::string m_cut; 01562 sg::painting_policy m_painting; 01563 sg::hatching_policy m_hatching; 01564 sg::projection_type m_projection; 01565 std::string m_font; 01566 int m_multi_node_limit; //could be no_limit = -1. 01567 int m_divisions; 01568 unsigned int m_rotation_steps; 01569 float m_transparency; 01570 float m_back_transparency; 01571 float m_back_shadow; 01572 float m_spacing; 01573 float m_angle; 01574 float m_scale; 01575 float m_offset; 01576 float m_strip_width; 01577 bool m_visible; 01578 float m_bar_offset; 01579 float m_bar_width; 01580 bool m_editable; 01581 bool m_automated; 01582 std::string m_options; 01583 std::string m_color_mapping; 01584 bool m_enforced; 01585 vec3f m_translation; 01586 winding_type m_front_face; 01587 sg::hjust m_hjust; 01588 sg::vjust m_vjust; 01589 }; 01590 01591 }} 01592 01593 #endif