断路器通用图元.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. ht.lib = ht.lib || {};
  2. if (!ht.lib['断路器通用图元']) {
  3. ht.lib['断路器通用图元'] = function (x, y, width, height, angle, localVarObj, localDynamicVar, nodename) {
  4. _ratio = GD.getRatioWithRotation(0, ratio);
  5. ht.lib['断路器通用图元'].superClass.constructor.apply(this);
  6. this.localVarObj = localVarObj;
  7. this.localDynamicVar = localDynamicVar;
  8. this.childNodes = [];
  9. this._styleObject = {};
  10. this._originWidth = 15*_ratio.ratioX;
  11. this._originHeight = 21*_ratio.ratioY;
  12. this._baseClass = "ht.lib.断路器通用图元";
  13. this._background = new ht.Node();
  14. this._background.setWidth(this._originWidth);
  15. this._background.setHeight(this._originHeight);
  16. this._background.setPosition(this._originWidth/2, this._originHeight/2);
  17. this._background.setImage({
  18. width: width,
  19. height: height,
  20. clip: true,
  21. comps: [
  22. {
  23. type: 'rect',
  24. background: 'rgba(0,255,0,0)',
  25. rect: [0,0,width, height]
  26. }
  27. ]
  28. });
  29. this._background.__parentLib = nodename;
  30. this._background.isLibBackground = true;
  31. this.childNodes.push(this._background);
  32. dataModel.add(this._background);
  33. /*@PageBackgroundInit@*/
  34. /*@PageBeforeInit@*/
  35. var Lib_断路器通用图元Node0;
  36. (function () {
  37. var _ratio = GD.getRatioWithRotation(0*Math.PI/180, ratio);
  38. var ratioX, ratioY;
  39. if ('Default' === 'False') {
  40. ratioX = 1;
  41. ratioY = 1;
  42. } else if ('Default' === 'X') {
  43. ratioX = ratioY = _ratio.ratioX;
  44. } else if ('Default' === 'Y') {
  45. ratioX = ratioY = _ratio.ratioY;
  46. } else {
  47. ratioX = _ratio.ratioX;
  48. ratioY = _ratio.ratioY;
  49. }
  50. ht.Default.setImage('imgimage//d030.png', PAGEROOTDIR + 'image//d030.png');
  51. Lib_断路器通用图元Node0 = new ht.Node();
  52. Lib_断路器通用图元Node0.setPosition(7*ratio.ratioX, 10*ratio.ratioY);
  53. Lib_断路器通用图元Node0.setSize(14*ratioX, 20*ratioY);
  54. Lib_断路器通用图元Node0.setImage('imgimage//d030.png');
  55. Lib_断路器通用图元Node0.setRotation(0*Math.PI/180);
  56. Lib_断路器通用图元Node0._zoomBy = 'Default';
  57. Lib_断路器通用图元Node0._nodeType = 'image';
  58. Lib_断路器通用图元Node0._disallowEvert = true;
  59. dataModel.add(Lib_断路器通用图元Node0);
  60. })();
  61. var Lib_断路器通用图元Node1;
  62. (function () {
  63. var _ratio = GD.getRatioWithRotation(0*Math.PI/180, ratio);
  64. var ratioX, ratioY;
  65. if ('Default' === 'False') {
  66. ratioX = 1;
  67. ratioY = 1;
  68. } else if ('Default' === 'X') {
  69. ratioX = ratioY = _ratio.ratioX;
  70. } else if ('Default' === 'Y') {
  71. ratioX = ratioY = _ratio.ratioY;
  72. } else {
  73. ratioX = _ratio.ratioX;
  74. ratioY = _ratio.ratioY;
  75. }
  76. ht.Default.setImage('imgimage//d040.png', PAGEROOTDIR + 'image//d040.png');
  77. Lib_断路器通用图元Node1 = new ht.Node();
  78. Lib_断路器通用图元Node1.setPosition(7*ratio.ratioX, 10*ratio.ratioY);
  79. Lib_断路器通用图元Node1.setSize(14*ratioX, 20*ratioY);
  80. Lib_断路器通用图元Node1.setImage('imgimage//d040.png');
  81. Lib_断路器通用图元Node1.setRotation(0*Math.PI/180);
  82. Lib_断路器通用图元Node1._zoomBy = 'Default';
  83. Lib_断路器通用图元Node1._nodeType = 'image';
  84. Lib_断路器通用图元Node1._disallowEvert = true;
  85. dataModel.add(Lib_断路器通用图元Node1);
  86. })();
  87. /*@GraphList@*/
  88. /*@PageInit@*/
  89. var localVarObj = this.localVarObj;
  90. var localDynamicVarObj = this.localDynamicVar();
  91. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  92. this['Lib_断路器通用图元Node0'] = Lib_断路器通用图元Node0;
  93. Lib_断路器通用图元Node0.__parentLib = nodename;
  94. Lib_断路器通用图元Node0.__parent = this;
  95. this.childNodes.push(Lib_断路器通用图元Node0);
  96. this['Lib_断路器通用图元Node1'] = Lib_断路器通用图元Node1;
  97. Lib_断路器通用图元Node1.__parentLib = nodename;
  98. Lib_断路器通用图元Node1.__parent = this;
  99. this.childNodes.push(Lib_断路器通用图元Node1);
  100. /*@ControlContextMenu@*/
  101. /*@Declare@*/
  102. this.init(x, y, width, height, angle);
  103. };
  104. ht.Default.def('ht.lib.断路器通用图元', Object, {
  105. refresh10ms: function () {
  106. var localVarObj = this.localVarObj;
  107. var localDynamicVarObj = this.localDynamicVar();
  108. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  109. var Lib_断路器通用图元Node0= this.Lib_断路器通用图元Node0;
  110. var Lib_断路器通用图元Node1= this.Lib_断路器通用图元Node1;
  111. /*@refresh10ms@*/
  112. },
  113. refresh100ms: function () {
  114. var localVarObj = this.localVarObj;
  115. var localDynamicVarObj = this.localDynamicVar();
  116. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  117. var Lib_断路器通用图元Node0= this.Lib_断路器通用图元Node0;
  118. var Lib_断路器通用图元Node1= this.Lib_断路器通用图元Node1;
  119. /*@refresh100ms@*/
  120. },
  121. refresh500ms: function () {
  122. var localVarObj = this.localVarObj;
  123. var localDynamicVarObj = this.localDynamicVar();
  124. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  125. var Lib_断路器通用图元Node0= this.Lib_断路器通用图元Node0;
  126. var Lib_断路器通用图元Node1= this.Lib_断路器通用图元Node1;
  127. if((1 )>0) {if(((getVarValue(xianshi1)==1)>0 )){Lib_断路器通用图元Node0.s('2d.visible',true&&this.getStyle('2d.visible'));}else{Lib_断路器通用图元Node0.s('2d.visible',false&&this.getStyle('2d.visible'));}}
  128. if((1 )>0) {if(((getVarValue(xianshi1)==0)>0 )){Lib_断路器通用图元Node1.s('2d.visible',true&&this.getStyle('2d.visible'));}else{Lib_断路器通用图元Node1.s('2d.visible',false&&this.getStyle('2d.visible'));}}
  129. /*@refresh500ms@*/
  130. },
  131. refresh1s: function () {
  132. var Counter1s = arguments[0] || 0;
  133. var localVarObj = this.localVarObj;
  134. var localDynamicVarObj = this.localDynamicVar();
  135. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  136. var Lib_断路器通用图元Node0= this.Lib_断路器通用图元Node0;
  137. var Lib_断路器通用图元Node1= this.Lib_断路器通用图元Node1;
  138. /*@refresh1s@*/
  139. },
  140. refresh5s: function () {
  141. var localVarObj = this.localVarObj;
  142. var localDynamicVarObj = this.localDynamicVar();
  143. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  144. var Lib_断路器通用图元Node0= this.Lib_断路器通用图元Node0;
  145. var Lib_断路器通用图元Node1= this.Lib_断路器通用图元Node1;
  146. /*@refresh5s@*/
  147. },
  148. /*@PageDynamic@*/
  149. onEvent: function (e, data, type, origin, offset, objMouseOn, ctm) {
  150. var localVarObj = this.localVarObj;
  151. var localDynamicVarObj = this.localDynamicVar();
  152. var xianshi1= localVarObj.xianshi1 || localDynamicVarObj.xianshi1;
  153. var Lib_断路器通用图元Node0= this.Lib_断路器通用图元Node0;
  154. var Lib_断路器通用图元Node1= this.Lib_断路器通用图元Node1;
  155. if (type === 'click') {
  156. /*@EvnentClicked@*/
  157. } else if (type === 'mousedown') {
  158. mouseX=e.clientX;
  159. mouseY=e.clientY;
  160. /*@EvnentMouseDown@*/
  161. } else if (type === 'mouseup') {
  162. /*@EvnentMouseUp@*/
  163. } else if (type === 'mousemove') {
  164. var mouseX, mouseY, position, zoom;
  165. position=origin.getLogicalPoint(e);
  166. zoom = graphView.getZoom();
  167. if (origin === graphView) {
  168. mouseX= position.x + origin.tx();
  169. mouseY = position.y + origin.ty();
  170. } else {
  171. offset = offset || {x: 0, y: 0};
  172. mouseX = position.x / zoom + offset.x + origin.tx();
  173. mouseY = position.y / zoom + offset.y + origin.ty();
  174. }
  175. /*@EvnentMouseLeave@*/
  176. /*@EvnentMouseOver@*/
  177. } else if (type === 'keydown') {
  178. /*@EvnentKeyDown@*/
  179. } else if (type === 'contextmenu') {
  180. /*@Declare@*/
  181. /*@SetNodeContextMenu@*/
  182. /*@SetPageContextMenu@*/
  183. }
  184. /*@LibEvent@*/
  185. },
  186. getBaseClass: function () {
  187. return this._baseClass;
  188. },
  189. getWidth: function () {
  190. return this._width;
  191. },
  192. getHeight: function () {
  193. return this._height;
  194. },
  195. getSize: function () {
  196. return {
  197. width: this._width,
  198. height: this._height
  199. }
  200. },
  201. setWidth: function (width) {
  202. if (width === undefined || width === null || width != width) {
  203. return ;
  204. }
  205. var originWidth = this._width;
  206. var ratio = width / originWidth;
  207. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), w, cw, ox, rotation = this.getRotation();
  208. for (var i = 0, len = childNodes.length; i < len; i++) {
  209. childNode = childNodes[i];
  210. p = childNode.getPosition();
  211. cw = childNode.getWidth();
  212. w = cw >=2 ? cw * ratio : cw;
  213. childNode.setWidth(w);
  214. ox = op.x + (p.x - op.x) * ratio;
  215. childNode.setPosition(ox, p.y);
  216. rotation = GD.calcRotation(rotation);
  217. if (rotation === 0 || rotation === Math.PI) {
  218. // 图元未旋转
  219. ox = op.x + (p.x - op.x)*ratio;
  220. childNode.setPosition(ox, p.y);
  221. } else if (rotation === 90 * Math.PI / 180) {
  222. // 图元旋转以后
  223. ox = op.y + (p.y - op.y)*ratio;
  224. childNode.setPosition(p.x, ox);
  225. }
  226. }
  227. this._width = width;
  228. this._originWidth = width;
  229. this._ratioX = ratio;
  230. return this;
  231. },
  232. setHeight: function (height) {
  233. if (height === undefined || height === null || height != height) {
  234. return ;
  235. }
  236. var originHeight = this._height;
  237. var ratio = height / originHeight;
  238. var childNodes = this.childNodes, childNode, p, op = this.getPosition(), h, ch, oy, rotation = this.getRotation();
  239. for (var i = 0, len = childNodes.length; i < len; i++) {
  240. childNode = childNodes[i];
  241. p = childNode.getPosition();
  242. ch = childNode.getHeight();
  243. h = ch >=2 ? ch * ratio : ch;
  244. childNode.setHeight(h);
  245. rotation = GD.calcRotation(rotation);
  246. if (rotation === 0 || rotation === Math.PI) {
  247. // 图元未旋转
  248. oy = op.y + (p.y - op.y)*ratio;
  249. childNode.setPosition(p.x, oy);
  250. } else if (rotation === 90 * Math.PI / 180) {
  251. // 图元旋转以后
  252. oy = op.x + (p.x - op.x)*ratio;
  253. childNode.setPosition(oy, p.y);
  254. }
  255. }
  256. this._height = height;
  257. this._originHeight = height;
  258. this._ratioY = ratio;
  259. return this;
  260. },
  261. setSize: function (size) {
  262. // var args = Array.prototype.slice.call(arguments, 0);
  263. // var height, width;
  264. // if (args.length === 0) {
  265. // return ;
  266. // }else if (args.length === 1) {
  267. // height = args[0].height;
  268. // width = args[0].width;
  269. // } else {
  270. // width = args[0];
  271. // height = args[1];
  272. // }
  273. // var wh = GD.getRatioWithRotation(angle, wid)
  274. // this.setHeight(height);
  275. // this.setWidth(width);
  276. // return this;
  277. var args = Array.prototype.slice.call(arguments, 0);
  278. var height, width;
  279. if (args.length === 0) {
  280. return ;
  281. }else if (args.length === 1) {
  282. height = args[0].height;
  283. width = args[0].width;
  284. angle = 0;
  285. } else if (args.length === 2) {
  286. if (typeof args[0] === 'object') {
  287. width = args[0].width;
  288. height = args[0].height;
  289. angle = args[1] || 0;
  290. } else {
  291. width = args[0];
  292. height = args[1];
  293. angle = 0;
  294. }
  295. } else if (args.length === 3) {
  296. width = args[0];
  297. height = args[1];
  298. angle = args[2] || 0;
  299. }
  300. var wh = GD.getRatioWithRotation(0, width, height);
  301. this.setHeight(wh.ratioY);
  302. this.setWidth(wh.ratioX);
  303. return this;
  304. },
  305. getPosition: function () {
  306. return {
  307. x: this._x,
  308. y: this._y
  309. }
  310. },
  311. setPosition: function () {
  312. var args = Array.prototype.slice.call(arguments, 0), x, y;
  313. if (args.length === 0) {
  314. return this;
  315. } else if (args.length === 1) {
  316. if (typeof args[0] != 'object') {
  317. return this;
  318. }
  319. x = args[0].x;
  320. y = args[0].y;
  321. } else {
  322. x = args[0];
  323. y = args[1];
  324. }
  325. if ((x !== 0 && !x) || (y !== 0 && !y)) {
  326. return this;
  327. }
  328. // var childNodes = this.childNodes, offset, childNode, p;
  329. // for (var i = 0, len = childNodes.length; i < len; i++) {
  330. // childNode = childNodes[i];
  331. // p = childNode.getPosition();
  332. // childNode.setPosition(x - (this._x-p.x)*this._ratioX, y - (this._y-p.y)*this._ratioY);
  333. // }
  334. // this._x = x;
  335. // this._y = y;
  336. // return this;
  337. var childNodes, childNode, background, offset = {}, op, cp;
  338. childNodes = this.childNodes;
  339. background = this._background;
  340. op = background.getPosition();
  341. offset.x = x - op.x;
  342. offset.y = y - op.y;
  343. for (var i = 0, len = childNodes.length; i < len; i++) {
  344. childNode = childNodes[i];
  345. cp = childNode.getPosition();
  346. childNode.setPosition(cp.x + offset.x, cp.y + offset.y);
  347. }
  348. this._x = x;
  349. this._y = y;
  350. this._position = {x: x, y: y};
  351. return this;
  352. },
  353. getStyle: function (key) {
  354. if (!key) {
  355. return undefined;
  356. }
  357. return this._styleObject[key];
  358. },
  359. setStyle: function (key, value, force) {
  360. var childNodes = this.childNodes, childNode;
  361. for (var i = 0, len = childNodes.length; i < len; i++) {
  362. childNode = childNodes[i];
  363. if (key === '2d.visible') {
  364. if (value === graphView.isVisible(childNode)) {
  365. continue;
  366. }
  367. if (!value) {
  368. childNode._savedIsVisible = graphView.isVisible(childNode);
  369. childNode.s({
  370. '2d.visible': false
  371. })
  372. } else {
  373. childNode.s({
  374. '2d.visible': childNode._savedIsVisible
  375. })
  376. }
  377. continue;
  378. }
  379. childNode.s({
  380. key: value
  381. });
  382. }
  383. this._styleObject[key] = value;
  384. return this;
  385. },
  386. calcSize: function () {
  387. var background = this._background;
  388. var position = background.getPosition(),
  389. width = background.getWidth(),
  390. height = background.getHeight();
  391. this._width = width;
  392. this._height = height;
  393. this._x = position.x;
  394. this._y = position.y;
  395. this._position = {
  396. x: this._x,
  397. y: this._y
  398. }
  399. return this;
  400. return this;
  401. },
  402. s: function (styleObj, force) {
  403. var args = Array.prototype.slice.call(arguments, 0);
  404. var styleObj;
  405. if (args.length === 0) {
  406. return this;
  407. } else if (args.length === 1) {
  408. styleObj = args[0];
  409. } else {
  410. this.setStyle(args[0], args[1]);
  411. return this;
  412. }
  413. for (var key in styleObj) {
  414. if (!styleObj.hasOwnProperty(key)) {
  415. continue;
  416. }
  417. this.setStyle(key, styleObj[key], force);
  418. }
  419. return this;
  420. },
  421. init: function (x, y, width, height, angle) {
  422. var that = this;
  423. this.calcSize();
  424. (function (width, height, angle) {
  425. // that.setSize(width, height, angle);
  426. // var wh = GD.getRatioWithRotation(angle, width, height);
  427. // width = wh.ratioX;
  428. // height = wh.ratioY;
  429. var originHeight = that._height;
  430. var originWidth = that._width;
  431. var ratioY = height / originHeight;
  432. var ratioX = width / originWidth;
  433. var childNodes = that.childNodes,
  434. childNode,p, op = that.getPosition(), h, ch, oy, w, cw, ox, name, borderRatio, borderWidth;
  435. for (var i = 0, len = childNodes.length; i < len; i++) {
  436. childNode = childNodes[i];
  437. p = childNode.getPosition();
  438. childNode.originHeight = childNode.originHeight || childNode.getHeight();
  439. ch = childNode.getHeight();
  440. cw = childNode.getWidth();
  441. if (ch > 2) {
  442. h = ch * ratioY;
  443. childNode.setHeight(h);
  444. }
  445. if (cw > 2) {
  446. w = cw * ratioX;
  447. childNode.setWidth(w);
  448. }
  449. borderRatio = (ratioX + ratioY)*0.5;
  450. if (childNode._nodeType === 'line') { // 如果是线,
  451. if (childNode.getWidth() > childNode.getHeight()) {
  452. borderRatio = ratioX;
  453. } else {
  454. borderRatio = ratioY;
  455. }
  456. }
  457. name = childNode._nodename;
  458. // if (childNode.borderWidth && name && ch > 2 && cw > 2) {
  459. // borderWidth = childNode.borderWidth / borderRatio;
  460. // if (borderWidth > ch*0.5 || borderWidth > cw *0.5) {
  461. // // borderWidth = childNode.borderWidth;
  462. // }
  463. // childNode.borderWidth = borderWidth;
  464. // childNode.a(name + '.borderwidth', borderWidth);
  465. // }
  466. }
  467. that._height = height;
  468. that._originHeight = height;
  469. that._ratioY = ratioY;
  470. that._width = width;
  471. that._originWidth = width;
  472. that._ratioX = ratioX;
  473. })(width, height, angle);
  474. that._x = width / 2;
  475. that._y = height / 2;
  476. that._rotation = 0;
  477. // that.setPosition(x, y);
  478. (function (x, y) {
  479. var childNodes = that.childNodes, offset, childNode;
  480. var w2 = that.getWidth() / 2, h2 = that.getHeight()/2;
  481. for (var i = 0, len = childNodes.length; i < len; i++) {
  482. childNode = childNodes[i];
  483. offset = childNode.getPosition();
  484. childNode.setPosition(x + offset.x * that._ratioX - w2, y + offset.y * that._ratioY - h2);
  485. }
  486. that._x = x;
  487. that._y = y;
  488. })(x, y);
  489. // setTimeout(that.addEVent, 1000);
  490. },
  491. setRotation: function (angle) {
  492. var that = this, _angle = that.getRotation();
  493. if (angle!==0 && !angle || angle === _angle) {
  494. return this;
  495. }
  496. var childNodes = this.childNodes, childNode, p = this.getPosition(), px = p.x, py = p.y;
  497. for (var i = 0, len = childNodes.length; i < len; i++) {
  498. childNode = childNodes[i];
  499. var x = childNode.getPosition().x - px;
  500. var y = childNode.getPosition().y - py;
  501. childNode.setPosition(Math.cos(angle-_angle) * x - Math.sin(angle-_angle) * y + px, Math.cos(angle-_angle) * y + Math.sin(angle-_angle) * x + py);
  502. childNode.setRotation(angle);
  503. }
  504. this._rotation = angle;
  505. return this;
  506. },
  507. getRotation: function () {
  508. return this._rotation;
  509. },
  510. setScale: function (sx, sy) {
  511. var that = this,
  512. childNodes = this.childNodes,
  513. childNode;
  514. if (sx === undefined || sx === null) return ;
  515. if (sy === undefined || sy === null) {
  516. sy = sx;
  517. }
  518. for (var i = 0, len = childNodes.length; i < len; i++) {
  519. childNode = childNodes[i];
  520. if (typeof childNode.setScale === 'function') {
  521. childNode.setScale(sx, sy);
  522. }
  523. }
  524. },
  525. getScale: function () {
  526. return this._background.getScale();
  527. },
  528. setScaleX: function (sx) {
  529. if (sx === undefined || sx === null) return;
  530. var that = this,
  531. childNodes = this.childNodes,
  532. childNode;
  533. for (var i = 0, len = childNodes.length; i < len; i++) {
  534. childNode = childNodes[i];
  535. if (typeof childNode.setScaleX === 'function') {
  536. childNode.setScaleX(sx);
  537. }
  538. }
  539. },
  540. setScaleY: function (sy) {
  541. if (sy === undefined || sy === null) return;
  542. var that = this,
  543. childNodes = this.childNodes,
  544. childNode;
  545. for (var i = 0, len = childNodes.length; i < len; i++) {
  546. childNode = childNodes[i];
  547. if (typeof childNode.setScaleY === 'function') {
  548. childNode.setScaleY(sy);
  549. }
  550. }
  551. },
  552. getScaleX: function () {
  553. return this._background.getScaleX();
  554. },
  555. getScaleY: function () {
  556. return this._background.getScaleY();
  557. },
  558. evert: function () {
  559. var that = this,
  560. childNodes = this.childNodes,
  561. background = this._background,
  562. bp = background.getPosition(),
  563. bx = bp.x,
  564. by = bp.y,
  565. childNode, distanceX, distanceY, x, y, p, nx, ny;
  566. for (var i = 0, len = childNodes.length; i < len; i++) {
  567. childNode = childNodes[i];
  568. p = childNode.getPosition();
  569. x = p.x;
  570. y = p.y;
  571. distanceX = bx - x;
  572. distanceY = by - y;
  573. nx = bx + distanceX;
  574. ny = by + distanceY;
  575. childNode.setPosition(nx, ny);
  576. if (typeof childNode.setScale === 'function') {
  577. if (!(childNode._disallowEvert === true))
  578. childNode.setScale(-1, -1);
  579. }
  580. }
  581. },
  582. evertX: function () {
  583. var that = this,
  584. childNodes = this.childNodes,
  585. background = this._background,
  586. bx = background.getPosition().x,
  587. childNode, distance, x, p, nx;
  588. for (var i = 0, len = childNodes.length; i < len; i++) {
  589. childNode = childNodes[i];
  590. p = childNode.getPosition();
  591. x = p.x;
  592. distance = bx - x;
  593. nx = bx + distance;
  594. childNode.setPosition(nx, p.y);
  595. if (typeof childNode.setScaleX === 'function') {
  596. if (!(childNode._disallowEvert === true))
  597. childNode.setScaleX(-1);
  598. }
  599. }
  600. },
  601. evertY: function () {
  602. var that = this,
  603. childNodes = this.childNodes,
  604. background = this._background,
  605. by = background.getPosition().y,
  606. childNode, distance, y, p, ny;
  607. for (var i = 0, len = childNodes.length; i < len; i++) {
  608. childNode = childNodes[i];
  609. p = childNode.getPosition();
  610. y = p.y;
  611. distance = by - y;
  612. ny = by + distance;
  613. childNode.setPosition(p.x, ny);
  614. if (typeof childNode.setScaleY === 'function') {
  615. if (!(childNode._disallowEvert === true))
  616. childNode.setScaleY(-1);
  617. }
  618. }
  619. },
  620. attr: function (key, value) {
  621. var _attrObj = this._attrObj || {};
  622. if (arguments.length === 1) {
  623. return _attrObj[key];
  624. }
  625. var childNodes = this.childNodes, childNode;
  626. _attrObj[key] = value;
  627. for (var i = 0; childNode = childNodes[i++];) {
  628. if (typeof childNode.a === 'function') {
  629. childNode.a(key, value);
  630. }
  631. }
  632. },
  633. a: function () {
  634. return this.attr.apply(this, arguments);
  635. }
  636. });
  637. }