public void SetNewName(DrawingItem item) { if (item != null) { item.Name = CreateNewDrawingItemName(item.GetType().Name); } }
public void SetDefaultDrawing(DrawingItem item) { Type t = item.GetType(); DrawingItem d = (DrawingItem)item.Clone(); if (_defaultObjects.ContainsKey(t)) { _defaultObjects[t] = d; } else { _defaultObjects.Add(t, d); } updateFile(); }
private void showDrawingBoard(object sender, EventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { DrawingPage page = mi.Tag as DrawingPage; if (page != null) { IDesignerHost host = (IDesignerHost)this.GetService(typeof(IDesignerHost)); if (host != null) { HostSurface surface = host.GetService(typeof(DesignSurface)) as HostSurface; if (surface != null) { ClassPointer root = surface.Loader.GetRootId(); DrawingLayerCollection layers = page.ShowDrawingsEditor(); if (layers != null) { //layers0 is the existing layer collections DrawingLayerCollection layers0 = page.DrawingLayers; //for layers0 if a drawing object's guid does not exist in layers then //the object has been deleted List <DrawingItem> deleted = new List <DrawingItem>(); foreach (DrawingLayer l0 in layers0) { DrawingItem d = null; for (int i = 0; i < l0.Count; i++) { DrawingItem d0 = l0[i]; d = layers.GetDrawingItemById(d0.DrawingId); if (d != null) { d0.Copy(d); //not deleted //move and resize the IDrawDesignControl foreach (Control c in page.Controls) { IDrawDesignControl dc0 = c as IDrawDesignControl; if (dc0 != null) { if (dc0.Item == d0) { c.Location = d0.Location; c.Size = d0.Bounds.Size; break; } } } } else { deleted.Add(d0); //deleted } } } if (deleted.Count > 0) { //check to see if each deleted item has usages List <DrawingItem> ls = new List <DrawingItem>(); foreach (DrawingItem d0 in deleted) { for (int i = 0; i < page.Controls.Count; i++) { IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl; if (dc != null) { if (dc.DrawingId == d0.DrawingId) { uint id = root.ObjectList.GetObjectID(dc); if (id == 0) { DesignUtil.WriteToOutputWindow("id not found on deleting component {0}", dc.Name); } else { List <ObjectTextID> list = root.GetComponentUsage(id); if (list.Count > 0) { dlgObjectUsage dlg = new dlgObjectUsage(); dlg.LoadData("Cannot delete this component. It is being used by the following objects", string.Format("Component - {0}", dc.Name), list); dlg.ShowDialog(); ls.Add(d0); } } break; } } } } if (ls.Count > 0) { foreach (DrawingItem d0 in ls) { deleted.Remove(d0); } } foreach (DrawingItem d0 in deleted) { for (int i = 0; i < page.Controls.Count; i++) { IDrawDesignControl dc = page.Controls[i] as IDrawDesignControl; if (dc != null) { if (dc.DrawingId == d0.DrawingId) { surface.Loader.DeleteComponent(page.Controls[i]); break; } } } } } //for a drawing object in layers if its guid does not exist in layers0 then //it is a new object //reset zorder according to the new layers List <Control> ctrls = new List <Control>(); foreach (DrawingLayer l in layers) { int zOrder = 0; foreach (DrawingItem d in l) { DrawingItem d0 = layers0.GetDrawingItemById(d.DrawingId); if (d0 == null) { //add a new drawing string name = d.Name + Guid.NewGuid().GetHashCode().ToString("x"); Type designerType = TypeMappingAttribute.GetMappedType(d.GetType()); if (designerType == null) { throw new DesignerException("Drawing type {0} does not have a designer", d.GetType()); } Control dc = (Control)surface.Loader.CreateComponent(designerType, name); IDrawDesignControl ddc = (IDrawDesignControl)dc; ddc.Item = d; dc.Location = d.Location; dc.Size = d.Bounds.Size; ctrls.Add(dc); ddc.ZOrder = zOrder; } else { for (int k = 0; k < page.Controls.Count; k++) { IDrawDesignControl dc = page.Controls[k] as IDrawDesignControl; if (dc != null) { if (dc.Item == d0) { dc.ZOrder = zOrder; break; } } } } zOrder += 10; } } if (ctrls.Count > 0) { page.Controls.AddRange(ctrls.ToArray()); } page.LoadData(layers, false); page.Refresh(); surface.SetModified(); surface.Loader.NotifyChanges(); } } } } } }
protected override void OnMouseDown(MouseEventArgs e) { sHelp = ""; if (curDrawing != null) { float x1, y1; bool bAdded; systemToCustomerXY(e.X, e.Y, out x1, out y1); System.Windows.Forms.MouseEventArgs e1 = new System.Windows.Forms.MouseEventArgs(e.Button, e.Clicks, (int)x1, (int)y1, e.Delta); System.Windows.Forms.DialogResult ret = curDrawing.CallDlgDrawingsMouseDown(this, e1, ref nStep, this); switch (ret) { case System.Windows.Forms.DialogResult.OK: if (nType == 0) { bAdded = this.DrawingLayers[0].AddDrawing(curDrawing); } else { bAdded = lstShapes.AddDrawing(curDrawing); hs.SetDrawings(lstShapes); formHS.Show(); formHS.TopMost = true; formHS.Invalidate(); } if (bAdded) { AddDrawing(curDrawing); } else { } editor.SelectItem(curDrawing); curDrawing.FinishDesign(); curDrawing = null; nStep = 0; editor.Show(); break; case System.Windows.Forms.DialogResult.Cancel: curDrawing.FinishDesign(); curDrawing = null; nStep = 0; editor.Show(); break; case System.Windows.Forms.DialogResult.Retry: nStep = 0; break; case System.Windows.Forms.DialogResult.None: break; } this.Invalidate(); } else { Point p = new Point(e.X, e.Y); DrawingItem item = HitTest(p); if (item != null) { SetItemSelection(item); if (e.Button == MouseButtons.Right) { MenuItem[] menus = item.GetContextMenuItems(p); if (menus != null && menus.Length > 0) { ContextMenu cm = new ContextMenu(); cm.MenuItems.AddRange(menus); cm.Show(this, p); } } } else { ClearMarks(); if ((e.Button & MouseButtons.Left) == MouseButtons.Left) { Type t = _toolBox.SelectedToolboxItem; if (t != null) { DrawingItem newObj = (DrawingItem)Activator.CreateInstance(t); if (_defaultDrawings == null) { _defaultDrawings = new DefaultDrawings(); } DrawingItem def = _defaultDrawings.GetDefaultDrawing(newObj.GetType()); if (def != null) { newObj.Copy(def); } _toolBox.ClearToolboxSelection(); newObj.ResetGuid(); makeNewName(newObj); newObj.Page = this; newObj.Location = p; AddDrawing(newObj); editor.SelectItem(newObj); editor.RefreshPropertyGrids(); _newObj = newObj; SetItemSelection(newObj); } } } } }