]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actioninfototallength.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actioninfototallength.cpp
1 // rs_actioninfototallength.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  06/04/2010  Added this text. :-)
13 //
14
15 #include "rs_actioninfototallength.h"
16
17 #include "rs_dialogfactory.h"
18
19 RS_ActionInfoTotalLength::RS_ActionInfoTotalLength(RS_EntityContainer & container, RS_GraphicView & graphicView): RS_ActionInterface("Info Total Length",
20                 container, graphicView)
21 {
22 }
23
24 RS_ActionInfoTotalLength::~RS_ActionInfoTotalLength()
25 {
26 }
27
28 void RS_ActionInfoTotalLength::init(int status)
29 {
30         RS_ActionInterface::init(status);
31         trigger();
32 }
33
34 void RS_ActionInfoTotalLength::trigger()
35 {
36         RS_DEBUG->print("RS_ActionInfoTotalLength::trigger()");
37
38         double len = 0.0;
39
40         for (RS_Entity * e = container->firstEntity(RS2::ResolveNone);
41              e != NULL;
42              e = container->nextEntity(RS2::ResolveNone))
43
44                 if (e->isVisible() && e->isSelected())
45                 {
46                         double l = e->getLength();
47
48                         if (l < 0.0)
49                         {
50                                 len = -1.0;
51                                 break;
52                         }
53                         else
54                                 len += l;
55                 }
56
57         if (len > 0.0)
58                 RS_DIALOGFACTORY->commandMessage(
59                         tr("Total Length of selected entities: %1").arg(len));
60         else
61                 RS_DIALOGFACTORY->commandMessage(tr("At least one of the selected "
62                                 "entities cannot be measured."));
63
64         finish();
65 }
66
67 void RS_ActionInfoTotalLength::updateToolBar()
68 {
69         if (RS_DIALOGFACTORY != NULL)
70         {
71                 if (!isFinished())
72                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarInfo);
73                 else
74                         RS_DIALOGFACTORY->requestToolBar(RS2::ToolBarMain);
75         }
76 }
77
78 // EOF