public GroupShape(IModel model) : base(model) { this.mEntities = new CollectionBase <IDiagramEntity>(); this.mEntities.OnItemAdded += new EventHandler <CollectionEventArgs <IDiagramEntity> >(mEntities_OnItemAdded); this.mEntities.OnClear += new EventHandler(mEntities_OnClear); this.mEntities.OnItemRemoved += new EventHandler <CollectionEventArgs <IDiagramEntity> >(mEntities_OnItemRemoved); }
public override void Redo() { //remove the group from the layer this.Controller.Model.DefaultPage.DefaultLayer.Entities.Remove(mGroup); //detach the entities from the group foreach (IDiagramEntity entity in mGroup.Entities) { //this will be recursive if an entity is itself an IGroup entity.Group = null; bundle.Entities.Add(entity); //mGroup.Entities.Remove(entity); } //change the visuals such that the entities in the group are selected CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>(); col.AddRange(mGroup.Entities); Selection.SelectedItems = col; mGroup.Invalidate(); mGroup = null; //note that the entities have never been disconnected from the layer //so they don't have to be re-attached to the anything. //The insertion of the Group simply got pushed in the scene-graph. }
public override void Undo() { //create a new group GroupShape group = new GroupShape(this.Controller.Model); //asign the entities to the group group.Entities = bundle.Entities; foreach (IDiagramEntity entity in group.Entities) { //this will be recursive if an entity is itself an IGroup entity.Group = group; } //add the new group to the layer this.Controller.Model.DefaultPage.DefaultLayer.Entities.Add(group); mGroup = group; //select the newly created group CollectionBase <IDiagramEntity> col = new CollectionBase <IDiagramEntity>(); col.Add(mGroup); Selection.SelectedItems = col; mGroup.Invalidate(); }
public ComplexShapeBase(IModel model) : base(model) { mChildren = new CollectionBase <IShapeMaterial>(); mChildren.OnItemAdded += new EventHandler <CollectionEventArgs <IShapeMaterial> >(mChildren_OnItemAdded); mServices = new Dictionary <Type, IInteraction>(); }
public static void TraverseCollect(IGroup group, ref CollectionBase <IDiagramEntity> collection) { #region Checks if (group == null) { throw new InconsistencyException("Cannot collect entities of a 'null' IGroup"); } if (collection == null) { throw new InconsistencyException("You need to instantiate a collection before using this method."); } #endregion foreach (IDiagramEntity entity in group.Entities) { if (entity is IGroup) { TraverseCollect(entity as IGroup, ref collection); } else { collection.Add(entity); } } }
protected ConnectorBase(Point p) : base() { #region FIX2006020701 attachedConnectors = new CollectionBase <IConnector>(); #endregion this.point = p; }
public Layer(string name) { mName = name; mEntities = new CollectionBase <IDiagramEntity>(); mEntities.OnItemAdded += new EventHandler <CollectionEventArgs <IDiagramEntity> >(mEntities_OnItemAdded); mEntities.OnItemRemoved += new EventHandler <CollectionEventArgs <IDiagramEntity> >(mEntities_OnItemRemoved); mEntities.OnClear += new EventHandler(mEntities_OnClear); }
public ShapeBase(IModel model) : base(model) { mRectangle = new Rectangle(0, 0, 100, 70); connectors = new CollectionBase <IConnector>(); shapeColor = ArtPallet.RandomLowSaturationColor; SetBrush(); }
public Page(string name) { mLayers = new CollectionBase <ILayer>(); //the one and only and indestructible layer mDefaultLayer = new Layer("Default Layer"); mDefaultLayer.OnEntityAdded += new EventHandler <EntityEventArgs>(defaultLayer_OnEntityAdded); mDefaultLayer.OnEntityRemoved += new EventHandler <EntityEventArgs>(mDefaultLayer_OnEntityRemoved); mDefaultLayer.OnClear += new EventHandler(mDefaultLayer_OnClear); mLayers.Add(mDefaultLayer); mName = name; }
public Bundle(CollectionBase <IDiagramEntity> collection) { mEntities = new CollectionBase <IDiagramEntity>(); //we could assign it directly but let's make sure the collection does not //contain unwanted elements foreach (IDiagramEntity entity in collection) { if ((entity is IShape) || (entity is IConnection) || (entity is IGroup)) { mEntities.Add(entity); } } //the following line would give problem. The event handler attached to the Selection would be triggered when //the mEntities collection is changed! //mEntities = collection; }
public void ShowTracker() { if (Selection.SelectedItems != null && Selection.SelectedItems.Count > 0) { CollectionBase <IDiagramEntity> ents = Selection.SelectedItems; bool showHandles = false; Rectangle rec = ents[0].Rectangle; foreach (IDiagramEntity entity in ents) { rec = Rectangle.Union(rec, entity.Rectangle); showHandles |= entity.Resizable; } //make the tracker slightly bigger than the actual bounding rectangle rec.Inflate(TrackerOffset, TrackerOffset); this.PaintTracker(rec, showHandles); } else //if the selection is 'null' or empty we annihilate the current tracker { ResetTracker(); } }
public Model() { mAmbience = new Ambience(this); //listen to events AttachToAmbience(mAmbience); //here I'll have to work on the scene graph this.mShapes = new ShapeCollection(); //the page collection mPages = new CollectionBase <IPage>(); //the default page mDefaultPage = new Page("Default Page"); mDefaultPage.OnEntityAdded += new EventHandler <EntityEventArgs>(mDefaultPage_OnEntityAdded); mDefaultPage.OnEntityRemoved += new EventHandler <EntityEventArgs>(mDefaultPage_OnEntityRemoved); mDefaultPage.OnClear += new EventHandler(mDefaultPage_OnClear); mPages.Add(mDefaultPage); //initially the current page is the one and only default page mCurrentPage = mDefaultPage; //the paintables mPaintables = new CollectionBase <IDiagramEntity>(); }
protected override void OnActivateTool() { /* * A lot of stuff is calculated here for something which might seem at first sight * a really simple action. In general the calculations will be short since a user does not * usually shift many shapes at the same time and the overlap with the selection * is small. */ if (Selection.SelectedItems != null && Selection.SelectedItems.Count > 0) { /* * They should give me a Nobel prize for so much thinking early in the morning... */ #region Preparation of the ordering Debug.Assert(Selection.SelectedItems[0] != null, "A selection cannot contain a 'null' entity."); //the items have to be moved in the order of the Paintables; the SortedList automatically orders things for us. SortedList <int, IDiagramEntity> list = new SortedList <int, IDiagramEntity>(); //We fetch a flattened selection, which means that if there is a group the constituents will be //returned rather than the group itself. foreach (IDiagramEntity entity in Selection.FlattenedSelectionItems) { //the addition will automatically put the item in increasing order list.Add(this.Controller.Model.Paintables.IndexOf(entity), entity); } //if the highest z-value is the last one in the paintables we cannot shift anything, so we quit if (list.Keys[list.Count - 1] == this.Controller.Model.Paintables.Count - 1) { return; } /*Send them forwards but make sure it's a visible effect! * It's not enough to move it only once since the shape(s) above might be of * high z-order degree, so we have to find which is the first shape overlapping with * the selection and take as many steps as it takes to surpass it. * If there is no overlap we'll shift the z-order with just one unit. */ int delta = 1; int lowestZInSelection = list.Keys[0]; bool found = false; //we can speed up the loop by noticing that the next shape in the z-stack is necessarily //above the first one of the selection for (int m = lowestZInSelection + 1; m < this.Controller.Model.Paintables.Count && !found; m++) { //the overlap has to be with an entity, not from the selection if (list.ContainsValue(this.Controller.Model.Paintables[m])) { continue; } for (int s = 0; s < list.Count; s++) { //if there is an overlap we found the required index if (this.Controller.Model.Paintables[m].Rectangle.IntersectsWith(list.Values[s].Rectangle)) { //an additional complication here; if the found shape is part of a group we have //to take the upper z-value of the group... if (this.Controller.Model.Paintables[m].Group != null) { int max = -1; CollectionBase <IDiagramEntity> leafs = new CollectionBase <IDiagramEntity>(); Utils.TraverseCollect(this.Controller.Model.Paintables[m].Group, ref leafs); foreach (IDiagramEntity groupMember in leafs) { max = Math.Max(max, this.Controller.Model.Paintables.IndexOf(groupMember)); } //take the found z-value of the group rather than the one of the group-child m = max; } delta = m - lowestZInSelection; found = true; break; } } } #endregion Debug.Assert(delta >= 1, "The shift cannot be less than one since we checked previous situations earlier."); for (int k = 0; k < list.Count; k++) { this.Controller.Model.SendForwards(list.Values[k], delta); } } DeactivateTool(); }
protected ConnectorBase(Point p, IModel model) : base(model) { attachedConnectors = new CollectionBase <IConnector>(); point = p; }
public CompoundCommand(IController controller) : base(controller) { commands = new CollectionBase <ICommand>(); }
public virtual void AddRange(CollectionBase <T> items) { this.innerList.AddRange(items); //TODO: raise for each item? }
protected ControllerBase(IDiagramControl surface) { //doesn't work if you supply a null reference if (surface == null) { throw new NullReferenceException("The diagram control assigned to the controller cannot be 'null'"); } mModel = new Model(); mModel.OnEntityAdded += new EventHandler <EntityEventArgs>(mModel_OnEntityAdded); mModel.OnEntityRemoved += new EventHandler <EntityEventArgs>(mModel_OnEntityRemoved); //create the undo/redo manager mUndoManager = new UndoManager(15); mUndoManager.OnHistoryChange += new EventHandler(mUndoManager_OnHistoryChange); #region Instantiation of listeners mouseListeners = new CollectionBase <IMouseListener>(); keyboardListeners = new CollectionBase <IKeyboardListener>(); dragdropListeners = new CollectionBase <IDragDropListener>(); #endregion //keep a reference to the parent control parentControl = surface; ListenTo(parentControl); //Make sure the static selection class knows about the model Selection.Controller = this; //Initialize the colorscheme ArtPallet.Init(); #region Tools: the registration order matters! registeredTools = new CollectionBase <ITool>(); TransformTool transformer = new TransformTool("Transform Tool"); transformer.Controller = this; this.AddTool(transformer); HitTool hitter = new HitTool("Hit Tool"); hitter.Controller = this; this.AddTool(hitter); MoveTool mover = new MoveTool("Move Tool"); mover.Controller = this; this.AddTool(mover); RectangleTool recter = new RectangleTool("Rectangle Tool"); recter.Controller = this; this.AddTool(recter); EllipseTool ellipser = new EllipseTool("Ellipse Tool"); ellipser.Controller = this; this.AddTool(ellipser); SelectionTool selecter = new SelectionTool("Selection Tool"); selecter.Controller = this; this.AddTool(selecter); DragDropTool dragdropper = new DragDropTool("DragDrop Tool"); dragdropper.Controller = this; this.AddTool(dragdropper); ConnectionTool connecter = new ConnectionTool("Connection Tool"); connecter.Controller = this; this.AddTool(connecter); ConnectorMoverTool conmover = new ConnectorMoverTool("Connector Mover Tool"); conmover.Controller = this; this.AddTool(conmover); GroupTool grouper = new GroupTool("Group Tool"); grouper.Controller = this; this.AddTool(grouper); UngroupTool ungrouper = new UngroupTool("Ungroup Tool"); ungrouper.Controller = this; this.AddTool(ungrouper); SendToBackTool sendback = new SendToBackTool("SendToBack Tool"); sendback.Controller = this; this.AddTool(sendback); SendBackwardsTool sendbackwards = new SendBackwardsTool("SendBackwards Tool"); sendbackwards.Controller = this; this.AddTool(sendbackwards); SendForwardsTool sendforwards = new SendForwardsTool("SendForwards Tool"); sendforwards.Controller = this; this.AddTool(sendforwards); SendToFrontTool sendfront = new SendToFrontTool("SendToFront Tool"); sendfront.Controller = this; this.AddTool(sendfront); TextTool texttool = new TextTool("Text Tool"); texttool.Controller = this; this.AddTool(texttool); HoverTool hoverer = new HoverTool("Hover Tool"); hoverer.Controller = this; this.AddTool(hoverer); #endregion }
public Bundle(IModel model) : base(model) { mEntities = new CollectionBase <IDiagramEntity>(); }
protected ConnectorBase(IModel model) : base(model) { attachedConnectors = new CollectionBase <IConnector>(); }
public void MouseMove(MouseEventArgs e) { if (!IsSuspended && this.Enabled) { IHoverListener listener = null; CollectionBase <IDiagramEntity> paintables = this.Controller.Model.Paintables; IDiagramEntity entity; if (paintables.Count == 0) { return; } //going from top to the bottom of the z-order for (int k = paintables.Count - 1; k >= 0; k--) { entity = paintables[k]; if (entity.Rectangle.Contains(e.Location)) //we caught an entity { //unhover the previous, if any if (previousHovered != null) { previousHovered.Hovered = false; } entity.Hovered = true; //tell the current one it's being hovered //fetch the hovering service, if defined listener = entity.GetService(typeof(IHoverListener)) as IHoverListener; if (listener != null) //the caught entity does listen { if (currentListener == listener) //it's the same as the previous time { listener.MouseHover(e); } else //we moved from one entity to another listening entity { if (currentListener != null) //tell the previous entity we are leaving { currentListener.MouseLeave(e); } listener.MouseEnter(e); //tell the current one we enter currentListener = listener; } } else //the caught entity does not listen { if (currentListener != null) { currentListener.MouseLeave(e); currentListener = null; } } previousHovered = entity; //remember, for the next time return; //if another entity is listening underneath this entity it will not receive the notification } } if (currentListener != null) { currentListener.MouseLeave(e); currentListener = null; } //unhover the previous, if any if (previousHovered != null) { previousHovered.Hovered = false; } } }
public Bundle() { mEntities = new CollectionBase <IDiagramEntity>(); }