void loadMatterScript_Click(object sender, EventArgs mouseEvent)
        {
            OpenFileDialogParams openParams = new OpenFileDialogParams("MatterScript Files, c-sharp code|*.part;*.cs");

            FileDialog.OpenFileDialog(openParams, (streamToLoadFrom) =>
            {
                if (streamToLoadFrom != null)
                {
                    SuspendLayout();
                    var loadedFileName = openParams.FileName;
                    string extension   = Path.GetExtension(openParams.FileName).ToUpper(CultureInfo.InvariantCulture);

                    string text = File.ReadAllText(loadedFileName);

                    StreamReader streamReader = new StreamReader(streamToLoadFrom.FileName);
                    textEdit.Text             = streamReader.ReadToEnd();
                    streamReader.Close();

                    varticalSplitter.SplitterDistance = varticalSplitter.SplitterDistance - 1;
                    varticalSplitter.SplitterDistance = varticalSplitter.SplitterDistance + 1;

                    ResumeLayout();
                    AnchorAll();
                    varticalSplitter.AnchorAll();
                    textSide.AnchorAll();
                    objectEditorView.Invalidate();
                    textSide.PerformLayout();
                    trackBallWidget.AnchorAll();
                    Invalidate();
                }
            });
        }
        public MainWindow() : base(1000, 1000)
        {
            //new BoxPrimitive(8, 20, 10);
            //rootUnion.Add(new Translate(new BoxPrimitive(10, 10, 20), 5, 10, 5));
            //rootUnion.Add(new Box(8, 20, 10));
            ////rootUnion.Add(new Cylinder(10, 40));
            //rootUnion.Add(new Translate(new Sphere(radius: 30), 15, 20, 40)); //not implemented
            //var testUnion = new Translate(new Box(10, 10, 20) - new Box(8, 20, 10), 5, 5, 5); //new Difference(
            //rootUnion.Add(new LinearExtrude(new double[] { 1.1, 2.2, 3.3, 6.3 }, 7)); //not implemented
            //rootUnion.Add(testUnion);
            //rootUnion.Box(8, 20, 40);

            SuspendLayout();
            varticalSplitter = new Splitter();
            varticalSplitter.SplitterDistance = 700;
            // panel 1 stuff
            #region TextSide
            textSide = new FlowLayoutWidget(FlowDirection.TopToBottom);

            objectEditorView = new GuiWidget();
            objectEditorList = new FlowLayoutWidget();
            objectEditorList.AddChild(new TextEditWidget("Text in box"));

            objectEditorView.AddChild(objectEditorList);
            objectEditorView.BackgroundColor = RGBA_Bytes.LightGray;
            //matterScriptEditor.LocalBounds = new RectangleDouble(0, 0, 200, 300);
            textSide.AddChild(objectEditorView);
            var code = new StringBuilder();
            code.AppendLine("var rootUnion = new MatterHackers.Csg.Operations.Union(\"root\");");
            code.AppendLine("//rootUnion.Add(new LinearExtrude(new double[] { 1.1, 2.2, 3.3, 6.3 }, 7));");
            code.AppendLine("rootUnion.Add(new Translate(new Cylinder(10, 40), 5, 10, 5));");
            code.AppendLine("rootUnion.Add(new BoxPrimitive(8, 20, 10));");

            code.AppendLine("for (int i = 0; i != 10; i++)");
            code.AppendLine("{");
            code.AppendLine("   rootUnion.Add(new Translate(new BoxPrimitive(18, i, 14), 10 * i, 10+i, 10+i*i));");
            code.AppendLine("}");

            code.AppendLine("return rootUnion;");

            //code.AppendLine("MatterHackers.PolygonMesh.Mesh mesh = new MatterHackers.PolygonMesh.Mesh();");
            //code.AppendLine("var v0 = mesh.CreateVertex(new Vector3(1, 0, 1));  // V0");
            //code.AppendLine("var v1 = mesh.CreateVertex(new Vector3(1, 0, -1)); // V1");
            //code.AppendLine("var v2 = mesh.CreateVertex(new Vector3(-1, 0, -1)); // V2");
            //code.AppendLine("var v3 = mesh.CreateVertex(new Vector3(-1, 0, 1)); // V3");
            //code.AppendLine("var v4 = mesh.CreateVertex(new Vector3(0, 1, 0)); // V4");

            //code.AppendLine("mesh.CreateFace(new Vertex[] { v0, v1, v2, v3 });");
            //code.AppendLine("mesh.CreateFace(new Vertex[] { v3, v0, v4 });");
            //code.AppendLine("mesh.CreateFace(new Vertex[] { v0, v1, v4 });");
            //code.AppendLine("mesh.CreateFace(new Vertex[] { v1, v2, v4 });");
            //code.AppendLine("mesh.CreateFace(new Vertex[] { v2, v3, v4 });");

            //code.AppendLine("RenderMeshToGl.Render(mesh, new RGBA_Floats(.3, .8, 7)); ");
            textEdit = new TextEditWidget(code.ToString().Replace('\r', '\n'));
            //   textEdit.BackgroundColor = RGBA_Bytes.Yellow;
            textEdit.TextChanged += Hello_TextChanged;
            textEdit.Multiline    = true;
            //     hello.Text = code.ToString();
            textSide.AddChild(textEdit);

            outputEdit = new TextEditWidget("Hello world!")
            {
                Multiline = true
            };
            outputEdit.AnchorAll();
            textSide.AddChild(outputEdit);
            textSide.AnchorAll();
            textEdit.AnchorAll();
            objectEditorList.AnchorAll();
            textSide.BoundsChanged += textSide_BoundsChanged;

            #region Buttons
            FlowLayoutWidget topButtonBar = new FlowLayoutWidget();

            Button load = new Button("Load OpenSharpCAD Script");
            load.Click += loadMatterScript_Click;
            topButtonBar.AddChild(load);
            Button save = new Button("Save OpenSharpCAD Script");
            save.Click += SaveMatterScript_Click;
            topButtonBar.AddChild(save);

            outputScad        = new Button("Output SCAD");
            outputScad.Click += outputScad_Click;
            topButtonBar.AddChild(outputScad);

            textSide.AddChild(topButtonBar);

            FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();

            //Button loadStl = new Button("Load STL");
            //loadStl.Click += LoadStl_Click;
            //bottomButtonBar.AddChild(loadStl);

            textSide.AddChild(bottomButtonBar);

            #endregion
            #endregion

            // pannel 2 stuff
            FlowLayoutWidget renderSide = new FlowLayoutWidget(FlowDirection.TopToBottom);
            renderSide.AnchorAll();

            trackBallWidget = new TrackballTumbleWidget();
            trackBallWidget.DrawGlContent += glLightedView_DrawGlContent;

            trackBallWidget.TrackBallController.Scale = 0.05;

            renderSide.AddChild(trackBallWidget);

            varticalSplitter.Panel2.AddChild(renderSide);
            varticalSplitter.Panel1.AddChild(textSide);

            ResumeLayout();

            AnchorAll();

            varticalSplitter.AnchorAll();

            textSide.AnchorAll();

            trackBallWidget.AnchorAll();

            AddChild(varticalSplitter);

            BackgroundColor = RGBA_Bytes.White;
            Compile();
        }
예제 #3
0
        public LibraryWidget(MainViewWidget mainViewWidget, ThemeConfig theme)
        {
            this.theme          = theme;
            this.mainViewWidget = mainViewWidget;
            this.Padding        = 0;
            this.AnchorAll();

            var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            libraryContext = ApplicationController.Instance.LibraryTabContext;

            libraryView = new LibraryListView(libraryContext, theme)
            {
                Name = "LibraryView",
                // Drop containers if ShowContainers != 1
                ContainerFilter   = (container) => this.ShowContainers,
                BackgroundColor   = theme.BackgroundColor,
                Border            = new BorderDouble(top: 1),
                DoubleClickAction = LibraryListView.DoubleClickActions.PreviewItem
            };

            navBar = new OverflowBar(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };
            theme.ApplyBottomBorder(navBar);

            breadCrumbWidget = new FolderBreadCrumbWidget(libraryContext, theme);
            navBar.AddChild(breadCrumbWidget);

            var searchPanel = new TextEditWithInlineCancel(theme)
            {
                Visible = false,
                Margin  = new BorderDouble(10, 0, 5, 0),
            };

            searchPanel.TextEditWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                this.PerformSearch();
            };
            searchPanel.ResetButton.Click += (s, e) =>
            {
                breadCrumbWidget.Visible = true;
                searchPanel.Visible      = false;

                searchPanel.TextEditWidget.Text = "";

                this.ClearSearch();
            };

            // Store a reference to the input field
            this.searchInput = searchPanel.TextEditWidget;

            navBar.AddChild(searchPanel);

            searchButton         = theme.CreateSearchButton();
            searchButton.Enabled = false;
            searchButton.Name    = "Search Library Button";
            searchButton.Click  += (s, e) =>
            {
                if (searchPanel.Visible)
                {
                    PerformSearch();
                }
                else
                {
                    searchContainer = libraryContext.ActiveContainer;

                    breadCrumbWidget.Visible = false;
                    searchPanel.Visible      = true;
                    searchInput.Focus();
                }
            };
            navBar.AddChild(searchButton);

            navBar.AddChild(CreateViewOptionsMenuButton(theme, libraryView, (show) => ShowContainers = show, () => ShowContainers));

            navBar.AddChild(CreateSortingMenuButton(theme, libraryView));

            allControls.AddChild(navBar);

            var horizontalSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };

            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = horizontalSplitter.SplitterDistance;
            };

            allControls.AddChild(horizontalSplitter);

            libraryTreeView = new TreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Margin  = 5
            };
            libraryTreeView.AfterSelect += async(s, e) =>
            {
                if (libraryTreeView.SelectedNode is ContainerTreeNode treeNode)
                {
                    if (!treeNode.ContainerAcquired)
                    {
                        await this.EnsureExpanded(treeNode.Tag as ILibraryItem, treeNode);
                    }

                    if (treeNode.ContainerAcquired)
                    {
                        libraryContext.ActiveContainer = treeNode.Container;
                    }
                }
            };
            horizontalSplitter.Panel1.AddChild(libraryTreeView);

            var rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Margin  = new BorderDouble(left: 10)
            };

            libraryTreeView.AddChild(rootColumn);

            if (AppContext.IsLoading)
            {
                ApplicationController.StartupActions.Add(new ApplicationController.StartupAction()
                {
                    Title    = "Initializing Library".Localize(),
                    Priority = 0,
                    Action   = () =>
                    {
                        this.LoadRootLibraryNodes(rootColumn);
                    }
                });
            }
            else
            {
                this.LoadRootLibraryNodes(rootColumn);
            }

            horizontalSplitter.Panel2.AddChild(libraryView);

            buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Padding = theme.ToolbarPadding,
            };
            AddLibraryButtonElements();
            allControls.AddChild(buttonPanel);

            allControls.AnchorAll();

            this.AddChild(allControls);

            // Register listeners
            libraryView.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
            libraryContext.ContainerChanged             += Library_ContainerChanged;
        }
예제 #4
0
        public SearchableTreePanel(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.theme      = theme;
            this.TreeLoaded = false;

            var searchIcon = StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16).SetToColor(theme.TextColor).AjustAlpha(0.3);

            searchBox = new TextEditWithInlineCancel(theme)
            {
                Name    = "Search",
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(6),
            };

            searchBox.ResetButton.Visible = false;

            var searchInput = searchBox.TextEditWidget;

            searchInput.BeforeDraw += (s, e) =>
            {
                if (!searchBox.ResetButton.Visible)
                {
                    e.Graphics2D.Render(
                        searchIcon,
                        searchInput.Width - searchIcon.Width - 5,
                        searchInput.LocalBounds.Bottom + searchInput.Height / 2 - searchIcon.Height / 2);
                }
            };

            searchBox.ResetButton.Click += (s, e) =>
            {
                this.ClearSearch();
            };

            searchBox.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    this.ClearSearch();
                    e.Handled = true;
                }
            };

            searchBox.TextEditWidget.ActualTextEditWidget.TextChanged += (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(searchBox.Text))
                {
                    this.ClearSearch();
                }
                else
                {
                    this.PerformSearch(searchBox.Text);
                }
            };

            horizontalSplitter = new Splitter()
            {
                SplitterDistance   = Math.Max(UserSettings.Instance.LibraryViewWidth, 20),
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };
            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = Math.Max(horizontalSplitter.SplitterDistance, 20);
            };

            this.AddChild(horizontalSplitter);

            var leftPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            leftPanel.AddChild(searchBox);

            treeView = new TreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };
            leftPanel.AddChild(treeView);

            horizontalSplitter.Panel1.AddChild(leftPanel);

            contentPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Margin  = new BorderDouble(left: 2)
            };
            treeView.AddChild(contentPanel);
        }
예제 #5
0
        public LibraryWidget(MainViewWidget mainViewWidget, ThemeConfig theme)
        {
            this.theme          = theme;
            this.mainViewWidget = mainViewWidget;
            this.Padding        = 0;
            this.AnchorAll();

            var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            libraryContext = ApplicationController.Instance.LibraryTabContext;

            libraryView = new LibraryListView(libraryContext, theme)
            {
                Name = "LibraryView",
                // Drop containers if ShowContainers != 1
                ContainerFilter   = (container) => UserSettings.Instance.ShowContainers,
                BackgroundColor   = theme.BackgroundColor,
                Border            = new BorderDouble(top: 1),
                DoubleClickAction = LibraryListView.DoubleClickActions.PreviewItem
            };

            navBar = new OverflowBar(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };
            allControls.AddChild(navBar);
            theme.ApplyBottomBorder(navBar);

            breadCrumbWidget = new FolderBreadCrumbWidget(libraryContext, theme);
            navBar.AddChild(breadCrumbWidget);

            var searchPanel = new SearchInputBox(theme)
            {
                Visible = false,
                Margin  = new BorderDouble(10, 0, 5, 0),
            };

            searchPanel.searchInput.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                this.PerformSearch();
            };
            searchPanel.ResetButton.Click += (s, e) =>
            {
                breadCrumbWidget.Visible = true;
                searchPanel.Visible      = false;

                searchPanel.searchInput.Text = "";

                this.ClearSearch();
            };

            // Store a reference to the input field
            this.searchInput = searchPanel.searchInput;

            navBar.AddChild(searchPanel);

            searchButton         = theme.CreateSearchButton();
            searchButton.Enabled = false;
            searchButton.Name    = "Search Library Button";
            searchButton.Click  += (s, e) =>
            {
                if (searchPanel.Visible)
                {
                    PerformSearch();
                }
                else
                {
                    searchContainer = libraryContext.ActiveContainer;

                    breadCrumbWidget.Visible = false;
                    searchPanel.Visible      = true;
                    searchInput.Focus();
                }
            };
            navBar.AddChild(searchButton);

            PopupMenuButton viewOptionsButton;

            navBar.AddChild(
                viewOptionsButton = new PopupMenuButton(
                    new ImageWidget(AggContext.StaticData.LoadIcon("fa-sort_16.png", 32, 32, theme.InvertIcons))
            {
                //VAnchor = VAnchor.Center
            },
                    theme)
            {
                AlignToRightEdge = true,
                Name             = "Print Library View Options"
            });

            viewOptionsButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Date Created".Localize(),
                    () => libraryView.ActiveSort.HasFlag(SortKey.CreatedDate),
                    (v) => libraryView.ActiveSort = SortKey.CreatedDate,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Date Modified".Localize(),
                    () => libraryView.ActiveSort.HasFlag(SortKey.ModifiedDate),
                    (v) => libraryView.ActiveSort = SortKey.ModifiedDate,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Name".Localize(),
                    () => libraryView.ActiveSort.HasFlag(SortKey.Name),
                    (v) => libraryView.ActiveSort = SortKey.Name,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateSeparator();

                siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Ascending".Localize(),
                    () => libraryView.Ascending,
                    (v) => libraryView.Ascending = true,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Descending".Localize(),
                    () => !libraryView.Ascending,
                    (v) => libraryView.Ascending = false,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                return(popupMenu);
            };

            PopupMenuButton viewMenuButton;

            navBar.AddChild(
                viewMenuButton = new PopupMenuButton(
                    new ImageWidget(AggContext.StaticData.LoadIcon("mi-view-list_10.png", 32, 32, theme.InvertIcons))
            {
                //VAnchor = VAnchor.Center
            },
                    theme)
            {
                AlignToRightEdge = true
            });

            viewMenuButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var listView = this.libraryView;

                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "View List".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.RowListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.RowListView;
                    listView.ListContentView = new RowListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#if DEBUG
                popupMenu.CreateBoolMenuItem(
                    "View XSmall Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView18,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView18;
                    listView.ListContentView = new IconListView(theme, 18);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Small Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView70,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView70;
                    listView.ListContentView = new IconListView(theme, 70);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#endif
                popupMenu.CreateBoolMenuItem(
                    "View Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView;
                    listView.ListContentView = new IconListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Large Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView256,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView256;
                    listView.ListContentView = new IconListView(theme, 256);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                return(popupMenu);
            };

            var horizontalSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };
            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = horizontalSplitter.SplitterDistance;
            };

            allControls.AddChild(horizontalSplitter);

            libraryTreeView = new TreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Margin  = 5
            };
            libraryTreeView.AfterSelect += async(s, e) =>
            {
                if (libraryTreeView.SelectedNode is ContainerTreeNode treeNode)
                {
                    if (!treeNode.ContainerAcquired)
                    {
                        await this.EnsureExpanded(treeNode.Tag as ILibraryItem, treeNode);
                    }

                    if (treeNode.ContainerAcquired)
                    {
                        libraryContext.ActiveContainer = treeNode.Container;
                    }
                }
            };
            horizontalSplitter.Panel1.AddChild(libraryTreeView);

            var rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Margin  = new BorderDouble(left: 10)
            };
            libraryTreeView.AddChild(rootColumn);

            if (AppContext.IsLoading)
            {
                ApplicationController.StartupActions.Add(new ApplicationController.StartupAction()
                {
                    Title    = "Initializing Library".Localize(),
                    Priority = 0,
                    Action   = () =>
                    {
                        this.LoadRootLibraryNodes(rootColumn);
                    }
                });
            }
            else
            {
                this.LoadRootLibraryNodes(rootColumn);
            }

            horizontalSplitter.Panel2.AddChild(libraryView);

            buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Padding = theme.ToolbarPadding,
            };
            AddLibraryButtonElements();
            allControls.AddChild(buttonPanel);

            allControls.AnchorAll();

            this.AddChild(allControls);

            // Register listeners
            libraryView.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
            libraryContext.ContainerChanged             += Library_ContainerChanged;
        }
        public MatterCadGuiWidget()
        {
            //rootUnion.Add(DemoProjects.PowerSupply()); //works but cutout is not working
            rootUnion.Add(SimplePartTester.Assembly());
            //rootUnion.Add(new BoxPrimitive(8, 20, 10));

            //rootUnion.Add(new LinearExtrude(new double[] { 1.1, 2.2, 3.3, 6.3 }, 7));
            //rootUnion.Add(
            //    new Difference (new Translate(new Cylinder(10, 40), 5, 10, 5), new Translate(new BoxPrimitive(10, 10, 20,"test",true), 5, 20, 5)));
            SuspendLayout();
            verticleSpliter = new Splitter();

            // pannel 1 stuff
            textSide = new FlowLayoutWidget(FlowDirection.TopToBottom);

            objectEditorView = new GuiWidget(300, 500);
            objectEditorList = new FlowLayoutWidget();

            textEdit         = new TextEditWidget("test", 300, 400);
            textEdit.HAnchor = HAnchor.ParentLeftRight;
            //     textEdit.MinimumSize = new Vector2(Math.Max(textEdit.MinimumSize.x, pixelWidth), Math.Max(textEdit.MinimumSize.y, pixelHeight));
            textEdit.VAnchor         = VAnchor.ParentBottomTop;
            textEdit.Multiline       = true;
            textEdit.BackgroundColor = RGBA_Bytes.Yellow;

            // objectEditorList.AddChild(textEdit);//CsgEditorBase.CreateEditorForCsg(rootUnion));
            //   objectEditorView.AddChild(objectEditorList);
            //    objectEditorView.BackgroundColor = RGBA_Bytes.Orange;
            //     objectEditorView.Text = "Hello World!";
            objectEditorView.LocalBounds = new RectangleDouble(0, 0, 200, 300);
            textSide.LocalBounds         = new RectangleDouble(0, 0, 200, 300);
            //      objectEditorView.DebugShowBounds = true;
            textSide.AddChild(textEdit);
            textSide.BoundsChanged += new EventHandler(textSide_BoundsChanged);

            FlowLayoutWidget topButtonBar = new FlowLayoutWidget();

            Button loadMatterScript = new Button("Load Matter Script");

            loadMatterScript.Click += loadMatterScript_Click;
            topButtonBar.AddChild(loadMatterScript);

            outputScad        = new Button("Output SCAD");
            outputScad.Click += OutputScad_Click;
            topButtonBar.AddChild(outputScad);

            textSide.AddChild(topButtonBar);

            FlowLayoutWidget bottomButtonBar = new FlowLayoutWidget();

            Button loadStl = new Button("Load STL");

            loadStl.Click += LoadStl_Click;
            bottomButtonBar.AddChild(loadStl);

            textSide.AddChild(bottomButtonBar);

            //    // pannel 2 stuff
            FlowLayoutWidget renderSide = new FlowLayoutWidget(FlowDirection.TopToBottom);

            renderSide.AnchorAll();

            trackBallWidget = new TrackballTumbleWidget();
            trackBallWidget.DrawGlContent += new EventHandler(glLightedView_DrawGlContent);
            renderSide.AddChild(trackBallWidget);

            verticleSpliter.Panel2.AddChild(renderSide);
            verticleSpliter.Panel1.AddChild(textSide);


            ResumeLayout();
            objectEditorView.AnchorAll();
            AnchorAll();
            verticleSpliter.AnchorAll();
            textSide.AnchorAll();
            trackBallWidget.AnchorAll();
            AddChild(verticleSpliter);
            BackgroundColor = RGBA_Bytes.White;
        }
예제 #7
0
        public override void Initialize()
        {
            base.Initialize();

            this.AnchorAll();
            this.Name            = "WidescreenPanel";
            this.BackgroundColor = theme.Colors.PrimaryBackgroundColor;

            // Push TouchScreenMode into GuiWidget
            GuiWidget.TouchScreenMode = UserSettings.Instance.IsTouchScreen;

            var library3DViewSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };

            library3DViewSplitter.AnchorAll();

            library3DViewSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = library3DViewSplitter.SplitterDistance;
            };

            this.AddChild(library3DViewSplitter);

            // put in the right column
            var partPreviewContent = new PartPreviewContent(theme)
            {
                VAnchor = VAnchor.Bottom | VAnchor.Top,
                HAnchor = HAnchor.Left | HAnchor.Right
            };

            library3DViewSplitter.Panel2.AddChild(partPreviewContent);

            // put in the left column
            var leftNav = new FlowLayoutWidget(FlowDirection.TopToBottom);

            using (leftNav.LayoutLock())
            {
                leftNav.AddChild(new BrandMenuButton(theme)
                {
                    HAnchor         = HAnchor.Stretch,
                    VAnchor         = VAnchor.Fit,
                    BackgroundColor = theme.TabBarBackground,
                    Border          = new BorderDouble(right: 1),
                    BorderColor     = theme.MinimalShade,
                    Padding         = theme.TabbarPadding.Clone(right: 0)
                });

                leftNav.AddChild(new PrintLibraryWidget(partPreviewContent, theme)
                {
                    BackgroundColor = theme.ActiveTabColor
                });
            }

            leftNav.AnchorAll();

            library3DViewSplitter.Panel1.AddChild(leftNav);
        }
예제 #8
0
        public HardwareTabPage(ThemeConfig theme)
        {
            this.theme   = theme;
            this.Padding = 0;
            this.AnchorAll();

            var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            var horizontalSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };

            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = horizontalSplitter.SplitterDistance;
            };

            allControls.AddChild(horizontalSplitter);

            treeView = new InventoryTreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Width   = 300,
                Margin  = 5
            };

            treeView.NodeMouseDoubleClick += (s, e) =>
            {
                if (e is MouseEventArgs mouseEvent &&
                    s is GuiWidget clickedWidget &&
                    mouseEvent.Button == MouseButtons.Left &&
                    mouseEvent.Clicks == 2)
                {
                    if (treeView?.SelectedNode.Tag is PrinterInfo printerInfo)
                    {
                        // Open printer
                        PrinterDetails.SwitchPrinters(printerInfo.ID);
                    }
                }
            };

            treeView.NodeMouseClick += (s, e) =>
            {
                if (e is MouseEventArgs mouseEvent &&
                    s is GuiWidget clickedWidget &&
                    mouseEvent.Button == MouseButtons.Right)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        var menu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                        var openMenuItem    = menu.CreateMenuItem("Open".Localize());
                        openMenuItem.Click += (s2, e2) =>
                        {
                            if (treeView?.SelectedNode.Tag is PrinterInfo printerInfo)
                            {
                                // Open printer
                                PrinterDetails.SwitchPrinters(printerInfo.ID);
                            }
                        };

                        menu.CreateHorizontalLine();

                        var deleteMenuItem    = menu.CreateMenuItem("Delete".Localize());
                        deleteMenuItem.Click += (s2, e2) =>
                        {
                            // Delete printer
                            StyledMessageBox.ShowMessageBox(
                                (deletePrinter) =>
                            {
                                if (deletePrinter)
                                {
                                    if (treeView.SelectedNode.Tag is PrinterInfo printerInfo)
                                    {
                                        ProfileManager.Instance.DeletePrinter(printerInfo.ID, true);
                                    }
                                }
                            },
                                "Are you sure you want to delete your currently selected printer?".Localize(),
                                "Delete Printer?".Localize(),
                                StyledMessageBox.MessageType.YES_NO,
                                "Delete Printer".Localize());
                        };


                        var systemWindow = this.Parents <SystemWindow>().FirstOrDefault();
                        systemWindow.ShowPopup(
                            new MatePoint(clickedWidget)
                        {
                            Mate    = new MateOptions(MateEdge.Left, MateEdge.Top),
                            AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
                        },
                            new MatePoint(menu)
                        {
                            Mate    = new MateOptions(MateEdge.Left, MateEdge.Top),
                            AltMate = new MateOptions(MateEdge.Right, MateEdge.Top)
                        },
                            altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1));
                    });
                }
            };

            treeView.ScrollArea.HAnchor = HAnchor.Stretch;

            treeView.AfterSelect += async(s, e) =>
            {
                if (treeView.SelectedNode.Tag is PrinterInfo printerInfo)
                {
                    horizontalSplitter.Panel2.CloseAllChildren();
                    horizontalSplitter.Panel2.AddChild(new PrinterDetails(printerInfo, theme)
                    {
                        HAnchor = HAnchor.MaxFitOrStretch,
                        VAnchor = VAnchor.Stretch,
                        Padding = theme.DefaultContainerPadding
                    });
                }
            };
            horizontalSplitter.Panel1.AddChild(treeView);

            horizontalSplitter.Panel2.AddChild(new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            });

            allControls.AnchorAll();

            this.AddChild(allControls);
        }