PMOptimize.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. for (var i = 0; i < this.pms.length; i++) {
  53. var pmFile = new QRadioButton(this.pms[i], pmWidget);
  54. pmFile.setGeometry(50, 25 + 40 * i, 1200, 40);
  55. this.btngrp.addButton(pmFile, i);
  56. pmFile.clicked.connect(this, this.pmClicked);
  57. }
  58. if (!this.selectLineDialog.exec()) {
  59. EAction.handleUserMessage("clicked~");
  60. destr(this.selectLineDialog);
  61. EAction.activateMainWindow();
  62. return undefined;
  63. }
  64. } catch (error) {
  65. EAction.handleUserMessage("PMOptimize.js, ERROR: " + error.toString());
  66. }
  67. };
  68. PMOptimize.prototype.opBtnClicked = function () {
  69. // 点击后的事件
  70. // if(this.pmsel){
  71. // var pmd = new PM();
  72. // pmd.interface(this.pms[this.pmid]);
  73. // }
  74. try {
  75. var pjPath = RSettings.getStringValue("OpenProject/Current", "");
  76. var array = new Array();
  77. array.push(pjPath + "/Output_data/平面参数-NDVI最优解.csv");
  78. array.push(pjPath + "/Output_data/平面参数-平衡解.csv");
  79. array.push(pjPath + "/Output_data/平面参数-造价最优解.csv");
  80. for (var i = 0; i < array.length; i++) {
  81. // CSV -> PM
  82. var convert = new CsvToPmConvert(array[i]);
  83. convert.convert();
  84. // 绘制PM
  85. var filePM = new DrawPM(convert.getPmFileName(), this.ratio, 0);
  86. filePM.applyDrawing();
  87. }
  88. // 关闭弹框
  89. this.exitBtnClicked();
  90. } catch (error) {
  91. EAction.handleUserMessage("PMOptimize.js, ERROR: " + error.toString());
  92. }
  93. };
  94. PMOptimize.prototype.exitBtnClicked = function () {
  95. if (this.selectLineDialog) {
  96. destr(this.selectLineDialog);
  97. }
  98. };
  99. PMOptimize.prototype.pmClicked = function () {
  100. this.pmsel = true;
  101. this.pmid = this.btngrp.checkedId();
  102. EAction.handleUserMessage(this.pms[this.pmid]);
  103. };