/// <summary> /// When the appropriate rectangle button is clicked the button's OnExecute event handler /// calls this method to hook up the mouse click event which will wait for the user to select /// a point from which to start the drawing of the rectangle /// </summary> public virtual void StartRectangleInteraction() { _interactionEvents = _inventorApplication.CommandManager.CreateInteractionEvents(); _rectangleInteractionGraphics = _interactionEvents.InteractionGraphics; _rectangleClientGraphics = _rectangleInteractionGraphics.OverlayClientGraphics; _rectangleLineNode = _rectangleClientGraphics.AddNode(1); _rectangleGraphicsDataSets = _rectangleInteractionGraphics.GraphicsDataSets; _rectangleCoordSet = _rectangleGraphicsDataSets.CreateCoordinateSet(1); _rectangleIndexSet = _rectangleGraphicsDataSets.CreateIndexSet(1); _onTerminate_Delegate = new InteractionEventsSink_OnTerminateEventHandler(StopInteraction); _interactionEvents.OnTerminate += _onTerminate_Delegate; _userInputEvents = _inventorApplication.CommandManager.UserInputEvents; _userInputEvents_OnContextMenuDelegate = new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu); _userInputEvents.OnContextMenu += _userInputEvents_OnContextMenuDelegate; _mouseEvents = _interactionEvents.MouseEvents; _mouseEvents.PointInferenceEnabled = true; _onMouseClick_Delegate = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_CreateRectangle); _mouseEvents.OnMouseClick += _onMouseClick_Delegate; _interactionEvents.StatusBarText = "Select a Point from which to start the rectangle"; _interactionEvents.AllowCommandAliases = true; _interactionEvents.Start(); }
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> /// This method reacts to the Mouse Move event and calls a method to reposition the points that make /// up the rectangle and also subscribes to the mouse click event for when the rectangle is to be /// instantiated by the user. /// </summary> /// <param name="button"></param> /// <param name="shiftKeys"></param> /// <param name="modelPosition"></param> /// <param name="viewPosition"></param> /// <param name="view"></param> protected void OnMouseMove_DragCornerOfRectangle(MouseButtonEnum button, ShiftStateEnum shiftKeys, Point modelPosition, Point2d viewPosition, Inventor.View view) { AdjustRectanglePosition(modelPosition); if (_onMouseClick_Delegate == null) { _onMouseClick_Delegate = new MouseEventsSink_OnMouseClickEventHandler(OnMouseClick_LockTheRectangle); _mouseEvents.OnMouseClick += _onMouseClick_Delegate; _userInputEvents_OnContextMenuDelegate += new UserInputEventsSink_OnContextMenuEventHandler(UserInputEvents_OnContextMenu); _userInputEvents.OnContextMenu += _userInputEvents_OnContextMenuDelegate; } }
/// <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()); } }
/// <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()); } }