Ejemplo n.º 1
0
        protected void ResetRectangle()
        {
            if (_mouseEvents != null)
            {
                _mouseEvents.OnMouseMove  -= _onMouseMove_Delegate;
                _onMouseMove_Delegate      = null;
                _mouseEvents.OnMouseClick -= _onMouseClick_Delegate;
                _onMouseClick_Delegate     = null;
                _mouseEvents = null;
            }

            _rectangleLines                        = null;
            _horizontalMidPointAlign               = null;
            _verticalMidPointAlign                 = null;
            _userInputEvents.OnContextMenu        -= _userInputEvents_OnContextMenuDelegate;
            _userInputEvents_OnContextMenuDelegate = null;
            _planarSketch  = null;
            _drawingSketch = null;
            _secondSelectedSketchEntity = null;
            _inferredOriginPoint        = null;
            _inferredFinalPositionPoint = null;
            _firstSelectedSketchEntity  = null;
            _pickedPoint2d                  = null;
            _pickedSketchPoint              = null;
            _rectangleOriginSketchPoint     = null;
            _rectangleCoordSet              = null;
            _rectanglePointCoords           = null;
            _rectangleInteractionGraphics   = null;
            _rectangleGraphicsColorSet      = null;
            _interactionEvents.OnTerminate -= _onTerminate_Delegate;
            _interactionEvents.Stop();
            _interactionEvents = null;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Method that reacts to the click event by the user to instantiate the rectangle. This method starts
        /// the ChangeProcessor which encapsulates the drawing of the rectangle into one undo/redo mechanism.
        /// </summary>
        /// <param name="button"></param>
        /// <param name="shiftKeys"></param>
        /// <param name="modelPosition"></param>
        /// <param name="viewPosition"></param>
        /// <param name="view"></param>
        protected void OnMouseClick_LockTheRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition,
                                                     Point2d viewPosition, Inventor.View view)
        {
            try
            {
                if (button == MouseButtonEnum.kLeftMouseButton)
                {
                    _mouseEvents.MouseMoveEnabled = false;

                    if (_mouseEvents.PointInferences.Count > 0)
                    {
                        _inferredFinalPositionPoint = _mouseEvents.PointInferences[1];
                    }

                    _finalPosition = modelPosition;

                    _changeProcessor.Connect();

                    ResetRectangle();

                    _rectangleButton.ButtonPressed = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// When the user clicks on a point in the model, this method runs and creates an interaction graphics rectangle.
        /// It also subscribes to the Mouse Move event to allow for the size of the rectangle to be driven by the location
        /// of the mouse on the sketch. Ultimately, this method waits for the next click event, in which case it calls a
        /// new method to actually create the sketched rectangle.  It has separate paths to react to whether it's a part
        /// sketch or a drawing sketch.
        /// </summary>
        /// <param name="button"></param>
        /// <param name="shiftKeys"></param>
        /// <param name="modelPosition"></param>
        /// <param name="viewPosition"></param>
        /// <param name="view"></param>
        protected void OnMouseClick_CreateRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition,
                                                    Point2d viewPosition, Inventor.View view)
        {
            try
            {
                if (button == MouseButtonEnum.kLeftMouseButton)
                {
                    _onMouseMove_Delegate                  = new MouseEventsSink_OnMouseMoveEventHandler(OnMouseMove_DragCornerOfRectangle);
                    _mouseEvents.OnMouseClick             -= _onMouseClick_Delegate;
                    _onMouseClick_Delegate                 = null;
                    _userInputEvents.OnContextMenu        -= _userInputEvents_OnContextMenuDelegate;
                    _userInputEvents_OnContextMenuDelegate = null;

                    if (_inventorApplication.ActiveEditObject is PlanarSketch)
                    {
                        _planarSketch = (PlanarSketch)_inventorApplication.ActiveEditObject;

                        if (_mouseEvents.PointInferences.Count > 0)
                        {
                            _inferredOriginPoint = _mouseEvents.PointInferences[1];

                            switch (_inferredOriginPoint.InferenceType)
                            {
                            case PointInferenceEnum.kPtAtIntersection:
                                _firstSelectedSketchEntity            = (SketchEntity)_inferredOriginPoint.Entity[1];
                                _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2];
                                break;

                            case PointInferenceEnum.kPtOnCurve:
                                _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1];
                                break;

                            case PointInferenceEnum.kPtOnPt:
                                _firstSelectedSketchEntity  = (SketchPoint)_inferredOriginPoint.Entity[1];
                                _pickedSketchPoint          = (SketchPoint)_firstSelectedSketchEntity;
                                _rectangleOriginSketchPoint = _pickedSketchPoint;
                                break;

                            case PointInferenceEnum.kPtAtMidPoint:
                                _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1];
                                break;
                            }
                        }

                        _pickedPoint2d = _planarSketch.ModelToSketchSpace(modelPosition);

                        DrawInteractionRectangle();

                        _mouseEvents.OnMouseMove     += _onMouseMove_Delegate;
                        _mouseEvents.MouseMoveEnabled = true;
                    }
                    else if (_inventorApplication.ActiveEditObject is DrawingSketch)
                    {
                        _drawingSketch = (DrawingSketch)_inventorApplication.ActiveEditObject;

                        if (_mouseEvents.PointInferences.Count > 0)
                        {
                            _inferredOriginPoint = _mouseEvents.PointInferences[1];

                            switch (_inferredOriginPoint.InferenceType)
                            {
                            case PointInferenceEnum.kPtAtIntersection:
                                _firstSelectedSketchEntity            = (SketchEntity)_inferredOriginPoint.Entity[1];
                                _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2];
                                break;

                            case PointInferenceEnum.kPtOnCurve:
                                _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1];
                                break;

                            case PointInferenceEnum.kPtOnPt:
                                _firstSelectedSketchEntity  = (SketchPoint)_inferredOriginPoint.Entity[1];
                                _pickedSketchPoint          = (SketchPoint)_firstSelectedSketchEntity;
                                _rectangleOriginSketchPoint = _pickedSketchPoint;
                                break;

                            case PointInferenceEnum.kPtAtMidPoint:
                                _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1];
                                break;
                            }
                        }
                        PointToPoint2d(modelPosition, out _pickedPoint2d);

                        DrawInteractionRectangle();

                        _mouseEvents.OnMouseMove     += _onMouseMove_Delegate;
                        _mouseEvents.MouseMoveEnabled = true;
                    }
                    else
                    {
                        MessageBox.Show("You must be editing a sketch in order to use this tool.");
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        protected void ResetRectangle()
        {
            if (_mouseEvents != null)
            {
                _mouseEvents.OnMouseMove -= _onMouseMove_Delegate;
                _onMouseMove_Delegate = null;
                _mouseEvents.OnMouseClick -= _onMouseClick_Delegate;
                _onMouseClick_Delegate = null;
                _mouseEvents = null;
            }

            _rectangleLines = null;
            _horizontalMidPointAlign = null;
            _verticalMidPointAlign = null;
            _userInputEvents.OnContextMenu -= _userInputEvents_OnContextMenuDelegate;
            _userInputEvents_OnContextMenuDelegate = null;
            _planarSketch = null;
            _drawingSketch = null;
            _secondSelectedSketchEntity = null;
            _inferredOriginPoint = null;
            _inferredFinalPositionPoint = null;
            _firstSelectedSketchEntity = null;
            _pickedPoint2d = null;
            _pickedSketchPoint = null;
            _rectangleOriginSketchPoint = null;
            _rectangleCoordSet = null;
            _rectanglePointCoords = null;
            _rectangleInteractionGraphics = null;
            _rectangleGraphicsColorSet = null;
            _interactionEvents.OnTerminate -= _onTerminate_Delegate;
            _interactionEvents.Stop();
            _interactionEvents = null;
        }
        /// <summary>
        /// Method that reacts to the click event by the user to instantiate the rectangle. This method starts 
        /// the ChangeProcessor which encapsulates the drawing of the rectangle into one undo/redo mechanism.
        /// </summary>
        /// <param name="button"></param>
        /// <param name="shiftKeys"></param>
        /// <param name="modelPosition"></param>
        /// <param name="viewPosition"></param>
        /// <param name="view"></param>
        protected void OnMouseClick_LockTheRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition,
            Point2d viewPosition, Inventor.View view)
        {
            try
            {
                if (button == MouseButtonEnum.kLeftMouseButton)
                {
                    _mouseEvents.MouseMoveEnabled = false;

                    if (_mouseEvents.PointInferences.Count > 0)
                    {
                        _inferredFinalPositionPoint = _mouseEvents.PointInferences[1];
                    }

                    _finalPosition = modelPosition;

                    _changeProcessor.Connect();

                    ResetRectangle();

                    _rectangleButton.ButtonPressed = false;
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
        /// <summary>
        /// When the user clicks on a point in the model, this method runs and creates an interaction graphics rectangle. 
        /// It also subscribes to the Mouse Move event to allow for the size of the rectangle to be driven by the location 
        /// of the mouse on the sketch. Ultimately, this method waits for the next click event, in which case it calls a 
        /// new method to actually create the sketched rectangle.  It has separate paths to react to whether it's a part
        /// sketch or a drawing sketch.
        /// </summary>
        /// <param name="button"></param>
        /// <param name="shiftKeys"></param>
        /// <param name="modelPosition"></param>
        /// <param name="viewPosition"></param>
        /// <param name="view"></param>
        protected void OnMouseClick_CreateRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition,
            Point2d viewPosition, Inventor.View view)
        {
            try
            {
                if (button == MouseButtonEnum.kLeftMouseButton)
                {
                    _onMouseMove_Delegate = new MouseEventsSink_OnMouseMoveEventHandler(OnMouseMove_DragCornerOfRectangle);
                    _mouseEvents.OnMouseClick -= _onMouseClick_Delegate;
                    _onMouseClick_Delegate = null;
                    _userInputEvents.OnContextMenu -= _userInputEvents_OnContextMenuDelegate;
                    _userInputEvents_OnContextMenuDelegate = null;

                    if (_inventorApplication.ActiveEditObject is PlanarSketch)
                    {
                        _planarSketch = (PlanarSketch)_inventorApplication.ActiveEditObject;

                        if (_mouseEvents.PointInferences.Count > 0)
                        {
                            _inferredOriginPoint = _mouseEvents.PointInferences[1];

                            switch (_inferredOriginPoint.InferenceType)
                            {
                                case PointInferenceEnum.kPtAtIntersection:
                                    _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1];
                                    _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2];
                                    break;
                                case PointInferenceEnum.kPtOnCurve:
                                    _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1];
                                    break;
                                case PointInferenceEnum.kPtOnPt:
                                    _firstSelectedSketchEntity = (SketchPoint)_inferredOriginPoint.Entity[1];
                                    _pickedSketchPoint = (SketchPoint)_firstSelectedSketchEntity;
                                    _rectangleOriginSketchPoint = _pickedSketchPoint;
                                    break;
                                case PointInferenceEnum.kPtAtMidPoint:
                                    _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1];
                                    break;
                            }
                        }

                        _pickedPoint2d = _planarSketch.ModelToSketchSpace(modelPosition);

                        DrawInteractionRectangle();

                        _mouseEvents.OnMouseMove += _onMouseMove_Delegate;
                        _mouseEvents.MouseMoveEnabled = true;
                    }
                    else if (_inventorApplication.ActiveEditObject is DrawingSketch)
                    {
                        _drawingSketch = (DrawingSketch)_inventorApplication.ActiveEditObject;

                        if (_mouseEvents.PointInferences.Count > 0)
                        {
                            _inferredOriginPoint = _mouseEvents.PointInferences[1];

                            switch (_inferredOriginPoint.InferenceType)
                            {
                                case PointInferenceEnum.kPtAtIntersection:
                                    _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1];
                                    _firstInferredIntersectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[2];
                                    break;
                                case PointInferenceEnum.kPtOnCurve:
                                    _firstSelectedSketchEntity = (SketchEntity)_inferredOriginPoint.Entity[1];
                                    break;
                                case PointInferenceEnum.kPtOnPt:
                                    _firstSelectedSketchEntity = (SketchPoint)_inferredOriginPoint.Entity[1];
                                    _pickedSketchPoint = (SketchPoint)_firstSelectedSketchEntity;
                                    _rectangleOriginSketchPoint = _pickedSketchPoint;
                                    break;
                                case PointInferenceEnum.kPtAtMidPoint:
                                    _firstSelectedSketchEntity = (SketchLine)_inferredOriginPoint.Entity[1];
                                    break;
                            }
                        }
                        PointToPoint2d(modelPosition, out _pickedPoint2d);

                        DrawInteractionRectangle();

                        _mouseEvents.OnMouseMove += _onMouseMove_Delegate;
                        _mouseEvents.MouseMoveEnabled = true;
                    }
                    else
                        MessageBox.Show("You must be editing a sketch in order to use this tool.");
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }