hackl / TikZ-StructuralAnalysis

TikZ Library for Structural Analysis
Other
123 stars 29 forks source link

Specifying styling for line widths #22

Open ccaprani opened 4 years ago

ccaprani commented 4 years ago

Hi Jurgen - really love this package - well done! I have forked it and am willing to do some development on the issue below, but thought I'd see what you think is a good approach first.

Problem A typical use case is to present the same structure multiple times as a basis for some other plots; e.g. BMD, SFD, deflected shape, etc. Repeating the structure drawing code makes no sense, and so using a \tikzset and pic is really useful. Using this approach, styles can be altered as needed using scopes as suggested in the package documentation:

\tikzset{
    pics/grid/.style args = {#1/#2}{
    code={
        \dpoint{c}{0}{0}{0}; 
        \dpoint{d}{ -#1 }{0}{0};
        \dpoint{e}{0}{ #1 }{0}; 
        \dpoint{f}{ #1 }{0}{0};
        \dpoint{g}{0}{-#1 }{0}; 
        \dpoint{z}{ -#1 }{ -#1 }{0}; 

        \daxis{1}{z}; 

        \begin{scope}[#2]
            \foreach \startn/\endn in {c/d,c/e,c/f,c/g}
            \dbeam{1}{\startn}{\endn};

            \support{1}{d}; \hinge{1}{d}
            \support{3}{e}[90];
            \support{1}{f}; \hinge{1}{f}
            \support{3}{g}[270];        
        \end{scope}

        \dnotation{1}{c}{$C$}[below=2mm];
        \dnotation{1}{d}{$D$}[above right];
        \dnotation{1}{e}{$E$}[above left];
        \dnotation{1}{f}{$F$}[above right];
        \dnotation{1}{g}{$G$}[below right];
    }},
    pics/grid/.default=4/black
}

One issue I have found is that line thicknesses cannot be changed using this approach. This is because the library defines line thickness as follows:

\tikzstyle{hugeLine}=[line width=\DhugeLineWidth,]

where \DhugeLineWidth is

\newcommand{\DhugeLineWidth}{2pt}

as a result, including line width in argument #2 of my pic above has no effect.

The problem can be solved by doing the following:

\begin{scope}[hugeLine/.append style={line width=1mm}]
    \pic{grid};
\end{scope}

but this requires the user to access the undocumented innards of the library (i.e. hugeLine in this case), and it may change the line width on elements other than those expected (wherever hugeLine is used to draw elements in the scope.

Question So my question is: what is the best way to adapt the library code to allow for line thickness specifications?

Solutions? In a bid to be helpful, I'm wondering if the solution is something like:

  1. Alter the commands definitions to include the option of overriding line widths;
  2. Documenting and exposing the library tikzset styles

I don't like (1) because it means editing all the library commands (lots of work); it also means more complex commands (additional argument); and it is inconsistent tikz design which should be all updateable through /.style appends or scope (which I prefer for simplicity).

I don't like (2) because it would mean introducing tikz styles for every type of element drawn, e.g. bending beam, truss rod, invisible just to name the ones possible for \dbeam.

On balance I think (2) is easier for both normal and advanced users. Is there a third (and better) solution?

Thanks!

ccaprani commented 4 years ago

I've been thinking a bit more on this.

Something I should have made clearer is that it is not only for line thicknesses but also for other decorations like force arrow head types. Again, use of scope on a pic would globally affect all force definitions, whereas some may like certain styles for (say) moments, and another style for linear forces.

Solution (2) I mentioned may not be so bad actually as it may not need tikzsets for each command option. Instead there may be a single dbeam_line with presets for the usual command options, but which can be overridden if desired. Further, it would not be every draw element that would need such flexibility - maybe just beam lines and forces? I can't see a use-case for needing to define different styles for draw elements of a support for example.

So in summary, perhaps all that is needed is: