Example #1
0
		/// <summary>
		/// Creates a configuration tree item (level0) for this state
		/// </summary>
		/// <param name="state">parent. can't be null</param>
		public StateConfigVm(StateVm state)
			: base(state.ParentWindowVm)
		{
			State = state;
			TreeLevel = 0;
			IsFixed = state.Model.StateStations.Any(ss => ss.Blocks.Any());
			ContentsList.CollectionChanged += ContentsList_CollectionChanged;
		}
Example #2
0
		/// <summary>
		/// Create a temporary state just for drag and drop
		/// </summary>
		/// <param name="x"></param>
		/// <param name="y"></param>
		/// <param name="parentWindowVm"></param>
		/// <returns></returns>
		public static StateVm CreateTemp(double x, double y, FpcWindowVm parentWindowVm)
		{
			var vm = new StateVm
			{
				InitializingPhase = true,
				ParentWindowVm = parentWindowVm,
				Width = 1,
				Height = 1,
				Location = new Vector(x, y),
				//since model is null, StateType will be Temp
			};
			return vm;
		}
Example #3
0
		public ConnectorVm(Model.Connector model, StateVm start, StateVm end, DataServices.ConnectorDataService connectorDataService, bool isLoose = false)
		{
			Model = model;
			Start = start;
			End = end;
			IsLoose = isLoose;
			DeleteCommand = new Commands.Command(o =>
			{
				if(Model != null)
					connectorDataService.DeleteModel(Model);
				if (ConnectorRemoved != null) 
					ConnectorRemoved();
			});
		}
Example #4
0
		/// <summary>
		/// Sets FocusedState to the specified state and do the following actions:
		/// <para>Place the state into FpcWindowVm if it's not placed yet, Otherwise start dragging the state</para>
		/// <para>Start drawing a connector if 'connector' is selected from menu bar</para>
		/// </summary>
		/// <param name="state"></param>
		/// <param name="pos_drawingArea">location of mouse relative to drawing area</param>
		/// <param name="pos_firstChild">location of mouse relative to first child of state</param>
		/// <param name="pos_state">location of mouse relative to state</param>
		public void MouseClicksState(StateVm state, Point pos_drawingArea, Point pos_firstChild, Point pos_state)
		{
			FocusedState = state;
			//place the newly created state which was dragging
			if (state == _newDraggingStateVm)
			{
				state.PlaceInFpc();
				_newDraggingStateVm = null;
				ToolSelection = true;
			}
			else
			{
				_initialDragPoint = pos_state;
				//connector is dragging
				if (ToolConnector)
				{
					RemoveHalfDrawnConnector();
					
					//create a temporary state and attach it to the end of connector
					var end = StateVm.CreateTemp(pos_drawingArea.X, pos_drawingArea.Y, this);
					DragTarget = end;
					States.Add(end);
					Connectors.Add(new ConnectorVm(null, state, end, fpcDataService.connectorDataService, true));

					RelativeDragPoint = new Point(0, 0);
				}
				//state is dragging
				else
				{
					DragTarget = state;
					RelativeDragPoint = pos_firstChild;
				}
			}
		}
Example #5
0
		/// <summary>
		/// Disconnects the dragging connector from the specified state
		/// <para>Exits if no connector is being dragged</para>
		/// <remarks>
		/// By 'dragging connector', we mean dragging state with StateType=Temp which holds the end of the connector
		/// </remarks>
		/// </summary>
		/// <param name="state">Target state as the end state for the connector</param>
		public void MouseLeavesState(StateVm state)
		{
			//find the drag target (temp state)
			var dt = DragTarget as StateVm;
			if (dt == null) return;
			if (dt.StateType != StateType.Temp) return;

			//find the connector that is being dragged
			var conn = Connectors.FirstOrDefault(x => x.End == dt);
			if (conn != null)
			{
				//make the connector loose again
				conn.IsLoose = true;
				_connectorDropTargetStateVm = null;
			}
		}
Example #6
0
		/// <summary>
		/// Connects the dragging connector to the specified state
		/// <para>Exits if no connector is being dragged</para>
		/// <remarks>
		/// By 'dragging connector', we mean dragging state with StateType=Temp which holds the end of the connector
		/// </remarks>
		/// </summary>
		/// <param name="state">Target state as the end state for the connector</param>
		public void MouseEntersState(StateVm state)
		{
			//find the drag target (temp state)
			var dt = DragTarget as StateVm;
			if (dt == null) return;
			if (dt.StateType != StateType.Temp) return;

			//find the connector that is being dragged
			var conn = Connectors.FirstOrDefault(x => x.End == dt);
			if (conn != null)
			{
				//if not making a loop or repeating an existing connector
				if (state != conn.Start && !Connectors.Any(x => x.End == state && x.Start == conn.Start))
				{
					//mark the connector to be attached
					conn.IsLoose = false;
					_connectorDropTargetStateVm = state;
				}
			}
		}
Example #7
0
		/// <summary>
		/// Adds a state to this fpc (both model and viewModel) and stick it to mouse
		/// </summary>
		private void addStateByTool()
		{
			var stateModel = new Model.State
			{
				StateType = StateType.Mid,
				X = -50,
				Y = -20,
				FPC = Model,
			};
			this.Model.States.Add(stateModel);

			_newDraggingStateVm = new StateVm(stateModel, this, false)
			{
				Opacity = 0.4d,
			};
			_newDraggingStateVm.Config = new StateConfigVm(_newDraggingStateVm);
			this.States.Add(_newDraggingStateVm);
			DragTarget = _newDraggingStateVm;
			RelativeDragPoint = new Point(50, 20);
		}
Example #8
0
		/// <summary>
		/// Removes the current dotted line (an incomplete connector)
		/// </summary>
		public void RemoveHalfDrawnConnector()
		{
			var conn = Connectors.Where(x => x.End.StateType == StateType.Temp).FirstOrDefault();
			if (conn == null) return;
			States.Remove(conn.End);
			Connectors.Remove(conn);
			_connectorDropTargetStateVm = null;
		}