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