Vector.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //CLASS:矢量图形类
  2. function Vector(geometry, style, attributes) {
  3. this.id = CanvasSketch.getId("vector");
  4. this.geometry = geometry;
  5. this.symbol2Ds = {};
  6. this.symbol2dsCount = 0;
  7. this.style = style;
  8. /*
  9. 墙有这种属性,主要是墙上面的symbol
  10. children
  11. 主要是针对symbol,其所在墙的id
  12. wallId=null;
  13. 与墙重合的宽度
  14. width;
  15. //所在墙的端点的位置,如果是墙角,则wallendindex没有值
  16. wallstartindex;
  17. wallendindex;
  18. //门或窗的端点坐标
  19. point1;
  20. point2;
  21. //朝向
  22. //如果为1,表示当前点对应的直线中的b要大于symbol对应的b
  23. //如果为-1,表示小于
  24. //如果当前symbol对应的线是平行于x轴,则1表示对应的y大于symbol对应的y,-1表示小于
  25. //如果当前symbol对应的线是平行于y轴,则1表示对应的x大于symbol对应的x,-1表示小于
  26. toward=1;
  27. vectorMeasureid=null;
  28. select=false;
  29. calculatePoints=false;
  30. exist=false;
  31. selectSymbolIds=[];
  32. */
  33. if (attributes) {
  34. this.attributes = attributes;
  35. } else {
  36. this.attributes = {};
  37. }
  38. };
  39. Vector.prototype.setwallInfo = function (wallid, startindex, endindex) {
  40. this.attributes.wallId = wallid;
  41. this.attributes.wallstartindex = startindex;
  42. this.attributes.wallendindex = endindex;
  43. };
  44. Vector.prototype.update = function (layer, wallid, startindex, endindex, point) {
  45. //向symbol设置墙的信息
  46. this.setwallInfo(wallid, startindex, endindex);
  47. //更新其他点
  48. var thick = layer.getThickness(wallid, startindex);
  49. this.geometry.wallType = layer.vectors[this.attributes.wallId].geometry.wallType;
  50. if (point != null) {
  51. this.attributes.toward = layer.calculateLine.getToward(this.geometry.point1, this.geometry.point2, point);
  52. }
  53. this.geometry.points = layer.calculateElement.getSymbolPoints(this.geometry.point1, this.geometry.point2, this.geometry.geoType, this.attributes.toward, thick);
  54. if (!this.attributes.draw) {
  55. layer.drawSingleVector(this);
  56. layer.vectors[this.id] = this;
  57. this.attributes.draw = true;
  58. }
  59. };
  60. Vector.prototype.getSymbolLen = function () {
  61. /*
  62. if(this.geometry.geoType=="Symbol2D_OpeningWindow")
  63. {
  64. return layer.parameter.windowLength[0];
  65. }
  66. else if(this.geometry.geoType=="Symbol2D_OpeningDoor")
  67. {
  68. return layer.parameter.doorLength[0];
  69. }
  70. else if(this.geometry.geoType=="Symbol2D_SimpleDoor")
  71. {
  72. return layer.parameter.doorLength[1];
  73. }
  74. else if(this.geometry.geoType=="Symbol2D_SingleCasement")
  75. {
  76. return layer.parameter.windowLength[1];
  77. }
  78. else if(this.geometry.geoType=="Symbol2D_SlidingDoor")
  79. {
  80. return layer.parameter.doorLength[2];
  81. }
  82. else if(this.geometry.geoType=="Symbol2D_SlidingWindow")
  83. {
  84. return layer.parameter.windowLength[2];
  85. }
  86. */
  87. if (this.geometry.points != null && this.geometry.points.length > 0) {
  88. //return BABYLON.Vector2.Distance(this.points[0],this.points[1]);
  89. return BABYLON.Vector2.Distance(this.geometry.point1, this.geometry.point2);
  90. } else if (this.geometry.geoType == "OpenDoor") {
  91. return 80;
  92. } else if (this.geometry.geoType == "OpenWindow") {
  93. return 60;
  94. } else if (this.geometry.geoType == "SimpleDoor") {
  95. return 80;
  96. } else if (this.geometry.geoType == "SingleCasement") {
  97. return 60;
  98. } else if (this.geometry.geoType == "BiFoldDoor") {
  99. return 120;
  100. } else if (this.geometry.geoType == "DoubleCasement") {
  101. return 100;
  102. } else if (this.geometry.geoType == "SlidingDoor") {
  103. return 120;
  104. } else if (this.geometry.geoType == "SlidingWindow") {
  105. return 100;
  106. }
  107. };