public void RestoreToCurrent(string path)
        {
            DebugUtil.Log("[CotangentSerializer] Restoring scene from " + path);

            XmlDocument doc = new XmlDocument();

            try {
                doc.Load(path);
            }catch (Exception) {
                DebugUtil.Log("[CotangentSerializer] failed to read XmlDocument");
                throw;
            }

            // begin restore
            CCActions.BeginRestoreExistingScene();

            // restore scene objects
            XMLInputStream stream = new XMLInputStream()
            {
                xml = doc
            };
            SceneSerializer serializer = new SceneSerializer()
            {
                SOFactory = new SOFactory()
            };

            serializer.Restore(stream, CC.ActiveScene);

            // complete scene restore

            CCActions.CompleteRestoreExistingScene();

            // restore datamodel
            RestoreDataModel(doc);
        }
Example #2
0
        public static void DoArgumentsImport(string[] filenames)
        {
            List <string> meshFiles, sceneFiles;

            get_valid_filenames(filenames, out meshFiles, out sceneFiles);

            // dismiss splash screen if we have these args
            if (sceneFiles.Count > 0 || meshFiles.Count > 0)
            {
                var go = UnityUtil.FindGameObjectByName("SplashScreenPanel");
                if (go != null)
                {
                    go.GetComponent <SplashScreenDialog>().TransitionVisibility(false);
                }
            }


            bool clear_scene = true;

            if (sceneFiles.Count > 0)
            {
                OpenSceneFile(sceneFiles[0]);
                clear_scene = false;
            }

            if (meshFiles.Count > 0)
            {
                if (clear_scene)
                {
                    CCActions.ClearScene();
                }
                run_arguments_imports(meshFiles);
            }
        }
        /// <summary>
        /// - if not replace input, convert preview to print
        /// - if replace, if one target and one preview, keep target and replace w/ mesh from preview
        ///   - otherwise remove targets and convert preview to print
        /// </summary>
        static void standard_mesh_tool_handler(List <DMeshSO> targets, DMeshSO previewSO, bool replace_input, string newNameStr = null)
        {
            if (replace_input)
            {
                if (targets.Count == 1)
                {
                    replace_single(targets[0], previewSO);
                    CC.ActiveScene.RemoveSceneObject(previewSO, true);
                }
                else
                {
                    foreach (DMeshSO so in targets)
                    {
                        CCActions.RemovePrintMesh(so as PrintMeshSO);
                    }
                    if (newNameStr != null)
                    {
                        previewSO.Name = UniqueNames.GetNext(newNameStr);
                    }
                    convert_to_print_mesh(previewSO);
                }
            }
            else
            {
                if (newNameStr != null)
                {
                    previewSO.Name = UniqueNames.GetNext(newNameStr);
                }

                convert_to_print_mesh(previewSO);
            }
        }
Example #4
0
        private void ObjSettings_OnSettingModified(ObjectSettings settings)
        {
            PrintMeshSO so = settings.SourceSO as PrintMeshSO;

            update_mesh_material(so);

            // set dirty flag on scene
            CCActions.SetCurrentSceneModified();
        }
Example #5
0
        private void Mesh_OnTransformModified(SceneObject so)
        {
            CC.InvalidateSlicing();

            slice_gizmo_valid = false;

            // set dirty flag on scene
            CCActions.SetCurrentSceneModified();
        }
Example #6
0
        public static void DoFileDialogImport()
        {
            Action <string> onCompletedF = (filename) => {
                FPlatform.SetPrefsString("LastImportPath", filename);
                CC.ActiveScene.History.PushInteractionCheckpoint();
                CCActions.UpdateViewClippingBounds();
            };

            FPlatform.GetOpenFileName_Async("Select File", "", new string[] { "*.stl", "*.obj" }, "Supported Files (.stl, .obj)",
                                            (sFilename) => { DoFileImport(sFilename, true, onCompletedF); });
        }
        /// <summary>
        /// convert preview SO to print mesh, discard preview
        /// TODO: be able to swap/transfer preview into print
        /// </summary>
        static PrintMeshSO convert_to_print_mesh(DMeshSO previewSO)
        {
            previewSO.EnableSpatial = true;
            PrintMeshSO printMeshSO = previewSO.DuplicateSubtype <PrintMeshSO>();

            printMeshSO.Name = previewSO.Name;
            printMeshSO.AssignSOMaterial(CCMaterials.PrintMeshMaterial);

            CC.ActiveScene.RemoveSceneObject(previewSO, true);

            CCActions.AddNewPrintMesh(printMeshSO);

            return(printMeshSO);
        }
Example #8
0
        private void Mesh_OnMeshModified(DMeshSO so)
        {
            CC.InvalidateSlicing();

            if (so is PrintMeshSO)
            {
                update_mesh_material(so as PrintMeshSO);
            }

            slice_gizmo_valid = false;

            // set dirty flag on scene
            CCActions.SetCurrentSceneModified();
        }
Example #9
0
        public static void ShutdownApp()
        {
            CCActions.CancelCurrentTool();

            CC.FileMonitor.Shutdown();          // will kill itself
            CC.MeshAnalysis.Shutdown();
            CC.GCodeAnalysis.Shutdown();

            CC.Slicer.PauseSlicing = true;
            CC.Slicer.InvalidateSlicing();      // should terminate background thread

            CC.Toolpather.PauseToolpathing = true;
            CC.Toolpather.InvalidateToolpaths();      // should terminate background thread
        }
Example #10
0
        public static void OnApply_SetDimensionsTool(SetDimensionsTool tool, List <DMeshSO> targets)
        {
            tool.PushFinalChanges();
            foreach (var so in targets)
            {
                BakeScalingChangeOp change = new BakeScalingChangeOp(so);
                CC.ActiveScene.History.PushChange(change, false);
            }

            // should this be in history?
            CCActions.UpdateViewClippingBounds();

            CC.ActiveScene.History.PushInteractionCheckpoint();
        }
Example #11
0
        // called every frame
        public static void Update()
        {
            if (FPlatform.ShutdownBackgroundThreadsOnQuit)
            {
                return;
            }

            Objects.Update();
            Slicer.Update();
            Toolpather.Update();
            MeshAnalysis.Update();
            GCodeAnalysis.Update();

            CCActions.UpdateCurrentToolStatus();
        }
Example #12
0
        public static async void DoDragDropImport(List <string> filenames)
        {
            List <string> meshFiles, sceneFiles;

            get_valid_filenames(filenames, out meshFiles, out sceneFiles);

            if (sceneFiles.Count > 0)
            {
                HaveOpenedOrImportedFile = true;
                DoDragDropOpen(sceneFiles);
            }

            int             count        = 0;
            Action <string> onCompletedF = (filename) => {
                count++;
            };

            if (CurrentSceneIsStartupScene)
            {
                ClearScene();
            }
            HaveOpenedOrImportedFile = true;

            CC.Slicer.InvalidateSlicing();

            CCStatus.BeginOperation("reading");

            foreach (string filename in filenames)
            {
                if (filename.Length > 0 && File.Exists(filename))
                {
                    MeshImporter importer = new MeshImporter();
                    await importer.ImportInteractive(filename, onCompletedF);
                }
            }

            CCStatus.EndOperation("reading");

            if (count > 0)
            {
                CC.ActiveScene.History.PushInteractionCheckpoint();
                CCActions.UpdateViewClippingBounds();
            }
            else
            {
                // show an error message or something...
            }
        }
Example #13
0
        public static void OnApply_SeparateSolidsTool(SeparateSolidsTool tool, List <DMeshSO> previews)
        {
            bool replace_input = tool.Parameters.GetValueBool("replace_input");

            if (replace_input)
            {
                foreach (DMeshSO so in tool.Targets)
                {
                    CCActions.RemovePrintMesh(so as PrintMeshSO);
                }
            }

            foreach (var so in previews)
            {
                so.Name = UniqueNames.GetNext("SeparatedPart");
                convert_to_print_mesh(so);
            }
            CC.ActiveScene.History.PushInteractionCheckpoint();
        }
Example #14
0
        static PrintMeshSO emit_new_print_mesh(DMesh3 mesh, DMeshSO fromParent)
        {
            PrintMeshSO newSO = new PrintMeshSO();

            newSO.Create(mesh, CCMaterials.PrintMeshMaterial);
            CCActions.AddNewPrintMesh(newSO);
            if (fromParent != null)
            {
                newSO.SetLocalScale(fromParent.GetLocalScale());
                newSO.SetLocalFrame(fromParent.GetLocalFrame(CoordSpace.SceneCoords), CoordSpace.SceneCoords);
            }
            else
            {
                throw new NotImplementedException("have not implemented this path yet...");
                // estimate frame??
            }

            return(newSO);
        }
Example #15
0
        public static void Initialize(FContext context)
        {
            ActiveContext = context;
            ActiveContext.Scene.SelectionChangedEvent += Scene_SelectionChangedEvent;
            ActiveContext.Scene.ChangedEvent          += Scene_ChangedEvent;

            PrinterDB = new SettingsDatabase();
            Settings  = new PrintSettings();

            PrinterDB.OnPrinterSelectionModified += PrinterDB_OnPrinterSelectionModified;
            PrinterDB.OnPresetSelectionModified  += PrinterDB_OnPresetSelectionModified;

            PrinterDB.Initialize();
            Settings.UpdateFromSettings(PrinterDB.ActivePreset.Settings);
            update_printer_bed();


            ObjSettings = new ObjectSettings();
            CCActions.UpdateObjectSettings();

            Objects = new PrintScene();

            Toolpather = new ToolpathGenerator();
            Toolpather.ToolpathsProgressEvent += (status) => {
                ToolpathProgressEvent?.Invoke(status);
            };

            Slicer = new GeometrySlicer();
            Slicer.SlicingProgressEvent += (status) => {
                SlicingProgressEvent?.Invoke(status);
            };
            Slicer.SlicingInvalidatedEvent += () => { InvalidateToolPaths(); };

            MeshAnalysis  = new MeshAnalysisManager();
            GCodeAnalysis = new GCodeAnalysisManager();
            GCodeAnalysis.EnableUpdates = false;

            FileMonitor = new ExternalFileMonitor();
        }
Example #16
0
        static public Button AddBasicStartToolButton(GameObject popupGO, string text, string toolIdentifier, Func <bool> isEnabledF = null)
        {
            GameObject buttonGO = GameObject.Instantiate(Resources.Load <GameObject>("BasicToolButton"));

            popupGO.AddChild(buttonGO, false);
            buttonGO.SetName(text);
            Button button = UnityUIUtil.GetButtonAndAddClickHandler(buttonGO, () => {
                CCActions.BeginTool(toolIdentifier);
            });

            UnityUIUtil.SetButtonText(button, text);

            if (isEnabledF != null)
            {
                var enabler = buttonGO.AddComponent <UIWidgetEnabler>();
                enabler.widget     = button;
                enabler.IsEnabledF = isEnabledF;
                enabler.Update();
            }

            return(button);
        }
Example #17
0
        public bool HandleShortcuts()
        {
            bool bShiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift);
            bool bCtrlDown  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

            // ESCAPE CLEARS ACTIVE TOOL OR SELECTION
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (CCActions.IsPreferencesVisible())
                {
                    CCActions.HidePreferencesDialog();
                }
                else if (CCActions.InTool)
                {
                    CCActions.CancelCurrentTool();
                }
                else if (context.Scene.Selected.Count > 0)
                {
                    context.Scene.ClearSelection();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Delete))
            {
                if (CCActions.InTool == false)
                {
                    CCActions.DeleteSelectedObjects(true);
                }
                return(true);


                // CENTER TARGET (??)
            }
            else if (Input.GetKeyUp(KeyCode.C))
            {
                Ray3f     cursorRay = context.MouseController.CurrentCursorWorldRay();
                AnyRayHit hit       = null;
                if (context.Scene.FindSceneRayIntersection(cursorRay, out hit))
                {
                    context.ActiveCamera.Animator().AnimatePanFocus(hit.hitPos, CoordSpace.WorldCoords, 0.3f);
                }
                return(true);

                // DROP A COPY
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                if (CCActions.InTool == false)
                {
                    CCActions.DuplicateSelectedObjects(true);
                }
                return(true);

                // Mesh Editor
            }
            else if (Input.GetKeyUp(KeyCode.E))
            {
                if (bCtrlDown)
                {
                    CCActions.DoMeshExport();
                }
                else
                {
                    CCActions.BeginTool(MeshEditorTool.Identifier);
                }
                return(true);

                // TOGGLE FRAME TYPE
            }
            else if (Input.GetKeyUp(KeyCode.F))
            {
                FrameType eCur = context.TransformManager.ActiveFrameType;
                context.TransformManager.ActiveFrameType = (eCur == FrameType.WorldFrame)
                    ? FrameType.LocalFrame : FrameType.WorldFrame;
                return(true);

                // Fill Holes
            }
            else if (Input.GetKeyUp(KeyCode.H))
            {
                CCActions.BeginTool(FillHolesTool.Identifier);
                return(true);

                // Autorepair
            }
            else if (Input.GetKeyUp(KeyCode.I))
            {
                CCActions.BeginTool(MeshAutoRepairTool.Identifier);
                return(true);

                // CENTER AND ON BED
            }
            else if (Input.GetKeyUp(KeyCode.N))
            {
                if (CCActions.InTool == false)
                {
                    CCActions.AcceptAndExitCurrentTool();
                    CCActions.MoveCurrentToPrintBed(false);
                    CCActions.CenterCurrent(true);
                }
                return(true);

                // Remesh or Simplify
            }
            else if (Input.GetKeyUp(KeyCode.R))
            {
                if (bShiftDown)
                {
                    CCActions.BeginTool(ReduceTool.Identifier);
                }
                else
                {
                    CCActions.BeginTool(RemeshTool.Identifier);
                }
                return(true);

                // SET UNITS/SIZE
            }
            else if (Input.GetKeyUp(KeyCode.U))
            {
                CCActions.BeginTool(SetDimensionsTool.Identifier);
                return(true);

                // VISIBILITY  (V HIDES, SHIFT+V SHOWS)
            }
            else if (Input.GetKeyUp(KeyCode.V))
            {
                // show/hide (should be abstracted somehow?? instead of directly accessing GOs?)
                if (bShiftDown)
                {
                    foreach (SceneObject so in context.Scene.SceneObjects)
                    {
                        so.RootGameObject.Show();
                    }
                }
                else
                {
                    foreach (SceneObject so in context.Scene.Selected)
                    {
                        so.RootGameObject.Hide();
                    }
                    context.Scene.ClearSelection();
                }
                return(true);

                // UNDO
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Z))
            {
                context.Scene.History.InteractiveStepBack();
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Backspace))
            {
                context.Scene.History.InteractiveStepBack();
                return(true);

                // REDO
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Y))
            {
                context.Scene.History.InteractiveStepForward();
                return(true);

                // Toggle Y/Z Up
            }
            else if (bShiftDown && Input.GetKeyUp(KeyCode.Z))
            {
                if (CCActions.InTool == false)
                {
                    CCActions.AcceptAndExitCurrentTool();
                    CCActions.SwapCurrentUpDirections(true);
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.UpArrow))
            {
                int step = (bShiftDown) ? 10 : 1;
                CC.Objects.CurrentLayer = CC.Objects.CurrentLayer + step;
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.DownArrow))
            {
                int step = (bShiftDown) ? 10 : 1;
                CC.Objects.CurrentLayer = CC.Objects.CurrentLayer - step;
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.A))
            {
                CCActions.AcceptAndExitCurrentTool();
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Q) && bCtrlDown)
            {
                FPlatform.QuitApplication();
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.S))
            {
                if (bCtrlDown && bShiftDown)
                {
                    CCActions.SaveCurrentSceneAs();
                }
                else if (bCtrlDown)
                {
                    CCActions.SaveCurrentSceneOrSaveAs();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.X))
            {
                if (FPlatform.InUnityEditor())
                {
                    //CC.ActiveContext.Scene.ClearHistory();
                    CC.ActiveContext.Scene.History.DebugPrint();
                }
                return(true);
            }
            else if (bShiftDown && Input.GetKeyUp(KeyCode.Alpha1))
            {
                if (FPlatform.InUnityEditor() == false && bCtrlDown == false)
                {
                    return(true);
                }
                string lastFile = FPlatform.GetPrefsString("LastImportPath", "");
                if (lastFile != "")
                {
                    if (lastFile.EndsWith(".cota"))
                    {
                        CCActions.DoFileOpen(lastFile, false, (str) => {
                            CC.ActiveScene.ClearHistory();
                        });
                    }
                    else
                    {
                        CCActions.ClearScene();
                        CCActions.DoFileImport(lastFile, false, (str) => {
                            CC.ActiveScene.ClearHistory();
                        });
                    }
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.W))
            {
                CCActions.WireframeEnabled = !CCActions.WireframeEnabled;
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha1))
            {
                CCActions.SwitchToViewMode(AppViewMode.PrintView);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha2))
            {
                CCActions.SwitchToViewMode(AppViewMode.RepairView);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha3))
            {
                CCActions.SwitchToViewMode(AppViewMode.ModelView);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #18
0
        async Task complete_import(string sFilename, DMesh3Builder builder, Action <string> onCompletedF)
        {
            AxisAlignedBox3d bounds = AxisAlignedBox3d.Empty;

            foreach (DMesh3 mesh in builder.Meshes)
            {
                bounds.Contain(mesh.CachedBounds);
            }
            Vector3d centerPt = bounds.Center;
            Vector3d basePt   = centerPt - bounds.Height * 0.5f * Vector3d.AxisY;

            Vector3d vTranslate = basePt;
            await Task.Run(() => {
                foreach (DMesh3 mesh in builder.Meshes)
                {
                    MeshTransforms.Translate(mesh, -vTranslate);
                }
            });

            bool     bFirst        = (CC.Objects.PrintMeshes.Count == 0);
            Vector3d postTranslate = Vector3d.Zero;

            switch (CCPreferences.ImportTransformMode)
            {
            case CCPreferences.ImportTransformModes.AutoCenterAll:
                break;

            case CCPreferences.ImportTransformModes.AutoCenterFirst:
                if (bFirst)
                {
                    CCState.SceneImportTransform = vTranslate;
                }
                postTranslate = vTranslate - CCState.SceneImportTransform;
                break;

            case CCPreferences.ImportTransformModes.NoAutoCenter:
                postTranslate = vTranslate;
                break;
            }

            // compact input meshes
            await Task.Run(() => {
                gParallel.ForEach(builder.Meshes, (mesh) => {
                    MeshEditor.RemoveUnusedVertices(mesh);
                });
                gParallel.ForEach(Interval1i.Range(builder.Meshes.Count), (k) => {
                    if (builder.Meshes[k].IsCompact == false)
                    {
                        builder.Meshes[k] = new DMesh3(builder.Meshes[k], true);
                    }
                });
            });

            string sBaseName = Path.GetFileNameWithoutExtension(sFilename);

            foreach (DMesh3 mesh in builder.Meshes)
            {
                PrintMeshSO meshSO = new PrintMeshSO();
                meshSO.Create(mesh, CCMaterials.PrintMeshMaterial);
                meshSO.UpDirection = UpDirection.ZUp;

                Frame3f f = meshSO.GetLocalFrame(CoordSpace.ObjectCoords);
                f.Origin = f.Origin + (Vector3f)postTranslate;
                meshSO.SetLocalFrame(f, CoordSpace.ObjectCoords);

                // if only one mesh, we can keep a reference
                if (builder.Meshes.Count == 1)
                {
                    meshSO.SourceFilePath        = sFilename;
                    meshSO.LastReadFileTimestamp = File.GetLastWriteTime(SourceFilePath).Ticks;
                }

                meshSO.Name = UniqueNames.GetNext(sBaseName);

                CCActions.AddNewPrintMesh(meshSO);
            }

            if (onCompletedF != null)
            {
                onCompletedF(sFilename);
            }
        }
Example #19
0
 private static void Scene_ChangedEvent(object sender, SceneObject so, SceneChangeType type)
 {
     CCActions.UpdateObjectSettings();
     CCActions.SetCurrentSceneModified();
 }
Example #20
0
 private static void Scene_SelectionChangedEvent(object sender, EventArgs e)
 {
     CCActions.UpdateObjectSettings();
 }