예제 #1
0
        public void Execute()
        {
            _nNodesTotal = 0;
            _nFragsTotal = 0;
            _pathDict    = new Dictionary <int[], Stack <ComApi.InwOaFragment3> >();

            DateTime dt = DateTime.Now;

            CallbackGeomListener.Init();

            // Convert to COM selection

            ComApi.InwOpState oState = ComBridge.State;
            walkNode(oState.CurrentPartition, false);

            // Generate primitives for collected fragments

            CallbackGeomListener cbl
                = new CallbackGeomListener();

            foreach (var kvp in _pathDict)
            {
                var frags = kvp.Value;
                while (frags.Count > 0)
                {
                    ComApi.InwOaFragment3 frag = frags.Pop();
                    frag.GenerateSimplePrimitives(
                        ComApi.nwEVertexProperty.eNORMAL, cbl);
                }
            }

            TimeSpan ts = DateTime.Now - dt;
            double   ms = ts.TotalMilliseconds;

            string s = string.Format(
                "Retrieved {0} geometry nodes and {1} fragments in {2} milliseconds.",
                _nNodesTotal, _nFragsTotal, ms.ToString("0.##"));

            Debug.Print(s);

            Debug.Print("Line, point, snappoint and triangle counts: {0}, {1}, {2}, {3}",
                        CallbackGeomListener.LineCount, CallbackGeomListener.PointCount,
                        CallbackGeomListener.SnapPointCount, CallbackGeomListener.TriangleCount);
        }
        void walkNode(COMApi.InwOaNode parentNode, bool bFoundFirst)
        {
            if (parentNode.IsGroup)
            {
                COMApi.InwOaGroup group = (COMApi.InwOaGroup)parentNode;
                long subNodesCount      = group.Children().Count;

                for (long subNodeIndex = 1; subNodeIndex <= subNodesCount; subNodeIndex++)
                {
                    COMApi.InwOaNode newNode = group.Children()[subNodeIndex];

                    if ((!bFoundFirst) && (subNodesCount > 1))
                    {
                        bFoundFirst = true;
                    }
                    walkNode(newNode, bFoundFirst);
                }
            }
            else if (parentNode.IsGeometry)
            {
                long fragsCount = parentNode.Fragments().Count;
                System.Diagnostics.Debug.WriteLine("frags count:" + fragsCount.ToString());

                for (long fragindex = 1; fragindex <= fragsCount; fragindex++)
                {
                    CallbackGeomListener callbkListener =
                        new CallbackGeomListener();

                    COMApi.InwNodeFragsColl fragsColl = parentNode.Fragments();
                    COMApi.InwOaFragment3   frag      = fragsColl[fragindex];

                    frag.GenerateSimplePrimitives(
                        COMApi.nwEVertexProperty.eNORMAL,
                        callbkListener);
                }

                fragCount    += fragsCount;
                geoNodeCount += 1;
            }
        }
예제 #3
0
        void walkNode(
            ComApi.InwOaNode parentNode,
            bool bFoundFirst)
        {
            if (parentNode.IsGroup)
            {
                ComApi.InwOaGroup group = (ComApi.InwOaGroup)parentNode;
                long n = group.Children().Count;

                for (long i = 1; i <= n; ++i)
                {
                    ComApi.InwOaNode newNode = group.Children()[i];

                    if ((!bFoundFirst) && (n > 1))
                    {
                        bFoundFirst = true;
                    }
                    walkNode(newNode, bFoundFirst);
                }
            }
            else if (parentNode.IsGeometry)
            {
                ComApi.InwNodeFragsColl fragsColl
                    = parentNode.Fragments();

                CallbackGeomListener cbl
                    = generate_primitives_for_all_fragments
            ? new CallbackGeomListener()
            : null;

                long nFrags = fragsColl.Count;

                Debug.WriteLine("frags count:"
                                + nFrags.ToString());

                for (long i = 1; i <= nFrags; ++i)
                {
                    ComApi.InwOaFragment3 frag = fragsColl[i];

                    if (generate_primitives_for_all_fragments)
                    {
                        frag.GenerateSimplePrimitives(
                            ComApi.nwEVertexProperty.eNORMAL, cbl);
                    }
                    else
                    {
                        // Collect single instance of each fragment
                        // in lookup dictionary for later call to
                        // GenerateSimplePrimitives

                        Array a = (Array)(object)frag.path.ArrayData;

                        //ComApi.InwOaPath p = frag.path;
                        //var a = p.ArrayData;

                        //Array b = (Array) a;
                        //int len = b.Length;
                        //int[] pathArr = b.ToArray<int>();

                        int[] pathArr = a.ToArray <int>();
                        if (!_pathDict.TryGetValue(pathArr,
                                                   out Stack <ComApi.InwOaFragment3> frags))
                        {
                            frags = new Stack <ComApi.InwOaFragment3>();
                            _pathDict[pathArr] = frags;
                        }
                        frags.Push(frag);
                    }
                    _nFragsTotal += nFrags;
                }
                ++_nNodesTotal;
            }
        }