]> Shamusworld >> Repos - architektonas/blob - src/base/insert.h
Initial removal of unnecessary rs_ prefixes from files.
[architektonas] / src / base / insert.h
1 #ifndef __INSERT_H__
2 #define __INSERT_H__
3
4 #include "entitycontainer.h"
5 #include "block.h"
6 #include "drawing.h"
7
8 /**
9  * Holds the data that defines an insert.
10  */
11 class RS_InsertData
12 {
13         public:
14                 /**
15                  * Default constructor.
16                  */
17                 RS_InsertData() {}
18
19                 /**
20                  * @param name The name of the block used as an identifier.
21                  * @param insertionPoint Insertion point of the block.
22                  * @param scaleFactor Scale factor in x / y.
23                  * @param angle Rotation angle.
24                  * @param cols Number of cols if we insert a whole array.
25                  * @param rows Number of rows if we insert a whole array.
26                  * @param spacing Spacing between rows and cols.
27                  * @param blockSource Source for the block to insert if other than parent.
28                  *    Normally blocks are requested from the entity's parent but the
29                  *    block can also come from another resource. RS_Text uses that
30                  *    to share the blocks (letters) from a font.
31                  * @param updateMode RS2::Update will update the insert entity instantly
32                  *    RS2::NoUpdate will not update the insert. You can update
33                  *        it later manually using the update() method. This is
34                  *    often the case since you might want to adjust attributes
35                  *    after creating an insert entity.
36                  */
37                 RS_InsertData(const QString & name, Vector insertionPoint, Vector scaleFactor,
38                         double angle, int cols, int rows, Vector spacing, RS_BlockList * blockSource = NULL,
39                         RS2::UpdateMode updateMode = RS2::Update)
40                 {
41                         this->name = name;
42                         this->insertionPoint = insertionPoint;
43                         this->scaleFactor = scaleFactor;
44                         this->angle = angle;
45                         this->cols = cols;
46                         this->rows = rows;
47                         this->spacing = spacing;
48                         this->blockSource = blockSource;
49                         this->updateMode = updateMode;
50                 }
51
52                 friend class RS_Insert;
53
54                 friend std::ostream & operator<<(std::ostream & os, const RS_InsertData & d)
55                 {
56                         os << "(" << d.name.toLatin1().data() << ")";
57                         return os;
58                 }
59
60                 QString name;
61                 Vector insertionPoint;
62                 Vector scaleFactor;
63                 double angle;
64                 int cols, rows;
65                 Vector spacing;
66                 RS_BlockList * blockSource;
67                 RS2::UpdateMode updateMode;
68 };
69
70 /**
71  * An insert inserts a block into the drawing at a certain location
72  * with certain attributes (angle, scale, ...).
73  * Inserts don't really contain other entities internally. They just
74  * refer to a block. However, to the outside world they act exactly
75  * like EntityContainer.
76  *
77  * @author Andrew Mustun
78  */
79 class RS_Insert: public RS_EntityContainer
80 {
81         public:
82                 RS_Insert(RS_EntityContainer * parent, const RS_InsertData & d);
83                 virtual ~RS_Insert();
84
85                 virtual RS_Entity * clone();
86                 virtual RS2::EntityType rtti() const;
87                 RS_InsertData getData() const;
88                 virtual void reparent(RS_EntityContainer * parent);
89
90                 RS_Block * getBlockForInsert();
91                 virtual void update();
92
93                 QString getName() const;
94                 void setName(const QString & newName);
95                 Vector getInsertionPoint() const;
96                 void setInsertionPoint(const Vector & i);
97                 Vector getScale() const;
98                 void setScale(const Vector & s);
99                 double getAngle() const;
100                 void setAngle(double a);
101                 int getCols() const;
102                 void setCols(int c);
103                 int getRows() const;
104                 void setRows(int r);
105                 Vector getSpacing() const;
106                 void setSpacing(const Vector & s);
107                 virtual bool isVisible();
108
109                 virtual VectorSolutions getRefPoints();
110                 virtual Vector getNearestRef(const Vector & coord, double * dist = NULL);
111
112                 virtual void move(Vector offset);
113                 virtual void rotate(Vector center, double angle);
114                 virtual void scale(Vector center, Vector factor);
115                 virtual void mirror(Vector axisPoint1, Vector axisPoint2);
116
117                 friend std::ostream & operator<<(std::ostream & os, const RS_Insert & i);
118
119         protected:
120                 RS_InsertData data;
121                 RS_Block * block;
122 };
123
124 #endif