예제 #1
0
        public bool Save(string folderPath)
        {
            bool result = false;

            DirectoryInfo dinf = Directory.CreateDirectory(folderPath);

            string libFileName = folderPath + Path.DirectorySeparatorChar + "Instances.xml";
            File.WriteAllText(libFileName, string.Empty);
            FileStream fs = new FileStream(libFileName, FileMode.OpenOrCreate);

            XmlTextWriter w = new XmlTextWriter(fs, System.Text.Encoding.UTF8);
            w.Formatting = Formatting.Indented;
            w.WriteStartElement("Instances");

            w.WriteElementString("InstanceIdCounter", stage.InstanceManager.instanceIdCounter.ToString());

            w.WriteStartElement("InstanceItems");

            foreach (uint key in items.Keys)
            {
                DesignInstance di = items[key];
                w.WriteStartElement("Item");
                w.WriteAttributeString("InstanceId", di.InstanceHash.ToString());
                w.WriteAttributeString("DefinitionId", di.DefinitionId.ToString());
                w.WriteAttributeString("ParentInstanceId", di.ParentInstanceId.ToString());
                w.WriteAttributeString("Type", di.GetType().ToString());
                w.WriteAttributeString("DataPath", di.GetDataPath());
                w.WriteEndElement();
            }
            w.WriteEndElement();

            w.WriteEndElement();
            w.Flush();
            fs.Close();

            // remove old defs
            foreach (uint key in removedPaths.Keys)
            {
                string path = folderPath + System.IO.Path.DirectorySeparatorChar + removedPaths[key];
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }
            removedPaths.Clear();

            // now write actual instance Items
            foreach (uint key in items.Keys)
            {
                DesignInstance di = items[key];
                if (di.HasSaveableChanges)
                {
                    di.Save(folderPath);
                }
            }

            hasSaveableChanges = false;

            return result;
        }
예제 #2
0
        public void UseCountTests()
        {
            DesignInstance si0a = dl.Add(lis[0].DefinitionId, new Point(10, 100));

            Assert.AreEqual(1, lis[0].UseCount);
            DesignInstance si0b = dl.Add(lis[0].DefinitionId, new Point(10, 100));
            DesignInstance si0c = dl.Add(lis[0].DefinitionId, new Point(10, 100));

            Assert.AreEqual(3, lis[0].UseCount);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(dl.InstanceIds, SelectionModifier.SetSelection));
            Assert.AreEqual(3, lis[0].UseCount);
            dl.Remove(si0a.InstanceHash);
            Assert.AreEqual(2, lis[0].UseCount);
            dl.RemoveInstancesById(new uint[] { si0b.InstanceHash, si0c.InstanceHash });
            Assert.AreEqual(0, lis[0].UseCount);

            dl.AddInstancesById(new uint[] { si0a.InstanceHash });
            Assert.AreEqual(1, lis[0].UseCount);

            DesignInstance si1 = dl.Add(lis[1].DefinitionId, new Point(20, 200));

            dl.AddInstancesById(new uint[] { si1.InstanceHash, si1.InstanceHash }); // should ignore multiple adds
            Assert.AreEqual(1, lis[0].UseCount);
            Assert.AreEqual(1, lis[1].UseCount);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { }, SelectionModifier.SetSelection));
            dl.Remove(si1.InstanceHash);
            dl.Remove(si0a.InstanceHash);
            Assert.AreEqual(0, lis[0].UseCount);
            Assert.AreEqual(0, lis[1].UseCount);
        }
예제 #3
0
        private void DistributeHorizontally(List <Bond> bondChain, Dictionary <uint, Vex.Rectangle> transforms)
        {
            Vex.Rectangle diFirst         = transforms[bondChain[0].SourceInstanceId];
            Vex.Rectangle diLast          = transforms[bondChain[bondChain.Count - 1].SourceInstanceId];
            float         firstWidth      = diFirst.Width;
            float         lastWidth       = diLast.Width;
            float         fillWidth       = diLast.Left - (diFirst.Left + diFirst.Width);
            float         remainingWidths = 0;

            for (int i = 1; i < bondChain.Count - 1; i++)
            {
                DesignInstance di = MainForm.CurrentInstanceManager[bondChain[i].SourceInstanceId];
                remainingWidths += di.StrokeBounds.Width;
            }

            float spacing = (fillWidth - remainingWidths) / (bondChain.Count - 1);

            float curLoc = diFirst.Left;

            for (int i = 0; i < bondChain.Count - 1; i++)
            {
                uint          id = bondChain[i].SourceInstanceId;
                Vex.Rectangle r  = transforms[id];

                transforms[id] = new Vex.Rectangle(curLoc, r.Top, r.Width, r.Height);

                curLoc += spacing + r.Width;
            }
        }
예제 #4
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();
        }
예제 #5
0
        private void DistributeVertically(List <Bond> bondChain, Dictionary <uint, Vex.Rectangle> transforms)
        {
            Vex.Rectangle diFirst          = transforms[bondChain[0].SourceInstanceId];
            Vex.Rectangle diLast           = transforms[bondChain[bondChain.Count - 1].SourceInstanceId];
            float         firstHeight      = diFirst.Height;
            float         lastHeight       = diLast.Height;
            float         fillHeight       = diLast.Top - (diFirst.Top + diFirst.Height);
            float         remainingHeights = 0;

            for (int i = 1; i < bondChain.Count - 1; i++)
            {
                DesignInstance di = MainForm.CurrentInstanceManager[bondChain[i].SourceInstanceId];
                remainingHeights += di.StrokeBounds.Height;
            }

            float spacing = (fillHeight - remainingHeights) / (bondChain.Count - 1);

            float curLoc = diFirst.Top;

            for (int i = 0; i < bondChain.Count - 1; i++)
            {
                uint          id = bondChain[i].SourceInstanceId;
                Vex.Rectangle r  = transforms[id];

                transforms[id] = new Vex.Rectangle(r.Left, curLoc, r.Width, r.Height);

                curLoc += spacing + r.Height;
            }
        }
예제 #6
0
 void tbInstance_LostFocus(object sender, EventArgs e)
 {
     if (MainForm.CurrentStage != null && MainForm.CurrentStage.CurrentEditItem != null && MainForm.CurrentStage.Selection.Count == 1)
     {
         DesignInstance di = MainForm.CurrentInstanceManager[MainForm.CurrentStage.Selection.SelectedIds[0]];
         di.InstanceName = tbInstance.Text;
     }
 }
예제 #7
0
        public void AddInstance(DesignInstance inst)
        {
            PointF[] pts = (inst.IsRotated) ? inst.GetTransformedCenter() : inst.GetTransformedPoints().GetMidpointsAndCenter();

            for (int i = 0; i < pts.Length; i++)
            {
                BondAttachment ba = BondAttachmentExtensions.GetTargetFromHandleIndex(i);
                AddPoint(xStops, pts[i].X, new CrossPoint(pts[i].Y, inst.InstanceHash, ba));
                AddPoint(yStops, pts[i].Y, new CrossPoint(pts[i].X, inst.InstanceHash, ba));
            }
        }
예제 #8
0
        public void UnExecute()
        {
            StageView stage = MainForm.CurrentStage;

            uint[] selIds = stage.Selection.SelectedIds;
            foreach (uint id in selIds)
            {
                DesignInstance di = stage.InstanceManager[id];
                di.AspectConstraint = prevConstraint;
            }

            stage.Selection.Update();
            MainForm.CurrentStage.InvalidateSelection();
        }
예제 #9
0
        private static bool CanBreakApart(DesignInstance di)
        {
            bool result = false;

            if (di is DesignTimeline)
            {
                DesignTimeline dt = (DesignTimeline)di;
                if (dt.Count > 1 || (dt.Count == 1 && MainForm.CurrentInstanceManager[dt.InstanceIds[0]].Definition is Vex.Timeline))
                {
                    result = true;
                }
            }
            return(result);
        }
예제 #10
0
 public DesignInstance this[uint id]
 {
     get
     {
         DesignInstance result = null;
         if (items.ContainsKey(id))
         {
             result = items[id];
         }
         else if (IsRemovedInstance(id))
         {
             result = removedItems[id];
         }
         return result;
     }
 }
예제 #11
0
        public void PopulateData(InstanceGroup selection)
        {
            if (selection == null || selection.Count == 0)
            {
                tDefinitionName.Text = "";
                tbInstance.Text      = "";
                tbX.Text             = "";
                tbY.Text             = "";
                tbWidth.Text         = "";
                tbHeight.Text        = "";
                tbXScale.Text        = "";
                tbYScale.Text        = "";
                tbRotation.Text      = "";
                tShear.Text          = "";
            }
            else
            {
                uint[]           ids = selection.SelectedIds;
                MatrixComponents mc  = selection.TransformMatrix.VexMatrix().GetMatrixComponents();
                if (selection.Count == 1)
                {
                    DesignInstance di = MainForm.CurrentInstanceManager[ids[0]];
                    tDefinitionName.Text = di.Definition.Name;
                    tbInstance.Text      = di.InstanceName;
                }
                else
                {
                }

                tbX.Text      = selection.Location.X.ToString("0.##");
                tbY.Text      = selection.Location.Y.ToString("0.##");
                tbWidth.Text  = (selection.UntransformedBounds.Width * mc.ScaleX).ToString("0.##");
                tbHeight.Text = (selection.UntransformedBounds.Height * mc.ScaleY).ToString("0.##");

                tbXScale.Text   = mc.ScaleX.ToString("0.##");
                tbYScale.Text   = mc.ScaleY.ToString("0.##");
                tbRotation.Text = mc.Rotation.ToString("0.##");
                tShear.Text     = mc.Shear.ToString("0.##");
            }

            if (MainForm.CurrentStage != null)
            {
                btStageColor.BackColor = MainForm.CurrentStage.BackgroundColor.SysColor();
                tbStageWidth.Text      = MainForm.CurrentStage.Width.ToString();
                tbStageHeight.Text     = MainForm.CurrentStage.Height.ToString();
            }
        }
예제 #12
0
        public void Execute()
        {
            StageView stage = MainForm.CurrentStage;

            // store old selection
            prevSelected = stage.Selection.IdsByDepth;// SelectedIds;
            prevOffset   = stage.Selection.StrokeBounds.Point;


            // create symbol from selected
            Vex.Timeline tl = new Vex.Timeline(stage.Library.NextLibraryId());

            tl.Name         = stage.Library.GetNextDefaultName();
            tl.StrokeBounds = stage.Selection.StrokeBounds.TranslatedRectangle(-prevOffset.X, -prevOffset.Y);

            // delete old symbols
            DesignInstance[] oldInstances = stage.RemoveInstancesById(prevSelected);

            for (int i = 0; i < prevSelected.Length; i++)
            {
                DesignInstance inst = oldInstances[i];// instMgr[prevSelected[i]];
                Vex.Matrix     m    = inst.GetMatrix();
                m.TranslateX -= prevOffset.X;
                m.TranslateY -= prevOffset.Y;
                inst.SetMatrix(m);
                tl.AddInstance(inst.Instance);
                stage.InstanceManager.AddInstance(inst); // reusing, so must readd (todo: don't  reuse ids?)
            }

            LibraryItem li = stage.CreateLibraryItem(tl, true);

            newLibraryItemId = li.DefinitionId;
            stage.Library.AddLibraryItem(li);
            LibraryView.CurrentLibraryView.AddItemToLibrary(li);

            // add new symbol to stage
            DesignInstance di = stage.AddInstance(tl.Id, prevOffset);

            newInstanceId = di.InstanceHash;

            // select new symbol
            stage.Selection.Set(new uint[] { di.InstanceHash });
            stage.ResetTransformHandles();
            stage.InvalidateSelection();
        }
예제 #13
0
        public uint AddInstance(DesignInstance item)
        {
            bool isNew = false;
            if (item.InstanceHash == 0)
            {
                isNew = true;
                item.InstanceHash = instanceIdCounter++;
            }
            uint hash = item.InstanceHash;

            if (removedItems.ContainsKey(hash))
            {
                CancelRemove(hash);
            }
            else if (!items.ContainsKey(hash))
            {
                items.Add(hash, item);
                if (removedPaths.ContainsKey(hash)) // shouldn't be needed
                {
                    removedPaths.Remove(hash);
                }
            }
            else if (!isNew) // recycling id
            {
                items[hash] = item;
                if (removedPaths.ContainsKey(hash)) // shouldn't be needed
                {
                    removedPaths.Remove(hash);
                }
            }
            else
            {
                throw new ArgumentException("duplicate instance id");
            }

            item.LibraryItem.UseCount++;
            if (hash > instanceIdCounter)
            {
                instanceIdCounter = hash;
            }

            return hash;
        }
예제 #14
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();
        }
예제 #15
0
        public void AddRemoveTest()
        {
            DesignInstance si0 = dl.Add(lis[0].DefinitionId, new Point(10, 100));
            DesignInstance si1 = dl.Add(lis[1].DefinitionId, new Point(20, 200));
            DesignInstance si2 = dl.Add(lis[2].DefinitionId, new Point(30, 300));
            DesignInstance si3 = dl.Add(lis[2].DefinitionId, new Point(40, 400));

            Assert.AreEqual(4, dl.Count);
            dl.Remove(si2.InstanceHash);
            Assert.AreEqual(3, dl.Count);

            uint[] defIds = new uint[] { lis[0].DefinitionId, lis[1].DefinitionId, lis[2].DefinitionId };
            dl.AddRange(new uint[] { }, new Point[] {});
            uint[] instIds = dl.AddRange(defIds, new Point[] { Point.Empty, Point.Empty, Point.Empty });
            Assert.AreEqual(6, dl.Count);

            dl.RemoveInstancesById(instIds);
            dl.RemoveInstancesById(new uint[] { si0.InstanceHash });
            dl.RemoveInstancesById(new uint[] { si1.InstanceHash });
            dl.RemoveInstancesById(new uint[] { si3.InstanceHash });
            Assert.AreEqual(0, dl.Count);
        }
예제 #16
0
        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();
        }
예제 #17
0
        public void SelectionTest()
        {
            DesignInstance si0 = dl.Add(lis[0].DefinitionId, new Point(10, 100));
            DesignInstance si1 = dl.Add(lis[1].DefinitionId, new Point(20, 200));
            DesignInstance si2 = dl.Add(lis[2].DefinitionId, new Point(30, 300));
            DesignInstance si3 = dl.Add(lis[2].DefinitionId, new Point(40, 400));

            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { }, SelectionModifier.SetSelection));
            Assert.AreEqual(0, dl.Selected.Count);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { si0.InstanceHash }, SelectionModifier.SetSelection));
            Assert.AreEqual(1, dl.Selected.Count);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { si1.InstanceHash }, SelectionModifier.AddToSelection));
            Assert.AreEqual(2, dl.Selected.Count);
            // no dups
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { si1.InstanceHash }, SelectionModifier.AddToSelection));
            Assert.AreEqual(2, dl.Selected.Count);

            Assert.True(si0.IsSelected);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { si0.InstanceHash }, SelectionModifier.SubtractFromSelection));
            Assert.False(si0.IsSelected);
            Assert.AreEqual(1, dl.Selected.Count);

            Assert.True(si1.IsSelected);

            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] {}, SelectionModifier.SetSelection));
            Assert.False(si1.IsSelected);
            Assert.False(si2.IsSelected);
            Assert.AreEqual(0, dl.Selected.Count);

            // delete selections when instances are deleted
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(dl.InstanceIds, SelectionModifier.SetSelection));
            Assert.AreEqual(4, dl.Selected.Count);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { si0.InstanceHash }, SelectionModifier.SubtractFromSelection));
            Assert.AreEqual(3, dl.Selected.Count);
            MainForm.CurrentStage.CommandStack.Do(new SelectInstancesCommand(new uint[] { }, SelectionModifier.SetSelection));
            Assert.AreEqual(0, dl.Selected.Count);
        }
예제 #18
0
        public void RemoveInstance(DesignInstance inst)
        {
            PointF[] pts = (inst.IsRotated) ? inst.GetTransformedCenter() : inst.GetTransformedPoints().GetMidpointsAndCenter();

            uint hash    = inst.InstanceHash;
            bool success = true;

            for (int i = 0; i < pts.Length; i++)
            {
                bool successX = RemovePoint(xStops, pts[i].X, pts[i].Y, hash);
                bool successY = RemovePoint(yStops, pts[i].Y, pts[i].X, hash);
                if (!successX || !successY)
                {
                    success = false;
                    break;
                }
            }

            if (!success)
            {
                RemoveByIndex(xStops, hash);
                RemoveByIndex(yStops, hash);
            }
        }
예제 #19
0
 //public void AddUseCountById(uint id)
 //{
 //    if (items.ContainsKey(id))
 //    {
 //        items[id].LibraryItem.UseCount++;
 //    }
 //}
 public void RemoveInstance(DesignInstance item)
 {
     RemoveInstance(item.InstanceHash);
 }
예제 #20
0
        public bool LoadUIL(string folderPath)
        {
            bool result = false;

            List<string> dataPaths = new List<string>();
            List<string> types = new List<string>();

            string libFileName = folderPath + "Instances.xml";
            FileStream fs = new FileStream(libFileName, FileMode.Open);
            XmlTextReader r = new XmlTextReader(fs);
            r.WhitespaceHandling = WhitespaceHandling.None;
            r.ReadStartElement("Instances");

            do
            {
                if (r.IsStartElement())
                {
                    switch (r.Name)
                    {
                        case "InstanceIdCounter":
                            if (r.Read())
                            {
                                stage.InstanceManager.instanceIdCounter = uint.Parse(r.Value.Trim(), NumberStyles.Any);
                                r.Read();
                            }
                            break;

                        case "InstanceItems":
                            while (r.Read())
                            {
                                if (r.IsStartElement() && r.Name == "Item")
                                {
                                    dataPaths.Add(r.GetAttribute("DataPath"));
                                    types.Add(r.GetAttribute("Type"));
                                }
                            }
                            break;

                        default:
                            r.Read();
                            break;
                    }
                }
            }
            while (r.Read());

            r.Close();
            fs.Close();

            // read actual DesignInstance Items
            for (int i = 0; i < dataPaths.Count; i++)
            {
                string dp = folderPath + dataPaths[i];
                string type = types[i];
                DesignInstance.LoadFromPath(stage, type, dp);
            }

            hasSaveableChanges = false;

            return result;
        }
예제 #21
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();
        }
예제 #22
0
 public UsageIdentifier(DesignTimeline parent, DesignInstance instance, int depth)
 {
     Parent   = parent;
     Instance = instance;
     Depth    = depth;
 }
예제 #23
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();
        }