<commit_before>'use strict';

var _ = require('lodash');


/**
 * The basic modeling entry point.
 *
 * @param {EventBus} eventBus
 * @param {CommandStack} commandStack
 */
function Modeling(eventBus, commandStack) {
  this._commandStack = commandStack;
  this._eventBus = eventBus;

  var self = this;

  eventBus.on('diagram.init', function() {
    // register modeling handlers
    self.registerHandlers(commandStack);
  });
}

module.exports = Modeling;


/**
 * Register handlers with the command stack
 *
 * @param {CommandStack} commandStack
 */
Modeling.prototype.registerHandlers = function(commandStack) {
  commandStack.registerHandler('shape.create', require('./cmd/CreateShapeHandler'));
  commandStack.registerHandler('shape.move', require('./cmd/MoveShapeHandler'));

  commandStack.registerHandler('shape.append', require('./cmd/AppendShapeHandler'));

  commandStack.registerHandler('label.create', require('./cmd/CreateLabelHandler'));

  commandStack.registerHandler('connection.create', require('./cmd/CreateConnectionHandler'));
  commandStack.registerHandler('connection.layout', require('./cmd/LayoutConnectionHandler'));
};



///// modeling helpers /////////////////////////////////////////


Modeling.prototype.createConnection = function(source, target, attrs, parent) {

  var context = {
    source: source,
    target: target,
    parent: parent,
    attrs: attrs
  };

  this._commandStack.execute('connection.create', context);

  return context.connection;
};


Modeling.prototype.moveShape = function(shape, delta, newParent) {

  var context = {
    shape: shape,
    delta: delta,
    newParent: newParent
  };

  this._commandStack.execute('shape.move', context);
};


Modeling.prototype.layoutConnection = function(connection) {

  var context = {
    connection: connection
  };

  this._commandStack.execute('connection.layout', context);
};


Modeling.prototype.createShape = function(attrs, position, parent) {

  var context = {
    attrs: attrs,
    position: position,
    parent: parent
  };

  this._commandStack.execute('shape.create', context);

  return context.shape;
};


Modeling.prototype.createLabel = function(labelTarget, position, attrs, parent) {

  var context = {
    labelTarget: labelTarget,
    position: position,
    attrs: attrs,
    parent: parent
  };

  this._commandStack.execute('label.create', context);

  return context.shape;
};


Modeling.prototype.appendShape = function(source, attrs, position, parent) {

  var context = {
    source: source,
    attrs: attrs,
    position: position,
    parent: parent
  };

  this._commandStack.execute('shape.append', context);

  return context.shape;
};<commit_msg>improve(modeling): #appendShape add connection info<commit_after>'use strict';

var _ = require('lodash');


/**
 * The basic modeling entry point.
 *
 * @param {EventBus} eventBus
 * @param {CommandStack} commandStack
 */
function Modeling(eventBus, commandStack) {
  this._commandStack = commandStack;
  this._eventBus = eventBus;

  var self = this;

  eventBus.on('diagram.init', function() {
    // register modeling handlers
    self.registerHandlers(commandStack);
  });
}

module.exports = Modeling;


/**
 * Register handlers with the command stack
 *
 * @param {CommandStack} commandStack
 */
Modeling.prototype.registerHandlers = function(commandStack) {
  commandStack.registerHandler('shape.create', require('./cmd/CreateShapeHandler'));
  commandStack.registerHandler('shape.move', require('./cmd/MoveShapeHandler'));

  commandStack.registerHandler('shape.append', require('./cmd/AppendShapeHandler'));

  commandStack.registerHandler('label.create', require('./cmd/CreateLabelHandler'));

  commandStack.registerHandler('connection.create', require('./cmd/CreateConnectionHandler'));
  commandStack.registerHandler('connection.layout', require('./cmd/LayoutConnectionHandler'));
};



///// modeling helpers /////////////////////////////////////////


Modeling.prototype.createConnection = function(source, target, attrs, parent) {

  var context = {
    source: source,
    target: target,
    parent: parent,
    attrs: attrs
  };

  this._commandStack.execute('connection.create', context);

  return context.connection;
};


Modeling.prototype.moveShape = function(shape, delta, newParent) {

  var context = {
    shape: shape,
    delta: delta,
    newParent: newParent
  };

  this._commandStack.execute('shape.move', context);
};


Modeling.prototype.layoutConnection = function(connection) {

  var context = {
    connection: connection
  };

  this._commandStack.execute('connection.layout', context);
};


Modeling.prototype.createShape = function(attrs, position, parent) {

  var context = {
    attrs: attrs,
    position: position,
    parent: parent
  };

  this._commandStack.execute('shape.create', context);

  return context.shape;
};


Modeling.prototype.createLabel = function(labelTarget, position, attrs, parent) {

  var context = {
    labelTarget: labelTarget,
    position: position,
    attrs: attrs,
    parent: parent
  };

  this._commandStack.execute('label.create', context);

  return context.shape;
};


Modeling.prototype.appendShape = function(source, attrs, position, connection, parent) {

  var context = {
    source: source,
    attrs: attrs,
    position: position,
    connection: connection,
    parent: parent
  };

  this._commandStack.execute('shape.append', context);

  return context.shape;
};
{'fraction_non_alphanumeric': 0.14671318398824826, 'fraction_numerical': 0.0, 'mean_word_length': 3.9789762340036563, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4102422', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1484, 'n_words': 313}