/// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="location">Location object to show.</param>
        private LocationGraphicObject(Location location)
            : base(location)
        {
            _location = location;
            _location.PropertyChanged += new PropertyChangedEventHandler(_LocationPropertyChanged);

            Geometry = _CreatePoint(location);

            Symbol = new LocationSymbol();
        }
        /// <summary>
        /// Create location point geometry.
        /// </summary>
        /// <param name="location">Location.</param>
        /// <returns>Location geometry.</returns>
        private ESRI.ArcGIS.Client.Geometry.MapPoint _CreatePoint(Location location)
        {
            ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint = null;

            // If location geocoded - create point.
            if (location.GeoLocation.HasValue)
            {
                ESRI.ArcLogistics.Geometry.Point geoLocation = location.GeoLocation.Value;

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

                mapPoint = new ESRI.ArcGIS.Client.Geometry.MapPoint(geoLocation.X, geoLocation.Y);
            }
            else
            {
                mapPoint = null;
            }

            return mapPoint;
        }
        /// <summary>
        /// Fill depot-specific properties.
        /// </summary>
        /// <param name="depot">Depot.</param>
        /// <param name="settings">Current solver settings.</param>
        /// <param name="result">Stop information to fill in.</param>
        private static void _FillDepotProperties(Location depot,
            SolverSettings settings, StopInfo result)
        {
            Debug.Assert(depot != null);
            Debug.Assert(result != null);

            // Fill curb approach policies.
            if (settings != null)
            {
                result.CurbApproach = settings.GetDepotCurbApproach();
            }
        }
 /// <summary>
 /// Zoom on current selected location.
 /// </summary>
 /// <param name="location">Location to zoom at.</param>
 private void _ZoomOnLocation(Location location)
 {
     // Current item can be null because zooming suspended.
     if (location != null)
     {
         // Zoom on location.
         List<ESRI.ArcLogistics.Geometry.Point> points = new List<ESRI.ArcLogistics.Geometry.Point>();
         points.Add(location.GeoLocation.Value);
         MapExtentHelpers.SetExtentOnCollection(mapCtrl, points);
     }
 }
        /// <summary>
        /// Create location and switch of address validation.
        /// </summary>
        /// <returns></returns>
        private Location _CreateLocationWithFakeNameAndWithoutValidation()
        {
            // Create new location with whitespace name. Do so to cheat validation, so there would
            // be no yellow ! at location name.
            Location location = new Location();
            location.Name = DataObjectNamesConstructor.GetNewWhiteSpacesName(_locations);

            // Turn off address validation.
            location.IsAddressValidationEnabled = false;

            return location;
        }
        /// <summary>
        /// Do geocode location using server geocoder.
        /// </summary>
        /// <param name="location">Location to geocode.</param>
        /// <param name="includeDisabledLocators">Is need to add candidates from disabled locators.</param>
        /// <returns>Candidates list.</returns>
        private static List<AddressCandidate> _DoGeocodeLocation(Location location, bool includeDisabledLocators)
        {
            List<AddressCandidate> candidates = new List<AddressCandidate>();

            Address address = location.Address;

            // Clean old geocoding info.
            address.MatchMethod = string.Empty;

            if (App.Current.Geocoder.AddressFormat == AddressFormat.MultipleFields)
                address.FullAddress = string.Empty;
            else
            {
                // Do nothing: do not clear full address since
                // it is used for geocoding in Single Address Field Format.
            }

            location.GeoLocation = null;

            // Find all candidates.
            AddressCandidate[] candidatesArr = App.Current.Geocoder.GeocodeCandidates(address, includeDisabledLocators);
            if (candidatesArr != null)
            {
                candidates.AddRange(candidatesArr);
            }

            return candidates;
        }
        /// <summary>
        /// Create graphic object for location.
        /// </summary>
        /// <param name="location">Source location.</param>
        /// <returns>Graphic object for location.</returns>
        public static LocationGraphicObject Create(Location location)
        {
            LocationGraphicObject graphic = new LocationGraphicObject(location);

            return graphic;
        }
Esempio n. 8
0
        ///////////////////////////////////////////////////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Creates a new object that is a copy of the current instance.
        /// </summary>
        /// <returns></returns>
        public override object Clone()
        {
            Location obj = new Location();
            this.CopyTo(obj);

            return obj;
        }
        /// <summary>
        /// Method converts location into GPFeature.
        /// </summary>
        /// <param name="loc">Location to convert.</param>
        /// <returns>Locations GPFeature.</returns>
        /// <exception cref="RouteException">If location is not geocoded.</exception>
        private GPFeature _ConvertDepot(Location loc)
        {
            Debug.Assert(loc != null);

            GPFeature feature = new GPFeature();

            // Geometry.
            feature.Geometry = new GeometryHolder();
            feature.Geometry.Value = GPObjectHelper.PointToGPPoint(_GetLocationPoint(loc));

            // Attributes.
            AttrDictionary attrs = new AttrDictionary();

            // Name.
            attrs.Add(NAAttribute.NAME, loc.Id.ToString());

            // Curb approach.
            attrs.Add(NAAttribute.CURB_APPROACH,
                (int)CurbApproachConverter.ToNACurbApproach(
                _context.SolverSettings.GetDepotCurbApproach()));

            // Set Time Windows attributes.
            TimeWindow timeWindow1 = loc.TimeWindow;
            TimeWindow timeWindow2 = loc.TimeWindow2;

            _SetTimeWindowsAttributes(attrs, ref timeWindow1, ref timeWindow2);

            feature.Attributes = attrs;

            return feature;
        }
        /// <summary>
        /// Method gets location point of Location.
        /// </summary>
        /// <param name="loc">Location to get information.</param>
        /// <returns>Point location.</returns>
        /// <exception cref="RouteException">If location is not geocoded.</exception>
        private static Point _GetLocationPoint(Location loc)
        {
            Debug.Assert(loc != null);

            IGeocodable gc = loc as IGeocodable;
            Debug.Assert(gc != null);

            if (!gc.IsGeocoded)
            {
                throw new RouteException(String.Format(
                    Properties.Messages.Error_LocationIsUngeocoded, loc.Id));
            }

            Debug.Assert(gc.GeoLocation != null);
            return (Point)gc.GeoLocation;
        }
        /// <summary>
        /// Method converts renewal location from route into GPFeature.
        /// </summary>
        /// <param name="loc">Location to convert.</param>
        /// <param name="route">Route on which location assigned.</param>
        /// <returns>Renewals GPFeature.</returns>
        private GPFeature _ConvertRenewal(Location loc, Route route)
        {
            Debug.Assert(loc != null);
            Debug.Assert(route != null);

            GPFeature feature = new GPFeature();

            // Attributes.
            AttrDictionary attrs = new AttrDictionary();

            // Route name.
            attrs.Add(NAAttribute.ROUTE_NAME, route.Id.ToString());
            // Depot name.
            attrs.Add(NAAttribute.DEPOT_NAME, loc.Id.ToString());
            // Service time.
            attrs.Add(NAAttribute.SERVICE_TIME, route.TimeAtRenewal);

            // Sequences: currently sequences are not used.

            feature.Attributes = attrs;

            return feature;
        }
Esempio n. 12
0
 /// <summary>
 /// Fill location tip
 /// </summary>
 /// <param name="inlines">Inlines to fill</param>
 /// <param name="location">Source location</param>
 private static void _FillLocation(InlineCollection inlines, Location location)
 {
     string name = location.Name;
     _AddLine(_nameCaption, name, inlines, false);
 }
        public static void makeEdit(string field, string value)
        {
            field = field.Replace(" ", "");

            string message = "Changing " + field + " to " + value + " for all seleced routes.";
            App.Current.Messenger.AddInfo(message);

            ISupportSelection selector = (ISupportSelection)App.Current.MainWindow.CurrentPage;

            for (int i = 0; i < selector.SelectedItems.Count; i++)
            {

                Route routeRef = (Route)selector.SelectedItems[i];
                double tempD;
                DateTime TWdateTime;

                try
                {
                    switch (field)
                    {
                        #region Case Statements

                        case "RouteName": routeRef.Name = value; break;

                        case "Vehicle":
                            foreach (Vehicle v in App.Current.Project.Vehicles)
                            {
                                if (v.Name == value)
                                    routeRef.Vehicle = v;
                            }
                            break;

                        case "Driver":
                            foreach (Driver d in App.Current.Project.Drivers)
                            {
                                if (d.Name == value)
                                    routeRef.Driver = d;
                            }
                            break;

                        case"StartTimeWindowStart":
                            if (DateTime.TryParse(value, out TWdateTime))
                            {
                                if (TWdateTime.TimeOfDay != TimeSpan.Zero)
                                {
                                    routeRef.StartTimeWindow.From = TWdateTime.TimeOfDay;
                                    routeRef.StartTimeWindow.IsWideOpen = false;
                                }
                            }
                            break;

                        case "StartTimeWindowFinish":
                            if (DateTime.TryParse(value, out TWdateTime))
                            {
                                if (TWdateTime.TimeOfDay != TimeSpan.Zero)
                                {
                                    routeRef.StartTimeWindow.To = TWdateTime.TimeOfDay;
                                    routeRef.StartTimeWindow.IsWideOpen = false;
                                }
                            }
                            break;

                        case "StartLocation":
                            foreach (Location l in App.Current.Project.Locations)
                            {
                                if (l.Name == value)
                                    routeRef.StartLocation = l;
                            }
                            break;

                        case "TimeAtStart":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.TimeAtStart = tempD;
                            break;

                        case "EndLocation":
                            foreach (Location l in App.Current.Project.Locations)
                            {
                                if (l.Name == value)
                                    routeRef.EndLocation = l;
                            }
                            break;

                        case "TimeAtEnd":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.TimeAtEnd = tempD;
                            break;

                        case "RenewalLocation":
                            if (value != "")
                            {
                                string[] stringSeparators2 = new string[] { ";", "," };
                                string[] locations2 = value.Split(stringSeparators2, StringSplitOptions.None);
                                foreach (string s in locations2)
                                {
                                    bool locationFound = false;
                                    bool addToRoute = true;
                                    Location l = new Location();
                                    l.Name = s;

                                    foreach (Location L in App.Current.Project.Locations)
                                    {
                                        if (String.Compare(L.Name, l.Name, true) == 0)
                                        {
                                            L.CopyTo(l);
                                            locationFound = true;
                                            break;
                                        }
                                    }
                                    foreach (Location L in routeRef.RenewalLocations)
                                    {
                                        if (String.Compare(L.Name, l.Name, true) == 0)
                                        {
                                            addToRoute = false;
                                            break;
                                        }
                                    }

                                    if(locationFound && addToRoute)
                                        routeRef.RenewalLocations.Add(l);
                                }
                            }
                            break;

                       case "TimeAtRenewal":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.TimeAtRenewal = tempD;
                            break;

                        case "MaxOrders":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.MaxOrders =(int) tempD;
                            break;

                        case "MaxTravelDistance":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.MaxTravelDistance = tempD;
                            break;

                        case "MaxTravelDuration":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.MaxTravelDuration = tempD;
                            break;

                        case "MaxTotalDuration":
                            if (Double.TryParse(value.ToString(), out tempD))
                                routeRef.MaxTotalDuration = tempD;
                            break;

                        case "Zones":
                            if (value != "")
                            {
                                string[] stringSeparators = new string[] { ";", "," };
                                string[] zones = value.Split(stringSeparators, StringSplitOptions.None);
                                foreach (string s in zones)
                                {
                                    bool zoneFound = false;
                                    bool addToRoute = true;
                                    Zone z = new Zone();
                                    z.Name = s;

                                    foreach (Zone Z in App.Current.Project.Zones)
                                    {
                                        if (String.Compare(Z.Name, z.Name, true) == 0)
                                        {
                                            Z.CopyTo(z);
                                            zoneFound = true;
                                            break;
                                        }
                                    }
                                    foreach (Zone Z in routeRef.Zones)
                                    {
                                        if (String.Compare(Z.Name, z.Name, true) == 0)
                                        {
                                            addToRoute = false;
                                            break;
                                        }
                                    }

                                    if (zoneFound && addToRoute)
                                        routeRef.Zones.Add(z);
                                }
                            }
                            break;

                        case "HardZones":
                            if ((String.Compare(value, "Yes", true) == 0) || (String.Compare(value, "Y", true) == 0) || (String.Compare(value, "True", true) == 0))
                                routeRef.HardZones = true;
                            else if ((String.Compare(value, "NO", true) == 0) || (String.Compare(value, "N", true) == 0) || (String.Compare(value, "False", true) == 0))
                                routeRef.HardZones = false;
                            break;

                        case "Comment":routeRef.Comment = value; break;

                        #endregion

                    }// End Switch
                }
                catch (Exception e)
                {
                    message = "Error: " + e.Message;
                    App.Current.Messenger.AddError(message);
                }
            }
            App.Current.Project.Save();
        }