//--------------------------------------------------------------------------------------------------

        public void SelectByRectangle(int[] corners, bool includeTouched, ViewportController viewportController)
        {
            _MouseEventData.DetectedAisInteractives.Clear();
            _MouseEventData.DetectedEntities.Clear();
            _MouseEventData.DetectedShapes.Clear();

            if (Occt.Helper.Ais.PickFromContext(Workspace.AisContext, corners[0], corners[1], corners[2], corners[3], includeTouched,
                                                viewportController.Viewport.V3dView,
                                                _MouseEventData.DetectedAisInteractives, _MouseEventData.DetectedShapes) > 0)
            {
                var entities = _MouseEventData.DetectedAisInteractives.Select(detected => VisualShapes.GetVisibleEntity(detected)).Where(entity => entity != null);
                _MouseEventData.DetectedEntities.AddRange(entities);
            }
        }
        //--------------------------------------------------------------------------------------------------

        void InitWorkspace()
        {
            Workspace.InitV3dViewer();
            Workspace.InitAisContext();
            _InitVisualSettings();

            foreach (var view in Workspace.Viewports)
            {
                var viewCtrl = new ViewportController(view, this);
                _ViewControllers.Add(viewCtrl);
            }

            VisualShapes.InitEntities();
        }
        //--------------------------------------------------------------------------------------------------

        public void MouseUp(bool shiftKey, ViewportController viewportController)
        {
            bool wasSelecting = IsSelecting;

            IsSelecting = false;

            if (CurrentTool != null)
            {
                if (CurrentTool.OnMouseUp(_MouseEventData, shiftKey))
                {
                    // Handled by tool
                    return;
                }
            }

            if (_ToolActions.Any())
            {
                foreach (var toolAction in _ToolActions)
                {
                    if (toolAction.OnMouseUp(_MouseEventData, shiftKey))
                    {
                        // Handled by tool action
                        return;
                    }
                }
            }

            if (wasSelecting)
            {
                if (_MouseEventData.DetectedEntities.Any())
                {
                    // Shape selected
                    Selection.SelectEntities(_MouseEventData.DetectedEntities, !shiftKey);
                    Invalidate();
                }
                else
                {
                    // Empty click
                    if (!shiftKey)
                    {
                        Selection.SelectEntity(null);
                        Invalidate();
                    }
                }
            }
        }
Exemple #4
0
        //--------------------------------------------------------------------------------------------------

        public ViewportHwndHost(ViewportController viewportController)
        {
            _ViewportController = viewportController;
        }
        //--------------------------------------------------------------------------------------------------

        public void SelectByPolyline(List <ValueTuple <int, int> > pointList, bool includeTouched, ViewportController viewportController)
        {
            _MouseEventData.DetectedAisInteractives.Clear();
            _MouseEventData.DetectedEntities.Clear();
            _MouseEventData.DetectedShapes.Clear();

            if (Occt.Helper.Ais.PickFromContext(Workspace.AisContext, pointList, includeTouched,
                                                viewportController.Viewport.V3dView,
                                                _MouseEventData.DetectedAisInteractives, _MouseEventData.DetectedShapes) > 0)
            {
                var entities = _MouseEventData.DetectedAisInteractives.Select(detected => VisualShapes.GetVisibleEntity(detected)).Where(entity => entity != null);
                _MouseEventData.DetectedEntities.AddRange(entities);
            }
        }
        //--------------------------------------------------------------------------------------------------

        public void MouseMove(Point pos, ViewportController viewportController)
        {
            _LastMouseMovePosition           = pos;
            _LastMouseMoveViewportController = viewportController;

            Selection.Update();

            if (pos.X < 0 || pos.Y < 0)
            {
                // Position is out of bounds, reset highlighting
                Workspace.AisContext.MoveTo(Int32.MinValue, Int32.MinValue, viewportController.Viewport.V3dView, false);;
                Invalidate(true);
                return;
            }

            var status = Workspace.AisContext.MoveTo(Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), viewportController.Viewport.V3dView, false);

            Invalidate(true);

            if (status != AIS_StatusOfDetection.AIS_SOD_Error)
            {
                Pnt rawPoint;
                if (!viewportController.Viewport.ScreenToPoint(Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), out rawPoint))
                {
                    IsMouseEventDataValid = false;
                    IsCursorPositionValid = false;
                    return;
                }

                Pnt planePoint;
                if (!viewportController.Viewport.ScreenToPoint(Workspace.WorkingPlane, Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), out planePoint))
                {
                    IsMouseEventDataValid = false;
                    IsCursorPositionValid = false;
                }

                _LastDetectedInteractive = null;
                _LastDetectedOwner       = null;
                InteractiveEntity detectedEntity = null;
                TopoDS_Shape      detectedShape  = null;
                if (Workspace.AisContext.HasDetected())
                {
                    _LastDetectedInteractive = Workspace.AisContext.DetectedInteractive();
                    _LastDetectedOwner       = Workspace.AisContext.DetectedOwner();
                    detectedEntity           = VisualShapes.GetVisibleEntity(_LastDetectedInteractive);
                    detectedShape            = Occt.Helper.Ais.GetDetectedShapeFromContext(Workspace.AisContext);
                }

                _MouseEventData.Set(viewportController.Viewport, pos, rawPoint, planePoint, detectedEntity, _LastDetectedInteractive, detectedShape);
                IsMouseEventDataValid = true;

                CursorPosition        = planePoint;
                CursorPosition2d      = Workspace.WorkingPlane.Parameters(planePoint);
                IsCursorPositionValid = true;
                bool handled = false;

                if (CurrentTool != null)
                {
                    handled = CurrentTool.OnMouseMove(_MouseEventData);
                }

                if (_ToolActions.Any() && !handled)
                {
                    foreach (var toolAction in _ToolActions)
                    {
                        if (toolAction.OnMouseMove(_MouseEventData))
                        {
                            break;
                        }
                    }
                }

                if (_MouseEventData.ForceReDetection)
                {
                    Workspace.AisContext.MoveTo(Convert.ToInt32(pos.X), Convert.ToInt32(pos.Y), viewportController.Viewport.V3dView, false);
                }

                return;
            }

            IsMouseEventDataValid = false;
            IsCursorPositionValid = false;
        }