C#C#进行Visio二次开发之动态仿真完结

 

要在Visio图纸上贯彻如上图的卡通片效果,其中最器重的奥秘是运用下边代码:

C# 1C# 2代码

 Visio应用曲高和寡,代码贴图众口难调;不求一举成名,但求潜移默化。

 

 

粗粗的代码如下所示:

 

Visio3回开发能够兑现的类别情景很多,如电气线路分析、配电互连网分析、流程图等,现因为品种供给,又认识多了3个采纳地方,液压传动的虚假。项目功能图如下所示:

 本文介绍怎样贯彻线路走向、颜色变化,以及特定图形(如底特律活塞队(Detroit Pistons))的动态仿真效果。

                                        Thread thread = new Thread(new ParameterizedThreadStart(HuoSaiMoving));
                                        thread.Start(param);
                                    }
                                    else
                                    {
                                        typeCell.Formula = VisioUtility.StringToFormulaForString(minValue);
                                        System.Windows.Forms.Application.DoEvents();
                                        //Thread.Sleep(500 * minFlowValue);
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                LogHelper.Error(ex);
                            }
                        } 
                        #endregion
                    }
                }
                
            }
        }

2)依照数据库结构,对配备关系进行辨析,拿到拓扑网络的装备层次结构列表

            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;

C# 3 

先是落到实处动态仿真效果,必须先分析出全体图纸的拓扑互联网顺序及层次,那样我们才能分晓科学的线路走向以及动画的生成顺序,如配电互连网线路图中,必定是电源开头,通过导线大概装备传递电源,以完结电路的贯通。在液压线路中,由油箱起初,经过一体系设备,最终又回到油箱。

 

Thread thread = new Thread(new ParameterizedThreadStart(HuoSaiMoving));
thread.Start(param);

            if (list.Count > 0)
            {
                AnalyzeShapeIdList.Clear();
                foreach (string shapeStrID in list)
                {
                    AnalyzeShapeIdList.Add(Convert.ToInt32(shapeStrID));
                }
                RunColorChanging(app);
            }
            else
            {
                MessageUtil.ShowWarning(“请检查线路是或不是连接正确。”);
            } 
        }

很多意况下,大家大概对那些Do伊夫nts函数的机能不是很理解,其实大家能够领略为积极触发事件,让音讯流提前进入拍卖流程,这样大家就能够看到在Visio图纸上的图片更新作用了。

3)依照不一致的设备项目和图纸当前情形,对设施开展适当的绘图和动画片仿真体现。

底特律活塞队(Detroit Pistons)运动是在路线联通后,继续循环举办动画的显得的,因为它是单独1个线程进行拍卖操作,通过判断标识来落到实处动画的告一段落控制的,具体处理活塞队(Detroit Pistons)动画的效能实现代码如下所示:

如活塞队运动的虚伪,须要不甘休动画的情事下,能够直接循环的变迁。
如下图所示的功力:

C# 4 

线路颜色变化以及动画彰显部分的代码如下所示 :

 

 

 

 

        /// <summary>
        /// 依据分析后的配备ID,把装备变色动画体现
        /// </summary>
        /// <param name=”visApp”></param>
        private void RunColorChanging(Visio.Application visApp)
        {
            Visio.Cell cell = visApp.ActiveDocument.Pages[1].PageSheet.get_Cells(“Scratch.A1”);
            int intValue = Convert.ToInt32(VisioUtility.FormulaStringToString(cell.Formula));
            if (intValue == 1)
            {
                cell.Formula = “0”;
            }
            else
            {
                cell.Formula = “1”;
                isMovie = !isMovie;
            }
……………….

                        VisioUtility.SetShapeLineColor(shape, VisDefaultColors.visDarkGreen);//有电(绿色)
                        System.Windows.Forms.Application.DoEvents();
                        Thread.Sleep(500 * minFlowValue);
                    }
                    else
                    {
                        shape.Text = “”;
                        VisioUtility.SetShapeLineColor(shape, VisDefaultColors.visBlack);//无电(黑色)
                        System.Windows.Forms.Application.DoEvents();
                    }
                    
                    string equipType = VisioUtility.GetShapeCellValue(shape, “设备项目”);
                    if (!string.IsNullOrEmpty(equipType))
                    {
                        #region 单作用、双作用
                        if (equipType == “单作用” || equipType == “双作用”)
                        {
                            string minValue = “Width*0.25”;
                            string maxValue = “Width*0.75”;
                            string cellName = “Controls.Row_1.X”;
                            try
                            {
                                if (shape.get_CellExistsU(cellName, (short)VisExistsFlags.visExistsAnywhere) != 0)
                                {
                                    short i = shape.get_CellsRowIndex(cellName);
                                    Visio.Cell typeCell = shape.get_CellsSRC((short)VisSectionIndices.visSectionControls, i, (short)VisCellIndices.visCtlX);
                                    if (intValue == 0)
                                    {
                                        ThreadParameterInfo param = new ThreadParameterInfo();
                                        param.Cell = typeCell;
                                        param.ScratchCell = cell;

            int sequence = 1;
            foreach (int shapeId in AnalyzeShapeIdList)
            {
                Visio.Shape shape = VisDocument.Pages[1].Shapes.get_ItemFromID(shapeId);
                if (shape != null)
                {
                    if (intValue == 0)
                    {
                        shape.Text = sequence++.ToString(“D2”);//string.Format(“{0}({1})”, sequence++, shape.ID);//

            if (message != “”)
            {
                MessageUtil.ShowError(message);
                return;
            }

        private void HuoSaiMoving(object obj)
        {
            ThreadParameterInfo objParam = obj as ThreadParameterInfo;
            Visio.Cell scratchCell = objParam.ScratchCell;
            Visio.Cell typeCell = objParam.Cell;
            int intValue = Convert.ToInt32(VisioUtility.FormulaStringToString(scratchCell.Formula));
            while (intValue == 1 && isMovie)
            {
                string minValue = “Width*0.25”;
                string maxValue = “Width*0.75”;
                //Visio.Cell typeCell = objCell as Visio.Cell;
                if (typeCell != null)
                {
                    string currentValue = “”;
                    //增加
                    for (int k = 1; k <= 10; k++)
                    {
                        currentValue = string.Format(“Width*0.25 + Width*{0}”, 0.05 * k);
                        typeCell.Formula = VisioUtility.StringToFormulaForString(currentValue);
                        System.Windows.Forms.Application.DoEvents();
                        Thread.Sleep(50);
                    }
                    //减少
                    for (int k = 1; k <= 10; k++)
                    {
                        currentValue = string.Format(“Width*0.75 – Width*{0}”, 0.05 * k);
                        typeCell.Formula = VisioUtility.StringToFormulaForString(currentValue);
                        System.Windows.Forms.Application.DoEvents();
                        Thread.Sleep(50);
                    }
                }
                intValue = Convert.ToInt32(VisioUtility.FormulaStringToString(scratchCell.Formula));
            }
        }

 

动态仿真,其实也正是模拟实际线路的走向,达成动画的呈现。在此以前作者的Visio的品种,基本上都以依照静态的图形展现,并不曾设置太多的动态彰显。原来配电网络的通电线路的剖析,严厉来说也是静态的,因为差不离是1遍性把通电和不通电的线路给绘制出来。而动态仿真则须求日益的卡通突显线路的走向和颜色变化。

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

全体图形分析的历程,分为1个步骤:

在那之中大家注意到了,底特律活塞队(Detroit Pistons)运动时三个独立的线程进行处理的,如下所示

 

1)举办不难的拓扑分析,把装备周边的关联维持到数据库进行辨析。

       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 { ; }

相关文章