Пример #1
0
        public static void Write(string fileName, IShapeCollection shapes, ShapeType shapeType, bool overwrite = false)
        {
            System.IO.MemoryStream shxWriter = new System.IO.MemoryStream();

            int offset = 50;

            foreach (IShape item in shapes)
            {
                shxWriter.Write(WriteHeaderToByte(offset, item.ContentLength), 0, 2 * ShapeConstants.IntegerSize);

                offset += item.ContentLength + 4;
            }

            System.IO.MemoryStream writer = new System.IO.MemoryStream();

            int fileLength = (int)shxWriter.Length / 2 + 50;

            writer.Write(WriteMainHeader(shapes, fileLength, shapeType), 0, 100);

            writer.Write(shxWriter.ToArray(), 0, (int)shxWriter.Length);

            //var mode = overwrite ? System.IO.FileMode.Create : System.IO.FileMode.CreateNew;
            var mode = Shapefile.GetMode(fileName, overwrite);

            System.IO.FileStream stream = new System.IO.FileStream(fileName, mode);

            writer.WriteTo(stream);

            shxWriter.Close();

            writer.Close();

            stream.Close();
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Presentation class that represents the PPTX file
            using (Presentation input = new Presentation())
            {
                // Accessing shapes collection for selected slide
                IShapeCollection shapes = input.Slides[0].Shapes;

                // Add autoshape Ellipse
                IAutoShape ellipse = shapes.AddAutoShape(ShapeType.Ellipse, 0, 100, 100, 100);

                // Add autoshape Rectangle
                IAutoShape rectangle = shapes.AddAutoShape(ShapeType.Rectangle, 100, 300, 100, 100);

                // Adding connector shape to slide shape collection
                IConnector connector = shapes.AddConnector(ShapeType.BentConnector2, 0, 0, 10, 10);

                // Joining Shapes to connectors
                connector.StartShapeConnectedTo = ellipse;
                connector.EndShapeConnectedTo   = rectangle;

                // Call reroute to set the automatic shortest path between shapes
                connector.Reroute();

                // Saving presenation
                input.Save(dataDir + "Connecting shapes using connectors_out.pptx", SaveFormat.Pptx);
            }
        }
        public static void Run()
        {
            //ExStart:CreateScalingFactorThumbnail
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Prseetation class
            using (Presentation pres = new Presentation())
            {
                // Get the first slide
                ISlide sld = pres.Slides[0];

                // Accessing the shape collection of slides
                IShapeCollection slideShapes = sld.Shapes;

                // Adding a group shape to the slide
                IGroupShape groupShape = slideShapes.AddGroupShape();

                // Adding shapes inside added group shape
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 100, 100, 100);
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 500, 100, 100, 100);
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 300, 300, 100, 100);
                groupShape.Shapes.AddAutoShape(ShapeType.Rectangle, 500, 300, 100, 100);

                // Adding group shape frame
                groupShape.Frame = new ShapeFrame(100, 300, 500, 40, NullableBool.False, NullableBool.False, 0);

                // Write the PPTX file to disk
                pres.Save(dataDir + "GroupShape_out.pptx", SaveFormat.Pptx);
            }
            //ExEnd:CreateScalingFactorThumbnail
        }
Пример #4
0
        public static IShapeCollection SimplifyByArea(IShapeCollection shapes, int zoomLevel)
        {
            var unitDistance = WebMercatorUtility.CalculateGroundResolution(zoomLevel, 35);

            var unitArea = unitDistance * unitDistance;

            return(SimplifyByArea(shapes, unitArea));
        }
Пример #5
0
        public static void Write(string shpFileName, IShapeCollection shapes, bool createDbf = false, bool overwrite = false)
        {
            if (shapes == null || shapes.Count < 1)
            {
                return;
            }

            var directory = System.IO.Path.GetDirectoryName(shpFileName);

            if (!System.IO.Directory.Exists(directory))
            {
                System.IO.Directory.CreateDirectory(directory);
            }

            ShapeType shapeType = shapes.First().Type;

            using (System.IO.MemoryStream featureWriter = new System.IO.MemoryStream())
            {
                int recordNumber = 0;

                foreach (IShape item in shapes)
                {
                    featureWriter.Write(WriteHeaderToByte(++recordNumber, item), 0, 2 * ShapeConstants.IntegerSize);

                    featureWriter.Write(item.WriteContentsToByte(), 0, 2 * item.ContentLength);
                }

                using (System.IO.MemoryStream shpWriter = new System.IO.MemoryStream())
                {
                    int fileLength = (int)featureWriter.Length / 2 + 50;

                    shpWriter.Write(WriteMainHeader(shapes, fileLength, shapeType), 0, 100);

                    shpWriter.Write(featureWriter.ToArray(), 0, (int)featureWriter.Length);

                    //var mode = overwrite ? System.IO.FileMode.Create : System.IO.FileMode.CreateNew;
                    var mode = Shapefile.GetMode(shpFileName, overwrite);

                    System.IO.FileStream stream = new System.IO.FileStream(shpFileName, mode);

                    shpWriter.WriteTo(stream);

                    stream.Close();

                    shpWriter.Close();

                    featureWriter.Close();
                }
            }

            ShxWriter.Write(Shapefile.GetShxFileName(shpFileName), shapes, shapeType, overwrite);

            if (createDbf)
            {
                Dbf.DbfFile.Write(Shapefile.GetDbfFileName(shpFileName), shapes.Count, overwrite);
            }
        }
Пример #6
0
        /// <ToBeCompleted></ToBeCompleted>
        public virtual void CopyFrom(IShapeCollection source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            Clear();
            foreach (Shape shape in source.BottomUp)
            {
                Shape shapeClone = null;
                // If the parent shape has no template, we assume that this is
                // the shape of the template itself, so it's children should be
                // template-free, too
                if (Owner.Template == null)
                {
                    shapeClone = shape.Type.CreateInstance();
                    shapeClone.CopyFrom(shape);
                }
                else
                {
                    shapeClone = shape.Clone();
                }
                shapeClone.ZOrder         = shape.ZOrder;
                shapeClone.Parent         = this.Owner;
                shapeClone.DisplayService = this.Owner.DisplayService;

                this.shapes.Add(shapeClone);
                this.AddShapeToIndex(shapeClone);
            }
            if (source is ShapeAggregation)
            {
                ShapeAggregation src = (ShapeAggregation)source;
                this.aggregationAngle = src.aggregationAngle;
                this.rotationCenter   = src.rotationCenter;
                // Copy center points of the shapes
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = src.shapePositions[src.shapes[i]];
                    this.shapePositions.Add(this.shapes[i], shapePos);
                }
            }
            else
            {
                // if the source ShapeCollection is not a ShapeAggregation,
                // store unrotated ShapePositions nevertheless
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = Point.Empty;
                    shapePos.Offset(shapes[i].X, shapes[i].Y);
                    this.shapePositions.Add(shapes[i], shapePos);
                }
            }
        }
Пример #7
0
        public static List <EsriPoint> ExtractPoints(this IShapeCollection shapes)
        {
            List <EsriPoint> result = new List <EsriPoint>();

            foreach (ISimplePoints shape in shapes)
            {
                result.AddRange(shape.Points);
            }

            return(result);
        }
Пример #8
0
 /// <override></override>
 public override void CopyFrom(IShapeCollection source)
 {
     base.CopyFrom(source);
     if (source is GroupShapeAggregation)
     {
         this.center = ((GroupShapeAggregation)source).Center;
     }
     else
     {
         CalcCenter();
     }
 }
Пример #9
0
        private void AddShapefile(IShapeCollection shapes, string title)
        {
            this.Presenter.ShapeCollections.Add(new ShapeCollection(shapes, title));

            var geometries = shapes.Select(i => i.AsSqlGeometry(0)).ToList();

            var vertexes = shapes.ExtractPoints().Select(i => (((Ham.SpatialBase.IPoint)i).AsSqlGeometry(0))).ToList();

            this.map.DrawGeometries(geometries, Guid.NewGuid().ToString(), VisualParameters.CreateNew(.7));

            this.map.DrawGeometries(vertexes, Guid.NewGuid().ToString(), VisualParameters.CreateNew(.9));
        }
Пример #10
0
        public ShapeCollection(IShapeCollection shapes, string title)
        {
            this.Title = title;

            this.Shapes = shapes;

            this.Geometries = shapes.Select(i => i.AsSqlGeometry(0)).ToList();


            this.Statistics = new AreaStatistics(shapes);

            this.AngleStat = new AngleStatistics(shapes);
        }
Пример #11
0
        public static List <SqlGeometry> AsSqlGeometry(this IShapeCollection shapes, int srid)
        {
            var count = shapes.Count();

            List <SqlGeometry> result = new List <SqlGeometry>(count);

            for (int i = 0; i < count; i++)
            {
                result.Add(shapes[i].AsSqlGeometry(srid));
            }

            return(result);
        }
Пример #12
0
        public static IShapeCollection AdditiveSimplifyByAngle(IShapeCollection shapes, double threshold)
        {
            return(Process(shapes, threshold, (i, t) => ShapeUtility.AdditiveSimplifyByAngle(i, t)));

            //if (shapes.First().Type == ShapeType.Polygon || shapes.First().Type == ShapeType.PolygonZ)
            //{
            //    var result = new ShapeCollection<Polygon>();

            //    foreach (ISimplePoints feature in shapes)
            //    {
            //        //var temp = ShapeUtility.SimplifyByAngle(feature.Points, threshold);
            //        var temp = feature.Parts.Select((i, index) => ShapeUtility.AdditiveSimplifyByAngle(feature.GetPart(index), threshold)).ToArray();

            //        if (temp == null || temp[0].Length == 0)
            //            continue;

            //        //if (temp.Length > 2)
            //        //{
            //        result.Add(new Polygon(temp));
            //        //}
            //    }

            //    return result;
            //}
            //else if (shapes.First().Type == ShapeType.PolyLine || shapes.First().Type == ShapeType.PolyLineZ || shapes.First().Type == ShapeType.PolyLineM)
            //{
            //    var result = new ShapeCollection<PolyLine>();

            //    foreach (ISimplePoints feature in shapes)
            //    {
            //        //var temp = ShapeUtility.SimplifyByAngle(feature.Points, threshold);
            //        var temp = feature.Parts.Select((i, index) => ShapeUtility.AdditiveSimplifyByAngle(feature.GetPart(index), threshold)).ToArray();

            //        if (temp == null || temp.Length == 0 || temp.Sum(i => i.Length) == 0)
            //            continue;

            //        //if (temp.Length > 1)
            //        //{
            //        result.Add(new PolyLine(temp));
            //        //}
            //    }

            //    return result;
            //}
            //else
            //{
            //    throw new NotImplementedException();
            //}
        }
Пример #13
0
        public static IShapeCollection SimplifyByAngle(IShapeCollection shapes, double threshold)
        {
            return(Process(shapes, threshold, (i, t) => ShapeUtility.SimplifyByAngle(i, t)));


            //if (shapes.First().Type == ShapeType.Polygon || shapes.First().Type == ShapeType.PolygonZ)
            //{
            //    var result = new ShapeCollection<Polygon>();

            //    foreach (ISimplePoints feature in shapes)
            //    {
            //        var temp = ShapeUtility.SimplifyByAngle(feature.Points, threshold);

            //        if (temp == null)
            //            continue;

            //        if (temp.Length > 2)
            //        {
            //            result.Add(new Polygon(temp));
            //        }
            //    }

            //    return result;
            //}
            //else if (shapes.First().Type == ShapeType.PolyLine || shapes.First().Type == ShapeType.PolyLineZ || shapes.First().Type == ShapeType.PolyLineM)
            //{
            //    var result = new ShapeCollection<PolyLine>();

            //    foreach (ISimplePoints feature in shapes)
            //    {
            //        var temp = ShapeUtility.SimplifyByAngle(feature.Points, threshold);

            //        if (temp == null)
            //            continue;

            //        if (temp.Length > 2)
            //        {
            //            result.Add(new PolyLine(temp));
            //        }
            //    }

            //    return result;
            //}
            //else
            //{
            //    throw new NotImplementedException();
            //}
        }
Пример #14
0
 /// <override></override>
 public override void CopyFrom(IShapeCollection source)
 {
     base.CopyFrom(source);
     if (source is CompositeShapeAggregation) {
         CompositeShapeAggregation src = (CompositeShapeAggregation)source;
         // Copy relative positions of the children
         relativePositions.Clear();
         int cnt = shapes.Count;
         for (int i = 0; i < cnt; ++i) {
             // Copy all items
             PointPositions srcPtPositions = src.relativePositions[src.shapes[i]];
             PointPositions dstPtPositions = new PointPositions();
             foreach (KeyValuePair<ControlPointId, RelativePosition> item in srcPtPositions.Items)
                 dstPtPositions.Items.Add(item.Key, item.Value);
             relativePositions.Add(shapes[i], dstPtPositions);
         }
     }
 }
Пример #15
0
        public static IShapeCollection AdditiveSimplifyByArea(IShapeCollection shapes, double threshold)
        {
            return(Process(shapes, threshold, (i, t) => ShapeUtility.AdditiveSimplifyByArea(i, t)));

            //ShapeCollection<Polygon> result = new ShapeCollection<Polygon>();

            //foreach (ISimplePoints feature in shapes)
            //{
            //    var points = feature.Parts.Select((i, index) => ShapeUtility.AdditiveSimplifyByArea(feature.GetPart(index), threshold)).ToArray();

            //    if (points == null)
            //        continue;

            //    result.Add(new Polygon(points));
            //}

            //return result;
        }
Пример #16
0
        public static IShapeCollection Process(IShapeCollection shapes, double threshold, Func <EsriPoint[], double, EsriPoint[]> method)
        {
            if (shapes.First().Type == ShapeType.Polygon || shapes.First().Type == ShapeType.PolygonZ)
            {
                var result = new List <Polygon>();

                foreach (ISimplePoints feature in shapes)
                {
                    var temp = feature.Parts.Select((i, index) => method(feature.GetPart(index), threshold)).Where(i => i != null && i.Length > 3).ToArray();

                    if (temp == null || temp.Length == 0 || temp.Sum(i => i.Length) == 0)
                    {
                        continue;
                    }

                    result.Add(new Polygon(temp));
                }

                return(new ShapeCollection <Polygon>(result));
            }
            else if (shapes.First().Type == ShapeType.PolyLine || shapes.First().Type == ShapeType.PolyLineZ || shapes.First().Type == ShapeType.PolyLineM)
            {
                var result = new List <PolyLine>();

                foreach (ISimplePoints feature in shapes)
                {
                    var temp = feature.Parts.Select((i, index) => method(feature.GetPart(index), threshold)).Where(i => i != null && i.Length > 1).ToArray();

                    if (temp == null || temp.Length == 0 || temp.Sum(i => i.Length) == 0)
                    {
                        continue;
                    }

                    result.Add(new PolyLine(temp));
                }

                return(new ShapeCollection <PolyLine>(result));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
        public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Presentation class
            using (Presentation srcPres = new Presentation(dataDir + "Source Frame.pptx"))
            {
                IShapeCollection sourceShapes = srcPres.Slides[0].Shapes;
                ILayoutSlide     blankLayout  = srcPres.Masters[0].LayoutSlides.GetByType(SlideLayoutType.Blank);
                ISlide           destSlide    = srcPres.Slides.AddEmptySlide(blankLayout);
                IShapeCollection destShapes   = destSlide.Shapes;
                destShapes.AddClone(sourceShapes[1], 50, 150 + sourceShapes[0].Height);
                destShapes.AddClone(sourceShapes[2]);
                destShapes.InsertClone(0, sourceShapes[0], 50, 150);

                //Write the PPTX file to disk
                srcPres.Save(dataDir + "CloneShape_out.pptx", SaveFormat.Pptx);
            }
        }
Пример #18
0
        public AreaStatistics(IShapeCollection shapes)
        {
            this.Areas = new List <double>();

            this.NumberOfPoints = 0;

            Threshold = 0;

            foreach (ISimplePoints item in shapes)
            {
                this.NumberOfPoints += item.Points.Length;

                var areas = ShapeUtility.GetAreas(item.Points);

                if (areas != null && areas.Length > 0)
                {
                    this.Areas.AddRange(areas);
                }
            }
        }
Пример #19
0
        public static IShapeCollection SimplifyByArea(IShapeCollection shapes, double threshold)
        {
            return(Process(shapes, threshold, (i, t) => ShapeUtility.SimplifyByArea(i, t)));

            //ShapeCollection<PolyLine> result = new ShapeCollection<PolyLine>();

            //foreach (ISimplePoints feature in shapes)
            //{
            //    var temp = ShapeUtility.SimplifyByArea(feature.Points, threshold);

            //    if (temp == null)
            //        continue;

            //    if (temp.Length > 2)
            //    {
            //        result.Add(new PolyLine(temp));
            //    }
            //}

            //return result;
        }
Пример #20
0
		/// <ToBeCompleted></ToBeCompleted>
		public virtual void CopyFrom(IShapeCollection source) {
			if (source == null) throw new ArgumentNullException("source");
			Clear();
			foreach (Shape shape in source.BottomUp) {
				Shape shapeClone = null;
				// If the parent shape has no template, we assume that this is 
				// the shape of the template itself, so it's children should be
				// template-free, too
				if (Owner.Template == null) {
					shapeClone = shape.Type.CreateInstance();
					shapeClone.CopyFrom(shape);
				} else shapeClone = shape.Clone();
				shapeClone.ZOrder = shape.ZOrder;
				shapeClone.Parent = this.Owner;
				shapeClone.DisplayService = this.Owner.DisplayService;

				this.shapes.Add(shapeClone);
				this.AddShapeToIndex(shapeClone);
			}
			if (source is ShapeAggregation) {
				ShapeAggregation src = (ShapeAggregation)source;
				this.aggregationAngle = src.aggregationAngle;
				this.rotationCenter = src.rotationCenter;
				// Copy center points of the shapes
				this.shapePositions.Clear();
				for (int i = 0; i < shapes.Count; ++i) {
					Point shapePos = src.shapePositions[src.shapes[i]];
					this.shapePositions.Add(this.shapes[i], shapePos);
				}
			} else {
				// if the source ShapeCollection is not a ShapeAggregation, 
				// store unrotated ShapePositions nevertheless
				this.shapePositions.Clear();
				for (int i = 0; i < shapes.Count; ++i) {
					Point shapePos = Point.Empty;
					shapePos.Offset(shapes[i].X, shapes[i].Y);
					this.shapePositions.Add(shapes[i], shapePos);
				}
			}
		}
        public static void Run()
        {
            //ExStart:ConnectShapeUsingConnectionSite
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Shapes();

            // Instantiate Presentation class that represents the PPTX file
            using (Presentation presentation = new Presentation())
            {
                // Accessing shapes collection for selected slide
                IShapeCollection shapes = presentation.Slides[0].Shapes;

                // Adding connector shape to slide shape collection
                IConnector connector = shapes.AddConnector(ShapeType.BentConnector3, 0, 0, 10, 10);

                // Add autoshape Ellipse
                IAutoShape ellipse = shapes.AddAutoShape(ShapeType.Ellipse, 0, 100, 100, 100);

                // Add autoshape Rectangle
                IAutoShape rectangle = shapes.AddAutoShape(ShapeType.Rectangle, 100, 200, 100, 100);

                // Joining Shapes to connectors
                connector.StartShapeConnectedTo = ellipse;
                connector.EndShapeConnectedTo   = rectangle;

                // Setting the desired connection site index of Ellipse shape for connector to get connected
                uint wantedIndex = 6;

                // Checking if desired index is less than maximum site index count
                if (ellipse.ConnectionSiteCount > wantedIndex)
                {
                    // Setting the desired connection site for connector on Ellipse
                    connector.StartShapeConnectionSiteIndex = wantedIndex;
                }

                // Save presentation
                presentation.Save(dataDir + "Connecting_Shape_on_desired_connection_site_out.pptx", SaveFormat.Pptx);
            }
            //ExEnd:ConnectShapeUsingConnectionSite
        }
Пример #22
0
 /// <override></override>
 public override void CopyFrom(IShapeCollection source)
 {
     base.CopyFrom(source);
     if (source is CompositeShapeAggregation)
     {
         ResizableShapeAggregation src = (ResizableShapeAggregation)source;
         // Copy relative positions of the children
         relativePositions.Clear();
         int cnt = shapes.Count;
         for (int i = 0; i < cnt; ++i)
         {
             // Copy all items
             PointPositions srcPtPositions = src.relativePositions[src.shapes[i]];
             PointPositions dstPtPositions = new PointPositions();
             foreach (KeyValuePair <ControlPointId, RelativePosition> item in srcPtPositions.Items)
             {
                 dstPtPositions.Items.Add(item.Key, item.Value);
             }
             relativePositions.Add(shapes[i], dstPtPositions);
         }
     }
 }
Пример #23
0
        public AngleStatistics(IShapeCollection shapes)
        {
            this.Angles = new List <double>();

            this.NumberOfPoints = 0;

            Threshold = 0;

            foreach (ISimplePoints item in shapes)
            {
                this.NumberOfPoints += item.Points.Length;

                var areas = ShapeUtility.GetCosineOfAngles(item.Points);

                if (areas != null && areas.Length > 0)
                {
                    this.Angles.AddRange(areas);
                }
            }

            RaisePropertyChanged("Average");
            RaisePropertyChanged("StandardDeviation");
            RaisePropertyChanged("Description");
        }
Пример #24
0
 public static IShapeCollection AdditiveSimplifyByAreaPlus(IShapeCollection shapes, double threshold)
 {
     return(Process(shapes, threshold, (i, t) => ShapeUtility.AdditiveSimplifyByAreaPlus(i, t)));
 }
Пример #25
0
        /// <ToBeCompleted></ToBeCompleted>
        public virtual void CopyFrom(IShapeCollection source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            Clear();
            foreach (Shape shape in source.BottomUp)
            {
                Shape shapeClone = null;
                // If the parent shape has no template, we assume that this is
                // the shape of the template itself, so it's children should be
                // template-free, too
                if (Owner.Template == null)
                {
                    shapeClone = shape.Type.CreateInstance();
                    shapeClone.CopyFrom(shape);
                }
                else
                {
                    shapeClone = shape.Clone();
                }
                shapeClone.ZOrder         = shape.ZOrder;
                shapeClone.Parent         = this.Owner;
                shapeClone.DisplayService = this.Owner.DisplayService;

                this.shapes.Add(shapeClone);
                this.AddShapeToIndex(shapeClone);
            }

            // Experimental version of copying shapes
            //// Copy shape properties over. If number of items does not match,
            //// create new shape clones.
            //IEnumerator<Shape> sourceShapes = source.BottomUp.GetEnumerator();
            //IEnumerator<Shape> destShapes = this.BottomUp.GetEnumerator();
            //while (sourceShapes.MoveNext()) {
            //    Shape shape = sourceShapes.Current;
            //    Shape shapeClone = null;
            //    bool shapeExists = destShapes.MoveNext();
            //    if (shapeExists) {
            //        shapeClone = destShapes.Current;
            //        shapeClone.CopyFrom(shape);
            //    } else {
            //        shapeClone = shape.Clone();
            //        shapeClone.Parent = this.Owner;
            //    }
            //    shapeClone.ZOrder = shape.ZOrder;
            //    shapeClone.DisplayService = this.Owner.DisplayService;

            //    // Add new shape to collection
            //    if (!shapeExists) {
            //        this.shapes.Add(shapeClone);
            //        this.AddShapeToIndex(shapeClone);
            //    }
            //}

            if (source is ShapeAggregation)
            {
                ShapeAggregation src = (ShapeAggregation)source;
                this.aggregationAngle = src.aggregationAngle;
                this.rotationCenter   = src.rotationCenter;
                // Copy center points of the shapes
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = src.shapePositions[src.shapes[i]];
                    this.shapePositions.Add(this.shapes[i], shapePos);
                }
            }
            else
            {
                // if the source ShapeCollection is not a ShapeAggregation,
                // store unrotated ShapePositions nevertheless
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i)
                {
                    Point shapePos = Point.Empty;
                    shapePos.Offset(shapes[i].X, shapes[i].Y);
                    this.shapePositions.Add(shapes[i], shapePos);
                }
            }
        }
Пример #26
0
		/// <override></override>
		public override void CopyFrom(IShapeCollection source) {
			base.CopyFrom(source);
			if (source is GroupShapeAggregation)
			   this.center = ((GroupShapeAggregation)source).Center;
			else CalcCenter();
		}
Пример #27
0
		/// <summary>
		/// Returns a collection of <see cref="T:Dataweb.NShape.Advanced.MenuItemDef" /> for constructing context menus etc.
		/// </summary>
		public IEnumerable<MenuItemDef> GetMenuItemDefs(IShapeCollection selectedShapes)
		{
			// ToDo: No actions at the moment
			yield break;
		}
Пример #28
0
        /// <ToBeCompleted></ToBeCompleted>
        public virtual void CopyFrom(IShapeCollection source)
        {
            if (source == null) throw new ArgumentNullException("source");
            Clear();
            foreach (Shape shape in source.BottomUp) {
                Shape shapeClone = null;
                // If the parent shape has no template, we assume that this is
                // the shape of the template itself, so it's children should be
                // template-free, too
                if (Owner.Template == null) {
                    shapeClone = shape.Type.CreateInstance();
                    shapeClone.CopyFrom(shape);
                } else shapeClone = shape.Clone();
                shapeClone.ZOrder = shape.ZOrder;
                shapeClone.Parent = this.Owner;
                shapeClone.DisplayService = this.Owner.DisplayService;

                this.shapes.Add(shapeClone);
                this.AddShapeToIndex(shapeClone);
            }

            // Experimental version of copying shapes
            //// Copy shape properties over. If number of items does not match,
            //// create new shape clones.
            //IEnumerator<Shape> sourceShapes = source.BottomUp.GetEnumerator();
            //IEnumerator<Shape> destShapes = this.BottomUp.GetEnumerator();
            //while (sourceShapes.MoveNext()) {
            //    Shape shape = sourceShapes.Current;
            //    Shape shapeClone = null;
            //    bool shapeExists = destShapes.MoveNext();
            //    if (shapeExists) {
            //        shapeClone = destShapes.Current;
            //        shapeClone.CopyFrom(shape);
            //    } else {
            //        shapeClone = shape.Clone();
            //        shapeClone.Parent = this.Owner;
            //    }
            //    shapeClone.ZOrder = shape.ZOrder;
            //    shapeClone.DisplayService = this.Owner.DisplayService;

            //    // Add new shape to collection
            //    if (!shapeExists) {
            //        this.shapes.Add(shapeClone);
            //        this.AddShapeToIndex(shapeClone);
            //    }
            //}

            if (source is ShapeAggregation) {
                ShapeAggregation src = (ShapeAggregation)source;
                this.aggregationAngle = src.aggregationAngle;
                this.rotationCenter = src.rotationCenter;
                // Copy center points of the shapes
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i) {
                    Point shapePos = src.shapePositions[src.shapes[i]];
                    this.shapePositions.Add(this.shapes[i], shapePos);
                }
            } else {
                // if the source ShapeCollection is not a ShapeAggregation,
                // store unrotated ShapePositions nevertheless
                this.shapePositions.Clear();
                for (int i = 0; i < shapes.Count; ++i) {
                    Point shapePos = Point.Empty;
                    shapePos.Offset(shapes[i].X, shapes[i].Y);
                    this.shapePositions.Add(shapes[i], shapePos);
                }
            }
        }
Пример #29
0
        internal static byte[] WriteMainHeader(IShapeCollection shapes, int fileLength, ShapeType shapeType)
        {
            System.IO.MemoryStream result = new System.IO.MemoryStream();

            result.Write(IRI.Ket.Common.Helpers.StreamHelper.Int32ToBigEndianOrderedBytes(ShapeConstants.FileCode), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            result.Write(IRI.Ket.Common.Helpers.StreamHelper.Int32ToBigEndianOrderedBytes(fileLength), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(ShapeConstants.Version), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes((int)shapeType), 0, ShapeConstants.IntegerSize);

            result.Write(System.BitConverter.GetBytes(shapes.MainHeader.XMin), 0, ShapeConstants.DoubleSize);

            result.Write(System.BitConverter.GetBytes(shapes.MainHeader.YMin), 0, ShapeConstants.DoubleSize);

            result.Write(System.BitConverter.GetBytes(shapes.MainHeader.XMax), 0, ShapeConstants.DoubleSize);

            result.Write(System.BitConverter.GetBytes(shapes.MainHeader.YMax), 0, ShapeConstants.DoubleSize);


            double tempValue = shapes.MainHeader.ZMin;

            if (double.IsNaN(tempValue))
            {
                tempValue = 0;
            }

            result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);


            tempValue = shapes.MainHeader.ZMax;

            if (double.IsNaN(tempValue))
            {
                tempValue = 0;
            }

            result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);


            tempValue = shapes.MainHeader.MMin;

            if (double.IsNaN(tempValue))
            {
                tempValue = 0;
            }

            result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);


            tempValue = shapes.MainHeader.MMax;

            if (double.IsNaN(tempValue))
            {
                tempValue = 0;
            }

            result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);

            return(result.ToArray());
        }
Пример #30
0
		private void BoundingRectangleTestCore(IShapeCollection shapes, int shapePos, int shapeSize, int shapeAngle) {
			foreach (Shape s in shapes) {
				// Move shape
				s.MoveTo(shapePos, shapePos);

				// Resize shape
				if (s is RectangleBase) {
					((RectangleBase)s).Width = shapeSize;
					((RectangleBase)s).Height = shapeSize;
				} else if (s is DiamondBase) {
					((DiamondBase)s).Width = shapeSize;
					((DiamondBase)s).Height = shapeSize;
				} else if (s is CircleBase)
					((CircleBase)s).Diameter = shapeSize;
				else if (s is SquareBase) {
					((SquareBase)s).Size = shapeSize;
				} else if (s is ImageBasedShape) {
					Rectangle r = s.GetBoundingRectangle(true);	// Get current size
					Point p = s.GetControlPointPosition(8);		// Get current control point pos
					((ImageBasedShape)s).MoveControlPointTo(8, 0, r.Bottom + (shapeSize - r.Height), ResizeModifiers.None);
				} else if (s is PolylineBase) {
					s.MoveControlPointTo(ControlPointId.FirstVertex, -shapeSize / 2, -shapeSize / 2, ResizeModifiers.None);
					s.MoveControlPointTo(ControlPointId.LastVertex, shapeSize / 2, shapeSize / 2, ResizeModifiers.None);
				} else if (s is CircularArcBase) {
					// ToDo: Add third point
					s.MoveControlPointTo(ControlPointId.FirstVertex, -shapeSize / 2, -shapeSize / 2, ResizeModifiers.None);
					s.MoveControlPointTo(ControlPointId.LastVertex, shapeSize / 2, shapeSize / 2, ResizeModifiers.None);
				} else if (s is ShapeGroup) {
					s.Children.Add(shapes.TopMost);
				} else throw new Exception(string.Format("Untested {0} '{1}'!", s.Type.GetType().Name, s.Type.FullName));

				// rotate shape
				if (shapeAngle != 0 && s is IPlanarShape)
					((IPlanarShape)s).Angle = shapeAngle;

				Rectangle tightBounds = s.GetBoundingRectangle(true);
				Rectangle looseBounds = s.GetBoundingRectangle(false);

				Assert.IsTrue(Geometry.IsValid(tightBounds));
				Assert.IsTrue(Geometry.IsValid(looseBounds));
				Assert.IsTrue(!tightBounds.IsEmpty);
				Assert.IsTrue(!looseBounds.IsEmpty);

				Assert.IsTrue(tightBounds.Width >= 0);
				Assert.IsTrue(tightBounds.Height >= 0);
				Assert.IsTrue(looseBounds.Width >= 0);
				Assert.IsTrue(looseBounds.Height >= 0);

				Assert.IsTrue(tightBounds.X >= looseBounds.X);
				Assert.IsTrue(tightBounds.Y >= looseBounds.Y);
				Assert.IsTrue(tightBounds.Width <= looseBounds.Width);
				Assert.IsTrue(tightBounds.Height <= looseBounds.Height);

				// ToDo: Add more precise tests
				// - Calculate expected (rotated) size of the shape and compare with tightBounds
				// - Calculate expected (rotated) size of the shape's control points and compare with looseBounds
			}
		}
Пример #31
0
 /// <summary>
 /// Returns a collection of <see cref="T:Dataweb.NShape.Advanced.MenuItemDef" /> for constructing context menus etc.
 /// </summary>
 public IEnumerable <MenuItemDef> GetMenuItemDefs(IShapeCollection selectedShapes)
 {
     // ToDo: No actions at the moment
     yield break;
 }
Пример #32
0
        internal static byte[] WriteMainHeader(IShapeCollection shapes, int fileLength, ShapeType shapeType)
        {
            return(ShpWriter.WriteMainHeader(shapes, fileLength, shapeType));
            //System.IO.MemoryStream result = new System.IO.MemoryStream();

            //result.Write(IRI.Ket.IO.Binary.Int32ToBigEndianOrderedBytes(ShapeConstants.FileCode), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(0), 0, ShapeConstants.IntegerSize);

            //result.Write(IRI.Ket.IO.Binary.Int32ToBigEndianOrderedBytes(fileLength), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(ShapeConstants.Version), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes((int)shapeType), 0, ShapeConstants.IntegerSize);

            //result.Write(System.BitConverter.GetBytes(MapStatistics.GetMinX(shapes)), 0, ShapeConstants.DoubleSize);

            //result.Write(System.BitConverter.GetBytes(MapStatistics.GetMinY(shapes)), 0, ShapeConstants.DoubleSize);

            //result.Write(System.BitConverter.GetBytes(MapStatistics.GetMaxX(shapes)), 0, ShapeConstants.DoubleSize);

            //result.Write(System.BitConverter.GetBytes(MapStatistics.GetMaxY(shapes)), 0, ShapeConstants.DoubleSize);


            //double tempValue = MapStatistics.GetMinZ(shapes);

            //if (double.IsNaN(tempValue)) { tempValue = 0; }

            //result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);


            //tempValue = MapStatistics.GetMaxZ(shapes);

            //if (double.IsNaN(tempValue)) { tempValue = 0; }

            //result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);


            //tempValue = MapStatistics.GetMinM(shapes);

            //if (double.IsNaN(tempValue)) { tempValue = 0; }

            //result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);


            //tempValue = MapStatistics.GetMaxM(shapes);

            //if (double.IsNaN(tempValue)) { tempValue = 0; }

            //result.Write(System.BitConverter.GetBytes(tempValue), 0, ShapeConstants.DoubleSize);

            //return result.ToArray();
        }