]> Shamusworld >> Repos - architektonas/blob - src/actions/rs_actionblocksremove.cpp
Major refactoring of actions: Moved implementation from header files
[architektonas] / src / actions / rs_actionblocksremove.cpp
1 // rs_actionblocksremove.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/03/2010  Added this text. :-)
13 //
14
15 #include "rs_actionblocksremove.h"
16
17 #include "rs_block.h"
18 #include "rs_dialogfactory.h"
19 #include "drawing.h"
20 #include "rs_graphicview.h"
21 #include "rs_insert.h"
22
23 RS_ActionBlocksRemove::RS_ActionBlocksRemove(RS_EntityContainer & container, RS_GraphicView & graphicView):
24         RS_ActionInterface("Remove Block", container, graphicView)
25 {
26 }
27
28 RS_ActionBlocksRemove::~RS_ActionBlocksRemove()
29 {
30 }
31
32 void RS_ActionBlocksRemove::trigger()
33 {
34         RS_DEBUG->print("RS_ActionBlocksRemove::trigger");
35
36         if (graphic != NULL)
37         {
38                 RS_Block * block = RS_DIALOGFACTORY->requestBlockRemovalDialog(graphic->getBlockList());
39
40                 // list of containers that might refer to the block via inserts:
41 //        Q3PtrList<RS_EntityContainer> containerList;
42                 QList<RS_EntityContainer *> containerList;
43                 containerList.append(graphic);
44                 RS_BlockList * blkLst = graphic->getBlockList();
45
46                 for (uint bi = 0; bi < blkLst->count(); bi++)
47                         containerList.append(blkLst->at(bi));
48
49                 if (block != NULL)
50                 {
51 //                      for (RS_EntityContainer * cont=containerList.first(); cont!=NULL;
52 //                              cont=containerList.next())
53                         for (int i = 0; i < containerList.size(); i++)
54                         {
55                                 RS_EntityContainer * cont = containerList[i];
56                                 // remove all inserts from the graphic:
57                                 bool done;
58
59                                 do
60                                 {
61                                         done = true;
62
63                                         for (RS_Entity * e = cont->firstEntity(RS2::ResolveNone); e != NULL;
64                                              e = cont->nextEntity(RS2::ResolveNone))
65                                                 if (e->rtti() == RS2::EntityInsert)
66                                                 {
67                                                         RS_Insert * ins = (RS_Insert *)e;
68
69                                                         if (ins->getName() == block->getName())
70                                                         {
71                                                                 cont->removeEntity(ins);
72                                                                 done = false;
73                                                                 break;
74                                                         }
75                                                 }
76                                 }
77                                 while (!done);
78                         }
79
80                         // close all windows that are editing this block:
81                         if (RS_DIALOGFACTORY != NULL)
82                                 RS_DIALOGFACTORY->closeEditBlockWindow(block);
83
84                         // Now remove the block from the block list:
85                         graphic->removeBlock(block);
86                         graphic->updateInserts();
87                         graphicView->redraw();
88                 }
89         }
90
91         finish();
92         RS_DIALOGFACTORY->updateSelectionWidget(container->countSelected());
93 }
94
95 void RS_ActionBlocksRemove::init(int status)
96 {
97         RS_ActionInterface::init(status);
98         trigger();
99 }
100