CreatingDrawing.dox 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*!
  2. \page CreatingDrawing Creating a Drawing
  3. With the QCAD Application Framework it is not only possible to
  4. create interactive tools but also to construct entire drawings
  5. based on user input (dialog, command line arguments, ...),
  6. mathematical formulas, data bases, files or other sources.
  7. This tutorial focuses on creating objects with the QCAD Application Framework
  8. and adding them to a drawing document. The example in this tutorial
  9. creates a drawing document from scratch, adds various objects
  10. to it and saves the document as a DXF file. No user interface
  11. is used for this example, so it can be run as a command line application
  12. without first starting the QCAD Application user interface.
  13. \section initialization Initialization
  14. Some initialization is required before we get started. We need to give the
  15. application a name (used among other things as ID for XDATA in DXF / DWG).
  16. \snippet CreatingDrawing.jsd init
  17. \section documents Creating a Document
  18. A drawing in the QCAD Application Framework is represented
  19. by a document (RDocument). The document is backed by a storage
  20. which stores the actual drawing data (RStorage) and is usually
  21. not accessed directly by script developers. Further, the
  22. document also owns a spatial index (RSpatialIndex) for fast entity
  23. lookup based on location. Script developers only need to worry
  24. about the spatial index to create a document.
  25. This code snippet creates a new, empty drawing document (RDocument)
  26. that is backed by a memory storage (RMemoryStorage) and a high performance
  27. spatial index implementation (RSpatialIndexNavel):
  28. \snippet CreatingDrawing.jsd document
  29. The new document already contains some default objects like a
  30. layer '0', the model space block and line type definitions.
  31. The document has no graphics views attached, so there is no
  32. visual representation of any kind. Graphics scenes and views
  33. could be attached to the document interface.
  34. \section operations Operations
  35. Every change to a document (including adding entities) is wrapped
  36. in a transaction (RTransaction) in the QCAD Application Framework.
  37. Transactions are a low level concept and usually don't have to be
  38. used directly by script developers.
  39. To control which changes belong to one transaction, the
  40. QCAD Application Framework offers a higher level concept of
  41. operations (ROperation). An operation essentially wraps a
  42. transaction with a user friendly interface. Operations can be
  43. applied to documents in way that the various graphics views
  44. and other user interface components are being updated
  45. automatically.
  46. The following example code adds three line entities in the
  47. shape of a regular triangle to a document:
  48. \snippet CreatingDrawing.jsd operation
  49. Note that we have not indicated a layer or any attributes
  50. (color, line type, line weight) for our lines. The lines are
  51. added to the current layer (layer '0') with the default attributes
  52. (color, line type and line weight inherited from layer).
  53. \section export_dxf DXF / DWG Export
  54. To store the drawing document to a DXF file, we can use the document
  55. interface:
  56. \snippet CreatingDrawing.jsd export
  57. \section creating_a_drawing_code Complete Code
  58. Here's the complete code of our example again:
  59. \snippet CreatingDrawing.jsd main
  60. To run the example, save it as a file (e.g. 'example.js') and launch QCAD,
  61. using this script as autostart script:
  62. \code
  63. ./qcad -autostart example.js
  64. \endcode
  65. */