////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // ClientGraphics simulation with or without transacting mode
        //
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        private void RunWithGraphics(bool transacting)
        {
            Initialize();

            System.Windows.Forms.Application.AddMessageFilter(new MsgFilter());

            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            AssemblyDocument doc = InvApp.ActiveDocument as AssemblyDocument;
            AssemblyComponentDefinition compDef = doc.ComponentDefinition;

            InvApp.UserInterfaceManager.UserInteractionDisabled = true;

            Transaction Tx = InvApp.TransactionManager.StartGlobalTransaction(doc as _Document, "Simulation");

            Matrix matrix = InvApp.TransientGeometry.CreateMatrix();

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

            clientGraphicsMng.SetGraphicsSource(doc as Document);

            clientGraphicsMng.Transacting = transacting;

            List<GraphicsNode> nodes = new List<GraphicsNode>();

            foreach (ComponentOccurrence occurrence in compDef.Occurrences)
            {
                SurfaceBody body = occurrence.Definition.SurfaceBodies[1];

                SurfaceGraphics surfGraph = clientGraphicsMng.DrawSurface(body, null);

                GraphicsNode node = surfGraph.Parent;

                if(occurrence.RenderStyle != null)
                    node.RenderStyle = occurrence.RenderStyle;

                nodes.Add(node);

                occurrence.Visible = false;
            }

            AdnTimer timer = new AdnTimer();

            double[] transfo = new double[16];

            _bActive = true;

            while (_bActive)
            {
                System.Windows.Forms.Application.DoEvents();

                double dT = timer.ElapsedSeconds;

                _dynamicsWorld.StepSimulation(dT, 10);

                int idx = 0;

                foreach (RigidBody body in _mapOccurrencesToBodies.Values)
                {
                    body.GetWorldTransform(ref transfo);

                    matrix.PutMatrixData(ref transfo);

                    nodes[idx].Transformation = matrix;

                    ++idx;
                }

                clientGraphicsMng.UpdateView();

                ComputeFrameRate(dT);
            }

            clientGraphicsMng.DeleteGraphics(doc as Document, true);

            _dynamicsWorld.CleanUp();

            foreach (ComponentOccurrence occurrence in compDef.Occurrences)
            {
                occurrence.Visible = true;
            }

            Tx.End();

            InvApp.UserInterfaceManager.UserInteractionDisabled = false;
        }
Esempio n. 2
0
        //////////////////////////////////////////////////////////////////////////////////////////////
        // Deletes all graphics created by ClientGraphicsManager
        // 
        //////////////////////////////////////////////////////////////////////////////////////////////
        public static void DeleteManagerGraphics()
        {
            Inventor.Application InvApp = AdnInventorUtilities.InvApplication;

            Document document = InvApp.ActiveDocument;

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

            switch (document.DocumentType)
            { 
                case DocumentTypeEnum.kAssemblyDocumentObject:
                case DocumentTypeEnum.kPartDocumentObject:

                    clientGraphicsMng.DeleteGraphics(document, true);
                    break;

                case DocumentTypeEnum.kDrawingDocumentObject:

                    DrawingDocument drawing = document as DrawingDocument;
                    clientGraphicsMng.DeleteGraphics(drawing.ActiveSheet, true);
                    break;

                default:
                    break;
            }

            clientGraphicsMng.UpdateView();
        }