simple_create.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822
  1. /**
  2. * Simple Creation API, mainly designed for use in the ECMAScript console.
  3. */
  4. /**
  5. * Sets the current color for newly added entities
  6. * \ingroup ecma_simple
  7. *
  8. * \code
  9. * setCurrentColor(new RColor(255, 255, 255))
  10. * setCurrentColor(new RColor("white"))
  11. * setCurrentColor(255, 255, 255)
  12. * \endcode
  13. */
  14. function setCurrentColor(color) {
  15. var di = getTransactionDocumentInterface();
  16. if (isNull(di)) {
  17. di = getTransactionDocument();
  18. }
  19. if (isNull(di)) {
  20. qWarning("no document interface or document");
  21. return;
  22. }
  23. // r, g, b:
  24. if (arguments.length===3) {
  25. setCurrentColor(new RColor(arguments[0], arguments[1], arguments[2]));
  26. return;
  27. }
  28. di.setCurrentColor(color);
  29. }
  30. /**
  31. * Checks if the given layer exists.
  32. * \ingroup ecma_simple
  33. *
  34. * \code
  35. * hasLayer("MyLayer1")
  36. * \endcode
  37. */
  38. function hasLayer(name) {
  39. var doc = getTransactionDocument();
  40. if (isNull(doc)) {
  41. return false;
  42. }
  43. return doc.hasLayer(name);
  44. }
  45. /**
  46. * Adds a layer to the drawing.
  47. * \ingroup ecma_simple
  48. *
  49. * \code
  50. * addLayer("MyLayer1")
  51. * addLayer("MyLayer2", "white", "CONTINUOUS", RLineweight.Weight025)
  52. * \endcode
  53. */
  54. function addLayer(name, colorName, linetypeName, lineWeight) {
  55. var doc = getTransactionDocument();
  56. if (isNull(doc)) {
  57. return undefined;
  58. }
  59. if (isNull(colorName)) {
  60. colorName = "white";
  61. }
  62. if (isNull(linetypeName)) {
  63. linetypeName = "CONTINUOUS";
  64. }
  65. if (isNull(lineWeight)) {
  66. lineWeight = RLineweight.Weight000;
  67. }
  68. if (doc.hasLayer(name)) {
  69. return undefined;
  70. }
  71. var layer = new RLayer(
  72. doc, name, false, false,
  73. new RColor(colorName),
  74. doc.getLinetypeId(linetypeName),
  75. lineWeight, false
  76. );
  77. return addObject(layer);
  78. }
  79. /**
  80. * Sets the current layer to the given layer.
  81. * \ingroup ecma_simple
  82. *
  83. * \param layerName Layer name or ID.
  84. */
  85. function setCurrentLayer(layerName) {
  86. var di = getTransactionDocumentInterface();
  87. if (isNull(di)) {
  88. return false;
  89. }
  90. di.setCurrentLayer(layerName);
  91. }
  92. /**
  93. * Adds a point to the drawing.
  94. * \ingroup ecma_simple
  95. *
  96. * \code
  97. * addPoint(x,y)
  98. * addPoint([x,y])
  99. * addPoint(new RVector(x,y))
  100. * \endcode
  101. */
  102. function addPoint(position) {
  103. if (arguments.length===2) {
  104. return addPoint(new RVector(arguments[0], arguments[1]));
  105. }
  106. if (isArray(position)) {
  107. return addPoint(new RVector(position));
  108. }
  109. return addShape(new RPoint(position));
  110. }
  111. /**
  112. * Adds a line to the drawing.
  113. * \ingroup ecma_simple
  114. *
  115. * \code
  116. * addLine(x1,y1, x2,y2)
  117. * addLine([x1,y1], [x2,y2])
  118. * addLine(new RVector(x1,y1), new RVector(x2,y2))
  119. * \endcode
  120. */
  121. function addLine(startPoint, endPoint) {
  122. if (arguments.length===4) {
  123. return addLine(new RVector(arguments[0], arguments[1]), new RVector(arguments[2], arguments[3]));
  124. }
  125. if (isArray(startPoint)) {
  126. startPoint = new RVector(startPoint);
  127. }
  128. if (isArray(endPoint)) {
  129. endPoint = new RVector(endPoint);
  130. }
  131. return addShape(new RLine(startPoint, endPoint));
  132. }
  133. /**
  134. * Adds an infinite line to the drawing.
  135. * The two vectors are the base point and the direction vector
  136. * (point relative to base point)
  137. * \ingroup ecma_simple
  138. *
  139. * \code
  140. * addXLine(x1,y1, dx,dy)
  141. * addXLine([x1,y1], [dx,dy])
  142. * addXLine(new RVector(x1,y1), new RVector(dx,dy))
  143. * \endcode
  144. */
  145. function addXLine(startPoint, directionVector) {
  146. if (arguments.length===4) {
  147. return addXLine(new RVector(arguments[0], arguments[1]), new RVector(arguments[2], arguments[3]));
  148. }
  149. if (isArray(startPoint)) {
  150. startPoint = new RVector(startPoint);
  151. }
  152. if (isArray(directionVector)) {
  153. directionVector = new RVector(directionVector);
  154. }
  155. return addShape(new RXLine(startPoint, directionVector));
  156. }
  157. /**
  158. * Adds an arc to the drawing.
  159. * \ingroup ecma_simple
  160. *
  161. * \code
  162. * addArc(cx,cy, radius, startAngle, endAngle, reversed)
  163. * addArc([cx,cy], radius, startAngle, endAngle, reversed)
  164. * addArc(new RVector(cx,cy), radius, startAngle, endAngle, reversed)
  165. * \endcode
  166. */
  167. function addArc(center, radius, startAngle, endAngle, reversed) {
  168. if (arguments.length===6) {
  169. return addArc(new RVector(arguments[0], arguments[1]), arguments[2], arguments[3], arguments[4], arguments[5]);
  170. }
  171. if (isArray(center)) {
  172. center = new RVector(center);
  173. }
  174. if (!isVector(center)) {
  175. qWarning("invalid center");
  176. throw("invalid center");
  177. }
  178. return addShape(new RArc(center, radius, deg2rad(startAngle), deg2rad(endAngle), reversed));
  179. }
  180. /**
  181. * Adds a circle to the drawing.
  182. * \ingroup ecma_simple
  183. *
  184. * \code
  185. * addCircle(cx,cy, radius)
  186. * addCircle([cx,cy], radius)
  187. * addCircle(new RVector(cx,cy), radius)
  188. * \endcode
  189. */
  190. function addCircle(center, radius) {
  191. if (arguments.length===3) {
  192. return addCircle(new RVector(arguments[0], arguments[1]), arguments[2]);
  193. }
  194. if (isArray(center)) {
  195. center = new RVector(center);
  196. }
  197. return addShape(new RCircle(center, radius));
  198. }
  199. /**
  200. * Adds a polyline to the drawing.
  201. * \ingroup ecma_simple
  202. * \author Andrew Mustun
  203. * \author tukuyomi
  204. *
  205. * \param p Array of type [ [ x, y, bulge, relative ], ..., [ ... ] ]
  206. * or [ [ vector, bulge, relative ], ..., [ ... ] ]
  207. * Where:
  208. * x: X coordinate
  209. * y: Y coordinate
  210. * vector: RVector with position of vertex
  211. * bulge: Bulge for next segment after vertex, defaults to 0.0.
  212. * relative: True if this vector's coordinates are relative to the previous coordinates,
  213. * defaults to false.
  214. *
  215. * \param closed True for an implicitly closed polyline. Default is false.
  216. * \param relative True to treat all coordinates as relative.
  217. * The first coordinate is always absolute. Default is false.
  218. *
  219. * \code
  220. * addPolyline([[x1,y1],[x2,y2],[x3,y3]], false)
  221. * addPolyline([ [ 100 , 0 ], [ 20 , -10 , 1 ], [ 0 , 40 , 0 , true ], [ -20 , -10 , 1 , true ] ])
  222. * addPolyline([new RVector(x1,y1),new RVector(x2,y2),new RVector(x3,y3)], closed, relative)
  223. * addPolyline([[new RVector(x1,y1),bulge1,rel1],[new RVector(x2,y2),bulge2,rel2],[new RVector(x3,y3),bulge3,rel3]], closed, relative)
  224. * \endcode
  225. */
  226. function addPolyline(points, closed, relative) {
  227. if (isNull(closed)) {
  228. closed = false;
  229. }
  230. if (isNull(relative)) {
  231. relative = false;
  232. }
  233. var pl = new RPolyline();
  234. pl.setClosed(closed);
  235. var v = new RVector(0,0);
  236. for (var i=0; i<points.length; i++) {
  237. var v0 = undefined;
  238. var b = 0.0;
  239. var rel = relative;
  240. if (isVector(points[i])) {
  241. v0 = points[i];
  242. }
  243. // first item in vertex tuple is RVector or x,y pair:
  244. else if (isArray(points[i])) {
  245. if (isVector(points[i][0])) {
  246. v0 = points[i][0];
  247. if (!isNull(points[i][1])) {
  248. b = points[i][1];
  249. }
  250. if (!isNull(points[i][2])) {
  251. rel = points[i][2];
  252. }
  253. }
  254. else {
  255. v0 = new RVector(points[i][0], points[i][1]);
  256. if (!isNull(points[i][2])) {
  257. b = points[i][2];
  258. }
  259. if (!isNull(points[i][3])) {
  260. rel = points[i][3];
  261. }
  262. }
  263. }
  264. // custom objects with .x, .y (, .z, .b) members:
  265. else if (isNumber(points[i].x) && isNumber(points[i].y)) {
  266. if (isNumber(points[i].z)) {
  267. v0 = new RVector(points[i].x, points[i].y, points[i].z);
  268. }
  269. else {
  270. v0 = new RVector(points[i].x, points[i].y);
  271. }
  272. if (isNumber(points[i].b)) {
  273. b = points[i].b;
  274. }
  275. }
  276. // relative or absolute vertex position:
  277. if (relative) {
  278. v = v.operator_add(v0);
  279. }
  280. else {
  281. v = v0;
  282. }
  283. pl.appendVertex(v, b);
  284. }
  285. return addShape(pl);
  286. }
  287. /**
  288. * Adds a spline to the drawing.
  289. * \ingroup ecma_simple
  290. *
  291. * \param fitPoints Array of RVector or [x,y] tuples.
  292. * \param closed True for a closed, periodic spline.
  293. *
  294. * \code
  295. * addSpline([[x1,y1],[x2,y2],[x3,y3]], false)
  296. * addSpline([new RVector(x1,y1),new RVector(x2,y2),new RVector(x3,y3)], false)
  297. * \endcode
  298. */
  299. function addSpline(points, closed) {
  300. if (isNull(closed)) {
  301. closed = false;
  302. }
  303. var sp = new RSpline();
  304. sp.setPeriodic(closed);
  305. for (var i=0; i<points.length; i++) {
  306. if (isVector(points[i])) {
  307. sp.appendFitPoint(points[i]);
  308. }
  309. else {
  310. sp.appendFitPoint(new RVector(points[i][0], points[i][1]));
  311. }
  312. }
  313. return addShape(sp);
  314. }
  315. /**
  316. * Adds a simple text to the drawing.
  317. * \ingroup ecma_simple
  318. *
  319. * \param text Text string.
  320. * \param position position
  321. * \param height Text height (defaults to 1)
  322. * \param angle Text angle (defaults to 0)
  323. * \param font Font (defaults to "standard")
  324. * \param vAlign Vertical alignment (defaults to RS.VAlignTop)
  325. * \param hAlign Horizontal alignment (defaults to RS.HAlignLeft)
  326. * \param bold True for bold text (TTF fonts only)
  327. * \param italic True for italic text (TTF fonts only)
  328. *
  329. * \code
  330. * addSimpleText(text, x, y, height, angle, font, vAlign, hAlign, bold, italic)
  331. * addSimpleText(text, [x, y], height, angle, font, vAlign, hAlign, bold, italic)
  332. * addSimpleText(text, new RVector(x, y), height, angle, font, vAlign, hAlign, bold, italic)
  333. * \endcode
  334. */
  335. function addSimpleText(text, position, height, angle, font, vAlign, hAlign, bold, italic) {
  336. if (arguments.length===10) {
  337. return addSimpleText(arguments[0], new RVector(arguments[1], arguments[2]), arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9]);
  338. }
  339. if (arguments.length===3 && isNumber(position)) {
  340. // addSimpleText("text", x, y)
  341. return addSimpleText(arguments[0], new RVector(arguments[1], arguments[2]));
  342. }
  343. var doc = getTransactionDocument();
  344. if (isNull(doc)) {
  345. return undefined;
  346. }
  347. if (isNull(height)) height = 10.0;
  348. if (isNull(angle)) angle = 0.0;
  349. if (isNull(font)) font = "Standard";
  350. if (isNull(vAlign)) vAlign = RS.VAlignTop;
  351. if (isNull(hAlign)) hAlign = RS.HAlignLeft;
  352. if (isNull(bold)) bold = false;
  353. if (isNull(italic)) italic = false;
  354. if (isArray(position)) {
  355. position = new RVector(position);
  356. }
  357. var entity = new RTextEntity(
  358. doc,
  359. new RTextData(
  360. position,
  361. position,
  362. height,
  363. 0.0,
  364. vAlign,
  365. hAlign,
  366. RS.LeftToRight,
  367. RS.Exact,
  368. 1.0,
  369. text,
  370. font,
  371. bold,
  372. italic,
  373. deg2rad(angle),
  374. true
  375. )
  376. );
  377. return addEntity(entity);
  378. }
  379. /**
  380. * Adds the given RShapes to the drawing as new entities using current layer and attributes.
  381. * \ingroup ecma_simple
  382. *
  383. * \return The added entities. The entities do not yet have valid IDs if they were added within a
  384. * transaction.
  385. */
  386. function addShapes(shapes) {
  387. for (var i=0; i<shapes.length; i++) {
  388. addShape(shapes[i]);
  389. }
  390. }
  391. /**
  392. * Adds the given RShape to the drawing as a new entity using current layer and attributes.
  393. * \ingroup ecma_simple
  394. *
  395. * \return The added entity. The entity does not yet have a valid ID if it was added within a
  396. * transaction.
  397. *
  398. * \code
  399. * addShape(shape)
  400. * addShape(shape, new RColor(255,0,0), "CONTINUOUS", 0.05)
  401. * \endcode
  402. */
  403. function addShape(shape, color, linetype, lineweight) {
  404. var doc = getTransactionDocument();
  405. if (isNull(doc)) {
  406. return undefined;
  407. }
  408. var entity = shapeToEntity(doc, shape);
  409. if (!isNull(color)) {
  410. entity.setColor(color);
  411. }
  412. if (isNumber(linetype)) {
  413. entity.setLinetypeId(linetype);
  414. }
  415. if (isString(linetype)) {
  416. entity.setLinetypeId(doc.getLinetypeId(linetype));
  417. }
  418. if (isNumber(lineweight)) {
  419. entity.setLineweight(lineweight);
  420. }
  421. return addEntity(entity);
  422. }
  423. /**
  424. * Adds the given REntity to the drawing using layer and attributes as set by the entity.
  425. * \ingroup ecma_simple
  426. *
  427. * \return The added entity. The entity does not yet have a valid ID if it was added within a
  428. * transaction.
  429. */
  430. function addEntity(entity) {
  431. return addObject(entity);
  432. }
  433. /**
  434. * Adds the given RObject to the drawing.
  435. * \ingroup ecma_simple
  436. *
  437. * \return The added object. The object does not yet have a valid ID if it was added within a
  438. * transaction.
  439. */
  440. function addObject(obj) {
  441. if (isFunction(obj.data)) {
  442. return addObject(obj.data().clone());
  443. }
  444. if (__simpleUseOp===true) {
  445. if (isNull(__simpleOp)) {
  446. __simpleOp = new RAddObjectsOperation();
  447. }
  448. __simpleOp.addObject(obj, false);
  449. return obj.clone();
  450. }
  451. else {
  452. var di = getDocumentInterface();
  453. di.applyOperation(new RAddObjectOperation(obj, false));
  454. return obj.clone();
  455. }
  456. }
  457. /**
  458. * Deletes the given RObject from the drawing.
  459. * \ingroup ecma_simple
  460. *
  461. * \return The added object. The object does not yet have a valid ID if it was added within a
  462. * transaction.
  463. */
  464. function deleteObject(obj) {
  465. if (isFunction(obj.data)) {
  466. deleteObject(obj.data().clone());
  467. }
  468. if (__simpleUseOp===true) {
  469. if (isNull(__simpleOp)) {
  470. __simpleOp = new RAddObjectsOperation();
  471. }
  472. __simpleOp.deleteObject(obj);
  473. }
  474. else {
  475. var di = getDocumentInterface();
  476. di.applyOperation(new RDeleteObjectOperation(obj));
  477. }
  478. }
  479. function addPolylinetoView(points, closed, relative, filetype,linecolor) {
  480. if (isNull(closed)) {
  481. closed = false;
  482. }
  483. if (isNull(relative)) {
  484. relative = false;
  485. }
  486. var pl = new RPolyline();
  487. pl.setClosed(closed);
  488. var v = new RVector(0, 0);
  489. for (var i = 0; i < points.length; i++) {
  490. var v0 = undefined;
  491. var b = 0.0;
  492. var rel = relative;
  493. if (isVector(points[i])) {
  494. v0 = points[i];
  495. }
  496. // first item in vertex tuple is RVector or x,y pair:
  497. else if (isArray(points[i])) {
  498. if (isVector(points[i][0])) {
  499. v0 = points[i][0];
  500. if (!isNull(points[i][1])) {
  501. b = points[i][1];
  502. }
  503. if (!isNull(points[i][2])) {
  504. rel = points[i][2];
  505. }
  506. }
  507. else {
  508. v0 = new RVector(points[i][0], points[i][1]);
  509. if (!isNull(points[i][2])) {
  510. b = points[i][2];
  511. }
  512. if (!isNull(points[i][3])) {
  513. rel = points[i][3];
  514. }
  515. }
  516. }
  517. // custom objects with .x, .y (, .z, .b) members:
  518. else if (isNumber(points[i].x) && isNumber(points[i].y)) {
  519. if (isNumber(points[i].z)) {
  520. v0 = new RVector(points[i].x, points[i].y, points[i].z);
  521. }
  522. else {
  523. v0 = new RVector(points[i].x, points[i].y);
  524. }
  525. if (isNumber(points[i].b)) {
  526. b = points[i].b;
  527. }
  528. }
  529. // relative or absolute vertex position:
  530. if (relative) {
  531. v = v.operator_add(v0);
  532. }
  533. else {
  534. v = v0;
  535. }
  536. pl.appendVertex(v, b);
  537. }
  538. return addShapetoView(filetype, pl, linecolor);
  539. }
  540. function addShapetoView(filetype, shape, color, linetype, lineweight) {
  541. var doc = getAssignTransactionDocument(filetype);
  542. if (isNull(doc)) {
  543. return undefined;
  544. }
  545. var entity = shapeToEntity(doc, shape);
  546. if (!isNull(color)) {
  547. entity.setColor(color);
  548. }
  549. if (isNumber(linetype)) {
  550. entity.setLinetypeId(linetype);
  551. }
  552. if (isString(linetype)) {
  553. entity.setLinetypeId(doc.getLinetypeId(linetype));
  554. }
  555. if (isNumber(lineweight)) {
  556. entity.setLineweight(lineweight);
  557. }
  558. return addObjecttoView(entity,filetype);
  559. }
  560. function addObjecttoView(obj, filetype) {
  561. if (isFunction(obj.data)) {
  562. return addObjecttoView(obj.data().clone(), filetype);
  563. }
  564. if (__simpleUseOp === true) {
  565. if (isNull(__simpleOp)) {
  566. __simpleOp = new RAddObjectsOperation();
  567. }
  568. __simpleOp.addObject(obj, false);
  569. return obj.clone();
  570. }
  571. else {
  572. var di = getAssignDocumentInterface(filetype);
  573. di.applyOperation(new RAddObjectOperation(obj, false));
  574. return obj.clone();
  575. }
  576. }
  577. /**
  578. * Adds an arc to the drawing.
  579. * \ingroup ecma_simple
  580. *
  581. * \code
  582. * addArc(cx,cy, radius, startAngle, endAngle, reversed)
  583. * addArc([cx,cy], radius, startAngle, endAngle, reversed)
  584. * addArc(new RVector(cx,cy), radius, startAngle, endAngle, reversed)
  585. * \endcode
  586. */
  587. function addArctoView(center, radius, startAngle, endAngle, reversed, filetype, linecolor) {
  588. if (arguments.length == 8) {
  589. return addArctoView(new RVector(arguments[0], arguments[1]), arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7]);
  590. }
  591. if (isArray(center)) {
  592. center = new RVector(center);
  593. }
  594. if (!isVector(center)) {
  595. qWarning("invalid center");
  596. throw ("invalid center");
  597. }
  598. return addShapetoView(filetype, new RArc(center, radius, deg2rad(startAngle), deg2rad(endAngle), reversed), linecolor);
  599. }
  600. /**
  601. * Adds a circle to the drawing.
  602. * \ingroup ecma_simple
  603. *
  604. * \code
  605. * addCircle(cx,cy, radius)
  606. * addCircle([cx,cy], radius)
  607. * addCircle(new RVector(cx,cy), radius)
  608. * \endcode
  609. */
  610. function addCircleToView(center, radius, filetype,linecolor) {
  611. if (arguments.length === 5) {
  612. return addCircleToView(new RVector(arguments[0], arguments[1]), arguments[2], arguments[3], arguments[4]);
  613. }
  614. if (isArray(center)) {
  615. center = new RVector(center);
  616. }
  617. return addShapetoView(filetype, new RCircle(center, radius), linecolor);
  618. }
  619. function addLayerToView(name, colorName, linetypeName, lineWeight, filetype) {
  620. var doc = getAssignTransactionDocument(filetype);
  621. if (isNull(doc)) {
  622. return undefined;
  623. }
  624. if (isNull(colorName)) {
  625. colorName = "white";
  626. }
  627. if (isNull(linetypeName)) {
  628. linetypeName = "CONTINUOUS";
  629. }
  630. if (isNull(lineWeight)) {
  631. lineWeight = RLineweight.Weight000;
  632. }
  633. if (doc.hasLayer(name)) {
  634. return undefined;
  635. }
  636. var layer = new RLayer(
  637. doc, name, false, false,
  638. new RColor(colorName),
  639. doc.getLinetypeId(linetypeName),
  640. lineWeight, false
  641. );
  642. addObjecttoView(layer, filetype);
  643. }
  644. /**
  645. * Adds a point to the drawing.
  646. * \ingroup ecma_simple
  647. *
  648. * \code
  649. * addPoint(x,y)
  650. * addPoint([x,y])
  651. * addPoint(new RVector(x,y))
  652. * \endcode
  653. */
  654. function addPointToView(position, filetype) {
  655. if (arguments.length === 3) {
  656. return addPointToView(new RVector(arguments[0], arguments[1]), arguments[2]);
  657. }
  658. if (isArray(position)) {
  659. return addPointToView(new RVector(position));
  660. }
  661. return addShapetoView(filetype, new RPoint(position));
  662. }
  663. /**
  664. * Adds a line to the drawing.
  665. * \ingroup ecma_simple
  666. *
  667. * \code
  668. * addLine(x1,y1, x2,y2)
  669. * addLine([x1,y1], [x2,y2])
  670. * addLine(new RVector(x1,y1), new RVector(x2,y2))
  671. * \endcode
  672. */
  673. function addLineToView(startPoint, endPoint, filetype) {
  674. if (arguments.length === 5) {
  675. return addLineToView(new RVector(arguments[0], arguments[1]), new RVector(arguments[2], arguments[3]), arguments[4]);
  676. }
  677. if (isArray(startPoint)) {
  678. startPoint = new RVector(startPoint);
  679. }
  680. if (isArray(endPoint)) {
  681. endPoint = new RVector(endPoint);
  682. }
  683. return addShapetoView(filetype, new RLine(startPoint, endPoint));
  684. }
  685. /**
  686. * Adds a simple text to the drawing.
  687. * \ingroup ecma_simple
  688. *
  689. * \param text Text string.
  690. * \param position position
  691. * \param height Text height (defaults to 1)
  692. * \param angle Text angle (defaults to 0)
  693. * \param font Font (defaults to "standard")
  694. * \param vAlign Vertical alignment (defaults to RS.VAlignTop)
  695. * \param hAlign Horizontal alignment (defaults to RS.HAlignLeft)
  696. * \param bold True for bold text (TTF fonts only)
  697. * \param italic True for italic text (TTF fonts only)
  698. *
  699. * \code
  700. * addSimpleText(text, x, y, height, angle, font, vAlign, hAlign, bold, italic)
  701. * addSimpleText(text, [x, y], height, angle, font, vAlign, hAlign, bold, italic)
  702. * addSimpleText(text, new RVector(x, y), height, angle, font, vAlign, hAlign, bold, italic)
  703. * \endcode
  704. */
  705. function addSimpleTextToView(text, position, height, angle, font, vAlign, hAlign, bold, italic, filetype) {
  706. if (arguments.length === 11) {
  707. return addSimpleTextToView(arguments[0], new RVector(arguments[1], arguments[2]), arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9], arguments[10]);
  708. }
  709. var doc = getAssignTransactionDocument(filetype);
  710. if (isNull(doc)) {
  711. return undefined;
  712. }
  713. if (isNull(height)) height = 1.0;
  714. if (isNull(angle)) angle = 0.0;
  715. if (isNull(font)) font = "Standard";
  716. if (isNull(vAlign)) vAlign = RS.VAlignTop;
  717. if (isNull(hAlign)) hAlign = RS.HAlignLeft;
  718. if (isNull(bold)) bold = false;
  719. if (isNull(italic)) italic = false;
  720. if (isArray(position)) {
  721. position = new RVector(position);
  722. }
  723. var entity = new RTextEntity(
  724. doc,
  725. new RTextData(
  726. position,
  727. position,
  728. height,
  729. 0.0,
  730. vAlign,
  731. hAlign,
  732. RS.LeftToRight,
  733. RS.Exact,
  734. 1.0,
  735. text,
  736. font,
  737. bold,
  738. italic,
  739. deg2rad(angle),
  740. true
  741. )
  742. );
  743. // return addEntity(entity);
  744. return addObjecttoView(entity, filetype);
  745. }