ImportantClasses.dox 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*!
  2. \page ImportantClasses Important Classes
  3. This section introduces some important part of the QCAD Application
  4. Framework API.
  5. \section rdocument The Drawing Document
  6. The document that is being viewed or edited is a central part for most
  7. applications. Within the QCAD Application Framework, documents can exist
  8. independent of any user interface components. Think of a document as
  9. a complete CAD drawing.
  10. \image html RDocument.png
  11. The following ECMAScript code creates an empty drawing document:
  12. \code
  13. // Creating the storage underneath the document:
  14. var storage = new RMemoryStorage();
  15. // Creating the spatial index:
  16. var spatialIndex = new RSpatialIndexNavel();
  17. // Creating the document:
  18. var document = new RDocument(storage, spatialIndex);
  19. // Creating the document interface
  20. // (required for import / export, graphics scenes and views):
  21. var documentInterface = new RDocumentInterface(document);
  22. \endcode
  23. Storage and spatial index are required for lower level data storage
  24. but usually only act behind the scenes.
  25. \section interaction Interaction
  26. The interaction between a user and an application typically consists of
  27. a user input, followed by an output of the application to indicate the result
  28. of the user input. The most important output when interacting with a CAD
  29. system is the visualization of the CAD drawing.
  30. \subsection RDocumentInterface Visualization
  31. The visualization of a drawing is handled in the QCAD Application Framework
  32. through one or multiple graphics views (classes derived from RGraphicsView).
  33. A graphics view is typically a visible widget or window.
  34. Each graphics view is attached to a graphics scene (RGraphicsScene) which
  35. manages the visual representation of the drawing entities. The graphics
  36. scene is connected to a document (RDocument) via a document interface
  37. (RDocumentInterface).
  38. While the document knows what entities are and how they are geometrically
  39. defined, the graphics scene knows how each entity looks like and the
  40. graphics view knows how to display that visual representation of an entity
  41. to the user. The document interface connects a document to one or
  42. multiple graphics scenes and has some other important responsibilities
  43. that are outlined later on.
  44. This structure makes it possible
  45. to visualize a drawing in multiple views. Each view can have its own scene
  46. or share a scene with other views. The following diagram shows the
  47. relationship between a document and its graphics scenes and views.
  48. Note that any changes to the document automatically trigger an update
  49. to all scenes and views attached to it.
  50. \image html RDocumentInterface.png
  51. Multiple scenes can be attached to a drawing interface to provide different
  52. visualizations, for example a 2D visualization and a 3D visualization of
  53. the same document.
  54. Multiple views can be attached to each scene to show the scene at a different
  55. zoom factor and offset or at a different angle.
  56. The following ECMAScript snippet attaches a graphics scene with one graphics
  57. view to a document interface. Note that RGraphicsViewQt is a complete
  58. implementation of a graphics view, based on a Qt QWidget. RGraphicsSceneQt
  59. is the graphics scene implementation that handles the visualization
  60. of the underlying document using QPainterPath objects.
  61. \code
  62. var graphicsScene = new RGraphicsSceneQt(documentInterface)
  63. var graphicsView = new RGraphicsViewQt();
  64. graphicsView.setScene(graphicsScene);
  65. \endcode
  66. \subsection RAction User Input
  67. In the QCAD Application Framework, user input and drawing visualization
  68. share the same structures. The document interface is at the heart
  69. of both visualization and interaction.
  70. Users typically interact with a graphics view, for example by moving the
  71. mouse, clicking a mouse button or pressing a key while a graphics view has
  72. the focus. The graphics view receives all such low level events
  73. from input devices and translates them into more useful, higher level events.
  74. For example the click of the left mouse button at a view coordinate in
  75. pixels is translated into a higher level event (RMouseEvent) that also
  76. stores the model coordinates of the click. These higher level events are
  77. then forwarded to the graphics scene to which the view is attached.
  78. The graphics scene simply forwards the events to the document interface.
  79. The document interface always knows what action (or tool) is currently
  80. active. For example if the user is drawing a line, the current action is
  81. a class derived from RAction that handles all user interaction to draw a
  82. line (e.g. Line2P). The document interface forwards all events it receives
  83. to the current action.
  84. The current action is responsible for handling the user input, typically
  85. by reacting to it and visualizing the result.
  86. This flow of user input and application output is shown in the figure below:
  87. \image html RDocumentInterface2.png
  88. \section RImporter Importers
  89. Whenever a document has to be produced from existing data, a class that
  90. is derived from RImporter should be used. If the source is a file, a
  91. specialized base class RFileImporter can be used.
  92. The QCAD Application Framework provides an importer for the DXF format.
  93. \section rexporter Exporters
  94. When a drawing is exported, an exporter, derived from RExporter is used.
  95. Graphics scenes are also derived from RExporter, since they are used
  96. to 'export' a drawing into a graphical representation (e.g. painter paths
  97. or an OpenGL context). For exporters that export to a file, the
  98. specialized class RFileExporter can be used as a base class.
  99. The QCAD Application Framework provides an exporter for the DXF format.
  100. */