我最近開始使用C#,并且我必須導(dǎo)入一個(gè)Visio文件,該文件包含具有不同路徑的流程圖.
I recently started to work with C# and I have to import a Visio file that is including a flow-chart with different path.
我使用此代碼加載文件.
I load the file with this code.
public Container loadFile(string fileName)
{
Microsoft.Office.Interop.Visio.Application app = new Microsoft.Office.Interop.Visio.Application();
app.Visible = false;
Documents docs = app.Documents;
Document doc = docs.Open(fileName);
Microsoft.Office.Interop.Visio.Page page = doc.Pages[1];
Container container = printProperties(page.Shapes);
return container;
}
public Container printProperties(Microsoft.Office.Interop.Visio.Shapes shapes)
{
Container container = new Container("Visio Import");
container.setParent(null);
// Look at each shape in the collection.
foreach (Microsoft.Office.Interop.Visio.Shape shape in shapes)
{
// traverse
}
return container;
}
我想遍歷流程圖的每個(gè)可能的(!)路徑并打印進(jìn)程名稱.例如
I want to traverse through every possible (!) path of the flow-chart and print the process names. E.g.
Path 1:
- Enter PIN
- Select Account
- Select Amount
- Print Receipt
- Take Money
Path 2:
- Enter PIN
- Select Account
- Check Money
- Abort
您能告訴我如何檢查單個(gè)流程之間的連接并遍歷嗎?非常感謝您的幫助!
Can you tell me how to check the connections between the single processes and traverse it? Thank you very much for your help!
我有執(zhí)行此操作的代碼,但由于它是商業(yè)產(chǎn)品的一部分,所以我無(wú)法共享它.
I have code that does this, but I cannot share it, since it's part of a commercial product.
但是,我可以告訴你,我在Visio中解決此問題的方式是,我首先在VBA中編寫了一組非常通用的有向圖類:一個(gè)用于節(jié)點(diǎn),一個(gè)用于邊緣,一個(gè)用于圖形作為所有的.我在圖形類中內(nèi)置了循環(huán)路徑檢查,以及用于在圖形中查找所有路徑的代碼.
However, I can tell you that the way I coped with doing this within Visio was, I first wrote a set of very generic directed graph classes in VBA: one for nodes, one for edges, and one for the graph as a whole. I built circular path checks into the graph class, as well as the code for finding all paths in the graph.
然后,我有一些代碼可以讀取Visio頁(yè)面并填充此簡(jiǎn)單的圖形表示形式,并調(diào)用適當(dāng)?shù)拇a.
Then I had some code that would read the Visio page and populate this simple graph representation, and call the appropriate code.
我認(rèn)為這也可能對(duì)您也有好處,因?yàn)閂isio方面不可避免地比簡(jiǎn)單的有向圖實(shí)現(xiàn)更混亂.因?yàn)楸仨氈С諺isio 2003,所以我沒有使用API??的ConnectedShapes部分,因此實(shí)際上我查看了形狀上的Connects和FromConnects對(duì)象,以查看將哪個(gè)OneD連接器附加到形狀上,并確定形狀是否正確.在箭頭的頭部或尾部.這是將圖形部分與Visio部分分開的另一個(gè)原因,因?yàn)槲覀冏x取Visio頁(yè)面的方式會(huì)隨著時(shí)間而變化,但是圖形理論將保持不變.
I think this would probably be good for you to do, too, since the Visio side of things will inevitably be messier than a simple directed graph implementation. I didn't use the ConnectedShapes part of the API since I have to support down to Visio 2003, so I actually look at the Connects and FromConnects objects on my shapes to see what OneD connectors are attached to a shape, and determine whether a shape is at the head or tail of an arrow. This is another reason to break the graph part away from the Visio part, since the way we read the Visio page is subject to change over time, but the graph theory will stay the same.
尋路算法的工作原理是首先找到圖中的所有終端節(jié)點(diǎn),我的意思是那些沒有下游節(jié)點(diǎn)的節(jié)點(diǎn).對(duì)于其中的每一個(gè),我添加一個(gè)名為DownstreamPaths的列表,該列表為空,因?yàn)橄掠螞]有任何內(nèi)容.然后,對(duì)于圖中的每個(gè)節(jié)點(diǎn),我調(diào)用一個(gè)遞歸函數(shù),該函數(shù)填充當(dāng)前節(jié)點(diǎn)的所有下游路徑,并且基本上它所做的就是在每個(gè)節(jié)點(diǎn)上構(gòu)建一個(gè)DownstreamPaths列表.該列表是列表的列表,因此您只需查看每個(gè)下游節(jié)點(diǎn),然后將該節(jié)點(diǎn)附加在其自己的DownstreamPaths列表的頭部,然后將其添加到當(dāng)前節(jié)點(diǎn)的路徑列表中即可. 完成這些操作后,您將找到所有起始節(jié)點(diǎn),而上游沒有任何內(nèi)容,并整理這些節(jié)點(diǎn)上的所有下游路徑列表,然后獲得路徑列表.
The path-finding algorithm works by first finding all the terminal nodes in the graph, and I mean those nodes with no Downstream nodes. For each of these I add a list called DownstreamPaths, which is just empty since there is nothing downstream. Then for each node in the graph I call a recursive function that populates all the downstream paths for the current node, and basically all it does is builds a DownstreamPaths list on each node. This list is a list of lists, so you just look at each downstream node, and append that node on the head of its own DownstreamPaths list, and add that into the current node's path list. When that's all done, you find all the starting nodes, with nothing upstream, and collate all the downstream paths lists on those, and you get your list of paths.
聯(lián)系客服