[Tex/LaTex] Orthogonal Edges Style

automataedgetikz-pgf

I'm trying to draw a block diagram. I want to make the edge (red) orthogonal, like the black path made with -|. I know there are the commands \tikztostart, \tikztotarget and the ....!0.5!... opertator, but cant make them work inside the every edge/.style{}. Here is my code (dont know how to add the compiled version).

\begin{tikzpicture}[line width=1pt,-{Stealth[scale=3,length=3,width=2]},on grid,node distance=2cm,every node/.style={font=\huge},every edge/.style={draw,red,rounded corners}]
\node[draw,rectangle]   (B)                         {$B$};
\node[draw,circle]      (S)     [right=of B]        {$+$};
\node[draw,rectangle]   (I)     [right=of S]        {$\dfrac{1}{s}$};
\node[draw,rectangle]   (C)     [right=of I]        {$C$};
\node[draw,rectangle]   (A)     [below=of I]        {$A$};
\node[draw,rectangle]   (D)     [above=of I]        {$D$};

\draw           (B)     edge    [auto=left]     node    {}  (S)
                (S)     edge    [auto=right]    node                        {}          (I)
                (A)     edge    [auto]                          node                        {$A$}           (S);
\draw   (A) -| node {$A$} (S);
\end{tikzpicture}

Best Answer

Something like this?

enter image description here

Code:

    \documentclass[border=3mm,
               tikz,
               preview
               ]{standalone}
\usetikzlibrary{arrows.meta,chains,positioning}
\usepackage{amsmath}

    \begin{document}
%---------------------------------------------------------------%
    \begin{tikzpicture}[
      line width = 1pt,
         on grid,
      start chain = going right,
    node distance = 2cm,
       box/.style = {draw, rectangle, font=\huge, on chain},
         L/.style = {draw, red, -{Stealth[scale=3,length=3,width=2]}},
         T/.style = {draw, red, rounded corners,
                     to path={-| (\tikztotarget)},
                     -{Stealth[scale=3,length=3,width=2]}}
                        ]
\node[box]              (B) {$B$};
\node[draw,circle,
      on chain]         (S) {$+$};
\node[box]              (I) {$\frac{1}{s}$};
\node[box]              (C) {$C$};
\node[box,below=of I]   (A) {$A$};
\node[box,above=of I]   (D) {$D$};

\draw%[]
    (B) edge[L] (S)
    (S) edge[L] (I) 
    (I) edge[L] (C) 
    (D) edge[T] (S) 
    (A) edge[T] (S) 
        ;
\end{tikzpicture}
%---------------------------------------------------------------%
    \end{document}   

Idea for quadrature edges is stolen from here.

Edit: In above code is typing error: instead of positionings should be positioning. I correct this now.

Upgrade: In a case, that you like to have edges labeled, this can be simply done only for edges of type L, for example:

\draw   (B) edge[L] node {b} (S) 
        (S) edge[L] (I);

however, for edges of type T, the definition of edge should be changed as follows:

...
T/.style args = {#1/#2}{draw, red, rounded corners,
                 to path={-| node[pos=#1] {#2}
                 (\tikztotarget)},
                 -{Stealth[scale=3,length=3,width=2]}},
    T/.default = / ]

and edges width node are:

\draw   (D) edge[T=0.75/a] (S)
        (A) edge[T=0.25/a] (S);

or in case, when edge hasn't node:

\draw   (D) edge[T] (S)
        (A) edge[T=0.25/a] (S);

Another detail: since edges are defined to be in red color, than in case, that you like to have for example in black, you need add option text=black in edge node options. An complete example with edge labels:

        \documentclass[border=3mm,
               tikz,
               preview
               ]{standalone}
\usetikzlibrary{arrows.meta,chains,positioning}
\usepackage{amsmath}

    \begin{document}
%---------------------------------------------------------------%
    \begin{tikzpicture}[
      line width = 1pt,
         auto,
      start chain = going right,
    node distance = 2cm,
       box/.style = {draw, rectangle, font=\huge, on chain},
         L/.style = {draw, red, rounded corners,
                    -{Stealth[scale=3,length=3,width=2]}},
                    ]
\node[box]              (B) {$B$};
\node[draw,circle,
      on chain]         (S) {$+$};
\node[box]              (I) {$\frac{1}{s}$};
\node[box]              (C) {$C$};
\node[box,below=of I]   (A) {$A$};
\node[box,above=of I]   (D) {$D$};

\draw   (B) edge[L] node {b} (S)
        (S) edge[L] (I)
        (I) edge[L] (C)
        (D) edge[T=0.75/$d$] (S)
        (A) edge[T=0.25/a] (S)
        ;
\end{tikzpicture}
%---------------------------------------------------------------%
    \end{document} 

Beside above solution there exist more simple solution:

        \documentclass[border=3mm,
               tikz,
               preview
               ]{standalone}
\usetikzlibrary{arrows.meta,chains,positioning}
\usepackage{amsmath}

    \begin{document}
%---------------------------------------------------------------%
    \begin{tikzpicture}[
      line width = 1pt,
         auto,
      start chain = going right,
    node distance = 2cm,
       box/.style = {draw, rectangle, font=\huge, on chain},
         L/.style = {draw, red, rounded corners,
                     -{Stealth[scale=3,length=3,width=2]}},
    T/.style args = {#1/#2}{draw, red, rounded corners,
                     to path={-| node[pos=#1,text=black] {#2}
                     (\tikztotarget)},
                     -{Stealth[scale=3,length=3,width=2]}},
        T/.default = / ]
\node[box]              (B) {$B$};
\node[draw,circle,
      on chain]         (S) {$+$};
\node[box]              (I) {$\frac{1}{s}$};
\node[box]              (C) {$C$};
\node[box,below=of I]   (A) {$A$};
\node[box,above=of I]   (D) {$D$};

\draw[L]    (B) edge node {b} (S)
            (S) edge (I)
            (I) edge (C);
\draw[L]    (D) -| node[pos=0.75] {$d$} (S);
\draw[L]    (A) -| node[pos=0.25] {a} (S);
\end{tikzpicture}

Both gives the same result:

enter image description here

The second, simpler solution instead complicated edge with orthogonal path use separately draw of each orthogonal path between nodes, i.e. you need for each path write \draw[L] ... what in the first case is not needed. Both solution has pros and cons. Which is more suitable? This I left to user(s) :-).