Пример #1
0
        private void CreateGroup(ISelectionContext selectionContext, ViewingContext viewingContext)
        {
            // build the group
            var newGroup = new DomNode(GroupType).As <Group>();

            newGroup.DefaultPinOrder = DefaultPinOrderStyle;
            newGroup.DomNode.Type.SetTag <ICircuitElementType>(newGroup);
            newGroup.Id   = "Group".Localize("a noun");
            newGroup.Name = newGroup.Id;
            newGroup.ShowExpandedGroupPins = CircuitDefaultStyle.ShowExpandedGroupPins;

            var selected          = selectionContext.LastSelected.As <DomNode>();
            var doc               = selected.GetRoot().Cast <DomDocument>();
            var subGraphValidator = doc.Cast <CircuitValidator>();

            subGraphValidator.Suspended = true;

            var circuitEditingContext = selected.Parent.Cast <CircuitEditingContext>();

            // Place the circuit group before the elements get repositioned to the group's local coordinate system.
            if (Placement == PlacementMode.Center)
            {
                // position it at center of grouped modules
                Rectangle bounds = viewingContext.GetBounds(selectionContext.Selection.AsIEnumerable <Element>());
                circuitEditingContext.Center(new object[] { newGroup }, new Point(
                                                 bounds.X + bounds.Width / 2,
                                                 bounds.Y + bounds.Height / 2));
            }
            else
            {
                // find upper-left corner of the subnodes
                Point minLocation = new Point(int.MaxValue, int.MaxValue);
                foreach (var module in selectionContext.Selection.AsIEnumerable <Element>())
                {
                    if (minLocation.X > module.Bounds.Location.X)
                    {
                        minLocation.X = module.Bounds.Location.X;
                    }
                    if (minLocation.Y > module.Bounds.Location.Y)
                    {
                        minLocation.Y = module.Bounds.Location.Y;
                    }
                }
                // position it at upper-left conner of grouped modules
                newGroup.Bounds   = new Rectangle(minLocation.X, minLocation.Y, newGroup.Bounds.Width, newGroup.Bounds.Height);
                newGroup.Position = newGroup.Bounds.Location;
            }

            CreateGroup(newGroup, selectionContext.Selection, circuitEditingContext.CircuitContainer);

            if (CreationOptions == GroupCreationOptions.HideUnconnectedPins)
            {
                newGroup.UpdateGroupPinInfo();
                foreach (var grpPin in newGroup.InputGroupPins)
                {
                    grpPin.Visible = grpPin.Info.ExternalConnected;
                }

                foreach (var grpPin in newGroup.OutputGroupPins)
                {
                    grpPin.Visible = grpPin.Info.ExternalConnected;
                }
            }

            // select the newly created group
            circuitEditingContext.Selection.Set(newGroup);
            subGraphValidator.Suspended = false;
        }
Пример #2
0
        private void CreateGroup(ISelectionContext selectionContext, ViewingContext viewingContext)
        {
            // build the group
            var newGroup = new DomNode(GroupType).As<Group>();
            newGroup.DefaultPinOrder = DefaultPinOrderStyle;
            newGroup.DomNode.Type.SetTag<ICircuitElementType>(newGroup);
            newGroup.Id = "Group".Localize("a noun");
            newGroup.Name = newGroup.Id;
            newGroup.ShowExpandedGroupPins = CircuitDefaultStyle.ShowExpandedGroupPins;

            var selected = selectionContext.LastSelected.As<DomNode>();
            var doc = selected.GetRoot().Cast<DomDocument>();
            var subGraphValidator = doc.Cast<CircuitValidator>();
            subGraphValidator.Suspended = true;

            var circuitEditingContext = selected.Parent.Cast<CircuitEditingContext>();

            // Place the circuit group before the elements get repositioned to the group's local coordinate system.
            if (Placement == PlacementMode.Center)
            {
                // position it at center of grouped modules
                Rectangle bounds = viewingContext.GetBounds(selectionContext.Selection.AsIEnumerable<Element>());
                circuitEditingContext.Center(new object[] { newGroup }, new Point(
                    bounds.X + bounds.Width / 2,
                    bounds.Y + bounds.Height / 2));
            }
            else
            {
                // find upper-left corner of the subnodes
                Point minLocation = new Point(int.MaxValue, int.MaxValue);
                foreach (var module in selectionContext.Selection.AsIEnumerable<Element>())
                {
                    if (minLocation.X > module.Bounds.Location.X)
                        minLocation.X = module.Bounds.Location.X;
                    if (minLocation.Y > module.Bounds.Location.Y)
                        minLocation.Y = module.Bounds.Location.Y;
                }
                // position it at upper-left conner of grouped modules
                newGroup.Bounds = new Rectangle(minLocation.X, minLocation.Y, newGroup.Bounds.Width, newGroup.Bounds.Height);
                newGroup.Position = newGroup.Bounds.Location;
            }

            CreateGroup(newGroup, selectionContext.Selection, circuitEditingContext.CircuitContainer);

            if (CreationOptions == GroupCreationOptions.HideUnconnectedPins)
            {
                newGroup.UpdateGroupPinInfo();
                foreach (var grpPin in newGroup.InputGroupPins)
                    grpPin.Visible = grpPin.Info.ExternalConnected;

                foreach (var grpPin in newGroup.OutputGroupPins)
                    grpPin.Visible = grpPin.Info.ExternalConnected;
            }

            // select the newly created group
            circuitEditingContext.Selection.Set(newGroup);
            subGraphValidator.Suspended = false;
        }