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