~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/lib/engine/rs_document.h

  • Committer: Scott Howard
  • Date: 2014-02-21 19:07:55 UTC
  • Revision ID: showard@debian.org-20140221190755-csjax9wb146hgdq4
first commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** This file is part of the LibreCAD project, a 2D CAD program
 
4
**
 
5
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
 
6
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
 
7
**
 
8
**
 
9
** This file may be distributed and/or modified under the terms of the
 
10
** GNU General Public License version 2 as published by the Free Software 
 
11
** Foundation and appearing in the file gpl-2.0.txt included in the
 
12
** packaging of this file.
 
13
**
 
14
** This program is distributed in the hope that it will be useful,
 
15
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
** GNU General Public License for more details.
 
18
** 
 
19
** You should have received a copy of the GNU General Public License
 
20
** along with this program; if not, write to the Free Software
 
21
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
22
**
 
23
** This copyright notice MUST APPEAR in all copies of the script!  
 
24
**
 
25
**********************************************************************/
 
26
 
 
27
 
 
28
#ifndef RS_DOCUMENT_H
 
29
#define RS_DOCUMENT_H
 
30
 
 
31
#include "rs_layerlist.h"
 
32
#include "rs_entitycontainer.h"
 
33
#include "rs_undo.h"
 
34
 
 
35
class RS_BlockList;
 
36
 
 
37
/**
 
38
 * Base class for documents. Documents can be either graphics or 
 
39
 * blocks and are typically shown in graphic views. Documents hold
 
40
 * an active pen for drawing in the Document, a file name and they
 
41
 * know whether they have been modified or not.
 
42
 *
 
43
 * @author Andrew Mustun
 
44
 */
 
45
class RS_Document : public RS_EntityContainer,
 
46
    public RS_Undo {
 
47
public:
 
48
    RS_Document(RS_EntityContainer* parent=NULL);
 
49
    virtual ~RS_Document(){}
 
50
 
 
51
    virtual RS_LayerList* getLayerList() = 0;
 
52
    virtual RS_BlockList* getBlockList() = 0;
 
53
 
 
54
    virtual void newDoc() = 0;
 
55
    virtual bool save(bool isAutoSave = false) = 0;
 
56
    virtual bool saveAs(const QString &filename, RS2::FormatType type, bool force) = 0;
 
57
    virtual bool open(const QString &filename, RS2::FormatType type) = 0;
 
58
    virtual bool loadTemplate(const QString &filename, RS2::FormatType type) = 0;
 
59
 
 
60
 
 
61
    /**
 
62
     * @return true for all document entities (e.g. Graphics or Blocks).
 
63
     */
 
64
    virtual bool isDocument() const {
 
65
        return true;
 
66
    }
 
67
 
 
68
    /**
 
69
     * Removes an entity from the entiy container. Implementation
 
70
     * from RS_Undo.
 
71
     */
 
72
    virtual void removeUndoable(RS_Undoable* u) {
 
73
        if (u!=NULL && u->undoRtti()==RS2::UndoableEntity) {
 
74
            removeEntity((RS_Entity*)u);
 
75
        }
 
76
    }
 
77
 
 
78
    /**
 
79
     * @return Currently active drawing pen.
 
80
     */
 
81
    RS_Pen getActivePen() const {
 
82
        return activePen;
 
83
    }
 
84
 
 
85
    /**
 
86
     * Sets the currently active drawing pen to p.
 
87
     */
 
88
    void setActivePen(RS_Pen p) {
 
89
        activePen = p;
 
90
    }
 
91
 
 
92
    /**
 
93
     * @return File name of the document currently loaded.
 
94
     * Note, that the default file name is empty.
 
95
     */
 
96
    QString getFilename() const {
 
97
        return filename;
 
98
    }
 
99
        
 
100
    /**
 
101
     * @return Auto-save file name of the document currently loaded.
 
102
     */
 
103
    QString getAutoSaveFilename() const {
 
104
        return autosaveFilename;
 
105
    }
 
106
        
 
107
    /**
 
108
     * Sets file name for the document currently loaded.
 
109
     */
 
110
    void setFilename(const QString& fn) {
 
111
        filename = fn;
 
112
    }
 
113
 
 
114
        /**
 
115
         * Sets the documents modified status to 'm'.
 
116
         */
 
117
        virtual void setModified(bool m) {
 
118
                //std::cout << "RS_Document::setModified: %d" << (int)m << std::endl;
 
119
                modified = m;
 
120
        }
 
121
        
 
122
        /**
 
123
         * @retval true The document has been modified since it was last saved.
 
124
         * @retval false The document has not been modified since it was last saved.
 
125
         */
 
126
    virtual bool isModified() const {
 
127
        return modified;
 
128
    }
 
129
        
 
130
        /**
 
131
         * Overwritten to set modified flag before starting an undo cycle.
 
132
         */
 
133
    virtual void startUndoCycle() {
 
134
                setModified(true);
 
135
                RS_Undo::startUndoCycle();
 
136
        }
 
137
 
 
138
    void setGraphicView(RS_GraphicView * g) {gv = g;}
 
139
    RS_GraphicView* getGraphicView() {return gv;}
 
140
 
 
141
protected:
 
142
    /** Flag set if the document was modified and not yet saved. */
 
143
    bool modified;
 
144
    /** Active pen. */
 
145
    RS_Pen activePen;
 
146
    /** File name of the document or empty for a new document. */
 
147
    QString filename;
 
148
        /** Auto-save file name of document. */
 
149
        QString autosaveFilename;
 
150
        /** Format type */
 
151
        RS2::FormatType formatType;
 
152
    RS_GraphicView * gv;//used to read/save current view
 
153
 
 
154
};
 
155
 
 
156
 
 
157
#endif