~librecad-dev/librecad/librecad

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
/****************************************************************************
**
** This file is part of the LibreCAD project, a 2D CAD program
**
** Copyright (C) 2010 R. van Twisk (librecad@rvt.dds.nl)
** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
**
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file gpl-2.0.txt included in the
** packaging of this file.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
**
** This copyright notice MUST APPEAR in all copies of the script!
**
**********************************************************************/


#ifndef RS_GRAPHIC_H
#define RS_GRAPHIC_H

#include <QDateTime>
#include "rs_blocklist.h"
#include "rs_layerlist.h"
#include "rs_variabledict.h"
#include "rs_document.h"
#include "rs_units.h"

class RS_VariableDict;
class QG_LayerWidget;

/**
 * A graphic document which can contain entities layers and blocks.
 *
 * @author Andrew Mustun
 */
class RS_Graphic : public RS_Document {
public:
    RS_Graphic(RS_EntityContainer* parent=NULL);
    virtual ~RS_Graphic();

    //virtual RS_Entity* clone() {
    //	return new RS_Graphic(*this);
    //}

    /** @return RS2::EntityGraphic */
    virtual RS2::EntityType rtti() const {
        return RS2::EntityGraphic;
    }

    virtual unsigned long int countLayerEntities(RS_Layer* layer);

    virtual RS_LayerList* getLayerList() {
        return &layerList;
    }
    virtual RS_BlockList* getBlockList() {
        return &blockList;
    }

    virtual void newDoc();
    virtual bool save(bool isAutoSave = false);
    virtual bool saveAs(const QString& filename, RS2::FormatType type, bool force = false);
    virtual bool open(const QString& filename, RS2::FormatType type);
    bool loadTemplate(const QString &filename, RS2::FormatType type);

        // Wrappers for Layer functions:
    void clearLayers() {
                layerList.clear();
        }
    unsigned countLayers() const {
        return layerList.count();
    }
    RS_Layer* layerAt(unsigned i) {
        return layerList.at(i);
    }
    void activateLayer(const QString& name) {
                layerList.activate(name);
        }
    void activateLayer(RS_Layer* layer) {
                layerList.activate(layer);
        }
    RS_Layer* getActiveLayer() {
        return layerList.getActive();
    }
    virtual void addLayer(RS_Layer* layer) {
                layerList.add(layer);
        }
    virtual void addEntity(RS_Entity* entity);
    virtual void removeLayer(RS_Layer* layer);
    virtual void editLayer(RS_Layer* layer, const RS_Layer& source) {
                layerList.edit(layer, source);
        }
    RS_Layer* findLayer(const QString& name) {
                return layerList.find(name);
        }
    void toggleLayer(const QString& name) {
                layerList.toggle(name);
        }
    void toggleLayer(RS_Layer* layer) {
                layerList.toggle(layer);
        }
    void toggleLayerLock(RS_Layer* layer) {
                layerList.toggleLock(layer);
        }
    void toggleLayerPrint(RS_Layer* layer) {
                layerList.togglePrint(layer);
        }
    void freezeAllLayers(bool freeze) {
                layerList.freezeAll(freeze);
        }

    void addLayerListListener(RS_LayerListListener* listener) {
                layerList.addListener(listener);
        }
    void removeLayerListListener(RS_LayerListListener* listener) {
                layerList.removeListener(listener);
        }


        // Wrapper for block functions:
    void clearBlocks() {
                blockList.clear();
        }
    unsigned countBlocks() {
        return blockList.count();
    }
    RS_Block* blockAt(unsigned i) {
        return blockList.at(i);
    }
    void activateBlock(const QString& name) {
                blockList.activate(name);
        }
    void activateBlock(RS_Block* block) {
                blockList.activate(block);
        }
    RS_Block* getActiveBlock() {
        return blockList.getActive();
    }
    virtual bool addBlock(RS_Block* block, bool notify=true) {
                return blockList.add(block, notify);
        }
    virtual void addBlockNotification() {
                blockList.addNotification();
        }
    virtual void removeBlock(RS_Block* block) {
                blockList.remove(block);
        }
    RS_Block* findBlock(const QString& name) {
                return blockList.find(name);
        }
    QString newBlockName() {
                return blockList.newName();
        }
    void toggleBlock(const QString& name) {
                blockList.toggle(name);
        }
    void toggleBlock(RS_Block* block) {
                blockList.toggle(block);
        }
    void freezeAllBlocks(bool freeze) {
                blockList.freezeAll(freeze);
        }
    void addBlockListListener(RS_BlockListListener* listener) {
                blockList.addListener(listener);
        }
    void removeBlockListListener(RS_BlockListListener* listener) {
                blockList.removeListener(listener);
        }

        // Wrappers for variable functions:
    void clearVariables() {
                variableDict.clear();
        }
    int countVariables() {
                return variableDict.count();
    }

    void addVariable(const QString& key, const RS_Vector& value, int code) {
                variableDict.add(key, value, code);
        }
    void addVariable(const QString& key, const QString& value, int code) {
                variableDict.add(key, value, code);
        }
    void addVariable(const QString& key, int value, int code) {
                variableDict.add(key, value, code);
        }
    void addVariable(const QString& key, double value, int code) {
                variableDict.add(key, value, code);
        }

    RS_Vector getVariableVector(const QString& key, const RS_Vector& def) {
                return variableDict.getVector(key, def);
        }
    QString getVariableString(const QString& key, const QString& def) {
                return variableDict.getString(key, def);
        }
    int getVariableInt(const QString& key, int def) {
                return variableDict.getInt(key, def);
        }
    double getVariableDouble(const QString& key, double def) {
                return variableDict.getDouble(key, def);
        }

    void removeVariable(const QString& key) {
                variableDict.remove(key);
        }

        QHash<QString, RS_Variable>& getVariableDict() {
                return variableDict.getVariableDict();
        }

        RS2::LinearFormat getLinearFormat();
        int getLinearPrecision();
        RS2::AngleFormat getAngleFormat();
        int getAnglePrecision();

        RS_Vector getPaperSize();
        void setPaperSize(const RS_Vector& s);

        RS_Vector getPaperInsertionBase();
        void setPaperInsertionBase(const RS_Vector& p);

        RS2::PaperFormat getPaperFormat(bool* landscape);
        void setPaperFormat(RS2::PaperFormat f, bool landscape);

        double getPaperScale();
        void setPaperScale(double s);

    virtual void setUnit(RS2::Unit u);
    virtual RS2::Unit getUnit();

        bool isGridOn();
        void setGridOn(bool on);
        bool isIsometricGrid();
        void setIsometricGrid(bool on);
        void setCrosshairType(RS2::CrosshairType chType);
        RS2::CrosshairType getCrosshairType();

        bool isDraftOn();
        void setDraftOn(bool on);

    /** Sets the unit of this graphic's dimensions to 'u' */
    /*virtual void setDimensionUnit(RS2::Unit u) {
                addVariable("$INSUNITS", (int)u, 70);
        dimensionUnit = u;
    }*/

    /** Gets the unit of this graphic's dimension */
    /*virtual RS2::Unit getDimensionUnit() {
        return dimensionUnit;
    }*/

        void centerToPage();
        bool fitToPage();

        /**
         * @retval true The document has been modified since it was last saved.
         * @retval false The document has not been modified since it was last saved.
         */
    virtual bool isModified() const {
        return modified || layerList.isModified() || blockList.isModified();
    }

        /**
         * Sets the documents modified status to 'm'.
         */
        virtual void setModified(bool m) {
                modified = m;
                layerList.setModified(m);
                blockList.setModified(m);
        }
virtual QDateTime getModifyTime(void){
            return modifiedTime;
        }

        //if set to true, will refuse to modify paper scale
        void setPaperScaleFixed(bool fixed)
        {
            paperScaleFixed=fixed;
        }
        bool getPaperScaleFixed()
        {
            return paperScaleFixed;
        }

    friend std::ostream& operator << (std::ostream& os, RS_Graphic& g);


private:

        bool BackupDrawingFile(const QString &filename);
        QDateTime modifiedTime;
        QString currentFileName; //keep a copy of filename for the modifiedTime

        RS_LayerList layerList;
        RS_BlockList blockList;
        RS_VariableDict variableDict;
        RS2::CrosshairType crosshairType; //corss hair type used by isometric grid
        //if set to true, will refuse to modify paper scale
        bool paperScaleFixed;
};


#endif