internal void PlaceInFlowNetworkElement(Component.FlNetElement _nwe, System.Windows.Point _offset, double _scale, List <double> _sizes, Dictionary <string, double> _params) { if (this.State.IsRealized) { return; } if (_nwe == null || _sizes == null || _params == null) { return; } if (_sizes.Count < 6) { return; } List <Point3D> gr_path; Matrix3D gr_ucs; GeometricRelationship.DeriveGeomPositionOutOfPlacementIn(_nwe, _offset, _scale, out gr_ucs, out gr_path); this.GeomCS = gr_ucs; if (this.State.Type == Relation2GeomType.CONNECTS) { this.InstancePath = gr_path; } this.InstanceNWElementID = _nwe.ID; this.InstanceNWElementName = _nwe.Name; this.InstanceSize = new List <double>(_sizes); this.instance_size_transfer_settings = new List <GeomSizeTransferDef>(); // per default NONE (i.e. direct user input into the InstanceSize list) this.InstanceParamValues = new Dictionary <string, double>(_params); }
internal static GeometricRelationship CreateAndPlaceInFlowNetworkElement(Component.FlNetElement _nwe, System.Windows.Point _offset, double _scale, Dictionary <string, double> _params) { if (_nwe == null) { return(null); } Relation2GeomState gr_state = new Relation2GeomState { IsRealized = false, Type = (_nwe is Component.FlNetEdge) ? Relation2GeomType.CONNECTS : Relation2GeomType.CONTAINED_IN }; List <Point3D> gr_path; Matrix3D gr_ucs; GeometricRelationship.DeriveGeomPositionOutOfPlacementIn(_nwe, _offset, _scale, out gr_ucs, out gr_path); GeometricRelationship gr_placement = new GeometricRelationship("placement", gr_state, new Point4D(-1, -1, -1, -1), gr_ucs, Matrix3D.Identity, Matrix3D.Identity); // todo: adjust the transforms... gr_placement.instance_size = new List <double> { 0, 0, 0, 0, 0, 0 }; gr_placement.instance_size_transfer_settings = new List <GeomSizeTransferDef>(); gr_placement.instance_nwe_id = _nwe.ID; gr_placement.instance_nwe_name = _nwe.Name; gr_placement.InstancePath = gr_path; gr_placement.InstanceParamValues = (_params == null) ? new Dictionary <string, double>() : new Dictionary <string, double>(_params); return(gr_placement); }
/// <summary> /// <para>Updates the local coordinate system if _nwe is a node.</para> /// <para>If _nwe is an edge, it also updates the path. If the geometric relationship is already realized nothing changes.</para> /// </summary> internal void UpdatePositionFrom(Component.FlNetElement _nwe, System.Windows.Point _offset, double _scale) { if (this.State.IsRealized) { return; } if (_nwe == null) { return; } List <Point3D> gr_path; Matrix3D gr_ucs; GeometricRelationship.DeriveGeomPositionOutOfPlacementIn(_nwe, _offset, _scale, out gr_ucs, out gr_path); this.GeomCS = gr_ucs; if (this.State.Type == Relation2GeomType.CONNECTS) { this.InstancePath = gr_path; } }
/// <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]); }