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