public MeshViewerWidget(Vector3 displayVolume, Vector2 bedCenter, BedShape bedShape, string startingTextMessage = "")
        {
            Scene.SelectionChanged += (sender, e) =>
            {
                Invalidate();
            };
            RenderType        = RenderTypes.Shaded;
            RenderBed         = true;
            RenderBuildVolume = false;
            //SetMaterialColor(1, RGBA_Bytes.LightGray, RGBA_Bytes.White);
            BedColor         = new ColorF(.8, .8, .8, .7).ToColor();
            BuildVolumeColor = new ColorF(.2, .8, .3, .2).ToColor();

            trackballTumbleWidget = new TrackballTumbleWidget(this.World, this);
            trackballTumbleWidget.TransformState = TrackBallTransformType.Rotation;

            AddChild(trackballTumbleWidget);

            CreatePrintBed(displayVolume, bedCenter, bedShape);

            trackballTumbleWidget.AnchorAll();

            partProcessingInfo = new PartProcessingInfo(startingTextMessage);

            GuiWidget labelContainer = new GuiWidget();

            labelContainer.AnchorAll();
            labelContainer.AddChild(partProcessingInfo);
            labelContainer.Selectable = false;

            SetMaterialColor(1, accentColor);

            this.AddChild(labelContainer);
        }
        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();
                }
            });
        }
Esempio n. 3
0
        public MeshViewerWidget(Vector3 displayVolume, Vector2 bedCenter, BedShape bedShape, string startingTextMessage = "")
        {
            RenderType        = RenderTypes.Shaded;
            RenderBed         = true;
            RenderBuildVolume = false;
            //SetMaterialColor(1, RGBA_Bytes.LightGray, RGBA_Bytes.White);
            BedColor         = new RGBA_Floats(.8, .8, .8, .7).GetAsRGBA_Bytes();
            BuildVolumeColor = new RGBA_Floats(.2, .8, .3, .2).GetAsRGBA_Bytes();

            trackballTumbleWidget = new TrackballTumbleWidget();
            trackballTumbleWidget.DrawRotationHelperCircle = false;
            trackballTumbleWidget.DrawGlContent           += trackballTumbleWidget_DrawGlContent;
            trackballTumbleWidget.TransformState           = TrackBallController.MouseDownType.Rotation;

            AddChild(trackballTumbleWidget);

            CreatePrintBed(displayVolume, bedCenter, bedShape);

            trackballTumbleWidget.AnchorAll();

            partProcessingInfo = new PartProcessingInfo(startingTextMessage);

            GuiWidget labelContainer = new GuiWidget();

            labelContainer.AnchorAll();
            labelContainer.AddChild(partProcessingInfo);
            labelContainer.Selectable = false;

            this.AddChild(labelContainer);
        }
Esempio n. 4
0
        public RayTraceWidget(int width = 200, int height = 200)
        {
            trackballTumbleWidget = new TrackballTumbleWidget();
            trackballTumbleWidget.DoOpenGlDrawing          = false;
            trackballTumbleWidget.DrawRotationHelperCircle = false;
            //trackballTumbleWidget.DrawGlContent += trackballTumbleWidget_DrawGlContent;
            trackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

            AddChild(trackballTumbleWidget);

            totalTime.Start();

            CreateScene();
            LocalBounds = new RectangleDouble(0, 0, width, height);

            trackballTumbleWidget.TrackBallController.Scale = .03;

            trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
            trackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));
            trackballTumbleWidget.AnchorAll();
        }
Esempio n. 5
0
        public RayTraceWidget(int width = 200, int height = 200)
        {
            world = new WorldView(width, height);

            trackballTumbleWidget = new TrackballTumbleWidget(world, this);
            //trackballTumbleWidget.DrawGlContent += trackballTumbleWidget_DrawGlContent;
            trackballTumbleWidget.TransformState = TrackBallTransformType.Rotation;

            AddChild(trackballTumbleWidget);

            totalTime.Start();

            CreateScene();
            LocalBounds = new RectangleDouble(0, 0, width, height);

            world.Scale = .03;

            world.Rotate(Quaternion.FromEulerAngles(new Vector3(0, 0, MathHelper.Tau / 16)));
            world.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .19, 0, 0)));

            trackballTumbleWidget.AnchorAll();
        }
Esempio n. 6
0
        public MeshViewerWidget(double bedXSize, double bedYSize, double scale)
        {
            ShowWireFrame = false;
            RenderBed     = true;
            PartColor     = RGBA_Bytes.White;

            this.partScale        = scale;
            trackballTumbleWidget = new TrackballTumbleWidget();
            trackballTumbleWidget.DrawRotationHelperCircle = false;
            trackballTumbleWidget.DrawGlContent           += trackballTumbleWidget_DrawGlContent;

            AddChild(trackballTumbleWidget);

            CreateBedGridImage((int)(bedXSize / 10), (int)(bedYSize / 10));

            printerBed = PlatonicSolids.CreateCube(bedXSize, bedYSize, 2);
            Face face = printerBed.Faces[0];

            {
                FaceData faceData = new FaceData();
                faceData.Textures.Add(bedCentimeterGridImage);
                face.Data = faceData;
                foreach (FaceEdge faceEdge in face.FaceEdgeIterator())
                {
                    FaceEdgeData edgeUV = new FaceEdgeData();
                    edgeUV.TextureUV.Add(new Vector2((bedXSize / 2 + faceEdge.vertex.Position.x) / bedXSize,
                                                     (bedYSize / 2 + faceEdge.vertex.Position.y) / bedYSize));
                    faceEdge.Data = edgeUV;
                }
            }

            foreach (Vertex vertex in printerBed.Vertices)
            {
                vertex.Position = vertex.Position - new Vector3(0, 0, 1);
            }

            trackballTumbleWidget.AnchorAll();
        }
        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();
        }
        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;
        }