<commit_before>var createFeatureAddedMethod = function(injectedMethods, geomType) {


    /**
     * @param {(OpenLayers.Feature | OpenLayers.Feature.Vector)} feature
     */
    var func = function (feature) {

        _.each(injectedMethods.getDefaultAttributes(), function(prop) {
            feature.attributes[prop] = "";
        });

        feature.attributes.geomType = geomType;


        injectedMethods.setModifiedState(feature,this);
        injectedMethods.deactivateCurrentControl();
        injectedMethods.openFeatureEditDialog(feature);
        feature.redraw();
    };

    return func;

};

var finalizePolygonValidOnly = function(cancel) {
    var wkt = this.polygon.geometry.toString();
    var reader = new jsts.io.WKTReader();
    var geom = reader.read(wkt);
    if (!geom.isValid()) {
        $.notify("Geometry not valid");
        this.destroyFeature(cancel);
        return;
    }

    return OpenLayers.Handler.Polygon.prototype.finalize.apply(this,arguments);
};


var DigitizingControlFactory = function (layer,injectedMethods,controlEvents) {

    var controls =  {

        drawText:  new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point,{
            featureAdded :  createFeatureAddedMethod(injectedMethods, 'label'),
        }),

        drawPoint: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point,{
            featureAdded : createFeatureAddedMethod(injectedMethods, 'point'),
        }),

        drawLine: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path,{
            featureAdded : createFeatureAddedMethod(injectedMethods, 'line'),
        }),

        drawPolygon: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
              finalize: finalizePolygonValidOnly,
            }
        }),


    drawRectangle: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.RegularPolygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
                sides: 4,
                irregular: true
            }
        }),

        drawCircle: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.RegularPolygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
                sides: 40
            }
        }),

        drawEllipse: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.RegularPolygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
                sides: 40,
                irregular: true
            }
        }),

        drawDonut: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {
            featureAdded : function() { console.warn("donut should not be created") },
            handlerOptions: {
                holeModifier: 'element',
                // Allow control only to draw holes in polygon, not to draw polygons themselves.
                addPoint: function(pixel) {
                    if(!this.drawingHole && this.evt && this.evt[this.holeModifier]) {
                        var geometry = this.point.geometry;
                        var features = this.control.layer.features;
                        var candidate, polygon;
                        // look for intersections, last drawn gets priority
                        for (var i=features.length-1; i>=0; --i) {
                            candidate = features[i].geometry;
                            if ((candidate instanceof OpenLayers.Geometry.Polygon ||
                                candidate instanceof OpenLayers.Geometry.MultiPolygon) &&
                                candidate.intersects(geometry)) {
                                polygon = features[i];
                                this.control.layer.removeFeatures([polygon], {silent: true});
                                this.control.layer.events.registerPriority(
                                    "sketchcomplete", this, this.finalizeInteriorRing
                                );
                                this.control.layer.events.registerPriority(
                                    "sketchmodified", this, this.enforceTopology
                                );
                                polygon.geometry.addComponent(this.line.geometry);
                                this.polygon = polygon;
                                this.drawingHole = true;
                                break;
                            }
                        }
                    }
                    if (!this.drawingHole) {
                        return;
                    }
                    OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments);
                },
                finalizeInteriorRing : function(event) {

                    var fir =  OpenLayers.Handler.Polygon.prototype.finalizeInteriorRing.apply(this, arguments);
                    injectedMethods.setModifiedState(this.polygon,this.control);
                    return fir;
                },
                finalize: finalizePolygonValidOnly,
            },

            activate: function() {
                this.layer.map.controls.forEach(function(control) {
                    if (control.dragPan) {
                        control.dragPan.deactivate();
                    }
                });
                OpenLayers.Control.DrawFeature.prototype.activate.apply(this,arguments);
            },

            deactivate: function() {
                this.layer.map.controls.forEach(function(control) {
                    if (control.dragPan) {
                        control.dragPan.activate();
                    }
                });
                OpenLayers.Control.DrawFeature.prototype.deactivate.apply(this,arguments);
            }


        }),

        modifyFeature: new OpenLayers.Control.ModifyFeature(layer,{

            /**
             * This function allows the easy use of the olEvent onModificationStart with the yml configurration
             * e.G. to prevent the modification or add additional data on modification
             * */

            onModificationStart: function (feature) {
                console.log("onModificationStart");

                if (injectedMethods.preventModification()) {
                    this.deactivate();
                    this.activate();
                    $.notify(Mapbender.DigitizerTranslator.translate('move.denied'));
                }


            },

            onModification: function (feature) {

                injectedMethods.setModifiedState(feature,this);
                console.log("onModification",feature);

            }
        }),

        moveFeature: new OpenLayers.Control.DragFeature(layer, {

            /**
             * * This function allows the easy use of the olEvent onStart( called on drag start) with the yml configurration
             * e.G. to prevent the move or add additional data on move
             * @param {(OpenLayers.Feature.Vector | OpenLayers.Feature)} feature
             * @param px
             */
            onStart: function (feature, px) {
                console.log("onStart");<commit_msg>Enable open FeatureEditDialog on Donut & Modification<commit_after>var createFeatureAddedMethod = function(injectedMethods, geomType) {


    /**
     * @param {(OpenLayers.Feature | OpenLayers.Feature.Vector)} feature
     */
    var func = function (feature) {

        _.each(injectedMethods.getDefaultAttributes(), function(prop) {
            feature.attributes[prop] = "";
        });

        feature.attributes.geomType = geomType;


        injectedMethods.setModifiedState(feature,this);
        injectedMethods.deactivateCurrentControl();
        injectedMethods.openFeatureEditDialog(feature);
        feature.redraw();
    };

    return func;

};

var finalizePolygonValidOnly = function(cancel) {
    var wkt = this.polygon.geometry.toString();
    var reader = new jsts.io.WKTReader();
    var geom = reader.read(wkt);
    if (!geom.isValid()) {
        $.notify("Geometry not valid");
        this.destroyFeature(cancel);
        return;
    }

    return OpenLayers.Handler.Polygon.prototype.finalize.apply(this,arguments);
};


var DigitizingControlFactory = function (layer,injectedMethods,controlEvents) {

    var controls =  {

        drawText:  new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point,{
            featureAdded :  createFeatureAddedMethod(injectedMethods, 'label'),
        }),

        drawPoint: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Point,{
            featureAdded : createFeatureAddedMethod(injectedMethods, 'point'),
        }),

        drawLine: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Path,{
            featureAdded : createFeatureAddedMethod(injectedMethods, 'line'),
        }),

        drawPolygon: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
              finalize: finalizePolygonValidOnly,
            }
        }),


    drawRectangle: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.RegularPolygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
                sides: 4,
                irregular: true
            }
        }),

        drawCircle: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.RegularPolygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
                sides: 40
            }
        }),

        drawEllipse: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.RegularPolygon, {
            featureAdded : createFeatureAddedMethod(injectedMethods, 'polygon'),
            handlerOptions: {
                sides: 40,
                irregular: true
            }
        }),

        drawDonut: new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler.Polygon, {
            featureAdded : function() { console.warn("donut should not be created") },
            handlerOptions: {
                holeModifier: 'element',
                // Allow control only to draw holes in polygon, not to draw polygons themselves.
                addPoint: function(pixel) {
                    if(!this.drawingHole && this.evt && this.evt[this.holeModifier]) {
                        var geometry = this.point.geometry;
                        var features = this.control.layer.features;
                        var candidate, polygon;
                        // look for intersections, last drawn gets priority
                        for (var i=features.length-1; i>=0; --i) {
                            candidate = features[i].geometry;
                            if ((candidate instanceof OpenLayers.Geometry.Polygon ||
                                candidate instanceof OpenLayers.Geometry.MultiPolygon) &&
                                candidate.intersects(geometry)) {
                                polygon = features[i];
                                this.control.layer.removeFeatures([polygon], {silent: true});
                                this.control.layer.events.registerPriority(
                                    "sketchcomplete", this, this.finalizeInteriorRing
                                );
                                this.control.layer.events.registerPriority(
                                    "sketchmodified", this, this.enforceTopology
                                );
                                polygon.geometry.addComponent(this.line.geometry);
                                this.polygon = polygon;
                                this.drawingHole = true;
                                break;
                            }
                        }
                    }
                    if (!this.drawingHole) {
                        return;
                    }
                    OpenLayers.Handler.Path.prototype.addPoint.apply(this, arguments);
                },
                finalize: finalizePolygonValidOnly,
                finalizeInteriorRing : function(event) {

                    var fir =  OpenLayers.Handler.Polygon.prototype.finalizeInteriorRing.apply(this, arguments);
                    var feature = this.polygon;
                    injectedMethods.setModifiedState(feature,this.control);
                    injectedMethods.openFeatureEditDialog(feature);
                    return fir;
                },
            },

            activate: function() {
                this.layer.map.controls.forEach(function(control) {
                    if (control.dragPan) {
                        control.dragPan.deactivate();
                    }
                });
                OpenLayers.Control.DrawFeature.prototype.activate.apply(this,arguments);
            },

            deactivate: function() {
                this.layer.map.controls.forEach(function(control) {
                    if (control.dragPan) {
                        control.dragPan.activate();
                    }
                });
                OpenLayers.Control.DrawFeature.prototype.deactivate.apply(this,arguments);
            }


        }),

        modifyFeature: new OpenLayers.Control.ModifyFeature(layer,{

            /**
             * This function allows the easy use of the olEvent onModificationStart with the yml configurration
             * e.G. to prevent the modification or add additional data on modification
             * */

            onModificationStart: function (feature) {
                console.log("onModificationStart");

                if (injectedMethods.preventModification()) {
                    this.deactivate();
                    this.activate();
                    $.notify(Mapbender.DigitizerTranslator.translate('move.denied'));
                }


            },

            onModification: function (feature) {

                injectedMethods.setModifiedState(feature,this);
                injectedMethods.openFeatureEditDialog(feature);

                console.log("onModification",feature);

            }
        }),

        moveFeature: new OpenLayers.Control.DragFeature(layer, {

            /**
             * * This function allows the easy use of the olEvent onStart( called on drag start) with the yml configurration
             * e.G. to prevent the move or add additional data on move
             * @param {(OpenLayers.Feature.Vector | OpenLayers.Feature)} feature
             * @param px
             */
            onStart: function (feature, px) {
                console.log("onStart");
{'fraction_non_alphanumeric': 0.09098810001337077, 'fraction_numerical': 0.0009359540045460623, 'mean_word_length': 1.597048611111111, 'pattern_counts': {'":': 0, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '123237', 'n_tokens_mistral': 3744, 'n_tokens_neox': 3457, 'n_words': 635}