Ejemplo n.º 1
0
        internal void ProcessIndexExpressions()
        {
            var updateItems = SheetObject3D.SortAndLockUpdateItems(this, (item) =>
            {
                if (!SheetObject3D.HasExpressionWithString(item, "=", true))
                {
                    return(false);
                }

                // WIP
                if (item.Parent == this)
                {
                    // only process our children that are not the source object
                    return(!(item is OperationSourceObject3D));
                }
                else if (item.Parent is OperationSourceContainerObject3D)
                {
                    // If we find another source container
                    // Only process its children that are the source container (they will be replicated and modified correctly by the source container)
                    return(item is OperationSourceObject3D);
                }
                else if (item.Parent is OperationSourceObject3D operationSourceObject3D &&
                         operationSourceObject3D.Parent == this)
                {
                    // we don't need to rebuild our source object
                    return(false);
                }

                // process everything else
                return(true);
            });
Ejemplo n.º 2
0
        public override async void OnInvalidate(InvalidateArgs invalidateArgs)
        {
            additonalInvalidate = invalidateArgs.InvalidateType;

            if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Children) ||
                 invalidateArgs.InvalidateType.HasFlag(InvalidateType.Matrix) ||
                 invalidateArgs.InvalidateType.HasFlag(InvalidateType.Mesh)) &&
                invalidateArgs.Source != this &&
                !RebuildLocked)
            {
                await Rebuild();
            }
            else if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateArgs.Source == this))
            {
                await Rebuild();
            }
            else if (SheetObject3D.NeedsRebuild(this, invalidateArgs))
            {
                await Rebuild();
            }
            else if (invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) ||
                     invalidateArgs.InvalidateType.HasFlag(InvalidateType.Matrix) ||
                     invalidateArgs.InvalidateType.HasFlag(InvalidateType.Mesh) ||
                     invalidateArgs.InvalidateType.HasFlag(InvalidateType.Children))
            {
                base.OnInvalidate(invalidateArgs);
            }

            base.OnInvalidate(invalidateArgs);

            additonalInvalidate = InvalidateType.None;
        }
Ejemplo n.º 3
0
        public async Task TestSheetFunctions()
        {
            SetupEvnironment();
            var root = new Object3D();

            // Create the scene (a cube and a sheet)
            var cube1 = new CubeObject3D();

            root.Children.Add(cube1);
            var sheet = await SheetObject3D.Create();

            root.Children.Add(sheet);
            // set the sheet A1 to 33
            sheet.SheetData[0, 0].Expression = "=33";
            // rebuild cube without a reference to sheet
            cube1.Invalidate(InvalidateType.Properties);
            Assert.AreEqual(20, cube1.Width.Value(cube1), "cube1 should be the default 20mm");
            // set the cube width to the sheet value, but with a bad description (needs an equals to work)
            cube1.Width = "A1";
            cube1.Invalidate(InvalidateType.Properties);
            Assert.AreEqual(0, cube1.Width.Value(cube1), "Should be 0 as the reference is bad");
            // now fix the reference
            cube1.Width = "=A1";
            cube1.Invalidate(InvalidateType.Properties);
            Assert.AreEqual(33, cube1.Width.Value(cube1), "Should now be the value ad A1");
            // Change the sheet value
            sheet.SheetData[0, 0].Expression = "=43";
            sheet.SheetData.Recalculate();
            // and rebuild the references
            sheet.Invalidate(InvalidateType.SheetUpdated);
            Assert.AreEqual(43, cube1.Width.Value(cube1));
        }
Ejemplo n.º 4
0
        public override async Task Rebuild()
        {
            var rebuildLock = this.RebuildLock();

            SourceContainer.Visible = true;

            using (new CenterAndHeightMaintainer(this, CenterAndHeightMaintainer.MaintainFlags.Height))
            {
                await ApplicationController.Instance.Tasks.Execute(
                    "Linear Array".Localize(),
                    null,
                    (reporter, cancellationToken) =>
                {
                    this.DebugDepth("Rebuild");

                    var newChildren = new List <IObject3D>();

                    newChildren.Add(SourceContainer);

                    var arrayItem = SourceContainer.Children.First();

                    var distance = Distance.Value(this);
                    var count    = Count.Value(this);

                    // add in all the array items
                    for (int i = 0; i < Math.Max(count, 1); i++)
                    {
                        var next    = arrayItem.Clone();
                        next.Matrix = arrayItem.Matrix *Matrix4X4.CreateTranslation(Direction.Normal.GetNormal() * distance *i);
                        newChildren.Add(next);
                    }

                    Children.Modify(list =>
                    {
                        list.Clear();
                        list.AddRange(newChildren);
                    });

                    foreach (var child in Children)
                    {
                        if (SheetObject3D.HasParametersWithActiveFunctions(child))
                        {
                            // This really needs to be 'Has Perameters With index at this level'
                            // And is not the source object (only the copies should try to re-build (that might fix the recursion bug without the extra filtering)
                            //child.Invalidate(new InvalidateArgs(child, InvalidateType.Properties));
                        }
                    }

                    SourceContainer.Visible = false;
                    UiThread.RunOnIdle(() =>
                    {
                        rebuildLock.Dispose();
                        Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                    });
                    return(Task.CompletedTask);
                });
            }
        }
Ejemplo n.º 5
0
        public override void Flatten(Agg.UI.UndoBuffer undoBuffer)
        {
            // convert [index] expressions to their constant values
            foreach (var item in this.Descendants((item) => !(item is ArrayObject3D)))
            {
                foreach (var expression in SheetObject3D.GetActiveExpressions(item, "[index]", false))
                {
                    expression.Expression = expression.Expression.Replace("[index]", SheetObject3D.RetrieveArrayIndex(item, 0).ToString());
                }
            }

            // then call base flatten
            base.Flatten(undoBuffer);
        }
Ejemplo n.º 6
0
 public override void OnInvalidate(InvalidateArgs invalidateArgs)
 {
     if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Children) ||
          invalidateArgs.InvalidateType.HasFlag(InvalidateType.Matrix) ||
          invalidateArgs.InvalidateType.HasFlag(InvalidateType.Mesh)) &&
         invalidateArgs.Source != this &&
         !RebuildLocked)
     {
         Rebuild();
     }
     else if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateArgs.Source == this))
     {
         Rebuild();
     }
     else if (SheetObject3D.NeedsRebuild(this, invalidateArgs))
     {
         Rebuild();
     }
     else
     {
         base.OnInvalidate(invalidateArgs);
     }
 }
Ejemplo n.º 7
0
 public override async void OnInvalidate(InvalidateArgs invalidateArgs)
 {
     if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Children) ||
          invalidateArgs.InvalidateType.HasFlag(InvalidateType.Matrix) ||
          invalidateArgs.InvalidateType.HasFlag(InvalidateType.Mesh)) &&
         invalidateArgs.Source != this &&
         !RebuildLocked)
     {
         await Rebuild();
     }
     else if ((invalidateArgs.InvalidateType.HasFlag(InvalidateType.Properties) && invalidateArgs.Source == this))
     {
         await Rebuild();
     }
     else if (SheetObject3D.NeedsRebuild(this, invalidateArgs))
     {
         await Rebuild();
     }
     else
     {
         // and also always pass back the actual type
         base.OnInvalidate(invalidateArgs);
     }
 }
Ejemplo n.º 8
0
        public override void Load()
        {
            var library = ApplicationController.Instance.Library;

            long index        = DateTime.Now.Ticks;
            var  libraryItems = new List <GeneratorItem>()
            {
                new GeneratorItem(
                    () => "Cube".Localize(),
                    async() => await CubeObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Pyramid".Localize(),
                    async() => await PyramidObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Wedge".Localize(),
                    async() => await WedgeObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Half Wedge".Localize(),
                    async() => await HalfWedgeObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Text".Localize(),
                    async() => await TextObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Cylinder".Localize(),
                    async() => await CylinderObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Cone".Localize(),
                    async() => await ConeObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Half Cylinder".Localize(),
                    async() => await HalfCylinderObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Torus".Localize(),
                    async() => await TorusObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Ring".Localize(),
                    async() => await RingObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Sphere".Localize(),
                    async() => await SphereObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Half Sphere".Localize(),
                    async() => await HalfSphereObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
#if DEBUG
                new GeneratorItem(
                    () => "SCAD Script".Localize(),
                    async() => await OpenScadScriptObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "MarchingSquares".Localize(),
                    async() => await MarchingSquaresObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
#endif
                new GeneratorItem(
                    () => "Image Converter".Localize(),
                    () =>
                {
                    // Construct an image
                    var imageObject = new ImageObject3D()
                    {
                        AssetPath = StaticData.Instance.ToAssetPath(Path.Combine("Images", "mh-logo.png"))
                    };

                    // Construct a scene
                    var bedConfig = new BedConfig(null);
                    var tempScene = bedConfig.Scene;
                    tempScene.Children.Add(imageObject);
                    tempScene.SelectedItem = imageObject;

                    // Invoke ImageConverter operation, passing image and scene
                    SceneOperations.ById("ImageConverter").Action(bedConfig);

                    // Return replacement object constructed in ImageConverter operation
                    var constructedComponent = tempScene.SelectedItem;
                    tempScene.Children.Remove(constructedComponent);

                    return(Task.FromResult(constructedComponent));
                })
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Measure Tool".Localize(),
                    async() => await MeasureToolObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Description".Localize(),
                    async() => await DescriptionObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
                new GeneratorItem(
                    () => "Variable Sheet".Localize(),
                    async() => await SheetObject3D.Create())
                {
                    DateCreated = new DateTime(index++)
                },
            };

            string title = "Primitive Shapes".Localize();

            foreach (var item in libraryItems)
            {
                item.Category = title;
                Items.Add(item);
            }

            this.ChildContainers.Add(
                new DynamicContainerLink(
                    () => "Primitives 2D".Localize(),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "folder.png")),
                    StaticData.Instance.LoadIcon(Path.Combine("Library", "primitives_library_icon.png")),
                    () => new Primitives2DContainer())
            {
                IsReadOnly = true
            });
        }