绘制内部节点以获取 BPMN 网关形状

绘制内部节点以获取 BPMN 网关形状

这个问题是如何使用节点样式在 TikZ 节点内部绘图?

我正在尝试从 BPMN 获取AND网关XOR,如下所示http://www.omg.org/bpmn/Samples/Elements/Gateways.GIF

作为起点,我找到了这个样式文件https://github.com/sbadia/gdeploy/blob/master/francegrilles/tikz-bpmn.sty但为了在网关中得到加号和 x,我必须将它们设置为文本。这看起来一点也不好看……我该如何为网关绘制一个粗“加号”,AND并为添加相同的旋转 45° 的份额XOR?“粗”的意思是它比形状的边框厚得多。还要注意,加号和 x 实际上都没有到达周围形状的边框。

BPMN 网关参考

答案1

我基于菱形创建了三种新形状。如果您需要缩放这些形状,并且需要缩放圆形、十字形、+ 等...,那么选择另一种方式在菱形内部进行绘制会很有趣。只有 EB 定义明确,对于所有其他形状,您需要绘制路径并填充它。但这需要大量工作。

图片

业务流程管理模型

代码

\documentclass[11pt]{scrartcl}
\usepackage{tikz} 
\usetikzlibrary{shapes}
\makeatletter

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

  \backgroundpath{
    \pgf@process{\outernortheast}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@ya}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@xc by-1.414213\pgf@xa%
    \advance\pgf@yc by-1.414213\pgf@ya%
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}%
    \pgfpathclose\pgfusepath{stroke} 
    % add 
    \advance\pgf@xc by -.5\pgf@xc% 
    \advance\pgf@yc by -.5\pgf@yc%
    \pgfsetlinewidth{2pt}
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}%
    \pgfpathmoveto{\pgfqpoint{0.707\pgf@xc}{0.707\pgf@yc}}%
     \pgfpathlineto{\pgfqpoint{-0.707\pgf@xc}{-0.707\pgf@yc}}%
     \pgfpathmoveto{\pgfqpoint{-0.707\pgf@xc}{0.707\pgf@yc}}%
     \pgfpathlineto{\pgfqpoint{0.707\pgf@xc}{-0.707\pgf@yc}}%  
      }
}

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

  \backgroundpath{
    \pgf@process{\outernortheast}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@ya}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@xc by-1.414213\pgf@xa%
    \advance\pgf@yc by-1.414213\pgf@ya%
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}%
    \pgfpathclose\pgfusepath{stroke} 
    % add 
    \advance\pgf@xc by -.5\pgf@xc% 
    \advance\pgf@yc by -.5\pgf@yc%
    \pgfsetlinewidth{2pt}
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathmoveto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}% 
      }
}

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

  \backgroundpath{
    \pgf@process{\outernortheast}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@ya}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@xc by-1.414213\pgf@xa%
    \advance\pgf@yc by-1.414213\pgf@ya%
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}%
    \pgfpathclose\pgfusepath{stroke}
    % add 
    \pgfsetlinewidth{2pt}
    \pgfutil@tempdima=\pgf@xc%
    \pgfutil@tempdima=0.5\pgfutil@tempdima%
    \pgfpathcircle{\pgfpointorigin}{\pgfutil@tempdima}
      }
} 

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

  \backgroundpath{
    \pgf@process{\outernortheast}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@ya}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@xc by-1.414213\pgf@xa%
    \advance\pgf@yc by-1.414213\pgf@ya%
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}%
    \pgfpathclose\pgfusepath{stroke}
    % add 
    \pgfutil@tempdima=\pgf@xc%
    \pgfutil@tempdima=0.6\pgfutil@tempdima%
    \pgfpathcircle{\pgfpointorigin}{\pgfutil@tempdima} 
        \pgfutil@tempdima=0.8\pgfutil@tempdima%
    \pgfpathcircle{\pgfpointorigin}{\pgfutil@tempdima}
     \pgfusepath{stroke} 
    %add 
        \pgfpathmoveto{\pgfqpoint{0pt}{\pgfutil@tempdima}}%
        \pgfpathlineto{\pgfqpoint{0.25\pgfutil@tempdima}{0.433\pgfutil@tempdima}}% 
        \pgfpathlineto{\pgfqpoint{0.866\pgfutil@tempdima}{0.5\pgfutil@tempdima}}%
        \pgfpathlineto{\pgfqpoint{0.5\pgfutil@tempdima}{0pt}}%
        \pgfpathlineto{\pgfqpoint{0.866\pgfutil@tempdima}{-0.5\pgfutil@tempdima}}%   
        \pgfpathlineto{\pgfqpoint{0.25\pgfutil@tempdima}{-0.433\pgfutil@tempdima}}% 
        \pgfpathlineto{\pgfqpoint{0pt}{-\pgfutil@tempdima}}% 
        \pgfpathlineto{\pgfqpoint{-0.25\pgfutil@tempdima}{-0.433\pgfutil@tempdima}}%    
        \pgfpathlineto{\pgfqpoint{-0.866\pgfutil@tempdima}{-0.5\pgfutil@tempdima}}%
        \pgfpathlineto{\pgfqpoint{-0.5\pgfutil@tempdima}{0pt}}%    
        \pgfpathlineto{\pgfqpoint{-0.866\pgfutil@tempdima}{0.5\pgfutil@tempdima}}% 
        \pgfpathlineto{\pgfqpoint{-0.25\pgfutil@tempdima}{0.433\pgfutil@tempdima}}%
        \pgfpathclose 
        \pgfusepath{fill}
       }
}  

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

  \backgroundpath{
    \pgf@process{\outernortheast}%
    \pgf@xc=\pgf@x%
    \pgf@yc=\pgf@y%
    \pgfmathsetlength{\pgf@xa}{\pgfkeysvalueof{/pgf/outer xsep}}%
    \pgfmathsetlength{\pgf@ya}{\pgfkeysvalueof{/pgf/outer ysep}}%
    \advance\pgf@xc by-1.414213\pgf@xa%
    \advance\pgf@yc by-1.414213\pgf@ya%
    \pgfpathmoveto{\pgfqpoint{\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{\pgf@yc}}%
    \pgfpathlineto{\pgfqpoint{-\pgf@xc}{0pt}}%
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgf@yc}}%
    \pgfpathclose\pgfusepath{stroke}
    %add 
    \advance\pgf@xc by -.5\pgf@xc% 
    \pgfsetlinewidth{2pt}
    \pgfpathmoveto{\pgfqpoint{ 0.6\pgf@xc}{0.8484\pgf@xc}}%
    \pgfpathlineto{\pgfqpoint{-0.6\pgf@xc}{-0.8484\pgf@xc}}%
    \pgfpathmoveto{\pgfqpoint{-0.6\pgf@xc}{0.8484\pgf@xc}}%
    \pgfpathlineto{\pgfqpoint{ 0.6\pgf@xc}{-0.8484\pgf@xc}}%  
    }
} 
\begin{document}

\begin{tikzpicture}
  \node[draw,shape=CD,minimum size=1cm] (x) {};
  \node[draw,shape=PF,minimum size=1cm] at ([shift=(0:5cm)]x) (y) {};
  \node[draw,shape=ID,minimum size=1cm] at ([shift=(90:5cm)]x) (z) {};
  \node[draw,shape=EB,minimum size=1cm] at ([shift=(0:5cm)]z) (t) {};
  \node[draw,shape=XOR,minimum size=1cm] at ([shift=(-30:3cm)]t) (v) {};   
  \draw[dashed,ultra thick] (x) -- (y) -- (z)--(t) -- (v);
\end{tikzpicture}

\end{document}

答案2

几年前我也遇到过类似的请求。我写了一个辅助库。请随意使用:https://blog.kubovy.eu/2013/10/04/latex-tikz-bpmn-2-0-gateways/

相关内容