Пример #1
0
        /// <summary>
        /// <para>Calculates the local coordinate system based on the position on the editor canvas.</para>
        /// <para>Calculates a simple path for edges which contains the ids of the start and end nodes in the first path entry.</para>
        /// </summary>
        private static void DeriveGeomPositionOutOfPlacementIn(Component.FlNetElement _nwe, System.Windows.Point _offset, double _scale, out Matrix3D ucs, out List <Point3D> path)
        {
            ucs  = Matrix3D.Identity;
            path = new List <Point3D>();
            if (_nwe == null)
            {
                return;
            }

            Point3D pivot = new Point3D(0, 0, 0);

            System.Windows.Point offset = new System.Windows.Point(_offset.X * _scale, _offset.Y * _scale);
            List <Vector3D>      axes   = new List <Vector3D>(); // x, y, z

            if (_nwe is Component.FlNetNode)
            {
                Component.FlNetNode node = _nwe as Component.FlNetNode;
                if (!(node.IsValid))
                {
                    return;
                }

                pivot.X = node.Position.X * _scale + offset.X;
                pivot.Z = node.Position.Y * _scale + offset.Y;

                axes.Add(new Vector3D(1, 0, 0));
                axes.Add(new Vector3D(0, 0, 1));
                axes.Add(new Vector3D(0, 1, 0));
            }
            else if (_nwe is Component.FlNetEdge)
            {
                Component.FlNetEdge edge = _nwe as Component.FlNetEdge;
                if (!(edge.IsValid))
                {
                    return;
                }

                pivot.X = edge.Start.Position.X * _scale + offset.X;
                pivot.Z = edge.Start.Position.Y * _scale + offset.Y;

                // the first entry in the path saves the ids of the start and end nodes to
                // communicate connectivity to the GeometryViewer
                long start_id = edge.Start.ID;
                long end_id   = edge.End.ID;
                if (edge.Start is Component.FlowNetwork)
                {
                    Component.FlowNetwork nw_start = edge.Start as Component.FlowNetwork;
                    Component.FlNetNode   nN       = nw_start.SortAndGetLastNode();
                    if (nN != null)
                    {
                        start_id = nN.ID;
                    }
                }
                if (edge.End is Component.FlowNetwork)
                {
                    Component.FlowNetwork nw_end = edge.End as Component.FlowNetwork;
                    Component.FlNetNode   n1     = nw_end.SortAndGetFirstNode();
                    if (n1 != null)
                    {
                        end_id = n1.ID;
                    }
                }

                path.Add(new Point3D(start_id, end_id, -1));
                path.Add(new Point3D(edge.Start.Position.X * _scale + offset.X, 0, edge.Start.Position.Y * _scale + offset.Y));
                path.Add(new Point3D(edge.End.Position.X * _scale + offset.X, 0, edge.End.Position.Y * _scale + offset.Y));

                Vector3D axis_x = path[1] - path[0];
                axis_x.Normalize();
                axes.Add(axis_x);
                axes.Add(new Vector3D(0, 0, 1));
                Vector3D axis_z = Vector3D.CrossProduct(axes[0], axes[1]);
                axis_z.Normalize();
                axes.Add(axis_z);
            }

            ucs = GeometricTransforms.PackUCS(pivot, axes[0], axes[1], axes[2]);
        }