PMOptimize.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/DrawPM.js")
  24. function PMOptimize(guiAction) {
  25. EAction.call(this, guiAction);
  26. this.pmsel = false;
  27. this.selectLineDialog = undefined;
  28. }
  29. PMOptimize.prototype = new EAction();
  30. PMOptimize.includeBasePath = includeBasePath;
  31. PMOptimize.prototype.beginEvent = function () {
  32. EAction.prototype.beginEvent.call(this);
  33. try {
  34. var appWin = EAction.getMainWindow();
  35. this.selectLineDialog = this.createWidget(PMOptimize.includeBasePath + "/SelectLineDialog.ui", appWin);
  36. var pmWidget = this.selectLineDialog.findChild("pmWidget");
  37. var opBtn = this.selectLineDialog.findChild("opBtn");
  38. var exitBtn = this.selectLineDialog.findChild("exitBtn");
  39. opBtn.clicked.connect(this, this.opBtnClicked);
  40. exitBtn.clicked.connect(this, this.exitBtnClicked);
  41. this.btngrp = new QButtonGroup(pmWidget);
  42. var allPMFile = RSettings.getStringValue("OpenDisplayFile/PMFile", "");
  43. EAction.handleUserMessage("allPMFile: " + allPMFile.toString());
  44. var pmList = allPMFile.split(',');
  45. this.pms = new Array();
  46. for (var i = 0; i < pmList.length; i++) {
  47. if (pmList[i] == "" || this.pms.indexOf(pmList[i]) !== -1) {
  48. continue;
  49. }
  50. this.pms.push(pmList[i]);
  51. }
  52. if (this.pms.length == 0) {
  53. opBtn.setEnabled(false);
  54. }
  55. for (var i = 0; i < this.pms.length; i++) {
  56. var pmFile = new QRadioButton(this.pms[i], pmWidget);
  57. pmFile.setGeometry(50, 25 + 40 * i, 1200, 40);
  58. this.btngrp.addButton(pmFile, i);
  59. pmFile.clicked.connect(this, this.pmClicked);
  60. }
  61. if (!this.selectLineDialog.exec()) {
  62. EAction.handleUserMessage("clicked~");
  63. destr(this.selectLineDialog);
  64. EAction.activateMainWindow();
  65. return undefined;
  66. }
  67. } catch (error) {
  68. EAction.handleUserMessage("PMOptimize.js, ERROR: " + error.toString());
  69. }
  70. };
  71. PMOptimize.prototype.opBtnClicked = function () {
  72. if (!this.pmsel) {
  73. var appWin = EAction.getMainWindow();
  74. QMessageBox.information(appWin, qsTr("提示"), qsTr("请选择优化的的文件"));
  75. return;
  76. }
  77. // 点击后的事件
  78. // if(this.pmsel){
  79. // var pmd = new PM();
  80. // pmd.interface(this.pms[this.pmid]);
  81. // }
  82. try {
  83. var pjPath = RSettings.getStringValue("OpenProject/Current", "");
  84. var array = new Array();
  85. array.push(pjPath + "/Output_data/平面参数-NDVI最优解.csv");
  86. array.push(pjPath + "/Output_data/平面参数-平衡解.csv");
  87. array.push(pjPath + "/Output_data/平面参数-造价最优解.csv");
  88. for (var i = 0; i < array.length; i++) {
  89. // CSV -> PM
  90. var convert = new CsvToPmConvert(array[i]);
  91. convert.convert();
  92. // 绘制PM
  93. var filePM = new DrawPM(convert.getPmFileName(), this.ratio, 0);
  94. filePM.applyDrawing();
  95. }
  96. // 关闭弹框
  97. this.exitBtnClicked();
  98. } catch (error) {
  99. EAction.handleUserMessage("PMOptimize.js, ERROR: " + error.toString());
  100. }
  101. };
  102. PMOptimize.prototype.exitBtnClicked = function () {
  103. if (this.selectLineDialog) {
  104. destr(this.selectLineDialog);
  105. }
  106. };
  107. PMOptimize.prototype.pmClicked = function () {
  108. this.pmsel = true;
  109. this.pmid = this.btngrp.checkedId();
  110. EAction.handleUserMessage(this.pms[this.pmid]);
  111. };