Exemplo n.º 1
0
        public static void DoSaveCurrentScene(string sFilename)
        {
            if (sFilename != null && sFilename.Length > 0)
            {
                if (sFilename.EndsWith(".cota", StringComparison.OrdinalIgnoreCase) == false)
                {
                    sFilename += ".cota";
                }

                CotangentSerializer serializer = new CotangentSerializer();
                serializer.SerializeOptions.MinimalMeshStorage     = true;
                serializer.SerializeOptions.FastCompression        = false;
                serializer.SerializeOptions.StoreMeshVertexNormals = false;
                serializer.SerializeOptions.StoreMeshVertexUVs     = false;
                serializer.SerializeOptions.StoreMeshVertexColors  = false;
                try {
                    serializer.StoreCurrent(sFilename);
                    SetCurrentSaveFilePath(sFilename);
                    ClearCurrentSceneModified();
                } catch (Exception e) {
                    DebugUtil.Log("DoSaveCurrentScene: Exception: " + e.Message);
                    CotangentUI.ShowModalMessageDialog("Save Failed",
                                                       "Error writing to file " + sFilename,
                                                       "Ok", null, null);
                }
            }
        }
Exemplo n.º 2
0
        public static async void DoFileOpen(string sFilename, bool bInteractive, Action <string> onCompletedF = null)
        {
            if (string.IsNullOrEmpty(sFilename))
            {
                return;
            }
            if (File.Exists(sFilename) == false)
            {
                CotangentUI.ShowModalMessageDialog("File Does Not Exist",
                                                   "File " + sFilename + " does not exist",
                                                   "Ok", null, null);
                return;
            }

            HaveOpenedOrImportedFile = true;

            if (sFilename.EndsWith(".cota", StringComparison.OrdinalIgnoreCase))
            {
                // [TODO] make this multi threaded?
                OpenSceneFile(sFilename);
                FPlatform.SetPrefsString("LastImportPath", sFilename);
            }
            else
            {
                ClearScene();
                MeshImporter importer = new MeshImporter();
                CCStatus.BeginOperation("reading");
                await importer.ImportInteractive(sFilename, onCompletedF);

                CCStatus.EndOperation("reading");
            }
        }
Exemplo n.º 3
0
        public static void DoDragDropOpen(List <string> filenames)
        {
            if (filenames.Count > 1)
            {
                CotangentUI.ShowModalMessageDialog("Cannot Open Multiple Scenes",
                                                   "Sorry, currently Cotangent can only open a single dropped scene.",
                                                   "Ok", null, null);
            }

            OpenSceneFile(filenames[0]);
        }
Exemplo n.º 4
0
        void on_delete_preset_clicked()
        {
            if (CC.PrinterDB.ActivePreset == CC.PrinterDB.ActiveMachine.DefaultPreset)
            {
                return;
            }

            CotangentUI.ShowModalConfirmDialog("Delete Preset?",
                                               "Are you sure you want to delete this Preset? <b>You cannot undo this change</b>",
                                               "Yes, Delete", "Cancel", null,
                                               (obj) => { CC.PrinterDB.DeleteActivePreset(); }, null);
        }
Exemplo n.º 5
0
 void on_save_preset_clicked()
 {
     if (CC.PrinterDB.ActivePreset == CC.PrinterDB.ActiveMachine.DefaultPreset)
     {
         CotangentUI.ShowModalConfirmDialog("Change Defaults?",
                                            "Are you sure you want to change the Machine Defaults? <b>You cannot undo this change</b>. Use the <i>Derive New Preset...</i> option in the Presets List to save the current settings as a new Preset",
                                            "Update Defaults", "Cancel", null,
                                            (obj) => { CC.PrinterDB.SaveActivePreset(); }, null);
     }
     else
     {
         CC.PrinterDB.SaveActivePreset();
     }
 }
Exemplo n.º 6
0
        public static void OpenSceneFile(string sFilename)
        {
            CotangentSerializer serializer = new CotangentSerializer();

            try {
                serializer.RestoreToCurrent(sFilename);
                SetCurrentSaveFilePath(sFilename);
                ClearCurrentSceneModified();
            } catch (Exception e) {
                DebugUtil.Log("OpenSceneFile: exception restoring cota file: " + e.Message);
                CotangentUI.ShowModalMessageDialog("Error Opening Scene",
                                                   "Sorry, errors ocurred while trying to read this scene file.",
                                                   "Ok", null, null);
            }
        }
Exemplo n.º 7
0
        void update_slicing(bool immediate = false)
        {
            if (immediate == false && time_to_start_new_compute() == false)
            {
                return;
            }

            // ui thing
            CotangentUI.HideSliceLabel();

            BackgroundThreadData d = new BackgroundThreadData();

            synchronize_meshes(d);

            mark_spawn_time();
            spawn_new_compute(d);
        }
Exemplo n.º 8
0
        public void CreateDerivedPreset()
        {
            MachineModel activeModel = ActiveMachine;

            MachinePreset basePreset = ActivePreset.Clone();

            CC.Settings.WriteToSettings(basePreset.Settings);

            CotangentUI.GetStringFromDialog("Create New Preset",
                                            "Enter the name of new Preset to be derived from \"" + basePreset.Settings.Identifier + "\"", null,
                                            (name) => { return(string.IsNullOrEmpty(name) == false && name.Contains('\"') == false); },
                                            (name, obj) => {
                MachinePreset derived = MachineDB.CreateDerivedPreset(activeModel, basePreset, name);
                SelectPreset(derived);
                // will cause refresh of presets list
                OnPrinterSelectionModified?.Invoke(ActiveManufacturer, ActiveMachine);
            },
                                            () => {
                SelectPreset(basePreset);
            }
                                            );
        }
Exemplo n.º 9
0
        public void CreateDerivedMachine()
        {
            MachineModel activeModel = ActiveMachine;

            MachinePreset defaultPreset = MachineDB.DefaultPresetForModel(ActiveMachine);

            CotangentUI.GetStringFromDialog("Create New Machine",
                                            "Enter the name of new Machine to be derived from \"" + activeModel.Name + "\"", null,
                                            (name) => { return(string.IsNullOrEmpty(name) == false && name.Contains('\"') == false); },
                                            (name, obj) => {
                try {
                    MachineModel newModel = MachineDB.CreateDerivedMachine(ActiveManufacturer, ActiveMachine, defaultPreset, name);
                    OnPrinterSelectionModified?.Invoke(null, null);
                    SelectMachine(newModel);
                } catch (Exception e) {
                    DebugUtil.Log("CreateDerivedMachine:  " + e.Message);
                }
            },
                                            () => {
                SelectMachine(ActiveMachine);
            }
                                            );
        }
Exemplo n.º 10
0
        public void Initialize(Cockpit cockpit)
        {
            cockpit.Name = "modelCockpit";


            // Configure how the cockpit moves

            //cockpit.PositionMode = Cockpit.MovementMode.TrackPosition;
            // [RMS] use orientation mode to make cockpit follow view orientation.
            //  (however default widgets below are off-screen!)
            cockpit.PositionMode = Cockpit.MovementMode.TrackOrientation;



            BoxContainer screenContainer           = new BoxContainer(new Cockpit2DContainerProvider(cockpit));
            PinnedBoxes2DLayoutSolver screenLayout = new PinnedBoxes2DLayoutSolver(screenContainer);
            PinnedBoxesLayout         layout       = new PinnedBoxesLayout(cockpit, screenLayout)
            {
                StandardDepth = 2.0f
            };

            cockpit.AddLayout(layout, "2D", true);



            Func <string, float, HUDLabel> MakeButtonF = (label, buttonW) => {
                HUDLabel button = new HUDLabel()
                {
                    Shape           = CotangentUI.MakeMenuButtonRect(buttonW, CotangentUI.MenuButtonHeight),
                    TextHeight      = CotangentUI.MenuButtonTextHeight,
                    AlignmentHorz   = HorizontalAlignment.Center,
                    BackgroundColor = CotangentUI.ButtonBGColor, TextColor = CotangentUI.ButtonTextColor, Text = label,
                    EnableBorder    = true, BorderWidth = CotangentUI.StandardButtonBorderWidth, BorderColor = CotangentUI.ButtonTextColor
                };
                button.Create();
                button.Name    = label;
                button.Enabled = true;
                return(button);
            };



            Vector2f          progressOffsetY = 4 * CotangentUI.PixelScale * Vector2f.AxisY;
            HUDRadialProgress slicerProgress  = new HUDRadialProgress()
            {
                Radius = 18 * CotangentUI.PixelScale
            };

            slicerProgress.Create();
            slicerProgress.Name = "slicer_progress";
            int MAX_PROGRESS = 1000;

            slicerProgress.MaxProgress = MAX_PROGRESS;
            CC.SlicingProgressEvent   += (status) => {
                if (status.bFailed)
                {
                    double t = 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = Colorf.VideoRed;
                }
                else
                {
                    double t = 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = Colorf.BlueMetal;
                }
            };
            CC.ToolpathProgressEvent += (status) => {
                if (status.bFailed)
                {
                    double t = 0.5 + 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = Colorf.VideoRed;
                }
                else
                {
                    double t = 0.5 + 0.5 * (double)status.curProgress / (double)status.maxProgress;
                    if (status.curProgress == 0 && status.maxProgress == 1)
                    {
                        t = 0;
                    }
                    slicerProgress.Progress       = (int)(t * MAX_PROGRESS);
                    slicerProgress.CompletedColor = (status.curProgress == status.maxProgress) ? Colorf.LightGreen : Colorf.BlueMetal;
                }
            };
            layout.Add(slicerProgress, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.BoxPointF(slicerProgress, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.CenterBottom, progressOffsetY)
            });



            HUDButton progressClick = new HUDButton()
            {
                Shape = new HUDShape(HUDShapeType.Disc, slicerProgress.Radius)
            };
            fMaterial normalMaterial = MaterialUtil.CreateFlatMaterialF(Colorf.White, 0);
            fMaterial pauseMaterial  = MaterialUtil.CreateTransparentImageMaterialF("icons/progress_pause");
            fMaterial pausedMaterial = MaterialUtil.CreateTransparentImageMaterialF("icons/progress_play");

            if (CCPreferences.ActiveSlicingUpdateMode == CCPreferences.SlicingUpdateModes.ImmediateSlicing)
            {
                progressClick.Create(normalMaterial, null, pauseMaterial);
            }
            else
            {
                progressClick.Create(pausedMaterial, null, null);
            }
            progressClick.Name = "progress_click";
            layout.Add(progressClick, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                DepthShift       = -0.1f,
                PinSourcePoint2D = LayoutUtil.BoxPointF(progressClick, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.CenterBottom, progressOffsetY)
            });
            progressClick.OnClicked += (o, e) => {
                if (CCPreferences.ActiveSlicingUpdateMode == CCPreferences.SlicingUpdateModes.ImmediateSlicing)
                {
                    CCPreferences.ActiveSlicingUpdateMode = CCPreferences.SlicingUpdateModes.SliceOnDemand;
                    progressClick.StandardMaterial        = pausedMaterial;
                    progressClick.HoverMaterial           = null;
                }
                else
                {
                    CCPreferences.ActiveSlicingUpdateMode = CCPreferences.SlicingUpdateModes.ImmediateSlicing;
                    progressClick.StandardMaterial        = normalMaterial;
                    progressClick.HoverMaterial           = pauseMaterial;
                }
                if (CC.Toolpather.ToolpathsValid == false)
                {
                    // not sure why we have to invalidate slicing here, but if we don't toolpath
                    // computation will not stop when we pause...
                    CC.Slicer.InvalidateSlicing();
                    //CC.InvalidateToolPaths();
                }
            };


            CotangentUI.PrintViewHUDItems = new List <HUDStandardItem>()
            {
                slicerProgress, progressClick
            };

            screenLayout.RecomputeLayout();


            // Configure interaction behaviors
            //   - below we add behaviors for mouse, gamepad, and spatial devices (oculus touch, etc)
            //   - keep in mind that Tool objects will register their own behaviors when active

            // setup key handlers (need to move to behavior...)
            cockpit.AddKeyHandler(new CotangentKeyHandler(cockpit.Context));

            // these behaviors let us interact with UIElements (ie left-click/trigger, or either triggers for Touch)
            cockpit.InputBehaviors.Add(new Mouse2DCockpitUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context)
            {
                Priority = 1
            });

            // selection / multi-selection behaviors
            // Note: this custom behavior implements some selection redirects that we use in various parts of Archform
            cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(cockpit.Context)
            {
                Priority = 10
            });

            // left click-drag to tumble, and left click-release to de-select
            cockpit.InputBehaviors.Add(new MouseClickDragSuperBehavior()
            {
                Priority     = 100,
                DragBehavior = new MouseViewRotateBehavior(cockpit.Context)
                {
                    Priority = 100, RotateSpeed = 3.0f
                },
                ClickBehavior = new MouseDeselectBehavior(cockpit.Context)
                {
                    Priority = 999
                }
            });

            // also right-click-drag to tumble
            cockpit.InputBehaviors.Add(new MouseViewRotateBehavior(cockpit.Context)
            {
                Priority  = 100, RotateSpeed = 3.0f,
                ActivateF = MouseBehaviors.RightButtonPressedF, ContinueF = MouseBehaviors.RightButtonDownF
            });

            // middle-click-drag to pan
            cockpit.InputBehaviors.Add(new MouseViewPanBehavior(cockpit.Context)
            {
                Priority  = 100, PanSpeed = 0.01f, Adaptive = true,
                ActivateF = MouseBehaviors.MiddleButtonPressedF, ContinueF = MouseBehaviors.MiddleButtonDownF
            });


            cockpit.OverrideBehaviors.Add(new MouseWheelZoomBehavior(cockpit)
            {
                Priority = 100, ZoomScale = 0.2f, Adaptive = true
            });

            // touch input
            cockpit.InputBehaviors.Add(new TouchUIBehavior(cockpit.Context)
            {
                Priority = 1
            });
            cockpit.InputBehaviors.Add(new Touch2DCockpitUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new TouchViewManipBehavior(cockpit.Context)
            {
                Priority = 999, TouchZoomSpeed = 0.1f, TouchPanSpeed = 0.03f
            });
        }