コード例 #1
0
        private IGeometry GetDefaultGeometry(ISnapResult snapResult)
        {
            IGeometry      defaultGeometry = null;
            IFeatureEditor featureEditor   = MapControl.SelectTool.GetFeatureEditor(Layer, null);

            if (null != featureEditor)
            {
                defaultGeometry = featureEditor.CreateDefaultGeometry(Layer, newLineGeometry[0],
                                                                      (null != snapResult) ? snapResult.NearestTarget : null,
                                                                      (null != snapResult) ? snapResult.Location : null);
                if (null != defaultGeometry)
                {
                    newLineGeometry.Clear();
                    newLineGeometry.Add(defaultGeometry);
                }
            }
            return(defaultGeometry);
        }
コード例 #2
0
        public override void OnMouseUp(ICoordinate worldPosition, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (newLineGeometry.Count == 0)
            {
                return;
            }

            ISnapResult snapResult = MapControl.SnapTool.ExecuteLayerSnapRules(Layer, null, adding ? newLineGeometry[0] : null,
                                                                               worldPosition,
                                                                               adding ? newLineGeometry[0].Coordinates.Length - 1 : -1);
            IGeometry      defaultGeometry = null;
            IFeatureEditor featureEditor   = MapControl.SelectTool.GetFeatureEditor(Layer, null);

            if (null != featureEditor)
            {
                defaultGeometry = featureEditor.CreateDefaultGeometry(Layer, newLineGeometry[0],
                                                                      (null != snapResult) ? snapResult.NearestTarget : null,
                                                                      (null != snapResult) ? snapResult.Location : null);
                if (null != defaultGeometry)
                {
                    newLineGeometry.Clear();
                    newLineGeometry.Add(defaultGeometry);
                }
            }
            ILineString lineString = (ILineString)newLineGeometry[0];

            if (null == lineString)
            {
                isBusy = false;
                return;
            }
            if (ActualAutoCurve)
            {
                if (null == defaultGeometry)
                {
                    snapResult = Snap(worldPosition);
                    if (null == snapResult)
                    {
                        // hack if obligatory snapping failed mimic result. This is not valid for NewNodeTool
                        // Think of solution within snaprule
                        snapResult = new SnapResult(worldPosition, null, null, -1, -1);
                    }
                    if (TemporalEnd)
                    {
                        GeometryHelper.SetCoordinate(lineString, lineString.Coordinates.Length - 1, snapResult.Location);
                    }
                    else
                    {
                        lineString = AppendCurvePoint(lineString, snapResult.Location);
                    }
                    lineString = RemoveDuplicatePoints(lineString);
                }
                adding             = false;
                newLineGeometry[0] = lineString;
                //Flush();
                SelectTool selectTool = MapControl.SelectTool;

                if (null != lineString && snapResult != null)
                {
                    // TODO: call editor here instead of feature provider
                    int count = FeatureProvider.GetFeatureCount();

                    try
                    {
                        FeatureProvider.Add(lineString); // will add Cross Section and call ConnectCrossSectionToBranch
                    }
                    catch (Exception exception)
                    {
                        // an exception during add operation can fail; for example when adding a branch feature
                        log.Warn(exception.Message);
                        adding = false;
                        StopDrawing();
                        newLineGeometry.Clear();
                        return;
                    }

                    // was adding succesfull?
                    if ((1 + count) == FeatureProvider.GetFeatureCount())
                    {
                        IFeature feature = FeatureProvider.GetFeature(count);
                        //Layer.RenderRequired = true;
                        MapControl.SelectTool.Select(Layer, feature, 0);
                    }
                }
                else
                {
                    // do not add a linestring with zero length
                    selectTool.Clear();
                }
                adding = false;
                StopDrawing();
                newLineGeometry.Clear();
            }
            Layer.RenderRequired = true;
            MapControl.Refresh();
            isBusy = false;
        }