public static Type GetDrawingItemType(Type controlType) { if (controlType.GetInterface("IDrawDesignControl") != null) { Type ret = TypeMappingAttribute.GetMappedType(controlType); if (ret == null) { throw new ExceptionDrawing2D("DrawingControl type {0} does not have DrawingItemTypeAttribute", controlType.AssemblyQualifiedName); } return(ret); } else { return(controlType); } }
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(); } } } } } }
static StringCollection _s_baseProperties; //subclasses must use their own static variables public DrawingGroupBox() { Visible = true; _item = (DrawingItem)Activator.CreateInstance(TypeMappingAttribute.GetMappedType(this.GetType())); }