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