[Therion] Metapost and user attributes

Xavier Pennec Xavier.Pennec at sophia.inria.fr
Sat Dec 22 19:59:50 CET 2007


Dear all,

I have a survey with lots of sections (which are on another map than the 
plan and the elevation, see attached files NaduelFilonCerisiersPlan.pdf 
and  NaduelRD8_sections.pdf) and I would like to add automatically a 
label numbering each section at the end of the section line in the plan. 
As I want to be able not to display the section lines AND the their 
numbers when I inlcude that survey into the larger map, I thought that 
adding a user attribute to the section line would be the right way.

Thus, I used a user attribute called label in my th2 file:
   line section -reverse on -direction both -attr label "one"
     312.0 327.0
     334.09 327.0 396.0 327.0 425.0 327.0
   endline

and I redefined the section line metapost command into in my layout:

code metapost
def l_section (expr P)(text txt) =
  T:=identity;
  path Q; Q = punked P;
  pickup PenC;
  for t = 0 upto length P - 1:
    pair zz[];
    zz1 := point t of P;
    zz2 := point t+1 of P;
    zz3 := postcontrol t of P;
    zz4 := precontrol t+1 of P;
    if (length(zz3-1/3[zz1,zz2]) > 0.1pt) or
       (length(zz4-2/3[zz1,zz2]) > 0.1pt):
      zz5 = whatever[zz1,zz2];
      (zz3-zz5) = whatever * (zz1-zz2) rotated 90;
      draw zz1--zz5;
      zz6 = whatever[zz1,zz2];
      (zz4-zz6) = whatever * (zz1-zz2) rotated 90;
      draw zz2--zz6;
    else:
      draw zz1--zz2;
    fi;
  endfor;
  for pnt=txt:
    if pnt=-1:
    else:
      T:=identity rotated angle(thdir(Q,pnt)) shifted (point pnt of Q);
      pickup PenC;
      thdraw (0,0)--(0,.8u);
      thdraw (-.1u,.55u)--(0,.8u)--(.1u,.55u);
      if known ATTR_label:
        p_label( ATTR_label, (point pnt of Q), 0, 5);
      fi;
    fi;
    exitif pnt=-1;
  endfor;
enddef;
endcode

The file NaduelRD5_plan.pdf is an example on what it gives. With that 
solution, I have two problems:
- the first one is that is I change     -attr label "one"    with     
-attr label "1"     then metapost crashes because ATTR_label is 
intrepreted in that case as a known numeric and not as a string.
- the second problem is how to give an offset to the label so that it is 
actually above and below the lines?

If there is any metapost guru that can help, I'll appreciate.

Xavier

PS: there would be another solution to my problem, which would be to put 
sections and their labels in separate scraps, simulating different 
layers as in gimp, and not to include these scraps into the large map. 
However, to define properly a scrap as a layer of another one, it would 
be needed to deform both scarps exactly in the same way, which is not 
the case right now if some reference survey station is moved in one 
scrap only. Thus, I would imagine that a bettre solution would be a 
special type of layer scrap where the geometry is copied from another 
(e.g. something like scrap scrap2_layer2 -copy scrap2). Is that 
something feasible?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: NaduelFilonCerisiersPlan.pdf
Type: application/pdf
Size: 177269 bytes
Desc: not available
URL: <http://mailman.speleo.sk/pipermail/therion/attachments/20071222/0bbc6ded/attachment.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NaduelRD8_sections.pdf
Type: application/pdf
Size: 206878 bytes
Desc: not available
URL: <http://mailman.speleo.sk/pipermail/therion/attachments/20071222/0bbc6ded/attachment-0001.pdf>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NaduelRD5_plan.pdf
Type: application/pdf
Size: 19981 bytes
Desc: not available
URL: <http://mailman.speleo.sk/pipermail/therion/attachments/20071222/0bbc6ded/attachment-0002.pdf>


More information about the Therion mailing list