# all files / bpmn-js/lib/features/modeling/ BpmnFactory.js

100% Statements 28/28
87.5% Branches 7/8
100% Functions 12/12
100% Lines 28/28

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105

    1189×

    1×

    1×
    6198×

    1×

    6923×

    6923×
    945×

    1×
    6923×

    6923×

    6923×

    1×
    73×

    1×

    509×

    1×
    583×

    1×
    1740×

    1740×
    4446×

    1×
    4446×

    1×
    216×

    1×
    31×

     import {
      map,
      assign,
      pick
    } from 'min-dash';

    import {
      isAny
    } from './util/ModelingUtil';

    export default function BpmnFactory(moddle) {
      this._model = moddle;
    }

    BpmnFactory.$inject = [ 'moddle' ];

    BpmnFactory.prototype._needsId = function(element) {
      return isAny(element, [
        'bpmn:RootElement',
        'bpmn:FlowElement',
        'bpmn:MessageFlow',
        'bpmn:DataAssociation',
        'bpmn:Artifact',
        'bpmn:Participant',
        'bpmn:Lane',
        'bpmn:LaneSet',
        'bpmn:Process',
        'bpmn:Collaboration',
        'bpmndi:BPMNShape',
        'bpmndi:BPMNEdge',
        'bpmndi:BPMNDiagram',
        'bpmndi:BPMNPlane',
        'bpmn:Property',
        'bpmn:CategoryValue'
      ]);
    };

    BpmnFactory.prototype._ensureId = function(element) {

      // generate semantic ids for elements
      // bpmn:SequenceFlow -> SequenceFlow_ID
      var prefix = (element.$type || '').replace(/^[^:]*:/g, '') + '_';

      if (!element.id && this._needsId(element)) {
        element.id = this._model.ids.nextPrefixed(prefix, element);
      }
    };

    BpmnFactory.prototype.create = function(type, attrs) {
      var element = this._model.create(type, attrs || {});

      this._ensureId(element);

      return element;
    };

    BpmnFactory.prototype.createDiLabel = function() {
      return this.create('bpmndi:BPMNLabel', {
        bounds: this.createDiBounds()
      });
    };

    BpmnFactory.prototype.createDiShape = function(semantic, bounds, attrs) {

      return this.create('bpmndi:BPMNShape', assign({
        bpmnElement: semantic,
        bounds: this.createDiBounds(bounds)
      }, attrs));
    };

    BpmnFactory.prototype.createDiBounds = function(bounds) {
      return this.create('dc:Bounds', bounds);
    };

    BpmnFactory.prototype.createDiWaypoints = function(waypoints) {
      var self = this;

      return map(waypoints, function(pos) {
        return self.createDiWaypoint(pos);
      });
    };

    BpmnFactory.prototype.createDiWaypoint = function(point) {
      return this.create('dc:Point', pick(point, [ 'x', 'y' ]));
    };

    BpmnFactory.prototype.createDiEdge = function(semantic, waypoints, attrs) {
      return this.create('bpmndi:BPMNEdge', assign({
        bpmnElement: semantic
      }, attrs));
    };

    BpmnFactory.prototype.createDiPlane = function(semantic) {
      return this.create('bpmndi:BPMNPlane', {
        bpmnElement: semantic
      });
    };