1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111 |
- using PaintDotNet.Base.SettingModel;
- using PaintDotNet.Base.CommTool;
- using PaintDotNet.DbOpreate.DbBll;
- using PaintDotNet.DbOpreate.DbModel;
- using PaintDotNet.ImageCollect;
- using PaintDotNet.SystemLayer;
- using System;
- using System.Collections.Generic;
- using System.Data.Entity.Core.Mapping;
- using System.Data.Entity.Core.Metadata.Edm;
- using System.Data.Entity.Infrastructure;
- using System.Diagnostics;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- using System.Configuration;
- using SenseShield;
- using System.Drawing;
- using Metis.ParameterSet;
- using PaintDotNet.Annotation;
- using PaintDotNet.Base;
- using StageController;
- using System.IO.Ports;
- using PaintDotNet.Camera;
- using OpenCvSharp;
- using Metis;
- namespace PaintDotNet
- {
- internal sealed class Startup
- {
- public static Startup instance;
- public SplashForm splashForm = null;
- /// <summary>
- /// 启动时传进来的参数,需要进行解析
- /// 在自定义快捷方式的时候会用到
- /// 读取不同的配置路径的配置信息
- /// </summary>
- private string[] args;
- /// <summary>
- /// 主窗体
- /// </summary>
- private MainForm mainForm;
- /// <summary>
- /// 设置信息所在的文件夹
- /// </summary>
- public string SettingPrefix = "Default";
- /// <summary>
- /// 常规设置-用户信息
- /// </summary>
- public UserInfoModel userInfo;
- /// <summary>
- /// 常规设置-网格信息
- /// </summary>
- public GridModel gridModel;
- /// <summary>
- /// 系统配置
- /// </summary>
- public ConfigModel configModel;
- /// <summary>
- /// 载物台配置
- /// </summary>
- public LoadingStageModel loadingStageModel;
- /// <summary>
- /// 快捷键配置
- /// </summary>
- public HotkeyModel hotkeyModel;
- /// <summary>
- /// 工具栏
- /// </summary>
- public ToolbarModel toolbarModel;
- /// <summary>
- /// 工具栏坐标
- /// </summary>
- //public ToolbarLocationModel toolbarLocationModel;
- /// <summary>
- /// 水印配置
- /// </summary>
- public WatermarkModel watermarkModel;
- /// <summary>
- /// 工字线配置
- /// </summary>
- public WorkTypeStyleModel workTypeStyleModel;
- /// <summary>
- /// 标尺配置
- /// </summary>
- public RulerModel rulerModel;
- /// <summary>
- /// 工作流程
- /// </summary>
- public WorkFlowModel workFlowModel;
- /// <summary>
- /// 快捷栏
- /// </summary>
- public ShortcutbarModel shortcutbarModel;
- /// <summary>
- /// 标注样式信息
- /// </summary>
- public LabelStyleModel labelStyleModel;
- /// <summary>
- /// 测量样式信息
- /// </summary>
- public MeasureStyleModel measureStyleModel;
- /// <summary>
- /// 设置-常规设置-辅助线样式信息
- /// </summary>
- public GuideStyleModel guideStyleModel;
- /// <summary>
- /// 换算完的标尺信息,包含所有系统内得单位
- /// </summary>
- public Dictionary<MeasurementUnit, double> rules = new Dictionary<MeasurementUnit, double>();
- /// <summary>
- /// 系统内选定的单位
- /// </summary>
- public MeasurementUnit measurementUnit;
- /// <summary>
- /// 相机参数
- /// </summary>
- public CameraParamModel cameraParamModel;
- /// <summary>
- /// 当前系统标尺
- /// </summary>
- public mic_rulers ruleDB;
- /// <summary>
- /// 标尺集合
- /// </summary>
- public List<mic_rulers> mic_rulersAll;
- /// <summary>
- /// 单位对应的枚举数字
- /// </summary>
- public Dictionary<string, int> companyEnume;
- /// <summary>
- /// 工艺图比照
- /// </summary>
- public ArtworkModel artworkModel;
- /// <summary>
- /// 电动偏光设置
- /// </summary>
- public MotorizedLightModel motorizedLightModel;
- /// <summary>
- /// 电压设置
- /// </summary>
- public VoltageModel voltageModel;
- /// <summary>
- /// 图像处理参数
- /// </summary>
- public ImageMenu imageMenuModel;
- /// <summary>
- /// 二值处理参数
- /// </summary>
- public ImageMenu binaryActionModel;
- /// <summary>
- /// 是否开启加密锁验证
- /// </summary>
- private static/*const*/ bool useSenseShield = false;//true;//
- private static bool haveShowSenseAlert = false;
- /// <summary>
- /// 将value为FALSE的菜单隐藏显示,key为要隐藏的menuID
- /// </summary>
- private static Dictionary<uint, bool> shieldValue = new Dictionary<uint, bool>();
- public static bool showNsegExtraction = true;//控制是否显示晶界重现菜单
- public int step_length = 1;
- /// <summary>
- /// 是否启用大图
- /// </summary>
- public bool useBigFile = true;
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="args"></param>
- private Startup(string[] args)
- {
- Application.SetCompatibleTextRenderingDefault(false);
- Application.EnableVisualStyles();
- //先单独获取App基础配置
- configModel = XmlSerializeHelper.DESerializer<ConfigModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Config.xml", FileMode.Open));
- PdnResources.Initialize(configModel);
- if (configModel.StartImgStatus == 2)
- {
- this.splashForm = new SplashForm(configModel.StartImg);
- var width = Screen.PrimaryScreen.WorkingArea.Width;
- var height = Screen.PrimaryScreen.WorkingArea.Height;
- this.splashForm.Location = new System.Drawing.Point(width / 2 - 300, height / 2 - 200);
- this.splashForm.TopMost = true;
- this.splashForm.Show();
- this.splashForm.Update();
- }
- this.args = args;
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
- config.ConnectionStrings.ConnectionStrings["DBEntities"].ConnectionString = "Data Source=" + Application.StartupPath + @"\microscope.db3";
- config.Save(ConfigurationSaveMode.Modified);
- ConfigurationManager.RefreshSection("connectionStrings");
- //用于EF暖机操作,以避免第一次度数据库过慢
- using (var dbcontext = new PaintDotNet.DbOpreate.DBEntities())
- {
- var objectContext = ((IObjectContextAdapter)dbcontext).ObjectContext;
- var mappingCollection = (StorageMappingItemCollection)objectContext.MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
- mappingCollection.GenerateViews(new List<EdmSchemaError>());
- }
- if (useBigFile)
- {
- //设置内存映射文件的路径,回头考虑写到配置文件,或者检测空闲最大的磁盘
- //Mat.SetMappingFilePath("d://");
- //设置最大像素值后采用内存映射文件
- //Mat.SetMaxPixelSize(MemoryBlock.bigFile);
- }
- }
- /// <summary>
- /// 启动一个实例
- /// </summary>
- /// <param name="parent"></param>
- /// <param name="requireAdmin">是否需要管理员权限</param>
- /// <param name="args">传递进来的参数</param>
- public static void StartNewInstance(IWin32Window parent, bool requireAdmin, string[] args)
- {
- StringBuilder allArgsSB = new StringBuilder();
- foreach (string arg in args)
- {
- allArgsSB.Append(' ');
- if (arg.IndexOf(' ') != -1)
- {
- allArgsSB.Append('"');
- }
- allArgsSB.Append(arg);
- if (arg.IndexOf(' ') != -1)
- {
- allArgsSB.Append('"');
- }
- }
- string allArgs;
- if (allArgsSB.Length > 0)
- {
- allArgs = allArgsSB.ToString(1, allArgsSB.Length - 1);
- }
- else
- {
- allArgs = null;
- }
- Shell.Execute(
- parent,
- Application.ExecutablePath,
- allArgs,
- requireAdmin ? ExecutePrivilege.RequireAdmin : ExecutePrivilege.AsInvokerOrAsManifest,
- ExecuteWaitType.ReturnImmediately);
- }
- /// <summary>
- /// 检查需要的文件是否存在
- /// 并且尝试修复
- /// </summary>
- /// <returns>
- /// 返回true则说明缺少东西
- /// 返回false则说明都正常
- /// </returns>
- private bool CheckForImportantFiles()
- {
- string[] requiredFiles =
- new string[]
- {
- "ICSharpCode.SharpZipLib.dll",
- "PaintDotNet.Base.dll",
- "PaintDotNet.Core.dll",
- "PaintDotNet.Data.dll",
- "PaintDotNet.Resources.dll",
- "PaintDotNet.Strings.3.DE-DE.resources",
- "PaintDotNet.Strings.3.EN-US.resources",
- "PaintDotNet.Strings.3.ZH-CN.resources",
- "PaintDotNet.SystemLayer.dll",
- "SetupNgen.exe",
- "ShellExtension_x64.dll",
- "ShellExtension_x86.dll"
- /*"Squish_x64.dll",
- "Squish_x86.dll",
- "Squish_x86_SSE2.dll"*/
- };
- string dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
- List<string> missingFiles = null;
- foreach (string requiredFile in requiredFiles)
- {
- bool missing;
- try
- {
- string pathName = Path.Combine(dirName, requiredFile);
- FileInfo fileInfo = new FileInfo(pathName);
- missing = !fileInfo.Exists;
- }
- catch (Exception)
- {
- missing = true;
- }
- if (missing)
- {
- if (missingFiles == null)
- {
- missingFiles = new List<string>();
- }
- missingFiles.Add(requiredFile);
- }
- }
- if (missingFiles == null)
- {
- return false;
- }
- else
- {
- if (Shell.ReplaceMissingFiles(missingFiles.ToArray()))
- {
- // Everything is repaired and happy.
- return true;
- }
- else
- {
- // Things didn't get fixed. Bail.
- Process.GetCurrentProcess().Kill();
- return false;
- }
- }
- }
- public void Start()
- {
- Process[] app = Process.GetProcessesByName("Metis");
- if (app.Length > 1)
- {
- //added begin by songxk
- //杀掉进程,启动metis
- for (int i = 0; i < app.Length - 1; i++)
- {
- var ap = app[i];
- ap.Kill();
- }
- //added end by songxk
- }
- // Initialize some misc. Windows Forms settings
- //StartAnimation();
- // If any files are missing, try to repair.
- // However, support /skipRepairAttempt for when developing in the IDE
- // so that we don't needlessly try to repair in that case.
- //if (this.args.Length > 0 &&
- // string.Compare(this.args[0], "/skipRepairAttempt", StringComparison.InvariantCultureIgnoreCase) == 0)
- //{
- // // do nothing: we need this so that we can run from IDE/debugger
- // // without it trying to repair itself all the time
- //}
- //else
- //{
- // if (CheckForImportantFiles())
- // {
- // Startup.StartNewInstance(null, true, args);
- // return;
- // }
- //}
- StartPart2();
- }
- /// <summary>
- /// 设置语言、地区等
- /// </summary>
- private void StartPart2()
- {
- InitCameraManager();
- InitStageController();
- string locale = Settings.CurrentUser.GetString(SettingNames.LanguageName, null);
- if (locale == null)
- {
- locale = Settings.SystemWide.GetString(SettingNames.LanguageName, null);
- }
- if (locale != null)
- {
- try
- {
- CultureInfo ci = new CultureInfo(locale, true);
- Thread.CurrentThread.CurrentUICulture = ci;
- }
- catch (Exception)
- {
- // Don't want bad culture name to crash us
- }
- }
- // Check system requirements
- if (!OS.CheckOSRequirement())
- {
- string message = PdnResources.GetString("Error.OSRequirement");
- Utility.ErrorBox(null, message);
- return;
- }
- // Parse command-line arguments
- if (this.args.Length == 1) // && this.args[0] == Updates.UpdatesOptionsDialog.CommandLineParameter
- {
- //Updates.UpdatesOptionsDialog.ShowUpdateOptionsDialog(null, false);
- }
- else
- {
- SingleInstanceManager singleInstanceManager = new SingleInstanceManager("hero");
- // If this is not the first instance of PDN.exe, then forward the command-line
- // parameters over to the first instance.
- if (!singleInstanceManager.IsFirstInstance)
- {
- singleInstanceManager.FocusFirstInstance();
- foreach (string arg in this.args)
- {
- singleInstanceManager.SendInstanceMessage(arg, 30);
- }
- singleInstanceManager.Dispose();
- singleInstanceManager = null;
- return;
- }
- // Create main window
- this.mainForm = new MainForm(this.args);
- this.mainForm.SingleInstanceManager = singleInstanceManager;
- singleInstanceManager = null; // mainForm owns it now
- if (useSenseShield)
- StartPart3();
- // 3 2 1 go
- Application.Run(this.mainForm);
- try
- {
- this.mainForm.Dispose();
- CameraManager.GetInstance().UnInitManager();
- AxisController.GetInstance().Close();
- }
- catch (Exception)
- {
- }
- this.mainForm = null;
- }
- }
- /// <summary>
- /// 设置定时方法
- /// </summary>
- private void StartPart3()
- {
- //主线程中启动一个支线程,执行doSomething这样的一个方法。
- Thread thread = new Thread(new ThreadStart(ThreadRun));
- thread.IsBackground = true;//这样能随主程序一起结束
- thread.Start();
- //Console.ReadKey();
- }
- delegate void Delegate_do();
- private void ThreadRun()
- {
- try
- {
- Delegate_do Delegate_do = new Delegate_do(FindAllProduct);
- Thread.Sleep(30000);//隔30秒后判断一下是否完成
- IAsyncResult result = Delegate_do.BeginInvoke(null, null);
- while (!result.IsCompleted)
- {
- Console.WriteLine("子线程未完成2");
- Thread.Sleep(10000);//每隔10秒判断一下是否完成
- }
- Console.WriteLine("-------子线程已完成-------");
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex.Message);
- }
- }
- private void FindAllProduct()
- {
- List<uint> moduleList = new List<uint>() { 1 };
- while (true)
- {
- try
- {
- uint[] moduleIds = moduleList.ToArray();
- moduleIds = DogDecrypting.decryptingModules(4/*, moduleIds*/);//第一个参数固定为4
- Console.WriteLine("颁发许可发现。");
- }
- catch (Exception ex)
- {
- if (!haveShowSenseAlert)
- {
- Console.WriteLine("发现错误:" + ex.Message);
- haveShowSenseAlert = true;
- ShowMessage(ex.Message);
- }
- while (senseShieldAutoLoop(moduleList) == false)
- {
- Console.WriteLine("仍然错误:颁发许可未发现");
- System.Threading.Thread.Sleep(20);
- }
- }
- Console.WriteLine("子线程未完成1");
- Thread.Sleep(10000);//每隔10秒判断一下是否发现颁发许可
- }
- }
- private bool senseShieldAutoLoop(List<uint> moduleList)
- {
- try
- {
- uint[] moduleIds = moduleList.ToArray();
- moduleIds = DogDecrypting.decryptingModules(4/*, moduleIds*/);//第一个参数固定为4
- }
- catch (Exception ex)
- {
- if (!haveShowSenseAlert)
- {
- haveShowSenseAlert = true;
- ShowMessage(ex.Message);
- }
- return false;
- }
- return true;
- }
- private void ShowMessage(string msg)
- {
- this.mainForm.Invoke(new MessageBoxShow(MessageBoxShow_F), new object[] { msg });
- }
- delegate void MessageBoxShow(string msg);
- void MessageBoxShow_F(string msg)
- {
- if (MessageBox.Show(msg, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
- haveShowSenseAlert = false;
- }
- /// <summary>
- /// 程序主入口
- /// </summary>
- [STAThread]
- public static int Main(string[] args)
- {
- //instance = new Startup(args);
- //instance.ModifySettingPrefix(args);
- //instance.SystemReset();
- //instance.InitSetting();
- //Application.Run(new Preview2.Preview2Dialog());
- //return 1;
- //这是要求管理员权限的版本
- /*//当前用户是管理员的时候,直接启动应用程序
- //如果不是管理员,则使用启动对象启动程序,以确保使用管理员身份运行
- //获得当前登录的Windows用户标示
- System.Security.Principal.WindowsIdentity identity = System.Security.Principal.WindowsIdentity.GetCurrent();
- //创建Windows用户主题
- Application.EnableVisualStyles();
- System.Security.Principal.WindowsPrincipal principal = new System.Security.Principal.WindowsPrincipal(identity);
- //判断当前登录用户是否为管理员
- if (principal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator))
- {
- //如果是管理员,则直接运行
- //Application.EnableVisualStyles();
- //Application.Run(new Form1());
- instance = new Startup(args);
- instance.ModifySettingPrefix(args);
- instance.SystemReset();
- instance.InitSetting();
- instance.Start();
- // 为了测试用
- if (System.IO.File.Exists(Application.StartupPath + @"\1.txt"))
- useSenseShield = true;
- if (useSenseShield)
- {
- shieldValue.Clear();
- try
- {
- //1.生成目录下需要有4个运行库,分别在x64和x86下,每个里面两个
- //2.在C#项目里引用SlmRuntimeCsharp.dll
- //3.插入加密狗,执行代码测试
- uint[] moduleIds = DogDecrypting.decryptingModules(4*//*, moduleIds*//*);//第一个参数固定为4
- //this.label2.Text = string.Format("加密狗内许可模块号:{0}{1}", Environment.NewLine, string.Join(",", moduleIds));
- foreach (uint menuId in moduleIds)
- if (!shieldValue.ContainsKey(menuId))
- shieldValue.Add(menuId, true);
- else
- shieldValue[menuId] = true;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return 0;
- }
- }
- instance = new Startup(args);
- instance.ModifySettingPrefix(args);
- instance.SystemReset();
- instance.InitSetting();
- instance.Start();
- }
- else
- {
- //创建启动对象
- System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
- //设置运行文件
- startInfo.FileName = System.Windows.Forms.Application.ExecutablePath;
- //设置启动参数
- //startInfo.Arguments = String.Join(" ", Args);
- //设置启动动作,确保以管理员身份运行
- startInfo.Verb = "runas";
- try
- {
- //如果不是管理员,则启动UAC
- System.Diagnostics.Process.Start(startInfo);
- //退出
- System.Windows.Forms.Application.Exit();
- }
- catch
- {
- }
- }*/
- //这是不要求管理员权限的版本
- if (System.IO.File.Exists(Application.StartupPath + @"\1.txt"))
- useSenseShield = true;
- if (System.IO.File.Exists(Application.StartupPath + @"\000.txt")) showNsegExtraction = false;
- if (useSenseShield)
- {
- shieldValue.Clear();
- try
- {
- //1.生成目录下需要有4个运行库,分别在x64和x86下,每个里面两个
- //2.在C#项目里引用SlmRuntimeCsharp.dll
- //3.插入加密狗,执行代码测试
- uint[] moduleIds = DogDecrypting.decryptingModules(4/*, moduleIds*/);//第一个参数固定为4
- //this.label2.Text = string.Format("加密狗内许可模块号:{0}{1}", Environment.NewLine, string.Join(",", moduleIds));
- foreach (uint menuId in moduleIds)
- if (!shieldValue.ContainsKey(menuId))
- shieldValue.Add(menuId, true);
- else
- shieldValue[menuId] = true;
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return 0;
- }
- }
- instance = new Startup(args);
- instance.ModifySettingPrefix(args);
- instance.SystemReset();
- instance.InitSetting();
- instance.Start();
- //if (instance.configModel.StartImgStatus == 2)
- //{
- // //this.splashForm = new SplashForm();
- // SplashForm splashForm = new SplashForm(Startup.instance.configModel.StartImg);
- // splashForm.TopMost = true;
- // splashForm.Show();
- // splashForm.Update();
- //}
- return 0;
- }
- /// <summary>
- /// 获取menuId对应的菜单是否显示
- /// </summary>
- /// <param name="menuId"></param>
- /// <returns></returns>
- public static bool getMenuIdVisible(int menuId)
- {
- if (shieldValue.ContainsKey((uint)menuId))
- return shieldValue[(uint)menuId];
- if (!useSenseShield)
- return true;
- return false;
- }
- public static bool senseShieldRunLoop()
- {
- try
- {
- uint[] moduleIds = DogDecrypting.decryptingModules(4/*, moduleIds*/);//第一个参数固定为4
- }
- catch (Exception ex)
- {
- if (!haveShowSenseAlert)
- {
- haveShowSenseAlert = true;
- if (MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
- haveShowSenseAlert = false;
- }
- return false;
- }
- return true;
- }
- /// <summary>
- /// 获取menuId对应的菜单是否可点击
- /// </summary>
- /// <param name="menuId"></param>
- /// <param name="showAlert">是否显示提示框</param>
- /// <returns></returns>
- public static bool getMenuIdUsable(List<int> menuIdlists, bool showAlert = false)
- {
- if (useSenseShield)
- {
- try
- {
- uint[] moduleIds = DogDecrypting.decryptingModules(4/*, moduleIds*/);//第一个参数固定为4
- //this.label2.Text = string.Format("加密狗内许可模块号:{0}{1}", Environment.NewLine, string.Join(",", moduleIds));
- bool existMenuId = false;
- foreach (uint theMenuId in moduleIds)
- if (menuIdlists.Contains((int)theMenuId))
- {
- existMenuId = true;
- break;
- }
- if (!existMenuId && showAlert && !haveShowSenseAlert)
- {
- haveShowSenseAlert = true;
- if (MessageBox.Show("该模块颁发许可未发现", "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
- haveShowSenseAlert = false;
- }
- //haveShowSenseAlert = false;
- return existMenuId;
- }
- catch (Exception ex)
- {
- if (showAlert && !haveShowSenseAlert)
- {
- haveShowSenseAlert = true;
- if (MessageBox.Show(ex.Message, "错误:", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
- haveShowSenseAlert = false;
- }
- //return false;
- while (senseShieldRunLoop() == false)
- {
- System.Threading.Thread.Sleep(20);
- }
- }
- }
- return true;
- }
- /// <summary>
- /// 初始化配置信息
- /// </summary>
- private void InitSetting()
- {
- //App基础配置
- //configModel = XmlSerializeHelper.DESerializer<ConfigModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Config.xml", FileMode.Open));
- //载物台配置信息
- loadingStageModel = XmlSerializeHelper.DESerializer<LoadingStageModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\LoadingStage.xml", FileMode.Open));
- //设置->常规设置->用户信息
- userInfo = XmlSerializeHelper.DESerializer<UserInfoModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\UserInfo.xml", FileMode.Open));
- //设置->网格设置
- gridModel = XmlSerializeHelper.DESerializer<GridModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Grid.xml", FileMode.Open));
- //工具->自定义界面-快捷键配置
- hotkeyModel = XmlSerializeHelper.DESerializer<HotkeyModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Hotkey.xml", FileMode.Open));
- //工具->工作流程
- workFlowModel = XmlSerializeHelper.DESerializer<WorkFlowModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\WorkFlow.xml", FileMode.Open));
- //工具->自定义界面-快捷栏
- shortcutbarModel = XmlSerializeHelper.DESerializer<ShortcutbarModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Shortcutbar.xml", FileMode.Open));
- //工具->自定义界面-工具栏
- toolbarModel = XmlSerializeHelper.DESerializer<ToolbarModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Toolbar.xml", FileMode.Open));
- //toolbarLocationModel = XmlSerializeHelper.DESerializer<ToolbarLocationModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\ToolbarLocation.xml", FileMode.Open));
- //标注样式配置
- labelStyleModel = XmlSerializeHelper.DESerializer<LabelStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Label\\" + configModel.LabelStyle, FileMode.Open));
- //测量样式配置
- measureStyleModel = XmlSerializeHelper.DESerializer<MeasureStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Measure\\" + configModel.MeasurementStyle, FileMode.Open));
- // 设置-常规设置-辅助线样式信息
- guideStyleModel = XmlSerializeHelper.DESerializer<GuideStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\SetUp\\" + "GuideStyle.xml", FileMode.Open)); ;
- //水印样式配置
- watermarkModel = XmlSerializeHelper.DESerializer<WatermarkModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Watermark\\" + configModel.Watermark, FileMode.Open));
- // 工字线配置
- workTypeStyleModel = XmlSerializeHelper.DESerializer<WorkTypeStyleModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\WorkType\\" + configModel.WorkType, FileMode.Open));
- //标尺样式配置
- rulerModel = XmlSerializeHelper.DESerializer<RulerModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Ruler.xml", FileMode.Open));
- //相机参数配置
- cameraParamModel = CameraConfigs.GetInstance().GetCurrentCameraParamModel(); // XmlSerializeHelper.DESerializer<CameraParamModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\CameraParam\\CameraParam.xml", FileMode.Open));
- //工艺图比照配置
- artworkModel = XmlSerializeHelper.DESerializer<ArtworkModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\ArtworkModel.xml", FileMode.Open));
- //电动偏光配置
- motorizedLightModel = XmlSerializeHelper.DESerializer<MotorizedLightModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\MotorizedLightModel.xml", FileMode.Open));
- //电压配置
- voltageModel = XmlSerializeHelper.DESerializer<VoltageModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\VoltageModel.xml", FileMode.Open));
- imageMenuModel = XmlSerializeHelper.DESerializer<ImageMenu>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\ParameterSaving\\ParameterSaving.xml", FileMode.Open));
- binaryActionModel = XmlSerializeHelper.DESerializer<ImageMenu>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\BinaryActionSaving\\ParameterSaving.xml", FileMode.Open));
- //初始化提取,DB中保存的的标尺
- mic_rulersAll = mic_rulers_BLL.FindAll();
- //初始化标尺信息
- InitRulerInfo();
- //初始化App内的单位
- InitUnitInfo();
- //初始化单位对应的枚举数字
- CompanyEnumeration();
- }
- /// <summary>
- /// 初始化系统选择的单位的信息
- /// 单位对应的枚举数字
- /// </summary>
- public void CompanyEnumeration()
- {
- companyEnume = new Dictionary<string, int>();
- companyEnume.Add(PdnResources.GetString("MeasurementUnit.Inch"), 1);//英寸
- companyEnume.Add(PdnResources.GetString("MeasurementUnit.Mil"), 7);//英寸
- companyEnume.Add(PdnResources.GetString("Menu.cm.text"), 2);//厘米
- companyEnume.Add(PdnResources.GetString("Menu.Mm.text"), 3);//毫米
- companyEnume.Add(PdnResources.GetString("Menu.Micron.text"), 4);//微米
- companyEnume.Add(PdnResources.GetString("Menu.nanometer.text"), 5);//纳米
- companyEnume.Add(PdnResources.GetString("Menu.Pixel.text"), 6);//像素
- }
- /// <summary>
- /// 初始化系统选择的单位的信息
- /// 如果初始安装没有设置过,则默认微米
- /// </summary>
- public void InitUnitInfo()
- {
- if (configModel != null && configModel.Unit > 0)
- {
- measurementUnit = (MeasurementUnit)Enum.Parse(typeof(MeasurementUnit), configModel.Unit.ToString());
- }
- else
- {
- measurementUnit = MeasurementUnit.Micron;
- }
- }
- /// <summary>
- /// 初始化标尺信息,从数据库中读取
- /// 然后根据标尺的单位,换算出所有单位的数据
- /// </summary>
- public void InitRulerInfo()
- {
- rules.Clear();
- if (configModel != null /*&& configModel.RulerId>0*/)
- {
- for (int i = 0; i < Startup.instance.mic_rulersAll.Count; i++)
- {
- if (Startup.instance.mic_rulersAll[i].id == configModel.RulerId)
- {
- ruleDB = Startup.instance.mic_rulersAll[i];
- break;
- }
- }
- //ruleDB = mic_rulers_BLL.FindDefault(configModel.RulerId);
- if (ruleDB != null)
- {
- //计算单位长度 比如0.05英寸/像素; 100纳米/像素;
- double unitLength = (double)(ruleDB.physical_length / (decimal)ruleDB.pixel_length);
- switch (ruleDB.ruler_units)
- {
- case (int)MeasurementUnit.Inch://英寸
- rules.Add(MeasurementUnit.Inch, unitLength); //英寸
- rules.Add(MeasurementUnit.Mil, 1000 * unitLength); //米尔
- rules.Add(MeasurementUnit.Centimeter, 2.54 * unitLength); //厘米
- rules.Add(MeasurementUnit.Millimeter, 25.4 * unitLength); //毫米
- rules.Add(MeasurementUnit.Micron, 25400 * unitLength); //微米
- rules.Add(MeasurementUnit.Nano, 25400000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Mil://米尔
- rules.Add(MeasurementUnit.Mil, unitLength); //米尔
- rules.Add(MeasurementUnit.Inch, 0.001 * unitLength); //英寸
- rules.Add(MeasurementUnit.Centimeter, 0.00254 * unitLength); //厘米
- rules.Add(MeasurementUnit.Millimeter, 0.0254 * unitLength); //毫米
- rules.Add(MeasurementUnit.Micron, 25.4 * unitLength); //微米
- rules.Add(MeasurementUnit.Nano, 25400 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Centimeter://厘米
- rules.Add(MeasurementUnit.Inch, 0.3937008 * unitLength); //英寸
- rules.Add(MeasurementUnit.Mil, 393.7008 * unitLength); //米尔
- rules.Add(MeasurementUnit.Centimeter, unitLength); //厘米
- rules.Add(MeasurementUnit.Millimeter, 10 * unitLength); //毫米
- rules.Add(MeasurementUnit.Micron, 10000 * unitLength); //微米
- rules.Add(MeasurementUnit.Nano, 10000000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Millimeter://毫米
- rules.Add(MeasurementUnit.Inch, 0.0393701 * unitLength); //英寸
- rules.Add(MeasurementUnit.Mil, 39.3701 * unitLength); //米尔
- rules.Add(MeasurementUnit.Centimeter, 0.1 * unitLength); //厘米
- rules.Add(MeasurementUnit.Millimeter, unitLength); //毫米
- rules.Add(MeasurementUnit.Micron, 1000 * unitLength); //微米
- rules.Add(MeasurementUnit.Nano, 1000000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Micron://微米
- rules.Add(MeasurementUnit.Inch, 0.00003937007874 * unitLength); //英寸
- rules.Add(MeasurementUnit.Mil, 0.03937007874 * unitLength); //米尔
- rules.Add(MeasurementUnit.Centimeter, 0.0001 * unitLength); //厘米
- rules.Add(MeasurementUnit.Millimeter, 0.001 * unitLength); //毫米
- rules.Add(MeasurementUnit.Micron, unitLength); //微米
- rules.Add(MeasurementUnit.Nano, 1000 * unitLength); //纳米
- break;
- case (int)MeasurementUnit.Nano://纳米
- rules.Add(MeasurementUnit.Inch, 3.9370e-8 * unitLength); //英寸
- rules.Add(MeasurementUnit.Mil, 3.9370e-5 * unitLength); //米尔
- rules.Add(MeasurementUnit.Centimeter, 1e-7 * unitLength); //厘米
- rules.Add(MeasurementUnit.Millimeter, 1e-6 * unitLength); //毫米
- rules.Add(MeasurementUnit.Micron, 0.001 * unitLength); //微米
- rules.Add(MeasurementUnit.Nano, unitLength); //纳米
- break;
- default:
- ruleDB = null;
- break;
- }
- }
- }
- if (ruleDB == null)
- {
- //如果没有标尺的时候,默认1微米/像素
- rules.Add(MeasurementUnit.Inch, 0.0000394); //英寸
- rules.Add(MeasurementUnit.Mil, 0.0394); //米尔
- rules.Add(MeasurementUnit.Centimeter, 0.0001); //厘米
- rules.Add(MeasurementUnit.Millimeter, 0.001); //毫米
- rules.Add(MeasurementUnit.Micron, 1); //微米
- rules.Add(MeasurementUnit.Nano, 1000); //纳米
- }
- //设置文档标尺
- Document.defaultDpi = 1 / rules[MeasurementUnit.Inch];
- }
- /// <summary>
- /// 判断是否根据快捷方式参数修改界面
- /// </summary>
- /// <param name="argsArr"></param>
- /// <returns></returns>
- private bool ModifySettingPrefix(string[] argsArr)
- {
- if (argsArr.Count() == 2 && (0 == string.Compare(argsArr[0], "/personalConfig", true)))
- {
- string configName = argsArr[1].Replace("/", "");
- if (Directory.Exists(Application.StartupPath + "\\Config\\" + configName + "\\"))
- {
- this.SettingPrefix = configName;
- //MessageBox.Show("配置文件为:" + this.SettingPrefix);
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- //启动动画
- public void StartAnimation()
- {
- if (Startup.instance.configModel.StartImgStatus == 2)
- {
- //this.splashForm = new SplashForm();
- this.splashForm = new SplashForm(Startup.instance.configModel.StartImg);
- this.splashForm.TopMost = true;
- this.splashForm.StartPosition = FormStartPosition.CenterParent;
- this.splashForm.Show();
- this.splashForm.Update();
- }
- }
- /// <summary>
- /// 系统复位
- /// </summary>
- /// <returns></returns>
- private void SystemReset()
- {
- //先单独获取App基础配置
- configModel = XmlSerializeHelper.DESerializer<ConfigModel>(FileOperationHelper.ReadStringFromFile(Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Config.xml", FileMode.Open));
- MarkPointRect.markPointRectWidth = configModel.MarkpointWidth;
- MarkPointRect.MarkpointAreaColor = configModel.MarkpointAreaColor;
- MarkPointRect.MarkpointLineColor = configModel.MarkpointLineColor;
- MarkPointRect.MarkpointLineWidth = configModel.MarkpointLineWidth;
- MarkPointRect.MarkpointStyle = configModel.MarkpointStyle;
- PdnResources.Initialize(configModel);
- //需要复位
- if (configModel.LabelInformationReset == 1 || configModel.MeasurementInformationReset == 1 || configModel.LogReset == 1 ||
- configModel.ShortcutBarReset == 1 || configModel.ToolbarReset == 1 || configModel.HotKeyReset == 1)
- {
- try
- {
- //标注初始化
- if (configModel.LabelInformationReset == 1)
- {
- string originalFilePath = Application.StartupPath + "\\Config\\Original\\Label\\Default.xml";
- string destFilePath = Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Label\\Default.xml";
- System.IO.File.Copy(originalFilePath, destFilePath, true);
- configModel.LabelInformationReset = 0;
- }
- //测量初始化
- if (configModel.MeasurementInformationReset == 1)
- {
- string originalFilePath = Application.StartupPath + "\\Config\\Original\\Measure\\Default.xml";
- string destFilePath = Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Measure\\Default.xml";
- System.IO.File.Copy(originalFilePath, destFilePath, true);
- configModel.MeasurementInformationReset = 0;
- }
- //log初始化
- if (configModel.LogReset == 1)
- {
- //未处理
- configModel.LogReset = 0;
- }
- //快捷栏初始化
- if (configModel.ShortcutBarReset == 1)
- {
- string originalFilePath = Application.StartupPath + "\\Config\\Original\\Shortcutbar.xml";
- string destFilePath = Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Shortcutbar.xml";
- System.IO.File.Copy(originalFilePath, destFilePath, true);
- configModel.ShortcutBarReset = 0;
- }
- //工具栏初始化
- if (configModel.ToolbarReset == 1)
- {
- string originalFilePath = Application.StartupPath + "\\Config\\Original\\Toolbar.xml";
- string destFilePath = Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Toolbar.xml";
- System.IO.File.Copy(originalFilePath, destFilePath, true);
- configModel.ToolbarReset = 0;
- }
- //快捷键初始化
- if (configModel.HotKeyReset == 1)
- {
- string originalFilePath = Application.StartupPath + "\\Config\\Original\\Hotkey.xml";
- string destFilePath = Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Hotkey.xml";
- System.IO.File.Copy(originalFilePath, destFilePath, true);
- configModel.HotKeyReset = 0;
- }
- string configModelXml = XmlSerializeHelper.XmlSerialize<ConfigModel>(configModel);
- FileOperationHelper.WriteStringToFile(configModelXml, Application.StartupPath + "\\Config\\" + SettingPrefix + "\\Config.xml", FileMode.Create);
- //MessageBox.Show(PdnResources.GetString("Menu.emresetsuccessfulthesoftw.text"));
- }
- catch (Exception)
- {
- MessageBox.Show(PdnResources.GetString("Menu.Systemresetfailure.text"));
- }
- }
- }
- public void InitCameraManager()
- {
- CameraManager.GetInstance();
- CameraManager.OnCaptureTimeOut += () =>
- {
- /*MessageBox.Show("相机采集超时");*/
- };
- }
- /// <summary>
- /// 初始化平台运动控制器
- /// </summary>
- public void InitStageController()
- {
- var m_Stage = AxisController.GetInstance(loadingStageModel.BaseSetType);
- if (SerialPort.GetPortNames().Length > 0 || AxisController.ControllerType.Equals("HDS"))
- {
- m_Stage.LoadingStageModel = instance.loadingStageModel;
- m_Stage.Open();
- }
- }
- }
- }
|