예제 #1
0
        public bool HandleShortcuts()
        {
            bool bShiftDown = Input.GetKey(KeyCode.LeftShift);
            bool bCtrlDown  = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl);

            // ESCAPE CLEARS ACTIVE TOOL OR SELECTION
            if (Input.GetKeyUp(KeyCode.Escape))
            {
                if (context.ToolManager.HasActiveTool(0) || context.ToolManager.HasActiveTool(1))
                {
                    context.ToolManager.DeactivateTool(0);
                    context.ToolManager.DeactivateTool(1);
                }
                else if (context.Scene.Selected.Count > 0)
                {
                    context.Scene.ClearSelection();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.A))
            {
                if (PanelGroup != null)
                {
                    PanelGroup.SelectModulo(PanelGroup.Selected + 1);
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.S))
            {
                if (PanelGroup != null)
                {
                    PanelGroup.SelectModulo(PanelGroup.Selected - 1);
                }
                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.Manipulator().ScenePanFocus(context.Scene, context.ActiveCamera, hit.hitPos, true);
                }
                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);

                // DROP A COPY
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                foreach (SceneObject so in context.Scene.Selected)
                {
                    SceneObject copy = so.Duplicate();
                    if (copy != null)
                    {
                        // [TODO] could have a lighter record here because we can just re-run Duplicate() ?
                        context.Scene.History.PushChange(
                            new AddSOChange()
                        {
                            scene = context.Scene, so = copy
                        });
                        context.Scene.History.PushInteractionCheckpoint();
                    }
                }
                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);

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

                // FILE OPEN
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.O))
            {
                var cp = new FileOpenCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);

                // FILE SAVE
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.S))
            {
                var cp = new FileSaveCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);

                // FILE IMPORT
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.I))
            {
                var cp = new FileImportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);

                // FILE EXPORT
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.E))
            {
                var cp = new FileExportCockpit()
                {
                    InitialPath = SceneGraphConfig.LastFileOpenPath
                };
                context.PushCockpit(cp);
                return(true);


                // APPLY CURRENT TOOL IF POSSIBLE
            }
            else if (Input.GetKeyUp(KeyCode.Return))
            {
                if (((context.ActiveInputDevice & InputDevice.Mouse) != 0) &&
                    context.ToolManager.HasActiveTool(ToolSide.Right) &&
                    context.ToolManager.ActiveRightTool.CanApply)
                {
                    context.ToolManager.ActiveRightTool.Apply();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha1))
            {
                context.ToolManager.SetActiveToolType(SnapDrawPrimitivesTool.Identifier, 1);
                context.ToolManager.ActivateTool(1);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha2))
            {
                context.ToolManager.SetActiveToolType(DrawTubeTool.Identifier, 1);
                context.ToolManager.ActivateTool(1);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Alpha3))
            {
                context.ToolManager.SetActiveToolType(DrawCurveTool.Identifier, 1);
                context.ToolManager.ActivateTool(1);
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.S))
            {
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Equals))
            {
                if (Application.isEditor)
                {
                    string sName = UniqueNames.GetNext("Screenshot");
                    sName = "C:\\scratch\\" + sName + ".png";
                    ScreenCapture.CaptureScreenshot(sName, 4);
                    Debug.Log("Wrote screenshot " + sName);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #2
0
        public void Initialize(Cockpit cockpit)
        {
            cockpit.Name = "cadSceneCockpit";

            // configure tracking
            SmoothCockpitTracker.Enable(cockpit);
            cockpit.TiltAngle = 10.0f;


            RegisterMessageHandlers(cockpit);

            // set up sphere layout
            SphereBoxRegion region3d = new SphereBoxRegion()
            {
                Radius           = fCockpitRadiusPanel,
                HorzDegreeLeft   = 50.0f, HorzDegreeRight = 15.0f,
                VertDegreeBottom = 40.0f, VertDegreeTop = 15.0f
            };
            BoxContainer uiContainer             = new BoxContainer(new BoxRegionContainerProvider(cockpit, region3d));
            PinnedBoxes3DLayoutSolver layoutCalc = new PinnedBoxes3DLayoutSolver(uiContainer, region3d);
            PinnedBoxesLayout         layout     = new PinnedBoxesLayout(cockpit, layoutCalc)
            {
                StandardDepth = 0   // widgets are on sphere
            };

            cockpit.AddLayout(layout, "PrimarySphere", true);


            HUDToggleGroup panelGroup = BuildPanels(cockpit);


            //BuildParameterPanel(cockpit);


            try {
                AddUndoRedo(cockpit);
                AddTransformToolToggleGroup(cockpit);
                AddFrameToggleGroup(cockpit);
                AddNavModeToggleGroup(cockpit);
                AddMenuButtonsGroup(cockpit);
            } catch (Exception e) {
                Debug.Log("[SetupCADCockpit.Initialize::buttons/etc] exception: " + e.Message);
            }

            // setup key handlers (need to move to behavior...)
            cockpit.AddKeyHandler(new CADKeyHandler(cockpit.Context)
            {
                PanelGroup = panelGroup
            });

            // setup mouse handling
            cockpit.InputBehaviors.Add(new VRMouseUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new VRGamepadUIBehavior(cockpit.Context)
            {
                Priority = 0
            });
            cockpit.InputBehaviors.Add(new VRSpatialDeviceUIBehavior(cockpit.Context)
            {
                Priority = 0
            });

            cockpit.InputBehaviors.Add(new TwoHandViewManipBehavior(cockpit)
            {
                Priority = 1
            });
            //cockpit.InputBehaviors.Add(new SpatialDeviceGrabViewBehavior(cockpit) { Priority = 2 });
            cockpit.InputBehaviors.Add(new SpatialDeviceViewManipBehavior(cockpit)
            {
                Priority = 2
            });

            RemoteGrabBehavior grabBehavior = new RemoteGrabBehavior(cockpit)
            {
                Priority = 5
            };
            SecondaryGrabBehavior secondGrab = new SecondaryGrabBehavior(cockpit, grabBehavior)
            {
                Priority = 4
            };

            grabBehavior.OnEndGrab += (sender, target) => {
                if (secondGrab.InGrab && secondGrab.GrabbedSO is GroupSO)
                {
                    cockpit.Context.RegisterNextFrameAction(() => {
                        GroupSO group           = secondGrab.GrabbedSO as GroupSO;
                        AddToGroupChange change = new AddToGroupChange(cockpit.Scene, group, target);
                        cockpit.Scene.History.PushChange(change, false);
                        cockpit.Scene.ClearSelection();
                        cockpit.Scene.Select(group, false);
                    });
                }
            };

            cockpit.InputBehaviors.Add(secondGrab);
            cockpit.InputBehaviors.Add(grabBehavior);

            cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(cockpit.Context)
            {
                Priority = 10
            });
            cockpit.InputBehaviors.Add(new GamepadMultiSelectBehavior(cockpit.Context)
            {
                Priority = 10
            });
            cockpit.InputBehaviors.Add(new SpatialDeviceMultiSelectBehavior(cockpit.Context)
            {
                Priority = 10
            });

            cockpit.InputBehaviors.Add(new MouseDeselectBehavior(cockpit.Context)
            {
                Priority = 999
            });
            cockpit.InputBehaviors.Add(new GamepadDeselectBehavior(cockpit.Context)
            {
                Priority = 999
            });
            cockpit.InputBehaviors.Add(new SpatialDeviceDeselectBehavior(cockpit.Context)
            {
                Priority = 999
            });

            cockpit.InputBehaviors.Add(new SceneRightClickBehavior(cockpit)
            {
                Priority = 20
            });
            cockpit.InputBehaviors.Add(new ClearBehavior(cockpit.Context)
            {
                Priority = 999
            });
            cockpit.InputBehaviors.Add(new UndoShortcutBehavior(cockpit.Context)
            {
                Priority = 999
            });

            cockpit.InputBehaviors.Add(new StickCycleBehavior(cockpit.Context)
            {
                Priority = 999, Side = CaptureSide.Left,
                Cycle    = (n) => { panelGroup.SelectModulo(panelGroup.Selected - n); }
            });


            //cockpit.OverrideBehaviors.Add(new ScreenCaptureBehavior() { Priority = 0,
            //    ScreenshotPath = Environment.GetEnvironmentVariable("homepath") + "\\DropBox\\ScreenShots\\" });
            cockpit.OverrideBehaviors.Add(new FBEncoderCaptureBehavior()
            {
                Priority       = 0,
                ScreenshotPath = Environment.GetEnvironmentVariable("homepath") + "\\DropBox\\ScreenShots\\"
            });

            // start auto-update check
            AutoUpdate.DoUpdateCheck(cockpit, 10.0f);
        }