Exemplo n.º 1
0
        public static IList<StateControl> FromCommon(StateModel stateModel)
        {
            List<StateControl> stateControls = new List<StateControl>();
            foreach (var state in stateModel.States)
            {
                var stateControl = new StateControl();
                stateControl.InitialPosition = new Point(state.X, state.Y);
                stateControl.DisplayName = state.Name;
                stateControl.StateId = state.StateID;
                stateControl.StartState = state.Default;
                stateControls.Add(stateControl);
            }

            foreach (var transition in stateModel.Transitions)
            {
                var sourceControl = (from sc in stateControls where sc.StateId == transition.SourceStateRef select sc).Single();
                var destControl = (from sc in stateControls where sc.StateId == transition.DestinationStateRef select sc).Single();
                if (sourceControl == null || destControl == null)
                {
                    throw new System.InvalidOperationException("cannot find states for transition");
                }
                var arrow = new Arrow();
                arrow.TailControl = sourceControl;
                arrow.HeadControl = destControl;
                sourceControl.AddArrow(arrow, StateControl.ArrowDirection.Out);
                destControl.AddArrow(arrow, StateControl.ArrowDirection.In);
            }
            return stateControls;
        }
Exemplo n.º 2
0
 public void AddArrow(Arrow arrow, ArrowDirection direction)
 {
     switch (direction)
     {
         case ArrowDirection.In:
             arrowsIn.Add(arrow);
             break;
         case ArrowDirection.Out:
             arrowsOut.Add(arrow);
             break;
     }
 }