Ejemplo n.º 1
0
        void RunView(UIViewType viewType, LoadDirection direction, ViewWithData arg = null)
        {
            if (requestedTarget?.ViewType == viewType)
            {
                arg             = requestedTarget;
                requestedTarget = null;
            }

            bool firstTime = CreateViewAndViewModel(viewType, arg);
            var  view      = GetObjectsForFlow(activeFlow)[viewType].View;

            transition.OnNext(new LoadData
            {
                View = view,
                Data = arg ?? new ViewWithData {
                    Flow = activeFlow, ViewType = viewType
                },
                Direction = direction
            });

            // controller might have been stopped in the OnNext above
            if (IsStopped)
            {
                return;
            }

            // if it's not the first time we've shown this view, no need
            // to set it up
            if (!firstTime)
            {
                return;
            }

            SetupView(viewType, view);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UniformLoad1D"/> class.
 /// </summary>
 /// <param name="magnitude">The magnitude of load.</param>
 /// <param name="direction">The direction of load.</param>
 /// <param name="sys">The coordination system type.</param>
 /// <param name="cse">The load case.</param>
 public UniformLoad1D(double magnitude, LoadDirection direction, CoordinationSystem sys, LoadCase cse)
 {
     this.magnitude          = magnitude;
     this.coordinationSystem = sys;
     this.direction          = direction;
     this.Case = cse;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 再帰呼び出しで道を作る
        /// </summary>
        /// <param name="startPointIndex">掘削の起点ポイント</param>
        public void RecursiveLoad(MapPoint startPointIndex)
        {
            //掘る方向を決める
            LoadDirection dir = GetDirection(startPointIndex);
            //掘る2マス先のポイントと中間地点を格納する変数
            MapPoint target, subTarget;

            //2マス先と中間マスを取得する
            switch (dir)
            {
            case LoadDirection.Top:
                target    = new MapPoint(startPointIndex.X, startPointIndex.Y - 2);
                subTarget = new MapPoint(startPointIndex.X, startPointIndex.Y - 1);
                break;

            case LoadDirection.Bottom:
                target    = new MapPoint(startPointIndex.X, startPointIndex.Y + 2);
                subTarget = new MapPoint(startPointIndex.X, startPointIndex.Y + 1);
                break;

            case LoadDirection.Left:
                target    = new MapPoint(startPointIndex.X - 2, startPointIndex.Y);
                subTarget = new MapPoint(startPointIndex.X - 1, startPointIndex.Y);
                break;

            case LoadDirection.Right:
                target    = new MapPoint(startPointIndex.X + 2, startPointIndex.Y);
                subTarget = new MapPoint(startPointIndex.X + 1, startPointIndex.Y);
                break;

            default:
                //もう掘れない場合は自分を掘削リストから削除して
                //既存のポイントから掘削を再開する
                //最初の一回目をゴールとする
                if (isGoalSet == false)
                {
                    isGoalSet = true;
                    GoalPoint = new MapPoint(startPointIndex.X, startPointIndex.Y);
                }
                LoadEvenPoint.Remove(startPointIndex);
                if (LoadEvenPoint.Count > 0)
                {
                    RecursiveLoad(LoadEvenPoint[rnd.Next(LoadEvenPoint.Count)]);
                }
                //掘削ポイントがもうない場合は終了する
                return;
            }
            //掘る先を掘削リストに追加
            LoadEvenPoint.Add(target);
            //対象と中間を掘る
            DungeonMap[target.X, target.Y]       = LoadStatus.Load;
            DungeonMap[subTarget.X, subTarget.Y] = LoadStatus.Load;
            //堀った先を中心に再帰
            RecursiveLoad(target);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// ポイントを起点に上下左右がすでに道化していないか調べる
        /// </summary>
        /// <param name="point"></param>
        /// <returns></returns>
        private LoadDirection GetDirection(MapPoint point)
        {
            List <LoadDirection> dir = new List <LoadDirection>();

            dir.Add(LoadDirection.Top);
            dir.Add(LoadDirection.Bottom);
            dir.Add(LoadDirection.Left);
            dir.Add(LoadDirection.Right);
            //上下左右4回チェック
            while (dir.Count > 0)
            {
                //調べる方向をランダム取得
                LoadDirection checkDir = dir[rnd.Next(dir.Count - 1)];
                //実際に調べるポイントを宣言
                MapPoint checkPoint = new MapPoint();
                //2マス先がまだ壁だったらその方向を返す
                switch (checkDir)
                {
                case LoadDirection.Top:
                    checkPoint.X = point.X;
                    checkPoint.Y = point.Y - 2;
                    break;

                case LoadDirection.Bottom:
                    checkPoint.X = point.X;
                    checkPoint.Y = point.Y + 2;
                    break;

                case LoadDirection.Left:
                    checkPoint.X = point.X - 2;
                    checkPoint.Y = point.Y;
                    break;

                case LoadDirection.Right:
                    checkPoint.X = point.X + 2;
                    checkPoint.Y = point.Y;
                    break;

                default:
                    break;
                }
                if (DungeonMap[checkPoint.X, checkPoint.Y] == LoadStatus.Wall)
                {
                    return(checkDir);
                }
                //対象の方向が道だったらその方向を削除してもう一度
                dir.Remove(checkDir);
            }
            //全方向進めなかった場合
            return(LoadDirection.None);
        }
Ejemplo n.º 5
0
        private void AddFixPoints(string[] fixPointList, LoadDirection direction, float leftPosition, float rightPosition)
        {
            var color        = direction == LoadDirection.Source ? Color.Red : Color.Blue;
            var fixPointType = direction == LoadDirection.Source ? FixPoint.Types.Start : FixPoint.Types.End;

            foreach (var fixPoint in fixPointList)
            {
                var localYaw      = Trigonometry.PI(Trigonometry.Angle2Rad(90.0f));
                var fixPointArray = fixPoint.Split(':');
                var side          = fixPointArray[0];
                var name          = fixPointArray.Length > 2 ? fixPointArray[2] : "";
                var trackSide     = string.Equals("R", side) ? rightPosition : leftPosition;
                if (string.Equals("R", side) && direction == LoadDirection.Source)
                {
                    localYaw = Trigonometry.PI(Trigonometry.Angle2Rad(270.0f));
                }
                if (string.Equals("L", side) && direction == LoadDirection.Destination)
                {
                    localYaw = Trigonometry.PI(Trigonometry.Angle2Rad(270.0f));
                }
                var trackPosition = TCarLength / 2 - 0.05f; // Default value to be replaced by TryParse
                var isFloat       = float.TryParse(fixPointArray[1], System.Globalization.NumberStyles.AllowDecimalPoint, System.Globalization.CultureInfo.CreateSpecificCulture("en-GB"), out trackPosition);
                if (isFloat)
                {
                    // Find out which fixpoint is the furthest
                    furthestFixPoint = furthestFixPoint < trackPosition ? trackPosition : furthestFixPoint;
                    DematicFixPoint fp = new DematicFixPoint(color, fixPointType, this);
                    fp.Name = name;
                    if (direction == LoadDirection.Source)
                    {
                        fp.OnSnapped   += new FixPoint.SnappedEvent(SourceFixPoint_OnSnapped);
                        fp.OnUnSnapped += new FixPoint.UnSnappedEvent(SourceFixPoint_OnUnSnapped);
                    }
                    else
                    {
                        fp.OnSnapped   += new FixPoint.SnappedEvent(DestinationFixPoint_OnSnapped);
                        fp.OnUnSnapped += new FixPoint.UnSnappedEvent(DestinationFixPoint_OnUnSnapped);
                    }
                    Add(fp);
                    fp.LocalPosition = new Vector3(-trackPosition, 0, trackSide);
                    fp.LocalYaw      = localYaw;
                    // Label
                    Text3D label = new Text3D(Color.Yellow, 0.08f, 0.1f, new Font(FontFamily.GenericSansSerif, 1.0f));
                    label.Text = name;
                    Add(label);
                    label.LocalPosition = new Vector3(-trackPosition + 0.08f, 0, trackSide - 0.02f);
                    label.Pitch         = Trigonometry.PI(Trigonometry.Angle2Rad(90.0f));
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Load1D"/> class.
 /// </summary>
 /// <param name="info">The information.</param>
 /// <param name="context">The context.</param>
 /// <exception cref="System.NotImplementedException"></exception>
 internal Load1D(SerializationInfo info, StreamingContext context)
     : base(info, context)
 {
     this.direction          = (LoadDirection)info.GetInt32("direction");
     this.coordinationSystem = (CoordinationSystem)info.GetInt32("coordinationSystem");
 }
Ejemplo n.º 7
0
 public PointLoad(double magnitude, double location, LoadDirection direction)
 {
     Location  = location;
     Magnitude = magnitude;
     Direction = direction;
 }
 public NavStep(LoadDirection direction, UIViewType viewtype)
 {
     Direction = direction;
     ViewType = viewtype;
 }
Ejemplo n.º 9
0
        void RunView(UIViewType viewType, LoadDirection direction, ViewWithData arg = null)
        {
            if (requestedTarget?.ViewType == viewType)
            {
                arg             = requestedTarget;
                requestedTarget = null;
            }

            if (arg == null)
            {
                arg = new ViewWithData {
                    ActiveFlow = activeFlow, MainFlow = mainFlow, ViewType = viewType
                }
            }
            ;
            bool firstTime = CreateViewAndViewModel(viewType, arg);
            var  view      = GetObjectsForFlow(activeFlow)[viewType].View;

            transition.OnNext(new LoadData
            {
                View      = view,
                Data      = arg,
                Direction = direction
            });

            // controller might have been stopped in the OnNext above
            if (IsStopped)
            {
                return;
            }

            // if it's not the first time we've shown this view, no need
            // to set it up
            if (!firstTime)
            {
                return;
            }

            SetupView(viewType, view);
        }

        void SetupView(UIViewType viewType, IView view)
        {
            var list = GetObjectsForFlow(activeFlow);
            var pair = list[viewType];

            // 2FA is set up when login is set up, so nothing to do
            if (viewType == UIViewType.TwoFactor)
            {
                return;
            }

            // we're setting up the login dialog, we need to setup the 2fa as
            // well to continue the flow if it's needed, since the
            // authenticationresult callback won't happen until
            // everything is done
            if (viewType == UIViewType.Login)
            {
                var pair2fa = list[UIViewType.TwoFactor];
                pair2fa.AddHandler(pair2fa.ViewModel.WhenAny(x => x.IsShowing, x => x.Value)
                                   .Where(x => x)
                                   .ObserveOn(RxApp.MainThreadScheduler)
                                   .Subscribe(_ => Fire(Trigger.Next)));

                pair2fa.AddHandler(pair2fa.View.Cancel
                                   .ObserveOn(RxApp.MainThreadScheduler)
                                   .Subscribe(_ => Fire(uiStateMachine.CanFire(Trigger.Cancel) ? Trigger.Cancel : Trigger.Finish)));

                pair.AddHandler(view.Done
                                .ObserveOn(RxApp.MainThreadScheduler)
                                .Subscribe(_ => Fire(Trigger.Finish)));
            }
            else
            {
                pair.AddHandler(view.Done
                                .ObserveOn(RxApp.MainThreadScheduler)
                                .Subscribe(_ => Fire(uiStateMachine.CanFire(Trigger.Next) ? Trigger.Next : Trigger.Finish)));

                var cv = view as IHasCreationView;
                if (cv != null)
                {
                    pair.AddHandler(cv.Create
                                    .ObserveOn(RxApp.MainThreadScheduler)
                                    .Subscribe(_ => Fire(Trigger.PRCreation)));
                }

                var dv = view as IHasDetailView;
                if (dv != null)
                {
                    pair.AddHandler(dv.Open
                                    .ObserveOn(RxApp.MainThreadScheduler)
                                    .Subscribe(x => Fire(Trigger.PRDetail, x)));
                }
            }

            pair.AddHandler(view.Cancel
                            .ObserveOn(RxApp.MainThreadScheduler)
                            .Subscribe(_ => Fire(uiStateMachine.CanFire(Trigger.Cancel) ? Trigger.Cancel : Trigger.Finish)));
        }

        /// <summary>
        /// Creates View/ViewModel instances for the specified <paramref name="viewType"/> if they
        /// haven't been created yet in the current flow
        /// </summary>
        /// <param name="viewType"></param>
        /// <returns>true if the View/ViewModel didn't exist and had to be created</returns>
        bool CreateViewAndViewModel(UIViewType viewType, ViewWithData data = null)
        {
            var list = GetObjectsForFlow(activeFlow);

            if (viewType == UIViewType.Login)
            {
                if (!list.ContainsKey(viewType))
                {
                    var d = factory.CreateViewAndViewModel(UIViewType.TwoFactor);
                    list.Add(UIViewType.TwoFactor, d);
                }
            }

            // 2fa view/viewmodel is created when login is created 'cause login needs the 2fa viewmodel
            // so the only thing we want to do is connect the viewmodel to the view when it's showing
            else if (viewType == UIViewType.TwoFactor)
            {
                var d = list[viewType];
                if (d.View.ViewModel == null)
                {
                    d.ViewModel.Initialize(data);
                    d.View.DataContext = d.ViewModel;
                }
            }

            if (!list.ContainsKey(viewType))
            {
                var d = factory.CreateViewAndViewModel(viewType);
                d.ViewModel.Initialize(data);
                d.View.DataContext = d.ViewModel;
                list.Add(viewType, d);
                return(true);
            }

            return(false);
        }

        /// <summary>
        /// Returns the view/viewmodel pair for a given flow
        /// </summary>
        Dictionary <UIViewType, IUIPair> GetObjectsForFlow(UIControllerFlow flow)
        {
            Dictionary <UIViewType, IUIPair> list;

            if (!uiObjects.TryGetValue(flow, out list))
            {
                list = new Dictionary <UIViewType, IUIPair>();
                uiObjects.Add(flow, list);
            }
            return(list);
        }

        void Fire(Trigger next, ViewWithData arg = null)
        {
            Debug.WriteLine("Firing {0} from {1} ({2})", next, uiStateMachine.State, GetHashCode());
            if (arg != null && triggers.ContainsKey(next))
            {
                uiStateMachine.Fire(triggers[next], arg);
            }
            else
            {
                uiStateMachine.Fire(next);
            }
        }

        UIViewType Go(Trigger trigger)
        {
            return(Go(trigger, activeFlow));
        }

        UIViewType Go(Trigger trigger, UIControllerFlow flow)
        {
            var m = machines[flow];

            Debug.WriteLine("Firing {0} from {1} for flow {2} ({3})", trigger, m.State, flow, GetHashCode());
            m.Fire(trigger);
            return(m.State);
        }

        void Reset()
        {
            if (connectionAdded != null)
            {
                connectionManager.Connections.CollectionChanged -= connectionAdded;
            }
            connectionAdded = null;

            var tr  = transition;
            var cmp = completion;

            transition = null;
            completion = null;
            disposables.Clear();
            tr?.Dispose();
            cmp?.Dispose();
            stopping   = false;
            connection = null;
        }

        bool disposed; // To detect redundant calls
Ejemplo n.º 10
0
 public void LoadMessages(LoadDirection direction)
 {
     MessageLoadRequested?.Invoke(this, new MessageLoadRequestedArgs(direction));
 }
Ejemplo n.º 11
0
 public NavStep(LoadDirection direction, UIViewType viewtype)
 {
     Direction = direction;
     ViewType  = viewtype;
 }
Ejemplo n.º 12
0
 public MessageLoadRequestedArgs(LoadDirection direction)
 {
     Direction = direction;
 }