public void Zero()
        {
            // sprawdzenie w którą stronę szybciej wypadnie zerowanie
            StepDirection direction = StepDirection.Left;

            // sprawdzenie w którą stronę będzie szybciej wyzerować silnik
            if (_realPositon > 180d)
            {
                direction = StepDirection.Right;
            }

            if (ReverseDirection)
            {
                if (direction == StepDirection.Left)
                {
                    direction = StepDirection.Right;
                }
                else
                {
                    direction = StepDirection.Left;
                }
            }

            Zero(direction);
        }
Exemple #2
0
    TickProfile(Arc sourceArc, int stepToTickRate, int tickRate)
    {
        Contract.Assert(tickRate > 0, @"Zero tick rate for {0}.", sourceArc);

        motor     = sourceArc.motor;
        size      = sourceArc.motor.stepSize;
        direction = sourceArc.direction;

        stepRate = tickRate;
        // Sync the start with the platform conversion rate.
        startTick = sourceArc.startStep * stepToTickRate;

        // Figure out how many steps we can actually take at our rate.
        int stepsAvailable = Mathf.FloorToInt((float)(sourceArc.length * stepToTickRate) / (float)tickRate);

        tickLength = stepsAvailable * tickRate;

        // If we were supposed to take a step in the arc,
        // try to take at least one step.
        if (sourceArc.length > 0)
        {
            tickLength = Mathf.Max(1, tickLength);
        }

        Contract.Assert(tickLength % tickRate == 0 || tickLength < tickRate,
                        @"Non-integral tick rate for {0} from {1}.",
                        this, sourceArc);
        Contract.Assert((sourceArc.length == 0 && tickLength == 0) ||
                        (tickLength > 0), @"Should take at least one tick step for {0} => {1}",
                        sourceArc, this);
    }
Exemple #3
0
        public Hexagon NextHex(StepDirection direction)
        {
            Hexagon newHex = this.Clone() as Hexagon;

            switch (direction)
            {
            case StepDirection.IncreaseZ:
                newHex.IncreaseZ();
                break;

            case StepDirection.DecreaseY:
                newHex.DecreaseY();
                break;

            case StepDirection.IncreaseX:
                newHex.IncreaseX();
                break;

            case StepDirection.DecreaseZ:
                newHex.DecreaseZ();
                break;

            case StepDirection.IncreaseY:
                newHex.IncreaseY();
                break;

            case StepDirection.DecreaseX:
                newHex.DecreaseX();
                break;
            }
            newHex.Value++;

            return(newHex);
        }
Exemple #4
0
 public static Turn Step(StepDirection direction)
 {
     return(new Turn(player =>
     {
         player.Move(player.Location + Offset.FromDirection(direction), player.Level);
     }));
 }
Exemple #5
0
 public void Initialize(StepDirection direction = StepDirection.Clockwise, StepMode stepMode = StepMode.Full, bool isEnabled = true)
 {
     Direction = direction;
     IsEnabled = isEnabled;
     Mode      = stepMode;
     //StepperMotor = stepperMotor;
 }
Exemple #6
0
 private static void SetDirection(double x, double y, double z,
                                  StepDirection dir)
 {
     dir.X = x;
     dir.Y = y;
     dir.Z = z;
 }
Exemple #7
0
 public Node(ushort px, ushort py, byte step, StepDirection dir)
 {
     this.px        = px;
     this.py        = py;
     this.TileStep  = step;
     this.direction = dir;
 }
Exemple #8
0
 public StepCommand(WD1797 w, StepRate rate, bool hld, bool verify, bool updateReg, StepDirection stepDir)
 {
     _w         = w;
     _rate      = rate;
     _hld       = hld;
     _verify    = verify;
     _updateReg = updateReg;
     _stepDir   = stepDir;
 }
Exemple #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Arc"/> class.
 /// </summary>
 /// <param name='aMaterial'>
 /// A material id.
 /// </param>
 /// <param name='aStartStep'>
 /// A start step.
 /// </param>
 public Arc(int aMaterial, int aStartStep)
 {
     motor               = null;
     material            = aMaterial;
     startStep           = aStartStep;
     endStep             = kNotInitialized;
     direction           = StepDirection.Unknown;
     hasVariableStepRate = false;
 }
Exemple #10
0
 /// <summary>
 /// Çlones an instance of the <see cref="Arc"/> class.
 /// </summary>
 /// <param name='aSource'>
 /// A source.
 /// </param>
 public Arc(Arc aSource)
 {
     motor               = aSource.motor;
     startStep           = aSource.startStep;
     endStep             = aSource.endStep;
     material            = aSource.material;
     direction           = aSource.direction;
     hasVariableStepRate = false;
 }
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Arc"/> class.
 /// </summary>
 /// <param name='anId'>
 /// An extruder identifier.
 /// </param>
 /// <param name='aStartStep'>
 /// A start step.
 /// </param>
 public Arc(PrinterMotor aMotor, int aStartStep)
 {
     motor               = aMotor;
     startStep           = aStartStep;
     endStep             = kNotInitialized;
     material            = kNotInitialized;
     direction           = aMotor.stepDirection;
     hasVariableStepRate = false;
 }
Exemple #12
0
 public MotorRateMover(MotorRateMover aMover, int aGlobalStart)
 {
     motor           = aMover.motor;
     direction       = aMover.direction;
     size            = aMover.size;
     stepRate        = aMover.stepRate;
     globalStartStep = aGlobalStart;
     stepCount       = aMover.stepCount;
 }
Exemple #13
0
 public MotorRateMover(PrinterMotor aMotor, StepDirection aDirection,
                       StepSize aSize, int aRate, int aGlobalStepStart, int totalStepCount)
 {
     motor           = aMotor;
     direction       = aDirection;
     size            = aSize;
     stepRate        = aRate;
     globalStartStep = aGlobalStepStart;
     stepCount       = totalStepCount;
 }
        public static CommunicationStrings CommandFromStepDirection(StepDirection stepDirection)
        {
            switch (stepDirection)
            {
            case StepDirection.CLOCKWISE:
                return(CommunicationStrings.DCL);

            case StepDirection.ANTICLOCKWISE:
                return(CommunicationStrings.DAC);

            default: return(CommunicationStrings.ERR);
            }
        }
Exemple #15
0
        public void SetCurrentStep(string name, StepDirection dir)
        {
            if (name == null || name == "")
            {
                throw new ArgumentException("Step is null or empty", "step");
            }

            BaseStep bws = steps[name];

            if (bws == null)
            {
                throw new ArgumentException("Step does not contain the name of a step in the wizard", "name");
            }

            SetCurrentStep(bws, dir);
        }
Exemple #16
0
    public TickProfile(TickProfile source, int aStartTick)
    {
        motor     = source.motor;
        size      = source.size;
        direction = source.direction;
        stepRate  = source.stepRate;

        startTick  = aStartTick;
        tickLength = source.tickLength;

        // NOTE: Negative tick profiles are OK
        // when pressurizing, so we don't
        // check for negative start ticks.
        Contract.Assert(tickLength >= 0, @"Negative tick length.");
        Contract.Assert(motor != null, @"No motor assigned to tick profile.");
        Contract.Assert(direction != StepDirection.Unknown, @"Unknown step direction.");
    }
Exemple #17
0
    private IGraphNode GetTargetNode(HexNode actorHexNode, StepDirection direction)
    {
        if (direction == StepDirection.Undefined)
        {
            throw new ArgumentException("Не определено направление.", nameof(direction));
        }

        var neighborNodes = _sectorManager.CurrentSector.Map.GetNext(actorHexNode).OfType <HexNode>();
        var directions    = HexHelper.GetOffsetClockwise();

        var stepDirectionIndex = _stepDirectionIndexes[direction];
        var targetCubeCoords   = actorHexNode.CubeCoords + directions[stepDirectionIndex];

        var targetNode = neighborNodes.SingleOrDefault(x => x.CubeCoords == targetCubeCoords);

        return(targetNode);
    }
Exemple #18
0
        private async Task HandleGetRecipeStep(IDialogContext context, StepDirection direction)
        {
            try
            {
                int           recipeId = -1;
                StepViewModel step     = null;
                var           stepId   = 0;

                if (!context.UserData.TryGetValue(Userdata_RecipeId, out recipeId))
                {
                    throw new RecipeIdNotFoundException();
                }

                if (!context.UserData.TryGetValue(Userdata_StepId, out stepId))
                {
                    stepId = -1;
                }

                using (var client = new GatewayClient())
                {
                    step = await client.GetStepAsync(recipeId, stepId, direction);
                }

                if (step == null)
                {
                    await context.PostAsync(Resources.Message_Error_UnableToReceiveStep);
                }
                else
                {
                    context.UserData.SetValue(Userdata_StepId, step.Id);
                    await context.PostAsync($"{Resources.Message_Step} {step.Order + 1} {Resources.Message_of} {step.TotalSteps} {Resources.Message_Steps}:{Bot_NewLine}{step.Description}");

                    if (step.Order + 1 >= step.TotalSteps)
                    {
                        await context.PostAsync(Resources.Message_CookingCompleted);
                    }
                }
            }
            catch (RecipeIdNotFoundException e)
            {
                await context.PostAsync(Resources.Message_Error_RecipeMustBeSelectedFirst);
            }
        }
Exemple #19
0
        private static void SetAxis(double axisX, double axisY, double axisZ, StepAxis2Placement axis, double aDirectionX,
                                    double aDirectionY, double aDirectionZ, double refDirectionX, double refDirectionY, double refDirectionZ)
        {
            StepCartesianPoint point = new StepCartesianPoint();

            SetCartesianPoint(axisX, axisY, axisZ, point);

            StepDirection axisDirection = new StepDirection();

            SetDirection(aDirectionX, aDirectionY, aDirectionZ, axisDirection);

            StepDirection refDirection = new StepDirection();

            SetDirection(refDirectionX, refDirectionY, refDirectionZ, refDirection);

            axis.Location     = point;
            axis.Axis         = axisDirection;
            axis.RefDirection = refDirection;
        }
Exemple #20
0
    static int ApplyPressure(PrinterMotor forMotor, StepDirection inDirection,
                             int usingPressureSteps, int usingPlatformRotation, List <TickProfile> toList)
    {
        Contract.Assert(usingPressureSteps <= kPressureSteps,
                        @"Requested {0} pressure steps; maximum is {1}.",
                        usingPressureSteps, kPressureSteps);

        // NOTE: We don't know how many steps it'll take to
        // accelerate over usingPressureSteps. So we need
        // to treat everything as if it stepped from
        // [0, usingPressureSteps) and then scale the
        // resulting ticks by anArc.startingStep.
        Arc pressureArc = new Arc(forMotor, 0);

        pressureArc.startStep = 0;
        pressureArc.endStep   = usingPressureSteps;
        pressureArc.direction = inDirection;

        PrinterExtruder extruder = (PrinterExtruder)forMotor;

        if (inDirection == StepDirection.Ccw)
        {
            extruder.pressureRequired -= usingPressureSteps;

            Contract.Assert(extruder.pressureRequired >= 0,
                            @"Pressurized more than {0} steps.", kPressureSteps);
        }
        else
        {
            extruder.pressureRequired += usingPressureSteps;

            Contract.Assert(extruder.pressureRequired <= kPressureSteps,
                            @"Motor {0} required pressure of {1} exceeds max of {2}.",
                            extruder.id, extruder.pressureRequired, kPressureSteps);
        }

        int ticksTaken = Accelerate(pressureArc, usingPlatformRotation, toList);

        Contract.Assert(ticksTaken > 0, @"Non-positive ticks taken over {0} step{1}.",
                        ticksTaken, Text.S(ticksTaken));
        return(ticksTaken);
    }
Exemple #21
0
        protected void SetCurrentStep(BaseStep step, StepDirection dir)
        {
            SuspendLayout();

            try
            {
                if (currentStep != null)
                {
                    DetatchStep();
                }

                currentStep = step;

                AttachStep(dir);
            }
            finally
            {
                ResumeLayout(true);
            }
        }
Exemple #22
0
    public TickProfile(PrinterMotor aMotor, StepSize aSize, StepDirection aDirection,
                       int aStepRate, int aStartTick, int aTickLength)
    {
        Contract.Assert(aMotor != null,
                        @"Tried to assign null motor to tick profile.");
        Contract.Assert(aDirection != StepDirection.Unknown,
                        @"Tried to assign unknown direction to tick profile.");
        Contract.Assert(aStepRate >= 0,
                        @"Negative step rate of {0}.", aStepRate);
        // NOTE: Negative tick profiles are OK
        // when pressurizing, so we don't
        // check for negative start ticks.

        motor     = aMotor;
        size      = aSize;
        direction = aDirection;
        stepRate  = aStepRate;

        startTick  = aStartTick;
        tickLength = aTickLength;
    }
        public void Zero(StepDirection direction)
        {
            _realPositon = 0d;

            // ustawienie konfiguracji zerowania
            byte config = _zeroConfig;

            if (ReverseDirection)
            {
                if (direction == StepDirection.Left)
                {
                    direction = StepDirection.Right;
                }
                else
                {
                    direction = StepDirection.Left;
                }
            }

            if (direction == StepDirection.Right)
            {
                config |= (1 << 7);
            }

            lock (_queueSync)
            {
                // wyczyszczenie kolejki rozkazów
                _requests.Clear();

                // dodanie rozkazu zerującego
                _requests.Enqueue(new MotorReuqest()
                {
                    Zero   = true,
                    Config = config
                });

                // powiadomienie o nowym rozkazie
                _newRequestEvent.Set();
            }
        }
Exemple #24
0
        private void AttachStep(StepDirection direction)
        {
            // Set its Wizard property
            currentStep.Wizard = this;

            // Add event handlers
            currentStep.StepTitleChanged       += new EventHandler(OnStepTitleChanged);
            currentStep.StepDescriptionChanged += new EventHandler(OnStepDescriptionChanged);
            currentStep.NextStepChanged        += new EventHandler(OnNextStepChanged);
            currentStep.PreviousStepChanged    += new EventHandler(OnPreviousStepChanged);
            currentStep.PageLayoutChanged      += new EventHandler(OnPageLayoutChanged);
            currentStep.LogoChanged            += new EventHandler(OnLogoChanged);
            currentStep.SideBarLogoChanged     += new EventHandler(OnSideBarLogoChanged);
            currentStep.SideBarImageChanged    += new EventHandler(OnSideBarImageChanged);

            // Update the title
            OnStepTitleChanged(null, EventArgs.Empty);
            OnStepDescriptionChanged(null, EventArgs.Empty);

            // Show the step
            currentStep.Dock = DockStyle.Fill;
            panelStep.Controls.Add(currentStep);

            // Update the buttons
            OnPreviousStepChanged(null, EventArgs.Empty);
            OnNextStepChanged(null, EventArgs.Empty);

            // Update wizard layout
            OnPageLayoutChanged(null, EventArgs.Empty);

            // Update logos if neccessary
            OnLogoChanged(null, EventArgs.Empty);
            OnSideBarLogoChanged(null, EventArgs.Empty);
            OnSideBarImageChanged(null, EventArgs.Empty);

            currentStep.FireShowEvent(new ShowStepEventArgs(direction));
        }
 public ShowStepEventArgs(StepDirection direction)
 {
     Direction = direction;
 }
        /// <summary>
        /// Determines and sets the state of the 4 pixels that
        /// represent our current state, and sets our current and
        /// previous directions
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void Step(int x, int y)
        {
            // Scan our 4 pixel area
            bool upLeft    = IsPixelSolid(x - 1, y - 1);
            bool upRight   = IsPixelSolid(x, y - 1);
            bool downLeft  = IsPixelSolid(x - 1, y);
            bool downRight = IsPixelSolid(x, y);

            // Store our previous step
            previousStep = nextStep;

            // Determine which state we are in
            int state = 0;

            if (upLeft)
            {
                state |= 1;
            }
            if (upRight)
            {
                state |= 2;
            }
            if (downLeft)
            {
                state |= 4;
            }
            if (downRight)
            {
                state |= 8;
            }

            // State now contains a number between 0 and 15
            // representing our state.
            // In binary, it looks like 0000-1111 (in binary)

            // An example. Let's say the top two pixels are filled,
            // and the bottom two are empty.
            // Stepping through the if statements above with a state
            // of 0b0000 initially produces:
            // Upper Left == true ==>  0b0001
            // Upper Right == true ==> 0b0011
            // The others are false, so 0b0011 is our state
            // (That's 3 in decimal.)

            // Looking at the chart above, we see that state
            // corresponds to a move right, so in our switch statement
            // below, we add a case for 3, and assign Right as the
            // direction of the next step. We repeat this process
            // for all 16 states.

            // So we can use a switch statement to determine our
            // next direction based on
            switch (state)
            {
            case 1: nextStep = StepDirection.Up; break;

            case 2: nextStep = StepDirection.Right; break;

            case 3: nextStep = StepDirection.Right; break;

            case 4: nextStep = StepDirection.Left; break;

            case 5: nextStep = StepDirection.Up; break;

            case 6:
                if (previousStep == StepDirection.Up)
                {
                    nextStep = StepDirection.Left;
                }
                else
                {
                    nextStep = StepDirection.Right;
                }
                break;

            case 7: nextStep = StepDirection.Right; break;

            case 8: nextStep = StepDirection.Down; break;

            case 9:
                if (previousStep == StepDirection.Right)
                {
                    nextStep = StepDirection.Up;
                }
                else
                {
                    nextStep = StepDirection.Down;
                }
                break;

            case 10: nextStep = StepDirection.Down; break;

            case 11: nextStep = StepDirection.Down; break;

            case 12: nextStep = StepDirection.Left; break;

            case 13: nextStep = StepDirection.Up; break;

            case 14: nextStep = StepDirection.Left; break;

            default:
                nextStep = StepDirection.None;
                break;
            }
        }
 public Tower Find(Game game, Tower tower, StepDirection stepDirection)
 {
     return stepDirection == StepDirection.Right
         ? NextTower(game, tower)
         : PreviousTower(game, tower);
 }
Exemple #28
0
		public void SelectNodeByAttribute(StepDirection dir, AttrType attrType, SearchMessageArea area)
		{
			var activeNode = (IMsg)_tgMsgs.ActiveNode;

			if (activeNode == null)
				return;

			var topic = activeNode.Topic;

			// Ищем в текущей ветке.
			var treeNodes = dir == StepDirection.Down
				? TreeGrid.TreeGrid.GetFlatArrayOfSubNodes(topic, activeNode)
				: TreeGrid.TreeGrid.GetFlatArrayOfSubNodesReverse(topic, activeNode);

			foreach (IMsg msg in treeNodes)
				if (IsMsgConformAttribute(msg, attrType))
				{
					_tgMsgs.ActiveNode = msg;
					return;
				}

			// Если не нашли, то ищем темы (кроневые ветки) имеющие ответы.
			var isCurrPassed = false;
			var messages = new Msg[_tgMsgs.Nodes.Count];

			_tgMsgs.Nodes.CopyTo(messages, 0);

			if (dir == StepDirection.Up)
				Array.Reverse(messages);

			foreach (IMsg msg in messages)
			{
				// Пропускаем все ветки пока не найдем текущую тему.
				if (!isCurrPassed && msg != topic)
					continue;

				if (!isCurrPassed)
				{
					isCurrPassed = true;
					continue; // Текущую тему тоже нужно пропустить.
				}

				// если топик сменился, а нас просили искать только в текущем топике - выходим
				if (area == SearchMessageArea.CurrentTopic && msg.TopicID != topic.TopicID)
					break;

				// Если в тему есть 
				var isFound = false;
				switch (attrType)
				{
					case AttrType.Any:
						isFound = true;
						break;
					case AttrType.Marked:
						isFound = msg.RepliesMarked > 0 || msg.Marked;
						break;
					case AttrType.Unread:
						isFound = msg.RepliesUnread > 0 || msg.IsUnread;
						break;
					case AttrType.UnreadAnswerToMe:
						isFound = msg.RepliesToMeUnread > 0;
						break;
				}

				if (isFound)
				{
					switch (attrType)
					{
						case AttrType.Any:
							break;
						case AttrType.Marked:
							isFound = msg.IsMarked;
							break;
						case AttrType.Unread:
							isFound = msg.IsUnread;
							break;
						default:
							isFound = false;
							break;
					}

					if (isFound)
					{
						_tgMsgs.ActiveNode = msg;
						return;
					}

					treeNodes = TreeGrid.TreeGrid.GetFlatArrayOfSubNodes(msg);

					if (dir == StepDirection.Up)
						Array.Reverse(treeNodes);

					foreach (IMsg subMsg in treeNodes)
						if (IsMsgConformAttribute(subMsg, attrType))
						{
							_tgMsgs.ActiveNode = subMsg;
							return;
						}

					throw new ApplicationException(
						"Аргрегированная информация не соответсвует реальному содержанию БД. Произведите " +
							"пересчет БД и обратитесь к разработчикам.");
				}
			}

			Beeper.DoBeep();
			return;
		}
Exemple #29
0
        public void SelectNodeByAttribute(StepDirection dir, AttrType attrType, SearchMessageArea area)
        {
            var activeNode = (IMsg)_tgMsgs.ActiveNode;

            if (activeNode == null)
            {
                return;
            }

            var topic = activeNode.Topic;

            // Ищем в текущей ветке.
            var treeNodes = dir == StepDirection.Down
                                ? TreeGrid.TreeGrid.GetFlatArrayOfSubNodes(topic, activeNode)
                                : TreeGrid.TreeGrid.GetFlatArrayOfSubNodesReverse(topic, activeNode);

            foreach (IMsg msg in treeNodes)
            {
                if (IsMsgConformAttribute(msg, attrType))
                {
                    _tgMsgs.ActiveNode = msg;
                    return;
                }
            }

            // Если не нашли, то ищем темы (кроневые ветки) имеющие ответы.
            var isCurrPassed = false;
            var messages     = new Msg[_tgMsgs.Nodes.Count];

            _tgMsgs.Nodes.CopyTo(messages, 0);

            if (dir == StepDirection.Up)
            {
                Array.Reverse(messages);
            }

            foreach (IMsg msg in messages)
            {
                // Пропускаем все ветки пока не найдем текущую тему.
                if (!isCurrPassed && msg != topic)
                {
                    continue;
                }

                if (!isCurrPassed)
                {
                    isCurrPassed = true;
                    continue;                     // Текущую тему тоже нужно пропустить.
                }

                // если топик сменился, а нас просили искать только в текущем топике - выходим
                if (area == SearchMessageArea.CurrentTopic && msg.TopicID != topic.TopicID)
                {
                    break;
                }

                // Если в тему есть
                var isFound = false;
                switch (attrType)
                {
                case AttrType.Any:
                    isFound = true;
                    break;

                case AttrType.Marked:
                    isFound = msg.RepliesMarked > 0 || msg.Marked;
                    break;

                case AttrType.Unread:
                    isFound = msg.RepliesUnread > 0 || msg.IsUnread;
                    break;

                case AttrType.UnreadAnswerToMe:
                    isFound = msg.RepliesToMeUnread > 0;
                    break;
                }

                if (isFound)
                {
                    switch (attrType)
                    {
                    case AttrType.Any:
                        break;

                    case AttrType.Marked:
                        isFound = msg.IsMarked;
                        break;

                    case AttrType.Unread:
                        isFound = msg.IsUnread;
                        break;

                    default:
                        isFound = false;
                        break;
                    }

                    if (isFound)
                    {
                        _tgMsgs.ActiveNode = msg;
                        return;
                    }

                    treeNodes = TreeGrid.TreeGrid.GetFlatArrayOfSubNodes(msg);

                    if (dir == StepDirection.Up)
                    {
                        Array.Reverse(treeNodes);
                    }

                    foreach (IMsg subMsg in treeNodes)
                    {
                        if (IsMsgConformAttribute(subMsg, attrType))
                        {
                            _tgMsgs.ActiveNode = subMsg;
                            return;
                        }
                    }

                    throw new ApplicationException(
                              "Аргрегированная информация не соответсвует реальному содержанию БД. Произведите " +
                              "пересчет БД и обратитесь к разработчикам.");
                }
            }

            Beeper.DoBeep();
            return;
        }
Exemple #30
0
        /// <summary>
        /// Determines and sets the state of the 4 pixels that represent our current state, and sets our current and previous directions
        /// </summary>
        /// <param name="x">X</param>
        /// <param name="y">Y</param>
        private void Step(int x, int y)
        {
            // Scan our 4 pixel area
            bool upLeft = IsBorder(x - 1, y - 1),upRight = IsBorder(x, y - 1);
            bool downLeft = IsBorder(x - 1, y), downRight = IsBorder(x, y);

            // Store our previous step
            _previousStep = _nextStep;

            // Determine which state we are in
            var state = 0;

            if (upLeft)
                state |= 1;
            if (upRight)
                state |= 2;
            if (downLeft)
                state |= 4;
            if (downRight)
                state |= 8;

            // State now contains a number between 0 and 15
            // representing our state.
            // In binary, it looks like 0000-1111 (in binary)

            // An example. Let's say the top two pixels are filled,
            // and the bottom two are empty.
            // Stepping through the if statements above with a state
            // of 0b0000 initially produces:
            // Upper Left == true ==>  0b0001
            // Upper Right == true ==> 0b0011
            // The others are false, so 0b0011 is our state
            // (That's 3 in decimal.)

            // Looking at the chart above, we see that state
            // corresponds to a move right, so in our switch statement
            // below, we add a case for 3, and assign Right as the
            // direction of the next step. We repeat this process
            // for all 16 states.

            // So we can use a switch statement to determine our
            // next direction based on
            switch (state)
            {
                case 1: _nextStep = StepDirection.Up; break;
                case 2: _nextStep = StepDirection.Right; break;
                case 3: _nextStep = StepDirection.Right; break;
                case 4: _nextStep = StepDirection.Left; break;
                case 5: _nextStep = StepDirection.Up; break;
                case 6:
                    _nextStep = _previousStep == StepDirection.Up ? StepDirection.Left : StepDirection.Right;
                    break;
                case 7: _nextStep = StepDirection.Right; break;
                case 8: _nextStep = StepDirection.Down; break;
                case 9:
                    _nextStep = _previousStep == StepDirection.Right ? StepDirection.Up : StepDirection.Down;
                    break;
                case 10: _nextStep = StepDirection.Down; break;
                case 11: _nextStep = StepDirection.Down; break;
                case 12: _nextStep = StepDirection.Left; break;
                case 13: _nextStep = StepDirection.Up; break;
                case 14: _nextStep = StepDirection.Left; break;
                default:
                    _nextStep = StepDirection.None;
                    break;
            }
        }
		private void AttachStep(StepDirection direction)
		{
			// Set its Wizard property
			currentStep.Wizard = this;

			// Add event handlers
			currentStep.StepTitleChanged += new EventHandler(OnStepTitleChanged);
			currentStep.StepDescriptionChanged += new EventHandler(OnStepDescriptionChanged);
			currentStep.NextStepChanged += new EventHandler(OnNextStepChanged);
			currentStep.PreviousStepChanged += new EventHandler(OnPreviousStepChanged);
			currentStep.PageLayoutChanged += new EventHandler(OnPageLayoutChanged);
			currentStep.LogoChanged += new EventHandler(OnLogoChanged);
			currentStep.SideBarLogoChanged += new EventHandler(OnSideBarLogoChanged);
			currentStep.SideBarImageChanged += new EventHandler(OnSideBarImageChanged);
			
			// Update the title
			OnStepTitleChanged(null, EventArgs.Empty);
			OnStepDescriptionChanged(null, EventArgs.Empty);

			// Show the step
			currentStep.Dock = DockStyle.Fill;
			panelStep.Controls.Add(currentStep);

			// Update the buttons
			OnPreviousStepChanged(null, EventArgs.Empty);
			OnNextStepChanged(null, EventArgs.Empty);

			// Update wizard layout
			OnPageLayoutChanged(null, EventArgs.Empty);

			// Update logos if neccessary
			OnLogoChanged(null, EventArgs.Empty);
			OnSideBarLogoChanged(null, EventArgs.Empty);
			OnSideBarImageChanged(null, EventArgs.Empty);

			currentStep.FireShowEvent(new ShowStepEventArgs(direction));
		}
Exemple #32
0
        private void SetCurrentStep(int index, StepDirection dir)
        {
            SuspendLayout();

            try
            {
                if (curStepNo != -1)
                {
                    DetatchStep();
                }

                curStepNo = index;

                AttachStep(dir);
            }
            finally
            {
                UpdateUIState();
                ResumeLayout(true);
            }
        }
        // Determines and sets the state of the 4 pixels that
        // represent our current state, and sets our current and
        // previous directions
        private void Step(int x, int y)
        {
            // Scan our 4 pixel area
            bool upLeft = IsPixelSolid(x - 1, y - 1);
            bool upRight = IsPixelSolid(x, y - 1);
            bool downLeft = IsPixelSolid(x - 1, y);
            bool downRight = IsPixelSolid(x, y);

            // Store our previous step
            previousStep = nextStep;

            // Determine which state we are in
            int state = 0;

            if (upLeft)
                state |= 1;
            if (upRight)
                state |= 2;
            if (downLeft)
                state |= 4;
            if (downRight)
                state |= 8;

            switch (state)
            {
                case 1: nextStep = StepDirection.Up; break;
                case 2: nextStep = StepDirection.Right; break;
                case 3: nextStep = StepDirection.Right; break;
                case 4: nextStep = StepDirection.Left; break;
                case 5: nextStep = StepDirection.Up; break;
                case 6:
                    if (previousStep == StepDirection.Up)
                    {
                        nextStep = StepDirection.Left;
                    }
                    else
                    {
                        nextStep = StepDirection.Right;
                    }
                    break;
                case 7: nextStep = StepDirection.Right; break;
                case 8: nextStep = StepDirection.Down; break;
                case 9:
                    if (previousStep == StepDirection.Right)
                    {
                        nextStep = StepDirection.Up;
                    }
                    else
                    {
                        nextStep = StepDirection.Down;
                    }
                    break;
                case 10: nextStep = StepDirection.Down; break;
                case 11: nextStep = StepDirection.Down; break;
                case 12: nextStep = StepDirection.Left; break;
                case 13: nextStep = StepDirection.Up; break;
                case 14: nextStep = StepDirection.Left; break;
                default:
                    nextStep = StepDirection.None;
                    break;
            }
        }
Exemple #34
0
        /// <summary>
        /// Searches a step of a recipe
        /// </summary>
        /// <param name="recipeId">Id of the owning Recipe</param>
        /// <param name="stepId">Id of a step</param>
        /// <param name="direction">To provide navigation you define if the step of the given id or one of its neighbors</param>
        /// <returns>Returns one step of a recipe</returns>
        public async Task <StepViewModel> GetStepAsync(int recipeId, int stepId = -1, StepDirection direction = StepDirection.ThisStep)
        {
            StepViewModel result = null;
            var           steps  = await this.GetStepsForRecipe(recipeId).ToListAsync();

            var step = stepId == -1 ? steps.FirstOrDefault() : steps.SingleOrDefault(x => x.Id.Equals(stepId));

            if (step == null)
            {
                var message = stepId == -1 ? $"Recipe {recipeId} does not define any steps" : $"No step with the id {stepId} was found";
                throw new DataObjectNotFoundException(message);
            }
            var stepIndex = steps.IndexOf(step);

            switch (direction)
            {
            case StepDirection.ThisStep:
                result = step;
                break;

            case StepDirection.Next:
                result = steps.ElementAtOrDefault(stepIndex + 1) ?? steps.Last();
                break;

            case StepDirection.Previous:
                result = steps.ElementAtOrDefault(stepIndex - 1) ?? steps.First();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(direction), direction, null);
            }
            return(result);
        }
Exemple #35
0
 public static Offset FromDirection(StepDirection stepDirection)
 {
     return(StepOffsets[(int)stepDirection]);
 }
		public void SetCurrentStep(string name, StepDirection dir)
		{
			if( name == null || name == "" )
			{
				throw new ArgumentException("Step is null or empty", "step");
			}

			BaseStep bws = steps[name];

			if( bws == null )
			{
				throw new ArgumentException("Step does not contain the name of a step in the wizard", "name");
			}

			SetCurrentStep(bws, dir);
		}
		protected void SetCurrentStep(BaseStep step, StepDirection dir)
		{
			SuspendLayout();

			try
			{
				if( currentStep != null )
				{
					DetatchStep();
				}

				currentStep = step;
			
				AttachStep(dir);
			}
			finally
			{
				ResumeLayout(true);
			}
		}
 private static StepDirection ReverseStepDirection(StepDirection startStepDirection)
 {
     return startStepDirection == StepDirection.Right
                ? StepDirection.Left
                : StepDirection.Right;
 }
 /// <summary>
 /// Move as specified in direction.
 /// </summary>
 /// <param name="direction">What step to do next.</param>
 public NextStep(StepDirection direction)
 {
     Direction = direction;
 }
Exemple #40
0
 public async Task <StepViewModel> GetStepAsync(int recipeId, int stepId = -1, StepDirection direction = StepDirection.ThisStep)
 {
     return(await this.Client.GetAsync <StepViewModel>($"Recipes/{recipeId}/Steps/{stepId}" + (direction != StepDirection.ThisStep ? $"?direction={direction}" : "")));
 }
Exemple #41
0
 private void AttachStep(StepDirection dir)
 {
     if (IsCurStepNoValid())
     {
         steps[curStepNo].Parent = this;
         steps[curStepNo].Dock = DockStyle.Fill;
         this.pnlBackGround.Controls.Add(steps[curStepNo]);
         steps[curStepNo].OnLoaded(dir);
     }
 }