Example #1
0
        private static void toDot(
            JointGraph g, StreamWriter writer,
            NodeSet nodes = null, NodeSet selected = null)
        {
            IEnumerable <Node> printNodes;

            if (null == nodes)
            {
                printNodes = g.nodes;
            }
            else
            {
                printNodes = nodes;
            }
            writeHeader(writer);
            foreach (Node node in printNodes)
            {
                if (null != selected && selected.Contains(node))
                {
                    writeNode(node, writer, true);  // fill color
                }
                else
                {
                    writeNode(node, writer);
                }
            }
            EdgeDict edges = g.directedEdges;

            foreach (Node node in printNodes)
            {
                writeEdge(node, edges[node], writer);
            }
            writeFooter(writer);
        }
Example #2
0
        private static JointGraph makeJointGraph(IPXPmx pmx)
        {
            JointGraph jointGraph = new JointGraph();

            foreach (IPXJoint joint in pmx.Joint)
            {
                Node jointNode = makeJointNode(joint);
                if (null != joint.BodyA)
                {
                    Node bodyANode = makeBodyNode(joint.BodyA);
                    jointGraph.addEdge(bodyANode, jointNode);
                }
                if (null != joint.BodyB)
                {
                    Node bodyBNode = makeBodyNode(joint.BodyB);
                    jointGraph.addEdge(jointNode, bodyBNode);
                }
            }
            // register isolated rigid bodies
            foreach (IPXBody body in pmx.Body)
            {
                jointGraph.addNode(makeBodyNode(body));
            }
            return(jointGraph);
        }
Example #3
0
        private static void plugin_main(
            IPXPmx pmx, IPEViewConnector view, IPEFormConnector form)
        {
            StreamWriter writer = makeWriter();

            using (writer) {
                int[] selectedBodies = view.PmxView.GetSelectedBodyIndices();
                int[] selectedJoints = view.PmxView.GetSelectedJointIndices();

                makeIndexDict(pmx);
                JointGraph g = makeJointGraph(pmx);

                NodeSet subNodes      = new NodeSet();
                NodeSet selectedNodes = new NodeSet();
                // pmxvewの選択情報は選択解除しても残ってしまうので
                // form の情報で判断する
                if (form.SelectedJointIndex >= 0)
                {
                    foreach (int i in selectedJoints)
                    {
                        Node jointNode = makeJointNode(pmx.Joint[i]);
                        selectedNodes.Add(jointNode);
                        subNodes.UnionWith(
                            g.getConnectedNodes(jointNode));
                    }
                }
                if (form.SelectedBodyIndex >= 0)
                {
                    foreach (int i in selectedBodies)
                    {
                        Node bodyNode = makeBodyNode(pmx.Body[i]);
                        selectedNodes.Add(bodyNode);
                        subNodes.UnionWith(
                            g.getConnectedNodes(bodyNode));
                    }
                }
                if (selectedNodes.Count > 0)
                {
                    toDot(g, writer, subNodes, selectedNodes);
                }
                else
                {
                    toDot(g, writer);
                }
                return;
            }
        }