Пример #1
0
 public override void Execute()
 {
     using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(StringTable.UndoUnitMakeCompoundPath))
     {
         SceneElementSelectionSet elementSelectionSet = this.SceneViewModel.ElementSelectionSet;
         List <PathElement>       otherElements       = new List <PathElement>();
         foreach (SceneElement element in elementSelectionSet.Selection)
         {
             PathElement pathElement = element as PathElement;
             if (pathElement != null)
             {
                 otherElements.Add(pathElement);
             }
             else if (PathConversionHelper.CanConvert(element))
             {
                 otherElements.Add(PathCommandHelper.ConvertToPath((BaseFrameworkElement)element));
             }
         }
         editTransaction.Update();
         this.DesignerContext.ActiveView.UpdateLayout();
         otherElements.Sort((IComparer <PathElement>) new ZOrderComparer <PathElement>(this.SceneViewModel.RootNode));
         elementSelectionSet.Clear();
         PathElement                      mainElement        = otherElements[0];
         BaseFrameworkElement             frameworkElement   = (BaseFrameworkElement)otherElements[otherElements.Count - 1];
         ISceneNodeCollection <SceneNode> collectionForChild = frameworkElement.ParentElement.GetCollectionForChild((SceneNode)frameworkElement);
         int       num       = collectionForChild.IndexOf((SceneNode)frameworkElement);
         SceneNode sceneNode = num + 1 < collectionForChild.Count ? collectionForChild[num + 1] : (SceneNode)null;
         otherElements.RemoveAt(0);
         PathCommandHelper.MakeCompoundPath(mainElement, otherElements, editTransaction);
         mainElement.Remove();
         if (sceneNode == null)
         {
             collectionForChild.Add((SceneNode)mainElement);
         }
         else
         {
             collectionForChild.Insert(collectionForChild.IndexOf(sceneNode), (SceneNode)mainElement);
         }
         elementSelectionSet.SetSelection((SceneElement)mainElement);
         editTransaction.Commit();
     }
 }
Пример #2
0
        public static void ConvertSelectionToPathIfNeeded(SceneElementSelectionSet sceneSelectionSet, SceneElementFilter isConversionNeeded)
        {
            ReadOnlyCollection <SceneElement> selection = sceneSelectionSet.Selection;
            SceneElement primarySelection1 = sceneSelectionSet.PrimarySelection;
            SceneElement primarySelection2 = (SceneElement)null;

            sceneSelectionSet.Clear();
            List <SceneElement> list = new List <SceneElement>(selection.Count);

            foreach (SceneElement element in selection)
            {
                SceneElement sceneElement = element;
                if (isConversionNeeded(element))
                {
                    sceneElement = (SceneElement)PathCommandHelper.ConvertToPath((BaseFrameworkElement)element);
                }
                if (element == primarySelection1)
                {
                    primarySelection2 = sceneElement;
                }
                list.Add(sceneElement);
            }
            sceneSelectionSet.SetSelection((ICollection <SceneElement>)list, primarySelection2);
        }