Ejemplo n.º 1
0
        public void RestoreToCurrent(string path)
        {
            DebugUtil.Log("[OGSerializer] Restoring scene from " + path);

            XmlDocument doc = new XmlDocument();

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

            // begin restore
            OGActions.BeginRestoreExistingScene();

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

            serializer.Restore(stream, OG.Scene);

            // restore datamodel
            RestoreDataModel(doc);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// "Reset" the DataModel for a new design
        /// </summary>
        public static void Reinitialize(FContext context, DesignTypes type)
        {
            DesignType = type;
            Context    = context;

            if (Model != null)
            {
                Model.OnDataModelModified -= OnDataModelModified;
            }
            Model = new OGDataModel();
            Model.Reinitialize(Context);
            Model.OnDataModelModified += notifyDataModelModified;

            OGActions.InitializeSocketDataModel();

            OGActions.InitializeCancelRouter();
            OGActions.InitializeAcceptRouter();

            WorkflowInitialized = true;
            OnWorfklowInitialized?.Invoke(null, EventArgs.Empty);
        }
Ejemplo n.º 3
0
        public static SocketDesignGraph Build()
        {
            ScanState scanState = new ScanState()
            {
                Name = ScanState.Identifier
            };
            RectifyState rectifyState = new RectifyState()
            {
                Name = RectifyState.Identifier
            };
            SocketDesignState socketState = new SocketDesignState()
            {
                Name = SocketDesignState.Identifier
            };

            SocketDesignGraph graph   = new SocketDesignGraph();
            WorkflowBuilder   builder = new WorkflowBuilder(graph);

            graph.AddState(scanState);
            graph.AddState(rectifyState);
            graph.AddState(socketState);


            WorkflowTransition toRectify = graph.AddTransition(scanState, rectifyState);

            toRectify.BeforeTransition.Add(() => {
                OG.Context.TransformManager.SetActiveGizmoType(TransformManager.NoGizmoType);
                OGActions.InitializeLegFromScan();
            });


            WorkflowTransition toSocket = graph.AddTransition(rectifyState, socketState);

            toSocket.BeforeTransition.Add(() => {
                OG.Context.TransformManager.SetActiveGizmoType(TransformManager.NoGizmoType);
            });

            WorkflowTransition backToRectify = graph.AddTransition(socketState, rectifyState);

            backToRectify.BeforeTransition.Add(() => {
                OG.Context.TransformManager.SetActiveGizmoType(TransformManager.NoGizmoType);
            });



            // scan tool states

            var trimScanTool = builder.AddState(OGWorkflow.TrimScanState, OGActions.BeginTrimScanTool);

            builder.AddTransition(scanState, trimScanTool, OGWorkflow.TrimScanStartT, OGActions.CanTrimScan, null, null);
            builder.AddTransition(trimScanTool, scanState, OGWorkflow.TrimScanAcceptT, OGActions.CanAcceptTrimScanTool, OGActions.AcceptTrimScanTool, null);
            builder.AddTransition(trimScanTool, scanState, OGWorkflow.TrimScanCancelT, null, OGActions.CancelTrimScanTool, null);

            var alignScanTool = builder.AddState(OGWorkflow.AlignScanState, OGActions.BeginAlignScanTool);

            builder.AddTransition(scanState, alignScanTool, OGWorkflow.AlignScanStartT, OGActions.CanAlignScan, null, null);
            builder.AddTransition(alignScanTool, scanState, OGWorkflow.AlignScanAcceptT, OGActions.CanAcceptAlignScanTool, OGActions.AcceptAlignScanTool, null);
            builder.AddTransition(alignScanTool, scanState, OGWorkflow.AlignScanCancelT, null, OGActions.CancelAlignScanTool, null);


            // rectify tool states

            var drawAreaTool = builder.AddState(OGWorkflow.DrawAreaState, OGActions.BeginDrawAreaTool);

            builder.AddTransition(rectifyState, drawAreaTool, OGWorkflow.DrawAreaStartT, OGActions.CanDrawArea, null, null);
            builder.AddTransition(drawAreaTool, rectifyState, OGWorkflow.DrawAreaExitT, null, OGActions.EndDrawAreaTool, null);

            var deformRingTool = builder.AddState(OGWorkflow.AddDeformRingState, OGActions.BeginDeformRingTool);

            builder.AddTransition(rectifyState, deformRingTool, OGWorkflow.AddDeformRingStartT, OGActions.CanAddDeformRing, null, null);
            builder.AddTransition(deformRingTool, rectifyState, OGWorkflow.AddDeformRingAcceptT, OGActions.CanAcceptDeformRingTool, OGActions.AcceptDeformRingTool, null);
            builder.AddTransition(deformRingTool, rectifyState, OGWorkflow.AddDeformRingCancelT, null, OGActions.CancelDeformRingTool, null);

            var sculptAreaTool = builder.AddState(OGWorkflow.SculptAreaState, OGActions.BeginSculptCurveTool);

            builder.AddTransition(rectifyState, sculptAreaTool, OGWorkflow.SculptAreaStartT, OGActions.CanSculptCurve, null, null);
            builder.AddTransition(sculptAreaTool, rectifyState, OGWorkflow.SculptAreaExitT, null, OGActions.EndSculptCurveTool, null);



            // socket tool states
            var drawTrimlineTool = builder.AddState(OGWorkflow.DrawTrimlineState, OGActions.BeginDrawTrimLineTool);

            builder.AddTransition(socketState, drawTrimlineTool, OGWorkflow.DrawTrimlineStartT, OGActions.CanDrawTrimLine, null, null);
            builder.AddTransition(drawTrimlineTool, socketState, OGWorkflow.DrawTrimlineExitT, null, OGActions.EndDrawTrimLineTool, null);

            var planeTrimlineTool = builder.AddState(OGWorkflow.PlaneTrimlineState, OGActions.BeginPlaneTrimLineTool);

            builder.AddTransition(socketState, planeTrimlineTool, OGWorkflow.PlaneTrimlineStartT, OGActions.CanAddPlaneTrimLine, null, null);
            builder.AddTransition(planeTrimlineTool, socketState, OGWorkflow.PlaneTrimlineAcceptT, OGActions.CanAcceptPlaneTrimLineTool, OGActions.AcceptPlaneTrimLineTool, null);
            builder.AddTransition(planeTrimlineTool, socketState, OGWorkflow.PlaneTrimlineCancelT, null, OGActions.CancelPlaneTrimLineTool, null);

            var sculptTrimlineTool = builder.AddState(OGWorkflow.SculptTrimlineState, OGActions.BeginSculptCurveTool);

            builder.AddTransition(socketState, sculptTrimlineTool, OGWorkflow.SculptTrimlineStartT, OGActions.CanSculptCurve, null, null);
            builder.AddTransition(sculptTrimlineTool, socketState, OGWorkflow.SculptTrimlineExitT, null, OGActions.EndSculptCurveTool, null);


            graph.LogF = DebugUtil.Log;   // print debug output


            return(graph);
        }
Ejemplo n.º 4
0
 private static void updateWorkflowForVR(object sender, EventArgs e)
 {
     OGActions.AddToAcceptRouter(OGVRWorkflow.VRAlignScanState, OGVRWorkflow.VRAlignScanAcceptT);
     OGActions.AddToCancelRouter(OGVRWorkflow.VRAlignScanState, OGVRWorkflow.VRAlignScanCancelT);
 }
Ejemplo n.º 5
0
        /// <summary>
        /// parse the DataModel section of the save file, and restore the scene/datamodel as necessary
        /// </summary>
        /// <param name="xml"></param>
        protected virtual void RestoreDataModel(XmlDocument xml)
        {
            // look up root datamodel (should only be one)
            XmlNodeList datamodels = xml.SelectNodes("//DataModel");
            XmlNode     datamodel  = datamodels[0];


            // find scan
            ScanSO scanSO = OG.Scene.FindSceneObjectsOfType <ScanSO>().FirstOrDefault();

            if (scanSO == null)
            {
                throw new Exception("OGSerializer.RestoreDataModel: no ScanSO?");
            }

            // [TODO] we have scanIn and scanOut, don't we?!?
            // start in scan state, restore the scan
            OGActions.RestoreSocketDesignFromScan(OG.Context, scanSO);


            // [TODO] should only do this transition if user has accepted scan
            //    (probably should have some current-state field in datamodel)
            OG.TransitionToState(RectifyState.Identifier);


            // restore LegModel deformation ops
            XmlNodeList deformationOps = datamodel.SelectNodes("LegDeformOp");

            foreach (XmlNode opNode in deformationOps)
            {
                string type    = opNode.Attributes["OpType"].InnerText;
                string so_uuid = opNode.Attributes["SceneObjectUUID"].InnerText;

                if (type == typeof(EnclosedRegionOffsetOp).ToString())
                {
                    EnclosedPatchSO patchSO = OG.Scene.FindByUUID(so_uuid) as EnclosedPatchSO;
                    var             newOp   = OGActions.AddNewRegionDeformation(patchSO, LegModel.LegDeformationTypes.Offset);
                    double          offset  = 0.0f;
                    if (double.TryParse(opNode.Attributes["Offset"].InnerText, out offset))
                    {
                        (newOp as EnclosedRegionOffsetOp).PushPullDistance = offset;
                    }
                }
                else if (type == typeof(EnclosedRegionSmoothOp).ToString())
                {
                    EnclosedPatchSO patchSO = OG.Scene.FindByUUID(so_uuid) as EnclosedPatchSO;
                    var             newOp   = OGActions.AddNewRegionDeformation(patchSO, LegModel.LegDeformationTypes.Smooth);
                    double          smooth  = 0.0f;
                    if (double.TryParse(opNode.Attributes["Smooth"].InnerText, out smooth))
                    {
                        (newOp as EnclosedRegionSmoothOp).SmoothAlpha = smooth;
                    }
                    double offset = 0.0f;
                    if (double.TryParse(opNode.Attributes["Offset"].InnerText, out offset))
                    {
                        (newOp as EnclosedRegionSmoothOp).OffsetDistance = offset;
                    }
                }
                else if (type == typeof(PlaneBandExpansionOp).ToString())
                {
                    PlaneIntersectionCurveSO curveSO = OG.Scene.FindByUUID(so_uuid) as PlaneIntersectionCurveSO;
                    var    newOp  = OGActions.AddNewPlaneBandExpansion(curveSO);
                    double extent = 0.0f;
                    if (double.TryParse(opNode.Attributes["Extent"].InnerText, out extent))
                    {
                        (newOp as PlaneBandExpansionOp).BandDistance = extent;
                    }
                    double offset = 0.0f;
                    if (double.TryParse(opNode.Attributes["Offset"].InnerText, out offset))
                    {
                        (newOp as PlaneBandExpansionOp).PushPullDistance = offset;
                    }
                    Vector3d origin = TryParseVector3(opNode.Attributes["Origin"].InnerText);
                    (newOp as PlaneBandExpansionOp).Origin = origin;
                    Vector3d normal = TryParseVector3(opNode.Attributes["Normal"].InnerText);
                    (newOp as PlaneBandExpansionOp).Normal = normal;
                }
                else if (type == typeof(LengthenOp).ToString())
                {
                    LengthenPivotSO pivotSO = OG.Scene.FindByUUID(so_uuid) as LengthenPivotSO;
                    LengthenOp      newOp   = OGActions.AddNewLengthenOp(pivotSO);
                    double          offset  = 0.0f;
                    if (double.TryParse(opNode.Attributes["Distance"].InnerText, out offset))
                    {
                        newOp.LengthenDistance = offset;
                    }
                }
            }


            // if we have a trimloop, restore it
            TrimLoopSO trimSO = OG.Scene.FindSceneObjectsOfType <TrimLoopSO>().FirstOrDefault();

            if (trimSO != null)
            {
                OG.TransitionToState(SocketDesignState.Identifier);
                OGActions.AddNewTrimCurve(trimSO);
            }

            // [TODO] restore socket enabled, parameters, etc
        }
Ejemplo n.º 6
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))
                {
                    OGActions.CancelCurrentTool();
                }
                else if (context.Scene.Selected.Count > 0)
                {
                    context.Scene.ClearSelection();
                }
                return(true);


                // ENTER AND LETTER A APPLY CURRENT TOOL IF POSSIBLE
            }
            else if (Input.GetKeyUp(KeyCode.Return) || Input.GetKeyUp(KeyCode.A))
            {
                if (OGActions.CanAcceptCurrentTool())
                {
                    OGActions.AcceptCurrentTool();
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.Delete))
            {
                if (context.Scene.Selected.Count == 1)
                {
                    DeleteSOChange change = new DeleteSOChange()
                    {
                        scene = context.Scene, so = context.Scene.Selected[0]
                    };
                    context.Scene.History.PushChange(change, false);
                }
                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);
            }
            else if (Input.GetKeyUp(KeyCode.D))
            {
                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);
            }
            else if (Input.GetKeyUp(KeyCode.Backspace))
            {
                if (OG.IsInState(OGWorkflow.SocketState) && OG.CanTransitionToState(OGWorkflow.RectifyState))
                {
                    OG.TransitionToState(OGWorkflow.RectifyState);
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.UpArrow) || Input.GetKeyUp(KeyCode.DownArrow))
            {
                float sign = Input.GetKeyUp(KeyCode.UpArrow) ? 1 : -1;
                if (OG.LastActiveModelingOp != null)
                {
                    if (OG.LastActiveModelingOp is PlaneBandExpansionOp)
                    {
                        PlaneBandExpansionOp deform = OG.LastActiveModelingOp as PlaneBandExpansionOp;
                        deform.BandDistance = MathUtil.Clamp(deform.BandDistance + sign * 2.0f, 10.0f, 1000.0f);
                    }
                    if (OG.LastActiveModelingOp is EnclosedRegionSmoothOp)
                    {
                        EnclosedRegionSmoothOp deform = OG.LastActiveModelingOp as EnclosedRegionSmoothOp;
                        deform.OffsetDistance += sign * 0.1f;
                    }
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.LeftArrow) || Input.GetKeyUp(KeyCode.RightArrow))
            {
                float sign = Input.GetKeyUp(KeyCode.RightArrow) ? 1 : -1;
                if (OG.LastActiveModelingOp != null)
                {
                    if (OG.LastActiveModelingOp is PlaneBandExpansionOp)
                    {
                        PlaneBandExpansionOp deform = OG.LastActiveModelingOp as PlaneBandExpansionOp;
                        deform.PushPullDistance += sign * 0.25f;
                    }
                    if (OG.LastActiveModelingOp is EnclosedRegionOffsetOp)
                    {
                        EnclosedRegionOffsetOp deform = OG.LastActiveModelingOp as EnclosedRegionOffsetOp;
                        deform.PushPullDistance += sign * 0.25f;
                    }
                    if (OG.LastActiveModelingOp is EnclosedRegionSmoothOp)
                    {
                        EnclosedRegionSmoothOp deform = OG.LastActiveModelingOp as EnclosedRegionSmoothOp;
                        deform.SmoothAlpha += sign * 0.1f;
                    }
                }
                return(true);
            }
            else if (Input.GetKeyUp(KeyCode.LeftBracket) || Input.GetKeyUp(KeyCode.RightBracket))
            {
                SculptCurveTool tool = OG.ActiveToolAs <SculptCurveTool>();
                if (tool != null)
                {
                    float  fSign    = Input.GetKeyUp(KeyCode.LeftBracket) ? -1 : 1;
                    double fRadiusS = tool.Radius.SceneValue;
                    fRadiusS    = MathUtil.Clamp(fRadiusS + 2.5 * fSign, 5.0, 100.0);
                    tool.Radius = fDimension.Scene(fRadiusS);
                }
                return(true);
            }
            else if (bCtrlDown && Input.GetKeyUp(KeyCode.Q))
            {
                FPlatform.QuitApplication();
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 7
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;
            var tracker = SmoothCockpitTracker.Enable(cockpit);

            //cockpit.TiltAngle = 10.0f;
            cockpit.TiltAngle     = 0.0f;
            tracker.ShowIndicator = false;



            FScene Scene = cockpit.Scene;
            //ISurfaceBoxRegion region = new CylinderBoxRegion() { Radius = 1.0f, MinHeight = -1.0f, MaxHeight = 0.3f, HorzDegreeLeft = 50, HorzDegreeRight = 50 };
            ISurfaceBoxRegion region = new SphereBoxRegion()
            {
                Radius = 1.0f, VertDegreeBottom = 30, VertDegreeTop = 10, HorzDegreeLeft = 55, HorzDegreeRight = 55
            };
            //Frame3f f = new Frame3f(new Vector3f(0, 0, 1), Vector3f.AxisZ);
            //f.RotateAround(Vector3f.Zero, Quaternionf.AxisAngleD(Vector3f.AxisX, 10));
            //f.RotateAround(Vector3f.Zero, Quaternionf.AxisAngleD(Vector3f.AxisY, -50));
            //ISurfaceBoxRegion region = new PlaneBoxRegion() {
            //    Frame = f, Dimensions = new AxisAlignedBox2f(-0.15f, -0.5f, 0.5f, 0.2f)
            //};
            BoxContainer leftPanelContainer           = new BoxContainer(new BoxRegionContainerProvider(cockpit, region));
            PinnedBoxes3DLayoutSolver leftPanelLayout = new PinnedBoxes3DLayoutSolver(leftPanelContainer, region);
            PinnedBoxesLayout         layout          = new PinnedBoxesLayout(cockpit, leftPanelLayout)
            {
                StandardDepth = 0.0f
            };

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


            ISurfaceBoxRegion cylregion = new CylinderBoxRegion()
            {
                Radius = 1.0f, MinHeight = -1.0f, MaxHeight = 0.2f, HorzDegreeLeft = 55, HorzDegreeRight = 50
            };
            BoxContainer cylPanelContainer           = new BoxContainer(new BoxRegionContainerProvider(cockpit, cylregion));
            PinnedBoxes3DLayoutSolver cylPanelLayout = new PinnedBoxes3DLayoutSolver(cylPanelContainer, cylregion);
            PinnedBoxesLayout         cyl_layout     = new PinnedBoxesLayout(cockpit, cylPanelLayout)
            {
                StandardDepth = 0.0f
            };

            cockpit.AddLayout(cyl_layout, "cylinder", true);


            float button_width   = 0.32f;
            float button_height  = 0.075f;
            float button_spacing = 0.015f;
            float text_height    = button_height * 0.6f;
            float row_y_shift    = button_height + button_spacing;



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


            /*
             * Scan UI
             */

            HUDElementList scan_buttons_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Vertical
            };


            HUDLabel trim_scan_button = MakeButtonF("Trim Scan", button_width);

            trim_scan_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.TrimScanStartT);
            };
            scan_buttons_list.AddListItem(trim_scan_button);

            HUDLabel align_scan_button = MakeButtonF("Align Scan", button_width);

            align_scan_button.OnClicked += (sender, e) => {
                OG.Transition(OGVRWorkflow.VRAlignScanStartT);
            };
            scan_buttons_list.AddListItem(align_scan_button);

            HUDLabel accept_scan_button = MakeButtonF("Done Scan", button_width);

            accept_scan_button.OnClicked += (sender, e) => {
                OG.TransitionToState(RectifyState.Identifier);
            };
            scan_buttons_list.AddListItem(accept_scan_button);

            scan_buttons_list.Create();
            scan_buttons_list.Name = "scan_buttons_list";
            cyl_layout.Add(scan_buttons_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(scan_buttons_list, BoxPosition.CenterTop),
                PinTargetPoint2D = LayoutUtil.BoxPointF(cylPanelContainer, BoxPosition.TopLeft)
            });


            /*
             * Model UI UI
             */


            HUDElementList model_buttons_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Vertical
            };


            HUDLabel draw_offset_area_button = MakeButtonF("Offset Area", button_width);

            draw_offset_area_button.OnClicked += (sender, e) => {
                OGActions.CurrentLegDeformType = LegModel.LegDeformationTypes.Offset;
                OG.Transition(OGWorkflow.DrawAreaStartT);
            };
            model_buttons_list.AddListItem(draw_offset_area_button);

            HUDLabel draw_smooth_area_button = MakeButtonF("Smooth Area", button_width);

            draw_smooth_area_button.OnClicked += (sender, e) => {
                OGActions.CurrentLegDeformType = LegModel.LegDeformationTypes.Smooth;
                OG.Transition(OGWorkflow.DrawAreaStartT);
            };
            model_buttons_list.AddListItem(draw_smooth_area_button);


            HUDLabel add_plane_button = MakeButtonF("Add Plane", button_width);

            add_plane_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.AddDeformRingStartT);
            };
            model_buttons_list.AddListItem(add_plane_button);

            HUDLabel add_lengthen_button = MakeButtonF("Add Lengthen", button_width);

            add_lengthen_button.OnClicked += (sender, e) => {
                if (OGActions.CanAddLengthenOp())
                {
                    OGActions.AddLengthenOp();
                }
            };
            model_buttons_list.AddListItem(add_lengthen_button);

            HUDLabel       sculpt_curve_model_button = MakeButtonF("Sculpt Curve", button_width);
            WorkflowRouter sculpt_router             = WorkflowRouter.Build(new[] {
                OGWorkflow.RectifyState, OGWorkflow.SculptAreaStartT,
                OGWorkflow.SocketState, OGWorkflow.SculptTrimlineStartT
            });

            sculpt_curve_model_button.OnClicked += (sender, e) => {
                sculpt_router.Apply(OG.Model.Workflow);
            };
            model_buttons_list.AddListItem(sculpt_curve_model_button);


            HUDLabel accept_rectify_button = MakeButtonF("Begin Socket", button_width);

            accept_rectify_button.OnClicked += (sender, e) => {
                OG.TransitionToState(SocketDesignState.Identifier);
                OG.Leg.SetOpWidgetVisibility(false);
            };
            model_buttons_list.AddListItem(accept_rectify_button);


            model_buttons_list.Create();
            model_buttons_list.Name = "model_buttons_list";
            cyl_layout.Add(model_buttons_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(model_buttons_list, BoxPosition.CenterTop),
                PinTargetPoint2D = LayoutUtil.BoxPointF(cylPanelContainer, BoxPosition.TopLeft)
            });



            /*
             * Model UI UI
             */


            HUDElementList socket_buttons_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Vertical
            };



            HUDLabel draw_trim_line_button = MakeButtonF("Draw Trimline", button_width);

            draw_trim_line_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.DrawTrimlineStartT);
            };
            socket_buttons_list.AddListItem(draw_trim_line_button);

            HUDLabel plane_trim_line_button = MakeButtonF("Plane Trimline", button_width);

            plane_trim_line_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.PlaneTrimlineStartT);
            };
            socket_buttons_list.AddListItem(plane_trim_line_button);

            HUDLabel sculpt_trimline_button = MakeButtonF("Sculpt Trimline", button_width);

            sculpt_trimline_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.SculptTrimlineStartT);
            };
            socket_buttons_list.AddListItem(sculpt_trimline_button);

            HUDLabel add_socket_button = MakeButtonF("Add Socket", button_width);

            add_socket_button.OnClicked += (sender, e) => {
                if (OGActions.CanAddSocket())
                {
                    OGActions.AddSocket();
                }
            };
            socket_buttons_list.AddListItem(add_socket_button);

            HUDLabel export_socket_button = MakeButtonF("Export", button_width);

            export_socket_button.OnClicked += (sender, e) => {
                if (OGActions.CanExportSocket())
                {
                    OGActions.ExportSocket();
                }
            };
            socket_buttons_list.AddListItem(export_socket_button);

            // align button list top top-left of ui
            socket_buttons_list.Create();
            socket_buttons_list.Name = "socket_buttons";
            cyl_layout.Add(socket_buttons_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(socket_buttons_list, BoxPosition.CenterTop),
                PinTargetPoint2D = LayoutUtil.BoxPointF(cylPanelContainer, BoxPosition.TopLeft)
            });



            HUDElementList ok_cancel_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Horizontal
            };

            HUDLabel accept_button = MakeButtonF("Accept", button_width * 0.75f);

            accept_button.OnClicked += (sender, e) => {
                OGActions.AcceptCurrentTool();
            };

            HUDLabel cancel_button = MakeButtonF("Cancel", button_width * 0.75f);

            cancel_button.OnClicked += (sender, e) => {
                OGActions.CancelCurrentTool();
            };

            ok_cancel_list.AddListItem(accept_button);
            ok_cancel_list.AddListItem(cancel_button);


            // align button list top top-left of ui
            ok_cancel_list.Create();
            ok_cancel_list.Name = "ok_cancel_list";
            layout.Add(ok_cancel_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(ok_cancel_list, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(leftPanelContainer, BoxPosition.BottomLeft)
            });



            HUDElementList size_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Horizontal
            };

            HUDLabel size_1to1 = MakeButtonF("Real Size", button_width * 0.75f);

            size_1to1.OnClicked += (sender, e) => {
                OGActions.SetSizeMode(OGActions.SizeModes.RealSize);
                OGActions.RecenterVRView(false);
            };

            HUDLabel size_medium = MakeButtonF("Zoom Size", button_width * 0.75f);

            size_medium.OnClicked += (sender, e) => {
                OGActions.SetSizeMode(OGActions.SizeModes.DemoSize);
                OGActions.RecenterVRView(false);
            };

            size_list.AddListItem(size_1to1);
            size_list.AddListItem(size_medium);

            size_list.Create();
            size_list.Name = "size_list";
            layout.Add(size_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(size_list, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(leftPanelContainer, BoxPosition.BottomLeft),
                FrameAxesShift   = new Vector3f(0, -row_y_shift, 0)
            });



            HUDElementList view_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Horizontal
            };


            HUDLabel recenter_button = MakeButtonF("Recenter", 2 * button_width * 0.75f);

            recenter_button.OnClicked += (sender, e) => {
                OGActions.RecenterVRView(true);
            };

            view_list.AddListItem(recenter_button);

            view_list.Create();
            view_list.Name = "view_list";
            layout.Add(view_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(view_list, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(leftPanelContainer, BoxPosition.BottomLeft),
                FrameAxesShift   = new Vector3f(0, -2 * row_y_shift, 0)
            });



            HUDElementList capture_list = new HUDElementList()
            {
                Width     = button_width,
                Height    = button_height,
                Spacing   = button_spacing,
                SizeMode  = HUDElementList.SizeModes.AutoSizeToFit,
                Direction = HUDElementList.ListDirection.Horizontal
            };

            HUDLabel capture_button = MakeButtonF("Capture", button_width * 0.75f);

            capture_button.OnClicked += (sender, e) => {
                if (FBCapture.CaptureOption.Active != null)
                {
                    if (capture_button.Text == "Capture")
                    {
                        DebugUtil.Log("Starting 2D Capture...");
                        FBCapture.CaptureOption.Active.doSurroundCaptureOption = false;
                        cockpit.Context.RegisterNextFrameAction(() => {
                            //FBCapture.CaptureOption.Active.videoWidth = 4096;
                            //FBCapture.CaptureOption.Active.videoHeight = 2048;
                            FBCapture.CaptureOption.Active.StartCaptureVideo();
                            capture_button.Text = "Stop";
                        });
                    }
                    else
                    {
                        FBCapture.CaptureOption.Active.StopCaptureVideo();
                        capture_button.Text = "Capture";
                    }
                }
            };


            HUDLabel vrcapture_button = MakeButtonF("VRCapture", button_width * 0.75f);

            vrcapture_button.OnClicked += (sender, e) => {
                if (FBCapture.CaptureOption.Active != null)
                {
                    if (vrcapture_button.Text == "VRCapture")
                    {
                        // [RMS] when we set this flag, we need to give CaptureOption.Update() a chance to see
                        //  it, which means we need to wait up to 2 frames
                        FBCapture.CaptureOption.Active.doSurroundCaptureOption = true;
                        cockpit.Context.RegisterNextFrameAction(() => {
                            cockpit.Context.RegisterNextFrameAction(() => {
                                GameObject encoderObj         = GameObject.Find("EncoderObject");
                                encoderObj.transform.position = Camera.main.transform.position;
                                encoderObj.transform.rotation = Quaternionf.Identity;
                                GameObject head = UnityUtil.FindGameObjectByName("VRHead");
                                head.SetVisible(false);
                                FBCapture.CaptureOption.Active.StartCaptureVideo();
                                vrcapture_button.Text = "Stop";
                            });
                        });
                    }
                    else
                    {
                        FBCapture.CaptureOption.Active.StopCaptureVideo();
                        vrcapture_button.Text = "VRCapture";
                    }
                }
            };

            capture_list.AddListItem(capture_button);
            capture_list.AddListItem(vrcapture_button);


            // align button list top top-left of ui
            capture_list.Create();
            capture_list.Name = "capture_list";
            layout.Add(capture_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.LocalBoxPointF(capture_list, BoxPosition.CenterBottom),
                PinTargetPoint2D = LayoutUtil.BoxPointF(leftPanelContainer, BoxPosition.BottomLeft),
                FrameAxesShift   = new Vector3f(0, -3 * row_y_shift, 0)
            });



            leftPanelLayout.RecomputeLayout();
            leftPanelLayout.RecomputeLayout();
            leftPanelLayout.RecomputeLayout();
            leftPanelLayout.RecomputeLayout();
            leftPanelLayout.RecomputeLayout();

            cylPanelLayout.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 OrthoVRKeyHandler(cockpit.Context));

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

            cockpit.InputBehaviors.Add(new SpatialDeviceGrabViewBehavior(cockpit)
            {
                Priority = 2
            });

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


            // selection / multi-selection behaviors
            cockpit.InputBehaviors.Add(new MouseMultiSelectBehavior(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 SpatialDeviceDeselectBehavior(cockpit.Context)
            {
                Priority = 999
            });



            // update buttons enable/disable on state transitions, selection changes
            string main_state = "";
            Action updateStateChangeButtons = () => {
                if (OG.IsInState(OGWorkflow.ScanState))
                {
                    main_state = OGWorkflow.ScanState;
                }
                else if (OG.IsInState(OGWorkflow.RectifyState))
                {
                    main_state = OGWorkflow.RectifyState;
                }
                else if (OG.IsInState(OGWorkflow.SocketState))
                {
                    main_state = OGWorkflow.SocketState;
                }

                scan_buttons_list.IsVisible   = (main_state == OGWorkflow.ScanState);
                model_buttons_list.IsVisible  = (main_state == OGWorkflow.RectifyState);
                socket_buttons_list.IsVisible = (main_state == OGWorkflow.SocketState);

                trim_scan_button.Enabled   = OG.CanTransition(OGWorkflow.TrimScanStartT);
                align_scan_button.Enabled  = OG.CanTransition(OGVRWorkflow.VRAlignScanStartT);
                accept_scan_button.Enabled =
                    OG.IsInState(ScanState.Identifier) && OG.CanTransitionToState(RectifyState.Identifier);

                draw_offset_area_button.Enabled = OG.CanTransition(OGWorkflow.DrawAreaStartT);
                draw_smooth_area_button.Enabled = OG.CanTransition(OGWorkflow.DrawAreaStartT);
                add_plane_button.Enabled        = OG.CanTransition(OGWorkflow.AddDeformRingStartT);
                add_lengthen_button.Enabled     = OGActions.CanAddLengthenOp();
                accept_rectify_button.Enabled   = OG.IsInState(RectifyState.Identifier) &&
                                                  OG.CanTransitionToState(SocketDesignState.Identifier);

                draw_trim_line_button.Enabled  = OG.CanTransition(OGWorkflow.DrawTrimlineStartT);
                plane_trim_line_button.Enabled = OG.CanTransition(OGWorkflow.PlaneTrimlineStartT);
                add_socket_button.Enabled      = OGActions.CanAddSocket();
                export_socket_button.Enabled   = OGActions.CanExportSocket();

                sculpt_curve_model_button.Enabled = sculpt_router.CanApply(OG.Model.Workflow);
                sculpt_trimline_button.Enabled    = OG.CanTransition(OGWorkflow.SculptTrimlineStartT);
            };

            OG.OnWorfklowInitialized            += (o, e) => { updateStateChangeButtons(); };
            OG.OnStateTransition                += (from, to) => { updateStateChangeButtons(); };
            OG.OnDataModelModified              += (from, to) => { updateStateChangeButtons(); };
            cockpit.Scene.SelectionChangedEvent += (o, e) => { if (OG.WorkflowInitialized)
                                                               {
                                                                   updateStateChangeButtons();
                                                               }
            };
            cockpit.Scene.ChangedEvent += (scene, so, type) => { if (OG.WorkflowInitialized)
                                                                 {
                                                                     updateStateChangeButtons();
                                                                 }
            };

            // accept/cancel buttons need to be checked every frame because the CanApply state
            // could change at any time, and there is no event about it
            cockpit.Context.RegisterEveryFrameAction("update_buttons", () => {
                if (cockpit.Context.ToolManager.ActiveRightTool != null)
                {
                    cancel_button.Enabled = true;
                    accept_button.Enabled = cockpit.Context.ToolManager.ActiveRightTool.CanApply;
                }
                else
                {
                    cancel_button.Enabled = accept_button.Enabled = false;
                }

                // [RMS] currently this state changes outside workflow state changes...
                add_socket_button.Enabled = OGActions.CanAddSocket();
            });
        }
Ejemplo n.º 8
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;



            FScene       Scene                     = cockpit.Scene;
            BoxContainer screenContainer           = new BoxContainer(new Cockpit2DContainerProvider(cockpit));
            PinnedBoxes2DLayoutSolver screenLayout = new PinnedBoxes2DLayoutSolver(screenContainer);
            PinnedBoxesLayout         layout       = new PinnedBoxesLayout(cockpit, screenLayout)
            {
                StandardDepth = 1.5f
            };

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


            Func <string, float, HUDLabel> MakeButtonF = (label, buttonW) => {
                HUDLabel button = new HUDLabel()
                {
                    Shape             = OrthogenUI.MakeMenuButtonRect(buttonW, OrthogenUI.MenuButtonHeight),
                    TextHeight        = OrthogenUI.MenuButtonTextHeight,
                    AlignmentHorz     = HorizontalAlignment.Center,
                    BackgroundColor   = OrthogenUI.ButtonBGColor,
                    TextColor         = OrthogenUI.ButtonTextColor,
                    DisabledTextColor = OrthogenUI.DisabledButtonTextColor,
                    Text         = label,
                    EnableBorder = true, BorderWidth = OrthogenUI.StandardButtonBorderWidth, BorderColor = OrthogenUI.ButtonTextColor
                };
                button.Create();
                button.Name    = label;
                button.Enabled = true;
                return(button);
            };
            Func <string, float, float, HUDSpacer> MakeSpacerF = (label, spacerw, spacerh) => {
                HUDSpacer spacer = new HUDSpacer()
                {
                    Shape = new HUDShape(HUDShapeType.Rectangle, spacerw, spacerh)
                };
                spacer.Create();
                spacer.Name = label;
                return(spacer);
            };


            HUDElementList button_list = new HUDElementList()
            {
                Width     = OrthogenUI.MenuButtonWidth,
                Height    = 5 * OrthogenUI.MenuButtonHeight,
                Spacing   = 10 * OrthogenUI.PixelScale,
                Direction = HUDElementList.ListDirection.Vertical
            };



            HUDLabel trim_scan_button = MakeButtonF("Trim Scan", OrthogenUI.MenuButtonWidth);

            trim_scan_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.TrimScanStartT);
            };
            button_list.AddListItem(trim_scan_button);

            HUDLabel align_scan_button = MakeButtonF("Align Scan", OrthogenUI.MenuButtonWidth);

            align_scan_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.AlignScanStartT);
            };
            button_list.AddListItem(align_scan_button);


            HUDLabel accept_scan_button = MakeButtonF("Done Scan", OrthogenUI.MenuButtonWidth);

            accept_scan_button.OnClicked += (sender, e) => {
                OG.TransitionToState(RectifyState.Identifier);
            };
            button_list.AddListItem(accept_scan_button);



            button_list.AddListItem(MakeSpacerF("space", OrthogenUI.MenuButtonWidth, 0.5f * OrthogenUI.MenuButtonHeight));


            HUDLabel draw_offset_area_button = MakeButtonF("Offset Area", OrthogenUI.MenuButtonWidth);

            draw_offset_area_button.OnClicked += (sender, e) => {
                OGActions.CurrentLegDeformType = LegModel.LegDeformationTypes.Offset;
                OG.Transition(OGWorkflow.DrawAreaStartT);
            };
            button_list.AddListItem(draw_offset_area_button);

            HUDLabel draw_smooth_area_button = MakeButtonF("Smooth Area", OrthogenUI.MenuButtonWidth);

            draw_smooth_area_button.OnClicked += (sender, e) => {
                OGActions.CurrentLegDeformType = LegModel.LegDeformationTypes.Smooth;
                OG.Transition(OGWorkflow.DrawAreaStartT);
            };
            button_list.AddListItem(draw_smooth_area_button);


            HUDLabel add_plane_button = MakeButtonF("Add Plane", OrthogenUI.MenuButtonWidth);

            add_plane_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.AddDeformRingStartT);
            };
            button_list.AddListItem(add_plane_button);

            HUDLabel add_lengthen_button = MakeButtonF("Add Lengthen", OrthogenUI.MenuButtonWidth);

            add_lengthen_button.OnClicked += (sender, e) => {
                if (OGActions.CanAddLengthenOp())
                {
                    OGActions.AddLengthenOp();
                }
            };
            button_list.AddListItem(add_lengthen_button);


            HUDLabel       sculpt_curve_button = MakeButtonF("Sculpt Curve", OrthogenUI.MenuButtonWidth);
            WorkflowRouter sculpt_router       = WorkflowRouter.Build(new[] {
                OGWorkflow.RectifyState, OGWorkflow.SculptAreaStartT,
                OGWorkflow.SocketState, OGWorkflow.SculptTrimlineStartT
            });

            sculpt_curve_button.OnClicked += (sender, e) => {
                sculpt_router.Apply(OG.Model.Workflow);
            };
            button_list.AddListItem(sculpt_curve_button);


            HUDLabel accept_rectify_button = MakeButtonF("Begin Socket", OrthogenUI.MenuButtonWidth);

            accept_rectify_button.OnClicked += (sender, e) => {
                OG.Leg.SetOpWidgetVisibility(false);
                OG.TransitionToState(SocketDesignState.Identifier);
            };
            button_list.AddListItem(accept_rectify_button);



            button_list.AddListItem(MakeSpacerF("space", OrthogenUI.MenuButtonWidth, 0.5f * OrthogenUI.MenuButtonHeight));



            HUDLabel draw_trim_line_button = MakeButtonF("Draw Trimline", OrthogenUI.MenuButtonWidth);

            draw_trim_line_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.DrawTrimlineStartT);
            };
            button_list.AddListItem(draw_trim_line_button);

            HUDLabel plane_trim_line_button = MakeButtonF("Plane Trimline", OrthogenUI.MenuButtonWidth);

            plane_trim_line_button.OnClicked += (sender, e) => {
                OG.Transition(OGWorkflow.PlaneTrimlineStartT);
            };
            button_list.AddListItem(plane_trim_line_button);

            HUDLabel add_socket_button = MakeButtonF("Add Socket", OrthogenUI.MenuButtonWidth);

            add_socket_button.OnClicked += (sender, e) => {
                if (OGActions.CanAddSocket())
                {
                    OGActions.AddSocket();
                }
            };
            button_list.AddListItem(add_socket_button);

            HUDLabel export_socket_button = MakeButtonF("Export", OrthogenUI.MenuButtonWidth);

            export_socket_button.OnClicked += (sender, e) => {
                if (OGActions.CanExportSocket())
                {
                    OGActions.ExportSocket();
                }
            };
            button_list.AddListItem(export_socket_button);



            button_list.AddListItem(MakeSpacerF("space", OrthogenUI.MenuButtonWidth, 1.0f * OrthogenUI.MenuButtonHeight));


            HUDLabel accept_button = MakeButtonF("Accept", OrthogenUI.MenuButtonWidth);

            accept_button.OnClicked += (sender, e) => {
                OGActions.AcceptCurrentTool();
            };


            HUDLabel cancel_button = MakeButtonF("Cancel", OrthogenUI.MenuButtonWidth);

            cancel_button.OnClicked += (sender, e) => {
                OGActions.CancelCurrentTool();
            };
            button_list.AddListItem(accept_button);
            button_list.AddListItem(cancel_button);



            button_list.Create();
            button_list.Name = "button_bar";

            // align button list to center of timeline
            layout.Add(button_list, new LayoutOptions()
            {
                Flags            = LayoutFlags.None,
                PinSourcePoint2D = LayoutUtil.BoxPointF(button_list, BoxPosition.TopLeft),
                PinTargetPoint2D = LayoutUtil.BoxPointF(screenContainer, BoxPosition.TopLeft, 10 * OrthogenUI.PixelScale * (Vector2f.AxisX - Vector2f.AxisY))
            });

            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 OrthoGenKeyHandler(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 = 10.0f,
                ActivateF = MouseBehaviors.MiddleButtonPressedF, ContinueF = MouseBehaviors.MiddleButtonDownF
            });


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

            // 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 = 1.0f, TouchPanSpeed = 0.3f
            });


            // update buttons enable/disable on state transitions, selection changes
            Action updateStateChangeButtons = () => {
                trim_scan_button.Enabled   = OG.CanTransition(OGWorkflow.TrimScanStartT);
                align_scan_button.Enabled  = OG.CanTransition(OGWorkflow.AlignScanStartT);
                accept_scan_button.Enabled =
                    OG.IsInState(ScanState.Identifier) && OG.CanTransitionToState(RectifyState.Identifier);

                draw_offset_area_button.Enabled = OG.CanTransition(OGWorkflow.DrawAreaStartT);
                draw_smooth_area_button.Enabled = OG.CanTransition(OGWorkflow.DrawAreaStartT);
                add_plane_button.Enabled        = OG.CanTransition(OGWorkflow.AddDeformRingStartT);
                add_lengthen_button.Enabled     = OGActions.CanAddLengthenOp();
                accept_rectify_button.Enabled   = OG.IsInState(RectifyState.Identifier) &&
                                                  OG.CanTransitionToState(SocketDesignState.Identifier);

                draw_trim_line_button.Enabled  = OG.CanTransition(OGWorkflow.DrawTrimlineStartT);
                plane_trim_line_button.Enabled = OG.CanTransition(OGWorkflow.PlaneTrimlineStartT);
                add_socket_button.Enabled      = OGActions.CanAddSocket();
                export_socket_button.Enabled   = OGActions.CanExportSocket();

                sculpt_curve_button.Enabled = sculpt_router.CanApply(OG.Model.Workflow);
            };

            OG.OnWorfklowInitialized            += (o, e) => { updateStateChangeButtons(); };
            OG.OnStateTransition                += (from, to) => { updateStateChangeButtons(); };
            OG.OnDataModelModified              += (from, to) => { updateStateChangeButtons(); };
            cockpit.Scene.SelectionChangedEvent += (o, e) => { if (OG.WorkflowInitialized)
                                                               {
                                                                   updateStateChangeButtons();
                                                               }
            };
            cockpit.Scene.ChangedEvent += (scene, so, type) => { if (OG.WorkflowInitialized)
                                                                 {
                                                                     updateStateChangeButtons();
                                                                 }
            };

            // accept/cancel buttons need to be checked every frame because the CanApply state
            // could change at any time, and there is no event about it
            cockpit.Context.RegisterEveryFrameAction("update_buttons", () => {
                if (cockpit.Context.ToolManager.ActiveRightTool != null)
                {
                    cancel_button.Enabled = true;
                    accept_button.Enabled = cockpit.Context.ToolManager.ActiveRightTool.CanApply;
                }
                else
                {
                    cancel_button.Enabled = accept_button.Enabled = false;
                }

                // [RMS] currently this state changes outside workflow state changes...
                add_socket_button.Enabled = OGActions.CanAddSocket();
            });
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Initialize datamodel / workflow / etc for Socket design, based on restored scan SO
 /// </summary>
 public static void RestoreSocketDesignFromScan(FContext context, ScanSO scanSO)
 {
     OG.Reinitialize(context, DesignTypes.StandardLegSocket);
     OGActions.RestoreScan(scanSO);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initialize datamodel / workflow / etc for Socket design, based on this scan mesh
 /// </summary>
 public static void BeginSocketDesignFromScan(FContext context, DMesh3 scanMesh)
 {
     context.NewScene(false, false);
     OG.Reinitialize(context, DesignTypes.StandardLegSocket);
     OGActions.InitializeScan(scanMesh);
 }