]> Shamusworld >> Repos - architektonas/blob - src/base/rs_document.cpp
b4aa5cbc80a3dc0cef369cfb986a73d147bc7448
[architektonas] / src / base / rs_document.cpp
1 // rs_document.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // Portions copyright (C) 2001-2003 RibbonSoft
7 // Copyright (C) 2010 Underground Software
8 // See the README and GPLv2 files for licensing and warranty information
9 //
10 // JLH = James L. Hammons <jlhamm@acm.org>
11 //
12 // Who  When        What
13 // ---  ----------  -----------------------------------------------------------
14 // JLH  05/28/2010  Added this text. :-)
15 //
16
17 #include "rs_document.h"
18
19 /**
20  * Constructor.
21  *
22  * @param parent Parent of the document. Often that's NULL but
23  *        for blocks it's the blocklist.
24  */
25 RS_Document::RS_Document(RS_EntityContainer * parent):
26         RS_EntityContainer(parent), RS_Undo()
27 {
28         RS_DEBUG->print("RS_Document::RS_Document() ");
29
30         filename = "";
31         formatType = RS2::FormatUnknown;
32         setModified(false);
33         RS_Color col(RS2::FlagByLayer);
34         activePen = RS_Pen(col, RS2::WidthByLayer, RS2::LineByLayer);
35 }
36
37 RS_Document::~RS_Document()
38 {
39 }
40
41 /**
42  * @return true for all document entities (e.g. Graphics or Blocks).
43  */
44 bool RS_Document::isDocument() const
45 {
46         return true;
47 }
48
49 /**
50  * Removes an entity from the entiy container. Implementation
51  * from RS_Undo.
52  */
53 void RS_Document::removeUndoable(RS_Undoable * u)
54 {
55         if (u != NULL && u->undoRtti() == RS2::UndoableEntity)
56         {
57                 removeEntity((RS_Entity *)u);
58         }
59 }
60
61 /**
62  * @return Currently active drawing pen.
63  */
64 RS_Pen RS_Document::getActivePen() const
65 {
66         return activePen;
67 }
68
69 /**
70  * Sets the currently active drawing pen to p.
71  */
72 void RS_Document::setActivePen(RS_Pen p)
73 {
74         activePen = p;
75 }
76
77 /**
78  * @return File name of the document currently loaded.
79  * Note, that the default file name is empty.
80  */
81 QString RS_Document::getFilename() const
82 {
83         return filename;
84 }
85
86 /**
87  * Sets file name for the document currently loaded.
88  */
89 void RS_Document::setFilename(const QString & fn)
90 {
91         filename = fn;
92 }
93
94 /**
95  * Sets the documents modified status to 'm'.
96  */
97 void RS_Document::setModified(bool m)
98 {
99         //std::cout << "RS_Document::setModified: %d" << (int)m << std::endl;
100         modified = m;
101 }
102
103 /**
104  * @retval true The document has been modified since it was last saved.
105  * @retval false The document has not been modified since it was last saved.
106  */
107 bool RS_Document::isModified() const
108 {
109         return modified;
110 }
111
112 /**
113  * Overwritten to set modified flag before starting an undo cycle.
114  */
115 void RS_Document::startUndoCycle()
116 {
117         setModified(true);
118         RS_Undo::startUndoCycle();
119 }