Example #1
0
        public void UnExecute()
        {
            StageView     stage = MainForm.CurrentStage;
            InstanceGroup sel   = MainForm.CurrentStage.Selection;

            uint[] ids = sel.SelectedIds;

            foreach (Bond b in addedBonds)
            {
                stage.CurrentEditItem.BondStore.RemoveBond(b);
            }

            for (int i = 0; i < ids.Length; i++)
            {
                DesignInstance di = MainForm.CurrentInstanceManager[ids[i]];

                Vex.Matrix m      = di.GetMatrix();
                Vex.Point  offset = new Vex.Point(-offsets[i].X, -offsets[i].Y);
                m.Translate(offset);
                stage.SetDesignInstanceMatrix(di, m);
            }

            if (useSmartBonds)
            {
                foreach (Bond b in previousBonds)
                {
                    stage.CurrentEditItem.BondStore.AddBond(b);
                }
            }

            sel.Update();
            MainForm.CurrentStage.ResetTransformHandles();
            MainForm.CurrentStage.InvalidateTransformedSelection();
        }
Example #2
0
        public void Execute()
        {
            StageView stage = MainForm.CurrentStage;

            InstanceGroup sel = stage.Selection;

            this.prevSelected = sel.SelectedIds;

            Vex.Point selRotCent = sel.GlobalRotationCenter.Translate(sel.Location.Negate());

            uint[]      libraryIds = new uint[prevSelected.Length];
            Vex.Point[] locations  = new Vex.Point[prevSelected.Length];
            for (int i = 0; i < prevSelected.Length; i++)
            {
                DesignInstance di = MainForm.CurrentInstanceManager[prevSelected[i]];
                libraryIds[i] = di.LibraryItem.DefinitionId;
                locations[i]  = new Vex.Point(di.Location.X + offset.X, di.Location.Y + offset.Y);
            }

            if (newInstanceIds == null)
            {
                newInstanceIds = stage.AddInstances(libraryIds, locations);
                for (int i = 0; i < newInstanceIds.Length; i++)
                {
                    DesignInstance oldDi = MainForm.CurrentInstanceManager[prevSelected[i]];
                    DesignInstance newDi = MainForm.CurrentInstanceManager[newInstanceIds[i]];
                    Vex.Matrix     m     = oldDi.GetMatrix();
                    stage.SetDesignInstanceMatrix(newDi, new Vex.Matrix(m.ScaleX, m.Rotate0, m.Rotate1, m.ScaleY, newDi.Location.X, newDi.Location.Y));

                    newDi.RotationCenter = oldDi.RotationCenter;
                }
            }
            else
            {
                stage.AddInstancesById(newInstanceIds);
            }

            sel.Set(newInstanceIds);
            sel.GlobalRotationCenter = selRotCent.Translate(sel.Location);
            stage.ResetTransformHandles();
            stage.InvalidateTransformedSelection();
        }
        public void UnExecute()
        {
            StageView stage = MainForm.CurrentStage;

            stage.Selection.Clear();
            stage.RemoveInstancesById(new uint[] { newInstanceId });
            LibraryView.CurrentLibraryView.RemoveItemFromLibrary(newLibraryItemId);

            stage.AddInstancesById(prevSelected);

            for (int i = 0; i < prevSelected.Length; i++)
            {
                DesignInstance inst = stage.InstanceManager[prevSelected[i]];
                Vex.Matrix     m    = inst.GetMatrix();
                m.TranslateX += prevOffset.X;
                m.TranslateY += prevOffset.Y;
                stage.SetDesignInstanceMatrix(inst, m);
            }

            stage.Selection.Set(prevSelected);
            stage.ResetTransformHandles();
        }
Example #4
0
        public void Execute()
        {
            StageView     stage = MainForm.CurrentStage;
            InstanceGroup sel   = MainForm.CurrentStage.Selection;

            Vex.Rectangle bounds = sel.StrokeBounds;
            uint[]        ids    = sel.SelectedIds;
            offsets = new Vex.Point[ids.Length];

            InstanceManager im      = MainForm.CurrentInstanceManager;
            List <uint>     sortIds = new List <uint>(ids);

            im.SortIndexesByLocation(sortIds, chainType);

            Vex.Point target = Vex.Point.Empty;

            if (chainType == ChainType.DistributedHorizontal)
            {
                float firstWidth      = MainForm.CurrentInstanceManager[sortIds[0]].StrokeBounds.Width;
                float lastWidth       = MainForm.CurrentInstanceManager[sortIds[sortIds.Count - 1]].StrokeBounds.Width;
                float fillWidth       = bounds.Width - firstWidth - lastWidth;
                float remainingWidths = 0;
                for (int i = 1; i < sortIds.Count - 1; i++)
                {
                    DesignInstance di = MainForm.CurrentInstanceManager[sortIds[i]];
                    remainingWidths += di.StrokeBounds.Width;
                }

                float spacing = (fillWidth - remainingWidths) / (sortIds.Count - 1);
                float curLoc  = bounds.Left;

                for (int i = 0; i < sortIds.Count; i++)
                {
                    DesignInstance di     = MainForm.CurrentInstanceManager[sortIds[i]];
                    Vex.Point      offset = new Vex.Point(curLoc - di.StrokeBounds.Left, 0);

                    Vex.Matrix m = di.GetMatrix();
                    m.Translate(offset);
                    stage.SetDesignInstanceMatrix(di, m);

                    curLoc += spacing + di.StrokeBounds.Width;

                    int realIndex = Array.IndexOf(ids, sortIds[i]);
                    offsets[realIndex] = offset;
                }

                target = new Vex.Point(spacing, float.NaN);
            }
            else if (chainType == ChainType.DistributedVertical)
            {
                float firstHeight      = MainForm.CurrentInstanceManager[sortIds[0]].StrokeBounds.Height;
                float lastHeight       = MainForm.CurrentInstanceManager[sortIds[sortIds.Count - 1]].StrokeBounds.Height;
                float fillHeight       = bounds.Height - firstHeight - lastHeight;
                float remainingHeights = 0;
                for (int i = 1; i < sortIds.Count - 1; i++)
                {
                    DesignInstance di = MainForm.CurrentInstanceManager[sortIds[i]];
                    remainingHeights += di.StrokeBounds.Height;
                }

                float spacing = (fillHeight - remainingHeights) / (sortIds.Count - 1);
                float curLoc  = bounds.Top;

                for (int i = 0; i < sortIds.Count; i++)
                {
                    DesignInstance di     = MainForm.CurrentInstanceManager[sortIds[i]];
                    Vex.Point      offset = new Vex.Point(0, curLoc - di.StrokeBounds.Top);

                    Vex.Matrix m = di.GetMatrix();
                    m.Translate(offset);
                    stage.SetDesignInstanceMatrix(di, m);

                    curLoc += spacing + di.StrokeBounds.Height;

                    int realIndex = Array.IndexOf(ids, sortIds[i]);
                    offsets[realIndex] = offset;
                }
                target = new Vex.Point(float.NaN, spacing);
            }
            else
            {
                Vex.Rectangle contrainedBounds = bounds.Clone();
                stage.CurrentEditItem.BondStore.ConstrainBounds(sortIds, ref contrainedBounds, chainType);

                switch (chainType)
                {
                case ChainType.AlignedLeft:
                    target = new Vex.Point(contrainedBounds.Left, float.NaN);
                    break;

                case ChainType.AlignedCenterVertical:
                    target = new Vex.Point(contrainedBounds.Center.X, float.NaN);
                    break;

                case ChainType.AlignedRight:
                    target = new Vex.Point(contrainedBounds.Right, float.NaN);
                    break;

                case ChainType.AlignedTop:
                    target = new Vex.Point(float.NaN, contrainedBounds.Top);
                    break;

                case ChainType.AlignedCenterHorizontal:
                    target = new Vex.Point(float.NaN, contrainedBounds.Center.Y);
                    break;

                case ChainType.AlignedBottom:
                    target = new Vex.Point(float.NaN, contrainedBounds.Bottom);
                    break;
                }

                for (int i = 0; i < sortIds.Count; i++)
                {
                    DesignInstance di     = MainForm.CurrentInstanceManager[sortIds[i]];
                    Vex.Point      offset = Vex.Point.Zero;

                    switch (chainType)
                    {
                    case ChainType.AlignedLeft:
                        offset.X = target.X - di.StrokeBounds.Left;
                        break;

                    case ChainType.AlignedCenterVertical:
                        offset.X = target.X - (di.StrokeBounds.Left + di.StrokeBounds.Width / 2);
                        break;

                    case ChainType.AlignedRight:
                        offset.X = target.X - (di.StrokeBounds.Left + di.StrokeBounds.Width);
                        break;

                    case ChainType.AlignedTop:
                        offset.Y = target.Y - di.StrokeBounds.Top;
                        break;

                    case ChainType.AlignedCenterHorizontal:
                        offset.Y = target.Y - (di.StrokeBounds.Top + di.StrokeBounds.Height / 2);
                        break;

                    case ChainType.AlignedBottom:
                        offset.Y = target.Y - (di.StrokeBounds.Top + di.StrokeBounds.Height);
                        break;
                    }

                    Vex.Matrix m = di.GetMatrix();
                    m.Translate(offset);
                    stage.SetDesignInstanceMatrix(di, m);

                    offsets[i] = offset;
                }
            }

            if (useSmartBonds)
            {
                stage.CurrentEditItem.BondStore.Align(sortIds.ToArray(), chainType, target, addedBonds, previousBonds);
            }

            sel.Update();
            MainForm.CurrentStage.ResetTransformHandles();
            MainForm.CurrentStage.InvalidateTransformedSelection();
        }
Example #5
0
        public void Execute()
        {
            StageView       stage   = MainForm.CurrentStage;
            InstanceGroup   sel     = stage.Selection;
            InstanceManager instMgr = stage.InstanceManager;

            prevSelection = sel.IdsByDepth;
            List <uint> addedInstances = new List <uint>();

            List <uint> newSelection   = new List <uint>();
            List <uint> toBreakApart   = new List <uint>();
            List <int>  originalDepths = new List <int>();

            for (int i = 0; i < prevSelection.Length; i++)
            {
                DesignInstance di = instMgr[prevSelection[i]];
                if (CanBreakApart(di))
                {
                    toBreakApart.Add(prevSelection[i]);
                    originalDepths.Add(di.Depth);
                }
                else
                {
                    newSelection.Add(prevSelection[i]);
                }
            }

            prevInstances = toBreakApart.ToArray();
            prevDepths    = originalDepths.ToArray();

            sel.Clear();
            for (int i = 0; i < toBreakApart.Count; i++)
            {
                uint           id        = toBreakApart[i];
                DesignInstance di        = instMgr[id];
                int            orgDepth  = di.Depth;
                Matrix         orgMatrix = di.GetSysMatrix();

                Vex.Point offset    = di.Location;
                uint[]    instances = ((DesignTimeline)di).InstanceIds;

                for (int j = instances.Length - 1; j >= 0; j--)
                {
                    DesignInstance orgInstance = instMgr[instances[j]];
                    uint           subLibId    = orgInstance.LibraryItem.DefinitionId;
                    DesignInstance inst        = stage.AddInstance(subLibId, Vex.Point.Zero);
                    stage.CurrentEditItem.ChangeDepth(inst.Depth, orgDepth);

                    using (Matrix m = orgInstance.GetSysMatrix().Clone())
                    {
                        m.Multiply(orgMatrix, MatrixOrder.Append);
                        stage.SetDesignInstanceMatrix(inst, m.VexMatrix());
                    }

                    addedInstances.Add(inst.InstanceHash);
                    newSelection.Add(inst.InstanceHash);
                }
                stage.RemoveInstancesById(new uint[] { id });
            }

            newInstances = addedInstances.ToArray();
            sel.Set(newSelection.ToArray());
            stage.ResetTransformHandles();
        }