]> Shamusworld >> Repos - architektonas/blob - src/base/rs_insert.h
9b4fdf400b5c51a26b77d4a4882580383bc2af15
[architektonas] / src / base / rs_insert.h
1 /****************************************************************************
2 ** $Id: rs_insert.h 2367 2005-04-04 16:57:36Z andrew $
3 **
4 ** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.
5 **
6 ** This file is part of the qcadlib Library project.
7 **
8 ** This file may be distributed and/or modified under the terms of the
9 ** GNU General Public License version 2 as published by the Free Software
10 ** Foundation and appearing in the file LICENSE.GPL included in the
11 ** packaging of this file.
12 **
13 ** Licensees holding valid qcadlib Professional Edition licenses may use
14 ** this file in accordance with the qcadlib Commercial License
15 ** Agreement provided with the Software.
16 **
17 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
18 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
19 **
20 ** See http://www.ribbonsoft.com for further details.
21 **
22 ** Contact info@ribbonsoft.com if any conditions of this licensing are
23 ** not clear to you.
24 **
25 **********************************************************************/
26
27 #ifndef RS_INSERT_H
28 #define RS_INSERT_H
29
30 #include "rs_entitycontainer.h"
31 #include "rs_block.h"
32 #include "rs_graphic.h"
33
34 /**
35  * Holds the data that defines an insert.
36  */
37 class RS_InsertData
38 {
39         public:
40                 /**
41                  * Default constructor.
42                  */
43                 RS_InsertData() {}
44
45                 /**
46                  * @param name The name of the block used as an identifier.
47                  * @param insertionPoint Insertion point of the block.
48                  * @param scaleFactor Scale factor in x / y.
49                  * @param angle Rotation angle.
50                  * @param cols Number of cols if we insert a whole array.
51                  * @param rows Number of rows if we insert a whole array.
52                  * @param spacing Spacing between rows and cols.
53                  * @param blockSource Source for the block to insert if other than parent.
54                  *    Normally blocks are requested from the entity's parent but the
55                  *    block can also come from another resource. RS_Text uses that
56                  *    to share the blocks (letters) from a font.
57                  * @param updateMode RS2::Update will update the insert entity instantly
58                  *    RS2::NoUpdate will not update the insert. You can update
59                  *        it later manually using the update() method. This is
60                  *    often the case since you might want to adjust attributes
61                  *    after creating an insert entity.
62                  */
63                 RS_InsertData(const QString & name, Vector insertionPoint, Vector scaleFactor,
64                         double angle, int cols, int rows, Vector spacing, RS_BlockList * blockSource = NULL,
65                         RS2::UpdateMode updateMode = RS2::Update)
66                 {
67                         this->name = name;
68                         this->insertionPoint = insertionPoint;
69                         this->scaleFactor = scaleFactor;
70                         this->angle = angle;
71                         this->cols = cols;
72                         this->rows = rows;
73                         this->spacing = spacing;
74                         this->blockSource = blockSource;
75                         this->updateMode = updateMode;
76                 }
77
78                 friend class RS_Insert;
79
80                 friend std::ostream & operator<<(std::ostream & os, const RS_InsertData & d)
81                 {
82                         os << "(" << d.name.toLatin1().data() << ")";
83                         return os;
84                 }
85
86                 QString name;
87                 Vector insertionPoint;
88                 Vector scaleFactor;
89                 double angle;
90                 int cols, rows;
91                 Vector spacing;
92                 RS_BlockList * blockSource;
93                 RS2::UpdateMode updateMode;
94 };
95
96 /**
97  * An insert inserts a block into the drawing at a certain location
98  * with certain attributes (angle, scale, ...).
99  * Inserts don't really contain other entities internally. They just
100  * refer to a block. However, to the outside world they act exactly
101  * like EntityContainer.
102  *
103  * @author Andrew Mustun
104  */
105 class RS_Insert: public RS_EntityContainer
106 {
107         public:
108                 RS_Insert(RS_EntityContainer * parent, const RS_InsertData & d);
109                 virtual ~RS_Insert();
110
111                 virtual RS_Entity * clone();
112                 virtual RS2::EntityType rtti() const;
113                 RS_InsertData getData() const;
114                 virtual void reparent(RS_EntityContainer * parent);
115
116                 RS_Block * getBlockForInsert();
117                 virtual void update();
118
119                 QString getName() const;
120                 void setName(const QString & newName);
121                 Vector getInsertionPoint() const;
122                 void setInsertionPoint(const Vector & i);
123                 Vector getScale() const;
124                 void setScale(const Vector & s);
125                 double getAngle() const;
126                 void setAngle(double a);
127                 int getCols() const;
128                 void setCols(int c);
129                 int getRows() const;
130                 void setRows(int r);
131                 Vector getSpacing() const;
132                 void setSpacing(const Vector & s);
133                 virtual bool isVisible();
134
135                 virtual VectorSolutions getRefPoints();
136                 virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
137
138                 virtual void move(Vector offset);
139                 virtual void rotate(Vector center, double angle);
140                 virtual void scale(Vector center, Vector factor);
141                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
142
143                 friend std::ostream & operator<<(std::ostream & os, const RS_Insert & i);
144
145         protected:
146                 RS_InsertData data;
147                 RS_Block * block;
148 };
149
150 #endif