~librecad-dev/librecad/librecad

« back to all changes in this revision

Viewing changes to librecad/src/plugins/document_interface.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) 2011 Rallaz (rallazz@gmail.com)
 
7
**
 
8
**
 
9
** This file is free software; you can redistribute it and/or modify
 
10
** it under the terms of the GNU General Public License as published by
 
11
** the Free Software Foundation; either version 2 of the License, or
 
12
** (at your option) any later version.
 
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
#ifndef DOCUMENT_INTERFACE_H
 
27
#define DOCUMENT_INTERFACE_H
 
28
 
 
29
#include <QPointF>
 
30
#include <QHash>
 
31
#include <QString>
 
32
#include <QColor>
 
33
 
 
34
namespace DPI {
 
35
    //! Vertical alignments.
 
36
    enum VAlign {
 
37
        VAlignTop,      /*!< Top. */
 
38
        VAlignMiddle,   /*!< Middle */
 
39
        VAlignBottom    /*!< Bottom */
 
40
    };
 
41
 
 
42
    //! Horizontal alignments.
 
43
    enum HAlign {
 
44
        HAlignLeft,     /*!< Left */
 
45
        HAlignCenter,   /*!< Centered */
 
46
        HAlignRight     /*!< Right */
 
47
    };
 
48
 
 
49
 
 
50
   //! Entity's type.
 
51
    enum ETYPE {
 
52
        POINT,
 
53
        LINE,
 
54
        CONSTRUCTIONLINE,
 
55
        CIRCLE,
 
56
        ARC,
 
57
        ELLIPSE,
 
58
        IMAGE,
 
59
        OVERLAYBOX,
 
60
        SOLID,/*end atomicEntity, start entityContainer*/
 
61
        MTEXT,
 
62
        TEXT,
 
63
        INSERT,
 
64
        POLYLINE,
 
65
        SPLINE,
 
66
        HATCH,
 
67
        DIMLEADER,
 
68
        DIMALIGNED,
 
69
        DIMLINEAR,
 
70
        DIMRADIAL,
 
71
        DIMDIAMETRIC,
 
72
        DIMANGULAR,
 
73
        UNKNOWN
 
74
    };
 
75
 
 
76
    //! Entity's data (dxf like).
 
77
 
 
78
    enum EDATA {
 
79
        ETYPE=0,        /*!< enum: entity type */
 
80
        TEXTCONTENT=1,  /*!< QString: text string */
 
81
        BLKNAME=2,      /*!< QString: block name */
 
82
        EID=5,          /*!< qulonglong: entity identifier */
 
83
        LTYPE=6,        /*!< QString: line type */
 
84
        TXTSTYLE=7,     /*!< QString: text style */
 
85
        LAYER=8,        /*!< QString: layer */
 
86
        STARTX=10,      /*!< double: start x coordinate */
 
87
        ENDX=11,        /*!< double: end x coordinate, or U-vector for images */
 
88
        VVECTORX=12,    /*!< double: V-vector for images, x coordinate */
 
89
        SIZEU=13,       /*!< double: image U size (width) */
 
90
        STARTY=20,      /*!< double: start y coordinate */
 
91
        ENDY=21,        /*!< double: end y coordinate, or U-vector for images */
 
92
        VVECTORY=22,    /*!< double: V-vector for images, y coordinate */
 
93
        SIZEV=23,       /*!< double: image V size (height) */
 
94
        STARTZ=30,      /*!< double: start z coordinate always 0 */
 
95
        ENDZ=30,        /*!< double: end z coordinate always 0 */
 
96
        LWIDTH=38,      /*!< QString: line width */  //verify number
 
97
        RADIUS=39,      /*!< double: radius */
 
98
        HEIGHT=40,      /*!< double: text heigt or ellipse ratio*/
 
99
        XSCALE=41,      /*!< double: x insert scale */
 
100
        YSCALE=42,      /*!< double: y insert scale */
 
101
        ZSCALE=43,      /*!< double: z insert scale always 1? */
 
102
        LTSCALE=48,     /*!< line type scale (not in LibreCAD) */
 
103
        STARTANGLE=50,  /*!< double: arc start angle or rotation angle for insert and text */
 
104
        ENDANGLE=51,    /*!< double: arc end angle */
 
105
        VISIBLE=60,     /*!< int: 1 visible, 0 invisible (reversed from dxf spec, but more logic*/
 
106
        COLOR=62,       /*!< QColor: entity color */
 
107
        CLOSEPOLY=70,   /*!< int: closed polyline 0=open, 1=closed */
 
108
        TXTALIGNH=72,   /*!< enum: horizontal alignment for text */
 
109
        TXTALIGNV=73,   /*!< enum: vertical alignment for text */
 
110
        REVERSED=291 /*!< bool: true if arc is reversed (clockwise) */
 
111
    };
 
112
 
 
113
    enum LineWidth {
 
114
        Width00 = 0,       /**< Width 1.  (0.00mm) */
 
115
        Width01 = 5,       /**< Width 2.  (0.05mm) */
 
116
        Width02 = 9,       /**< Width 3.  (0.09mm) */
 
117
        Width03 = 13,      /**< Width 4.  (0.13mm) */
 
118
        Width04 = 15,      /**< Width 5.  (0.15mm) */
 
119
        Width05 = 18,      /**< Width 6.  (0.18mm) */
 
120
        Width06 = 20,      /**< Width 7.  (0.20mm) */
 
121
        Width07 = 25,      /**< Width 8.  (0.25mm) */
 
122
        Width08 = 30,      /**< Width 9.  (0.30mm) */
 
123
        Width09 = 35,      /**< Width 10. (0.35mm) */
 
124
        Width10 = 40,      /**< Width 11. (0.40mm) */
 
125
        Width11 = 50,      /**< Width 12. (0.50mm) */
 
126
        Width12 = 53,      /**< Width 13. (0.53mm) */
 
127
        Width13 = 60,      /**< Width 14. (0.60mm) */
 
128
        Width14 = 70,      /**< Width 15. (0.70mm) */
 
129
        Width15 = 80,      /**< Width 16. (0.80mm) */
 
130
        Width16 = 90,      /**< Width 17. (0.90mm) */
 
131
        Width17 = 100,     /**< Width 18. (1.00mm) */
 
132
        Width18 = 106,     /**< Width 19. (1.06mm) */
 
133
        Width19 = 120,     /**< Width 20. (1.20mm) */
 
134
        Width20 = 140,     /**< Width 21. (1.40mm) */
 
135
        Width21 = 158,     /**< Width 22. (1.58mm) */
 
136
        Width22 = 200,     /**< Width 23. (2.00mm) */
 
137
        Width23 = 211,     /**< Width 24. (2.11mm) */
 
138
        WidthByLayer = -1, /**< Line width defined by layer not entity. */
 
139
        WidthByBlock = -2, /**< Line width defined by block not entity. */
 
140
        WidthDefault = -3  /**< Line width defaults to the predefined line width. */
 
141
    };
 
142
 
 
143
    enum LineType {
 
144
        NoPen = 0,            /**< No line at all. */
 
145
        SolidLine = 1,        /**< Normal line. */
 
146
        DotLine = 2,          /**< Dotted line. */
 
147
        DotLine2 = 3,         /**< Dotted line small. */
 
148
        DotLineX2 = 4,        /**< Dotted line large. */
 
149
        DashLine = 5,         /**< Dashed line. */
 
150
        DashLine2 = 6,        /**< Dashed line small. */
 
151
        DashLineX2 = 7,       /**< Dashed line large. */
 
152
        DashDotLine = 8,      /**< Alternate dots and dashes. */
 
153
        DashDotLine2 = 9,     /**< Alternate dots and dashes small. */
 
154
        DashDotLineX2 = 10,   /**< Alternate dots and dashes large. */
 
155
        DivideLine = 11,      /**< dash, dot, dot. */
 
156
        DivideLine2 = 12,     /**< dash, dot, dot small. */
 
157
        DivideLineX2 = 13,    /**< dash, dot, dot large. */
 
158
        CenterLine = 14,      /**< dash, small dash. */
 
159
        CenterLine2 = 15,     /**< dash, small dash small. */
 
160
        CenterLineX2 = 16,    /**< dash, small dash large. */
 
161
        BorderLine = 17,      /**< dash, dash, dot. */
 
162
        BorderLine2 = 18,     /**< dash, dash, dot small. */
 
163
        BorderLineX2 = 19,    /**< dash, dash, dot large. */
 
164
        LineByLayer = -1,     /**< Line type defined by layer not entity */
 
165
        LineByBlock = -2      /**< Line type defined by block not entity */
 
166
    };
 
167
 
 
168
}
 
169
 
 
170
class Plug_VertexData
 
171
{
 
172
public:
 
173
    Plug_VertexData(QPointF p, double b){
 
174
        point = p;
 
175
        bulge = b;
 
176
    }
 
177
    QPointF point;
 
178
    double bulge;
 
179
};
 
180
 
 
181
//! Wrapper for acces entities from plugins.
 
182
 /*!
 
183
 *  Wrapper class for create, acces and modify entities from plugins.
 
184
 *  TODO: terminate acces function -> getData()
 
185
 *        terminate implementation of modify function -> updateData()
 
186
 *        terminate implementation of create function (ctor called from document)
 
187
 *           can't create entities:
 
188
 *           - atomic = CONSTRUCTIONLINE, OVERLAYBOX, SOLID,
 
189
 *           - container = INSERT, POLYLINE, SPLINE, HATCH, DIMLEADER,
 
190
 *             DIMALIGNED, DIMLINEAR, DIMRADIAL, DIMDIAMETRIC, DIMANGULAR,
 
191
 *        verify destructor if needed or not to delete entity
 
192
 * @author Rallaz
 
193
 */
 
194
class Plug_Entity
 
195
{
 
196
public:
 
197
    virtual ~Plug_Entity() {}
 
198
 
 
199
    //! Obtain the entity data.
 
200
    /*!
 
201
    * The data is a QHash with the EDATA keys relevant to the type of entity
 
202
    *  \param data pointer to a QHash<int, QVariant> to store the entity data.
 
203
    */
 
204
    virtual void getData(QHash<int, QVariant> *data) = 0;
 
205
 
 
206
    //! Update the entity data.
 
207
    /*!
 
208
    * The data is a QHash with the EDATA keys relevant to the type of entity
 
209
    *  \param data pointer to a QHash<int, QVariant> with the entity data.
 
210
    */
 
211
    virtual void updateData(QHash<int, QVariant> *data) = 0;
 
212
 
 
213
    //! Obtain the polyline list of vertex.
 
214
    /*!
 
215
    * The data is a QList to store a Plug_VertexData for heach vertex form the polyline
 
216
    *  \param data pointer to a QList<Plug_VertexData> to store the vertex list.
 
217
    */
 
218
    virtual void getPolylineData(QList<Plug_VertexData> *data) = 0;
 
219
 
 
220
    //! Update the polyline list of vertex.
 
221
    /*!
 
222
    * The data is a QList of Plug_VertexData with the coordinates of each vertex to the
 
223
    * polyline the cuurent vertex are removed and replaced for the new list.
 
224
    *  \param data pointer to a QList<Plug_VertexData> with the coordinates vertex's.
 
225
    */
 
226
    virtual void updatePolylineData(QList<Plug_VertexData> *data) = 0;
 
227
 
 
228
    //! Move the entity.
 
229
    /*!
 
230
    *  \param offset move the entity by the given QPointF.
 
231
    */
 
232
    virtual void move(QPointF offset) = 0;
 
233
 
 
234
    //! rotate the entity.
 
235
    /*!
 
236
    *  \param center center of rotation.
 
237
    *  \param angle angle to rotate.
 
238
    */
 
239
    virtual void rotate(QPointF center, double angle) = 0;
 
240
 
 
241
    //! Scale the entity.
 
242
    /*!
 
243
    *  \param center base point for scale.
 
244
    *  \param factor scale factor.
 
245
    */
 
246
    virtual void scale(QPointF center, QPointF factor) = 0;
 
247
 
 
248
};
 
249
 
 
250
//! Interface for comunicate plugins.
 
251
 /*!
 
252
 * Class for comunicate plugins with document (drawing).
 
253
 * entities whitout add*() function:
 
254
 * atomic = CONSTRUCTIONLINE, OVERLAYBOX, SOLID,
 
255
 * container = INSERT, POLYLINE, SPLINE, HATCH, DIMLEADER,
 
256
 * DIMALIGNED, DIMLINEAR, DIMRADIAL, DIMDIAMETRIC, DIMANGULAR,
 
257
 * TODO: memory assignation and cleanup in plugin
 
258
 *   added----    implementation of function -> deleteEntity()
 
259
 * @author Rallaz
 
260
 */
 
261
class Document_Interface
 
262
{
 
263
public:
 
264
    virtual ~Document_Interface() {}
 
265
    //! Force to update the graphic view.
 
266
    /*! Force to update the graphic view.
 
267
    */
 
268
    virtual void updateView() = 0;
 
269
 
 
270
    //! Add point entity to current document.
 
271
    /*! Add point entity to current document with current attributes.
 
272
    *  \param start point coordinate.
 
273
    */
 
274
    virtual void addPoint(QPointF *start) = 0;
 
275
 
 
276
    //! Add line entity to current document.
 
277
    /*! Add line entity to current document with current attributes.
 
278
    *  \param start start point coordinate.
 
279
    *  \param end end point coordinate.
 
280
    */
 
281
    virtual void addLine(QPointF *start, QPointF *end) = 0;
 
282
 
 
283
    //! Add text entity to current document.
 
284
    /*! Add text entity to current document with current attributes
 
285
    *  \param txt a QString with text content
 
286
    *  \param sty a QString with text style name
 
287
    *  \param start insertion point coordinate
 
288
    *  \param height height of text
 
289
    *  \param angle rotation angle of text
 
290
    *  \param ha horizontal alignement of text
 
291
    *  \param va vertical alignement of text
 
292
    */
 
293
    virtual void addText(QString txt, QString sty, QPointF *start, double height,
 
294
                double angle, DPI::HAlign ha,  DPI::VAlign va) = 0;
 
295
 
 
296
    //! Add circle entity to current document.
 
297
    /*! Add circle entity to current document with current attributes.
 
298
    *  \param start center point coordinate.
 
299
    *  \param radius radius for circle.
 
300
    */
 
301
    virtual void addCircle(QPointF *start, qreal radius) = 0;
 
302
 
 
303
    //! Add arc entity to current document.
 
304
    /*! Add arc of circumference entity to current document with current attributes.
 
305
    *  \param start center point coordinate.
 
306
    *  \param radius radius for circle.
 
307
    */
 
308
    virtual void addArc(QPointF *start, qreal radius, qreal a1, qreal a2) = 0;
 
309
 
 
310
    //! Add ellipse entity to current document.
 
311
    /*! Add ellipse entity to current document with current attributes.
 
312
    *  \param start center point coordinate.
 
313
    *  \param radius radius for arc.
 
314
    */
 
315
    virtual void addEllipse(QPointF *start, QPointF *end, qreal ratio, qreal a1, qreal a2) = 0;
 
316
 
 
317
    //! Add image entity to current document.
 
318
    /*! Add image entity to current document with current attributes.
 
319
    *  \param start start point coordinate.
 
320
    *  \param end end point coordinate.
 
321
    */
 
322
    virtual void addImage(int handle, QPointF *start, QPointF *uvr, QPointF *vvr,
 
323
                  int w, int h, QString name, int br, int con, int fade) = 0;
 
324
 
 
325
    //! Add insert entity to current document.
 
326
    /*! Add a block insert entity to current document with current attributes.
 
327
    *  \param name name of block to insert.
 
328
    *  \param ins insertion point coordinate.
 
329
    *  \param scale x,y scale factor.
 
330
    *  \param rot rotation angle.
 
331
    */
 
332
    virtual void addInsert(QString name, QPointF ins, QPointF scale, qreal rot) = 0;
 
333
 
 
334
    //! Add block definition from disk to current document.
 
335
    /*! Add block definition from disk to current document.
 
336
    *  \param fullName path+name of dxf file to add.
 
337
    *  \return name of created block or NULL if fail.
 
338
    */
 
339
    virtual QString addBlockfromFromdisk(QString fullName) = 0;
 
340
 
 
341
    //! Add a entity to current document.
 
342
    /*! Add a entity to current document with the data sets with Plug_Entity.updateData().
 
343
    *  \param handle a pointer to Plug_Entity.
 
344
    */
 
345
    virtual void addEntity(Plug_Entity *handle) = 0;
 
346
 
 
347
    //! Create a new Plug_Entity.
 
348
    /*! Create a new Plug_Entity of type ETYPE with default data.
 
349
    * sets the data with Plug_Entity.updateData().
 
350
    * if fail (unknoun or unhandled entity) return NULL
 
351
    *  \param type an DPI::ETYPE type.
 
352
    *  \return handle to pointer of Plug_Entity with type DPI::ETYPE or NULL if fail.
 
353
    */
 
354
    virtual Plug_Entity *newEntity(enum DPI::ETYPE type) = 0;
 
355
 
 
356
    //! Remove a Entity.
 
357
    /*! Remove a entity from current drawing.
 
358
    *  \param ent handle to pointer of Plug_Entity.
 
359
    */
 
360
    virtual void removeEntity(Plug_Entity *ent) = 0;
 
361
 
 
362
    //! Set the current layer in current document.
 
363
    /*! Set the current layer in current document, if not exist create it.
 
364
    *  \param name a QString with the name of the layer.
 
365
    */
 
366
    virtual void setLayer(QString name) = 0;
 
367
 
 
368
    //! Get the current layer in current document.
 
369
    /*! Get the current layer in current document.
 
370
    *  \return The name of the current layer.
 
371
    */
 
372
    virtual QString getCurrentLayer() = 0;
 
373
 
 
374
    //! Gets the layers list in current document.
 
375
    /*! Gets the list of names of all layers in current document.
 
376
    *  \return A list with the name of all layers in document.
 
377
    */
 
378
    virtual QStringList getAllLayer() = 0;
 
379
 
 
380
    //! Gets the blocks list in current document.
 
381
    /*! Gets the list of names of all blocks in current document.
 
382
    *  \return A list with the name of all blocks in document.
 
383
    */
 
384
    virtual QStringList getAllBlocks() = 0;
 
385
 
 
386
    //! Delete a layer in current document.
 
387
    /*! Delete the layer "name" in current document if it exist.
 
388
    *  \return The name of the current layer.
 
389
    */
 
390
    virtual bool deleteLayer(QString name) = 0;
 
391
 
 
392
    virtual void getCurrentLayerProperties(QColor *c, DPI::LineWidth *w, DPI::LineType *t) = 0;
 
393
    virtual void getCurrentLayerProperties(QColor *c, QString *w, QString *t) = 0;
 
394
    virtual void setCurrentLayerProperties(QColor c, DPI::LineWidth w, DPI::LineType t) = 0;
 
395
    virtual void setCurrentLayerProperties(QColor c, QString w, QString t) = 0;
 
396
 
 
397
    //! Gets a point.
 
398
    /*! Prompt message or an default message to the user asking for a point.
 
399
    *   If base is present draw a line from base to cursor position.
 
400
    * \param point a pointer to QPointF to store the obtained point.
 
401
    * \param mesage an optional QString with prompt message.
 
402
    * \param base visual helper point, if present.
 
403
    * \return true if succes.
 
404
    * \return false if fail, i.e. user cancel.
 
405
    */
 
406
    virtual bool getPoint(QPointF *point, const QString& mesage = "", QPointF *base = 0) = 0;
 
407
 
 
408
    //! Select a entity.
 
409
    /*! Prompt message or a default message to the user asking for a sigle selection.
 
410
    * You can delete the Plug_Entity wen no more needed.
 
411
    * \param mesage an optional QString with prompt message.
 
412
    * \return a Plug_Entity handle the selected entity or NULL.
 
413
    */
 
414
    virtual Plug_Entity *getEnt(const QString& mesage = "") = 0;
 
415
 
 
416
    //! Gets a entities selection.
 
417
    /*! Prompt message or an default message to the user asking for a selection.
 
418
    * You can delete all, the Plug_Entity and the returned QList wen no more needed.
 
419
    * \param sel a QList of poiters to Plug_Entity handled the selected entities.
 
420
    * \param mesage an optional QString with prompt message.
 
421
    * \return true if succes.
 
422
    * \return false if fail, i.e. user cancel.
 
423
    */
 
424
    virtual bool getSelect(QList<Plug_Entity *> *sel, const QString& mesage = "") = 0;
 
425
 
 
426
    //! Gets all entities in document.
 
427
    /*! You can delete all, the Plug_Entity and the returned QList wen no more needed.
 
428
    * \param sel a QList of poiters to Plug_Entity handled the selected entities.
 
429
    * \param visible default fo false, do not select entities in hidden layers.
 
430
    * \return true if succes.
 
431
    * \return false if fail, i.e. user cancel.
 
432
    */
 
433
    virtual bool getAllEntities(QList<Plug_Entity *> *sel, bool visible = false) = 0;
 
434
 
 
435
    virtual bool getVariableInt(const QString& key, int *num) = 0;
 
436
    virtual bool getVariableDouble(const QString& key, double *num) = 0;
 
437
    virtual bool addVariable(const QString& key, int value, int code=70) = 0;
 
438
    virtual bool addVariable(const QString& key, double value, int code=40) = 0;
 
439
 
 
440
    virtual bool getInt(int *num, const QString& mesage = "", const QString& title = "") = 0;
 
441
    virtual bool getReal(qreal *num, const QString& mesage = "", const QString& title = "") = 0;
 
442
    virtual bool getString(QString *txt, const QString& mesage = "", const QString& title = "") = 0;
 
443
 
 
444
    //! Convert real to string.
 
445
    /*! Convert a real number to string using indicated units format & precision. If omitted
 
446
    * are the current drawing units & precision are used.
 
447
    * \param num Number to convert.
 
448
    * \param units Units format to use. current configured=0, Scientific=1,
 
449
    * Decimal=2, Engineering=3, Architectural=4, Fractional=5.
 
450
    * \param prec number of decimals added in the string.
 
451
    * \return a string with the converted number.
 
452
    */
 
453
    virtual QString realToStr(const qreal num, const int units = 0, const int prec = 0) = 0;
 
454
};
 
455
 
 
456
 
 
457
#endif // DOCUMENT_INTERFACE_H