[Tex/LaTex] How to draw inside a TikZ node using node style with arguments

nodestikz-pgftikz-styles

The question is an extension to this question, and is also related to this one.

I want to draw a Simulink-style sum block which is basically a circle node with a port in each direction (north, west, south, east). If a port is used as an added (or subtracted) input, a plus (or minus) sign is shown at the port. I hope I can specify the port configurations using custom node styles with arguments:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[
    positive/.pic = {\draw (-1mm,0)--(1mm,0) (0,-1mm)--(0,1mm);},
    negative/.pic = {\draw (-1mm,0)--(1mm,0);},
    sum block/.style = {draw, circle, inner sep=0pt, minimum size=9mm,
        north/.style = {append after command={pic at +(0,3mm) {#1}}},
        south/.style = {append after command={pic at +(0,-3mm) {#1}}},
        west/.style = {append after command={pic at +(-3mm,0) {#1}}},
        east/.style = {append after command={pic at +(3mm,0) {#1}}},
    },
]
% I wish to create a node like this:
\path (1cm, 0) node [sum block] {} pic at +(0,3mm) {positive} pic at +(-3mm, 0) {negative};
% using a more elegant syntax like this:
\node at (2cm, 0) [sum block, north=positive, west=negative] {};
\end{tikzpicture}
\end{document}

The result is as follows; the desired fancy syntax is not producing any port sign.

test output

Is there an easy way to meet the objective? A TikZ-only solution like this one is preferred.

Best Answer

Do you want something like this?

\documentclass[tikz, border=5pt]{standalone}
\begin{document}
  \tikzset{
    charge node/.style={inner sep=0pt},
    pics/sum block/.style n args={4}{
      code={
        \path node (n) [draw, circle, inner sep=0pt, minimum size=9mm] {}
          (n.north) +(0,-1.5mm) node [charge node] {$#1$}
          (n.south) +(0,1.5mm) node [charge node] {$#2$}
          (n.west) +(1.5mm,0) node [charge node] {$#3$}
          (n.east) +(-1.5mm,0) node [charge node] {$#4$}
          ;
      }
    }
  }
  \begin{tikzpicture}
    \path pic at (10mm,0) {sum block={+}{-}{+}{-}}
    pic at (20mm,0) {sum block={}{+}{-}{}}
    ;
  \end{tikzpicture}
\end{document}

charge pics