当前位置: 首页>>代码示例>>C#>>正文


C# Shape.GetConnectionInfos方法代码示例

本文整理汇总了C#中Shape.GetConnectionInfos方法的典型用法代码示例。如果您正苦于以下问题:C# Shape.GetConnectionInfos方法的具体用法?C# Shape.GetConnectionInfos怎么用?C# Shape.GetConnectionInfos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shape的用法示例。


在下文中一共展示了Shape.GetConnectionInfos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CalcDisplacement

        private void CalcDisplacement(Shape shape, ref Size displacement)
        {
            int totalForceX = 0;
            int totalForceY = 0;

            // Summarize all attracting forces
            foreach (ShapeConnectionInfo sci1 in shape.GetConnectionInfos(ControlPointId.Any, null)) {
                foreach (ShapeConnectionInfo sci2 in sci1.OtherShape.GetConnectionInfos(ControlPointId.Any, null)) {
                    if (sci2.OtherShape == shape) continue;
                    // Wenn man hier nicht prüft ob das OtherShape ebenfalls verknüpft ist, dann zieht bspw. ein
                    // mit einer verknüpften Linie verknüpftes Shape unendlich lang einseitig an der Linie und
                    // es kommt letztendlich zu einem "Integer Overflow".
                    if (ExcludeFromFitting(sci2.OtherShape)) continue;

                    // Shape shape ist über s mit sci2.Shape verknüpft
                    int distance = (int)Geometry.DistancePointPoint(sci2.OtherShape.X, sci2.OtherShape.Y, shape.X, shape.Y);
                    int force = distance * springRate - friction;
                    if (force > 0) {
                        totalForceX += (sci2.OtherShape.X - shape.X) * force / distance;
                        totalForceY += (sci2.OtherShape.Y - shape.Y) * force / distance;
                    }
                }
            }
            // Summarize all repulsive forces
            foreach (Shape s in AllShapes) {
                if (ExcludeFromFitting(s)) continue;
                if (s != shape) {
                    int distance = (int)Geometry.DistancePointPoint(s.X, s.Y, shape.X, shape.Y);
                    if (distance <= repulsionRange) {
                        int force = (repulsionRange - distance) * repulsion - friction;
                        // The force cannot become negative due to the friction
                        if (force < 0) force = 0;
                        if (distance <= 0) {
                            // The shapes are located at the same coordinate. Therefore, no direction can be calculated.
                            // We take a random normal vector, which should ensure that the other shape is moved elsewhere.
                            int directionX = random.Next(100);
                            int directionY = (int)Math.Sqrt(10000 - directionX * directionX);
                            totalForceX += force * directionX / 100;
                            totalForceY += force * directionY / 100;
                        } else {
                            totalForceX += (shape.X - s.X) * force / distance;
                            totalForceY += (shape.Y - s.Y) * force / distance;
                        }
                    }
                }
            }
            // Calculate movement
            displacement.Width = (totalForceX * TimeInterval * TimeInterval / (2 * Mass));
            displacement.Height = (totalForceY * TimeInterval * TimeInterval / (2 * Mass));
        }
开发者ID:LudovicT,项目名称:NShape,代码行数:50,代码来源:Layouter.cs

示例2: ConnectPreviewOfShape

		/// <summary>
		/// Create previews of shapes connected to the given shape (and it's children) and connect them to the
		/// shape's preview (or the preview of it's child)
		/// </summary>
		private void ConnectPreviewOfShape(IDiagramPresenter diagramPresenter, Shape shape)
		{
			// process shape's children
			if (shape.Children != null && shape.Children.Count > 0) {
				foreach (Shape childShape in shape.Children)
					ConnectPreviewOfShape(diagramPresenter, childShape);
			}

			Shape preview = FindPreviewOfShape(shape);
			foreach (ShapeConnectionInfo connectionInfo in shape.GetConnectionInfos(ControlPointId.Any, null)) {
				if (!diagramPresenter.IsLayerVisible(connectionInfo.OtherShape.Layers)) continue;
				if (diagramPresenter.SelectedShapes.Contains(connectionInfo.OtherShape)) {
					// Do not connect previews if BOTH of the connected shapes are part of the selection because 
					// this would restrict movement of the connector shapes and decreases performance (many 
					// unnecessary FollowConnectionPointWithGluePoint() calls)
					if (shape.HasControlPointCapability(connectionInfo.OwnPointId, ControlPointCapabilities.Glue)) {
						if (IsConnectedToNonSelectedShape(diagramPresenter, shape)) {
							Shape targetPreview = FindPreviewOfShape(connectionInfo.OtherShape);
							preview.Connect(connectionInfo.OwnPointId, targetPreview, connectionInfo.OtherPointId);
						}
					}
				}
				else {
					// Connect preview of shape to a non-selected shape if it is a single shape 
					// that has a glue point (e.g. a Label)
					if (preview.HasControlPointCapability(connectionInfo.OwnPointId, ControlPointCapabilities.Glue)) {
						// Only connect if the control point to be connected is not the control point to be moved
						if (shape == selectedShapeAtCursorInfo.Shape &&
						    connectionInfo.OwnPointId != selectedShapeAtCursorInfo.ControlPointId)
							preview.Connect(connectionInfo.OwnPointId, connectionInfo.OtherShape, connectionInfo.OtherPointId);
					}
					else
						// Create a preview of the shape that is connected to the preview (recursive call)
						CreateConnectedTargetPreviewShape(diagramPresenter, preview, connectionInfo);
				}
			}
		}
开发者ID:stewmc,项目名称:vixen,代码行数:41,代码来源:ConfigFiltersAndPatching-Tools.cs

示例3: CanConnectTo

		/// <summary>
		/// Indicates wether the given shape can connect to the given targetShape with the specified glue point.
		/// </summary>
		protected bool CanConnectTo(Shape shape, ControlPointId gluePointId, Shape targetShape) {
			if (shape == null) throw new ArgumentNullException("shape");
			if (targetShape == null) throw new ArgumentNullException("targetShape");
			// Connecting to a shape via Pointpto-shape connection is not allowed for both ends
			ControlPointId connectedPoint = ControlPointId.None;
			foreach (ShapeConnectionInfo sci in shape.GetConnectionInfos(ControlPointId.Any, targetShape)) {
				if ((sci.OtherPointId == ControlPointId.Reference && sci.OwnPointId != gluePointId)
					|| (sci.OwnPointId == ControlPointId.Reference && targetShape.HasControlPointCapability(sci.OtherPointId, ControlPointCapabilities.Glue)))
					return false;
			}
			return true;
		}
开发者ID:jestonitiro,项目名称:nshape,代码行数:15,代码来源:Tool.cs


注:本文中的Shape.GetConnectionInfos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。