1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
25
#include "diagramviewer.h"
26
#include "shapeview.h"
27
#include "deleteshapescmd.h"
29
DeleteShapesCmd::DeleteShapesCmd(ShapeView *v):
30
Command(v->GetViewer()->GetDiagram(),v->GetViewer()) {
31
shapes = new List<GShape *>(*v->GetSelection());
32
deleteSubjects = new List<Subject *>;
33
updateSubjects = new List<Subject *>;
34
diagram = v->GetViewer()->GetDiagram();
35
dviewer = v->GetViewer();
37
// add the lines connected to the shapes.
38
v->CompleteShapes(shapes);
39
List<Subject *> tmpsubjects;
40
List<GShape *> tmpshapes;
41
for (shapes->first(); !shapes->done(); shapes->next()) {
42
Subject *subject = shapes->cur()->GetSubject();
43
if (check(subject) && tmpsubjects.find(subject) == -1)
44
tmpsubjects.add(subject);
46
for (tmpsubjects.first(); !tmpsubjects.done(); tmpsubjects.next()) {
47
Subject *subject = tmpsubjects.cur();
49
dviewer->GetShapes(subject, &tmpshapes);
50
int n = tmpshapes.count();
54
// there is one shape for subject-> delete the subject.
55
deleteSubjects->add(subject);
57
// look if all those shapes are in 'shapes'.
58
bool rmSubject = True;
59
for (tmpshapes.first(); !tmpshapes.done();
61
GShape *shape = tmpshapes.cur();
62
if (shapes->find(shape) == -1) {
67
// all shapes of subject deleted -> delete the subject.
69
deleteSubjects->add(subject);
70
// one of the two representing shapes are deleted->
71
// update duplication mark of the other.
72
else if (n == 2 && !rmSubject)
73
updateSubjects->add(subject);
79
DeleteShapesCmd::~DeleteShapesCmd() {
82
deleteSubjects->clear();
83
updateSubjects->empty();
86
delete deleteSubjects;
87
delete updateSubjects;
90
void DeleteShapesCmd::Execute() {
91
view->RemoveShapes(shapes);
92
diagram->RemoveSubjects(deleteSubjects);
93
dviewer->UpdateDuplicationMarks(updateSubjects);
97
void DeleteShapesCmd::UnExecute() {
98
view->AddShapes(shapes);
99
diagram->AddSubjects(deleteSubjects);
100
dviewer->UpdateDuplicationMarks(updateSubjects);
101
Command::UnExecute();