nodo tikz con entorno de listado

nodo tikz con entorno de listado

Estoy intentando crear una jerarquía de clases en C++. Cada nodo de la jerarquía es una descripción de clase con una lista de códigos y varios nodos están conectados mediante líneas y flechas que representan la jerarquía. Estoy tratando de crear el nodo usando tcolorboxuna lista de códigos y abarcar el cuadro tikz nodepara poder dibujar líneas entre los nodos.

Así que creé el entorno CodeNode e intenté llamar a nodecosas relacionadas en el entorno. El MWE está aquí

\documentclass{book}

\usepackage{tcolorbox}
\usepackage{tikz}
\usepackage{environ}

\tcbuselibrary{listings}


\NewEnviron{CodeNode}{
  \node{%
    \begin{minipage}{0.8\textwidth}
      \begin{tcbwritetemp}
        {\BODY}
      \end{tcbwritetemp}
      \tcbox[arc=0pt,outer arc=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm,
             boxrule=0.6pt,title=#1]{\tcbusetemplisting}
    \end{minipage}
  };
}

\begin{document}

\begin{figure}
  \begin{tcolorbox}
   \begin{tikzpicture}
     \begin{CodeNode}[class name]
       virtual void draw() = 0;
       virtual void some_other_function() = 0;
     \end{CodeNode}
   \end{tikzpicture}
  \end{tcolorbox}
\end{figure}

\end{document}

Recibo un error en tcbwritetemp

Library (tcolorbox): 'tcblistingscore.code.tex' version '2.60'
)) (./mwe.aux) ABD: EveryShipout initializing macros
! Argument of \next has an extra }.
<inserted text> 
                \par 
l.30      \end{CodeNode}

Que me estoy perdiendo aqui ?

Respuesta1

El principal problema parece ser la captura del texto palabra por palabra en interacción con tikzy environ.

Mi propuesta de solución omite el environpaquete, que es una gran herramienta, pero no es necesaria aquí. Las CodeNodeopciones se guardan con mynodeoptionsy mytcboptions. Agregué parámetros obligatorios como el nombre del nodo y la posición a las opciones. Puede adaptar fácilmente la configuración de mi ejemplo dado a sus propias necesidades.

\documentclass{book}

\usepackage{tcolorbox}
\usepackage{tikz}

\tcbuselibrary{listings}

\newenvironment{CodeNode}[4][]{
  \tikzset{mynodeoptions/.style={at={(#2)},name=#3,#1}}%
  \tcbset{mytcboptions/.style={title=#4}}%
  \tcboutputlisting%
}{\endtcboutputlisting%
  \node[inner sep=0pt,outer sep=0pt,draw=none,fill=none,mynodeoptions]{%
    \tcbinputlisting{listing only,width=0.8\textwidth,colback=white,
      arc=0pt,outer arc=0pt,top=1mm,bottom=1mm,left=1mm,right=1mm,
      boxrule=0.6pt,mytcboptions}};%
}

\begin{document}

\begin{figure}
\begin{tcolorbox}[center upper,colframe=blue!50!black,colback=blue!5!white]
\begin{tikzpicture}
  \begin{CodeNode}{0,2}{anode}{class name}
virtual void draw() = 0;
virtual void some_other_function() = 0;
  \end{CodeNode}
  \begin{CodeNode}{0,-2}{bnode}{other class name}
virtual void other_draw() = 0;
virtual void yet_some_other_function() = 0;
  \end{CodeNode}
  \draw[red,very thick,->] (anode)--(bnode);
  \draw[red,very thick,->] (anode.east)-- ++(1,0);
  \draw[red,very thick,->] (anode.west)-- ++(-1,0);
\end{tikzpicture}
\end{tcolorbox}
\end{figure}

\end{document}

ingrese la descripción de la imagen aquí

información relacionada