]> Shamusworld >> Repos - architektonas/blob - src/widgets/qg_actionhandler.cpp
5e8627942363e2ff1b1bd4eab3e977331d3265a0
[architektonas] / src / widgets / qg_actionhandler.cpp
1 // qg_actionhandler.cpp
2 //
3 // Part of the Architektonas Project
4 // Originally part of QCad Community Edition by Andrew Mustun
5 // Extensively rewritten and refactored by James L. Hammons
6 // (C) 2010 Underground Software
7 //
8 // JLH = James L. Hammons <jlhamm@acm.org>
9 //
10 // Who  When        What
11 // ---  ----------  -----------------------------------------------------------
12 // JLH  05/10/2010  Added this text. :-)
13 //
14
15 #include "qg_actionhandler.h"
16
17 #include "commands.h"
18 #include "rs_actionblocksadd.h"
19 #include "rs_actionblocksattributes.h"
20 #include "rs_actionblockscreate.h"
21 #include "rs_actionblocksedit.h"
22 #include "rs_actionblocksexplode.h"
23 #include "rs_actionblocksfreezeall.h"
24 #include "rs_actionblocksinsert.h"
25 #include "rs_actionblocksremove.h"
26 #include "rs_actionblockstoggleview.h"
27 #include "rs_actiondimaligned.h"
28 #include "rs_actiondimangular.h"
29 #include "rs_actiondimdiametric.h"
30 #include "rs_actiondimleader.h"
31 #include "rs_actiondimlinear.h"
32 #include "rs_actiondimradial.h"
33 #include "rs_actiondrawarc.h"
34 #include "rs_actiondrawarc3p.h"
35 #include "rs_actiondrawarctangential.h"
36 #include "rs_actiondrawcircle.h"
37 #include "rs_actiondrawcircle2p.h"
38 #include "rs_actiondrawcircle3p.h"
39 #include "rs_actiondrawcirclecr.h"
40 #include "rs_actiondrawellipseaxis.h"
41 #include "rs_actiondrawhatch.h"
42 #include "rs_actiondrawimage.h"
43 #include "rs_actiondrawline.h"
44 #include "rs_actiondrawlineangle.h"
45 #include "rs_actiondrawlinebisector.h"
46 #include "rs_actiondrawlinefree.h"
47 #include "rs_actiondrawlinehorvert.h"
48 #include "rs_actiondrawlineparallel.h"
49 #include "rs_actiondrawlineparallelthrough.h"
50 #include "rs_actiondrawlinepolygon.h"
51 #include "rs_actiondrawlinepolygon2.h"
52 #include "rs_actiondrawlinerectangle.h"
53 #include "rs_actiondrawlinerelangle.h"
54 #include "rs_actiondrawlinetangent1.h"
55 #include "rs_actiondrawlinetangent2.h"
56 #include "rs_actiondrawpoint.h"
57 #include "rs_actiondrawspline.h"
58 #include "rs_actiondrawtext.h"
59 #include "rs_actioneditcopy.h"
60 #include "rs_actioneditpaste.h"
61 #include "rs_actioneditundo.h"
62 #include "rs_actionfileopen.h"
63 #include "rs_actionfilesaveas.h"
64 #include "rs_actioninfoangle.h"
65 #include "rs_actioninfoarea.h"
66 #include "rs_actioninfodist.h"
67 #include "rs_actioninfodist2.h"
68 #include "rs_actioninfoinside.h"
69 #include "rs_actioninfototallength.h"
70 #include "rs_actionlayersadd.h"
71 #include "rs_actionlayersedit.h"
72 #include "rs_actionlayersfreezeall.h"
73 #include "rs_actionlayersremove.h"
74 #include "rs_actionlayerstogglelock.h"
75 #include "rs_actionlayerstoggleview.h"
76 #include "rs_actionlibraryinsert.h"
77 #include "rs_actionlockrelativezero.h"
78 #include "rs_actionmodifyattributes.h"
79 #include "rs_actionmodifybevel.h"
80 #include "rs_actionmodifycut.h"
81 #include "rs_actionmodifydelete.h"
82 #include "rs_actionmodifydeletefree.h"
83 #include "rs_actionmodifydeletequick.h"
84 #include "rs_actionmodifyentity.h"
85 #include "rs_actionmodifyexplodetext.h"
86 #include "rs_actionmodifymirror.h"
87 #include "rs_actionmodifymove.h"
88 #include "rs_actionmodifymoverotate.h"
89 #include "rs_actionmodifyrotate.h"
90 #include "rs_actionmodifyrotate2.h"
91 #include "rs_actionmodifyround.h"
92 #include "rs_actionmodifyscale.h"
93 #include "rs_actionmodifystretch.h"
94 #include "rs_actionmodifytrim.h"
95 #include "rs_actionmodifytrimamount.h"
96 #include "rs_actionoptionsdrawing.h"
97 #include "rs_actionselect.h"
98 #include "rs_actionselectall.h"
99 #include "rs_actionselectcontour.h"
100 #include "rs_actionselectintersected.h"
101 #include "rs_actionselectinvert.h"
102 #include "rs_actionselectlayer.h"
103 #include "rs_actionselectsingle.h"
104 #include "rs_actionselectwindow.h"
105 #include "rs_actionsetrelativezero.h"
106 #include "rs_actionsetsnapmode.h"
107 #include "rs_actionsetsnaprestriction.h"
108 #include "rs_actionsnapintersectionmanual.h"
109 #include "rs_actiontoolregeneratedimensions.h"
110 #include "rs_actionzoomauto.h"
111 #include "rs_actionzoomin.h"
112 #include "rs_actionzoompan.h"
113 #include "rs_actionzoomprevious.h"
114 #include "rs_actionzoomredraw.h"
115 #include "rs_actionzoomwindow.h"
116
117 #warning "!!! Need to add polyline functionality !!!"
118 #ifdef RS_PROF
119 #include "rs_actiondrawpolyline.h"
120 #include "rs_actionpolylineadd.h"
121 #include "rs_actionpolylineappend.h"
122 #include "rs_actionpolylinedel.h"
123 #include "rs_actionpolylinedelbetween.h"
124 #include "rs_actionpolylinetrim.h"
125 #endif
126
127 #ifdef RS_CAM
128 #include "rs_actioncamexportauto.h"
129 #include "rs_actioncamreorder.h"
130 #endif
131
132 #include "qg_mainwindowinterface.h"
133 #include "cadtoolbarsnap.h"
134
135 /**
136  * Constructor
137  */
138 QG_ActionHandler::QG_ActionHandler(QG_MainWindowInterface * mw)
139 {
140         RS_DEBUG->print("QG_ActionHandler::QG_ActionHandler");
141         mainWindow = mw;
142
143         snapFree = NULL;
144         snapGrid = NULL;
145         snapEndpoint = NULL;
146         snapOnEntity = NULL;
147         snapCenter = NULL;
148         snapMiddle = NULL;
149         snapDist = NULL;
150
151         restrictNothing = NULL;
152         restrictOrthogonal = NULL;
153         restrictHorizontal = NULL;
154         restrictVertical = NULL;
155
156         lockRelativeZero = NULL;
157         RS_DEBUG->print("QG_ActionHandler::QG_ActionHandler: OK");
158 }
159
160 /**
161  * Destructor
162  */
163 QG_ActionHandler::~QG_ActionHandler()
164 {
165         RS_DEBUG->print("QG_ActionHandler::~QG_ActionHandler");
166         RS_DEBUG->print("QG_ActionHandler::~QG_ActionHandler: OK");
167 }
168
169 /**
170  * Kills all running selection actions. Called when a selection action
171  * is launched to reduce confusion.
172  */
173 void QG_ActionHandler::killSelectActions()
174 {
175         RS_GraphicView * gv = mainWindow->getGraphicView();
176
177         if (gv != NULL)
178                 gv->killSelectActions();
179 }
180
181 /**
182  * @return Current action or NULL.
183  */
184 RS_ActionInterface * QG_ActionHandler::getCurrentAction()
185 {
186         RS_GraphicView * gv = mainWindow->getGraphicView();
187
188         if (gv)
189                 return gv->getCurrentAction();
190
191         return NULL;
192 }
193
194 #if 0
195 Instead of the following giant switch statement, you could something like the following:
196 RS_ActionInterface * QG_ActionHandler::setCurrentAction(RS_ActionInterface * action)
197 {
198         RS_GraphicView * gv = mainWindow->getGraphicView();
199         RS_Document * doc = mainWindow->getDocument();
200
201         // only global options are allowed without a document:
202         if (gv == NULL || doc == NULL)
203         {
204                 return NULL;
205         }
206
207         if (action != NULL)
208                 gv->setCurrentAction(action);
209
210         return action;
211 }
212 Then you'd call it with:
213                 a = new RS_ActionEditUndo(true, *doc, *gv);
214
215 Hmmm.... We need gv & doc *before* we call this...
216
217 What you'd do then is have the form of the thing worked ahead of time and the function
218 itself would create the gv & doc. So for the EditUndo, we'd have:
219         FunctionCreateAction(bool);
220         FunctionCreateAction(void);
221
222 Well... The problem is the action, they're all different...
223 #endif
224
225 /**
226  * Sets current action.
227  *
228  * @return Pointer to the created action or NULL.
229  */
230 RS_ActionInterface * QG_ActionHandler::setCurrentAction(RS2::ActionType id)
231 {
232         RS_DEBUG->print("QG_ActionHandler::setCurrentAction()");
233
234         RS_GraphicView * gv = mainWindow->getGraphicView();
235         RS_Document * doc = mainWindow->getDocument();
236         RS_ActionInterface * a = NULL;
237
238         // only global options are allowed without a document:
239         if (gv == NULL || doc == NULL)
240         {
241                 RS_DEBUG->print(RS_Debug::D_WARNING,
242                         "QG_ActionHandler::setCurrentAction: graphic view or document is NULL");
243                 return NULL;
244         }
245
246         switch (id)
247         {
248                 //case RS2::ActionFileNew:
249                 //    a = new RS_ActionFileNew(*doc, *gv);
250                 //      break;
251                 //case RS2::ActionFileSave:
252                 //    a = new RS_ActionFileSave(*doc, *gv);
253                 //      break;
254                 //case RS2::ActionFileClose:
255                 //    //a = new RS_ActionFileClose(*doc, *gv);
256                 //      break;
257                 //case RS2::ActionFileQuit:
258                 //    //a = new RS_ActionFileQuit(*doc, *gv);
259                 //      break;
260         case RS2::ActionFileOpen:
261                 a = new RS_ActionFileOpen(*doc, *gv);
262                 break;
263         case RS2::ActionFileSaveAs:
264                 a = new RS_ActionFileSaveAs(*doc, *gv);
265                 break;
266
267                 // Editing actions:
268                 //
269         case RS2::ActionEditUndo:
270                 a = new RS_ActionEditUndo(true, *doc, *gv);
271                 break;
272         case RS2::ActionEditRedo:
273                 a = new RS_ActionEditUndo(false, *doc, *gv);
274                 break;
275         case RS2::ActionEditCut:
276                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionEditCutNoSelect);
277                 break;
278         case RS2::ActionEditCutNoSelect:
279                 a = new RS_ActionEditCopy(false, *doc, *gv);
280                 break;
281         case RS2::ActionEditCopy:
282                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionEditCopyNoSelect);
283                 break;
284         case RS2::ActionEditCopyNoSelect:
285                 a = new RS_ActionEditCopy(true, *doc, *gv);
286                 break;
287         case RS2::ActionEditPaste:
288                 a = new RS_ActionEditPaste(*doc, *gv);
289                 break;
290
291                 // Selecting actions:
292                 //
293         case RS2::ActionSelectSingle:
294                 gv->killSelectActions();
295                 a = new RS_ActionSelectSingle(*doc, *gv);
296                 break;
297         case RS2::ActionSelectContour:
298                 gv->killSelectActions();
299                 a = new RS_ActionSelectContour(*doc, *gv);
300                 break;
301         case RS2::ActionSelectAll:
302                 a = new RS_ActionSelectAll(*doc, *gv, true);
303                 break;
304         case RS2::ActionDeselectAll:
305                 a = new RS_ActionSelectAll(*doc, *gv, false);
306                 break;
307         case RS2::ActionSelectWindow:
308                 gv->killSelectActions();
309                 a = new RS_ActionSelectWindow(*doc, *gv, true);
310                 break;
311         case RS2::ActionDeselectWindow:
312                 gv->killSelectActions();
313                 a = new RS_ActionSelectWindow(*doc, *gv, false);
314                 break;
315         case RS2::ActionSelectInvert:
316                 a = new RS_ActionSelectInvert(*doc, *gv);
317                 break;
318         case RS2::ActionSelectIntersected:
319                 gv->killSelectActions();
320                 a = new RS_ActionSelectIntersected(*doc, *gv, true);
321                 break;
322         case RS2::ActionDeselectIntersected:
323                 gv->killSelectActions();
324                 a = new RS_ActionSelectIntersected(*doc, *gv, false);
325                 break;
326         case RS2::ActionSelectLayer:
327                 gv->killSelectActions();
328                 a = new RS_ActionSelectLayer(*doc, *gv);
329                 break;
330
331                 // Tool actions:
332                 //
333         case RS2::ActionToolRegenerateDimensions:
334                 a = new RS_ActionToolRegenerateDimensions(*doc, *gv);
335                 break;
336
337                 // Zooming actions:
338                 //
339         case RS2::ActionZoomIn:
340                 a = new RS_ActionZoomIn(*doc, *gv, RS2::In, RS2::Both);
341                 break;
342         case RS2::ActionZoomOut:
343                 a = new RS_ActionZoomIn(*doc, *gv, RS2::Out, RS2::Both);
344                 break;
345         case RS2::ActionZoomAuto:
346                 a = new RS_ActionZoomAuto(*doc, *gv);
347                 break;
348         case RS2::ActionZoomWindow:
349                 a = new RS_ActionZoomWindow(*doc, *gv);
350                 break;
351         case RS2::ActionZoomPan:
352                 a = new RS_ActionZoomPan(*doc, *gv);
353                 break;
354         case RS2::ActionZoomPrevious:
355                 a = new RS_ActionZoomPrevious(*doc, *gv);
356                 break;
357         case RS2::ActionZoomRedraw:
358                 a = new RS_ActionZoomRedraw(*doc, *gv);
359                 break;
360
361                 // Drawing actions:
362                 //
363         case RS2::ActionDrawPoint:
364                 a = new RS_ActionDrawPoint(*doc, *gv);
365                 break;
366         case RS2::ActionDrawLine:
367                 a = new RS_ActionDrawLine(*doc, *gv);
368                 break;
369         case RS2::ActionDrawLineAngle:
370                 a = new RS_ActionDrawLineAngle(*doc, *gv, 0.0, false);
371                 break;
372         case RS2::ActionDrawLineHorizontal:
373                 a = new RS_ActionDrawLineAngle(*doc, *gv, 0.0, true);
374                 break;
375         case RS2::ActionDrawLineHorVert:
376                 a = new RS_ActionDrawLineHorVert(*doc, *gv);
377                 break;
378         case RS2::ActionDrawLineVertical:
379                 a = new RS_ActionDrawLineAngle(*doc, *gv, M_PI/2.0, true);
380                 break;
381         case RS2::ActionDrawLineFree:
382                 a = new RS_ActionDrawLineFree(*doc, *gv);
383                 break;
384         case RS2::ActionDrawLineParallel:
385                 a = new RS_ActionDrawLineParallel(*doc, *gv);
386                 break;
387         case RS2::ActionDrawLineParallelThrough:
388                 a = new RS_ActionDrawLineParallelThrough(*doc, *gv);
389                 break;
390         case RS2::ActionDrawLineRectangle:
391                 a = new RS_ActionDrawLineRectangle(*doc, *gv);
392                 break;
393         case RS2::ActionDrawLineBisector:
394                 a = new RS_ActionDrawLineBisector(*doc, *gv);
395                 break;
396         case RS2::ActionDrawLineTangent1:
397                 a = new RS_ActionDrawLineTangent1(*doc, *gv);
398                 break;
399         case RS2::ActionDrawLineTangent2:
400                 a = new RS_ActionDrawLineTangent2(*doc, *gv);
401                 break;
402         case RS2::ActionDrawLineOrthogonal:
403                 a = new RS_ActionDrawLineRelAngle(*doc, *gv, M_PI / 2.0, true);
404                 break;
405         case RS2::ActionDrawLineRelAngle:
406                 a = new RS_ActionDrawLineRelAngle(*doc, *gv, M_PI / 2.0, false);
407                 break;
408 #warning "!!! Need to add polyline functionality !!!"
409 #ifdef RS_PROF
410         case RS2::ActionDrawPolyline:
411                 a = new RS_ActionDrawPolyline(*doc, *gv);
412                 break;
413         case RS2::ActionPolylineAdd:
414                 a = new RS_ActionPolylineAdd(*doc, *gv);
415                 break;
416         case RS2::ActionPolylineAppend:
417                 a = new RS_ActionPolylineAppend(*doc, *gv);
418                 break;
419         case RS2::ActionPolylineDel:
420                 a = new RS_ActionPolylineDel(*doc, *gv);
421                 break;
422         case RS2::ActionPolylineDelBetween:
423                 a = new RS_ActionPolylineDelBetween(*doc, *gv);
424                 break;
425         case RS2::ActionPolylineTrim:
426                 a = new RS_ActionPolylineTrim(*doc, *gv);
427                 break;
428 #endif
429         case RS2::ActionDrawLinePolygon:
430                 a = new RS_ActionDrawLinePolygon(*doc, *gv);
431                 break;
432         case RS2::ActionDrawLinePolygon2:
433                 a = new RS_ActionDrawLinePolygon2(*doc, *gv);
434                 break;
435         case RS2::ActionDrawCircle:
436                 a = new RS_ActionDrawCircle(*doc, *gv);
437                 break;
438         case RS2::ActionDrawCircleCR:
439                 a = new RS_ActionDrawCircleCR(*doc, *gv);
440                 break;
441         case RS2::ActionDrawCircle2P:
442                 a = new RS_ActionDrawCircle2P(*doc, *gv);
443                 break;
444         case RS2::ActionDrawCircle3P:
445                 a = new RS_ActionDrawCircle3P(*doc, *gv);
446                 break;
447         case RS2::ActionDrawCircleParallel:
448                 a = new RS_ActionDrawLineParallel(*doc, *gv);
449                 break;
450         case RS2::ActionDrawArc:
451                 a = new RS_ActionDrawArc(*doc, *gv);
452                 break;
453         case RS2::ActionDrawArc3P:
454                 a = new RS_ActionDrawArc3P(*doc, *gv);
455                 break;
456         case RS2::ActionDrawArcParallel:
457                 a = new RS_ActionDrawLineParallel(*doc, *gv);
458                 break;
459         case RS2::ActionDrawArcTangential:
460                 a = new RS_ActionDrawArcTangential(*doc, *gv);
461                 break;
462         case RS2::ActionDrawEllipseAxis:
463                 a = new RS_ActionDrawEllipseAxis(*doc, *gv, false);
464                 break;
465         case RS2::ActionDrawEllipseArcAxis:
466                 a = new RS_ActionDrawEllipseAxis(*doc, *gv, true);
467                 break;
468         case RS2::ActionDrawSpline:
469                 a = new RS_ActionDrawSpline(*doc, *gv);
470                 break;
471         case RS2::ActionDrawText:
472                 a = new RS_ActionDrawText(*doc, *gv);
473                 break;
474         case RS2::ActionDrawHatch:
475                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionDrawHatchNoSelect);
476                 break;
477         case RS2::ActionDrawHatchNoSelect:
478                 a = new RS_ActionDrawHatch(*doc, *gv);
479                 break;
480         case RS2::ActionDrawImage:
481                 a = new RS_ActionDrawImage(*doc, *gv);
482                 break;
483
484                 // Dimensioning actions:
485                 //
486         case RS2::ActionDimAligned:
487                 a = new RS_ActionDimAligned(*doc, *gv);
488                 break;
489         case RS2::ActionDimLinear:
490                 a = new RS_ActionDimLinear(*doc, *gv);
491                 break;
492         case RS2::ActionDimLinearHor:
493                 a = new RS_ActionDimLinear(*doc, *gv, 0.0, true);
494                 break;
495         case RS2::ActionDimLinearVer:
496                 a = new RS_ActionDimLinear(*doc, *gv, M_PI/2.0, true);
497                 break;
498         case RS2::ActionDimRadial:
499                 a = new RS_ActionDimRadial(*doc, *gv);
500                 break;
501         case RS2::ActionDimDiametric:
502                 a = new RS_ActionDimDiametric(*doc, *gv);
503                 break;
504         case RS2::ActionDimAngular:
505                 a = new RS_ActionDimAngular(*doc, *gv);
506                 break;
507         case RS2::ActionDimLeader:
508                 a = new RS_ActionDimLeader(*doc, *gv);
509                 break;
510
511                 // Modifying actions:
512                 //
513         case RS2::ActionModifyAttributes:
514                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyAttributesNoSelect);
515                 break;
516         case RS2::ActionModifyAttributesNoSelect:
517                 a = new RS_ActionModifyAttributes(*doc, *gv);
518                 break;
519         case RS2::ActionModifyDelete:
520                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyDeleteNoSelect);
521                 break;
522         case RS2::ActionModifyDeleteNoSelect:
523                 a = new RS_ActionModifyDelete(*doc, *gv);
524                 break;
525         case RS2::ActionModifyDeleteQuick:
526                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyDeleteQuick);
527                 break;
528         case RS2::ActionModifyDeleteFree:
529                 a = new RS_ActionModifyDeleteFree(*doc, *gv);
530                 break;
531         case RS2::ActionModifyMove:
532                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyMoveNoSelect);
533                 break;
534         case RS2::ActionModifyMoveNoSelect:
535                 a = new RS_ActionModifyMove(*doc, *gv);
536                 break;
537         case RS2::ActionModifyRotate:
538                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyRotateNoSelect);
539                 break;
540         case RS2::ActionModifyRotateNoSelect:
541                 a = new RS_ActionModifyRotate(*doc, *gv);
542                 break;
543         case RS2::ActionModifyScale:
544                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyScaleNoSelect);
545                 break;
546         case RS2::ActionModifyScaleNoSelect:
547                 a = new RS_ActionModifyScale(*doc, *gv);
548                 break;
549         case RS2::ActionModifyMirror:
550                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyMirrorNoSelect);
551                 break;
552         case RS2::ActionModifyMirrorNoSelect:
553                 a = new RS_ActionModifyMirror(*doc, *gv);
554                 break;
555         case RS2::ActionModifyMoveRotate:
556                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyMoveRotateNoSelect);
557                 break;
558         case RS2::ActionModifyMoveRotateNoSelect:
559                 a = new RS_ActionModifyMoveRotate(*doc, *gv);
560                 break;
561         case RS2::ActionModifyRotate2:
562                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyRotate2NoSelect);
563                 break;
564         case RS2::ActionModifyRotate2NoSelect:
565                 a = new RS_ActionModifyRotate2(*doc, *gv);
566                 break;
567         case RS2::ActionModifyEntity:
568                 a = new RS_ActionModifyEntity(*doc, *gv);
569                 break;
570         case RS2::ActionModifyTrim:
571                 a = new RS_ActionModifyTrim(*doc, *gv, false);
572                 break;
573         case RS2::ActionModifyTrim2:
574                 a = new RS_ActionModifyTrim(*doc, *gv, true);
575                 break;
576         case RS2::ActionModifyTrimAmount:
577                 a = new RS_ActionModifyTrimAmount(*doc, *gv);
578                 break;
579         case RS2::ActionModifyCut:
580                 a = new RS_ActionModifyCut(*doc, *gv);
581                 break;
582         case RS2::ActionModifyStretch:
583                 a = new RS_ActionModifyStretch(*doc, *gv);
584                 break;
585         case RS2::ActionModifyBevel:
586                 a = new RS_ActionModifyBevel(*doc, *gv);
587                 break;
588         case RS2::ActionModifyRound:
589                 a = new RS_ActionModifyRound(*doc, *gv);
590                 break;
591         case RS2::ActionModifyExplodeText:
592                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionModifyExplodeTextNoSelect);
593                 break;
594         case RS2::ActionModifyExplodeTextNoSelect:
595                 a = new RS_ActionModifyExplodeText(*doc, *gv);
596                 break;
597
598                 // Snapping actions:
599                 //
600         case RS2::ActionSnapFree:
601                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapFree);
602                 break;
603         case RS2::ActionSnapGrid:
604                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapGrid);
605                 break;
606         case RS2::ActionSnapEndpoint:
607                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapEndpoint);
608                 break;
609         case RS2::ActionSnapOnEntity:
610                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapOnEntity);
611                 break;
612         case RS2::ActionSnapCenter:
613                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapCenter);
614                 break;
615         case RS2::ActionSnapMiddle:
616                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapMiddle);
617                 break;
618         case RS2::ActionSnapDist:
619                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapDist);
620                 break;
621         case RS2::ActionSnapIntersection:
622                 a = new RS_ActionSetSnapMode(*doc, *gv, RS2::SnapIntersection);
623                 break;
624         case RS2::ActionSnapIntersectionManual:
625                 a = new RS_ActionSnapIntersectionManual(*doc, *gv);
626                 break;
627
628                 // Snap restriction actions:
629                 //
630         case RS2::ActionRestrictNothing:
631                 a = new RS_ActionSetSnapRestriction(*doc, *gv, RS2::RestrictNothing);
632                 break;
633         case RS2::ActionRestrictOrthogonal:
634                 a = new RS_ActionSetSnapRestriction(*doc, *gv,
635                                                                                         RS2::RestrictOrthogonal);
636                 break;
637         case RS2::ActionRestrictHorizontal:
638                 a = new RS_ActionSetSnapRestriction(*doc, *gv,
639                                                                                         RS2::RestrictHorizontal);
640                 break;
641         case RS2::ActionRestrictVertical:
642                 a = new RS_ActionSetSnapRestriction(*doc, *gv,
643                                                                                         RS2::RestrictVertical);
644                 break;
645
646                 // Relative zero:
647                 //
648         case RS2::ActionSetRelativeZero:
649                 a = new RS_ActionSetRelativeZero(*doc, *gv);
650                 break;
651         case RS2::ActionLockRelativeZero:
652                 a = new RS_ActionLockRelativeZero(*doc, *gv, true);
653                 break;
654         case RS2::ActionUnlockRelativeZero:
655                 a = new RS_ActionLockRelativeZero(*doc, *gv, false);
656                 break;
657
658                 // Info actions:
659                 //
660         case RS2::ActionInfoInside:
661                 a = new RS_ActionInfoInside(*doc, *gv);
662                 break;
663         case RS2::ActionInfoDist:
664                 a = new RS_ActionInfoDist(*doc, *gv);
665                 break;
666         case RS2::ActionInfoDist2:
667                 a = new RS_ActionInfoDist2(*doc, *gv);
668                 break;
669         case RS2::ActionInfoAngle:
670                 a = new RS_ActionInfoAngle(*doc, *gv);
671                 break;
672         case RS2::ActionInfoTotalLength:
673                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionInfoTotalLengthNoSelect);
674                 break;
675         case RS2::ActionInfoTotalLengthNoSelect:
676                 a = new RS_ActionInfoTotalLength(*doc, *gv);
677                 break;
678         case RS2::ActionInfoArea:
679                 a = new RS_ActionInfoArea(*doc, *gv);
680                 break;
681
682                 // Layer actions:
683                 //
684         case RS2::ActionLayersDefreezeAll:
685                 a = new RS_ActionLayersFreezeAll(false, *doc, *gv);
686                 break;
687         case RS2::ActionLayersFreezeAll:
688                 a = new RS_ActionLayersFreezeAll(true, *doc, *gv);
689                 break;
690         case RS2::ActionLayersAdd:
691                 a = new RS_ActionLayersAdd(*doc, *gv);
692                 break;
693         case RS2::ActionLayersRemove:
694                 a = new RS_ActionLayersRemove(*doc, *gv);
695                 break;
696         case RS2::ActionLayersEdit:
697                 a = new RS_ActionLayersEdit(*doc, *gv);
698                 break;
699         case RS2::ActionLayersToggleView:
700                 a = new RS_ActionLayersToggleView(*doc, *gv);
701                 break;
702         case RS2::ActionLayersToggleLock:
703                 a = new RS_ActionLayersToggleLock(*doc, *gv);
704                 break;
705
706                 // Block actions:
707                 //
708         case RS2::ActionBlocksDefreezeAll:
709                 a = new RS_ActionBlocksFreezeAll(false, *doc, *gv);
710                 break;
711         case RS2::ActionBlocksFreezeAll:
712                 a = new RS_ActionBlocksFreezeAll(true, *doc, *gv);
713                 break;
714         case RS2::ActionBlocksAdd:
715                 a = new RS_ActionBlocksAdd(*doc, *gv);
716                 break;
717         case RS2::ActionBlocksRemove:
718                 a = new RS_ActionBlocksRemove(*doc, *gv);
719                 break;
720         case RS2::ActionBlocksAttributes:
721                 a = new RS_ActionBlocksAttributes(*doc, *gv);
722                 break;
723         case RS2::ActionBlocksEdit:
724                 a = new RS_ActionBlocksEdit(*doc, *gv);
725                 break;
726         case RS2::ActionBlocksInsert:
727                 a = new RS_ActionBlocksInsert(*doc, *gv);
728                 break;
729         case RS2::ActionBlocksToggleView:
730                 a = new RS_ActionBlocksToggleView(*doc, *gv);
731                 break;
732         case RS2::ActionBlocksCreate:
733                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionBlocksCreateNoSelect);
734                 break;
735         case RS2::ActionBlocksCreateNoSelect:
736                 a = new RS_ActionBlocksCreate(*doc, *gv);
737                 break;
738         case RS2::ActionBlocksExplode:
739                 a = new RS_ActionSelect(*doc, *gv, RS2::ActionBlocksExplodeNoSelect);
740                 break;
741         case RS2::ActionBlocksExplodeNoSelect:
742                 a = new RS_ActionBlocksExplode(*doc, *gv);
743                 break;
744
745
746                 // library browser:
747                 //
748         case RS2::ActionLibraryInsert:
749                 a = new RS_ActionLibraryInsert(*doc, *gv);
750                 break;
751
752                 // options:
753                 //
754                 //case RS2::ActionOptionsGeneral:
755                 //    a = new RS_ActionOptionsGeneral(*doc, *gv);
756                 //      break;
757
758         case RS2::ActionOptionsDrawing:
759                 a = new RS_ActionOptionsDrawing(*doc, *gv);
760                 break;
761
762                 // cam:
763                 //
764 #ifdef RS_CAM
765         case RS2::ActionCamExportAuto:
766                 a = new RS_ActionCamExportAuto(*doc, *gv);
767                 break;
768         case RS2::ActionCamReorder:
769                 a = new RS_ActionCamReorder(*doc, *gv);
770                 break;
771 #endif
772
773         default:
774                 RS_DEBUG->print(RS_Debug::D_WARNING,
775                         "QG_ActionHandler::setCurrentAction(): No such action found.");
776                 break;
777         }
778
779         if (a != NULL)
780                 gv->setCurrentAction(a);
781
782         RS_DEBUG->print("QG_ActionHandler::setCurrentAction(): OK");
783
784         return a;
785 }
786
787 /**
788  * @return Available commands of the application or the current action.
789  */
790 QStringList QG_ActionHandler::getAvailableCommands()
791 {
792         RS_ActionInterface * currentAction = getCurrentAction();
793
794         if (currentAction != NULL)
795                 return currentAction->getAvailableCommands();
796         else
797         {
798                 QStringList cmd;
799                 cmd += "line";
800                 cmd += "rectangle";
801                 return cmd;
802         }
803 }
804
805 /**
806  * Launches the command represented by the given keycode if possible.
807  *
808  * @return true: the command was recognized.
809  *         false: the command is not known and was probably intended for a
810  *            running action.
811  */
812 bool QG_ActionHandler::keycode(const QString & code)
813 {
814         QString c = code.toLower();
815
816         // pass keycode on to running action:
817         //RS_keycodeEvent e(cmd);
818
819         //RS_GraphicView* gv = mainWindow->getGraphicView();
820         //if (gv!=NULL) {
821         //    gv->keycodeEvent(&e);
822         //}
823
824         // if the current action can't deal with the keycode,
825         //   it might be intended to launch a new keycode
826         //if (!e.isAccepted()) {
827         // keycode for new action:
828         RS2::ActionType type = RS_COMMANDS->keycodeToAction(code);
829         if (type != RS2::ActionNone)
830         {
831                 // some actions require special handling (GUI update):
832                 switch (type)
833                 {
834                 case RS2::ActionSnapFree:
835                         slotSnapFree();
836                         break;
837                 case RS2::ActionSnapGrid:
838                         slotSnapGrid();
839                         break;
840                 case RS2::ActionSnapEndpoint:
841                         slotSnapEndpoint();
842                         break;
843                 case RS2::ActionSnapOnEntity:
844                         slotSnapOnEntity();
845                         break;
846                 case RS2::ActionSnapCenter:
847                         slotSnapCenter();
848                         break;
849                 case RS2::ActionSnapMiddle:
850                         slotSnapMiddle();
851                         break;
852                 case RS2::ActionSnapDist:
853                         slotSnapDist();
854                         break;
855                 case RS2::ActionSnapIntersection:
856                         slotSnapIntersection();
857                         break;
858                 case RS2::ActionSnapIntersectionManual:
859                         slotSnapIntersectionManual();
860                         break;
861
862                 case RS2::ActionRestrictNothing:
863                         slotRestrictNothing();
864                         break;
865                 case RS2::ActionRestrictOrthogonal:
866                         slotRestrictOrthogonal();
867                         break;
868                 case RS2::ActionRestrictHorizontal:
869                         slotRestrictHorizontal();
870                         break;
871                 case RS2::ActionRestrictVertical:
872                         slotRestrictVertical();
873                         break;
874
875                 default:
876                         setCurrentAction(type);
877                         break;
878                 }
879                 return true;
880         }
881         //}
882
883         return false;
884 }
885
886 /**
887  * Launches the given command if possible.
888  *
889  * @return true: the command was recognized.
890  *         false: the command is not known and was probably intended for a
891  *            running action.
892  */
893 bool QG_ActionHandler::command(const QString & cmd)
894 {
895         RS_DEBUG->print("QG_ActionHandler::command: %s", cmd.toLatin1().data());
896         QString c = cmd.toLower();
897
898         if (c == "\n")
899         {
900                 RS_GraphicView * gv = mainWindow->getGraphicView();
901
902                 if (gv != NULL)
903                         gv->back();
904
905                 RS_DEBUG->print("QG_ActionHandler::command: back");
906                 return true;
907         }
908
909         // pass command on to running action:
910         RS_CommandEvent e(cmd);
911
912         RS_GraphicView * gv = mainWindow->getGraphicView();
913
914         if (gv != NULL)
915         {
916                 RS_DEBUG->print("QG_ActionHandler::command: trigger command event in graphic view");
917                 gv->commandEvent(&e);
918         }
919
920         // if the current action can't deal with the command,
921         //   it might be intended to launch a new command
922         if (!e.isAccepted())
923         {
924                 RS_DEBUG->print("QG_ActionHandler::command: convert cmd to action type");
925                 // command for new action:
926                 RS2::ActionType type = RS_COMMANDS->cmdToAction(cmd);
927
928                 if (type != RS2::ActionNone)
929                 {
930                         RS_DEBUG->print("QG_ActionHandler::command: setting current action");
931                         setCurrentAction(type);
932                         RS_DEBUG->print("QG_ActionHandler::command: current action set");
933                         return true;
934                 }
935         }
936
937         RS_DEBUG->print("QG_ActionHandler::command: current action not set");
938         return false;
939 }
940
941 //void QG_ActionHandler::slotFileNew() {
942 //      setCurrentAction(RS2::ActionFileNew);
943 //}
944
945 void QG_ActionHandler::slotFileOpen()
946 {
947         setCurrentAction(RS2::ActionFileOpen);
948 }
949 /*
950 void QG_ActionHandler::slotFileSave() {
951         setCurrentAction(RS2::ActionFileSave);
952 }
953 */
954
955 void QG_ActionHandler::slotFileSaveAs()
956 {
957         setCurrentAction(RS2::ActionFileSaveAs);
958 }
959
960 /*
961 void QG_ActionHandler::slotFileClose()
962 {
963         setCurrentAction(RS2::ActionFileClose);
964 }
965
966 void QG_ActionHandler::slotFilePrint()
967 {
968         setCurrentAction(RS2::ActionFilePrint);
969 }
970 */
971
972 void QG_ActionHandler::slotZoomIn()
973 {
974         setCurrentAction(RS2::ActionZoomIn);
975 }
976
977 void QG_ActionHandler::slotZoomOut()
978 {
979         setCurrentAction(RS2::ActionZoomOut);
980 }
981
982 void QG_ActionHandler::slotZoomAuto()
983 {
984         setCurrentAction(RS2::ActionZoomAuto);
985 }
986
987 void QG_ActionHandler::slotZoomWindow()
988 {
989         setCurrentAction(RS2::ActionZoomWindow);
990 }
991
992 void QG_ActionHandler::slotZoomPan()
993 {
994         setCurrentAction(RS2::ActionZoomPan);
995 }
996
997 void QG_ActionHandler::slotZoomPrevious()
998 {
999         setCurrentAction(RS2::ActionZoomPrevious);
1000 }
1001
1002 void QG_ActionHandler::slotZoomRedraw()
1003 {
1004         setCurrentAction(RS2::ActionZoomRedraw);
1005 }
1006
1007 void QG_ActionHandler::slotToolRegenerateDimensions()
1008 {
1009         setCurrentAction(RS2::ActionToolRegenerateDimensions);
1010 }
1011
1012 void QG_ActionHandler::slotEditUndo()
1013 {
1014         setCurrentAction(RS2::ActionEditUndo);
1015 }
1016
1017 void QG_ActionHandler::slotEditRedo()
1018 {
1019         setCurrentAction(RS2::ActionEditRedo);
1020 }
1021
1022 void QG_ActionHandler::slotEditCut()
1023 {
1024         setCurrentAction(RS2::ActionEditCut);
1025 }
1026
1027 void QG_ActionHandler::slotEditCopy()
1028 {
1029         setCurrentAction(RS2::ActionEditCopy);
1030 }
1031
1032 void QG_ActionHandler::slotEditPaste()
1033 {
1034         setCurrentAction(RS2::ActionEditPaste);
1035 }
1036
1037 void QG_ActionHandler::slotSelectSingle()
1038 {
1039         setCurrentAction(RS2::ActionSelectSingle);
1040 }
1041
1042 void QG_ActionHandler::slotSelectContour()
1043 {
1044         setCurrentAction(RS2::ActionSelectContour);
1045 }
1046
1047 void QG_ActionHandler::slotSelectWindow()
1048 {
1049         setCurrentAction(RS2::ActionSelectWindow);
1050 }
1051
1052 void QG_ActionHandler::slotDeselectWindow()
1053 {
1054         setCurrentAction(RS2::ActionDeselectWindow);
1055 }
1056
1057 void QG_ActionHandler::slotSelectAll()
1058 {
1059         setCurrentAction(RS2::ActionSelectAll);
1060 }
1061
1062 void QG_ActionHandler::slotDeselectAll()
1063 {
1064         setCurrentAction(RS2::ActionDeselectAll);
1065 }
1066
1067 void QG_ActionHandler::slotSelectInvert()
1068 {
1069         setCurrentAction(RS2::ActionSelectInvert);
1070 }
1071
1072 void QG_ActionHandler::slotSelectIntersected()
1073 {
1074         setCurrentAction(RS2::ActionSelectIntersected);
1075 }
1076
1077 void QG_ActionHandler::slotDeselectIntersected()
1078 {
1079         setCurrentAction(RS2::ActionDeselectIntersected);
1080 }
1081
1082 void QG_ActionHandler::slotSelectLayer()
1083 {
1084         setCurrentAction(RS2::ActionSelectLayer);
1085 }
1086
1087 void QG_ActionHandler::slotDrawPoint()
1088 {
1089         setCurrentAction(RS2::ActionDrawPoint);
1090 }
1091
1092 void QG_ActionHandler::slotDrawLine()
1093 {
1094         setCurrentAction(RS2::ActionDrawLine);
1095 }
1096
1097 void QG_ActionHandler::slotDrawLineAngle()
1098 {
1099         setCurrentAction(RS2::ActionDrawLineAngle);
1100 }
1101
1102 void QG_ActionHandler::slotDrawLineHorizontal()
1103 {
1104         setCurrentAction(RS2::ActionDrawLineHorizontal);
1105 }
1106
1107 void QG_ActionHandler::slotDrawLineHorVert()
1108 {
1109         setCurrentAction(RS2::ActionDrawLineHorVert);
1110 }
1111
1112 void QG_ActionHandler::slotDrawLineVertical()
1113 {
1114         setCurrentAction(RS2::ActionDrawLineVertical);
1115 }
1116
1117 void QG_ActionHandler::slotDrawLineFree()
1118 {
1119         setCurrentAction(RS2::ActionDrawLineFree);
1120 }
1121
1122 void QG_ActionHandler::slotDrawLineParallel()
1123 {
1124         setCurrentAction(RS2::ActionDrawLineParallel);
1125 }
1126
1127 void QG_ActionHandler::slotDrawLineParallelThrough()
1128 {
1129         setCurrentAction(RS2::ActionDrawLineParallelThrough);
1130 }
1131
1132 void QG_ActionHandler::slotDrawLineRectangle()
1133 {
1134         setCurrentAction(RS2::ActionDrawLineRectangle);
1135 }
1136
1137 void QG_ActionHandler::slotDrawLineBisector()
1138 {
1139         setCurrentAction(RS2::ActionDrawLineBisector);
1140 }
1141
1142 void QG_ActionHandler::slotDrawLineTangent1()
1143 {
1144         setCurrentAction(RS2::ActionDrawLineTangent1);
1145 }
1146
1147 void QG_ActionHandler::slotDrawLineTangent2()
1148 {
1149         setCurrentAction(RS2::ActionDrawLineTangent2);
1150 }
1151
1152 void QG_ActionHandler::slotDrawLineOrthogonal()
1153 {
1154         setCurrentAction(RS2::ActionDrawLineOrthogonal);
1155 }
1156
1157 void QG_ActionHandler::slotDrawLineRelAngle()
1158 {
1159         setCurrentAction(RS2::ActionDrawLineRelAngle);
1160 }
1161
1162 void QG_ActionHandler::slotDrawPolyline()
1163 {
1164         setCurrentAction(RS2::ActionDrawPolyline);
1165 }
1166
1167 void QG_ActionHandler::slotPolylineAdd()
1168 {
1169         setCurrentAction(RS2::ActionPolylineAdd);
1170 }
1171
1172 void QG_ActionHandler::slotPolylineAppend()
1173 {
1174         setCurrentAction(RS2::ActionPolylineAppend);
1175 }
1176
1177 void QG_ActionHandler::slotPolylineDel()
1178 {
1179         setCurrentAction(RS2::ActionPolylineDel);
1180 }
1181
1182 void QG_ActionHandler::slotPolylineDelBetween()
1183 {
1184         setCurrentAction(RS2::ActionPolylineDelBetween);
1185 }
1186
1187 void QG_ActionHandler::slotPolylineTrim()
1188 {
1189         setCurrentAction(RS2::ActionPolylineTrim);
1190 }
1191
1192 void QG_ActionHandler::slotDrawLinePolygon()
1193 {
1194         setCurrentAction(RS2::ActionDrawLinePolygon);
1195 }
1196
1197 void QG_ActionHandler::slotDrawLinePolygon2()
1198 {
1199         setCurrentAction(RS2::ActionDrawLinePolygon2);
1200 }
1201
1202 void QG_ActionHandler::slotDrawCircle()
1203 {
1204         setCurrentAction(RS2::ActionDrawCircle);
1205 }
1206
1207 void QG_ActionHandler::slotDrawCircleCR()
1208 {
1209         setCurrentAction(RS2::ActionDrawCircleCR);
1210 }
1211
1212 void QG_ActionHandler::slotDrawCircle2P()
1213 {
1214         setCurrentAction(RS2::ActionDrawCircle2P);
1215 }
1216
1217 void QG_ActionHandler::slotDrawCircle3P()
1218 {
1219         setCurrentAction(RS2::ActionDrawCircle3P);
1220 }
1221
1222 void QG_ActionHandler::slotDrawCircleParallel()
1223 {
1224         setCurrentAction(RS2::ActionDrawCircleParallel);
1225 }
1226
1227 void QG_ActionHandler::slotDrawArc()
1228 {
1229         setCurrentAction(RS2::ActionDrawArc);
1230 }
1231
1232 void QG_ActionHandler::slotDrawArc3P()
1233 {
1234         setCurrentAction(RS2::ActionDrawArc3P);
1235 }
1236
1237 void QG_ActionHandler::slotDrawArcParallel()
1238 {
1239         setCurrentAction(RS2::ActionDrawArcParallel);
1240 }
1241
1242 void QG_ActionHandler::slotDrawArcTangential()
1243 {
1244         setCurrentAction(RS2::ActionDrawArcTangential);
1245 }
1246
1247 void QG_ActionHandler::slotDrawEllipseAxis()
1248 {
1249         setCurrentAction(RS2::ActionDrawEllipseAxis);
1250 }
1251
1252 void QG_ActionHandler::slotDrawEllipseArcAxis()
1253 {
1254         setCurrentAction(RS2::ActionDrawEllipseArcAxis);
1255 }
1256
1257 void QG_ActionHandler::slotDrawSpline()
1258 {
1259         setCurrentAction(RS2::ActionDrawSpline);
1260 }
1261
1262 void QG_ActionHandler::slotDrawText()
1263 {
1264         setCurrentAction(RS2::ActionDrawText);
1265 }
1266
1267 void QG_ActionHandler::slotDrawHatch()
1268 {
1269         setCurrentAction(RS2::ActionDrawHatch);
1270 }
1271
1272 void QG_ActionHandler::slotDrawImage()
1273 {
1274         setCurrentAction(RS2::ActionDrawImage);
1275 }
1276
1277 void QG_ActionHandler::slotDimAligned()
1278 {
1279         setCurrentAction(RS2::ActionDimAligned);
1280 }
1281
1282 void QG_ActionHandler::slotDimLinear()
1283 {
1284         setCurrentAction(RS2::ActionDimLinear);
1285 }
1286
1287 void QG_ActionHandler::slotDimLinearHor()
1288 {
1289         setCurrentAction(RS2::ActionDimLinearHor);
1290 }
1291
1292 void QG_ActionHandler::slotDimLinearVer()
1293 {
1294         setCurrentAction(RS2::ActionDimLinearVer);
1295 }
1296
1297 void QG_ActionHandler::slotDimRadial()
1298 {
1299         setCurrentAction(RS2::ActionDimRadial);
1300 }
1301
1302 void QG_ActionHandler::slotDimDiametric()
1303 {
1304         setCurrentAction(RS2::ActionDimDiametric);
1305 }
1306
1307 void QG_ActionHandler::slotDimAngular()
1308 {
1309         setCurrentAction(RS2::ActionDimAngular);
1310 }
1311
1312 void QG_ActionHandler::slotDimLeader()
1313 {
1314         setCurrentAction(RS2::ActionDimLeader);
1315 }
1316
1317
1318 void QG_ActionHandler::slotModifyAttributes()
1319 {
1320         setCurrentAction(RS2::ActionModifyAttributes);
1321 }
1322
1323 void QG_ActionHandler::slotModifyDelete()
1324 {
1325         setCurrentAction(RS2::ActionModifyDelete);
1326 }
1327
1328 void QG_ActionHandler::slotModifyDeleteQuick()
1329 {
1330         //setCurrentAction(RS2::ActionModifyDeleteQuick);
1331         setCurrentAction(RS2::ActionModifyDeleteNoSelect);
1332 }
1333
1334 void QG_ActionHandler::slotModifyDeleteFree()
1335 {
1336         setCurrentAction(RS2::ActionModifyDeleteFree);
1337 }
1338
1339 void QG_ActionHandler::slotModifyMove()
1340 {
1341         setCurrentAction(RS2::ActionModifyMove);
1342 }
1343
1344 void QG_ActionHandler::slotModifyRotate()
1345 {
1346         setCurrentAction(RS2::ActionModifyRotate);
1347 }
1348
1349 void QG_ActionHandler::slotModifyScale()
1350 {
1351         setCurrentAction(RS2::ActionModifyScale);
1352 }
1353
1354 void QG_ActionHandler::slotModifyStretch()
1355 {
1356         setCurrentAction(RS2::ActionModifyStretch);
1357 }
1358
1359 void QG_ActionHandler::slotModifyBevel()
1360 {
1361         setCurrentAction(RS2::ActionModifyBevel);
1362 }
1363
1364 void QG_ActionHandler::slotModifyRound()
1365 {
1366         setCurrentAction(RS2::ActionModifyRound);
1367 }
1368
1369 void QG_ActionHandler::slotModifyMirror()
1370 {
1371         setCurrentAction(RS2::ActionModifyMirror);
1372 }
1373
1374 void QG_ActionHandler::slotModifyMoveRotate()
1375 {
1376         setCurrentAction(RS2::ActionModifyMoveRotate);
1377 }
1378
1379 void QG_ActionHandler::slotModifyRotate2()
1380 {
1381         setCurrentAction(RS2::ActionModifyRotate2);
1382 }
1383
1384 void QG_ActionHandler::slotModifyEntity()
1385 {
1386         setCurrentAction(RS2::ActionModifyEntity);
1387 }
1388
1389 void QG_ActionHandler::slotModifyTrim()
1390 {
1391         setCurrentAction(RS2::ActionModifyTrim);
1392 }
1393
1394 void QG_ActionHandler::slotModifyTrim2()
1395 {
1396         setCurrentAction(RS2::ActionModifyTrim2);
1397 }
1398
1399 void QG_ActionHandler::slotModifyTrimAmount()
1400 {
1401         setCurrentAction(RS2::ActionModifyTrimAmount);
1402 }
1403
1404 void QG_ActionHandler::slotModifyCut()
1405 {
1406         setCurrentAction(RS2::ActionModifyCut);
1407 }
1408
1409 void QG_ActionHandler::slotModifyExplodeText()
1410 {
1411         setCurrentAction(RS2::ActionModifyExplodeText);
1412 }
1413
1414
1415 void QG_ActionHandler::slotSnapFree()
1416 {
1417         disableSnaps();
1418
1419         if (snapFree != NULL)
1420                 snapFree->setChecked(true);
1421
1422         if (cadToolBarSnap != NULL)
1423                 cadToolBarSnap->setSnapMode(RS2::SnapFree);
1424
1425         setCurrentAction(RS2::ActionSnapFree);
1426 }
1427
1428 void QG_ActionHandler::slotSnapGrid()
1429 {
1430         disableSnaps();
1431
1432         if (snapGrid != NULL)
1433                 snapGrid->setChecked(true);
1434
1435         if (cadToolBarSnap != NULL)
1436                 cadToolBarSnap->setSnapMode(RS2::SnapGrid);
1437
1438         setCurrentAction(RS2::ActionSnapGrid);
1439 }
1440
1441 void QG_ActionHandler::slotSnapEndpoint()
1442 {
1443         disableSnaps();
1444
1445         if (snapEndpoint != NULL)
1446                 snapEndpoint->setChecked(true);
1447
1448         if (cadToolBarSnap != NULL)
1449                 cadToolBarSnap->setSnapMode(RS2::SnapEndpoint);
1450
1451         setCurrentAction(RS2::ActionSnapEndpoint);
1452 }
1453
1454 void QG_ActionHandler::slotSnapOnEntity()
1455 {
1456         disableSnaps();
1457         if (snapOnEntity!=NULL) {
1458                 snapOnEntity->setChecked(true);
1459         }
1460 //#if QT_VERSION>=0x030000
1461         if (cadToolBarSnap!=NULL) {
1462                 cadToolBarSnap->setSnapMode(RS2::SnapOnEntity);
1463         }
1464 //#endif
1465         setCurrentAction(RS2::ActionSnapOnEntity);
1466 }
1467
1468 void QG_ActionHandler::slotSnapCenter()
1469 {
1470         disableSnaps();
1471
1472         if (snapCenter != NULL)
1473                 snapCenter->setChecked(true);
1474
1475 //#if QT_VERSION>=0x030000
1476         if (cadToolBarSnap != NULL)
1477                 cadToolBarSnap->setSnapMode(RS2::SnapCenter);
1478 //#endif
1479
1480         setCurrentAction(RS2::ActionSnapCenter);
1481 }
1482
1483 void QG_ActionHandler::slotSnapMiddle()
1484 {
1485         disableSnaps();
1486
1487         if (snapMiddle != NULL)
1488                 snapMiddle->setChecked(true);
1489
1490 //#if QT_VERSION>=0x030000
1491         if (cadToolBarSnap != NULL)
1492                 cadToolBarSnap->setSnapMode(RS2::SnapMiddle);
1493 //#endif
1494
1495         setCurrentAction(RS2::ActionSnapMiddle);
1496 }
1497
1498 void QG_ActionHandler::slotSnapDist()
1499 {
1500         disableSnaps();
1501
1502         if (snapDist != NULL)
1503                 snapDist->setChecked(true);
1504
1505 //#if QT_VERSION>=0x030000
1506         if (cadToolBarSnap != NULL)
1507                 cadToolBarSnap->setSnapMode(RS2::SnapDist);
1508 //#endif
1509
1510         setCurrentAction(RS2::ActionSnapDist);
1511 }
1512
1513 void QG_ActionHandler::slotSnapIntersection()
1514 {
1515         disableSnaps();
1516
1517         if (snapIntersection != NULL)
1518                 snapIntersection->setChecked(true);
1519
1520 //#if QT_VERSION>=0x030000
1521         if (cadToolBarSnap != NULL)
1522                 cadToolBarSnap->setSnapMode(RS2::SnapIntersection);
1523 //#endif
1524
1525         setCurrentAction(RS2::ActionSnapIntersection);
1526 }
1527
1528 void QG_ActionHandler::slotSnapIntersectionManual()
1529 {
1530         //disableSnaps();
1531         /*if (snapIntersectionManual!=NULL) {
1532                 snapIntersectionManual->setChecked(true);
1533 }*/
1534         /*if (cadToolBarSnap!=NULL) {
1535                 cadToolBarSnap->setSnapMode(RS2::SnapIntersectionManual);
1536 }*/
1537         setCurrentAction(RS2::ActionSnapIntersectionManual);
1538 }
1539
1540 void QG_ActionHandler::disableSnaps()
1541 {
1542         if (snapFree != NULL)
1543                 snapFree->setChecked(false);
1544
1545         if (snapGrid != NULL)
1546                 snapGrid->setChecked(false);
1547
1548         if (snapEndpoint != NULL)
1549                 snapEndpoint->setChecked(false);
1550
1551         if (snapOnEntity != NULL)
1552                 snapOnEntity->setChecked(false);
1553
1554         if (snapCenter != NULL)
1555                 snapCenter->setChecked(false);
1556
1557         if (snapMiddle != NULL)
1558                 snapMiddle->setChecked(false);
1559
1560         if (snapDist != NULL)
1561                 snapDist->setChecked(false);
1562
1563         if (snapIntersection != NULL)
1564                 snapIntersection->setChecked(false);
1565
1566         if (snapIntersectionManual != NULL)
1567                 snapIntersectionManual->setChecked(false);
1568
1569         if (cadToolBarSnap != NULL)
1570                 cadToolBarSnap->disableSnaps();
1571 }
1572
1573 void QG_ActionHandler::slotRestrictNothing()
1574 {
1575         disableRestrictions();
1576
1577         if (restrictNothing != NULL)
1578                 restrictNothing->setChecked(true);
1579
1580         if (cadToolBarSnap != NULL)
1581                 cadToolBarSnap->setSnapRestriction(RS2::RestrictNothing);
1582
1583         setCurrentAction(RS2::ActionRestrictNothing);
1584 }
1585
1586 void QG_ActionHandler::slotRestrictOrthogonal()
1587 {
1588         disableRestrictions();
1589
1590         if (restrictOrthogonal != NULL)
1591                 restrictOrthogonal->setChecked(true);
1592
1593         if (cadToolBarSnap != NULL)
1594                 cadToolBarSnap->setSnapRestriction(RS2::RestrictOrthogonal);
1595
1596         setCurrentAction(RS2::ActionRestrictOrthogonal);
1597 }
1598
1599 void QG_ActionHandler::slotRestrictHorizontal()
1600 {
1601         disableRestrictions();
1602
1603         if (restrictHorizontal != NULL)
1604                 restrictHorizontal->setChecked(true);
1605
1606         if (cadToolBarSnap != NULL)
1607                 cadToolBarSnap->setSnapRestriction(RS2::RestrictHorizontal);
1608
1609         setCurrentAction(RS2::ActionRestrictHorizontal);
1610 }
1611
1612 void QG_ActionHandler::slotRestrictVertical()
1613 {
1614         disableRestrictions();
1615
1616         if (restrictVertical != NULL)
1617                 restrictVertical->setChecked(true);
1618
1619         if (cadToolBarSnap != NULL)
1620                 cadToolBarSnap->setSnapRestriction(RS2::RestrictVertical);
1621
1622         setCurrentAction(RS2::ActionRestrictVertical);
1623 }
1624
1625 void QG_ActionHandler::disableRestrictions()
1626 {
1627         if (restrictNothing != NULL)
1628                 restrictNothing->setChecked(false);
1629
1630         if (restrictOrthogonal != NULL)
1631                 restrictOrthogonal->setChecked(false);
1632
1633         if (restrictHorizontal != NULL)
1634                 restrictHorizontal->setChecked(false);
1635
1636         if (restrictVertical != NULL)
1637                 restrictVertical->setChecked(false);
1638
1639         if (cadToolBarSnap != NULL)
1640                 cadToolBarSnap->disableRestrictions();
1641 }
1642
1643 /**
1644  * Updates the snap mode for the current document from the selected menu.
1645  * Used after the active window changed.
1646  */
1647 void QG_ActionHandler::updateSnapMode()
1648 {
1649         if (snapFree != NULL && snapFree->isChecked())
1650                 slotSnapFree();
1651         else if (snapGrid != NULL && snapGrid->isChecked())
1652                 slotSnapGrid();
1653         else if (snapEndpoint != NULL && snapEndpoint->isChecked())
1654                 slotSnapEndpoint();
1655         else if (snapOnEntity != NULL && snapOnEntity->isChecked())
1656                 slotSnapOnEntity();
1657         else if (snapCenter != NULL && snapCenter->isChecked())
1658                 slotSnapCenter();
1659         else if (snapMiddle != NULL && snapMiddle->isChecked())
1660                 slotSnapMiddle();
1661         else if (snapDist != NULL && snapDist->isChecked())
1662                 slotSnapDist();
1663         else if (snapIntersection != NULL && snapIntersection->isChecked())
1664                 slotSnapIntersection();
1665
1666         // snap restricitons:
1667         if (restrictNothing != NULL && restrictNothing->isChecked())
1668                 slotRestrictNothing();
1669         else if (restrictOrthogonal != NULL && restrictOrthogonal->isChecked())
1670                 slotRestrictOrthogonal();
1671         else if (restrictHorizontal != NULL && restrictHorizontal->isChecked())
1672                 slotRestrictHorizontal();
1673         else if (restrictVertical != NULL && restrictVertical->isChecked())
1674                 slotRestrictVertical();
1675
1676         // lock of relative zero:
1677         if (lockRelativeZero != NULL)
1678                 slotLockRelativeZero(lockRelativeZero->isChecked());
1679 }
1680
1681 void QG_ActionHandler::slotSetRelativeZero()
1682 {
1683         setCurrentAction(RS2::ActionSetRelativeZero);
1684 }
1685
1686 void QG_ActionHandler::slotLockRelativeZero(bool on)
1687 {
1688         if (lockRelativeZero != NULL)
1689                 lockRelativeZero->setChecked(on);
1690
1691         if (on)
1692                 setCurrentAction(RS2::ActionLockRelativeZero);
1693         else
1694                 setCurrentAction(RS2::ActionUnlockRelativeZero);
1695
1696         if (cadToolBarSnap != NULL)
1697                 cadToolBarSnap->setLockRelativeZero(on);
1698 }
1699
1700 void QG_ActionHandler::slotInfoInside()
1701 {
1702         setCurrentAction(RS2::ActionInfoInside);
1703 }
1704
1705 void QG_ActionHandler::slotInfoDist()
1706 {
1707         setCurrentAction(RS2::ActionInfoDist);
1708 }
1709
1710 void QG_ActionHandler::slotInfoDist2()
1711 {
1712         setCurrentAction(RS2::ActionInfoDist2);
1713 }
1714
1715 void QG_ActionHandler::slotInfoAngle()
1716 {
1717         setCurrentAction(RS2::ActionInfoAngle);
1718 }
1719
1720 void QG_ActionHandler::slotInfoTotalLength()
1721 {
1722         setCurrentAction(RS2::ActionInfoTotalLength);
1723 }
1724
1725 void QG_ActionHandler::slotInfoArea()
1726 {
1727         setCurrentAction(RS2::ActionInfoArea);
1728 }
1729
1730 void QG_ActionHandler::slotLayersDefreezeAll()
1731 {
1732         setCurrentAction(RS2::ActionLayersDefreezeAll);
1733 }
1734
1735 void QG_ActionHandler::slotLayersFreezeAll()
1736 {
1737         setCurrentAction(RS2::ActionLayersFreezeAll);
1738 }
1739
1740 void QG_ActionHandler::slotLayersAdd()
1741 {
1742         setCurrentAction(RS2::ActionLayersAdd);
1743 }
1744
1745 void QG_ActionHandler::slotLayersRemove()
1746 {
1747         setCurrentAction(RS2::ActionLayersRemove);
1748 }
1749
1750 void QG_ActionHandler::slotLayersEdit()
1751 {
1752         setCurrentAction(RS2::ActionLayersEdit);
1753 }
1754
1755 void QG_ActionHandler::slotLayersToggleView()
1756 {
1757         setCurrentAction(RS2::ActionLayersToggleView);
1758 }
1759
1760 void QG_ActionHandler::slotLayersToggleLock()
1761 {
1762         setCurrentAction(RS2::ActionLayersToggleLock);
1763 }
1764
1765
1766 void QG_ActionHandler::slotBlocksDefreezeAll()
1767 {
1768         setCurrentAction(RS2::ActionBlocksDefreezeAll);
1769 }
1770
1771 void QG_ActionHandler::slotBlocksFreezeAll()
1772 {
1773         setCurrentAction(RS2::ActionBlocksFreezeAll);
1774 }
1775
1776 void QG_ActionHandler::slotBlocksAdd()
1777 {
1778         setCurrentAction(RS2::ActionBlocksAdd);
1779 }
1780
1781 void QG_ActionHandler::slotBlocksRemove()
1782 {
1783         setCurrentAction(RS2::ActionBlocksRemove);
1784 }
1785
1786 void QG_ActionHandler::slotBlocksAttributes()
1787 {
1788         setCurrentAction(RS2::ActionBlocksAttributes);
1789 }
1790
1791 void QG_ActionHandler::slotBlocksEdit()
1792 {
1793         setCurrentAction(RS2::ActionBlocksEdit);
1794 }
1795
1796 void QG_ActionHandler::slotBlocksInsert()
1797 {
1798         setCurrentAction(RS2::ActionBlocksInsert);
1799 }
1800
1801 void QG_ActionHandler::slotBlocksToggleView()
1802 {
1803         setCurrentAction(RS2::ActionBlocksToggleView);
1804 }
1805
1806 void QG_ActionHandler::slotBlocksCreate()
1807 {
1808         setCurrentAction(RS2::ActionBlocksCreate);
1809 }
1810
1811 void QG_ActionHandler::slotBlocksExplode()
1812 {
1813         setCurrentAction(RS2::ActionBlocksExplode);
1814 }
1815
1816
1817 void QG_ActionHandler::slotOptionsDrawing()
1818 {
1819         setCurrentAction(RS2::ActionOptionsDrawing);
1820 }
1821
1822 void QG_ActionHandler::slotCamExportAuto()
1823 {
1824 #ifdef RS_CAM
1825         setCurrentAction(RS2::ActionCamExportAuto);
1826 #endif
1827 }
1828
1829 void QG_ActionHandler::slotCamReorder()
1830 {
1831 #ifdef RS_CAM
1832         setCurrentAction(RS2::ActionCamReorder);
1833 #endif
1834 }
1835
1836 void QG_ActionHandler::slotFocusNormal()
1837 {
1838         //QG_GraphicView* gv = mainWindow->getGraphicView();
1839         //if (gv!=NULL) {
1840                 //gv->setFocus();
1841         mainWindow->setFocus2();
1842         //}
1843 }
1844
1845 void QG_ActionHandler::setActionSnapFree(QAction * a)
1846 {
1847         snapFree = a;
1848 }
1849
1850 void QG_ActionHandler::setActionSnapGrid(QAction * a)
1851 {
1852         snapGrid = a;
1853 }
1854
1855 void QG_ActionHandler::setActionSnapEndpoint(QAction * a)
1856 {
1857         snapEndpoint = a;
1858 }
1859
1860 void QG_ActionHandler::setActionSnapOnEntity(QAction * a)
1861 {
1862         snapOnEntity = a;
1863 }
1864
1865 void QG_ActionHandler::setActionSnapCenter(QAction * a)
1866 {
1867         snapCenter = a;
1868 }
1869
1870 void QG_ActionHandler::setActionSnapMiddle(QAction * a)
1871 {
1872         snapMiddle = a;
1873 }
1874
1875 void QG_ActionHandler::setActionSnapDist(QAction * a)
1876 {
1877         snapDist = a;
1878 }
1879
1880 void QG_ActionHandler::setActionSnapIntersection(QAction * a)
1881 {
1882         snapIntersection = a;
1883 }
1884
1885 void QG_ActionHandler::setActionSnapIntersectionManual(QAction * a)
1886 {
1887         snapIntersectionManual = a;
1888 }
1889
1890 void QG_ActionHandler::setActionRestrictNothing(QAction * a)
1891 {
1892         restrictNothing = a;
1893 }
1894
1895 void QG_ActionHandler::setActionRestrictOrthogonal(QAction * a)
1896 {
1897         restrictOrthogonal = a;
1898 }
1899
1900 void QG_ActionHandler::setActionRestrictHorizontal(QAction * a)
1901 {
1902         restrictHorizontal = a;
1903 }
1904
1905 void QG_ActionHandler::setActionRestrictVertical(QAction * a)
1906 {
1907         restrictVertical = a;
1908 }
1909
1910 void QG_ActionHandler::setActionLockRelativeZero(QAction * a)
1911 {
1912         lockRelativeZero = a;
1913 }
1914
1915 /**
1916  * Creates link to snap tool bar so we can update the button
1917  * state if the snapping action changes.
1918  */
1919 void QG_ActionHandler::setCadToolBarSnap(CadToolBarSnap * tb)
1920 {
1921         cadToolBarSnap = tb;
1922 }