终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
2 роки тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. using BeDesignerSCADA.Common;
  2. using BeDesignerSCADA.View;
  3. using BeDesignerSCADA.ViewModel;
  4. using BPASmart.Model;
  5. using BPASmartClient.Compiler;
  6. using BPASmartClient.DATABUS;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Reflection;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Controls.Primitives;
  18. using System.Windows.Data;
  19. using System.Windows.Documents;
  20. using System.Windows.Forms;
  21. using System.Windows.Input;
  22. using System.Windows.Markup;
  23. using System.Windows.Media;
  24. using System.Windows.Media.Animation;
  25. using System.Windows.Media.Imaging;
  26. using System.Windows.Navigation;
  27. using System.Windows.Shapes;
  28. namespace BeDesignerSCADA.Controls
  29. {
  30. /// <summary>
  31. /// MainCanvasPanel.xaml 的交互逻辑
  32. /// </summary>
  33. public partial class MainCanvasPanel : System.Windows.Controls.UserControl
  34. {
  35. /// <summary>
  36. /// 布局文件路径
  37. /// </summary>
  38. public string Path = string.Empty;
  39. List<Type> controls = new List<Type>();
  40. MainViewModelNew viewModel = new MainViewModelNew();
  41. public MainCanvasPanel(string _Path)
  42. {
  43. InitializeComponent();
  44. EditorHelper.Register<BindingExpression, BindingConvertor>();
  45. Path = _Path;
  46. viewModel.LayoutsPath=Path;
  47. this.DataContext = viewModel;
  48. viewModel.Loaded(cav, runCanvas);
  49. //控件加载
  50. Assembly assembly = Assembly.LoadFile($"{System.AppDomain.CurrentDomain.BaseDirectory}\\BPASmartClient.SCADAControl.dll"); //Assembly.GetExecutingAssembly();
  51. controls = assembly.GetTypes().Where(t => t.GetInterface("IExecutable") != null).OrderBy(o => o.Name)?.ToList();
  52. //controls.Add(new Line().GetType());
  53. CtlList.ItemsSource = controls;
  54. //读取文件
  55. FileRead(_Path);
  56. }
  57. #region 位置调整
  58. /// <summary>
  59. /// 左对齐
  60. /// </summary>
  61. /// <param name="sender"></param>
  62. /// <param name="e"></param>
  63. private void AglinLeftBtn_Click(object sender, RoutedEventArgs e)
  64. {
  65. cav.AlignLeft();
  66. }
  67. /// <summary>
  68. /// 底部对齐
  69. /// </summary>
  70. /// <param name="sender"></param>
  71. /// <param name="e"></param>
  72. private void AglinBottomBtn_Click(object sender, RoutedEventArgs e)
  73. {
  74. cav.AlignBottom();
  75. }
  76. /// <summary>
  77. /// 顶部对齐
  78. /// </summary>
  79. /// <param name="sender"></param>
  80. /// <param name="e"></param>
  81. private void AglinTopBtn_Click(object sender, RoutedEventArgs e)
  82. {
  83. cav.AlignTop();
  84. }
  85. /// <summary>
  86. /// 右对齐
  87. /// </summary>
  88. /// <param name="sender"></param>
  89. /// <param name="e"></param>
  90. private void AglinRightBtn_Click(object sender, RoutedEventArgs e)
  91. {
  92. cav.AlignRight();
  93. }
  94. /// <summary>
  95. /// 居中
  96. /// </summary>
  97. /// <param name="sender"></param>
  98. /// <param name="e"></param>
  99. private void AglinCenterBtn_Click(object sender, RoutedEventArgs e)
  100. {
  101. cav.AlignCenter();
  102. }
  103. /// <summary>
  104. /// 垂直分布
  105. /// </summary>
  106. /// <param name="sender"></param>
  107. /// <param name="e"></param>
  108. private void VerticalLayoutBtn_Click(object sender, RoutedEventArgs e)
  109. {
  110. cav.VertialLayout();
  111. }
  112. /// <summary>
  113. /// 水平分布
  114. /// </summary>
  115. /// <param name="sender"></param>
  116. /// <param name="e"></param>
  117. private void HorizontalLayoutBtn_Click(object sender, RoutedEventArgs e)
  118. {
  119. cav.HorizontalLayout();
  120. }
  121. #endregion
  122. #region 其他事件操作
  123. /// <summary>
  124. /// 传入变量管理器地址
  125. /// </summary>
  126. /// <param name="path"></param>
  127. private void LoadBtnValue_Click(object sender, RoutedEventArgs e)
  128. {
  129. OpenFileDialog ofd = new OpenFileDialog();
  130. ofd.Filter = "变量管理器文件|*.json";
  131. if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  132. {
  133. viewModel.VariablePath = ofd.FileName;
  134. bool isSucess= DataBusModel.GetInstance().RefreshVariableManager(ofd.FileName);
  135. System.Windows.MessageBox.Show(isSucess ? "加载成功!" : "加载失败!");
  136. }
  137. }
  138. /// <summary>
  139. /// 运行
  140. /// </summary>
  141. /// <param name="sender"></param>
  142. /// <param name="e"></param>
  143. private void RunBtn_Click(object sender, RoutedEventArgs e)
  144. {
  145. if (sender is System.Windows.Controls.Button btn)
  146. {
  147. if (btn.Tag.ToString() == "运行")
  148. {
  149. cav.ClearSelection();
  150. runCanvas.Run(cav.Generator());
  151. }
  152. else if (btn.Tag.ToString() == "停止")
  153. {
  154. runCanvas.Destory();
  155. }
  156. }
  157. }
  158. /// <summary>
  159. /// 模拟运行
  160. /// </summary>
  161. /// <param name="sender"></param>
  162. /// <param name="e"></param>
  163. private void MNRunBtn_Click(object sender, RoutedEventArgs e)
  164. {
  165. cav.ClearSelection();
  166. RunWindowsLao runWindows = new RunWindowsLao();
  167. runWindows.LoadingData(cav.Generator());
  168. runWindows.Show();
  169. }
  170. /// <summary>
  171. /// 加载
  172. /// </summary>
  173. /// <param name="sender"></param>
  174. /// <param name="e"></param>
  175. private void LoadBtn_Click(object sender, RoutedEventArgs e)
  176. {
  177. OpenFileDialog ofd = new OpenFileDialog();
  178. ofd.Filter = "布局文件|*.lay";
  179. if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  180. {
  181. cav.Load(ofd.FileName);
  182. }
  183. DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250)));
  184. da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
  185. CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da);
  186. DoubleAnimation daop = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(250)));
  187. daop.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
  188. cav.BeginAnimation(OpacityProperty, daop);
  189. }
  190. /// <summary>
  191. /// 读取文件
  192. /// </summary>
  193. /// <param name="path"></param>
  194. public void FileRead(string path)
  195. {
  196. try
  197. {
  198. if (File.Exists(path))
  199. {
  200. cav.Load(path);
  201. DoubleAnimation da = new DoubleAnimation(-200, 0, new Duration(TimeSpan.FromMilliseconds(250)));
  202. da.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
  203. CanvasTranslate.BeginAnimation(TranslateTransform.XProperty, da);
  204. DoubleAnimation daop = new DoubleAnimation(0, 1, new Duration(TimeSpan.FromMilliseconds(250)));
  205. daop.EasingFunction = new CubicEase() { EasingMode = EasingMode.EaseOut };
  206. cav.BeginAnimation(OpacityProperty, daop);
  207. }
  208. }
  209. catch (Exception ex)
  210. {
  211. }
  212. }
  213. /// <summary>
  214. /// 根据流加载数据
  215. /// </summary>
  216. public void LoadFrameworkElement(UIElementCollection frameworks)
  217. {
  218. try
  219. {
  220. cav.Children.Clear();
  221. foreach (FrameworkElement element in frameworks)
  222. {
  223. string xamlText = XamlWriter.Save(element);
  224. FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement;
  225. cav.Children.Add(item);
  226. }
  227. cav.SelectedItems?.Clear();
  228. }
  229. catch (Exception ex)
  230. {
  231. throw;
  232. }
  233. }
  234. /// <summary>
  235. /// 获取所有控件
  236. /// </summary>
  237. /// <returns></returns>
  238. public List<FrameworkElement> GetChildren()
  239. {
  240. List<FrameworkElement> frameworks = new List<FrameworkElement>();
  241. foreach (FrameworkElement child in cav.Children)
  242. {
  243. string xamlText = XamlWriter.Save(child);
  244. FrameworkElement item = XamlReader.Parse(xamlText) as FrameworkElement;
  245. frameworks.Add(item);
  246. }
  247. return frameworks;
  248. }
  249. /// <summary>
  250. /// 保存文件
  251. /// </summary>
  252. public void FileSave()
  253. {
  254. SaveBtn_Click(null, null);
  255. }
  256. /// <summary>
  257. /// 传入变量管理器地址
  258. /// </summary>
  259. /// <param name="path"></param>
  260. public void VariableManagerPath(string path)
  261. {
  262. try
  263. {
  264. viewModel.VariablePath = path;
  265. }
  266. catch (Exception ex)
  267. {
  268. }
  269. }
  270. /// <summary>
  271. /// 运行程序
  272. /// </summary>
  273. public void Run()
  274. {
  275. try
  276. {
  277. cav.ClearSelection();
  278. runCanvas.Run(cav.Generator());
  279. }
  280. catch (Exception ex)
  281. {
  282. }
  283. }
  284. /// <summary>
  285. /// 停止运行程序
  286. /// </summary>
  287. public void Destory()
  288. {
  289. try
  290. {
  291. runCanvas.Destory();
  292. }
  293. catch (Exception ex)
  294. {
  295. throw;
  296. }
  297. }
  298. /// <summary>
  299. /// 保存
  300. /// </summary>
  301. /// <param name="sender"></param>
  302. /// <param name="e"></param>
  303. private void SaveBtn_Click(object sender, RoutedEventArgs e)
  304. {
  305. if (File.Exists(Path))
  306. {
  307. string str = cav.Save();
  308. File.WriteAllText(Path, str, Encoding.Unicode);
  309. }
  310. else
  311. {
  312. SaveFileDialog sfd = new SaveFileDialog();
  313. sfd.Filter = "布局文件|*.lay";
  314. if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  315. {
  316. string str = cav.Save();
  317. File.WriteAllText(sfd.FileName, str, Encoding.Unicode);
  318. }
  319. }
  320. }
  321. /// <summary>
  322. /// 模拟消息发送
  323. /// </summary>
  324. /// <param name="sender"></param>
  325. /// <param name="e"></param>
  326. private void MNBtn_Click(object sender, RoutedEventArgs e)
  327. {
  328. }
  329. #endregion
  330. #region 左侧控件栏移动
  331. /// <summary>
  332. /// 移动到右侧
  333. /// </summary>
  334. /// <param name="sender"></param>
  335. /// <param name="e"></param>
  336. private void CtlList_PreviewMouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  337. {
  338. if (CtlList.SelectedItem != null && e.LeftButton == MouseButtonState.Pressed)
  339. {
  340. DragDrop.DoDragDrop(CtlList, CtlList.SelectedItem, System.Windows.DragDropEffects.Copy);
  341. codeEditor.Text = cav.Save();
  342. }
  343. }
  344. /// <summary>
  345. /// 显示代码
  346. /// </summary>
  347. /// <param name="sender"></param>
  348. /// <param name="e"></param>
  349. private void showCode_Click(object sender, RoutedEventArgs e)
  350. {
  351. codeEditor.Text = cav.Save();
  352. }
  353. /// <summary>
  354. /// 编辑
  355. /// </summary>
  356. /// <param name="sender"></param>
  357. /// <param name="e"></param>
  358. private void ToggleButton_Click(object sender, RoutedEventArgs e)
  359. {
  360. try
  361. {
  362. if (sender is ToggleButton)
  363. {
  364. ToggleButton toggle = (ToggleButton)sender;
  365. Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
  366. if (propertyGridCommand != null)
  367. {
  368. viewModel.Edit(propertyGridCommand);
  369. }
  370. }
  371. }
  372. catch (Exception ex)
  373. {
  374. }
  375. }
  376. /// <summary>
  377. /// 路径资源选择
  378. /// </summary>
  379. /// <param name="sender"></param>
  380. /// <param name="e"></param>
  381. private void LJToggleButton_Click(object sender, RoutedEventArgs e)
  382. {
  383. try
  384. {
  385. if (sender is ToggleButton)
  386. {
  387. ToggleButton toggle = (ToggleButton)sender;
  388. Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
  389. if (propertyGridCommand != null)
  390. {
  391. viewModel.SelectPath(propertyGridCommand);
  392. }
  393. }
  394. }
  395. catch (Exception ex)
  396. {
  397. }
  398. }
  399. /// <summary>
  400. /// 选择进程
  401. /// </summary>
  402. /// <param name="sender"></param>
  403. /// <param name="e"></param>
  404. private void XZToggleButton_Click(object sender, RoutedEventArgs e)
  405. {
  406. try
  407. {
  408. if (sender is ToggleButton)
  409. {
  410. ToggleButton toggle = (ToggleButton)sender;
  411. Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
  412. if (propertyGridCommand != null)
  413. {
  414. viewModel.SelectValuePath(propertyGridCommand);
  415. }
  416. }
  417. }
  418. catch (Exception ex)
  419. {
  420. }
  421. }
  422. /// <summary>
  423. /// 设置子控件模板
  424. /// </summary>
  425. /// <param name="sender"></param>
  426. /// <param name="e"></param>
  427. private void ChildToggleButton_Click(object sender, RoutedEventArgs e)
  428. {
  429. try
  430. {
  431. if (sender is ToggleButton)
  432. {
  433. ToggleButton toggle = (ToggleButton)sender;
  434. Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
  435. if (propertyGridCommand != null)
  436. {
  437. viewModel.ChildEdit(propertyGridCommand);
  438. }
  439. }
  440. }
  441. catch (Exception ex)
  442. {
  443. }
  444. }
  445. /// <summary>
  446. /// 数据绑定
  447. /// </summary>
  448. /// <param name="sender"></param>
  449. /// <param name="e"></param>
  450. private void BingToggleButton_Click(object sender, RoutedEventArgs e)
  451. {
  452. try
  453. {
  454. if (sender is ToggleButton)
  455. {
  456. ToggleButton toggle = (ToggleButton)sender;
  457. Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
  458. if (propertyGridCommand != null)
  459. {
  460. viewModel.BingEdit(propertyGridCommand);
  461. }
  462. }
  463. }
  464. catch (Exception ex)
  465. {
  466. }
  467. }
  468. /// <summary>
  469. /// 清除绑定
  470. /// </summary>
  471. /// <param name="sender"></param>
  472. /// <param name="e"></param>
  473. private void ClearBingToggleButton_Click(object sender, RoutedEventArgs e)
  474. {
  475. try
  476. {
  477. if (sender is ToggleButton)
  478. {
  479. ToggleButton toggle = (ToggleButton)sender;
  480. Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem propertyGridCommand = toggle.DataContext as Xceed.Wpf.Toolkit.PropertyGrid.PropertyItem;
  481. if (propertyGridCommand != null)
  482. {
  483. viewModel.ClearBingEdit(propertyGridCommand);
  484. }
  485. }
  486. }
  487. catch (Exception ex)
  488. {
  489. }
  490. }
  491. #endregion
  492. }
  493. }