首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C# Visio 二次開發:動態仿真實現(二)——拓撲分析與動畫觸發架構

     編輯:關於C語言

動態仿真核心三步驟

  1. 拓撲分析:掃描圖面,建立設備連接關係,存入資料庫
  2. 層次構建:依資料庫關係分析,產生拓撲網絡設備層次結構列表
  3. 動畫展示:依設備類型與當前狀態,執行繪製與動畫仿真

關鍵技術:Application.DoEvents()

System.Windows.Forms.Application.DoEvents();
Thread.Sleep(50);

原理:主動處理訊息佇列,讓 UI 執行緒立即繪製更新,否則批次操作會等所有邏輯完成才一次性重繪,無法看到動畫過程。

完整分析觸發流程

private void PowerCutAnalyze(Visio.Application app)
{
    #region 取得操作設備與驗證
    Visio.Shape shapeSelected = null;
    try
    {
        Visio.Window wndVisio = app.ActiveWindow;
        if (wndVisio.Selection.Count == 1)
            shapeSelected = wndVisio.Selection.get_Item16(1);
    }
    catch { }
    
    if (!VisioUtility.HasShapeInWindow(VisWindow))
    {
        MessageUtil.ShowWarning("圖紙上沒有設備, 不能執行該操作");
        return;
    }
    #endregion
    
    app.UndoEnabled = false; // 關閉復原提升效能
    List<string> list = new List<string>();
    string message = "";
    
    // 業務層執行拓撲分析
    list = powerCutBLL.RunPowerCutAnalyzing(app, shapeSelected, ref message);
    app.UndoEnabled = true;
    
    if (message != "")
    {
        MessageUtil.ShowError(message);
        return;
    }
    
    if (list.Count > 0)
    {
        AnalyzeShapeIdList.Clear();
        foreach (string shapeStrID in list)
            AnalyzeShapeIdList.Add(Convert.ToInt32(shapeStrID));
        
        RunColorChanging(app); // 觸發動畫
    }
    else
    {
        MessageUtil.ShowWarning("請檢查線路是否連接正確。");
    }
}

架構亮點

  • 業務邏輯(BLL)與 UI 解耦,RunPowerCutAnalyzing 回傳拓撲順序 ID 列表
  • AnalyzeShapeIdList 作為動畫引擎的輸入資料源
  • 關閉 UndoEnabled 避免大量操作產生龐大復原記錄
  • 錯誤訊息分級處理(Warning/Error)提升用戶體驗
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved