-
Notifications
You must be signed in to change notification settings - Fork 2
/
csiitem.cpp
executable file
·404 lines (351 loc) · 13.6 KB
/
csiitem.cpp
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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/****************************************************************************
**
** Copyright (C) 2007-2009 Kevin Clague. All rights reserved.
**
** This file may be used under the terms of the GNU General Public
** License version 2.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of
** this file. Please review the following information to ensure GNU
** General Public Licensing requirements will be met:
** http://www.trolltech.com/products/qt/opensource.html
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
****************************************************************************/
/****************************************************************************
*
* The class described in this file is the graphical representation of
* a step's construction step image (CSI), or assembly image.
*
* Please see lpub.h for an overall description of how the files in LPub
* make up the LPub program.
*
***************************************************************************/
#include <QMenu>
#include <QAction>
#include <QGraphicsRectItem>
#include <QGraphicsSceneContextMenuEvent>
#include "lpub.h"
#include "step.h"
#include "ranges.h"
#include "ranges_element.h"
#include "callout.h"
#include "csiitem.h"
#include "metaitem.h"
#include "commonmenus.h"
CsiItem::CsiItem(
Step *_step,
Meta *_meta,
QPixmap &pixmap,
int _submodelLevel,
QGraphicsItem *parent,
PlacementType _parentRelativeType)
{
step = _step;
meta = _meta;
submodelLevel = _submodelLevel;
parentRelativeType = _parentRelativeType;
setPixmap(pixmap);
setParentItem(parent);
assem = &meta->LPub.assem;
if (parentRelativeType == StepGroupType) {
divider = &meta->LPub.multiStep.divider;
} else if (parentRelativeType == CalloutType) {
divider = &meta->LPub.callout.divider;
} else {
divider = NULL;
}
setTransformationMode(Qt::SmoothTransformation);
setToolTip(step->path() + "- popup menu");
setFlag(QGraphicsItem::ItemIsSelectable,true);
setFlag(QGraphicsItem::ItemIsMovable,true);
modelScale = meta->LPub.assem.modelScale;
}
void CsiItem::setFlag(GraphicsItemFlag flag, bool value)
{
QGraphicsItem::setFlag(flag,value);
}
void CsiItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
{
QMenu menu;
MetaItem mi;
int numSteps = mi.numSteps(step->top.modelName);
Boundary boundary = step->boundary();
QAction *addNextAction = NULL;
if (step->stepNumber.number != numSteps &&
(parentRelativeType == SingleStepType ||
(parentRelativeType == StepGroupType && (boundary & EndOfSteps)))) {
addNextAction = menu.addAction("Add Next Step");
addNextAction->setWhatsThis("Add Next Step:\n Add the first step of the next page to this page");
}
QAction *addPrevAction = NULL;
if ( step->stepNumber.number > 1 &&
(parentRelativeType == SingleStepType ||
(parentRelativeType == StepGroupType && (boundary & StartOfSteps)))) {
addPrevAction = menu.addAction("Add Previous Step");
addPrevAction->setWhatsThis("Add Previous Step:\n Add the last step of the previous page to this page");
}
QAction *removeAction = NULL;
if (parentRelativeType == StepGroupType &&
(boundary & (StartOfSteps | EndOfSteps))) {
removeAction = menu.addAction("Remove this Step");
if (boundary & StartOfSteps) {
removeAction->setWhatsThis("Remove this Step:\n Move this step from this page to the previous page");
} else {
removeAction->setWhatsThis("Remove this Step:\n Move this step from this page to the next page");
}
}
QAction *movePrevAction = NULL;
QAction *moveNextAction = NULL;
QAction *addDividerAction = NULL;
QAction *allocAction = NULL;
AllocEnc allocType = step->parent->allocType();
if (parentRelativeType == StepGroupType || parentRelativeType == CalloutType) {
if ((boundary & StartOfRange) && ! (boundary & StartOfSteps)) {
if (allocType == Vertical) {
movePrevAction = menu.addAction("Add to Previous Column");
movePrevAction->setWhatsThis(
"Add to Previous Column:\n"
" Move this step to the previous column");
} else {
movePrevAction = menu.addAction("Add to Previous Row");
movePrevAction->setWhatsThis(
"Add to Previous Row:\n"
" Move this step to the previous row\n");
}
}
if ((boundary & EndOfRange) && ! (boundary & EndOfSteps)) {
if (allocType == Vertical) {
moveNextAction = menu.addAction("Add to Next Column");
moveNextAction->setWhatsThis(
"Add to Next Colum:\n"
" Remove this step from its current column,\n"
" and put it in the column to the right");
} else {
moveNextAction = menu.addAction("Add to Next Row");
moveNextAction->setWhatsThis(
"Add to Next Row:\n"
" Remove this step from its current column,\n"
" and put it in the row above");
}
}
if ( ! (boundary & EndOfRange) && ! (boundary & EndOfSteps)) {
addDividerAction = menu.addAction("Add Divider After Step");
if (allocType == Vertical) {
addDividerAction->setWhatsThis(
"Add Divider After Step:\n"
" Put the step(s) after this into a new column");
} else {
addDividerAction->setWhatsThis(
"Add Divider After Step:\n"
" Put the step(s) after this into a new row");
}
}
if (allocType == Vertical) {
allocAction = menu.addAction("Display as Rows");
allocAction->setWhatsThis(
"Display as Rows:\n"
" Change this whole set of steps from columns of steps\n"
" to rows of steps");
} else {
allocAction = menu.addAction("Display as Columns");
allocAction->setWhatsThis(
"Display as Columns:\n"
" Change this whole set of steps from rows of steps\n"
" to columns of steps");
}
}
QAction *placementAction = NULL;
if (parentRelativeType == SingleStepType) {
placementAction = menu.addAction("Move This Step");
placementAction->setWhatsThis(
"Move This Step:\n"
" Move this assembly step image using a dialog (window)\n"
" with buttons. You can also move this step image around\n"
" by clicking and dragging it using the mouse.");
}
QAction *scaleAction = menu.addAction("Change Scale");
scaleAction->setWhatsThis("Change Scale:\n"
" You can change the size of this assembly image using the scale\n"
" dialog (window). A scale of 1.0 is true size. A scale of 2.0\n"
" doubles the size of your model. A scale of 0.5 makes your model\n"
" half real size\n");
QAction *marginsAction = menu.addAction("Change Assembly Margins");
switch (parentRelativeType) {
case SingleStepType:
marginsAction->setWhatsThis("Change Assembly Margins:\n"
" Margins are the empty space around this assembly picture.\n"
" You can change the margins if things are too close together,\n"
" or too far apart. ");
break;
case StepGroupType:
marginsAction->setWhatsThis("Change Assembly Margins:\n"
" Margins are the empty space around this assembly picture.\n"
" You can change the margins if things are too close together,\n"
" or too far apart. You can change the margins around the\n"
" whole group of steps, by clicking the menu button with your\n"
" cursor near this assembly image, and using that\n"
" \"Change Step Group Margins\" menu");
break;
case CalloutType:
marginsAction->setWhatsThis("Change Assembly Margins:\n"
" Margins are the empty space around this assembly picture.\n"
" You can change the margins if things are too close together,\n"
" or too far apart. You can change the margins around callout\n"
" this step is in, by putting your cursor on the background\n"
" of the callout, clicking the menu button, and using that\n"
" \"Change Callout Margins\" menu");
break;
default:
break;
}
QAction *noStepAction = menu.addAction("Don't Show This Step");
QAction *selectedAction = menu.exec(event->screenPos());
if ( ! selectedAction ) {
return;
}
Callout *callout = step->callout();
Where topOfStep = step->topOfStep();
Where bottomOfStep = step->bottomOfStep();
Where topOfSteps = step->topOfSteps();
Where bottomOfSteps = step->bottomOfSteps();
Where begin = topOfSteps;
if (parentRelativeType == StepGroupType) {
MetaItem mi;
mi.scanForward(begin,StepGroupMask);
}
if (selectedAction == addPrevAction) {
addPrevMultiStep(topOfSteps,bottomOfSteps);
} else if (selectedAction == addNextAction) {
addNextMultiStep(topOfSteps,bottomOfSteps);
} else if (selectedAction == removeAction) {
if (boundary & StartOfSteps) {
deleteFirstMultiStep(topOfSteps);
} else {
deleteLastMultiStep(topOfSteps,bottomOfSteps);
}
} else if (selectedAction == movePrevAction) {
addToPrev(parentRelativeType,topOfStep);
} else if (selectedAction == moveNextAction) {
addToNext(parentRelativeType,topOfStep);
} else if (selectedAction == addDividerAction) {
addDivider(parentRelativeType,bottomOfStep,divider);
} else if (selectedAction == allocAction) {
if (parentRelativeType == StepGroupType) {
changeAlloc(begin,
bottomOfSteps,
step->allocMeta());
} else {
changeAlloc(callout->topOfCallout(),
callout->bottomOfCallout(),
step->allocMeta());
}
} else if (selectedAction == placementAction) {
changePlacement(parentRelativeType,
CsiType,
"Assembly Placement",
topOfStep,
bottomOfStep,
&meta->LPub.assem.placement);
} else if (selectedAction == scaleAction) {
bool allowLocal = parentRelativeType != StepGroupType &&
parentRelativeType != CalloutType;
changeFloatSpin("Assembly",
"Model Size",
begin,
bottomOfSteps,
&meta->LPub.assem.modelScale,
1,allowLocal);
} else if (selectedAction == marginsAction) {
MarginsMeta *margins;
switch (parentRelativeType) {
case StepGroupType:
margins = &meta->LPub.multiStep.csi.margin;
break;
case CalloutType:
margins = &meta->LPub.callout.csi.margin;
break;
default:
margins = &meta->LPub.assem.margin;
break;
}
changeMargins("Assembly Margins",
topOfStep,
bottomOfStep,
margins);
} else if (selectedAction == noStepAction) {
appendMeta(topOfStep,"0 !LPUB NOSTEP");
}
}
void CsiItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mousePressEvent(event);
positionChanged = false;
//placeGrabbers();
position = pos();
gui->showLine(step->topOfStep());
}
void CsiItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if (isSelected() && (flags() & QGraphicsItem::ItemIsMovable)) {
QPoint delta(int(pos().x() - position.x() + 0.5),
int(pos().y() - position.y() + 0.5));
if (delta.x() || delta.y()) {
for (int i = 0; i < step->list.size(); i++) {
Callout *callout = step->list[i];
callout->drawTips(delta);
}
positionChanged = true;
//placeGrabbers();
}
QGraphicsPixmapItem::mouseMoveEvent(event);
}
}
void CsiItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
QGraphicsItem::mouseReleaseEvent(event);
if (isSelected() && (flags() & QGraphicsItem::ItemIsMovable)) {
if (positionChanged) {
beginMacro(QString("DragCsi"));
PlacementData placementData = step->csiPlacement.placement.value();
qreal topLeft[2] = { sceneBoundingRect().left(), sceneBoundingRect().top() };
qreal size[2] = { sceneBoundingRect().width(), sceneBoundingRect().height() };
calcOffsets(placementData,placementData.offsets,topLeft,size);
step->csiPlacement.placement.setValue(placementData);
QPoint deltaI(int(pos().x() - position.x()),
int(pos().y() - position.y()));
if (step) {
for (int i = 0; i < step->list.size(); i++) {
Callout *callout = step->list[i];
callout->updatePointers(deltaI);
}
}
changePlacementOffset(step->topOfStep(),&step->csiPlacement.placement,CsiType);
endMacro();
}
}
}
void CsiItem::change()
{
if (isSelected() && (flags() & QGraphicsItem::ItemIsMovable)) {
if (sizeChanged) {
beginMacro(QString("Resize"));
PlacementData placementData = meta->LPub.assem.placement.value();
qreal topLeft[2] = { sceneBoundingRect().left(), sceneBoundingRect().top() };
qreal size[2] = { sceneBoundingRect().width(), sceneBoundingRect().height() };
calcOffsets(placementData,placementData.offsets,topLeft,size);
meta->LPub.assem.placement.setValue(placementData);
QPoint deltaI(int(pos().x() - position.x()),
int(pos().y() - position.y()));
for (int i = 0; i < step->list.size(); i++) {
Callout *callout = step->list[i];
callout->updatePointers(deltaI);
}
changePlacementOffset(step->topOfStep(),&meta->LPub.assem.placement,CsiType,true,false);
modelScale.setValue(modelScale.value()*oldScale);
changeFloat(step->topOfStep(),step->bottomOfStep(),&modelScale,1,0);
endMacro();
}
}
}