public virtual void SetPosition(int idx, Vector3 pos) { int nNodeCnt = m_aNodeArray.Count; if (idx >= 0 && idx < nNodeCnt) { SubPoint sTheNode = m_aNodeArray[idx]; sTheNode.Pos = pos; if (idx > 0) { m_aNodeArray[idx - 1].Distance = (m_aNodeArray[idx - 1].Pos - pos).Length(); } if (idx < nNodeCnt - 1) { sTheNode.Distance = (sTheNode.Pos - m_aNodeArray[idx + 1].Pos).Length(); } m_fMaxDistance = 0; for (int i = 0; i < nNodeCnt; ++i) { m_fMaxDistance += m_aNodeArray[i].Distance; } if (idx <= 1 || idx >= nNodeCnt - 2) { IsTangentOnTail = m_bTangentOnTail; } } }
private List <SubPoint> SortWayPoints(List <SubPoint> points, double x, double y) { var lastGeo = new GeoCoordinate(x, y); var lastPoint = new SubPoint(); var isOver = false; var minDist = double.MaxValue; var list = new List <SubPoint>(); while (!isOver) { isOver = true; foreach (var point in points) { var distanceTo = lastGeo.GetDistanceTo(new GeoCoordinate(point.X, point.Y)); if (distanceTo < minDist) { isOver = false; minDist = distanceTo; lastPoint = point; } } if (!isOver) { list.Add(lastPoint); points.Remove(lastPoint); minDist = double.MaxValue; } } return(list); }
public List <SubPoint> GetEntitiesInStaType(string id) { SqlParameter[] parms = { new SqlParameter("@StaTypeId", SqlDbType.VarChar, 100) }; parms[0].Value = SqlTypeConverter.DBNullStringChecker(id); var entities = new List <SubPoint>(); using (var rdr = SqlHelper.ExecuteReader(this._databaseConnectionString, CommandType.Text, SqlCommands_Rs.Sql_SubPoint_Repository_GetEntitiesInStaType, parms)) { while (rdr.Read()) { var entity = new SubPoint(); entity.PointId = SqlTypeConverter.DBNullStringHandler(rdr["PointId"]); entity.StationTypeId = SqlTypeConverter.DBNullStringHandler(rdr["StaTypeId"]); entity.AlarmLevel = SqlTypeConverter.DBNullEnmLevelHandler(rdr["AlarmLevel"]); entity.AlarmLimit = SqlTypeConverter.DBNullDoubleHandler(rdr["AlarmLimit"]); entity.AlarmDelay = SqlTypeConverter.DBNullInt32Handler(rdr["AlarmDelay"]); entity.AlarmRecoveryDelay = SqlTypeConverter.DBNullInt32Handler(rdr["AlarmRecoveryDelay"]); entity.SavedPeriod = SqlTypeConverter.DBNullInt32Handler(rdr["SavedPeriod"]); entity.AbsoluteThreshold = SqlTypeConverter.DBNullDoubleHandler(rdr["AbsoluteThreshold"]); entity.PerThreshold = SqlTypeConverter.DBNullDoubleHandler(rdr["PerThreshold"]); entity.StaticPeriod = SqlTypeConverter.DBNullInt32Handler(rdr["StaticPeriod"]); entity.StorageRefTime = SqlTypeConverter.DBNullStringHandler(rdr["StorageRefTime"]); entities.Add(entity); } } return(entities); }
public static SubPoint CreateSubPoint(Drawing drawing, Point coordinates) { SubPoint result = new SubPoint() { Drawing = drawing }; result.MoveTo(coordinates); return(result); }
public List <SubPoint> GetEntities() { var entities = new List <SubPoint>(); using (var rdr = SqlHelper.ExecuteReader(this._databaseConnectionString, CommandType.Text, SqlCommands_Rs.Sql_SubPoint_Repository_GetEntities, null)) { while (rdr.Read()) { var entity = new SubPoint(); entity.PointId = SqlTypeConverter.DBNullStringHandler(rdr["PointId"]); entity.StationTypeId = SqlTypeConverter.DBNullStringHandler(rdr["StaTypeId"]); entity.AlarmLevel = SqlTypeConverter.DBNullEnmLevelHandler(rdr["AlarmLevel"]); entity.AlarmLimit = SqlTypeConverter.DBNullDoubleHandler(rdr["AlarmLimit"]); entity.AlarmDelay = SqlTypeConverter.DBNullInt32Handler(rdr["AlarmDelay"]); entity.AlarmRecoveryDelay = SqlTypeConverter.DBNullInt32Handler(rdr["AlarmRecoveryDelay"]); entity.SavedPeriod = SqlTypeConverter.DBNullInt32Handler(rdr["SavedPeriod"]); entity.AbsoluteThreshold = SqlTypeConverter.DBNullDoubleHandler(rdr["AbsoluteThreshold"]); entity.PerThreshold = SqlTypeConverter.DBNullDoubleHandler(rdr["PerThreshold"]); entity.StaticPeriod = SqlTypeConverter.DBNullInt32Handler(rdr["StaticPeriod"]); entity.StorageRefTime = SqlTypeConverter.DBNullStringHandler(rdr["StorageRefTime"]); entities.Add(entity); } } return(entities); }
public void SetPoint(Point pt) { if (m_Prop != null) { if (SubPoint != null) { var offset = pt - GetPoint(); SubPoint.SetPoint(SubPoint.GetPoint() + offset); } if (m_Prop.PropertyType == typeof(double)) { if (m_RelativeToProp != null) { var ptR = (Point)m_Object.GetValue(m_RelativeToProp); pt -= (Vector)ptR; } if (m_Dings == 0) { m_Object.SetValue(m_Prop, pt.X); } else { m_Object.SetValue(m_Prop, pt.Y); } } else if (m_Prop.PropertyType == typeof(Point)) { m_Object.SetValue(m_Prop, pt); } else if (m_Prop.PropertyType == typeof(Rect)) { Rect rect = (Rect)m_Object.GetValue(m_Prop); switch (m_Dings) { case -1: rect.Location = pt; break; case 0: if (pt.X > rect.Right) { pt.X = rect.Right; } if (pt.Y > rect.Bottom) { pt.Y = rect.Bottom; } rect.Width = rect.Right - pt.X; rect.Height = rect.Bottom - pt.Y; rect.Location = pt; break; case 1: if (pt.X < rect.Left) { pt.X = rect.Left; } if (pt.Y > rect.Bottom) { pt.Y = rect.Bottom; } rect.Width = pt.X - rect.Left; rect.Height = rect.Bottom - pt.Y; rect.Location = new Point(rect.Location.X, pt.Y); break; case 2: if (pt.X > rect.Right) { pt.X = rect.Right; } if (pt.Y < rect.Top) { pt.Y = rect.Top; } rect.Width = rect.Right - pt.X; rect.Location = new Point(pt.X, rect.Location.Y); rect.Height = pt.Y - rect.Top; break; case 3: if (pt.X < rect.Left) { pt.X = rect.Left; } if (pt.Y < rect.Top) { pt.Y = rect.Top; } rect.Width = pt.X - rect.Left; rect.Height = pt.Y - rect.Top; break; } m_Object.SetValue(m_Prop, rect); } } }
public virtual void BuildVelocity(int idx) { int nNodeCnt = m_aNodeArray.Count; if (idx < 0 || idx >= nNodeCnt) { return; } SubPoint sNode = m_aNodeArray[idx]; if (idx == 0) { // 调整第一个节点 sNode.Velocity1 = Vector3.Zero; if (nNodeCnt > 1) { sNode.Velocity2 = CalcVel(m_aNodeArray[1].Pos, sNode.Pos, sNode.Distance); } // 调整最后一个节点 if (nNodeCnt == 2) { m_aNodeArray[1].Velocity1 = CalcVel(sNode.Pos, m_aNodeArray[1].Pos, sNode.Distance); m_aNodeArray[1].Velocity2 = Vector3.Zero; } } else if (idx == nNodeCnt - 1) { // 调整第一个节点 if (idx == 1) { m_aNodeArray[0].Velocity1 = Vector3.Zero; m_aNodeArray[0].Velocity2 = CalcVel(sNode.Pos, m_aNodeArray[0].Pos, m_aNodeArray[0].Distance); } // 调整最后一个节点 if (idx > 0) { sNode.Velocity1 = CalcVel(m_aNodeArray[idx - 1].Pos, sNode.Pos, m_aNodeArray[idx - 1].Distance); sNode.Velocity2 = Vector3.Zero; } } else { Vector3 v1 = m_aNodeArray[idx - 1].Pos - sNode.Pos; Vector3 v2 = m_aNodeArray[idx + 1].Pos - sNode.Pos; var n1 = v1; n1.Normalize(); var n2 = v2; n2.Normalize(); Vector3 vTg = n2 - n1; vTg.Normalize(); sNode.Velocity2 = vTg * sNode.Distance; sNode.Velocity1 = -1 * vTg * sNode.Distance; // 调整第一个节点 if (idx == 1) { m_aNodeArray[0].Velocity1 = Vector3.Zero; m_aNodeArray[0].Velocity2 = CalcVel(sNode.Pos, m_aNodeArray[0].Pos, m_aNodeArray[0].Distance); } // 调整最后一个节点 if (idx == nNodeCnt - 2) { m_aNodeArray[nNodeCnt - 1].Velocity1 = CalcVel(sNode.Pos, m_aNodeArray[nNodeCnt - 1].Pos, sNode.Distance); m_aNodeArray[nNodeCnt - 1].Velocity2 = Vector3.Zero; } } }
public SubPoint AddPoint(string name, string description, double x, double y, DateTime dateCreate, bool isSpecial, string pointType, string[] performances) { var point = DataContext.Points .FirstOrDefault( p => p.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); if (point != null) { return(null); //Точка {name} уже существует! } var type = DataContext.PointTypes .FirstOrDefault( p => p.Name.Equals(pointType, StringComparison.CurrentCultureIgnoreCase)); if (type == null) { return(null); //Не найден тип {pointType} ! } var listPerf = DataContext.Performances.Where(p => performances.Contains(p.Name)).ToList(); if (listPerf.Count != performances.Length) { return(null); //Не найдены характеристики для точки } point = new Point { Name = name, PointType = type, DateCreate = dateCreate, IsSpecial = isSpecial, X = x, Y = y, Description = description }; DataContext.Points.Add(point); DataContext.SaveChanges(); foreach (var performance in listPerf) { var perfPoint = new PerformancePoint { Performance = performance, Point = point }; DataContext.PerformancePoints.Add(perfPoint); } DataContext.SaveChanges(); var subPoint = new SubPoint { Name = point.Name, Description = point.Description, Id = point.Id, Y = point.Y, X = point.X, PointType = type, PerformancePoint = DataContext.PerformancePoints.Include(p => p.Point).First(p => p.Point.Id == point.Id) }; return(subPoint); }