]> Shamusworld >> Repos - architektonas/blob - src/base/rs_document.cpp
8279b38457f41c491cc970145977b0f499eb42f4
[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 #include "rs_debug.h"
20
21 /**
22  * Constructor.
23  *
24  * @param parent Parent of the document. Often that's NULL but
25  *        for blocks it's the blocklist.
26  */
27 RS_Document::RS_Document(RS_EntityContainer * parent):
28         RS_EntityContainer(parent), RS_Undo()
29 {
30         RS_DEBUG->print("RS_Document::RS_Document() ");
31
32         filename = "";
33         formatType = RS2::FormatUnknown;
34         setModified(false);
35         RS_Color col(RS2::FlagByLayer);
36         activePen = RS_Pen(col, RS2::WidthByLayer, RS2::LineByLayer);
37 }
38
39 RS_Document::~RS_Document()
40 {
41 }
42
43 /**
44  * @return true for all document entities (e.g. Graphics or Blocks).
45  */
46 bool RS_Document::isDocument() const
47 {
48         return true;
49 }
50
51 /**
52  * Removes an entity from the entiy container. Implementation
53  * from RS_Undo.
54  */
55 void RS_Document::removeUndoable(RS_Undoable * u)
56 {
57         if (u != NULL && u->undoRtti() == RS2::UndoableEntity)
58         {
59                 removeEntity((RS_Entity *)u);
60         }
61 }
62
63 /**
64  * @return Currently active drawing pen.
65  */
66 RS_Pen RS_Document::getActivePen() const
67 {
68         return activePen;
69 }
70
71 /**
72  * Sets the currently active drawing pen to p.
73  */
74 void RS_Document::setActivePen(RS_Pen p)
75 {
76         activePen = p;
77 }
78
79 /**
80  * @return File name of the document currently loaded.
81  * Note, that the default file name is empty.
82  */
83 QString RS_Document::getFilename() const
84 {
85         return filename;
86 }
87
88 /**
89  * Sets file name for the document currently loaded.
90  */
91 void RS_Document::setFilename(const QString & fn)
92 {
93         filename = fn;
94 }
95
96 /**
97  * Sets the documents modified status to 'm'.
98  */
99 void RS_Document::setModified(bool m)
100 {
101         //std::cout << "RS_Document::setModified: %d" << (int)m << std::endl;
102         modified = m;
103 }
104
105 /**
106  * @retval true The document has been modified since it was last saved.
107  * @retval false The document has not been modified since it was last saved.
108  */
109 bool RS_Document::isModified() const
110 {
111         return modified;
112 }
113
114 /**
115  * Overwritten to set modified flag before starting an undo cycle.
116  */
117 void RS_Document::startUndoCycle()
118 {
119         setModified(true);
120         RS_Undo::startUndoCycle();
121 }