Why is the text (the black bullets) not at coordinate (0,0) where I have defined the anchor center but is a bit above on the right ?
\documentclass[border=10pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,shapes.symbols}
\tikzset{%
couleur/.style={fill={#1},top couleur/.style={fill=#1!50}},%
}%
\makeatletter%
\pgfkeys{/tikz/remplissage/.initial = -1cm}%hauteur de fluide -1 = vide
% ---------------- %
% erlenmeyer %
% ---------------- %
\pgfdeclareshape{erlenmeyer}{ \nodeparts{text}
\anchor{center}{\pgfpoint{0}{0cm}}%
\anchor{north}{\pgfpoint{0}{1.85cm}}%
\anchor{south}{\pgfpoint{0}{-2cm}}%
\saveddimen\hauteurphase{\pgf@x=\pgfkeysvalueof{/tikz/remplissage}}%
\behindbackgroundpath{ %
\path[draw,clip] (-0.5,1.75) to[rounded
corners=2pt]++(0,-1)to[rounded corners=10pt]++(-1,-2.5)to[rounded
corners=10pt, bend right=15pt]++(3,0) to[rounded
corners=2pt]++(-1,2.5)--++(0,1)++(-0.5,0) circle [x radius=0.5, y
radius=0.1];%
\path[couleur](-1.6,-2) rectangle (1.6,{\hauteurphase-2cm});
\path[draw=white,top couleur] (0,\hauteurphase-2cm) circle [x
radius=1.5cm-(\hauteurphase-0.25cm)*0.4 , y
radius=0.1 cm];%
}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[couleur = green, remplissage = 1cm]
\draw (0,0)node[erlenmeyer]{$\bullet$};%
\draw [help lines] (0,-2) node{(0,-2)}grid(3,2)node{(3,2)};%
\end{tikzpicture}
\end{document}
@cfr Indeed dealing with \anchor{text} and \pgfnodeparttextbox solved that problem but introduce an other one that I will talk later.
I read and tried to understand the manual p1035 as you suggested I think that the code has to specify the coordinate of the lower left text box corner in the shape coordinate system. To put the text centered in the origin, the lower left text box corner has to be placed half of width on the left of the origin and half of height below the origin.
\documentclass[border=10pt, tikz]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,shapes.geometric,shapes.symbols}
\tikzset{%
couleur/.style={fill={#1},top couleur/.style={fill=#1!50}},%
}%
\makeatletter%
\pgfkeys{/tikz/remplissage/.initial = -1
cm}%hauteur de fluide -1 = vide
% ---------------- %
% erlenmeyer %
% ---------------- %
\pgfdeclareshape{erlenmeyer}{%
\nodeparts{text}%
\savedanchor{\lowerlefttextcorner}{
\pgf@y=-0.5\ht\pgfnodeparttextbox % height of the box, ignoring the depth
\pgf@x=-0.5\wd\pgfnodeparttextbox % width of the box
}%
\anchor{center}{\pgfpoint{0}{0cm}}%
\anchor{north}{\pgfpoint{0}{1.85cm}}%
\anchor{south}{\pgfpoint{0}{-2cm}}%
\anchor{text}{%
\lowerlefttextcorner%
}%
\saveddimen\hauteurphase{\pgf@x=\pgfkeysvalueof{/tikz/remplissage}}%
\behindbackgroundpath{ %
\path[draw,clip] (-0.5,1.75) to[rounded
corners=2pt]++(0,-1)to[rounded corners=10pt]++(-1,-2.5)to[rounded
corners=10pt, bend right=15pt]++(3,0) to[rounded
corners=2pt]++(-1,2.5)--++(0,1)++(-0.5,0) circle [x radius=0.5, y
radius=0.1];%
\path[couleur](-1.6,-2) rectangle (1.6,{\hauteurphase-2cm});
\path[draw=white,top couleur] (0,\hauteurphase-2cm) circle [x
radius=1.5cm-(\hauteurphase-0.25cm)*0.4 , y
radius=0.1 cm];%
}%
}
\makeatother
\begin{document}
\begin{tikzpicture}[anchor=center, remplissage = 1cm]
\draw[olive, ultra thick] (0,0)node[scale=2]{$\bullet$} --(3,0) node[scale=2]{$\bullet$};%
\draw (0,0)node[erlenmeyer, couleur = cyan]{$\bullet$}
++ (3,0)node[erlenmeyer, couleur = yellow]{$\bullet$};%
\draw [help lines] (0,-2) node[olive]{this text is well
placed}grid(3,2)node[olive]{this text is well placed};%
\draw (0,-3)node[right]{With anchor center};
\end{tikzpicture}
\begin{tikzpicture}[anchor=south, remplissage = 1cm]
\draw[red, ultra thick] (0,0)node[scale=2]{$\bullet$} --(3,0) node[scale=2]{$\bullet$};%
\draw (0,0)node[erlenmeyer, couleur = red]{$\bullet$}
++ (3,0)node[erlenmeyer, couleur = blue]{$\bullet$};%
\draw [help lines] (0,-2) node[red]{this text is higher than I
expected}grid(3,2)node[red]{this text is higher than I expected};%
\draw (0,-3)node[right]{With anchor south: and where are the scaled twice bullets?};
\end{tikzpicture}
\begin{tikzpicture}[anchor=north, remplissage = 1cm]
\draw[red, ultra thick] (0,0)node[scale=2]{$\bullet$} --(3,0)
node[scale=2]{$\bullet$};%
\draw (0,0)node[erlenmeyer, couleur = magenta]{$\bullet$}
++ (3,0)node[erlenmeyer, couleur = olive]{$\bullet$};%
\draw [help lines] (0,-2) node[red]{this text is lower than I
expected}grid(3,2)node[red]{this text is lower than I expected};%
\draw (0,-5)node[right]{With anchor north: and why are the scaled
twice bullets so low?};
\end{tikzpicture}
\end{document}
The erlenmeyer node with center anchor parameter is working but the new problem is that the south and north anchor parameters are working well for the erlenmeyer placement but have sides effects: they are destroying the placement of the other stuff outside of the erlenmeyer node.
As cfr said if I want north or south alignement, I have to pass it as a node option so it doesn't affect everything.
\begin{tikzpicture}[anchor=center, remplissage = 1cm]
\draw[red, ultra thick] (0,0)node[scale=2]{$\bullet$} --(3,0) node[scale=2]{$\bullet$};%
\draw (0,0)node[erlenmeyer, couleur = cyan]{$\bullet$}
++ (3,0)node[erlenmeyer, couleur = yellow]{$\bullet$};%
\draw [help lines] (0,-2) node{(0,-2)}grid(3,2)node{(3,2)};%
\draw (0,-3)node[right]{With anchor center};
\end{tikzpicture}
\begin{tikzpicture}[ remplissage = 1cm]
\draw[red, ultra thick] (0,0)node[scale=2]{$\bullet$} --(3,0) node[scale=2]{$\bullet$};%
\draw (0,0)node[erlenmeyer,anchor=south, couleur = red]{$\bullet$}
++ (3,0)node[erlenmeyer ,anchor=south, couleur = blue]{$\bullet$};%
\draw [help lines] (0,-2) node{(0,-2)}grid(3,2)node{(3,2)};%
\draw (0,-3)node[right]{With anchor south};
\end{tikzpicture}
\begin{tikzpicture}[remplissage = 1cm]
\draw[red, ultra thick] (0,0)node[scale=2]{$\bullet$} --(3,0)
node[scale=2]{$\bullet$};%
\draw (0,0)node[erlenmeyer, anchor=north, couleur = magenta]{$\bullet$}
++ (3,0)node[erlenmeyer, anchor=north, couleur = olive]{$\bullet$};%
\draw [help lines] (0,-2) node{(0,-2)}grid(3,2)node{(3,2)};%
\draw (0,-5)node[right]{With anchor north};
\end{tikzpicture}
\savedanchor
or is my reading of the manual's explanation of\pgfdeclareshape
hopelessly ignorant? That is, don't you need a\pgfnodeparttextbox
somewhere?