首页 > 编程语言 >c# aveva marine hull design Design Explorer 的自定义

c# aveva marine hull design Design Explorer 的自定义

时间:2024-02-16 19:33:20浏览次数:24  
标签:Explorer 自定义 ContextMenu c# true item var null config

首先显示界面如下

左边为改造后的,右边为默认的界面

1# 将内部名称显示改为装配名显示

2# 直接显示了零件是否已经拉装配

这部分代码也很简单

其次改造下元素的右键菜单

封装的方法,没写注释,看不明白可以联系我交流


public class MyDesignExplorerRightClicKAtt : Attribute
{
    public string AllowType { get; set; }
    public string ToolTiString { get; set; }
    public MyDesignExplorerRightClicKAtt(string allowEleType = "", string Caption = "")
    {
        this.AllowType = allowEleType;
        this.ToolTiString = Caption;
    }
}

public class AM界面管理
 {
     static CommandBarManager CommandBarManager =>(ServiceManager.Instance.GetService(typeof(CommandBarManager)) as CommandBarManager);
     static IExplorer Design_Explorer =>(ServiceManager.Instance.GetService(typeof(ExplorerService)) as ExplorerService).GetExplorer("DESIGN EXPLORER");
     static List<MenuTool> MyMenus = new List<MenuTool>();
     static string LastDbeleType = "";
     public static void DesignxplorerLetRightAttributeCustomized(bool OnorOff = true, DbAttribute left = null, DbAttribute right = null)
     {
         try
         {
             var de1 = Design_Explorer;
             var cbm = CommandBarManager;
             var config = de1.Configuration;
             if (OnorOff)
             {
                 config.FontStyle.LeftNameColor = System.Drawing.Color.Gray;
                 config.FontStyle.LeftNameAttribute = left == null ? DbAttributeInstance.ASMBLS : left;
                 config.FontStyle.NameColor = System.Drawing.Color.DarkRed;
                 //config.FontStyle.NameAttribute = DbAttributeInstance.FLNN;
                 config.FontStyle.RightNameAttribute = right == null ? DbAttributeInstance.PRTIDL : right;
                 config.FontStyle.RightNameColor = System.Drawing.Color.Blue;
                 config.ShowLeaves = true;
                 config.FontName = "Arial";
                 //AM界面管理.DesginExplorerShowAssemblyAndParnamFlag = true;
                 #region 增加右键菜单
                 cbm.AllowCustomization = true;
                 var curArr = Assembly.GetExecutingAssembly();
                 var allCls = curArr.GetTypes().Where(t => t.IsPublic && t.IsClass);
                 foreach (var item in allCls)
                 {
                     var curClsMis = item.GetMethods().Where(m =>
                     m.GetCustomAttributes(typeof(MyDesignExplorerRightClicKAtt), true).Any() && m.IsStatic && m.IsPublic);
                     var methodInfos = curClsMis.ToList();
                     if (methodInfos.Any())
                     {
                         if (!cbm.RootTools.Contains(item.Name))
                         {
                             var cbmtMain = cbm.RootTools.AddMenuTool(item.Name, item.Name, null);
                             if (!config.ContextMenu.Tools.Contains(cbmtMain.Key))
                             {
                                 var itm = config.ContextMenu.Tools.AddTool(cbmtMain.Key) as MenuTool;
                                 foreach (var mi in methodInfos)
                                 {
                                     var att = mi.GetCustomAttributes(typeof(MyDesignExplorerRightClicKAtt), true).FirstOrDefault() as MyDesignExplorerRightClicKAtt;
                                     var cmdKey = cbmtMain.Key + "." + mi.Name;
                                     var cbmtSub = cbm.RootTools.AddButtonTool(cmdKey, mi.Name, null);
                                     cbmtSub.ToolClick += (s, e) => { mi.Invoke(null, null); };
                                     var its = itm.Tools.AddTool(cbmtSub.Key);
                                     its.IsFirstInGroup = true;
                                     its.Visible = true;
                                     its.Tag = att.AllowType;
                                     if (att.ToolTiString != "")
                                         its.Tooltip = att.ToolTiString;
                                 }
                                 itm.IsFirstInGroup = true;
                                 itm.Visible = true;
                                 MyMenus.Add(itm);
                             }
                         }
                     }
                 }
                 //config.RightContextMenu.ShowPopup();
                 config.ContextMenu.BeforePopup += ContextMenu_BeforePopup;
                 config.ContextMenu.AfterCloseup += ContextMenu_AfterCloseup;
                 config.ContextMenu.PopupStyle = PopupStyle.Menu;
                 config.ContextMenu.DropDownArrowStyle = DropDownArrowStyle.SegmentedStateButton;
                 //config.ContextMenu.AllowTearaway = true;
                 #endregion
             }
             else
             {
                 config.FontStyle.LeftNameAttribute = null;
                 config.FontStyle.RightNameAttribute = null;
             }
             de1.Configuration = config;
         }
         catch (Exception ex)
         {
             ex.OutPutExcptionMess();
         }
     }

     private static void ContextMenu_AfterCloseup(object sender, EventArgs e)
     {
         try
         {
             foreach (var item in MyMenus)
             {

                 foreach (ITool btl in item.Tools)
                 {
                     btl.Visible = true;
                 }
                 item.Visible = true;
             }
         }
         catch (Exception ex)
         {
             ex.OutPutExcptionMess();
         }
     }

     private static void ContextMenu_BeforePopup(object sender, EventArgs e)
     {
         try
         {
             var activeNode = UIEx.Design_Explorer.SelectedNode as ExplorerTreeNode;
             if (activeNode == null) return;
             var curEleType = activeNode.Element.GetActualType().Name;
             foreach (var item in MyMenus)
             {
                 int counUnVisiable = 0;

                 foreach (ITool btl in item.Tools)
                 {
                     var methodNeedType = btl.Tag.ToString();
                     if (methodNeedType == "")
                     {
                         btl.Visible = true;
                     }
                     else
                     {
                         if (!methodNeedType.Contains(","))
                         {
                             btl.Visible = string.Compare(methodNeedType, curEleType, true) == 0;
                             if (!btl.Visible)
                             {
                                 counUnVisiable++;
                             }
                         }
                         else
                         {
                             var types = methodNeedType.Split(',').ToList().Select(c => c.ToUpper());
                             btl.Visible = types.Contains(curEleType);
                             if (!btl.Visible)
                             {
                                 counUnVisiable++;
                             }
                         }
                     }
                 }
                 if (counUnVisiable == item.Tools.Count)
                     item.Visible = false;
             }
         }
         catch (Exception ex)
         {
             ex.OutPutExcptionMess();
         }
     }
 }

示例方法

 

[MyDesignExplorerRightClicKAtt("")]
public static void 查找占用人员信息()
{
    try
    {
        var cdl = Aveva.Pdms.Graphics.DrawListManager.Instance.CurrentDrawList;
        AmHullEnv env = new AmHullEnv();
        var ce = Aveva.Pdms.Shared.CurrentElement.Element;
        if (!ce.IsOk()) return;
        StringBuilder sb = new StringBuilder();
        List<DbAttribute> attributes = new List<DbAttribute>()
        {
            DbAttributeInstance.CLMID,
             DbAttributeInstance.USERC
        };
        foreach (var item in attributes)
        {
            sb.AppendLine($"{item.ShortName}====>{ce.GetAsString(item)}");
        }
        env.Ui.MessageConfirm(sb.ToString());
    }
    catch (Exception ex)
    {
        ex.OutPutExcptionMess();
    }
}

 

标签:Explorer,自定义,ContextMenu,c#,true,item,var,null,config
From: https://www.cnblogs.com/NanShengBlogs/p/18017401

相关文章

  • [Vue] CSS中的v-bind
    在Vue中说到v-bind大多数时候都是想到template中动态绑定script中的响应式数据。但其实在单文件组件(SFC)中,<style>标签内也可以使用v-bind函数绑定数据。如上图第18行代码,使用v-bind(color)绑定了数据。当数据变化时,css样式随之变化:原理:(截取自Vue官方文档)实际的值会被编......
  • D. Sasha and a Walk in the City
    D.SashaandaWalkintheCitySashawantstotakeawalkwithhisgirlfriendinthecity.Thecityconsistsof$n$intersections,numberedfrom$1$to$n$.Someofthemareconnectedbyroads,andfromanyintersection,thereisexactlyonesimplepath$......
  • edusrc尝试
    挖掘基本工具准备信息搜集:OneForAlloneforall可以搜集子域名,并且会输出保存在表格中,非常方便oneforall基本用法:pyoneforall.py--targetwww.xx.com结果保存在results目录下的对应域名的excel表格中抓包工具:burpsuite,proxifier如果不挖微信小程序或者app,只有burp......
  • Unity 类胡闹厨房游戏 KitchenChaos 阶段1整理记录
    原教程地址:https://youtu.be/AmGSEH7QcDg部分代码:usingSystem.Collections;usingSystem.Collections.Generic;usingUnityEngine;publicclassPlayerAnimator:MonoBehaviour{privateconststringIS_WALKING="IsWalking";[SerializeField]priv......
  • CF739A Alyona and mex 题解
    题目简单构造,首先我们知道一个区间\([l,r]\)内的最大答案为为这个区间的长度\(len\),因为其中可以包括\([0,r-l+1]\)这些数。所以\(ans=min(len_i)\)。考虑如何满足这个条件,设最小长度为\(len_{min}\),我们可以轮流输出\([0,len_{min}]\),因为\(len_{min}\)是最小长度,所......
  • P1204 [USACO1.2] 挤牛奶Milking Cows
    原题链接题解细节颇多看代码code#include<bits/stdc++.h>usingnamespacestd;structunit{ints,e;}milk[5005];boolcmp(unita,unitb){returna.s<b.s;}intmain(){intn;cin>>n;for(inti=1;i<=n;i++)cin>>milk[i].s......
  • Excalibur维护日记
    序之前看一些大神都有自己写的pwn题写exp用的python库,想着自己也写一个自用,方便exp的编写虽然不是什么好东西,也只有几行简单的代码,但本着开源分享的原则,今天研究了一下传到pypi上了23年暑假写的时候正在狂刷fate,然后直接粉上吾王,于是给库其名为Excalibur。至于为什么有个2,传的......
  • 第 8章 Python 爬虫框架 Scrapy(下)
    第8章Python爬虫框架Scrapy(下)8.1Scrapy对接Selenium有一种反爬虫策略就是通过JS动态加载数据,应对这种策略的两种方法如下:分析Ajax请求,找出请求接口的相关规则,直接去请求接口获取数据。使用Selenium模拟浏览器渲染后抓取页面内容。8.1.1如何对接单独使用Sc......
  • Codeforces Round 926 (Div. 2) DEF
    D.SashaandaWalkintheCity题意:给定一棵树,问不存在三个点属于同一条路径的点集个数。\(f[x]\)表示,最近公共祖先为\(x\)的合法非空集数量。如果选\(x\),那么只能为不选子树或选一棵子树,否则\(u\insubtree[y_1]\),\(v\insubtree[y_2]\)与\(x\)共链。?贡献为\(......
  • 计数选讲tzc
    ARC154EReverseandInversion要长脑子了。首先先尝试拆一拆贡献。对原来的式子进行一定的化简,可以得到:\[\sum\limits_{i}i(\sum\limits_{i>j}[P_j>P_i]-\sum\limits_{i<j}[P_i>P_j])\\=\sum\limits_{i}i(i-P_i)\]因此我们只需要求出每个\(P_i\)被换到哪里即可。注意到初......