Exemple #1
0
        public static List <PathElement> ReleaseCompoundPaths(PathElement pathElement, SceneEditTransaction editTransaction)
        {
            List <PathElement> list              = new List <PathElement>();
            PathGeometry       pathGeometry1     = pathElement.PathGeometry;
            Transform          geometryTransform = pathElement.GeometryTransform;
            ISceneNodeCollection <SceneNode> collectionContainer = pathElement.GetCollectionContainer();
            int num            = collectionContainer.IndexOf((SceneNode)pathElement);
            int oldFigureIndex = 0;

            foreach (PathFigure original in pathGeometry1.Figures)
            {
                PathFigure   pathFigure    = PathFigureUtilities.Copy(original, geometryTransform);
                PathGeometry pathGeometry2 = new PathGeometry();
                if (pathGeometry1.Transform != null && pathGeometry1.Transform.Value != Matrix.Identity)
                {
                    pathGeometry2.Transform = pathGeometry1.Transform.Clone();
                }
                if (pathGeometry2.FillRule != pathGeometry1.FillRule)
                {
                    pathGeometry2.FillRule = pathGeometry1.FillRule;
                }
                pathGeometry2.Figures.Add(pathFigure);
                DocumentNode node         = pathElement.DocumentNode.Clone(pathElement.DocumentContext);
                PathElement  pathElement1 = (PathElement)pathElement.ViewModel.GetSceneNode(node);
                collectionContainer.Insert(num++, (SceneNode)pathElement1);
                Rect extent = pathGeometry2.Bounds;
                extent = PathCommandHelper.InflateRectByStrokeWidth(extent, pathElement1, false);
                Vector vector = new Vector(-extent.Left, -extent.Top);
                PathCommandHelper.ReplacePathGeometry(pathElement1, pathGeometry2, editTransaction);
                Matrix transformToElement = pathElement.GetComputedTransformToElement((SceneElement)pathElement1);
                transformToElement.OffsetX += vector.X;
                transformToElement.OffsetY += vector.Y;
                PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(pathElement.Platform);
                PathCommandHelper.TransferPathFigureAnimations(pathElement, pathElement1, propertyReference, oldFigureIndex, 0, (Transform) new MatrixTransform(transformToElement));
                PathCommandHelper.AdjustPathForAnimations(pathElement1, editTransaction);
                list.Add(pathElement1);
                ++oldFigureIndex;
            }
            string name = pathElement.Name;

            pathElement.ViewModel.ElementSelectionSet.RemoveSelection((SceneElement)pathElement);
            pathElement.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)pathElement);
            pathElement.Remove();
            foreach (SceneNode sceneNode in list)
            {
                sceneNode.Name = name;
            }
            return(list);
        }
Exemple #2
0
        public static void MakeCompoundPath(PathElement mainElement, List <PathElement> otherElements, SceneEditTransaction editTransaction)
        {
            PathElement              pathElement       = otherElements[otherElements.Count - 1];
            ISceneElementCollection  elementCollection = (ISceneElementCollection) new SceneElementCollection();
            PathAnimationMovePackage animationMove     = new PathAnimationMovePackage();
            PathGeometry             pathGeometry      = new PathGeometry();

            System.Windows.Media.Geometry geometry1 = (System.Windows.Media.Geometry)mainElement.TransformedGeometry;
            pathGeometry.AddGeometry(geometry1);
            foreach (PathElement oldElement in otherElements)
            {
                System.Windows.Media.Geometry geometry2 = (System.Windows.Media.Geometry)oldElement.TransformedGeometry;
                Matrix    transformToElement            = oldElement.GetComputedTransformToElement((SceneElement)mainElement);
                bool      isIdentity = transformToElement.IsIdentity;
                Transform transform  = isIdentity ? Transform.Identity : (Transform) new MatrixTransform(transformToElement);
                transform.Freeze();
                if (!isIdentity)
                {
                    GeometryGroup geometryGroup = new GeometryGroup();
                    geometryGroup.Children.Add(geometry2);
                    geometryGroup.Transform = transform;
                    geometry2 = (System.Windows.Media.Geometry)geometryGroup;
                }
                int count = pathGeometry.Figures.Count;
                pathGeometry.AddGeometry(geometry2);
                int num = pathGeometry.Figures.Count - count;
                PropertyReference propertyReference = PathCommandHelper.GetPathDataPropertyReference(oldElement.Platform);
                for (int oldFigureIndex = 0; oldFigureIndex < num; ++oldFigureIndex)
                {
                    PathCommandHelper.TransferPathFigureAnimations(oldElement, mainElement, propertyReference, oldFigureIndex, count + oldFigureIndex, transform, animationMove);
                }
                elementCollection.Add((SceneElement)oldElement);
            }
            animationMove.Remove();
            Transform transform1 = PathCommandHelper.ReplacePathGeometry(mainElement, pathGeometry, editTransaction);

            animationMove.ApplyTransformToNewAnimations(transform1);
            animationMove.Add();
            PathCommandHelper.AdjustPathForAnimations(mainElement, editTransaction);
            foreach (SceneElement element in (IEnumerable <SceneElement>)elementCollection)
            {
                element.ViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
                element.ViewModel.RemoveElement((SceneNode)element);
            }
        }
Exemple #3
0
 public override void Execute()
 {
     using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(this.undoDescription))
     {
         this.ConvertSelectedElementsToPathIfNecessary();
         editTransaction.Update();
         this.SceneViewModel.DefaultView.UpdateLayout();
         SceneElementSelectionSet      elementSelectionSet   = this.SceneViewModel.ElementSelectionSet;
         SceneElement                  primarySelection      = elementSelectionSet.PrimarySelection;
         System.Windows.Media.Geometry renderedGeometryAsWpf = this.SceneView.GetRenderedGeometryAsWpf(primarySelection);
         if (renderedGeometryAsWpf == null)
         {
             return;
         }
         this.Initialize(renderedGeometryAsWpf);
         SceneElementCollection elementCollection = new SceneElementCollection();
         foreach (SceneElement shapeElement in elementSelectionSet.Selection)
         {
             if (shapeElement != primarySelection)
             {
                 elementCollection.Add(shapeElement);
                 System.Windows.Media.Geometry secondaryGeometry = this.SceneView.GetRenderedGeometryAsWpf(shapeElement);
                 if (secondaryGeometry == null)
                 {
                     return;
                 }
                 Matrix transformToElement = shapeElement.GetComputedTransformToElement(primarySelection);
                 if (!transformToElement.IsIdentity)
                 {
                     MatrixTransform matrixTransform = new MatrixTransform(transformToElement);
                     matrixTransform.Freeze();
                     GeometryGroup geometryGroup = new GeometryGroup();
                     geometryGroup.Children.Add(secondaryGeometry);
                     geometryGroup.Transform = (Transform)matrixTransform;
                     secondaryGeometry       = (System.Windows.Media.Geometry)geometryGroup;
                 }
                 this.Combine(secondaryGeometry);
             }
         }
         PathGeometry result = this.GetResult();
         BooleanCommand.CleanUpPathGeometry(ref result);
         PathGeometry pathGeometry = PathConversionHelper.RemoveDegeneratePoints((System.Windows.Media.Geometry)result);
         elementSelectionSet.Clear();
         PathGeometryUtilities.CollapseSingleSegmentsToPolySegments(pathGeometry);
         PathElement pathElement = (PathElement)this.SceneViewModel.CreateSceneNode(PlatformTypes.Path);
         Dictionary <IPropertyId, SceneNode> properties = (Dictionary <IPropertyId, SceneNode>)null;
         using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove())
         {
             this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(primarySelection);
             properties = SceneElementHelper.StoreProperties((SceneNode)primarySelection);
             ISceneNodeCollection <SceneNode> collectionContainer = primarySelection.GetCollectionContainer();
             int index = collectionContainer.IndexOf((SceneNode)primarySelection);
             collectionContainer[index] = (SceneNode)pathElement;
         }
         foreach (SceneElement element in elementCollection)
         {
             this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree(element);
             element.Remove();
         }
         using (this.SceneViewModel.ForceBaseValue())
         {
             if (properties != null)
             {
                 SceneElementHelper.ApplyProperties((SceneNode)pathElement, properties);
             }
             pathElement.SetValueAsWpf(ShapeElement.StretchProperty, (object)Stretch.Fill);
             PathCommandHelper.ReplacePathGeometry(pathElement, pathGeometry, editTransaction);
         }
         elementSelectionSet.SetSelection((SceneElement)pathElement);
         editTransaction.Commit();
     }
 }