void DoDemo()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            _interactionManager = new AdnInteractionManager(InvApp);

            _interactionManager.Initialize();

            _interactionManager.OnTerminateEvent +=
               new AdnInteractionManager.OnTerminateHandler(OnTerminateEvent);

            _interactionManager.MouseEvents.OnMouseDown +=
                new MouseEventsSink_OnMouseDownEventHandler(MouseEvents_OnMouseDown);

            _interactionManager.Start("Click points anywhere in model window: ");

            _clientGraphicsMng = new AdnClientGraphicsManager(
                AdnInventorUtilities.InvApplication,
                AdnInventorUtilities.AddInGuid);

            _clientGraphicsMng.SetGraphicsSource(
                _interactionManager.InteractionEvents);

            _lineStripGraph = null;
        }
示例#2
0
        void DoDemo()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            _interactionManager = new AdnInteractionManager(InvApp);

            _interactionManager.Initialize();

            _interactionManager.OnTerminateEvent +=
                new AdnInteractionManager.OnTerminateHandler(OnTerminateEvent);

            _interactionManager.MouseEvents.OnMouseDown +=
                new MouseEventsSink_OnMouseDownEventHandler(MouseEvents_OnMouseDown);

            _interactionManager.Start("Click points anywhere in model window: ");

            _clientGraphicsMng = new AdnClientGraphicsManager(
                AdnInventorUtilities.InvApplication,
                AdnInventorUtilities.AddInGuid);

            _clientGraphicsMng.SetGraphicsSource(
                _interactionManager.InteractionEvents);

            _lineStripGraph = null;
        }
        public LineStripGraphics DrawLineStrip(
            double[] coordinates,
            GraphicsNode node)
        {
            try
            {
                AdnGraphics graphicsData = WorkingGraphics;

                if (node == null)
                {
                    node = graphicsData.ClientGraphics.AddNode(
                        graphicsData.GetGraphicNodeFreeId());
                }

                LineStripGraphics graphic = node.AddLineStripGraphics();

                if (coordinates != null)
                {
                    GraphicsCoordinateSet coordSet =
                        graphicsData.GraphicsDataSets.CreateCoordinateSet(
                            graphicsData.GetDataSetFreeId());

                    coordSet.PutCoordinates(ref coordinates);

                    graphic.CoordinateSet = coordSet;
                }

                return(graphic);
            }
            catch
            {
                return(null);
            }
        }
示例#4
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        //
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void MouseEvents_OnMouseDown(
            MouseButtonEnum Button,
            ShiftStateEnum ShiftKeys,
            Inventor.Point ModelPosition,
            Point2d ViewPosition,
            Inventor.View View)
        {
            if (Button != MouseButtonEnum.kLeftMouseButton)
            {
                return;
            }

            if (_lineStripGraph == null)
            {
                double[] front    = AdnInventorUtilities.ToArray(ModelPosition);
                double[] back     = AdnInventorUtilities.ToArray(ModelPosition);
                double[] combined = front.Concat(back).ToArray();

                _rd = new Random();

                _lineStripGraph = _clientGraphicsMng.DrawLineStrip(
                    combined,
                    null);

                _lineStripGraph.ColorBinding = ColorBindingEnum.kPerItemColors;

                int id = _clientGraphicsMng.WorkingGraphics.GetDataSetFreeId();

                _lineStripGraph.ColorSet =
                    _clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id);

                _lineStripGraph.ColorSet.Add(
                    _lineStripGraph.ColorSet.Count + 1,
                    (byte)_rd.Next(0, 255),
                    (byte)_rd.Next(0, 255),
                    (byte)_rd.Next(0, 255));

                _lineStripGraph.LineWeight = 5;

                _interactionManager.MouseEvents.MouseMoveEnabled = true;

                _interactionManager.MouseEvents.OnMouseMove +=
                    new MouseEventsSink_OnMouseMoveEventHandler(MouseEvents_OnMouseMove);
            }
            else
            {
                _lineStripGraph.CoordinateSet.Add(
                    _lineStripGraph.CoordinateSet.Count + 1,
                    ModelPosition);

                _lineStripGraph.ColorSet.Add(
                    _lineStripGraph.ColorSet.Count + 1,
                    (byte)_rd.Next(0, 255),
                    (byte)_rd.Next(0, 255),
                    (byte)_rd.Next(0, 255));
            }
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // The public static method to start the demo
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void Demo()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            object selection1 = InvApp.CommandManager.Pick(
                SelectionFilterEnum.kPartVertexFilter,
                "Select first vertex: ");

            if (selection1 == null)
            {
                return;
            }

            object selection2 = InvApp.CommandManager.Pick(
                SelectionFilterEnum.kPartVertexFilter,
                "Select second vertex: ");

            if (selection2 == null)
            {
                return;
            }

            object selection3 = InvApp.CommandManager.Pick(
                SelectionFilterEnum.kPartVertexFilter,
                "Select third vertex: ");

            if (selection3 == null)
            {
                return;
            }

            List <double> coords = new List <double>();

            coords.AddRange(AdnInventorUtilities.ToArray(AdnInventorUtilities.GetPoint(selection1)));
            coords.AddRange(AdnInventorUtilities.ToArray(AdnInventorUtilities.GetPoint(selection2)));
            coords.AddRange(AdnInventorUtilities.ToArray(AdnInventorUtilities.GetPoint(selection3)));

            AdnClientGraphicsManager clientGraphicsMng = new AdnClientGraphicsManager(
                InvApp,
                AdnInventorUtilities.AddInGuid);

            LineStripGraphics lineStrip =
                clientGraphicsMng.DrawLineStrip(coords.ToArray());

            lineStrip.LineWeight = 5.0;

            int id = clientGraphicsMng.WorkingGraphics.GetDataSetFreeId();

            lineStrip.ColorSet =
                clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id);

            lineStrip.ColorSet.Add(1, 119, 187, 17);

            clientGraphicsMng.UpdateView();
        }
示例#6
0
        /// <summary>
        /// Draws the interaction graphics rectangle. Again, two paths for the part sketch or drawing sketch, with
        /// the drawing sketch not getting any color overrides due to how it blends into the "paper". Instead it
        /// defaults to black in the drawing sketch.  The part sketch gets a color from the Degrees of Freedom color
        /// schema.
        /// </summary>
        protected void DrawInteractionRectangle()
        {
            _upperRightPoint2d.X = _pickedPoint2d.X + 0.0001;
            _upperRightPoint2d.Y = _pickedPoint2d.Y + 0.0001;

            PositionPoint2dObjects();

            WriteToInteractionPointCoords();

            _rectangleCoordSet.PutCoordinates(ref _rectanglePointCoords);

            if (_planarSketch != null)
            {
                _activeDOFFreeColor        = _inventorApplication.ActiveColorScheme.DOFFreeColor;
                _rectangleGraphicsColorSet = _rectangleGraphicsDataSets.CreateColorSet(1);
                _rectangleGraphicsColorSet.Add(1, _activeDOFFreeColor.Red, _activeDOFFreeColor.Green, _activeDOFFreeColor.Blue);

                _rectangleIndexSet.Add(1, 1);
                _rectangleIndexSet.Add(2, 2);
                _rectangleIndexSet.Add(3, 3);
                _rectangleIndexSet.Add(4, 4);
                _rectangleIndexSet.Add(5, 1);

                _rectangleLineStripGraphics = _rectangleLineNode.AddLineStripGraphics();
                _rectangleLineStripGraphics.CoordinateSet      = _rectangleCoordSet;
                _rectangleLineStripGraphics.CoordinateIndexSet = _rectangleIndexSet;
                _rectangleLineStripGraphics.ColorSet           = _rectangleGraphicsColorSet;
            }
            else if (_drawingSketch != null)
            {
                _rectangleIndexSet.Add(1, 1);
                _rectangleIndexSet.Add(2, 2);
                _rectangleIndexSet.Add(3, 3);
                _rectangleIndexSet.Add(4, 4);
                _rectangleIndexSet.Add(5, 1);

                _rectangleLineStripGraphics = _rectangleLineNode.AddLineStripGraphics();
                _rectangleLineStripGraphics.CoordinateSet      = _rectangleCoordSet;
                _rectangleLineStripGraphics.CoordinateIndexSet = _rectangleIndexSet;
            }

            _rectangleInteractionGraphics.UpdateOverlayGraphics(_inventorApplication.ActiveView);
        }
        //////////////////////////////////////////////////////////////////////////////////////////////
        // 
        //
        //////////////////////////////////////////////////////////////////////////////////////////////
        void MouseEvents_OnMouseDown(
            MouseButtonEnum Button,
            ShiftStateEnum ShiftKeys,
            Inventor.Point ModelPosition,
            Point2d ViewPosition,
            Inventor.View View)
        {
            if (Button != MouseButtonEnum.kLeftMouseButton)
                return;

            if (_lineStripGraph == null)
            {
                double[] front = AdnInventorUtilities.ToArray(ModelPosition);
                double[] back = AdnInventorUtilities.ToArray(ModelPosition);
                double[] combined = front.Concat(back).ToArray();

                _rd = new Random();

                _lineStripGraph = _clientGraphicsMng.DrawLineStrip(
                    combined,
                    null);

                _lineStripGraph.ColorBinding = ColorBindingEnum.kPerItemColors;

                int id = _clientGraphicsMng.WorkingGraphics.GetDataSetFreeId();

                _lineStripGraph.ColorSet =
                    _clientGraphicsMng.WorkingGraphics.GraphicsDataSets.CreateColorSet(id);

                _lineStripGraph.ColorSet.Add(
                    _lineStripGraph.ColorSet.Count + 1, 
                    (byte)_rd.Next(0, 255), 
                    (byte)_rd.Next(0, 255),
                    (byte)_rd.Next(0, 255));

                _lineStripGraph.LineWeight = 5;

                _interactionManager.MouseEvents.MouseMoveEnabled = true;

                _interactionManager.MouseEvents.OnMouseMove +=
                    new MouseEventsSink_OnMouseMoveEventHandler(MouseEvents_OnMouseMove);
            }
            else
            {
                _lineStripGraph.CoordinateSet.Add(
                    _lineStripGraph.CoordinateSet.Count + 1,
                    ModelPosition);

                 _lineStripGraph.ColorSet.Add(
                    _lineStripGraph.ColorSet.Count + 1, 
                    (byte)_rd.Next(0, 255), 
                    (byte)_rd.Next(0, 255),
                    (byte)_rd.Next(0, 255));
            }
        }
示例#8
0
        private void m_MouseEvents_OnMouseUp(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            //if the interaction event is MyScreenshot, create the image
            if (m_InteractionEvents.Name == "MyScreenshot")
            {
                m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete();
                m_inventorApplication.ActiveView.Update();

                if (oGiLineStripG != null)
                {
                    oGiLineStripG.Delete();
                    oGiLineStripG = null;
                }

                if (oGiLineG != null)
                {
                    oGiLineG.Delete();
                    oGiLineG = null;
                }

                //stop interaction event
                m_InteractionEvents.SetCursor(CursorTypeEnum.kCursorBuiltInArrow);
                m_flagMouseDown = false;
                if (m_MouseEvents != null)
                {
                    m_MouseEvents.OnMouseDown -= m_MouseEvents_OnMouseDown;
                    m_MouseEvents.OnMouseMove -= m_MouseEvents_OnMouseMove;
                    m_MouseEvents.OnMouseUp   -= m_MouseEvents_OnMouseUp;
                    m_MouseEvents              = null;
                }
                m_InteractionEvents.Stop();
                m_InteractionEvents = null;

                //prepare size of the image region, in pixel

                oSize = new Size(Convert.ToInt32(Math.Abs(ViewPosition.X - m_MouseStartViewPt.X)), Convert.ToInt32(Math.Abs(ViewPosition.Y - m_MouseStartViewPt.Y)));

                if (ViewPosition.X > m_MouseStartViewPt.X & ViewPosition.Y > m_MouseStartViewPt.Y)
                {
                    oCornerPt = m_MouseStartViewPt;
                }
                else if (ViewPosition.X > m_MouseStartViewPt.X & ViewPosition.Y < m_MouseStartViewPt.Y)
                {
                    oCornerPt.X = m_MouseStartViewPt.X;
                    oCornerPt.Y = ViewPosition.Y;
                }
                else if (ViewPosition.X <m_MouseStartViewPt.X& ViewPosition.Y> m_MouseStartViewPt.Y)
                {
                    oCornerPt.X = ViewPosition.X;
                    oCornerPt.Y = m_MouseStartViewPt.Y;
                }
                else
                {
                    oCornerPt = ViewPosition;
                }

                //take the view position in screen, calculate
                //the real pixel data of the corners

                oCornerPt.X = (int)View.Left + oCornerPt.X;
                oCornerPt.Y = (int)View.Top + oCornerPt.Y;
            }
        }
示例#9
0
        private void m_MouseEvents_OnMouseDown(Inventor.MouseButtonEnum Button, Inventor.ShiftStateEnum ShiftKeys, Inventor.Point ModelPosition, Inventor.Point2d ViewPosition, Inventor.View View)
        {
            //if the interaction event is MyScreenshot,
            //then get the view position and model position

            if (m_InteractionEvents.Name == "MyScreenshot")
            {
                m_MouseStartViewPt = ViewPosition;
                m_StartModelPt     = ModelPosition;
                m_flagMouseDown    = true;

                //clean the last graphics
                m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.Delete();
                m_inventorApplication.ActiveView.Update();

                //gi node
                oGiNode   = m_InteractionEvents.InteractionGraphics.PreviewClientGraphics.AddNode(1);
                oCoordSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateCoordinateSet(1);

                //color set
                oColorSet = m_InteractionEvents.InteractionGraphics.GraphicsDataSets.CreateColorSet(1);
                oColorSet.Add(1, 255, 0, 0);

                TransientGeometry tg    = m_inventorApplication.TransientGeometry;
                Inventor.Point    tempP = tg.CreatePoint(ViewPosition.X, ViewPosition.Y, 0);

                oCoordSet.Add(1, tempP);
                oCoordSet.Add(2, tempP);
                oCoordSet.Add(3, tempP);
                oCoordSet.Add(4, tempP);
                oCoordSet.Add(5, tempP);

                try
                {
                    if (oGiLineStripG != null)
                    {
                        oGiLineStripG.Delete();
                        oGiLineStripG = null;
                    }
                    oGiLineStripG = oGiNode.AddLineStripGraphics();
                    oGiLineStripG.CoordinateSet = oCoordSet;
                    oGiLineStripG.ColorSet      = oColorSet;
                    oGiLineStripG.BurnThrough   = true;
                }
                catch (Exception ex)
                {
                    //a problem in Inventor 2009( R13 ) with
                    //LineStripGraphics.BurnThrough. Use LineGraphics as workaround

                    if (oGiLineG != null)
                    {
                        oGiLineG.Delete();
                        oGiLineG = null;
                    }

                    oGiLineG = oGiNode.AddLineGraphics();
                    oGiLineG.CoordinateSet = oCoordSet;
                    oGiLineG.ColorSet      = oColorSet;
                    oGiLineG.BurnThrough   = true;
                }
            }
        }
        /// <summary>
        /// Draws the interaction graphics rectangle. Again, two paths for the part sketch or drawing sketch, with 
        /// the drawing sketch not getting any color overrides due to how it blends into the "paper". Instead it 
        /// defaults to black in the drawing sketch.  The part sketch gets a color from the Degrees of Freedom color
        /// schema.
        /// </summary>
        protected void DrawInteractionRectangle()
        {
            _upperRightPoint2d.X = _pickedPoint2d.X + 0.0001;
            _upperRightPoint2d.Y = _pickedPoint2d.Y + 0.0001;

            PositionPoint2dObjects();

            WriteToInteractionPointCoords();

            _rectangleCoordSet.PutCoordinates(ref _rectanglePointCoords);

            if (_planarSketch != null)
            {
                _activeDOFFreeColor = _inventorApplication.ActiveColorScheme.DOFFreeColor;
                _rectangleGraphicsColorSet = _rectangleGraphicsDataSets.CreateColorSet(1);
                _rectangleGraphicsColorSet.Add(1, _activeDOFFreeColor.Red, _activeDOFFreeColor.Green, _activeDOFFreeColor.Blue);

                _rectangleIndexSet.Add(1, 1);
                _rectangleIndexSet.Add(2, 2);
                _rectangleIndexSet.Add(3, 3);
                _rectangleIndexSet.Add(4, 4);
                _rectangleIndexSet.Add(5, 1);

                _rectangleLineStripGraphics = _rectangleLineNode.AddLineStripGraphics();
                _rectangleLineStripGraphics.CoordinateSet = _rectangleCoordSet;
                _rectangleLineStripGraphics.CoordinateIndexSet = _rectangleIndexSet;
                _rectangleLineStripGraphics.ColorSet = _rectangleGraphicsColorSet;
            }
            else if (_drawingSketch != null)
            {
                _rectangleIndexSet.Add(1, 1);
                _rectangleIndexSet.Add(2, 2);
                _rectangleIndexSet.Add(3, 3);
                _rectangleIndexSet.Add(4, 4);
                _rectangleIndexSet.Add(5, 1);

                _rectangleLineStripGraphics = _rectangleLineNode.AddLineStripGraphics();
                _rectangleLineStripGraphics.CoordinateSet = _rectangleCoordSet;
                _rectangleLineStripGraphics.CoordinateIndexSet = _rectangleIndexSet;
            }

            _rectangleInteractionGraphics.UpdateOverlayGraphics(_inventorApplication.ActiveView);
        }