コード例 #1
0
		/// <override></override>
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) {
			if (context != null && context.Instance != null && provider != null) {
				IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
				if (edSvc != null && context.Instance is Shape) {
					Shape shape = (Shape)context.Instance;
					using (CheckedListBox listBox = new CheckedListBox()) {
						listBox.BorderStyle = BorderStyle.None;
						listBox.IntegralHeight = false;
						listBox.Items.Clear();

						// Add existing layers and check shape's layers
						foreach (Layer l in shape.Diagram.Layers) {
							int idx = listBox.Items.Count;
							listBox.Items.Insert(idx, l);
							listBox.SetItemChecked(idx, ((shape.Layers & l.Id) != 0));
						}

						edSvc.DropDownControl(listBox);
						LayerIds shapeLayers = LayerIds.None;
						for (int i = listBox.Items.Count - 1; i >= 0; --i) {
							if (listBox.GetItemChecked(i))
								shapeLayers |= ((Layer)listBox.Items[i]).Id;
						}
						shape.Diagram.RemoveShapeFromLayers(shape, LayerIds.All);
						shape.Diagram.AddShapeToLayers(shape, shapeLayers);

						value = shapeLayers;
					}
				}
			}
			return value;
		}
コード例 #2
0
ファイル: LayerController.cs プロジェクト: LudovicT/NShape
        private string GetNewLayerName(Diagram diagram)
        {
            string result = string.Empty;
            // get all used Layerids
            LayerIds usedLayerIds = LayerIds.None;

            foreach (Layer l in diagram.Layers)
            {
                usedLayerIds |= l.Id;
            }
            // find the first Id available
            foreach (LayerIds value in Enum.GetValues(typeof(LayerIds)))
            {
                if (value == LayerIds.None)
                {
                    continue;
                }
                if ((usedLayerIds & value) == 0)
                {
                    int bitNo = (int)Math.Log((int)value, 2);
                    result = string.Format("Layer {0:D2}", bitNo + 1);
                    break;
                }
            }
            return(result);
        }
コード例 #3
0
        private List <LayerInfo> GetLayerInfos(Map map)
        {
            List <LayerInfo> layers = null;

            if (map != null && map.Layers != null)
            {
                foreach (Layer layer in map.Layers)
                {
                    FeatureLayer fLayer = layer as FeatureLayer;
                    if (fLayer != null && !string.IsNullOrWhiteSpace(fLayer.ID) && !fLayer.IsReadOnly)
                    {
                        if (layers == null)
                        {
                            layers = new List <LayerInfo>();
                        }

                        layers.Add(new LayerInfo()
                        {
                            Layer = fLayer, IsChecked = LayerIds != null ? LayerIds.Contains(layer.ID) : false
                        });
                        layer.SetValue(LayerProperties.IsEditableProperty, LayerIds == null ? true : LayerIds.Contains(layer.ID));
                    }
                }
            }
            return(layers);
        }
コード例 #4
0
ファイル: LayerController.cs プロジェクト: LudovicT/NShape
 /// <ToBeCompleted></ToBeCompleted>
 public static IEnumerable <Layer> GetLayers(LayerIds layerId, Diagram diagram)
 {
     if (diagram == null)
     {
         throw new ArgumentNullException("diagram");
     }
     return(diagram.Layers.GetLayers(layerId));
 }
コード例 #5
0
        /// <ToBeCompleted></ToBeCompleted>
        public static LayerInfo Create(int homeLayer, LayerIds supplementalLayers)
        {
            LayerInfo result = LayerInfo.Empty;

            result.HomeLayer          = homeLayer;
            result.SupplementalLayers = supplementalLayers;
            return(result);
        }
コード例 #6
0
        private LayerIds GetSelectedLayerIds()
        {
            LayerIds result = LayerIds.None;

            foreach (Layer selectedLayer in selectedLayers)
            {
                result |= selectedLayer.Id;
            }
            return(result);
        }
コード例 #7
0
ファイル: Collections.cs プロジェクト: nilavanrajamani/NShape
 public Layer this[LayerIds layerId] {
     get {
         Layer result = GetLayer(layerId);
         if (result == null)
         {
             throw new ItemNotFoundException <Layer>(result);
         }
         return(result);
     }
 }
コード例 #8
0
        public Layer GetLayer(LayerIds layerId)
        {
            int layerBit = GetLayerBit(layerId);

            if (layerBit < 0)
            {
                throw new ItemNotFoundException <LayerIds>(layerId);
            }
            return(layers[layerBit]);
        }
コード例 #9
0
        private LayerIds GetSelectedLayerIds()
        {
            LayerIds result = LayerIds.None;

            for (int i = selectedLayers.Count - 1; i >= 0; --i)
            {
                result |= selectedLayers[i].Id;
            }
            return(result);
        }
コード例 #10
0
        private Layer ConvertToLayer(ITypeDescriptorContext context, LayerIds value)
        {
            // Try interpreting as Name/Title
            Diagram diagram = GetDiagram(context);

            if (diagram == null)
            {
                throw new ArgumentException();
            }
            return(diagram.Layers[value]);
        }
コード例 #11
0
 public IEnumerable <Layer> FindLayers(LayerIds layerIds)
 {
     foreach (int id in LayerHelper.GetAllLayerIds(layerIds))
     {
         Layer layer = FindLayer(id);
         if (layer != null)
         {
             yield return(layer);
         }
     }
 }
コード例 #12
0
        private string ConvertToLayerName(ITypeDescriptorContext context, LayerIds value)
        {
            if (value == LayerIds.None)
            {
                return(null);
            }
            Layer layer = ConvertToLayer(context, value);

            if (layer == null)
            {
                throw new ArgumentException();
            }
            return(layer.Name);
        }
コード例 #13
0
 public IEnumerable <Layer> GetLayers(LayerIds layerId)
 {
     foreach (int layerBit in GetLayerBits(layerId))
     {
         if (layerBit == -1)
         {
             continue;
         }
         if (layers[layerBit] != null)
         {
             yield return(layers[layerBit]);
         }
     }
 }
コード例 #14
0
        private void UpdateLayerInfosState()
        {
            if (LayerInfos != null)
            {
                foreach (LayerInfo layerInfo in LayerInfos)
                {
                    layerInfo.IsChecked = LayerIds != null?LayerIds.Contains(layerInfo.Layer.ID) : false;

                    if (layerInfo.Layer != null)
                    {
                        layerInfo.Layer.SetValue(LayerProperties.IsEditableProperty, LayerIds == null ? true : LayerIds.Contains(layerInfo.Layer.ID));
                    }
                }
            }
        }
コード例 #15
0
        /// <summary>
        /// Converts a collection of combinable layers to a LayerIds value.
        /// Layers with ids that are not combinable will be omitted.
        /// </summary>
        public static LayerIds ConvertToLayerIds(IEnumerable <Layer> layers)
        {
            if (layers == null)
            {
                throw new ArgumentNullException("layers");
            }
            LayerIds result = LayerIds.None;

            foreach (Layer layer in layers)
            {
                if (IsCombinable(layer.LayerId))
                {
                    result |= ConvertToLayerIds(layer.LayerId);
                }
            }
            return(result);
        }
コード例 #16
0
        /// <summary>
        /// Converts a collection of combinable integer layer ids to a LayerIds value.
        /// Layer ids that are not comnbinable will be omitted.
        /// </summary>
        public static LayerIds ConvertToLayerIds(IEnumerable <int> layerNos)
        {
            if (layerNos == null)
            {
                throw new ArgumentNullException("layerIds");
            }
            LayerIds result = LayerIds.None;

            foreach (int id in layerNos)
            {
                if (IsCombinable(id))
                {
                    result |= ConvertToLayerIds(id);
                }
            }
            return(result);
        }
コード例 #17
0
        private int GetLayerBit(LayerIds layerId)
        {
            int result = -1;

            foreach (int layerBit in GetLayerBits(layerId))
            {
                if (result < 0)
                {
                    result = layerBit;
                }
                else
                {
                    throw new ArgumentException(string.Format("{0} is not a valid LayerId for one single layer."));
                }
            }
            return(result);
        }
コード例 #18
0
        /// <summary>
        /// Returns all layer ids of the given combined layers.
        /// </summary>
        public static IEnumerable <int> GetAllLayerIds(LayerIds layers)
        {
            if (layers == LayerIds.None)
            {
                yield break;
            }
            int bitNr = 1;

            foreach (LayerIds id in Enum.GetValues(typeof(LayerIds)))
            {
                if (id == LayerIds.None || id == LayerIds.All)
                {
                    continue;
                }
                if ((layers & id) != 0)
                {
                    yield return(bitNr);
                }
                ++bitNr;
            }
        }
コード例 #19
0
        private IEnumerable <int> GetLayerBits(LayerIds layerIds)
        {
            if (layerIds == LayerIds.None)
            {
                yield break;
            }
            int bitNo = 0;

            foreach (LayerIds id in Enum.GetValues(typeof(LayerIds)))
            {
                if (id == LayerIds.None || id == LayerIds.All)
                {
                    continue;
                }
                if ((layerIds & id) != 0)
                {
                    yield return(bitNo);
                }
                ++bitNo;
            }
        }
コード例 #20
0
        /// <summary>
        /// Converts a combinable LayerIds value to an integer layer id.
        /// </summary>
        /// <param name="layerId">A LayerIds value.</param>
        /// <remarks>Combinations of LayerIds values as well as LayerIds.All will lead to an ArgumentException.</remarks>
        public static int ConvertToLayerId(LayerIds layerId)
        {
            if (layerId > LayerIds.Layer32)
            {
                throw new ArgumentOutOfRangeException("layerId");
            }
            if (layerId == LayerIds.All)
            {
                throw new ArgumentException(string.Format(Dataweb.NShape.Properties.Resources.MessageFmt_0IsNotAValidLayerIdForOneSingleLayer, layerId), "layerId");
            }
            if (layerId == LayerIds.None)
            {
                return(Layer.NoLayerId);
            }
            double result = Math.Round(Math.Log((uint)layerId, 2), 12);

            if (result != (int)result)
            {
                throw new ArgumentException(string.Format(Dataweb.NShape.Properties.Resources.MessageFmt_0IsNotAValidLayerIdForOneSingleLayer, layerId), "layerId");
            }
            return(1 + (int)result);
        }
コード例 #21
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <summary>
		/// Aggregate the given shapes to a composite shape based on the bottom shape.
		/// </summary>
		public void AggregateCompositeShape(Diagram diagram, Shape compositeShape, IEnumerable<Shape> shapes,
		                                    LayerIds activeLayers)
		{
			if (compositeShape == null) throw new ArgumentNullException("compositeShape");
			if (shapes == null) throw new ArgumentNullException("shapes");
			// Add shapes to buffer (TopDown)
			shapeBuffer.Clear();
			foreach (Shape shape in shapes) {
				if (shape == compositeShape) continue;
				shapeBuffer.Add(shape);
			}
			ICommand cmd = new AggregateCompositeShapeCommand(diagram, activeLayers, compositeShape, shapeBuffer);
			Project.ExecuteCommand(cmd);
			shapeBuffer.Clear();
		}
コード例 #22
0
ファイル: Diagram.cs プロジェクト: LudovicT/NShape
 /// <summary>
 /// Disociates the given collection of <see cref="T:Dataweb.NShape.Advanced.Shape" /> to all specified layers.
 /// </summary>
 public void RemoveShapesFromLayers(IEnumerable<Shape> shapes, LayerIds layerIds)
 {
     if (shapes == null) throw new ArgumentNullException("shapes");
     foreach (Shape shape in shapes) {
         shape.Layers ^= (shape.Layers & layerIds);
         shape.Invalidate();
     }
 }
コード例 #23
0
ファイル: Diagram.cs プロジェクト: LudovicT/NShape
 /// <summary>
 /// Associates the given <see cref="T:Dataweb.NShape.Advanced.Shape" /> to all specified layers.
 /// </summary>
 public void AddShapeToLayers(Shape shape, LayerIds layerIds)
 {
     if (shape == null) throw new ArgumentNullException("shape");
     shape.Layers |= layerIds;
     shape.Invalidate();
 }
コード例 #24
0
ファイル: Diagram.cs プロジェクト: LudovicT/NShape
 /// <summary>
 /// Associates the given collection of <see cref="T:Dataweb.NShape.Advanced.Shape" /> to all specified layers.
 /// </summary>
 public void AddShapesToLayers(IEnumerable<Shape> shapes, LayerIds layerIds)
 {
     if (shapes == null) throw new ArgumentNullException("shapes");
     foreach (Shape shape in shapes) {
         shape.Layers |= layerIds;
         shape.Invalidate();
     }
 }
コード例 #25
0
ファイル: LayerController.cs プロジェクト: stewmc/vixen
		/// <ToBeCompleted></ToBeCompleted>
		public static IEnumerable<Layer> GetLayers(LayerIds layerId, Diagram diagram)
		{
			if (diagram == null) throw new ArgumentNullException("diagram");
			return diagram.Layers.GetLayers(layerId);
		}
コード例 #26
0
ファイル: Helpers.cs プロジェクト: nilavanrajamani/NShape
        public static void CreateDiagram(Project project, string diagramName, int shapesPerRow, int shapesPerColumn, bool connectShapes, bool withModels, bool withTerminalMappings, bool withModelMappings, bool withLayers, IList <String> shapeTypeNames)
        {
            const int shapeSize  = 80;
            int       lineLength = shapeSize / 2;

            //
            // Create the templates
            CreateTemplatesFromShapeTypes(project, shapeTypeNames, shapeSize, withModels, withTerminalMappings, withModelMappings, shapesPerRow * shapesPerColumn);
            //
            // Prepare the connection points
            ControlPointId leftPoint   = withModels ? ControlPointId.Reference : 4;
            ControlPointId rightPoint  = withModels ? ControlPointId.Reference : 5;
            ControlPointId topPoint    = withModels ? ControlPointId.Reference : 2;
            ControlPointId bottomPoint = withModels ? ControlPointId.Reference : 7;
            //
            // Create the diagram
            Diagram diagram = new Diagram(diagramName);
            //
            // Create and add layers
            LayerIds planarLayer = LayerIds.None, linearLayer = LayerIds.None, oddRowLayer = LayerIds.None,
                     evenRowLayer = LayerIds.None, oddColLayer = LayerIds.None, evenColLayer = LayerIds.None;

            if (withLayers)
            {
                const string planarLayerName   = "PlanarShapesLayer";
                const string linearLayerName   = "LinearShapesLayer";
                const string oddRowsLayerName  = "OddRowsLayer";
                const string evenRowsLayerName = "EvenRowsLayer";
                const string oddColsLayerName  = "OddColsLayer";
                const string evenColsLayerName = "EvenColsLayer";
                // Create Layers
                Layer planarShapesLayer = new Layer(planarLayerName);
                planarShapesLayer.Title = "Planar Shapes";
                planarShapesLayer.LowerZoomThreshold = 5;
                planarShapesLayer.UpperZoomThreshold = 750;
                diagram.Layers.Add(planarShapesLayer);
                Layer linearShapesLayer = new Layer(linearLayerName);
                linearShapesLayer.Title = "Linear Shapes";
                linearShapesLayer.LowerZoomThreshold = 10;
                linearShapesLayer.UpperZoomThreshold = 500;
                diagram.Layers.Add(linearShapesLayer);
                Layer oddRowsLayer = new Layer(oddRowsLayerName);
                oddRowsLayer.Title = "Odd Rows";
                oddRowsLayer.LowerZoomThreshold = 2;
                oddRowsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(oddRowsLayer);
                Layer evenRowsLayer = new Layer(evenRowsLayerName);
                evenRowsLayer.Title = "Even Rows";
                evenRowsLayer.LowerZoomThreshold = 2;
                evenRowsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(evenRowsLayer);
                Layer oddColsLayer = new Layer(oddColsLayerName);
                oddColsLayer.Title = "Odd Columns";
                oddColsLayer.LowerZoomThreshold = 2;
                oddColsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(oddColsLayer);
                Layer evenColsLayer = new Layer(evenColsLayerName);
                evenColsLayer.Title = "Even Columns";
                evenColsLayer.LowerZoomThreshold = 2;
                evenColsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(evenColsLayer);
                // Assign LayerIds
                planarLayer  = diagram.Layers.FindLayer(planarLayerName).Id;
                linearLayer  = diagram.Layers.FindLayer(linearLayerName).Id;
                oddRowLayer  = diagram.Layers.FindLayer(oddRowsLayerName).Id;
                evenRowLayer = diagram.Layers.FindLayer(evenRowsLayerName).Id;
                oddColLayer  = diagram.Layers.FindLayer(oddColsLayerName).Id;
                evenColLayer = diagram.Layers.FindLayer(evenColsLayerName).Id;
            }

            Template planarTemplate = null;
            Template linearTemplate = null;
            int      searchRange    = shapeSize / 2;

            for (int rowIdx = 0; rowIdx < shapesPerRow; ++rowIdx)
            {
                LayerIds rowLayer = ((rowIdx + 1) % 2 == 0) ? evenRowLayer : oddRowLayer;
                for (int colIdx = 0; colIdx < shapesPerRow; ++colIdx)
                {
                    LayerIds colLayer  = ((colIdx + 1) % 2 == 0) ? evenColLayer : oddColLayer;
                    int      shapePosX = shapeSize + colIdx * (lineLength + shapeSize);
                    int      shapePosY = shapeSize + rowIdx * (lineLength + shapeSize);

                    planarTemplate = GetNextPlanarTemplate(project, planarTemplate);
                    Shape planarShape = planarTemplate.CreateShape();
                    // Apply shape specific property values
                    if (planarShape is PictureBase)
                    {
                        ((PictureBase)planarShape).Image = new NamedImage(Properties.Resources.SamplePicture, "Sample Picture");
                    }
                    if (planarShape is ICaptionedShape)
                    {
                        ((ICaptionedShape)planarShape).SetCaptionText(0, string.Format("{0} / {1}", rowIdx + 1, colIdx + 1));
                    }
                    planarShape.MoveTo(shapePosX, shapePosY);
                    if (withModels)
                    {
                        project.Repository.Insert(planarShape.ModelObject);
                        ((GenericModelObject)planarShape.ModelObject).IntegerValue = rowIdx;
                    }

                    diagram.Shapes.Add(planarShape, project.Repository.ObtainNewTopZOrder(diagram));
                    if (withLayers)
                    {
                        diagram.AddShapeToLayers(planarShape, planarLayer | rowLayer | colLayer);
                    }
                    if (connectShapes)
                    {
                        linearTemplate = GetNextLinearTemplate(project, linearTemplate);
                        if (rowIdx > 0)
                        {
                            Shape lineShape = linearTemplate.CreateShape();
                            if (planarShape.HasControlPointCapability(topPoint, ControlPointCapabilities.Connect))
                            {
                                lineShape.Connect(ControlPointId.FirstVertex, planarShape, topPoint);
                                Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, planarShape));
                            }
                            Shape otherShape = diagram.Shapes.FindShape(shapePosX, shapePosY - shapeSize, ControlPointCapabilities.None, searchRange, null);
                            if (otherShape != null && otherShape.HasControlPointCapability(bottomPoint, ControlPointCapabilities.Connect))
                            {
                                lineShape.Connect(ControlPointId.LastVertex, otherShape, bottomPoint);
                                Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape));
                            }
                            // Add line shape if at least one connection was established.
                            if (lineShape.IsConnected(ControlPointId.FirstVertex, null) != ControlPointId.None && lineShape.IsConnected(ControlPointId.LastVertex, null) != ControlPointId.None)
                            {
                                diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram));
                                if (withLayers)
                                {
                                    diagram.AddShapeToLayers(lineShape, linearLayer);
                                }
                            }
                        }
                        if (colIdx > 0)
                        {
                            Shape lineShape = linearTemplate.CreateShape();
                            if (planarShape.HasControlPointCapability(leftPoint, ControlPointCapabilities.Connect))
                            {
                                lineShape.Connect(1, planarShape, leftPoint);
                                Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, planarShape));
                            }
                            Shape otherShape = diagram.Shapes.FindShape(shapePosX - shapeSize, shapePosY, ControlPointCapabilities.None, searchRange, null);
                            if (otherShape != null && otherShape.HasControlPointCapability(rightPoint, ControlPointCapabilities.Connect))
                            {
                                lineShape.Connect(2, otherShape, rightPoint);
                                Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape));
                            }
                            // Add line shape if at least one connection was established.
                            if (lineShape.IsConnected(ControlPointId.FirstVertex, null) != ControlPointId.None && lineShape.IsConnected(ControlPointId.LastVertex, null) != ControlPointId.None)
                            {
                                diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram));
                                if (withLayers)
                                {
                                    diagram.AddShapeToLayers(lineShape, linearLayer);
                                }
                            }
                        }
                    }
                }
            }
            diagram.Width  = (lineLength + shapeSize) * shapesPerRow + 2 * shapeSize;
            diagram.Height = (lineLength + shapeSize) * shapesPerColumn + 2 * shapeSize;
            project.Repository.InsertAll(diagram);
        }
コード例 #27
0
 public IEnumerable <Layer> GetLayers(LayerIds layerIds)
 {
     return(FindLayers(layerIds));
 }
コード例 #28
0
        public Layer FindLayer(LayerIds layerId)
        {
            int id = Layer.ConvertToLayerId(layerId);

            return(FindLayer(id));
        }
コード例 #29
0
 public Layer GetLayer(LayerIds layerId)
 {
     return(FindLayer(layerId));
 }
コード例 #30
0
 public Layer this[LayerIds layerId] {
     get { return(this[Layer.ConvertToLayerId(layerId)]); }
 }
コード例 #31
0
ファイル: Diagram.cs プロジェクト: LudovicT/NShape
 /// <summary>
 /// Disociates the given <see cref="T:Dataweb.NShape.Advanced.Shape" /> to all specified layers.
 /// </summary>
 public void RemoveShapeFromLayers(Shape shape, LayerIds layerIds)
 {
     if (shape == null) throw new ArgumentNullException("shape");
     if (layerIds == LayerIds.None) return;
     if (layerIds == LayerIds.All)
         shape.Layers = LayerIds.None;
     else shape.Layers ^= (shape.Layers & layerIds);
     shape.Invalidate();
 }
コード例 #32
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <ToBeCompleted></ToBeCompleted>
		public void Paste(Diagram destination, LayerIds activeLayers, int offsetX, int offsetY)
		{
			if (destination == null) throw new ArgumentNullException("destination");
			if (!editBuffer.IsEmpty) {
				++editBuffer.pasteCount;

				// Check if there are connections to restore
				if (editBuffer.connections.Count > 0) {
					// Restore connections of cut shapes at first paste action.
					for (int i = editBuffer.connections.Count - 1; i >= 0; --i) {
						editBuffer.connections[i].ConnectorShape.Connect(
							editBuffer.connections[i].GluePointId,
							editBuffer.connections[i].TargetShape,
							editBuffer.connections[i].TargetPointId);
					}
					// After the paste action, the (then connected) shapes are cloned 
					// with their connections, so we can empty the buffer here.
					editBuffer.connections.Clear();
				}

				// Create command
				ICommand cmd = new CreateShapesCommand(
					destination,
					activeLayers,
					editBuffer.shapes,
					editBuffer.withModelObjects,
					(editBuffer.action == EditAction.Cut),
					offsetX,
					offsetY);
				// Execute InsertCommand and select inserted shapes
				Project.ExecuteCommand(cmd);

				// Clone shapes for another paste operation
				// We have to copy the shapes immediately because shapes (and/or model objects) may 
				// be deleted after they are copied to 'clipboard'.
				editBuffer.shapes = editBuffer.shapes.Clone(editBuffer.withModelObjects);
				if (editBuffer.action == EditAction.Cut) editBuffer.action = EditAction.Copy;
			}
		}
コード例 #33
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <ToBeCompleted></ToBeCompleted>
		public void Paste(Diagram destination, LayerIds activeLayers)
		{
			Paste(destination, activeLayers, 20, 20);
		}
コード例 #34
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <ToBeCompleted></ToBeCompleted>
		public void InsertShape(Diagram diagram, Shape shape, LayerIds activeLayers, bool withModelObjects)
		{
			if (diagram == null) throw new ArgumentNullException("diagram");
			if (shape == null) throw new ArgumentNullException("shape");
			InsertShapes(diagram, SingleInstanceEnumerator<Shape>.Create(shape), activeLayers, withModelObjects);
		}
コード例 #35
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <ToBeCompleted></ToBeCompleted>
		public void InsertShapes(Diagram diagram, IEnumerable<Shape> shapes, LayerIds activeLayers, bool withModelObjects)
		{
			if (diagram == null) throw new ArgumentNullException("diagram");
			if (shapes == null) throw new ArgumentNullException("shapes");
			ICommand cmd = new CreateShapesCommand(diagram, activeLayers, shapes, withModelObjects, true);
			Project.ExecuteCommand(cmd);
		}
コード例 #36
0
		/// <ToBeCompleted></ToBeCompleted>
		public void Paste(Diagram destination, LayerIds activeLayers, int offsetX, int offsetY) {
			if (destination == null) throw new ArgumentNullException("destination");
			if (!editBuffer.IsEmpty) {
				++editBuffer.pasteCount;

				// create command
				ICommand cmd = new InsertShapeCommand(
					destination,
					activeLayers,
					editBuffer.shapes,
					editBuffer.withModelObjects,
					(editBuffer.action == EditAction.Cut),
					offsetX,
					offsetY);
				// Execute InsertCommand and select inserted shapes
				Project.ExecuteCommand(cmd);

				// Clone shapes for another paste operation
				// We have to copy the shapes immediately because shapes (and/or model objects) may 
				// be deleted after they are copied to 'clipboard'.
				editBuffer.shapes = editBuffer.shapes.Clone(editBuffer.withModelObjects);
				if (editBuffer.action == EditAction.Cut) editBuffer.action = EditAction.Copy;
			}
		}
コード例 #37
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <ToBeCompleted></ToBeCompleted>
		public void Paste(Diagram destination, LayerIds activeLayers, Point position)
		{
			if (!editBuffer.IsEmpty) {
				int dx = 40, dy = 40;
				if (Geometry.IsValid(position)) {
					Rectangle rect = editBuffer.shapes.GetBoundingRectangle(true);
					dx = position.X - (rect.X + (rect.Width/2));
					dy = position.Y - (rect.Y + (rect.Height/2));
				}
				Paste(destination, activeLayers, dx, dy);
				editBuffer.initialMousePos = position;
			}
		}
コード例 #38
0
        public static void CreateDiagram(Project project, string diagramName, int shapesPerRow, int shapesPerColumn, bool connectShapes, bool withModels, bool withTerminalMappings, bool withModelMappings, bool withLayers)
        {
            const int shapeSize  = 80;
            int       lineLength = shapeSize / 2;
            //
            // Create ModelMappings
            NumericModelMapping numericModelMapping = null;
            FormatModelMapping  formatModelMapping  = null;
            StyleModelMapping   styleModelMapping   = null;

            if (withModelMappings)
            {
                // Create numeric- and format model mappings
                numericModelMapping = new NumericModelMapping(2, 4, NumericModelMapping.MappingType.FloatInteger, 10, 0);
                formatModelMapping  = new FormatModelMapping(4, 2, FormatModelMapping.MappingType.StringString, "{0}");
                // Create style model mapping
                float range = (shapesPerRow * shapesPerColumn) / 15f;
                styleModelMapping = new StyleModelMapping(1, 4, StyleModelMapping.MappingType.FloatStyle);
                for (int i = 0; i < 15; ++i)
                {
                    IStyle style = null;
                    switch (i)
                    {
                    case 0: style = project.Design.LineStyles.None; break;

                    case 1: style = project.Design.LineStyles.Dotted; break;

                    case 2: style = project.Design.LineStyles.Dashed; break;

                    case 3: style = project.Design.LineStyles.Special1; break;

                    case 4: style = project.Design.LineStyles.Special2; break;

                    case 5: style = project.Design.LineStyles.Normal; break;

                    case 6: style = project.Design.LineStyles.Blue; break;

                    case 7: style = project.Design.LineStyles.Green; break;

                    case 8: style = project.Design.LineStyles.Yellow; break;

                    case 9: style = project.Design.LineStyles.Red; break;

                    case 10: style = project.Design.LineStyles.HighlightDotted; break;

                    case 11: style = project.Design.LineStyles.HighlightDashed; break;

                    case 12: style = project.Design.LineStyles.Highlight; break;

                    case 13: style = project.Design.LineStyles.HighlightThick; break;

                    case 14: style = project.Design.LineStyles.Thick; break;

                    default: style = null; break;
                    }
                    if (style != null)
                    {
                        styleModelMapping.AddValueRange(i * range, style);
                    }
                }
            }
            //
            // Create model obejct for the planar shape's template
            IModelObject planarModel = null;

            if (withModels)
            {
                planarModel = project.ModelObjectTypes["Core.GenericModelObject"].CreateInstance();
            }
            //
            // Create a shape for the planar shape's template
            Circle circleShape = (Circle)project.ShapeTypes["Circle"].CreateInstance();

            circleShape.Diameter = shapeSize;
            //
            // Create a template for the planar shapes
            Template planarTemplate = new Template("PlanarShape Template", circleShape);

            if (withModels)
            {
                planarTemplate.Shape.ModelObject = planarModel;
                planarTemplate.MapTerminal(TerminalId.Generic, ControlPointId.Reference);
                if (withTerminalMappings)
                {
                    foreach (ControlPointId id in planarTemplate.Shape.GetControlPointIds(ControlPointCapabilities.Connect))
                    {
                        planarTemplate.MapTerminal(TerminalId.Generic, id);
                    }
                }
                if (withModelMappings)
                {
                    planarTemplate.MapProperties(numericModelMapping);
                    planarTemplate.MapProperties(formatModelMapping);
                    planarTemplate.MapProperties(styleModelMapping);
                }
            }
            //
            // Create a template for the linear shapes
            Template linearTemplate = null;

            if (connectShapes)
            {
                linearTemplate = new Template("LinearShape Template", project.ShapeTypes["Polyline"].CreateInstance());
            }
            //
            // Insert the created templates into the repository
            project.Repository.InsertAll(planarTemplate);
            if (connectShapes)
            {
                project.Repository.InsertAll(linearTemplate);
            }
            //
            // Prepare the connection points
            ControlPointId leftPoint   = withModels ? ControlPointId.Reference : 4;
            ControlPointId rightPoint  = withModels ? ControlPointId.Reference : 5;
            ControlPointId topPoint    = withModels ? ControlPointId.Reference : 2;
            ControlPointId bottomPoint = withModels ? ControlPointId.Reference : 7;
            //
            // Create the diagram
            Diagram diagram = new Diagram(diagramName);
            //
            // Create and add layers
            LayerIds planarLayer = LayerIds.None, linearLayer = LayerIds.None, oddRowLayer = LayerIds.None,
                     evenRowLayer = LayerIds.None, oddColLayer = LayerIds.None, evenColLayer = LayerIds.None;

            if (withLayers)
            {
                const string planarLayerName   = "PlanarShapesLayer";
                const string linearLayerName   = "LinearShapesLayer";
                const string oddRowsLayerName  = "OddRowsLayer";
                const string evenRowsLayerName = "EvenRowsLayer";
                const string oddColsLayerName  = "OddColsLayer";
                const string evenColsLayerName = "EvenColsLayer";
                // Create Layers
                Layer planarShapesLayer = new Layer(planarLayerName);
                planarShapesLayer.Title = "Planar Shapes";
                planarShapesLayer.LowerZoomThreshold = 5;
                planarShapesLayer.UpperZoomThreshold = 750;
                diagram.Layers.Add(planarShapesLayer);
                Layer linearShapesLayer = new Layer(linearLayerName);
                linearShapesLayer.Title = "Linear Shapes";
                linearShapesLayer.LowerZoomThreshold = 10;
                linearShapesLayer.UpperZoomThreshold = 500;
                diagram.Layers.Add(linearShapesLayer);
                Layer oddRowsLayer = new Layer(oddRowsLayerName);
                oddRowsLayer.Title = "Odd Rows";
                oddRowsLayer.LowerZoomThreshold = 2;
                oddRowsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(oddRowsLayer);
                Layer evenRowsLayer = new Layer(evenRowsLayerName);
                evenRowsLayer.Title = "Even Rows";
                evenRowsLayer.LowerZoomThreshold = 2;
                evenRowsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(evenRowsLayer);
                Layer oddColsLayer = new Layer(oddColsLayerName);
                oddColsLayer.Title = "Odd Columns";
                oddColsLayer.LowerZoomThreshold = 2;
                oddColsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(oddColsLayer);
                Layer evenColsLayer = new Layer(evenColsLayerName);
                evenColsLayer.Title = "Even Columns";
                evenColsLayer.LowerZoomThreshold = 2;
                evenColsLayer.UpperZoomThreshold = 1000;
                diagram.Layers.Add(evenColsLayer);
                // Assign LayerIds
                planarLayer  = diagram.Layers.FindLayer(planarLayerName).Id;
                linearLayer  = diagram.Layers.FindLayer(linearLayerName).Id;
                oddRowLayer  = diagram.Layers.FindLayer(oddRowsLayerName).Id;
                evenRowLayer = diagram.Layers.FindLayer(evenRowsLayerName).Id;
                oddColLayer  = diagram.Layers.FindLayer(oddColsLayerName).Id;
                evenColLayer = diagram.Layers.FindLayer(evenColsLayerName).Id;
            }

            for (int rowIdx = 0; rowIdx < shapesPerRow; ++rowIdx)
            {
                LayerIds rowLayer = ((rowIdx + 1) % 2 == 0) ? evenRowLayer : oddRowLayer;
                for (int colIdx = 0; colIdx < shapesPerRow; ++colIdx)
                {
                    LayerIds colLayer  = ((colIdx + 1) % 2 == 0) ? evenColLayer : oddColLayer;
                    int      shapePosX = shapeSize + colIdx * (lineLength + shapeSize);
                    int      shapePosY = shapeSize + rowIdx * (lineLength + shapeSize);

                    circleShape      = (Circle)planarTemplate.CreateShape();
                    circleShape.Text = string.Format("{0} / {1}", rowIdx + 1, colIdx + 1);
                    circleShape.MoveTo(shapePosX, shapePosY);
                    if (withModels)
                    {
                        project.Repository.Insert(circleShape.ModelObject);
                        ((GenericModelObject)circleShape.ModelObject).IntegerValue = rowIdx;
                    }

                    diagram.Shapes.Add(circleShape, project.Repository.ObtainNewTopZOrder(diagram));
                    if (withLayers)
                    {
                        diagram.AddShapeToLayers(circleShape, planarLayer | rowLayer | colLayer);
                    }
                    if (connectShapes)
                    {
                        if (rowIdx > 0)
                        {
                            Shape lineShape = linearTemplate.CreateShape();
                            lineShape.Connect(ControlPointId.FirstVertex, circleShape, topPoint);
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, circleShape));

                            Shape otherShape = diagram.Shapes.FindShape(shapePosX, shapePosY - shapeSize, ControlPointCapabilities.None, 0, null);
                            lineShape.Connect(ControlPointId.LastVertex, otherShape, bottomPoint);
                            diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram));
                            if (withLayers)
                            {
                                diagram.AddShapeToLayers(lineShape, linearLayer);
                            }
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape));
                        }
                        if (colIdx > 0)
                        {
                            Shape lineShape = linearTemplate.CreateShape();
                            lineShape.Connect(1, circleShape, leftPoint);
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.FirstVertex, circleShape));

                            Shape otherShape = diagram.Shapes.FindShape(shapePosX - shapeSize, shapePosY, ControlPointCapabilities.None, 0, null);
                            lineShape.Connect(2, otherShape, rightPoint);
                            diagram.Shapes.Add(lineShape, project.Repository.ObtainNewBottomZOrder(diagram));
                            if (withLayers)
                            {
                                diagram.AddShapeToLayers(lineShape, linearLayer);
                            }
                            Assert.AreNotEqual(ControlPointId.None, lineShape.IsConnected(ControlPointId.LastVertex, otherShape));
                        }
                    }
                }
            }
            diagram.Width  = (lineLength + shapeSize) * shapesPerRow + 2 * shapeSize;
            diagram.Height = (lineLength + shapeSize) * shapesPerColumn + 2 * shapeSize;
            project.Repository.InsertAll(diagram);
        }
コード例 #39
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <summary>
		/// Aggregates the given shapes to a group.
		/// </summary>
		public void GroupShapes(Diagram diagram, IEnumerable<Shape> shapes, LayerIds activeLayers)
		{
			if (diagram == null) throw new ArgumentNullException("diagram");
			if (shapes == null) throw new ArgumentNullException("shapes");
			int cnt = 0;
			foreach (Shape s in shapes)
				if (++cnt > 1) break;
			if (cnt > 1) {
				ShapeType groupShapeType = Project.ShapeTypes["ShapeGroup"];
				Debug.Assert(groupShapeType != null);

				Shape groupShape = groupShapeType.CreateInstance();
				ICommand cmd = new GroupShapesCommand(diagram, activeLayers, groupShape, shapes);
				Project.ExecuteCommand(cmd);
			}
		}
コード例 #40
0
ファイル: Diagram.cs プロジェクト: LudovicT/NShape
        /// <summary>
        /// Draws the diagram shapes.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="layers"></param>
        /// <param name="clipRectangle"></param>
        public void DrawShapes(Graphics graphics, LayerIds layers, Rectangle clipRectangle)
        {
            if (graphics == null) throw new ArgumentNullException("graphics");
            int x = clipRectangle.X;
            int y = clipRectangle.Y;
            int width = clipRectangle.Width;
            int height = clipRectangle.Height;

            foreach (Shape shape in diagramShapes.BottomUp) {
                // Paint shape if it intersects with the clipping area
                if (shape.Layers != LayerIds.None && (shape.Layers & layers) == 0) continue;
                if (Geometry.RectangleIntersectsWithRectangle(shape.GetBoundingRectangle(false), x, y, width, height))
                    shape.Draw(graphics);
            }
        }
コード例 #41
0
ファイル: DiagramSetController.cs プロジェクト: stewmc/vixen
		/// <summary>
		/// Removes the given shapes from the given layers.
		/// </summary>
		public void RemoveShapesFromLayers(Diagram diagram, IEnumerable<Shape> shapes, LayerIds layerIds)
		{
			if (diagram == null) throw new ArgumentNullException("diagram");
			if (shapes == null) throw new ArgumentNullException("shapes");

			ICommand cmd = new RemoveShapesFromLayersCommand(diagram, shapes);
			Project.ExecuteCommand(cmd);
		}
コード例 #42
0
		/// <ToBeCompleted></ToBeCompleted>
		public void Paste(Diagram destination, LayerIds activeLayers, Point position) {
			if (!editBuffer.IsEmpty) {
				int dx = 40, dy = 40;
				if (Geometry.IsValid(position)) {
					Rectangle rect = editBuffer.shapes.GetBoundingRectangle(true);
					dx = position.X - (rect.X + (rect.Width / 2));
					dy = position.Y - (rect.Y + (rect.Height / 2));

					// Old version:
					// Shifting the shape by the movement of the mouse is not what the user
					// typically wants: The shape is expected to move where the mouse cursor 
					// is at the moment.
					//if (Geometry.IsValid(editBuffer.initialMousePos)) {
					//    dx = position.X - editBuffer.initialMousePos.X;
					//    dy = position.Y - editBuffer.initialMousePos.Y;
					//} else {
					//    Rectangle rect = editBuffer.shapes.GetBoundingRectangle(true);
					//    dx = position.X - (rect.X + (rect.Width / 2));
					//    dy = position.Y - (rect.Y + (rect.Height / 2));
					//}
				}
				Paste(destination, activeLayers, dx, dy);
				editBuffer.initialMousePos = position;
			}
		}