Exemplo n.º 1
0
        public void List_Remove()
        {
            var lst = new EventedList <string, string>("CONTEXT", false);

            var first = true;

            lst.GetReadOnlyEvent = (_) => false;

            lst.Add("a");
            lst.Add("b");
            lst.Add("c");

            Aver.AreEqual(3, lst.Count);

            lst.ChangeEvent = (l, ct, p, idx, v) =>
            {
                Aver.AreObjectsEqual(EventedList <string, string> .ChangeType.Remove, ct);
                Aver.AreObjectsEqual(first ? EventPhase.Before : EventPhase.After, p);
                Aver.AreEqual(-1, idx);
                Aver.AreEqual("b", v);
                first = false;
            };

            lst.Remove("b");
            Aver.AreEqual(2, lst.Count);
        }
Exemplo n.º 2
0
        public void CreateFromCollection()
        {
            EventedList<SampleFeature> features = new EventedList<SampleFeature>();

            features.Add(new SampleFeature());
            features.Add(new SampleFeature());
            features.Add(new SampleFeature());

            features[0].Geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)");
            features[1].Geometry = GeometryFromWKT.Parse("LINESTRING (30 30, 30 40, 40 40, 40 30, 50 30)");
            features[2].Geometry = GeometryFromWKT.Parse("LINESTRING (40 40, 40 50, 50 50, 50 40, 60 40)");

            FeatureCollection featureCollection = new FeatureCollection {Features = features};

            Map map = new Map();
            
            VectorLayer vectorLayer = new VectorLayer();
            vectorLayer.DataSource = featureCollection;
            
            map.Layers.Add(vectorLayer);

            Assert.AreEqual(3, vectorLayer.DataSource.GetFeatureCount());
            Assert.AreEqual("LineString", vectorLayer.DataSource.GetGeometryByID(0).GeometryType);

            // ShowMap(map);
        }
Exemplo n.º 3
0
        public void List_Clear()
        {
            var lst = new EventedList <string, string>("CONTEXT", false);

            var first = true;

            lst.GetReadOnlyEvent = (_) => false;

            lst.Add("a");
            lst.Add("b");
            lst.Add("c");

            Assert.AreEqual(3, lst.Count);

            lst.ChangeEvent = (l, ct, p, idx, v) =>
            {
                Assert.AreEqual(EventedList <string, string> .ChangeType.Clear, ct);
                Assert.AreEqual(first ? EventPhase.Before : EventPhase.After, p);
                Assert.AreEqual(-1, idx);
                Assert.AreEqual(null, v);
                first = false;
            };

            lst.Clear();
            Assert.AreEqual(0, lst.Count);
        }
Exemplo n.º 4
0
        public void List_Clear()
        {
            var lst = new EventedList<string, string>("CONTEXT", false);

              var first = true;
              lst.GetReadOnlyEvent = (_) => false;

              lst.Add("a");
              lst.Add("b");
              lst.Add("c");

              Assert.AreEqual(3, lst.Count);

              lst.ChangeEvent = (l, ct, p, idx, v) =>
                            {
                              Assert.AreEqual( EventedList<string, string>.ChangeType.Clear, ct);
                              Assert.AreEqual( first ? EventPhase.Before : EventPhase.After, p);
                              Assert.AreEqual( -1, idx);
                              Assert.AreEqual( null, v);
                              first = false;
                            };

              lst.Clear();
              Assert.AreEqual( 0, lst.Count);
        }
Exemplo n.º 5
0
        public void CreateFromCollection()
        {
            EventedList <SampleFeature> features = new EventedList <SampleFeature>();

            features.Add(new SampleFeature());
            features.Add(new SampleFeature());
            features.Add(new SampleFeature());

            features[0].Geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)");
            features[1].Geometry = GeometryFromWKT.Parse("LINESTRING (30 30, 30 40, 40 40, 40 30, 50 30)");
            features[2].Geometry = GeometryFromWKT.Parse("LINESTRING (40 40, 40 50, 50 50, 50 40, 60 40)");

            FeatureCollection featureCollection = new FeatureCollection {
                Features = features
            };

            Map map = new Map();

            VectorLayer vectorLayer = new VectorLayer();

            vectorLayer.DataSource = featureCollection;

            map.Layers.Add(vectorLayer);

            Assert.AreEqual(3, vectorLayer.DataSource.GetFeatureCount());
            Assert.AreEqual("LineString", vectorLayer.DataSource.GetGeometryByID(0).GeometryType);

            // ShowMap(map);
        }
Exemplo n.º 6
0
        public void CollectionChangedReplaceDataItemsResultInCollectionChangedForAdapter()
        {
            //create a list of dataItem containing urls
            IEventedList <IDataItem> dataItems = new EventedList <IDataItem>();
            var oldUrl   = new Url();
            var newUrl   = new Url();
            var dataItem = new DataItem(oldUrl);

            dataItems.Add(dataItem);

            //adapter for the list
            var adapter = new DataItemListAdapter <Url>(dataItems);

            int callCount = 0;

            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Replace, e.Action);
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(newUrl, e.Item);
                //discutable but current eventedlist implementation does this
                Assert.AreEqual(-1, e.OldIndex);
                Assert.AreEqual(0, e.Index);
            };

            //action! replace one dataitem with another
            dataItems[0] = new DataItem(newUrl);
            Assert.AreEqual(1, callCount);
        }
        /// <summary>
        /// rewire all components and arguments
        /// </summary>
        /// <param name="clonedFunctions"></param>
        /// <param name="sourceFunctions"></param>
        private static void ReconnectClonedComponentsAndArguments(IList <IFunction> clonedFunctions,
                                                                  IList <IFunction> sourceFunctions)
        {
            for (int i = 0; i < sourceFunctions.Count; i++)
            {
                IFunction sourceFunction = sourceFunctions[i];
                IFunction clonedFunction = clonedFunctions[i];

                var arguments = new EventedList <IVariable>();
                foreach (IVariable argument in sourceFunction.Arguments)
                {
                    int argumentIndex = sourceFunctions.IndexOf(argument);
                    arguments.Add((IVariable)clonedFunctions[argumentIndex]);
                }

                clonedFunction.Arguments = arguments;

                var components = new EventedList <IVariable>();
                foreach (IVariable component in sourceFunction.Components)
                {
                    int componentIndex = sourceFunctions.IndexOf(component);
                    components.Add((IVariable)clonedFunctions[componentIndex]);
                }

                clonedFunction.Components = components;
            }
        }
Exemplo n.º 8
0
        public void CollectionChangedReplaceDataItemsResultInCollectionChangedForAdapter()
        {
            //create a list of dataItem containing urls
            IEventedList<IDataItem> dataItems = new EventedList<IDataItem>();
            var oldUrl = new Url();
            var newUrl = new Url();
            var dataItem = new DataItem(oldUrl);
            dataItems.Add(dataItem);

            //adapter for the list
            var adapter = new DataItemListAdapter<Url>(dataItems);

            int callCount = 0;
            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Replace,e.Action);
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(newUrl, e.Item);
                //discutable but current eventedlist implementation does this
                Assert.AreEqual(-1, e.OldIndex);
                Assert.AreEqual(0, e.Index);
            };

            //action! replace one dataitem with another
            dataItems[0] = new DataItem(newUrl);
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 9
0
        public void DataItemLinkToIsCollectionChanged()
        {
            //create a list of dataItem containing urls
            IEventedList <IDataItem> dataItems = new EventedList <IDataItem>();
            var oldUrl   = new Url();
            var dataItem = new DataItem(oldUrl);

            dataItems.Add(dataItem);

            //adapter for the list
            var adapter = new DataItemsEventedListAdapter <Url>(dataItems);


            var newUrl         = new Url();
            var sourceDataItem = new DataItem(newUrl);
            int callCount      = 0;

            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangeAction.Replace, e.Action);
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(newUrl, e.Item);
                //discutable but current eventedlist implementation does this
                Assert.AreEqual(-1, e.OldIndex);
                Assert.AreEqual(0, e.Index);
            };

            //action! link the first dataItem.
            dataItems[0].LinkTo(sourceDataItem);
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 10
0
 private void AddManyObjectsWithEvents(EventedList <MockWithPropertyAndCollectionChanged> eventedList)
 {
     for (var i = 0; i < 100000; i++)
     {
         eventedList.Add(new MockWithPropertyAndCollectionChanged());
     }
 }
Exemplo n.º 11
0
        public void CollectionChangedRemoveDataItemsResultInCollectionChangedForAdapter()
        {
            //create a list of dataItem containing urls
            IEventedList <IDataItem> dataItems = new EventedList <IDataItem>();
            var url      = new Url();
            var dataItem = new DataItem(url);

            dataItems.Add(dataItem);

            //adapter for the list
            var adapter = new DataItemsEventedListAdapter <Url>(dataItems);

            int callCount = 0;

            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(url, e.Item);
                Assert.AreEqual(0, e.Index);
            };

            //action! remove the url from the dataitems list
            dataItems.Remove(dataItem);
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 12
0
        public void UnsubscribeFromOldItemOnReplace()
        {
            var eventedList = new EventedList <MockClassWithTwoProperties>();

            var aPropertyChangeCount    = 0;
            var listPropertyChangeCount = 0;

            var a = new MockClassWithTwoProperties {
                StringProperty = "a"
            };

            eventedList.Add(a);

            eventedList.PropertyChanged += delegate { listPropertyChangeCount++; };
            a.PropertyChanged           += delegate { aPropertyChangeCount++; };

            // replace item
            eventedList[0] = new MockClassWithTwoProperties {
                StringProperty = "second a"
            };

            a.StringProperty = "a2";

            Assert.AreEqual(0, listPropertyChangeCount);
            Assert.AreEqual(1, aPropertyChangeCount);
        }
Exemplo n.º 13
0
        public void List_Readonly()
        {
            var lst = new EventedList <string, string>("CONTEXT", false);

            var ro = false;

            lst.GetReadOnlyEvent = (l) => ro;

            lst.Add("a");
            lst.Add("b");
            lst.Add("c");

            Aver.AreEqual(3, lst.Count);
            ro = true;

            Aver.Throws <NFXException>(() => lst.Add("d"));
        }
Exemplo n.º 14
0
        public void ClearTest()
        {
            var l = new EventedList <EClass>();

            l.Add(new EClass());
            Assert.That(l.Count, Is.EqualTo(1));
            l.Clear();
            Assert.That(l.Count, Is.EqualTo(0));
        }
Exemplo n.º 15
0
        public void LastIndexOfTest()
        {
            var a = new[] { new EClass(1), new EClass(2) };
            var l = new EventedList <EClass>(a);

            l.Add(a[0]);
            Assert.That(l.LastIndexOf(a[0]), Is.EqualTo(2));
            Assert.That(l.LastIndexOf(a[0], 1, 2), Is.EqualTo(0));
        }
Exemplo n.º 16
0
        public void ItemReplaced()
        {
            var eventedList = new EventedList<int>();

            var called = false;
            eventedList.Add(1);
            eventedList.CollectionChanged += delegate { called = true; };
            eventedList[0] = 2;
            Assert.IsTrue(called);
        }
Exemplo n.º 17
0
        public void UpdateFolderParent()
        {
            Folder folder                = new Folder();
            Folder childFolder           = new Folder();
            EventedList <Folder> folders = new EventedList <Folder>();

            folders.Add(childFolder);
            folder.Folders = folders;
            Assert.AreEqual(folder, childFolder.Parent);
        }
Exemplo n.º 18
0
        public void UpdateFolderParent()
        {
            Folder folder = new Folder();
            Folder childFolder = new Folder();
            EventedList<Folder>folders=new EventedList<Folder>();
            folders.Add(childFolder);
            folder.Folders = folders;
            Assert.AreEqual(folder, childFolder.Parent);

        }
Exemplo n.º 19
0
        public void CollectionChangedWhenValueIsRemoved()
        {
            var eventedList = new EventedList<int>();

            var called = false;
            eventedList.Add(1);
            eventedList.CollectionChanged += delegate { called = true; };
            eventedList.Remove(1);
            Assert.IsTrue(called);
        }
Exemplo n.º 20
0
        protected override void DoConfigure(IConfigSectionNode node)
        {
            if (node == null)
            {
                //0 get very root
                node = App.ConfigRoot[SysConsts.CONFIG_WAVE_SECTION];
                if (!node.Exists)
                {
                    return;
                }

                //1 try to find the server with the same name as this instance
                var snode = node.Children.FirstOrDefault(cn => cn.IsSameName(CONFIG_SERVER_SECTION) && cn.IsSameNameAttr(Name));

                //2 try to find a server without a name
                if (snode == null)
                {
                    snode = node.Children.FirstOrDefault(cn => cn.IsSameName(CONFIG_SERVER_SECTION) && cn.AttrByName(Configuration.CONFIG_NAME_ATTR).Value.IsNullOrWhiteSpace());
                }

                if (snode == null)
                {
                    return;
                }
                node = snode;
            }


            ConfigAttribute.Apply(this, node);

            m_Prefixes.Clear();
            foreach (var name in node.Children
                     .Where(c => c.IsSameName(CONFIG_PREFIX_SECTION))
                     .Select(c => c.AttrByName(Configuration.CONFIG_NAME_ATTR).Value)
                     .Where(n => n.IsNotNullOrWhiteSpace()))
            {
                m_Prefixes.Add(name);
            }

            var nGate = node[CONFIG_GATE_SECTION];

            if (nGate.Exists)
            {
                m_Gate = FactoryUtils.MakeAndConfigure <INetGateImplementation>(nGate, typeof(NetGate), args: new object[] { this });
            }

            var nDispatcher = node[CONFIG_DISPATCHER_SECTION];

            if (nDispatcher.Exists)
            {
                m_Dispatcher = FactoryUtils.MakeAndConfigure <WorkDispatcher>(nDispatcher, typeof(WorkDispatcher), args: new object[] { this });
            }

            ErrorFilter.ConfigureMatches(node[CONFIG_DEFAULT_ERROR_HANDLER_SECTION], m_ErrorShowDumpMatches, m_ErrorLogMatches, null, GetType().FullName);
        }
Exemplo n.º 21
0
        public void CollectionChangedWhenValueIsRemoved()
        {
            var eventedList = new EventedList <int>();

            var called = false;

            eventedList.Add(1);
            eventedList.CollectionChanged += delegate { called = true; };
            eventedList.Remove(1);
            Assert.IsTrue(called);
        }
Exemplo n.º 22
0
        public void TestAdd()
        {
            Init();

            string addee = "String 1";

            m_uut.Add(addee);

            Assert.IsTrue(m_responses.Equals("m_uut_AboutToAddItem String 1 | m_uut_AddedItem String 1 | m_uut_ContentsChanged | "));
            Console.WriteLine(m_responses);
        }
Exemplo n.º 23
0
        public void ItemReplaced()
        {
            var eventedList = new EventedList <int>();

            var called = false;

            eventedList.Add(1);
            eventedList.CollectionChanged += delegate { called = true; };
            eventedList[0] = 2;
            Assert.IsTrue(called);
        }
Exemplo n.º 24
0
        public void UpdateDataItemOwner()
        {
            EventedList<IDataItem> dataItems = new EventedList<IDataItem>();
            DataItem dataItem = new DataItem();
            dataItems.Add(dataItem);
            Folder folder = new Folder {DataItems = dataItems};
            Assert.AreEqual(folder, dataItem.Owner);

            EventedList<IDataItem> dataItems2 = new EventedList<IDataItem>();
            DataItem dataItem2 = new DataItem();
            dataItems2.Add(dataItem2);
            folder.DataItems = dataItems2;
        }
Exemplo n.º 25
0
 public void CollectionChangedWhenValueIsAdded()
 {
     var eventedList = new EventedList<object>();
     var callCount = 0;
     var item = new object();
     eventedList.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e)
                                          {
                                              Assert.AreEqual(eventedList, sender);
                                              Assert.AreEqual(item, e.Item);
                                              callCount++;
                                          };
     eventedList.Add(item);
     Assert.AreEqual(1, callCount);
 }
Exemplo n.º 26
0
        public void CollectionChangedWhenValueIsAdded()
        {
            var eventedList = new EventedList <object>();
            var callCount   = 0;
            var item        = new object();

            eventedList.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e)
            {
                Assert.AreEqual(eventedList, sender);
                Assert.AreEqual(item, e.Item);
                callCount++;
            };
            eventedList.Add(item);
            Assert.AreEqual(1, callCount);
        }
        public object DeepCopy(object value)
        {
            if (value == null)
            {
                return(null);
            }

            var result = new EventedList <ICoordinate>();

            foreach (ICoordinate c in (EventedList <ICoordinate>)value)
            {
                result.Add(new Coordinate(c.X, c.Y, c.Z));
            }
            return(result);
        }
Exemplo n.º 28
0
        public void BinarySearchTest()
        {
            var l = new EventedList <EClass>(100);
            var r = new Random();

            for (var i = 0; i < 100; i++)
            {
                l.Add(new EClass(r.Next()));
            }
            l.Sort();
            var x = l[27];

            Assert.That(l.BinarySearch(x), Is.EqualTo(27));
            Assert.That(l.BinarySearch(x, new CEClass()), Is.EqualTo(27));
            Assert.That(l.BinarySearch(10, 40, x, new CEClass()), Is.EqualTo(27));
            Assert.That(l.BinarySearch(50, 40, x, new CEClass()), Is.Negative);
        }
Exemplo n.º 29
0
        public void UpdateDataItemOwner()
        {
            EventedList <IDataItem> dataItems = new EventedList <IDataItem>();
            DataItem dataItem = new DataItem();

            dataItems.Add(dataItem);
            Folder folder = new Folder {
                DataItems = dataItems
            };

            Assert.AreEqual(folder, dataItem.Owner);

            EventedList <IDataItem> dataItems2 = new EventedList <IDataItem>();
            DataItem dataItem2 = new DataItem();

            dataItems2.Add(dataItem2);
            folder.DataItems = dataItems2;
        }
Exemplo n.º 30
0
        public void CollectionChangedAddToDataItemsResultInCollectionChangedForAdapter()
        {
            IEventedList < IDataItem > dataItems  = new EventedList<IDataItem>();

            var adapter = new DataItemListAdapter<Url>(dataItems);

            var url = new Url();
            int callCount = 0;
            adapter.CollectionChanged += (sender, e) =>
                                             {
                                                 callCount++;
                                                 Assert.AreEqual(adapter, sender);
                                                 Assert.AreEqual(url, e.Item);
                                                 Assert.AreEqual(0, e.Index);
                                             };
            //action! add
            dataItems.Add(new DataItem(url));
            Assert.AreEqual(1,callCount);
        }
Exemplo n.º 31
0
        public void SettingDataItemsChangesList()
        {
            IEventedList <IDataItem> dataItems1 = new EventedList <IDataItem>();
            IEventedList <IDataItem> dataItems2 = new EventedList <IDataItem>();

            var adapter = new DataItemsEventedListAdapter <Url>(dataItems1);

            adapter.Add(new Url());
            adapter.DataItems = dataItems2;
            adapter.Add(new Url());

            //make sure both sets have one url now
            Assert.AreEqual(1, dataItems1.Count);
            Assert.AreEqual(1, dataItems2.Count);

            //make sure changes in the first set are not bubbled
            adapter.CollectionChanged += (s, e) => Assert.Fail("No change expected");
            dataItems1.Add(new DataItem(new Url()));
        }
Exemplo n.º 32
0
        public void CollectionChangedAddToDataItemsResultInCollectionChangedForAdapter()
        {
            IEventedList <IDataItem> dataItems = new EventedList <IDataItem>();

            var adapter = new DataItemsEventedListAdapter <Url>(dataItems);

            var url       = new Url();
            int callCount = 0;

            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(url, e.Item);
                Assert.AreEqual(0, e.Index);
            };
            //action! add
            dataItems.Add(new DataItem(url));
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 33
0
        public void ListShouldSubscribeToPropertyChangesInChildObjectAfterAdd()
        {
            var eventedList = new EventedList <MockClassWithTwoProperties>();

            //add three integers to the list.
            var properties = new MockClassWithTwoProperties();

            eventedList.Add(properties);

            object theSender = null;
            PropertyChangedEventArgs theEventArgs = null;

            eventedList.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
            {
                theSender    = sender;
                theEventArgs = e;
            };
            properties.StringProperty = "iets";
            Assert.AreEqual(properties, theSender);
            Assert.AreEqual("StringProperty", theEventArgs.PropertyName);
        }
Exemplo n.º 34
0
        public void UnsubscribeFromOldItemOnReplace()
        {
            var eventedList = new EventedList<MockClassWithTwoProperties>();

            var aPropertyChangeCount = 0;
            var listPropertyChangeCount = 0;

            var a = new MockClassWithTwoProperties {StringProperty = "a"};

            eventedList.Add(a);

            eventedList.PropertyChanged += delegate { listPropertyChangeCount++; };
            a.PropertyChanged += delegate { aPropertyChangeCount++; };

            // replace item
            eventedList[0] = new MockClassWithTwoProperties {StringProperty = "second a"};

            a.StringProperty = "a2";

            Assert.AreEqual(0, listPropertyChangeCount);
            Assert.AreEqual(1, aPropertyChangeCount);
        }
Exemplo n.º 35
0
        public void CollectionChangedRemoveDataItemsResultInCollectionChangedForAdapter()
        {
            //create a list of dataItem containing urls
            IEventedList<IDataItem> dataItems = new EventedList<IDataItem>();
            var url = new Url();
            var dataItem = new DataItem(url);
            dataItems.Add(dataItem);

            //adapter for the list
            var adapter = new DataItemListAdapter<Url>(dataItems);

            int callCount = 0;
            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(url, e.Item);
                Assert.AreEqual(0, e.Index);
            };

            //action! remove the url from the dataitems list
            dataItems.Remove(dataItem);
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 36
0
        public void DataValueSettingIsCollectionChanged()
        {
            //create a list of dataItem containing urls
            IEventedList<IDataItem> dataItems = new EventedList<IDataItem>();
            var oldUrl = new Url();
            var dataItem = new DataItem(oldUrl);
            dataItems.Add(dataItem);

            //adapter for the list
            var adapter = new DataItemListAdapter<Url>(dataItems);


            var newUrl = new Url();
            var sourceDataItem = new DataItem(newUrl);
            int callCount = 0;
            adapter.CollectionChanged += (sender, e) =>
            {
                callCount++;
                Assert.AreEqual(NotifyCollectionChangedAction.Replace, e.Action);
                Assert.AreEqual(adapter, sender);
                Assert.AreEqual(newUrl, e.Item);
                //discutable but current eventedlist implementation does this
                Assert.AreEqual(-1, e.OldIndex);
                Assert.AreEqual(0, e.Index);
            };

            //action! set Value of the first dataItem.
            dataItems[0].Value = newUrl;
            
            Assert.AreEqual(1, callCount);
        }
Exemplo n.º 37
0
        public void ZoomHistory()
        {
            const double cToleranceZoom = 0.001;

            // Setup test environment
            EventedList <IMapTool> tools = new EventedList <IMapTool>();

            MapControl      mapControl             = new MapControl();
            ZoomHistoryTool zoomHistoryToolMapTool = new ZoomHistoryTool(mapControl);

            zoomHistoryToolMapTool = new ZoomHistoryTool(mapControl);
            tools.Add(zoomHistoryToolMapTool);

            // First rendering is ignored
            mapControl.Map.Zoom   = 1.0;
            mapControl.Map.Center = new Coordinate(0.1, 0.2);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(0, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // First recorded rendering
            mapControl.Map.Zoom   = 1.1;
            mapControl.Map.Center = new Coordinate(1.2, 1.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(1, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Undo and redo the zoom
            zoomHistoryToolMapTool.PreviousZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(0, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(1, zoomHistoryToolMapTool.RedoCount);
            Assert.AreEqual(1.0, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(0.1, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(0.2, mapControl.Map.Center.Y, cToleranceZoom);

            zoomHistoryToolMapTool.NextZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(1, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);
            Assert.AreEqual(1.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(1.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(1.3, mapControl.Map.Center.Y, cToleranceZoom);

            // Second recorded rendering
            mapControl.Map.Zoom   = 2.1;
            mapControl.Map.Center = new Coordinate(2.2, 2.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(2, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Third recorded rendering
            mapControl.Map.Zoom   = 3.1;
            mapControl.Map.Center = new Coordinate(3.2, 3.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(3, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Fourth recorded rendering
            mapControl.Map.Zoom   = 4.1;
            mapControl.Map.Center = new Coordinate(4.2, 4.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(4, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Undo 2 times and redo 2 times
            Assert.AreEqual(4, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            zoomHistoryToolMapTool.PreviousZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(3.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(3.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(3.3, mapControl.Map.Center.Y, cToleranceZoom);
            Assert.AreEqual(3, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(1, zoomHistoryToolMapTool.RedoCount);

            zoomHistoryToolMapTool.PreviousZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(2.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(2.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(2.3, mapControl.Map.Center.Y, cToleranceZoom);
            Assert.AreEqual(2, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(2, zoomHistoryToolMapTool.RedoCount);

            zoomHistoryToolMapTool.NextZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(3.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(3.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(3.3, mapControl.Map.Center.Y, cToleranceZoom);
        }
Exemplo n.º 38
0
        public void ZoomHistory()
        {
            const double cToleranceZoom = 0.001;

            // Setup test environment
            EventedList<IMapTool> tools = new EventedList<IMapTool>();

            MapControl mapControl = new MapControl();
            ZoomHistoryTool zoomHistoryToolMapTool = new ZoomHistoryTool(mapControl);
            zoomHistoryToolMapTool = new ZoomHistoryTool(mapControl);
            tools.Add(zoomHistoryToolMapTool);

            // First rendering is ignored
            mapControl.Map.Zoom = 1.0;
            mapControl.Map.Center = new Coordinate(0.1, 0.2);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(0, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // First recorded rendering
            mapControl.Map.Zoom = 1.1;
            mapControl.Map.Center = new Coordinate(1.2, 1.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(1, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Undo and redo the zoom
            zoomHistoryToolMapTool.PreviousZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(0, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(1, zoomHistoryToolMapTool.RedoCount);
            Assert.AreEqual(1.0, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(0.1, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(0.2, mapControl.Map.Center.Y, cToleranceZoom);
          
            zoomHistoryToolMapTool.NextZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(1, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);
            Assert.AreEqual(1.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(1.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(1.3, mapControl.Map.Center.Y, cToleranceZoom);

            // Second recorded rendering
            mapControl.Map.Zoom = 2.1;
            mapControl.Map.Center = new Coordinate(2.2, 2.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(2, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Third recorded rendering
            mapControl.Map.Zoom = 3.1;
            mapControl.Map.Center = new Coordinate(3.2, 3.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(3, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Fourth recorded rendering
            mapControl.Map.Zoom = 4.1;
            mapControl.Map.Center = new Coordinate(4.2, 4.3);
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(4, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            // Undo 2 times and redo 2 times
            Assert.AreEqual(4, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(0, zoomHistoryToolMapTool.RedoCount);

            zoomHistoryToolMapTool.PreviousZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(3.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(3.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(3.3, mapControl.Map.Center.Y, cToleranceZoom);
            Assert.AreEqual(3, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(1, zoomHistoryToolMapTool.RedoCount);

            zoomHistoryToolMapTool.PreviousZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(2.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(2.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(2.3, mapControl.Map.Center.Y, cToleranceZoom);
            Assert.AreEqual(2, zoomHistoryToolMapTool.UndoCount);
            Assert.AreEqual(2, zoomHistoryToolMapTool.RedoCount);
            
            zoomHistoryToolMapTool.NextZoomState();
            zoomHistoryToolMapTool.MapRendered(mapControl.Map);
            Assert.AreEqual(3.1, mapControl.Map.Zoom, cToleranceZoom);
            Assert.AreEqual(3.2, mapControl.Map.Center.X, cToleranceZoom);
            Assert.AreEqual(3.3, mapControl.Map.Center.Y, cToleranceZoom);
        }
Exemplo n.º 39
0
        /// <summary>
        /// Initializes a new map
        /// </summary>
        public MapControl()
        {
            SetStyle(
                ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |
                ControlStyles.UserPaint, true);

            LostFocus     += MapBox_LostFocus;
            base.AllowDrop = true;

            tools = new EventedList <IMapTool>();

            tools.CollectionChanged += tools_CollectionChanged;
            // Visible = true, kalo ingin nampilin Arah Utara
            var northArrowTool = new NorthArrowTool(this)
            {
                Anchor  = AnchorStyles.Right | AnchorStyles.Top,
                Visible = false
            };

            Tools.Add(northArrowTool);

            var scaleBarTool = new ScaleBarTool(this)
            {
                Size    = new Size(230, 50),
                Anchor  = AnchorStyles.Right | AnchorStyles.Bottom,
                Visible = true
            };

            Tools.Add(scaleBarTool);
            // Visible = true, utuk menampilkan legend Map
            //legendTool = new LegendTool(this) {Anchor = AnchorStyles.Left | AnchorStyles.Top, Visible = false};
            //Tools.Add(legendTool);

            queryTool = new QueryTool(this);
            Tools.Add(queryTool);

            // add commonly used tools

            zoomHistoryTool = new ZoomHistoryTool(this);
            Tools.Add(zoomHistoryTool);

            panZoomTool = new PanZoomTool(this);
            Tools.Add(panZoomTool);

            wheelPanZoomTool = new PanZoomUsingMouseWheelTool(this)
            {
                WheelZoomMagnitude = 0.8
            };                                                                                   //-2};
            Tools.Add(wheelPanZoomTool);

            rectangleZoomTool = new ZoomUsingRectangleTool(this);
            Tools.Add(rectangleZoomTool);

            fixedZoomInTool = new FixedZoomInTool(this);
            Tools.Add(fixedZoomInTool);

            fixedZoomOutTool = new FixedZoomOutTool(this);
            Tools.Add(fixedZoomOutTool);

            selectTool = new SelectTool {
                IsActive = true
            };
            Tools.Add(selectTool);

            // Active = true, biar bisa move point...
            moveTool = new MoveTool {
                Name          = "Move selected vertices",
                FallOffPolicy = FallOffPolicyRule.None,
                IsActive      = true
            };
            Tools.Add(moveTool);

            linearMoveTool = new MoveTool
            {
                Name          = "Move selected vertices (linear)",
                FallOffPolicy = FallOffPolicyRule.Linear
            };
            Tools.Add(linearMoveTool);

            deleteTool = new DeleteTool();
            Tools.Add(deleteTool);

            measureTool = new MeasureTool(this);
            tools.Add(measureTool);

            profileTool = new CoverageProfileTool(this)
            {
                Name = "Make grid profile"
            };
            tools.Add(profileTool);

            curvePointTool = new CurvePointTool();
            Tools.Add(curvePointTool);

            drawPolygonTool = new DrawPolygonTool();
            Tools.Add(drawPolygonTool);

            snapTool = new SnapTool();
            Tools.Add(snapTool);

            var toolTipTool = new ToolTipTool();

            Tools.Add(toolTipTool);

            MapTool fileHandlerTool = new FileDragHandlerTool();

            Tools.Add(fileHandlerTool);

            Width  = 100;
            Height = 100;

            mapPropertyChangedEventHandler =
                new DelayedEventHandler <PropertyChangedEventArgs>(map_PropertyChanged_Delayed)
            {
                SynchronizingObject = this,
                FireLastEventOnly   = true,
                FullRefreshDelay    = 300,
                Filter = (sender, e) => sender is ILayer ||
                         sender is VectorStyle ||
                         sender is ITheme,
                Enabled = false
            };
            mapCollectionChangedEventHandler =
                new DelayedEventHandler <NotifyCollectionChangingEventArgs>(map_CollectionChanged_Delayed)
            {
                SynchronizingObject = this,
                FireLastEventOnly   = true,
                FullRefreshDelay    = 300,
                Filter = (sender, e) => sender is Map ||
                         sender is ILayer,
                Enabled = false
            };

            Map = new Map(ClientSize)
            {
                Zoom = 100
            };
        }
Exemplo n.º 40
0
        /// <summary>
        /// Initializes a new map
        /// </summary>
        public MapControl()
        {
            SetStyle(
                ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw |
                ControlStyles.UserPaint, true);

            LostFocus += MapBox_LostFocus;
            AllowDrop  = true;

            tools = new EventedList <IMapTool>();

            tools.CollectionChanged += tools_CollectionChanged;

            var northArrowTool = new NorthArrowTool(this);

            northArrowTool.Anchor  = AnchorStyles.Right | AnchorStyles.Top;
            northArrowTool.Visible = false; // activate using commands
            Tools.Add(northArrowTool);

            var scaleBarTool = new ScaleBarTool(this);

            scaleBarTool.Size    = new Size(230, 50);
            scaleBarTool.Anchor  = AnchorStyles.Right | AnchorStyles.Bottom;
            scaleBarTool.Visible = true;
            Tools.Add(scaleBarTool);

            legendTool = new LegendTool(this)
            {
                Anchor = AnchorStyles.Left | AnchorStyles.Top, Visible = false
            };
            Tools.Add(legendTool);

            queryTool = new QueryTool(this);
            Tools.Add(queryTool);

            // add commonly used tools

            zoomHistoryTool = new ZoomHistoryTool(this);
            Tools.Add(zoomHistoryTool);

            panZoomTool = new PanZoomTool(this);
            Tools.Add(panZoomTool);

            wheelZoomTool = new ZoomUsingMouseWheelTool(this);
            wheelZoomTool.WheelZoomMagnitude = 0.8;
            Tools.Add(wheelZoomTool);

            rectangleZoomTool = new ZoomUsingRectangleTool(this);
            Tools.Add(rectangleZoomTool);

            fixedZoomInTool = new FixedZoomInTool(this);
            Tools.Add(fixedZoomInTool);

            fixedZoomOutTool = new FixedZoomOutTool(this);
            Tools.Add(fixedZoomOutTool);

            selectTool = new SelectTool {
                IsActive = true
            };
            Tools.Add(selectTool);

            moveTool               = new MoveTool();
            moveTool.Name          = "Move selected vertices";
            moveTool.FallOffPolicy = FallOffPolicyRule.None;
            Tools.Add(moveTool);

            linearMoveTool               = new MoveTool();
            linearMoveTool.Name          = "Move selected vertices (linear)";
            linearMoveTool.FallOffPolicy = FallOffPolicyRule.Linear;
            Tools.Add(linearMoveTool);

            deleteTool = new DeleteTool();
            Tools.Add(deleteTool);

            measureTool = new MeasureTool(this);
            tools.Add(measureTool);

            profileTool      = new GridProfileTool(this);
            profileTool.Name = "Make grid profile";
            tools.Add(profileTool);

            curvePointTool = new CurvePointTool();
            Tools.Add(curvePointTool);

            snapTool = new SnapTool();
            Tools.Add(snapTool);

            var toolTipTool = new ToolTipTool();

            Tools.Add(toolTipTool);

            MapTool fileHandlerTool = new FileDragHandlerTool();

            Tools.Add(fileHandlerTool);

            Tools.Add(new ExportMapToImageMapTool());

            Width  = 100;
            Height = 100;

            mapPropertyChangedEventHandler =
                new SynchronizedDelayedEventHandler <PropertyChangedEventArgs>(map_PropertyChanged_Delayed)
            {
                FireLastEventOnly = true,
                Delay2            = 300,
                Filter            = (sender, e) => sender is ILayer ||
                                    sender is VectorStyle ||
                                    sender is ITheme,
                SynchronizeInvoke = this,
                Enabled           = false
            };
            mapCollectionChangedEventHandler =
                new SynchronizedDelayedEventHandler <NotifyCollectionChangedEventArgs>(map_CollectionChanged_Delayed)
            {
                FireLastEventOnly = true,
                Delay2            = 300,
                Filter            = (sender, e) => sender is Map ||
                                    sender is ILayer,
                SynchronizeInvoke = this,
                Enabled           = false
            };

            Map = new Map(ClientSize)
            {
                Zoom = 100
            };
        }
Exemplo n.º 41
0
 private void AddManyObjectsWithEvents(EventedList<MockWithPropertyAndCollectionChanged> eventedList)
 {
     for(var i = 0; i < 100000; i++)
     {
         eventedList.Add(new MockWithPropertyAndCollectionChanged());
     }
 }
Exemplo n.º 42
0
        public void List_Readonly()
        {
            var lst = new EventedList<string, string>("CONTEXT", false);

              var ro = false;

              lst.GetReadOnlyEvent = (l) => ro;

              lst.Add("a");
              lst.Add("b");
              lst.Add("c");

              Assert.AreEqual(3, lst.Count);
              ro = true;

              Assert.Throws<NFXException>(() =>  lst.Add("d"));
        }
Exemplo n.º 43
0
        public void ListShouldSubscribeToPropertyChangesInChildObjectAfterAdd()
        {
            var eventedList = new EventedList<MockClassWithTwoProperties>();

            //add three integers to the list.
            var properties = new MockClassWithTwoProperties();
            eventedList.Add( properties );

            object theSender = null;
            PropertyChangedEventArgs theEventArgs = null;
            eventedList.PropertyChanged += delegate(object sender, PropertyChangedEventArgs e)
                                               {
                                                   theSender = sender;
                                                   theEventArgs = e;
                                               };
            properties.StringProperty = "iets";
            Assert.AreEqual(properties, theSender);
            Assert.AreEqual("StringProperty", theEventArgs.PropertyName);
        }
        public object DeepCopy(object value)
        {
            if (value == null)
            {
                return null;
            }

            var result = new EventedList<ICoordinate>();
            foreach (ICoordinate c in (EventedList<ICoordinate>)value)
            {
                result.Add(new Coordinate(c.X,c.Y,c.Z));
            }
            return result;
        }
Exemplo n.º 45
0
		private EventedList<ConsoleMessage> GetFilteredBuffer(List<byte> filter) {
			EventedList<ConsoleMessage> ret = new EventedList<ConsoleMessage>();

			if (filter.Count > 0) {
				for (int i = 0; i < buffer.Count; i++) {
					if (filter.Contains(((ConsoleMessage)buffer[i]).Channel)) {
						ret.Add(buffer[i]);
					}
				}
				return ret;
			} else
				return buffer;
		}