-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.h
296 lines (224 loc) · 4.8 KB
/
model.h
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
#ifndef MODELH
#define MODELH
#include <vector>
#include <algorithm>
#include <process.h>
#include <fstream>
#include <string>
#include <typeinfo>
#include <sstream>
#include "myvector.h"
#include <stdlib.h>
#define streq(a,b) (!strcmp(a,b))
#define MAXFILENAME 256
#define OFF 0
#define SOLID 1
#define SMALL 1
#define BLACK 0
#define MAXLAYER 8
#define DEFAULTCOLOR BLACK
#define DEFAULTWIDTH SMALL
#define DEFAULTTYPE SOLID
#define TRUE 1
#define FALSE 0
enum toolType {T0,T1,T2,T3,T4,T5,T6,T7,T8,T9};
const float DEFAULT_SPEED=10.0;//mm/min
const toolType DEFAULT_TOOL=T0;//T0
const float DEFAULT_Z=0.0;
const float MIN_Z=-10.0;
const float MAX_Z=10.0;
enum {ONE,TWO,THREE,FOR,FIFE,SIX,SEVEN,EIGHT,NINE,TEN};
enum entityType {tPoint,tLine,tArc};
const int MAX=255;
enum {OUTENTITY,INENTITY};
class Layer
{
private:
bool hide;
int type,width,color;
float Z;
float speed;
toolType tool;
static unsigned char countID;
unsigned char ID;
public:
Layer();
static unsigned char getCount();
unsigned char getID();
int getType()const;
int getWidth()const;
int getColor()const;
float getZ()const;
float getSpeed()const;
toolType getTool()const;
void show()const;
void setZ(float);
void setSpeed(float);
void setTool(toolType);
};
class Entity
{
protected:
unsigned char layerID;
bool selected;
float Z;
float speed;
toolType tool;
public:
virtual void show()=0;
virtual bool getDataFromUser()=0;
virtual entityType getType()const;
virtual bool hitCursor(int,int,int)=0;
unsigned char getLayerID();
bool setLayerID(unsigned char);
bool getState();
void setZ(float);
float getZ();
void setSpeed(float);
float getSpeed();
void setTool(toolType);
toolType getTool();
virtual bool printInfo()=0;
virtual bool getInfo(char *)=0;
virtual bool scale(float)=0;
virtual bool move(float,float)=0;
/* virtual unsigned char getLayer()=0;
virtual bool setLayer(unsigned char)=0;
virtual bool rotate()=0;
virtual bool mirror()=0;
virtual bool offset()=0;
virtual bool trim()=0;
virtual bool lenghten()=0;
*/
friend bool operator==(const Entity&,const Entity&);
};
class Point:public Entity
{
private:
float x,y;
int type,width,color;
public:
Point();
Point(Layer*);
Point(float,float);
Point(float,float,Layer*);
Point(vec2);
void show();
bool printInfo();
bool getInfo(char*);
void getPoint();
float getX();
float getY();
bool setXY(float,float);
bool getDataFromUser();
bool scale(float);
bool move(float,float);
bool rotate(float);
bool rotRad(float);
bool hitCursor(int,int,int);
};
class Line:public Entity
{
private:
Point start,end;
int type,width,color;
public:
Line();
Line(Layer*);
Line(Point*,Point*);
Line(Point*,Point*,Layer*);
bool scale(float );
bool move(float, float);
bool setStart(float,float);
bool setEnd(float,float);
void show();
bool getInfo(char*);
bool printInfo();
void getLine();
bool getDataFromUser();
bool hitCursor(int,int,int);
Point* getStart();
Point* getEnd();
};
class ArcSegment:public Entity
{
private:
int type,width,color;
float xc,yc;
float radius;
float xs,ys, xe,ye;
int direction;
public:
ArcSegment();
ArcSegment(float,float,float,float,float,float,float,int);
void show();
bool scale(float);
bool move(float,float);
bool getInfo(char*);
bool printInfo();
bool getDataFromUser();
bool hitCursor(int,int,int);
float getAngle();
float getStartX();
float getStartY();
float getEndX();
float getEndY();
float getCenterX();
float getCenterY();
float getRadius();
int getDirection();
float getSignRad();
};
class Model
{
private:
char FileName[256];
std::vector<Entity*> entities;
std::vector<Entity*>::iterator iter;
std::vector<Entity*>::iterator iterFind;
Layer *ptrToDefaultLayer;
Layer *ptrToCurrentLayer;
int selectedCount;
float osnapX,osnapY;
bool flagOsnap;
bool markerOsnap;
public:
Model();
int setFileName(char*);
bool appendLine(Point*,Point*);
bool appendPoint();
bool appendArc(float, float, float, float, float, float, float, int);
bool appendArcCenAngRad(float, float, float, float, float);
bool addEntity(Entity*);
int deleteEntity(Entity*);
int transformEntity(int[]);
bool hitModel(int,int,int);
bool hitOsnap(int,int);
bool setOsnapXY(std::vector<Entity*>::iterator&,int,int);
bool stateOsnap();
bool switchOsnap();
float getOsnapX();
float getOsnapY();
bool markerOsnapVisible();
int readModel(char *);
int writeModel(const char *);
int saveGcodeISO(const char *);
int saveNC1000(const char *);
int saveDXF(const char *);
int loadDXF(const char *);
int scaleModel(float);
void showModel();
int printModelInfo()const;
int deleteAll();
float getDistance(float,float,float,float);
};
class HitOsnap
{
public:
bool operator()(const Entity* ptrE1,
const Entity* ptrE2)const
{
return *ptrE1==*ptrE2;
}
};
#endif