public override double CountSignalStrength(Position pStart, Position pEnd, Parameters pParameters)
        {
            var range = Tools.GetRealDistanceBetweenNodes(pStart, pEnd);
            Log.Write(LogLevel.Info, string.Format("Obliczanie mocy sygnału nadawanego w odległości {0} m od nadajnika. Parametry: Częstotliwość {1} MHz, n = 0, N = {2}",
                      range, pParameters.CentralFrequency / Tools.GetFrequencyMetricsWithValues()["[MHz]"], PowerLossCoefficient));

            var signalStrength = CountSignalStrength(range, pParameters);
            Log.Write(LogLevel.Info, string.Format("Moc sygnału nadawanego w odległości {0} m od nadajnika wyniosła {1} dBm.", range, signalStrength));

            return signalStrength;
        }
        private string GenerateLinkInfo(Position pos1, Position pos2, NodeLink.Mode mode)
        {
            var info = new StringBuilder();
            var distance = Tools.GetRealDistanceBetweenNodes(pos1, pos2);

            info.Append("Odległość: ").Append(distance.ToString("#0.####")).AppendLine(" m");
            info.Append("Możliwość komunikacji: ").Append(GetConnectionMode(mode));

            return info.ToString();
        }
        private Position CopyPosition(Position position)
        {
            if (mBlueprint.IsGeometryMode)
            {
                var width = mBlueprint.CellWidth;
                var height = mBlueprint.CellHeight;

                return new Position
                {
                    X = position.X * width,
                    Y = position.Y * height
                };
            }

            return new Position
            {
                X = position.X,
                Y = position.Y
            };
        }
 /// <summary>
 /// Fills cells with signal strength using given propagation model.
 /// </summary>
 public void FillAreaWithSignalStrength(PropagationModel pPropagationModel, Parameters pParameters, Position pPosition, Guid pNodeGuid)
 {
     UpdateEstimationParameters();
     EstimateRange(pPropagationModel, pParameters, pPosition, pNodeGuid);
     CountMaxRange(pPosition);
 }
        private bool GoWest(int pIndex, Position pNodePosition, PropagationModel pPropagationModel, Parameters pParameters, Guid pNodeGuid)
        {
            bool signalAboveThreshold = false;
            var endPoint = pNodePosition.X - pIndex;

            var position = new Position { X = pNodePosition.X + pIndex, Y = pNodePosition.Y + pIndex };
            Debug.WriteLine("Going to SW corner. Starting point [{0}, {1}]", position.X, position.Y);

            if (position.X > mBlueprint.Columns) position.X = mBlueprint.Columns;
            if (position.Y > mBlueprint.Rows) return false;

            while (position.X != endPoint)
            {
                Debug.WriteLine("Counting signal strength for cell [{0}, {1}]", position.X, position.Y);
                var signal = pPropagationModel.CountSignalStrength(pNodePosition, position, pParameters);

                if (signal > mTreshold)
                {
                    signalAboveThreshold = true;
                    var cell = mBlueprint[(int)position.X, (int)position.Y];
                    cell.SetSignalSource(pNodeGuid.ToString(), signal);
                }
                position.X--;
            }

            return signalAboveThreshold;
        }
        private bool GoEast(int pIndex, Position pNodePosition, PropagationModel pPropagationModel, Parameters pParameters, Guid pNodeGuid)
        {
            bool signalAboveThreshold = false;
            var endPoint = pNodePosition.X + pIndex;

            var position = new Position {X = pNodePosition.X - pIndex, Y = pNodePosition.Y - pIndex};
            Debug.WriteLine("Going to NE corner. Starting point [{0}, {1}]", position.X, position.Y);

            if (position.X < 0) position.X = 0;
            if (position.Y < 0) return false; // index outside cell area, dont count anything

            while (position.X != endPoint)
            {
                Debug.WriteLine("Counting signal strength for cell [{0}, {1}]", position.X, position.Y);
                var signal = pPropagationModel.CountSignalStrength(pNodePosition, position, pParameters);

                if (signal > mTreshold)
                {
                    signalAboveThreshold = true;
                    var cell = mBlueprint[(int)position.X, (int)position.Y];
                    cell.SetSignalSource(pNodeGuid.ToString(), signal);
                }
                position.X++;
            }

            return signalAboveThreshold;
        }
        private void AssignObstacle(Position startOffset)
        {
            var cell = mBlueprint[(int)startOffset.Y, (int)startOffset.X];

            if (cell.Obstacle.Type == "Brak") return;

            if (!PathObstacles.ContainsKey(cell.Obstacle.Type))
            {
                PathObstacles.Add(cell.Obstacle.Type, new ObstacleCount { Count = 1, Obstacle = cell.Obstacle });
            }
            else
            {
                PathObstacles[cell.Obstacle.Type].Count++;
            }
        }
        public override double CountSignalStrength(Position pStart, Position pEnd, Parameters pParameters)
        {
            PathObstacles.Clear();
            var startPos = new Position { X = pStart.X, Y = pStart.Y };
            var endPos = new Position { X = pEnd.X, Y = pEnd.Y };

            if (pStart.X - pEnd.X == 0)
                AsymptoteObstacles(startPos, endPos);
            else if (pStart.Y - pEnd.Y == 0)
                LevelObstacles(startPos, endPos);
            else
                FunctionObstacles(startPos, endPos);

            var signalStrength = CountSignalStrength(Tools.GetRealDistanceBetweenNodes(pStart, pEnd), pParameters);
            var obstaclesAttenuation = CountObstaclesAttenuation(pParameters);

            return signalStrength - obstaclesAttenuation;
        }
        private void LevelObstacles(Position start, Position end)
        {
            if (start.X > end.X)
                SwitchPositions(ref start, ref end);

            while (start.X != end.X)
            {
                AssignObstacle(start);
                start.X += 1;
            }
        }
 private void SwitchPositions(ref Position position1, ref Position position2)
 {
     var position = new Position { X = position1.X, Y = position1.Y };
     position1 = position2;
     position2 = position;
 }
        private void FunctionObstacles(Position start, Position end)
        {
            var startOffset = AddPositionOffset(start);
            var endOffset = AddPositionOffset(end);
            //var startPos = new Position { X = start.X, Y = start.Y };
            //var endPos = new Position { X = end.X, Y = end.Y };

            if (startOffset.X > endOffset.X)
                SwitchPositions(ref startOffset, ref endOffset);

            AssignXYParams(startOffset, endOffset);

            var cells = new List<Position>();
            for (var i = startOffset.X; i <= endOffset.X; i += 0.5)
            {
                var yValue = YValue(i);

                if (!cells.Any(p => p.X == (int)i && p.Y == (int)yValue))
                    cells.Add(new Position { X = (int)i, Y = (int)yValue });
            }

            if (startOffset.Y > endOffset.Y)
            {
                for (var i = startOffset.Y; i <= endOffset.Y; i -= 0.5)
                {
                    var xValue = XValue(i);

                    if (!cells.Any(p => p.X == (int)xValue && p.Y == (int)i))
                        cells.Add(new Position { X = (int)xValue, Y = (int)i });
                }
            }
            else
            {
                for (var i = startOffset.Y; i <= endOffset.Y; i += 0.5)
                {
                    var xValue = XValue(i);

                    if (!cells.Any(p => p.X == (int)xValue && p.Y == (int)i))
                        cells.Add(new Position { X = (int)xValue, Y = (int)i });
                }
            }

            foreach (var position in cells)
            {
                AssignObstacle(position);
            }

            //while (startPos.X != endPos.X && startPos.Y != endPos.Y)
            //{
            //    AssignObstacle(startPos);

            //    var yResult = YValue(startPos.X + 1);

            //    if ((int) yResult != startPos.Y)
            //    {
            //        if ((int) yResult > startPos.Y)
            //            startPos.Y += 1;
            //        else
            //            startPos.Y -= 1;
            //    }
            //    else
            //    {
            //        startPos.X += 1;
            //    }
            //}
        }
        private void AsymptoteObstacles(Position start, Position end)
        {
            if (start.Y > end.Y)
                SwitchPositions(ref start, ref end);

            while (start.Y != end.Y)
            {
                AssignObstacle(start);
                start.Y++;
            }
        }
        private void AssignXYParams(Position start, Position end)
        {
            X1 = start.X;
            Y1 = start.Y;
            X2 = end.X;
            Y2 = end.Y;

            A = ((Y1 - Y2) / (X1 - X2));
            B = (Y1 - ((Y1 - Y2) / (X1 - X2)) * X1);
        }
        /// <summary>
        /// Gets real distance in meters between two nodes.
        /// </summary>
        public static double GetRealDistanceBetweenNodes(Position pStart, Position pEnd)
        {
            var range = GetDistanceBetweenTwoPoints(pStart, pEnd);
            var dist = range * GetMeterToPixelRatio();

            return Blueprint.Instance.IsGeometryMode ? dist * Blueprint.Instance.CellWidth : dist;
        }
        private void CountMaxRange(Position pPosition)
        {
            // Log.Write(LogLevel.Debug, "Counting Node's maximum transmission range.");

            //Log.Write(LogLevel.Debug, "Maximum transmission range is: {0}");
        }
 public abstract double CountSignalStrength(Position pStart, Position pEnd, Parameters pParameters);
        private void EstimateRange(PropagationModel pPropagationModel, Parameters pParameters, Position pPosition, Guid pNodeGuid)
        {
            // Log.Write(LogLevel.Debug, "Estimating Node signal strength in CellArea.");

            var IsAboveThreshold = new []{true, true, true, true};
            for(int i = 1; IsAboveThreshold.Any(s => s); i++)
            {
                IsAboveThreshold[(int)MoveDirection.East] = GoEast(i, pPosition, pPropagationModel, pParameters, pNodeGuid);
                IsAboveThreshold[(int)MoveDirection.South] = GoSouth(i, pPosition, pPropagationModel, pParameters, pNodeGuid);
                IsAboveThreshold[(int)MoveDirection.West] = GoWest(i, pPosition, pPropagationModel, pParameters, pNodeGuid);
                IsAboveThreshold[(int)MoveDirection.North] = GoNorth(i, pPosition, pPropagationModel, pParameters, pNodeGuid);
            }
        }
 public override double CountSignalStrength(Position pStart, Position pEnd, Parameters pParameters)
 {
     var range = Tools.GetRealDistanceBetweenNodes(pStart, pEnd);
     return CountSignalStrength(range, pParameters);
 }
        private Position AddPositionOffset(Position position)
        {
            var width = mBlueprint.CellWidth;
            var height = mBlueprint.CellHeight;

            return new Position
            {
                X = position.X + 0.5,
                Y = position.Y + 0.5
            };
        }