From 1e2769f7bef2922d5649e3a49e48e70267daeeac Mon Sep 17 00:00:00 2001 From: Vladimir Georgiev Date: Thu, 12 May 2016 16:38:49 +0300 Subject: [PATCH] - Line rope: Removed the hiding, added option to show/hide anchors and rebelay loops with the "-anchors on/off" and "rebelays on/off" options. Based on the already existing metapost code - Line handrail: use small squares instead of points to look a bit different from line rope --- mpost/thLine.mp | 20 ++++++++++++-------- thline.cxx | 44 +++++++++++++++++++++++++++++++++++++++++--- thline.h | 7 +++++++ thmpost.cxx | 20 ++++++++++++-------- thsymbolset.cxx | 9 +++++++-- thsymbolsetlist.h | 2 +- thsymbolsetlist.pl | 2 +- 7 files changed, 81 insertions(+), 23 deletions(-) diff --git a/mpost/thLine.mp b/mpost/thLine.mp index a1b4cd8..dc56060 100644 --- a/mpost/thLine.mp +++ b/mpost/thLine.mp @@ -976,10 +976,10 @@ def l_gradient_BCRA (expr P) = enddef; -def l_rope_SKBB (expr P,exact) = +def l_rope_SKBB (expr P, show_anchors, show_rebelays) = T:=identity; pickup PenC; - if exact: + if not show_rebelays: draw P; else: d:=0.5u; @@ -1007,14 +1007,15 @@ def l_rope_SKBB (expr P,exact) = endfor; endfor; pair x; - x = point (length P)-1 of P + whatewer * down; + x = point (length P)-1 of P + whatever * down; x = point (length P) of P + whatever * right; draw point (length P)-1 of P -- x; -% thdraw point length P of P withpen pencircle scaled 0.3u withcolor red; fi; - for i:=0 upto length P if not exact: -1 fi: - thdraw point i of P withpen pencircle scaled 0.3u; - endfor; + if show_anchors: + for i:=0 upto length P if show_rebelays: -1 fi: + thdraw point i of P withpen pencircle scaled 0.25u; + endfor; + fi; enddef; def l_border_presumed_SKBB (expr Path) = @@ -1101,12 +1102,15 @@ def l_handrail_SKBB (expr P) = else: T:=identity; cas := 0; + pair coord; + sq_size:=0.12u; dlzka := arclength P; mojkrok:=adjust_step(dlzka, u); pickup PenD; forever: t := arctime cas of P; - thdraw point t of P withpen pencircle scaled .25u; + coord := point t of P; + thfill coord+(-sq_size,-sq_size)--coord+(sq_size,-sq_size)--coord+(sq_size,sq_size)--coord+(-sq_size,sq_size)--cycle; cas := cas + mojkrok; exitif cas > dlzka + (mojkrok / 3); % for rounding errors endfor; diff --git a/thline.cxx b/thline.cxx index bc81c56..040dc5b 100644 --- a/thline.cxx +++ b/thline.cxx @@ -218,8 +218,22 @@ void thline::set(thcmd_option_desc cod, char ** args, int argenc, unsigned long case TT_LINE_MARK: this->insert_point_mark(*args); break; - - + + case TT_LINE_ANCHORS: + case TT_LINE_REBELAYS: + if (this->type != TT_LINE_TYPE_ROPE) + ththrow(("-anchors and -rebelays not valid with type %s", thmatch_string(this->type,thtt_line_types))) + int flag, tagtype; + flag = thmatch_token(*args,thtt_bool); + if (flag == TT_UNKNOWN_BOOL) + ththrow(("logical value expected -- %s",*args)) + tagtype = (cod.id == TT_LINE_ANCHORS) ? TT_LINE_TAG_ROPE_ANCHORS : TT_LINE_TAG_ROPE_REBELAYS; + if (flag == TT_TRUE) + this->tags |= tagtype; + else + this->tags &= ~tagtype; + break; + // if not found, try to set fathers properties default: th2ddataobject::set(cod, args, argenc, indataline); @@ -294,6 +308,10 @@ void thline::parse_type(char * ss) case TT_LINE_TYPE_CEILING_MEANDER: this->place = TT_2DOBJ_PLACE_DEFAULT_TOP; break; + case TT_LINE_TYPE_ROPE: // show anchors and rebelays on line rope by default + this->tags |= TT_LINE_TAG_ROPE_ANCHORS; + this->tags |= TT_LINE_TAG_ROPE_REBELAYS; + break; } } @@ -892,11 +910,31 @@ bool thline::export_mp(class thexpmapmpxs * out) thline_type_export_mp(TT_LINE_TYPE_GRADIENT, SYML_GRADIENT) thline_type_export_mp(TT_LINE_TYPE_U, SYML_U) thline_type_export_mp(TT_LINE_TYPE_HANDRAIL, SYML_HANDRAIL) - thline_type_export_mp(TT_LINE_TYPE_ROPE, SYML_ROPE) thline_type_export_mp(TT_LINE_TYPE_ROPE_LADDER, SYML_ROPELADDER) thline_type_export_mp(TT_LINE_TYPE_FIXED_LADDER, SYML_FIXEDLADDER) thline_type_export_mp(TT_LINE_TYPE_STEPS, SYML_STEPS) thline_type_export_mp(TT_LINE_TYPE_VIA_FERRATA, SYML_VIAFERRATA) + + case TT_LINE_TYPE_ROPE: + macroid = SYML_ROPE; + if (this->context >= 0) + macroid = this->context; + if (!out->symset->is_assigned(macroid)) { + postprocess = false; + break; + } + if (out->file == NULL) + return(true); + + out->symset->export_mp_symbol_options(out->file, SYML_ROPE); + fprintf(out->file,"%s(",out->symset->get_mp_macro(SYML_ROPE)); + this->export_path_mp(out); + fprintf(out->file,",%s,%s);\n", ((this->tags & TT_LINE_TAG_ROPE_ANCHORS) > 0 ? "true" : "false"), + ((this->tags & TT_LINE_TAG_ROPE_REBELAYS) > 0 ? "true" : "false")); + + postprocess = false; + break; + case TT_LINE_TYPE_ARROW: macroid = SYML_ARROW; if (this->context >= 0) diff --git a/thline.h b/thline.h index 11fd98f..5f0fcd3 100644 --- a/thline.h +++ b/thline.h @@ -57,6 +57,8 @@ enum { TT_LINE_TEXT = 3017, TT_LINE_ADJUST = 3018, TT_LINE_HEIGHT = 3019, + TT_LINE_ANCHORS = 3020, + TT_LINE_REBELAYS = 3021, }; @@ -74,6 +76,9 @@ enum { // tags pre arrow TT_LINE_TAG_HEAD_BEGIN = 1, TT_LINE_TAG_HEAD_END = 2, +// tags for type rope, indicating to show rebelays and anchors + TT_LINE_TAG_ROPE_ANCHORS = 1, + TT_LINE_TAG_ROPE_REBELAYS = 2, }; @@ -85,6 +90,7 @@ enum { static const thstok thtt_line_opt[] = { {"adjust", TT_LINE_ADJUST}, {"altitude", TT_LINE_ALTITUDE}, + {"anchors", TT_LINE_ANCHORS}, {"border", TT_LINE_BORDER}, {"close", TT_LINE_CLOSED}, {"direction", TT_LINE_DIRECTION}, @@ -97,6 +103,7 @@ static const thstok thtt_line_opt[] = { {"orientation", TT_LINE_ORIENT}, {"outline", TT_LINE_OUTLINE}, {"r-size",TT_LINE_RSIZE}, + {"rebelays", TT_LINE_REBELAYS}, {"reverse", TT_LINE_REVERSE}, {"size",TT_LINE_SIZE}, {"smooth",TT_LINE_SMOOTH}, diff --git a/thmpost.cxx b/thmpost.cxx index 3660627..7331302 100644 --- a/thmpost.cxx +++ b/thmpost.cxx @@ -2908,10 +2908,10 @@ const char * thmpost_library = "enddef;\n" "\n" "\n" -"def l_rope_SKBB (expr P,exact) =\n" +"def l_rope_SKBB (expr P, show_anchors, show_rebelays) =\n" " T:=identity;\n" " pickup PenC;\n" -" if exact:\n" +" if not show_rebelays:\n" " draw P;\n" " else:\n" " d:=0.5u;\n" @@ -2939,14 +2939,15 @@ const char * thmpost_library = " endfor;\n" " endfor;\n" " pair x;\n" -" x = point (length P)-1 of P + whatewer * down;\n" +" x = point (length P)-1 of P + whatever * down;\n" " x = point (length P) of P + whatever * right;\n" " draw point (length P)-1 of P -- x;\n" -"% thdraw point length P of P withpen pencircle scaled 0.3u withcolor red;\n" " fi;\n" -" for i:=0 upto length P if not exact: -1 fi:\n" -" thdraw point i of P withpen pencircle scaled 0.3u;\n" -" endfor;\n" +" if show_anchors:\n" +" for i:=0 upto length P if show_rebelays: -1 fi:\n" +" thdraw point i of P withpen pencircle scaled 0.25u;\n" +" endfor;\n" +" fi;\n" "enddef;\n" "\n" "def l_border_presumed_SKBB (expr Path) =\n" @@ -3033,12 +3034,15 @@ const char * thmpost_library = " else:\n" " T:=identity;\n" " cas := 0;\n" +" pair coord;\n" +" sq_size:=0.12u;\n" " dlzka := arclength P;\n" " mojkrok:=adjust_step(dlzka, u);\n" " pickup PenD; \n" " forever:\n" " t := arctime cas of P;\n" -" thdraw point t of P withpen pencircle scaled .25u;\n" +" coord := point t of P;\n" +" thfill coord+(-sq_size,-sq_size)--coord+(sq_size,-sq_size)--coord+(sq_size,sq_size)--coord+(-sq_size,sq_size)--cycle;\n" " cas := cas + mojkrok;\n" " exitif cas > dlzka + (mojkrok / 3); % for rounding errors\n" " endfor;\n" diff --git a/thsymbolset.cxx b/thsymbolset.cxx index 079a9c6..8776cf7 100644 --- a/thsymbolset.cxx +++ b/thsymbolset.cxx @@ -1325,13 +1325,18 @@ void thsymbolset::export_pdf(class thlayout * layout, FILE * mpf, unsigned & sfi legend_point(SYMP_NOEQUIPMENT,thT("point no-equipment",layout->lang)); legend_point(SYMP_ANCHOR,thT("point anchor",layout->lang)); legend_point(SYMP_ROPE,thT("point rope",layout->lang)); - legend_eqline(SYML_ROPE,thT("line rope",layout->lang)); legend_point(SYMP_ROPELADDER,thT("point rope-ladder",layout->lang)); legend_eqline(SYML_ROPELADDER,thT("line rope-ladder",layout->lang)); legend_point(SYMP_FIXEDLADDER,thT("point fixed-ladder",layout->lang)); legend_eqline(SYML_FIXEDLADDER,thT("line fixed-ladder",layout->lang)); legend_point(SYMP_STEPS,thT("point steps",layout->lang)); - + + insfig(SYML_ROPE,thT("line rope",layout->lang)); + this->export_mp_symbol_options(mpf, SYML_ROPE); + fprintf(mpf,"%s(((0.1,0.85) -- (0.25,0.6) -- (0.5,0.1)) inscale, true, true);\n",thsymbolset__mp[SYML_ROPE]); + fprintf(mpf,"%s(((0.6,0.8) -- (0.8,0.2)) inscale, true, false);\n",thsymbolset__mp[SYML_ROPE]); + endfig; + insfig(SYML_STEPS,thT("line steps",layout->lang)); this->export_mp_symbol_options(mpf, SYML_STEPS); fprintf(mpf,"%s(((0.1,0.3) -- (0.9,.3) -- (0.9,0.7) -- (0.1,0.7) -- cycle) inscale);\n",thsymbolset__mp[SYML_STEPS]); diff --git a/thsymbolsetlist.h b/thsymbolsetlist.h index e515a59..11a38a4 100644 --- a/thsymbolsetlist.h +++ b/thsymbolsetlist.h @@ -678,7 +678,7 @@ static const bool thsymbolset__hidden [] = { false, false, false, - true, + false, false, false, false, diff --git a/thsymbolsetlist.pl b/thsymbolsetlist.pl index daabbc0..73f1542 100644 --- a/thsymbolsetlist.pl +++ b/thsymbolsetlist.pl @@ -24,7 +24,7 @@ $SYMHASH{l_wall_invisible} = "hidden"; # ??? $SYMHASH{l_survey} = "noassign"; $SYMHASH{l_undefined} = "noassign"; $SYMHASH{l_label} = "noassign"; -$SYMHASH{l_rope} = "noassign hidden"; +$SYMHASH{l_rope} = "noassign"; $SYMHASH{l_u} = ""; $SYMHASH{l_} = "noassign hidden"; $SYMHASH{l_zzz} = "noassign hidden"; -- 2.6.4.windows.1