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