Re: [Tutorial] Grafica ad oggetti con TikZ

#82202
Up
0
Down
::


Hai imposto che [tt]mod1[/tt] è alle coordinate [tt]x=20[/tt] e [tt]y=0[/tt] attraverso:`\mod.set and draw(mod1,Bisogni educativi speciali,20,0)` Esistono fondamentalmente due strade per operare: specificando sempre le coordinate dell’oggetto con [tt].set and draw[/tt] oppure usando riferimenti relativi (nello stesso modo di TikZ tradizionale) con [tt].set and place[/tt].

Per le connessioni potresti anche usare un apposito metodo:`\documentclass{article}

\usepackage{lmodern}

\usepackage{tikz}
\usepgfmodule{oo}
\usetikzlibrary{positioning}

\pgfooclass{module}{

% class attributes
\attribute text;
\attribute text width=2.5cm;
\attribute border color=orange;
\attribute top color=none;
\attribute bottom color=none;
\attribute text color=black;
\attribute label;
\attribute width=3cm;
\attribute height=1cm;

% constructor method
\method module() {
}

\method text(#1) {
\pgfooset{text}{#1}
}

\method set text width(#1) {
\pgfooset{text width}{#1}
}

\method set border color(#1) {
\pgfooset{border color}{#1}
}

\method set top color(#1) {
\pgfooset{top color}{#1}
}

\method set bottom color(#1) {
\pgfooset{bottom color}{#1}
}

\method set text color(#1) {
\pgfooset{text color}{#1}
}

\method set label(#1) {
\pgfooset{label}{#1}
}

\method set width(#1) {
\pgfooset{width}{#1}
}

\method set height(#1) {
\pgfooset{height}{#1}
}

\method draw(#1,#2) {
\node [rectangle,
rounded corners,
draw=\pgfoovalueof{border color},
top color=\pgfoovalueof{top color},
bottom color=\pgfoovalueof{bottom color},
text=\pgfoovalueof{text color},
align=center,
text width=\pgfoovalueof{text width},
minimum width=\pgfoovalueof{width},
minimum height=\pgfoovalueof{height},
] (\pgfoovalueof{label}) at (#1,#2) {\pgfoovalueof{text}};
}

\method place(#1) {
\node [rectangle,
rounded corners,
draw=\pgfoovalueof{border color},
top color=\pgfoovalueof{top color},
bottom color=\pgfoovalueof{bottom color},
text=\pgfoovalueof{text color},
align=center,
text width=\pgfoovalueof{text width},
minimum width=\pgfoovalueof{width},
minimum height=\pgfoovalueof{height},
#1
] (\pgfoovalueof{label}) {\pgfoovalueof{text}};
}

% shortcut method to easily set labels, text and draw
% use the \pgfoothis to refer to the current object
\method set and draw(#1,#2,#3,#4) {
\pgfoothis.set label(#1)
\pgfoothis.text(#2)
\pgfoothis.draw(#3,#4)
}

% shortcut method to easily set labels, text and place
% objects
\method set and place(#1,#2,#3) {
\pgfoothis.set label(#1)
\pgfoothis.text(#2)
\pgfoothis.place(#3)
}

% shortcut method to easily set the style
\method set style(#1,#2,#3) {
\pgfoothis.set border color(#1)
\pgfoothis.set top color(#2)
\pgfoothis.set bottom color(#3)
}

% shortcut method to easily set the dimensions
\method set dimensions(#1,#2,#3) {
\pgfoothis.set width(#1)
\pgfoothis.set height(#2)
\pgfoothis.set text width(#3)
}

% appositi metodi di connessione
\method connect(#1,#2) {
\draw[->] (#1)–(#2);
}

\method multi connect(#1) {
\foreach \i in {#1}{
\draw[->] (\pgfoovalueof{label})–(\i);
}
}

}

\begin{document}

\begin{tikzpicture}[node distance=4.5cm,scale=0.75, transform shape]
% declaring the new object with the constructor method
\pgfoonew \mod=new module()

% method set style:
% #1= border color
% #2= top color
% #3= bottom color
\mod.set style(black,white,white)

% method set and draw:
% #1= label of the node
% #2= text
% #3,#4= coordinates
\mod.set and draw(mod1,Bisogni educativi speciali,20,0)

% \mod.set style(blue!50!cyan,blue!50!cyan!40,blue!50!cyan!5)

% method set dimensions:
% #1= module width
% #2= module height
% #3= text width
%\mod.set dimensions(5cm,1cm,4.9cm)

% method set and place:
% #1= label of the node
% #2= text
% #3= position with respect to another node identified with a label
\mod.set and place(mod2,{\mbox{Motivi fisici}} ,below left of=mod1)
\mod.set and place(mod3,{\mbox{Motivi biologici}} ,right of=mod2)
\mod.set and place(mod4,{\mbox{Motivi sociali}} ,right of=mod3)
\mod.set and place(mod5,{\mbox{Motivi fisiologici}} ,right of=mod4)
\mod.set and place(mod6,{\mbox{Motivi fisiologici}} ,right of=mod5)

% l'ultimo oggetto ha label mod6 quindi no posso usare multi connect
% \mod.multi connect(mod1,mod2,mod3,mod4,mod5)
% prova per capire cosa succede

\mod.connect(mod1,mod2)
\mod.connect(mod1,mod3)
\mod.connect(mod1,mod4)
\mod.connect(mod1,mod5)
\mod.connect(mod1,mod6)

\end{tikzpicture}
\end{document}
`
Ciao
Claudio

Go to top