/// <ToBeCompleted></ToBeCompleted> public void SetLayerZoomBounds(Diagram diagram, Layer layer, int lowerZoomBounds, int upperZoomBounds) { if (diagram == null) { throw new ArgumentNullException("diagram"); } if (layer == null) { throw new ArgumentNullException("layer"); } AssertDiagramSetControllerIsSet(); ICommand cmdMinZoom = null; ICommand cmdMaxZoom = null; if (layer.LowerZoomThreshold != lowerZoomBounds) { cmdMinZoom = new EditLayerCommand(diagram, layer, EditLayerCommand.ChangedProperty.LowerZoomThreshold, layer.LowerZoomThreshold, lowerZoomBounds); } if (layer.UpperZoomThreshold != upperZoomBounds) { cmdMaxZoom = new EditLayerCommand(diagram, layer, EditLayerCommand.ChangedProperty.UpperZoomThreshold, layer.UpperZoomThreshold, upperZoomBounds); } ICommand cmd; if (cmdMinZoom != null && cmdMaxZoom != null) { cmd = new AggregatedCommand(); ((AggregatedCommand)cmd).Add(cmdMinZoom); ((AggregatedCommand)cmd).Add(cmdMaxZoom); } else if (cmdMinZoom != null && cmdMaxZoom == null) { cmd = cmdMinZoom; } else if (cmdMaxZoom != null && cmdMinZoom == null) { cmd = cmdMaxZoom; } else { cmd = null; } if (cmd != null) { Project.ExecuteCommand(cmd); if (LayerModified != null) { LayerModified(this, LayerHelper.GetLayersEventArgs(LayerHelper.GetLayers(layer.Id, diagram))); } } }
/// <summary> /// Starts collecting all added commands in an aggregated command. /// Aggregated commands can be undone with a single call of Undo()/Redo(). /// While aggregating commands, the CommandAdded event will not be raised. /// </summary> public void BeginAggregatingCommands() { aggregatingCommands = true; aggregatedCommand = new AggregatedCommand(); }
/// <ToBeCompleted></ToBeCompleted> public void SetLayerZoomBounds(Diagram diagram, Layer layer, int lowerZoomBounds, int upperZoomBounds) { if (diagram == null) throw new ArgumentNullException("diagram"); if (layer == null) throw new ArgumentNullException("layer"); AssertDiagramSetControllerIsSet(); ICommand cmdMinZoom = null; ICommand cmdMaxZoom = null; if (layer.LowerZoomThreshold != lowerZoomBounds) cmdMinZoom = new EditLayerCommand(diagram, layer, EditLayerCommand.ChangedProperty.LowerZoomThreshold, layer.LowerZoomThreshold, lowerZoomBounds); if (layer.UpperZoomThreshold != upperZoomBounds) cmdMaxZoom = new EditLayerCommand(diagram, layer, EditLayerCommand.ChangedProperty.UpperZoomThreshold, layer.UpperZoomThreshold, upperZoomBounds); ICommand cmd; if (cmdMinZoom != null && cmdMaxZoom != null) { cmd = new AggregatedCommand(); ((AggregatedCommand) cmd).Add(cmdMinZoom); ((AggregatedCommand) cmd).Add(cmdMaxZoom); } else if (cmdMinZoom != null && cmdMaxZoom == null) cmd = cmdMinZoom; else if (cmdMaxZoom != null && cmdMinZoom == null) cmd = cmdMaxZoom; else cmd = null; if (cmd != null) { Project.ExecuteCommand(cmd); if (LayerModified != null) LayerModified(this, LayerHelper.GetLayersEventArgs(LayerHelper.GetLayers(layer.Id, diagram))); } }
/// <summary> /// End aggregation of commands and adds the AggregatedCommand to the History. /// Raises a CommandAdded event. /// Does not execute the collected commands. /// </summary> public void EndAggregatingCommands() { aggregatingCommands = false; AddCommand(aggregatedCommand); aggregatedCommand = null; }
/// <summary> /// Cancels the aggregation of commands. All collected commands will be undone and not added to the history. /// </summary> public void CancelAggregatingCommands() { if (aggregatingCommands) { aggregatingCommands = false; aggregatedCommand.Revert(); aggregatedCommand = null; } }
/// <summary> /// Creates a new LinearShape and inserts it into the diagram of the CurrentDisplay by executing a Command. /// </summary> private void FinishExtendLine(IDiagramPresenter diagramPresenter, MouseState mouseState, bool ignorePointAtMouse) { #if DEBUG_DIAGNOSTICS Assert(PreviewShape != null); Assert(modifiedLinearShape != null); #endif Shape modifiedShape = (Shape)modifiedLinearShape; // Copy points from the PreviewShape to the new shape // Start at the opposite point of the point at mouse cursor and skip all existing points ControlPointId pointId, endPointId; bool firstToLast; if (pointAtCursor == ControlPointId.FirstVertex) { pointId = ControlPointId.LastVertex; endPointId = ignorePointAtMouse ? lastInsertedPointId : (ControlPointId)ControlPointId.FirstVertex; firstToLast = false; } else { pointId = ControlPointId.FirstVertex; endPointId = ignorePointAtMouse ? lastInsertedPointId : (ControlPointId)ControlPointId.LastVertex; firstToLast = true; } // Create an aggregated command which performs connecting the new shape to other shapes in one step AggregatedCommand aggregatedCommand = null; // Process all point id's do { ControlPointId nextPointId = GetNextResizePointId(PreviewLinearShape, pointId, firstToLast); ControlPointId nextOrigPtId = GetNextResizePointId(modifiedLinearShape, pointId, firstToLast); if (nextPointId != nextOrigPtId && nextPointId != endPointId) { // If the next point id of the preview does not equal the original shape's point id, // we have to create it... Point p = PreviewShape.GetControlPointPosition(nextPointId); ControlPointId beforePointId = (firstToLast) ? (ControlPointId)ControlPointId.LastVertex : pointId; if (aggregatedCommand == null) aggregatedCommand = new AggregatedCommand(); aggregatedCommand.Add(new InsertVertexCommand(modifiedShape, beforePointId, p.X, p.Y)); } pointId = nextPointId; } while (pointId != endPointId); // Set last point's position ControlPointId lastPtId = firstToLast ? ControlPointId.LastVertex : ControlPointId.FirstVertex; Point currPos = modifiedShape.GetControlPointPosition(lastPtId); Point newPos = PreviewShape.GetControlPointPosition(endPointId); #if DEBUG_DIAGNOSTICS Assert(aggregatedCommand != null); #endif aggregatedCommand.Add(new MoveControlPointCommand(modifiedShape, lastPtId, newPos.X - currPos.X, newPos.Y - currPos.Y, ResizeModifiers.None)); // Create connection for the last vertex ShapeAtCursorInfo targetInfo = FindConnectionTarget(ActionDiagramPresenter, modifiedShape, lastPtId, newPos, false, true); if (!targetInfo.IsEmpty && !targetInfo.IsCursorAtGluePoint && targetInfo.ControlPointId != ControlPointId.None) { if (aggregatedCommand == null) aggregatedCommand = new AggregatedCommand(); aggregatedCommand.Add(new ConnectCommand(modifiedShape, lastPtId, targetInfo.Shape, targetInfo.ControlPointId)); } // Execute command and insert it into the history if (aggregatedCommand != null) ActionDiagramPresenter.Project.ExecuteCommand(aggregatedCommand); }
/// <summary> /// Creates a new LinearShape and inserts it into the diagram of the CurrentDisplay by executing a Command. /// </summary> private void FinishLine(IDiagramPresenter diagramPresenter, MouseState mouseState, bool ignorePointAtMouse) { #if DEBUG_DIAGNOSTICS Assert(PreviewShape != null); #endif // Create a new shape from the template Shape newShape = Template.CreateShape(); // Copy points from the PreviewShape to the new shape // The current EndPoint of the preview (sticking to the mouse cursor) will be discarded foreach (ControlPointId pointId in PreviewShape.GetControlPointIds(ControlPointCapabilities.Resize)) { Point p = PreviewShape.GetControlPointPosition(pointId); switch (pointId) { case ControlPointId.Reference: // Skip ReferencePoint as it is not a physically existing vertex (identically to FirstVertex) continue; case ControlPointId.LastVertex: if (ignorePointAtMouse) continue; newShape.MoveControlPointTo(ControlPointId.LastVertex, p.X, p.Y, ResizeModifiers.None); break; case ControlPointId.FirstVertex: newShape.MoveControlPointTo(ControlPointId.FirstVertex, p.X, p.Y, ResizeModifiers.None); break; default: // Treat the last inserted Point as EndPoint if ((ignorePointAtMouse && pointId == lastInsertedPointId) || ((ILinearShape)newShape).VertexCount == ((ILinearShape)newShape).MaxVertexCount) newShape.MoveControlPointTo(ControlPointId.LastVertex, p.X, p.Y, ResizeModifiers.None); else ((ILinearShape)newShape).InsertVertex(ControlPointId.LastVertex, p.X, p.Y); break; } } // Insert the new linear shape ActionDiagramPresenter.InsertShape(newShape); // Create an aggregated command which performs connecting the new shape to other shapes in one step AggregatedCommand aggregatedCommand = null; // Create connections foreach (ControlPointId gluePointId in newShape.GetControlPointIds(ControlPointCapabilities.Glue)) { ShapeConnectionInfo sci = PreviewShape.GetConnectionInfo(gluePointId, null); if (!sci.IsEmpty) { if (aggregatedCommand == null) aggregatedCommand = new AggregatedCommand(); aggregatedCommand.Add(new ConnectCommand(newShape, gluePointId, sci.OtherShape, sci.OtherPointId)); } else { // Create connection for the last vertex Point gluePtPos = newShape.GetControlPointPosition(gluePointId); ShapeAtCursorInfo targetInfo = FindConnectionTarget(ActionDiagramPresenter, newShape, ControlPointId.LastVertex, gluePtPos, false, true); if (!targetInfo.IsEmpty && !targetInfo.IsCursorAtGluePoint && targetInfo.ControlPointId != ControlPointId.None) { if (aggregatedCommand == null) aggregatedCommand = new AggregatedCommand(); aggregatedCommand.Add(new ConnectCommand(newShape, gluePointId, targetInfo.Shape, targetInfo.ControlPointId)); } } } // execute command and insert it into the history if (aggregatedCommand != null) ActionDiagramPresenter.Project.ExecuteCommand(aggregatedCommand); }