# How to connect different own TikZ macros together + default names of node

I will ask you for solution about a little bit more complex problem. Maybe it isn't so hard as it seems to be but, for me it is hard one. Let's say that i want to create four own macros \objecta, \objectb, \objectc, \objectd of these drawings:

\documentclass{article}
\usepackage{tikz}

\newcommand{\objecta}[1]{
\begin{tikzpicture}\draw (0,0)--(1,0)--(1,1)--(0,1)--cycle;
\draw [->](-0.2,0.5)--(0.5,1.2);
\node at (-0.5,0.5){#1};
\end{tikzpicture}}

\newcommand{\objectb}[2]{
\begin{tikzpicture}
\draw (0,0)--(2,0)--(2,1)--(0,1)--cycle;
\draw (0.3,0.5)--(0.5,0.5);
\draw (1.5,0.5)--(1.7,0.5);
\draw (0.5,0.35)--(1.5,0.35)--(1.5,0.65)--(0.5,0.65)--cycle;
\node at (0.2,0.8){$\triangledown$};
\node at (1.8,0.2){$T$};
\node at (0.4,1.2){#1};
\node at (-0.3,0.5){#2};
\end{tikzpicture}}

\newcommand{\objectc}{
\begin{tikzpicture}
\node[minimum height=2cm,minimum width=2cm, draw, rectangle] at (0,0) {PI};
\draw (0.3,-1)--(1,0)--(0.3,1);
\end{tikzpicture}}

\def\objectd{\node [circle,draw] {M};}

\begin{document}
.
.
.
\end{document}


ObjectA has only 1 node (label). ObjectB has four nodes (labels) (drawing under first with all labels), but only one is default (T). The rest two objects have default nodes. So my first question is how to specify macro where when I put nothing in {#1} {#2} {#3} ... the default text will be displayed.

So I have these macros, now I want to connect them together like this:

It is possible to create a macro or procedure for positioning those objects and macro/procedure for creating paths? Something that i will specify only node of first macro, node of second macro and path will be created.

Many thanks. ( sorry for the grammar if it is bad )

EDIT:

• Sorry I'm quite new so don't know right now what I can define as node,anchor,label when I have it only in my mind and you can have different solution. Due that i didn't post any code, because though that for you it will be easier to work with own code not with mine clumsy one.
• problem with the default text of node is minor, mainly I want help with positioning and creating paths from macro to another macro. And if it's possible and how to create macro or procedure for it.
• Added macro code, as you see it is clumsy code. Don't know how to work with node placement (text) to be ok.
• Hmm again my post has to be edited - due pictures
• Will appreciate any help, due I'm hopelessly lost and don't know how to move with it.
• I would like to help more if I could, but dunno move with it
-
It would be really hard for us to help if you don't provide a minimal working example having these shapes and declarations such that we can copy and compile your code and see it for ourselves to modify.. Please note that the emphasis is on the minimal. –  percusse Mar 8 '12 at 11:39
It looks to me that what you are calling objects would best be implemented in TikZ as nodes, what you are calling nodes or labels would be best implemented as anchors for the TikZ nodes. Labels in TikZ are a third thing entirely! –  Matthew Leingang Mar 8 '12 at 12:52
Also, as far as your first question goes, I can't quite tell what you mean by "default." For instance, it seems you want a macro that creates ObjectB, where the user must specify something to go in the bottom right, but may further specify something to go on the left edge, top left corner inside, and top left corner outside. That would more commonly be described as a macro with three optional arguments and one mandatory argument. If that is what you want, see the xparse documentation for further information. –  Matthew Leingang Mar 8 '12 at 12:57
Welcome to TeX.SE. Thanks for including the code snippets as that helps. But it would be very helpful to compose a fully compilable MWE that sets up the problem to where you need help. This should include the \documentclass and all the appropriate packages and be compilable. –  Peter Grill Mar 8 '12 at 17:52
Is it possible to create path between macros with this way? [link] (tex.stackexchange.com/questions/27769/…) I mean your solution Peter. Just put a picture there as node. My Tex crash every time, when i try compile it.  \newcommand*{\mymacro}[2]{#1+#2}% \begin{document} \begin{tikzpicture} \node (0) at (0,0) {X}; \node (\mymacro{2}{3}) at (1,2) {Y}; \draw (\mymacro{2}{3}) -- (0); \end{tikzpicture} \end{document} –  Berso Mar 9 '12 at 7:55

In a chat session, we have defined two of these node shapes as the following and the others are asked to the community in this question.

\documentclass{article}
\usepackage{tikz}

\makeatletter
\pgfdeclareshape{pinode}{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}

\backgroundpath{%
\pgfpathrectanglecorners{\southwest}{\northeast}
\northeast \pgf@xa=0\pgf@x \pgf@ya=\pgf@y \pgf@xb=\pgf@x
\southwest \pgf@yc = \pgf@y \pgf@yb=0pt
\pgfpathmoveto{\pgfpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpoint{\pgf@xa}{\pgf@yc}}
\pgfusepath{stroke}
}
}
\pgfdeclareshape{arrowednode}{
\inheritsavedanchors[from=rectangle]
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\backgroundpath{%
\pgfpathrectanglecorners{\southwest}{\northeast}
\pgfusepath{stroke}
\northeast \pgf@ya=\pgf@y
\southwest \pgf@xa= \pgf@x
\pgfsetarrowsstart{stealth}
\pgfusepath{stroke}
}
}
\makeatother

\begin{document}
\begin{tikzpicture}
\draw[opacity=0.2,style=help lines] (-1,-1) grid[step=1cm] (6cm,6cm);
\node [draw,arrowednode,inner sep=5mm] (a) at (0,4) {Y};
\node [draw,pinode,inner sep=5mm] (b) at (4,5) {PI};
\node [draw,arrowednode,inner sep=0.5cm] (c) at (0,2) {X};
\node [draw,pinode,inner sep=0.5cm] (d) at (0,0) {Z};
\draw[->,thick] (d.east)-| ++(1.5,0) |- (b.205);
\draw[->,thick] (c.east)-| ++(1,0) |- (b.180);
\draw[->,thick] (a.east)-| ++ (0.5cm,1cm) |- (b.155);
\end{tikzpicture}
\end{document}


-