<commit_before>"use strict";

define(['logManager', './AutoRouter', './Profiler'], function (logManager, AutoRouter, Profiler) {

    var ConnectionRouteManager3,
        DESIGNERITEM_SUBCOMPONENT_SEPARATOR = "_x_";

    ConnectionRouteManager3 = function (options) {
        this.logger = (options && options.logger) || logManager.create(((options && options.loggerName) || "ConnectionRouteManager3"));

        this.diagramDesigner = options ? options.diagramDesigner : null;

        if (this.diagramDesigner === undefined || this.diagramDesigner === null) {
            this.logger.error("Trying to initialize a ConnectionRouteManager3 without a canvas...");
            throw ("ConnectionRouteManager3 can not be created");
        }

        this.autorouter = new AutoRouter();

        this.profiler = new Profiler('AutoRouter');

        this.logger.debug("ConnectionRouteManager3 ctor finished");
    };

    ConnectionRouteManager3.prototype.initialize = function () {
        //Define container that will map obj+subID -> box
        this._autorouterBoxes = {};
        this._autorouterPorts = {}; //Maps boxIds to an array of port ids that have been mapped
        this._autorouterPaths = {};
        this.autorouter.clear();

        //Adding event listeners
        var self = this;

/*
        this._onComponentUpdate = function(_canvas, ID) {//Boxes and lines
            //this.diagramDesigner.itemIds
            //this.diagramDesigner.connectionIds
            self.logger.warning("ON_COMPONENT_UPDATE: " + ID);
            //self.autorouter.setBox();
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_COMPONENT_UPDATE, this._onComponentUpdate);
*/

        this._onComponentCreate = function(_canvas, ID) {//Boxes and lines
            self.logger.warning("Added Component: " + ID);
            self.insertItem( ID );
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_COMPONENT_CREATE, this._onComponentCreate);

        this._onComponentResize = function(_canvas, ID) {//Boxes and lines
            self.logger.warning("Resized Component: " + ID.ID); 
            if( self._autorouterBoxes[ID.ID] )
                self._resizeItem( ID.ID );
            else
                self.insertItem( ID.ID );
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ITEM_SIZE_CHANGED, this._onComponentResize);

        this._onComponentDelete = function(_canvas, ID) {//Boxes and lines
            self.logger.warning("Deleting : " + ID);
            self.deleteItem( ID );
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_COMPONENT_DELETE, this._onComponentDelete);
        //ON_UNREGISTER_SUBCOMPONENT

        this._onItemPositionChanged = function(_canvas, eventArgs) {
            if( self._autorouterBoxes[eventArgs.ID] )
                self.autorouter.move(self._autorouterBoxes[eventArgs.ID].box, { "dx": eventArgs.x, "dy": eventArgs.y });
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ITEM_POSITION_CHANGED, this._onItemPositionChanged);

        this._onClear = function(_canvas, eventArgs) {
            self.logger.warning("Clearing...");
            self._initializeGraph();
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_CLEAR, this._onClear);

    };

    ConnectionRouteManager3.prototype.destroy = function () {
        //removeEventListener(eventName, handler);
        //this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_COMPONENT_UPDATE, this._onComponentUpdate);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_COMPONENT_CREATE, this._onComponentCreate);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ITEM_SIZE_CHANGED, this._onComponentResize);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_COMPONENT_DELETE, this._onComponentDelete);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ITEM_POSITION_CHANGED, this._onItemPositionChanged);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_CLEAR, this._onClear);
    };

    ConnectionRouteManager3.prototype.redrawConnections = function (idList) {
        var i;

        console.log('About to REDRAW');

        this.profiler.clear();
        this.profiler.startProfile('redrawConnections');


        //no matter what, we want the id's of all the connections
        //not just the ones that explicitly needs rerouting
        idList = this.diagramDesigner.connectionIds.slice(0);

        i = idList.length;

        //0 - clear out autorouter
        //this.autorouter.clear();

        this.profiler.startProfile('_updateBoxesAndPorts');
        //1 - update all box information the connection endpoint connectable area information
        this._updateBoxesAndPorts(idList);
        this.profiler.endProfile('_updateBoxesAndPorts');

        this.profiler.startProfile('_updateConnectionCoordinates');
        //2 - we have each connection end connectability info
        //find the closest areas for each connection
        while (i--) {
            this._updateConnectionCoordinates(idList[i]);
        }
        this.profiler.endProfile('_updateConnectionCoordinates');


        //3 autoroute
        this.profiler.startProfile('autoroute');
        this.autorouter.autoroute();
        this.profiler.endProfile('autoroute');

        //4 - Get the path points and redraw
        this.profiler.startProfile('setConnectionRenderData');
        var pathPoints,
            realPathPoints;
        for (i = 0; i < idList.length; i += 1) {
            pathPoints = this.autorouter.getPathPoints(this._autorouterPaths[idList[i]]);
            realPathPoints = [];
            for(var j = 0; j < pathPoints.length; j++){
                realPathPoints.push({'x': pathPoints[j][0], 'y': pathPoints[j][1] });
            }

            this.diagramDesigner.items[idList[i]].setConnectionRenderData(realPathPoints);
        }
        this.profiler.endProfile('setConnectionRenderData');

        //need to return the IDs of the connections that was really
        //redrawn or any other visual property chenged (width, etc)

        this.profiler.endProfile('redrawConnections');
        this.profiler.dump();

        return idList;
    };

    ConnectionRouteManager3.prototype._initializeGraph = function () {
        /*
         * In this method, we will update the boxes using the canvas.itemIds list and
         * add any ports as needed (from the canvas.connectionIds)
         */
        var canvas = this.diagramDesigner,
            connIdList = canvas.connectionIds,
            itemIdList = canvas.itemIds,
            i = itemIdList.length,
            connId,
            srcObjId,
            srcSubCompId,
            dstObjId,
            dstSubCompId;

        this.autorouter.clear();
        this._autorouterBoxes = {};
        this._autorouterPorts = {};
        this._autorouterPaths = {};

        this.endpointConnectionAreaInfo = {};

        while(i--){
            this.insertItem(itemIdList[i]);
        }
<commit_msg>Adjusted the redrawConnections method to only redraw and not initialize boxes/ports.<commit_after>"use strict";

define(['logManager', './AutoRouter', './Profiler'], function (logManager, AutoRouter, Profiler) {

    var ConnectionRouteManager3,
        DESIGNERITEM_SUBCOMPONENT_SEPARATOR = "_x_";

    ConnectionRouteManager3 = function (options) {
        this.logger = (options && options.logger) || logManager.create(((options && options.loggerName) || "ConnectionRouteManager3"));

        this.diagramDesigner = options ? options.diagramDesigner : null;

        if (this.diagramDesigner === undefined || this.diagramDesigner === null) {
            this.logger.error("Trying to initialize a ConnectionRouteManager3 without a canvas...");
            throw ("ConnectionRouteManager3 can not be created");
        }

        this.autorouter = new AutoRouter();

        this.profiler = new Profiler('AutoRouter');

        this.logger.debug("ConnectionRouteManager3 ctor finished");
    };

    ConnectionRouteManager3.prototype.initialize = function () {
        this._initializeGraph();

        //Adding event listeners
        var self = this;

/*
        this._onComponentUpdate = function(_canvas, ID) {//Boxes and lines
            //this.diagramDesigner.itemIds
            //this.diagramDesigner.connectionIds
            self.logger.warning("ON_COMPONENT_UPDATE: " + ID);
            //self.autorouter.setBox();
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_COMPONENT_UPDATE, this._onComponentUpdate);
*/

        this._onComponentCreate = function(_canvas, ID) {//Boxes and lines
            self.insertItem( ID );
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_COMPONENT_CREATE, this._onComponentCreate);

        this._onComponentResize = function(_canvas, ID) {//Boxes and lines
            if( self._autorouterBoxes[ID.ID] )
                self._resizeItem( ID.ID );
            else
                self.insertItem( ID.ID );
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ITEM_SIZE_CHANGED, this._onComponentResize);

        this._onComponentDelete = function(_canvas, ID) {//Boxes and lines
            self.deleteItem( ID );
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_COMPONENT_DELETE, this._onComponentDelete);
        //ON_UNREGISTER_SUBCOMPONENT

        this._onItemPositionChanged = function(_canvas, eventArgs) {
            if( self._autorouterBoxes[eventArgs.ID] )
                self.autorouter.move(self._autorouterBoxes[eventArgs.ID].box, { "x": eventArgs.x, "y": eventArgs.y });
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ITEM_POSITION_CHANGED, this._onItemPositionChanged);

        this._onClear = function(_canvas, eventArgs) {
            self.logger.warning("Clearing Screen");
            self._initializeGraph();
        };
        this.diagramDesigner.addEventListener(this.diagramDesigner.events.ON_CLEAR, this._onClear);

    };

    ConnectionRouteManager3.prototype.destroy = function () {
        //removeEventListener(eventName, handler);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_COMPONENT_CREATE, this._onComponentCreate);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ITEM_SIZE_CHANGED, this._onComponentResize);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_COMPONENT_DELETE, this._onComponentDelete);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ITEM_POSITION_CHANGED, this._onItemPositionChanged);
        this.diagramDesigner.removeEventListener(this.diagramDesigner.events.ON_CLEAR, this._onClear);
    };

    ConnectionRouteManager3.prototype.redrawConnections = function (idList) {
        var i;

        console.log('About to REDRAW');

        this.profiler.clear();
        this.profiler.startProfile('redrawConnections');


        //no matter what, we want the id's of all the connections
        //not just the ones that explicitly needs rerouting
        idList = this.diagramDesigner.connectionIds.slice(0);

        i = idList.length;

        this.profiler.startProfile('_updateConnectionCoordinates');
        //1 - we have each connection end connectability info
        //find the closest areas for each connection
        while (i--) {
            this._updateConnectionCoordinates(idList[i]);
        }
        this.profiler.endProfile('_updateConnectionCoordinates');


        //2 - autoroute
        this.profiler.startProfile('autoroute');
        this.autorouter.autoroute();
        this.profiler.endProfile('autoroute');

        //3 - Get the path points and redraw
        this.profiler.startProfile('setConnectionRenderData');
        var pathPoints,
            realPathPoints;
        for (i = 0; i < idList.length; i += 1) {
            pathPoints = this.autorouter.getPathPoints(this._autorouterPaths[idList[i]]);
            realPathPoints = [];
            for(var j = 0; j < pathPoints.length; j++){
                realPathPoints.push({'x': pathPoints[j][0], 'y': pathPoints[j][1] });
            }

            this.diagramDesigner.items[idList[i]].setConnectionRenderData(realPathPoints);
        }
        this.profiler.endProfile('setConnectionRenderData');

        //need to return the IDs of the connections that was really
        //redrawn or any other visual property changed (width, etc)

        this.profiler.endProfile('redrawConnections');
        this.profiler.dump();

        return idList;
    };

    ConnectionRouteManager3.prototype._initializeGraph = function () {
        /*
         * In this method, we will update the boxes using the canvas.itemIds list and
         * add any ports as needed (from the canvas.connectionIds)
         */
        this.logger.warning("Initializing Screen");
        
        var canvas = this.diagramDesigner,
            connIdList = canvas.connectionIds,
            itemIdList = canvas.itemIds,
            i = itemIdList.length,
            connId,
            srcObjId,
            srcSubCompId,
            dstObjId,
            dstSubCompId;

        this.autorouter.clear();
        this._autorouterBoxes = {};//Define container that will map obj+subID -> box
        this._autorouterPorts = {};//Maps boxIds to an array of port ids that have been mapped
        this._autorouterPaths = {};

        this.endpointConnectionAreaInfo = {};

        while(i--){
            this.insertItem(itemIdList[i]);
        }

{'fraction_non_alphanumeric': 0.10612185965925498, 'fraction_numerical': 0.0028876696505919725, 'mean_word_length': 2.682349813928761, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 5, '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': '2012606', 'n_tokens_mistral': 3801, 'n_tokens_neox': 3786, 'n_words': 691}