~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/dg/deleteshapescmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
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).
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "gshape.h"
 
23
#include "subject.h"
 
24
#include "diagram.h"
 
25
#include "diagramviewer.h"
 
26
#include "shapeview.h"
 
27
#include "deleteshapescmd.h"
 
28
 
 
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();
 
36
        view = v;
 
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);
 
45
        }
 
46
        for (tmpsubjects.first(); !tmpsubjects.done(); tmpsubjects.next()) {
 
47
                Subject *subject = tmpsubjects.cur();
 
48
                tmpshapes.empty();
 
49
                dviewer->GetShapes(subject, &tmpshapes);
 
50
                int n = tmpshapes.count();
 
51
                if (!check (n != 0))
 
52
                        return;
 
53
                if (n == 1)
 
54
                        // there is one shape for subject-> delete the subject.
 
55
                        deleteSubjects->add(subject);
 
56
                else if (n >= 2) {
 
57
                        // look if all those shapes are in 'shapes'.
 
58
                        bool rmSubject = True;
 
59
                        for (tmpshapes.first(); !tmpshapes.done(); 
 
60
                                        tmpshapes.next()) {
 
61
                                GShape *shape = tmpshapes.cur();
 
62
                                if (shapes->find(shape) == -1) {
 
63
                                        rmSubject = False;
 
64
                                        break;
 
65
                                }
 
66
                        }
 
67
                        // all shapes of subject deleted -> delete the subject.
 
68
                        if (rmSubject)
 
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);
 
74
                }
 
75
                tmpshapes.empty();
 
76
        }
 
77
}
 
78
 
 
79
DeleteShapesCmd::~DeleteShapesCmd() {
 
80
        if (CmdDone()) {
 
81
                shapes->clear();
 
82
                deleteSubjects->clear();
 
83
                updateSubjects->empty();
 
84
        }
 
85
        delete shapes;
 
86
        delete deleteSubjects;
 
87
        delete updateSubjects;
 
88
}
 
89
 
 
90
void DeleteShapesCmd::Execute() {
 
91
        view->RemoveShapes(shapes);
 
92
        diagram->RemoveSubjects(deleteSubjects);
 
93
        dviewer->UpdateDuplicationMarks(updateSubjects);
 
94
        Command::Execute();
 
95
}
 
96
 
 
97
void DeleteShapesCmd::UnExecute() {
 
98
        view->AddShapes(shapes);
 
99
        diagram->AddSubjects(deleteSubjects);
 
100
        dviewer->UpdateDuplicationMarks(updateSubjects);
 
101
        Command::UnExecute();
 
102
}