PMOptimize.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/EAction.js");
  20. include("scripts/simple.js");
  21. include("scripts/Layer/Layer.js");
  22. include("scripts/Common/CsvToPmConvert.js")
  23. include("scripts/Common/OptimizeConvert.js")
  24. include("scripts/Common/DrawPM.js")
  25. function PMOptimize(guiAction) {
  26. EAction.call(this, guiAction);
  27. this.pmsel = false;
  28. this.selectLineDialog = undefined;
  29. }
  30. PMOptimize.prototype = new EAction();
  31. PMOptimize.includeBasePath = includeBasePath;
  32. PMOptimize.prototype.beginEvent = function () {
  33. EAction.prototype.beginEvent.call(this);
  34. try {
  35. var appWin = EAction.getMainWindow();
  36. this.selectLineDialog = this.createWidget(PMOptimize.includeBasePath + "/SelectLineDialog.ui", appWin);
  37. var pmWidget = this.selectLineDialog.findChild("pmWidget");
  38. var opBtn = this.selectLineDialog.findChild("opBtn");
  39. var exitBtn = this.selectLineDialog.findChild("exitBtn");
  40. opBtn.clicked.connect(this, this.opBtnClicked);
  41. exitBtn.clicked.connect(this, this.exitBtnClicked);
  42. this.btngrp = new QButtonGroup(pmWidget);
  43. var allPMFile = RSettings.getStringValue("OpenDisplayFile/PMFile", "");
  44. EAction.handleUserMessage("allPMFile: " + allPMFile.toString());
  45. var pmList = allPMFile.split(',');
  46. this.pms = new Array();
  47. for (var i = 0; i < pmList.length; i++) {
  48. if (pmList[i] == "" || this.pms.indexOf(pmList[i]) !== -1) {
  49. continue;
  50. }
  51. this.pms.push(pmList[i]);
  52. }
  53. if (this.pms.length == 0) {
  54. opBtn.setEnabled(false);
  55. }
  56. for (var i = 0; i < this.pms.length; i++) {
  57. var pmFile = new QRadioButton(this.pms[i], pmWidget);
  58. pmFile.setGeometry(50, 25 + 40 * i, 1200, 40);
  59. this.btngrp.addButton(pmFile, i);
  60. pmFile.clicked.connect(this, this.pmClicked);
  61. }
  62. if (!this.selectLineDialog.exec()) {
  63. EAction.handleUserMessage("clicked~");
  64. destr(this.selectLineDialog);
  65. EAction.activateMainWindow();
  66. return undefined;
  67. }
  68. } catch (error) {
  69. EAction.handleUserMessage("PMOptimize.js, ERROR: " + error.toString());
  70. }
  71. };
  72. PMOptimize.prototype.opBtnClicked = function () {
  73. if (!this.pmsel) {
  74. var appWin = EAction.getMainWindow();
  75. QMessageBox.information(appWin, qsTr("提示"), qsTr("请选择优化的的文件"));
  76. return;
  77. }
  78. // 点击后的事件
  79. // if(this.pmsel){
  80. // var pmd = new PM();
  81. // pmd.interface(this.pms[this.pmid]);
  82. // }
  83. try {
  84. // 模拟优化过程
  85. var optimize = new OptimizeConvert("平面");
  86. optimize.exec();
  87. // 优化完毕,开始绘画PM
  88. var pjPath = RSettings.getStringValue("OpenProject/Current", "");
  89. var array = new Array();
  90. array.push(pjPath + "/Output_data/平面参数-NDVI最优解.csv");
  91. array.push(pjPath + "/Output_data/平面参数-平衡解.csv");
  92. array.push(pjPath + "/Output_data/平面参数-造价最优解.csv");
  93. for (var i = 0; i < array.length; i++) {
  94. // CSV -> PM
  95. var convert = new CsvToPmConvert(array[i]);
  96. convert.convert();
  97. // 绘制PM
  98. var filePM = new DrawPM(convert.getPmFileName(), this.ratio, i + 3);
  99. filePM.applyDrawing();
  100. }
  101. // 关闭弹框
  102. this.exitBtnClicked();
  103. } catch (error) {
  104. EAction.handleUserMessage("PMOptimize.js, ERROR: " + error.toString());
  105. }
  106. };
  107. PMOptimize.prototype.exitBtnClicked = function () {
  108. if (this.selectLineDialog) {
  109. destr(this.selectLineDialog);
  110. }
  111. };
  112. PMOptimize.prototype.pmClicked = function () {
  113. this.pmsel = true;
  114. this.pmid = this.btngrp.checkedId();
  115. EAction.handleUserMessage(this.pms[this.pmid]);
  116. };