]> Shamusworld >> Repos - architektonas/blob - src/actions/actioninfototallength.cpp
Last checkin before major refactor...
[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 // (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 "actioninfototallength.h"
16
17 #include "rs_dialogfactory.h"
18
19 ActionInfoTotalLength::ActionInfoTotalLength(RS_EntityContainer & container, GraphicView & graphicView): ActionInterface("Info Total Length",
20                 container, graphicView)
21 {
22 }
23
24 ActionInfoTotalLength::~ActionInfoTotalLength()
25 {
26 }
27
28 void ActionInfoTotalLength::init(int status)
29 {
30         ActionInterface::init(status);
31         trigger();
32 }
33
34 void ActionInfoTotalLength::trigger()
35 {
36         RS_DEBUG->print("ActionInfoTotalLength::trigger()");
37
38         double len = 0.0;
39
40         for(RS_Entity * e=container->firstEntity(RS2::ResolveNone); e!=NULL;
41                 e=container->nextEntity(RS2::ResolveNone))
42         {
43                 if (e->isVisible() && e->isSelected())
44                 {
45                         double l = e->getLength();
46
47                         if (l < 0.0)
48                         {
49                                 len = -1.0;
50                                 break;
51                         }
52                         else
53                                 len += l;
54                 }
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 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 }