private void ApplyRelativeTransformToElements(IEnumerable targetElements, PropertyReference reference, IApplyRelativeTransform transformModel) { foreach (SceneNode sceneNode in targetElements) { SceneElement sceneElement = sceneNode as SceneElement; if (sceneElement != null) { if (sceneElement is BaseFrameworkElement && sceneElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { sceneElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } object computedValueAsWpf = sceneElement.GetComputedValueAsWpf(reference); object obj = transformModel.ApplyRelativeTransform(computedValueAsWpf); CanonicalTransform canonicalTransform = obj as CanonicalTransform; if (canonicalTransform != (CanonicalTransform)null) { sceneElement.SetValue(reference, canonicalTransform.GetPlatformTransform(sceneElement.Platform.GeometryHelper)); } else { CanonicalTransform3D canonicalTransform3D = obj as CanonicalTransform3D; if (canonicalTransform3D != (CanonicalTransform3D)null) { sceneElement.SetValue(reference, (object)canonicalTransform3D.ToTransform()); } } } } }
protected void SetBrushTransform(CanonicalTransform transform) { this.EnsureEditTransaction(); transform.CenterX = RoundingHelper.RoundLength(transform.CenterX); transform.CenterY = RoundingHelper.RoundLength(transform.CenterY); transform.ScaleX = RoundingHelper.RoundScale(transform.ScaleX); transform.ScaleY = RoundingHelper.RoundScale(transform.ScaleY); transform.SkewX = RoundingHelper.RoundAngle(transform.SkewX); transform.SkewY = RoundingHelper.RoundAngle(transform.SkewY); transform.RotationAngle = RoundingHelper.RoundAngle(transform.RotationAngle); transform.TranslationX = RoundingHelper.RoundLength(transform.TranslationX); transform.TranslationY = RoundingHelper.RoundLength(transform.TranslationY); IProjectContext projectContext = this.ActiveDocument.ProjectContext; CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.GetBrushValue(BrushNode.RelativeTransformProperty)); if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterX, transform.CenterX) != 0 || JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterY, transform.CenterY) != 0) { this.SetBrushValue(BrushNode.RelativeTransformProperty, transform.GetPlatformTransform(this.RootNode.Platform.GeometryHelper)); } else { if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleX, transform.ScaleX) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleXReference, transform.ScaleX); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleY, transform.ScaleY) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleYReference, transform.ScaleY); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewX, transform.SkewX) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewXReference, transform.SkewX); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewY, transform.SkewY) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewYReference, transform.SkewY); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.RotationAngle, transform.RotationAngle) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushRotationAngleReference, transform.RotationAngle); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationX, transform.TranslationX) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationXReference, transform.TranslationX); } if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationY, transform.TranslationY) != 0) { this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationYReference, transform.TranslationY); } } this.UpdateEditTransaction(); }
protected void FlipElements(BasisComponent basisComponent, string description) { SceneElementSelectionSet elementSelectionSet = this.SceneViewModel.ElementSelectionSet; PropertyReference propertyReference = (PropertyReference)null; foreach (SceneElement sceneElement in elementSelectionSet.Selection) { if (sceneElement is BaseFrameworkElement || sceneElement is StyleNode) { propertyReference = new PropertyReference((ReferenceStep)sceneElement.ProjectContext.ResolveProperty(Base2DElement.RenderTransformProperty)); break; } if (sceneElement is Base3DElement) { propertyReference = new PropertyReference((ReferenceStep)sceneElement.ProjectContext.ResolveProperty((sceneElement as Base3DElement).TransformPropertyId)); break; } } if (propertyReference == null) { return; } using (SceneEditTransaction editTransaction = this.SceneViewModel.CreateEditTransaction(description)) { foreach (SceneElement sceneElement in elementSelectionSet.Selection) { object computedValueAsWpf = sceneElement.GetComputedValueAsWpf(propertyReference); object obj = new ReflectTransform(basisComponent).ApplyRelativeTransform(computedValueAsWpf); CanonicalTransform canonicalTransform = obj as CanonicalTransform; if (canonicalTransform != (CanonicalTransform)null) { sceneElement.SetValue(propertyReference, canonicalTransform.GetPlatformTransform(sceneElement.Platform.GeometryHelper)); if (sceneElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { sceneElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } } else { CanonicalTransform3D canonicalTransform3D = obj as CanonicalTransform3D; if (canonicalTransform3D != (CanonicalTransform3D)null) { sceneElement.SetValue(propertyReference, (object)canonicalTransform3D.ToTransform()); } } } editTransaction.Commit(); } }
private SceneNode[] Ungroup(SceneEditTransaction transaction, BaseFrameworkElement group) { SceneElement parentElement = group.ParentElement; if (parentElement == null) { return(new SceneNode[0]); } transaction.Update(); ILayoutDesigner designerForParent1 = this.SceneViewModel.GetLayoutDesignerForParent(parentElement, true); Rect childRect = designerForParent1.GetChildRect(group); Matrix effectiveRenderTransform = group.GetEffectiveRenderTransform(false); SceneNode[] array = new SceneNode[group.DefaultContent.Count]; group.DefaultContent.CopyTo(array, 0); using (this.SceneViewModel.DisableUpdateChildrenOnAddAndRemove()) { Transform[] transformArray = new Transform[array.Length]; Point[] pointArray = new Point[array.Length]; LayoutCacheRecord[] layoutCacheRecordArray = new LayoutCacheRecord[array.Length]; ILayoutDesigner designerForParent2 = group.ViewModel.GetLayoutDesignerForParent((SceneElement)group, true); for (int index = 0; index < array.Length; ++index) { BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement; if (frameworkElement != null) { transformArray[index] = (Transform)frameworkElement.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty); pointArray[index] = frameworkElement.RenderTransformOrigin; designerForParent2.GetChildRect(frameworkElement); LayoutCacheRecord layoutCacheRecord = designerForParent2.CacheLayout(frameworkElement); layoutCacheRecordArray[index] = layoutCacheRecord; } } int num1; if (array.Length == 1 && array[0] is BaseFrameworkElement) { int?fixedCapacity = group.DefaultContent.FixedCapacity; num1 = fixedCapacity.GetValueOrDefault() != 1 ? 0 : (fixedCapacity.HasValue ? true : false); } else { num1 = 0; } bool flag = num1 != 0; if (flag) { Dictionary <IPropertyId, SceneNode> properties = SceneElementHelper.StoreProperties((SceneNode)group, designerForParent1.GetLayoutProperties(), true); SceneElementHelper.FixElementNameBindingsInStoredProperties((SceneNode)group, array[0], properties); if (!SceneElementHelper.ApplyProperties(array[0], properties)) { flag = false; } } if (array.Length == 1 && array[0] is SceneElement) { VisualStateManagerSceneNode.MoveStates((SceneElement)group, (SceneElement)array[0]); } using (this.SceneViewModel.ForceBaseValue()) { SceneElement sceneElement = (SceneElement)null; for (int index = 0; index < array.Length; ++index) { BaseFrameworkElement frameworkElement = array[index] as BaseFrameworkElement; if (frameworkElement != null) { if (this.SceneViewModel.LockedInsertionPoint != null && this.SceneViewModel.LockedInsertionPoint.SceneElement == frameworkElement) { sceneElement = (SceneElement)frameworkElement; } DocumentNodeHelper.PreserveFormatting(frameworkElement.DocumentNode); frameworkElement.Remove(); } } ISceneNodeCollection <SceneNode> collectionContainer = group.GetCollectionContainer(); int index1 = collectionContainer.IndexOf((SceneNode)group); this.SceneViewModel.AnimationEditor.DeleteAllAnimationsInSubtree((SceneElement)group); this.SceneViewModel.RemoveElement((SceneNode)group); Matrix matrix1 = effectiveRenderTransform; matrix1.OffsetX = 0.0; matrix1.OffsetY = 0.0; for (int index2 = array.Length - 1; index2 >= 0; --index2) { BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement; if (frameworkElement != null) { Matrix matrix2 = (transformArray[index2] ?? Transform.Identity).Value; collectionContainer.Insert(index1, (SceneNode)frameworkElement); CanonicalTransform canonicalTransform = new CanonicalTransform((Transform) new MatrixTransform(matrix2 * matrix1)); if (frameworkElement.GetLocalValue(Base2DElement.RenderTransformProperty) != null || !canonicalTransform.TransformGroup.Value.IsIdentity) { frameworkElement.SetValue(Base2DElement.RenderTransformProperty, canonicalTransform.GetPlatformTransform(frameworkElement.Platform.GeometryHelper)); if (frameworkElement.IsSet(Base2DElement.RenderTransformOriginProperty) == PropertyState.Unset) { frameworkElement.SetValueAsWpf(Base2DElement.RenderTransformOriginProperty, (object)new Point(0.5, 0.5)); } } } } transaction.Update(); if (sceneElement != null) { this.SceneViewModel.SetLockedInsertionPoint(sceneElement); } bool[] flagArray = new bool[array.Length]; int length = 0; for (int index2 = 0; index2 < array.Length; ++index2) { BaseFrameworkElement frameworkElement = array[index2] as BaseFrameworkElement; if (frameworkElement != null && array[index2].Parent != null) { if (!flag) { LayoutCacheRecord layoutCacheRecord = layoutCacheRecordArray[index2]; Rect rect1 = layoutCacheRecord.Rect; Point point1 = new Point(rect1.X + rect1.Width * pointArray[index2].X, rect1.Y + rect1.Height * pointArray[index2].Y); Point point2 = effectiveRenderTransform.Transform(point1); Rect rect2 = new Rect(rect1.TopLeft + point2 - point1 + (Vector)childRect.TopLeft, rect1.Size); designerForParent1.ClearUnusedLayoutProperties(frameworkElement); designerForParent1.SetChildRect(frameworkElement, rect2, layoutCacheRecord.Overrides, LayoutOverrides.Margin | LayoutOverrides.GridBox, LayoutOverrides.None); } flagArray[index2] = true; ++length; } } SceneNode[] sceneNodeArray = new SceneNode[length]; int num2 = 0; for (int index2 = 0; index2 < array.Length; ++index2) { if (flagArray[index2]) { sceneNodeArray[num2++] = array[index2]; } } return(sceneNodeArray); } } }