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