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