/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="barrier">Barrier to show.</param>
        private BarrierGraphicObject(Barrier barrier)
            : base(barrier)
        {
            _barrier = barrier;
            _barrier.PropertyChanged += new PropertyChangedEventHandler(_BarrierPropertyChanged);

            Geometry = _CreateGeometry(barrier);

            Attributes.Add(START_ATTRIBUTE_NAME, null);
            Attributes.Add(FINISH_ATTRIBUTE_NAME, null);

            Attributes.Add(ESRI.ArcLogistics.App.OrderSymbology.SymbologyContext.FILL_ATTRIBUTE_NAME,
                new SolidColorBrush(Colors.Red));
        }
        /// <summary>
        /// Create graphic object for barrier.
        /// </summary>
        /// <param name="barrier">Source barrier.</param>
        /// <returns>Graphic object for barrier.</returns>
        public static BarrierGraphicObject Create(Barrier barrier)
        {
            BarrierGraphicObject graphic = new BarrierGraphicObject(barrier);

            return graphic;
        }
        /// <summary>
        /// Create barrier geometry.
        /// </summary>
        /// <param name="barrier">Barrier.</param>
        /// <returns>Barrier geometry.</returns>
        private ESRI.ArcGIS.Client.Geometry.Geometry _CreateGeometry(Barrier barrier)
        {
            ESRI.ArcGIS.Client.Geometry.Geometry geometry = null;

            if (barrier.Geometry != null)
            {
                int? spatialReference = null;
                if (ParentLayer != null)
                {
                    spatialReference = ParentLayer.SpatialReferenceID;
                }

                if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Point)
                {
                    ESRI.ArcLogistics.Geometry.Point point = (ESRI.ArcLogistics.Geometry.Point)barrier.Geometry;

                    // Project point from WGS84 to Web Mercator if spatial reference of map is Web Mercator
                    if (ParentLayer != null && ParentLayer.SpatialReferenceID != null)
                    {
                        point = WebMercatorUtil.ProjectPointToWebMercator(point, spatialReference.Value);
                    }

                    geometry = new ESRI.ArcGIS.Client.Geometry.MapPoint(point.X, point.Y);
                }
                else if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polygon)
                {
                    geometry = MapHelpers.ConvertToArcGISPolygon(
                        barrier.Geometry as ESRI.ArcLogistics.Geometry.Polygon, spatialReference);
                }
                else if (barrier.Geometry is ESRI.ArcLogistics.Geometry.Polyline)
                {
                    geometry = MapHelpers.ConvertToArcGISPolyline(
                        barrier.Geometry as ESRI.ArcLogistics.Geometry.Polyline, spatialReference);
                }
                else
                {
                    System.Diagnostics.Debug.Assert(false);
                }

                _SetSymbol();
            }
            else
            {
                geometry = null;
            }

            return geometry;
        }
        /// <summary>
        /// Method returns collection of barriers dates. If any of dates is null - returns null
        /// </summary>
        /// <param name="barrier"></param>
        /// <returns></returns>
        private ICollection<DateTime> _GetBarrierDatesRange(Barrier barrier)
        {
            if (barrier.FinishDate == null || barrier.StartDate == null)
                return null;

            ICollection<DateTime> dates = new Collection<DateTime>();

            DateTime date = (DateTime)barrier.StartDate;

            while (date <= barrier.FinishDate)
            {
                dates.Add(date);
                date = date.AddDays(1);
            }

            return dates;
        }
        /// <summary>
        /// React on dependency property changing.
        /// </summary>
        private void _OnValueChanged()
        {
            if (_barrier != null)
            {
                _barrier.PropertyChanged -= new PropertyChangedEventHandler(_BarrierPropertyChanged);
            }

            Cell cell = XceedVisualTreeHelper.GetCellByEditor(this);
            Row row = XceedVisualTreeHelper.FindParent<Row>(cell);

            _barrier = row.DataContext as Barrier;

            if (_barrierEditor != null)
            {
                _barrierEditor.Barrier = _barrier;
            }

            if (_barrier != null)
            {
                _barrier.PropertyChanged += new PropertyChangedEventHandler(_BarrierPropertyChanged);
            }
        }
        /// <summary>
        /// Method adds dates statuses in necessary range. Barriers start and end dates should not be null
        /// </summary>
        /// <param name="calendarStartDate"></param>
        /// <param name="calendarEndDate"></param>
        /// <param name="barrier"></param>
        private void _AddDateStatusesRange(Barrier barrier)
        {
            // start date and finish date cannot be null
            Debug.Assert(barrier.StartDate != null);
            Debug.Assert(barrier.FinishDate != null);

            // if barriers dates are out of range of current calendar dates - return
            if (barrier.FinishDate < _calendarStartDate || barrier.StartDate > _calendarEndDate)
                return;

            ICollection<DateTime> barrierDates = _GetBarrierDatesRange(barrier); // get callection of all barriers dates

            foreach (DateTime barrierDate in barrierDates)
            {
                // if immediate date is in necessary range - change dictionary value
                if (barrierDate >= _calendarStartDate && barrierDate <= _calendarEndDate)
                {
                    if (!_dayStatuses.Contains(barrierDate))
                        _dayStatuses.Add(barrierDate);
                }
            }
        }
        /// <summary>
        /// Fill barrier tip
        /// </summary>
        /// <param name="inlines">Inlines to fill</param>
        /// <param name="location">Source barrier</param>
        private static void _FillBarrier(InlineCollection inlines, Barrier barrier)
        {
            string name = barrier.Name;
            _AddLine(_nameCaption, name, inlines, false);

            string availableAt = string.Format(BARRIER_AVAILABLE_FMT,
                barrier.StartDate.Date.ToShortDateString(),
                barrier.FinishDate.Date.ToShortDateString());
            _AddLine(_barrierAvailableCaption, availableAt, inlines, false);
        }
Beispiel #8
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        public override object Clone()
        {
            Barrier obj = new Barrier(this.StartDate, this.FinishDate);
            this.CopyTo(obj);

            return obj;
        }
        /// <summary>
        /// Initialize popup editor.
        /// </summary>
        /// <param name="barrier"></param>
        /// <param name="popup"></param>
        public void Initialize(Barrier barrier, Popup popup)
        {
            _barrier = barrier;
            BarrierEditor.Barrier = barrier;
            _popup = popup;

            // Save initial barrier effect.
            _initialBarrierEffect = barrier.BarrierEffect.Clone() as BarrierEffect;

            App.Current.MainWindow.PreviewMouseDown += new MouseButtonEventHandler(_MainWindowPreviewMouseDown);
            App.Current.MainWindow.Deactivated += new System.EventHandler(_MainWindowDeactivated);
            this.KeyDown += new KeyEventHandler(_BarrierPopupEditorKeyDown);
        }
        /// <summary>
        /// Show barrier editor on map
        /// </summary>
        /// <param name="barrier">Barrier to show.</param>
        /// <param name="point">Last added point.</param>
        private void _ShowBarrierEditor(Barrier barrier, Point point)
        {
            _barrierPopupEditor = new BarrierPopupEditor();

            //Subscribe to popupeditor events.
            _barrierPopupEditor.OnComplete += new EventHandler(_BarrierPopupEditorOnComplete);
            _barrierPopupEditor.OnCancel += new EventHandler(_BarrierPopupEditorOnCancel);

            Point projectedPoint = new Point(point.X, point.Y);
            if (_mapCtrl.Map.SpatialReferenceID.HasValue)
            {
                projectedPoint = WebMercatorUtil.ProjectPointToWebMercator(projectedPoint,
                    _mapCtrl.Map.SpatialReferenceID.Value);
            }

            // Get left down point.
            System.Windows.Point screenPoint =
                _mapCtrl.map.MapToScreen(new ESRI.ArcGIS.Client.Geometry.MapPoint(projectedPoint.X,
                    projectedPoint.Y));
            System.Windows.Rect rect = new System.Windows.Rect(
                screenPoint.X, screenPoint.Y - _barrierPopupEditor.MinHeight,
                _barrierPopupEditor.MinWidth, _barrierPopupEditor.MinHeight);

            Popup popup = _CreatePopup(_barrierPopupEditor, rect);
            _barrierPopupEditor.Initialize(barrier, popup);
        }