CreatingDrawing.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. function main() {
  20. //! [main]
  21. //! [init]
  22. // init application name:
  23. qApp.applicationName = "MyApplication";
  24. //! [init]
  25. //! [document]
  26. var storage = new RMemoryStorage();
  27. var spatialIndex = new RSpatialIndexSimple();
  28. var document = new RDocument(storage, spatialIndex);
  29. // create document interface (needed for file export functionality):
  30. var di = new RDocumentInterface(document);
  31. //! [document]
  32. //! [operation]
  33. // create an operation:
  34. var operation = new RAddObjectsOperation();
  35. // corner point of the triangle::
  36. var p1 = new RVector(0, 0);
  37. var p2 = new RVector(10, 0);
  38. var p3 = new RVector(5, Math.sin(RMath.deg2rad(60))*10);
  39. // add line entity to operation:
  40. operation.addObject(new RLineEntity(document, new RLineData(p1, p2)));
  41. operation.addObject(new RLineEntity(document, new RLineData(p2, p3)));
  42. operation.addObject(new RLineEntity(document, new RLineData(p3, p1)));
  43. // apply operation to document:
  44. operation.apply(document);
  45. //! [operation]
  46. //! [export]
  47. // export document to DXF, version 2000:
  48. di.exportFile("example.dxf", "DXF 2000");
  49. //! [export]
  50. //! [main]
  51. }
  52. if (typeof(including)=='undefined' || including===false) {
  53. main();
  54. }