Exemplo n.º 1
0
        protected override DocumentNode CreateValue(BaseFrameworkElement source)
        {
            ImageBrushNode imageBrush;

            this.newGeometryElement = GeometryCreationHelper3D.ConvertImageTo3D(this.DesignerContext.ActiveSceneViewModel, source, source.Name + "Model", out imageBrush);
            return(imageBrush.DocumentNode);
        }
Exemplo n.º 2
0
        protected virtual IList <SceneElement> AddToDocumentInternal(string importedFilePath, SceneElement element, ISceneInsertionPoint insertionPoint, SceneViewModel sceneViewModel, SceneEditTransaction undoTransaction)
        {
            List <SceneElement> list              = new List <SceneElement>();
            SceneElement        sceneElement      = insertionPoint.SceneElement;
            Viewport3DElement   viewport3Delement = sceneElement as Viewport3DElement;

            if (viewport3Delement != null || sceneElement is Base3DElement)
            {
                if (element.TargetType == typeof(Image))
                {
                    string[] strArray = importedFilePath.Split('.');
                    string   newName  = strArray.Length <= 1 || strArray[0] == null ? "Image" : strArray[0];
                    element = (SceneElement)GeometryCreationHelper3D.ConvertImageTo3D(sceneViewModel, (BaseFrameworkElement)element, newName);
                }
                IChildContainer3D childContainer3D = sceneElement as IChildContainer3D;
                if (ModelVisual3DElement.ContentProperty.Equals((object)insertionPoint.Property))
                {
                    element = (SceneElement)BaseElement3DCoercionHelper.CoerceToModel3D(sceneViewModel, element);
                    if (element != null)
                    {
                        list.Add(element);
                        insertionPoint.Insert((SceneNode)element);
                    }
                }
                else if (childContainer3D != null)
                {
                    Base3DElement child = (Base3DElement)element;
                    list.Add(childContainer3D.AddChild(sceneViewModel, child));
                    if (viewport3Delement != null && viewport3Delement.Camera == null)
                    {
                        ModelVisual3DElement modelVisual3Delement = element as ModelVisual3DElement;
                        Camera camera;
                        if (modelVisual3Delement != null)
                        {
                            Rect computedTightBounds = viewport3Delement.GetComputedTightBounds();
                            camera = Helper3D.CreateEnclosingPerspectiveCamera(45.0, computedTightBounds.Width / computedTightBounds.Height, modelVisual3Delement.DesignTimeBounds, 0.8);
                        }
                        else
                        {
                            camera = (Camera) new PerspectiveCamera(new Point3D(0.0, 0.0, -5.0), new Vector3D(0.0, 0.0, 1.0), new Vector3D(0.0, 1.0, 0.0), 45.0);
                        }
                        viewport3Delement.Camera = (CameraElement)sceneViewModel.CreateSceneNode((object)camera);
                    }
                }
            }
            else
            {
                ModelVisual3DElement modelVisual3D = element as ModelVisual3DElement;
                if (modelVisual3D != null)
                {
                    Viewport3DElement forModelVisual3D = GeometryCreationHelper3D.GetEnclosingViewportForModelVisual3D(sceneViewModel, modelVisual3D);
                    list.Add((SceneElement)forModelVisual3D);
                    insertionPoint.Insert((SceneNode)forModelVisual3D);
                }
                else if (insertionPoint.CanInsert((ITypeId)element.Type))
                {
                    list.Add(element);
                    insertionPoint.Insert((SceneNode)element);
                }
            }
            return((IList <SceneElement>)list);
        }
Exemplo n.º 3
0
        private static SceneElement PasteElement(SceneViewModel viewModel, SceneElement element, List <PasteCommand.DelayedElementTranslationInfo> elementsToTranslateLater, ISceneInsertionPoint insertionPoint)
        {
            SceneNodeIDHelper sceneNodeIdHelper = new SceneNodeIDHelper(viewModel, (SceneNode)insertionPoint.SceneNode.StoryboardContainer);
            SceneElement      element1          = (SceneElement)null;

            using (viewModel.ForceBaseValue())
            {
                PasteCommand.StripStoryboardsAndTriggers(element);
                PasteCommand.StripExtraNamespaces(element);
                BaseFrameworkElement frameworkElement = element as BaseFrameworkElement;
                if (frameworkElement != null || element is DataGridColumnNode)
                {
                    if (!(insertionPoint.SceneElement is Viewport3DElement) && !(insertionPoint.SceneElement is Base3DElement))
                    {
                        if (insertionPoint.CanInsert((ITypeId)element.Type))
                        {
                            if (!PlatformTypes.FrameworkTemplate.IsAssignableFrom((ITypeId)insertionPoint.SceneElement.Type) && (!PlatformTypes.UserControl.Equals((object)insertionPoint.SceneElement.Type) || insertionPoint.SceneElement.DocumentNode.DocumentRoot.RootNode != insertionPoint.SceneElement.DocumentNode))
                            {
                                if (element.Name != null)
                                {
                                    string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)element, element.Name);
                                    sceneNodeIdHelper.SetLocalName((SceneNode)element, validCopiedElementId);
                                }
                                sceneNodeIdHelper.FixNameConflicts((SceneNode)element);
                            }
                            if (viewModel.DesignerContext.PrototypingService != null)
                            {
                                viewModel.DesignerContext.PrototypingService.ProcessElementBeforeInsertion(insertionPoint, element);
                            }
                            insertionPoint.Insert((SceneNode)element);
                            if (element.GetLocalValue(DesignTimeProperties.LayoutRectProperty) != null && frameworkElement != null)
                            {
                                elementsToTranslateLater.Add(new PasteCommand.DelayedElementTranslationInfo(frameworkElement));
                            }
                            element1 = element;
                        }
                    }
                    else if (element.TargetType == typeof(Image))
                    {
                        GeometryModel3DElement geometryModel3Delement = GeometryCreationHelper3D.ConvertImageTo3D(viewModel, frameworkElement, element.Name);
                        IChildContainer3D      childContainer3D       = insertionPoint.SceneElement as IChildContainer3D;
                        if (childContainer3D != null)
                        {
                            childContainer3D.AddChild(viewModel, (Base3DElement)geometryModel3Delement);
                            element1 = (SceneElement)geometryModel3Delement;
                        }
                    }
                }
                else
                {
                    Base3DElement child;
                    if ((child = element as Base3DElement) != null)
                    {
                        if (child.Name != null)
                        {
                            string validCopiedElementId = sceneNodeIdHelper.GetValidCopiedElementID((SceneNode)child, child.Name);
                            sceneNodeIdHelper.SetLocalName((SceneNode)child, validCopiedElementId);
                        }
                        DependencyPropertyReferenceStep propertyReferenceStep = insertionPoint.Property as DependencyPropertyReferenceStep;
                        if (propertyReferenceStep != null && propertyReferenceStep.DependencyProperty == ModelVisual3D.ContentProperty)
                        {
                            Model3DElement model3Delement = BaseElement3DCoercionHelper.CoerceToModel3D(viewModel, (SceneElement)child);
                            if (model3Delement != null)
                            {
                                insertionPoint.Insert((SceneNode)model3Delement);
                                element1 = (SceneElement)model3Delement;
                            }
                        }
                        else
                        {
                            IChildContainer3D childContainer3D = insertionPoint.SceneElement as IChildContainer3D;
                            if (childContainer3D != null)
                            {
                                element1 = childContainer3D.AddChild(viewModel, child);
                            }
                        }
                    }
                }
                if (element1 != null)
                {
                    if (!(viewModel.ActiveEditingContainer is FrameworkTemplateElement))
                    {
                        PasteCommand.StripTemplateBindings(element1);
                    }
                }
            }
            return(element1);
        }