示例#1
0
        public void Initialize(Cockpit cockpit)
        {
            cockpit.Name = "modelCockpit";


            // Configure how the cockpit moves

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



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

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



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



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

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

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



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

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


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

            screenLayout.RecomputeLayout();


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

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

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

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

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

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

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


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

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