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

« back to all changes in this revision

Viewing changes to src/sd/dv/c2r2line.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 1996-2000, Vrije Universiteit Amsterdam and University of Twente
 
5
// Author: Frank Dehne (frank@cs.vu.nl).
 
6
// Author: Henk van de Zandschulp (henkz@cs.utwente.nl).
 
7
//
 
8
// TCM is free software; you can redistribute it and/or modify
 
9
// it under the terms of the GNU General Public License as published by
 
10
// the Free Software Foundation; either version 2 of the License, or 
 
11
// (at your option) any later version.
 
12
//
 
13
// TCM is distributed in the hope that it will be useful,
 
14
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
// GNU General Public License for more details.
 
17
//
 
18
// You should have received a copy of the GNU General Public License
 
19
// along with TCM; if not, write to the Free Software
 
20
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 
21
// 02111-1307, USA.
 
22
////////////////////////////////////////////////////////////////////////////////
 
23
#include "inputfile.h"
 
24
#include "outputfile.h"
 
25
#include "grafport.h"
 
26
#include <math.h>
 
27
#include "binaryrelationship.h"
 
28
#include "c2r2line.h"
 
29
#include "erviewer.h"
 
30
#include "updatereaddirectioncmd.h"
 
31
 
 
32
C2R2Line::C2R2Line(ShapeView *v, Grafport *g, GShape *node1, GShape *node2, 
 
33
                List<Point *> *aline, bool Curved): 
 
34
                        T4Line(v, g, node1, node2, aline, Curved) {
 
35
        InitTextShapes();
 
36
}
 
37
 
 
38
C2R2Line::C2R2Line(ShapeView *v, Grafport *g, GShape *node1, GShape *node2, 
 
39
                bool Curved): T4Line(v, g, node1, node2, Curved) {
 
40
        InitTextShapes();
 
41
}
 
42
 
 
43
void C2R2Line::InitTextShapes() {
 
44
        GetTextShape1()->SetDescription("Cardinality Constraint");
 
45
        GetTextShape2()->SetDescription("Cardinality Constraint");
 
46
        GetTextShape3()->SetDescription("Role Name");
 
47
        GetTextShape4()->SetDescription("Role Name");
 
48
        GetTextShape1()->SetOneLine(True);
 
49
        GetTextShape2()->SetOneLine(True);
 
50
        SetNameDirection(ReadDirection::NONE);
 
51
}
 
52
 
 
53
bool C2R2Line::SetAssocSubject(AssocList *al) {
 
54
        if (!T4Line::SetAssocSubject(al))
 
55
                return False;
 
56
        int classType = GetSubject()->GetClassType();
 
57
        if (check(GetSubject() && 
 
58
            (classType==Code::BINARY_RELATIONSHIP ||
 
59
             classType==Code::SSD_BINARY_ASSOCIATION_EDGE ||
 
60
             classType==Code::UCD_BINARY_ASSOCIATION_EDGE ||
 
61
             classType==Code::SSD_AGGREGATION_EDGE ||
 
62
             classType==Code::SSD_COMPOSITION_EDGE)))
 
63
                return True;
 
64
        SetSubject(0);
 
65
        return False;
 
66
}
 
67
 
 
68
void C2R2Line::SetTextShape() {
 
69
        T4Line::SetTextShape();
 
70
        int classType = GetSubject()->GetClassType();
 
71
        if (check(GetSubject() && 
 
72
            (classType==Code::BINARY_RELATIONSHIP ||
 
73
             classType==Code::SSD_BINARY_ASSOCIATION_EDGE ||
 
74
             classType==Code::UCD_BINARY_ASSOCIATION_EDGE ||
 
75
             classType==Code::SSD_AGGREGATION_EDGE ||
 
76
             classType==Code::SSD_COMPOSITION_EDGE))) {
 
77
                GetTextShape1()->SetString(
 
78
                        ((BinaryRelationship *)GetSubject())->GetConstraint1());
 
79
                GetTextShape2()->SetString(
 
80
                        ((BinaryRelationship *)GetSubject())->GetConstraint2());
 
81
                GetTextShape3()->SetString(((BinaryRelationship *)GetSubject())->
 
82
                                GetRoleName1());
 
83
                GetTextShape4()->SetString(((BinaryRelationship *)GetSubject())->
 
84
                                GetRoleName2());
 
85
        }
 
86
}
 
87
 
 
88
TextShape *C2R2Line::ChooseTextShape(int x, int y) {
 
89
        Rectangle rect2(GetName()->GetRightMost(), 
 
90
                        GetName()->GetTopMost(),
 
91
                        16,
 
92
                        GetName()->GetHeight());
 
93
        if (rect2.Inside(x, y)) {
 
94
                if (GetName()->GetStringWidth() > 0) {  // toggle OK
 
95
                        int newDir = ((int) GetNameDirection() + 1) % 3;
 
96
                        ERViewer *erviewer = dynamic_cast<ERViewer *>(GetViewer());
 
97
                        if (erviewer)
 
98
                                erviewer->UpdateReadDirection((ReadDirection::Type) newDir);
 
99
                }       //toggle OK
 
100
                return GetName();
 
101
        }
 
102
        return T4Line::ChooseTextShape(x, y);
 
103
}
 
104
 
 
105
TextShape *C2R2Line::HitTextShape(int x, int y) {
 
106
        Rectangle rect2(GetName()->GetRightMost(), 
 
107
                        GetName()->GetTopMost(),
 
108
                        16,
 
109
                        GetName()->GetHeight());
 
110
        if (GetNameDirection() != ReadDirection::NONE && rect2.Inside(x, y)) {
 
111
                return GetName();
 
112
        }
 
113
        return T4Line::HitTextShape(x, y);
 
114
}
 
115
 
 
116
void C2R2Line::DrawShape() {
 
117
        T4Line::DrawShape();
 
118
        DrawDirection();
 
119
}
 
120
        
 
121
void C2R2Line::WriteMembers(OutputFile *ofile) {
 
122
        T4Line::WriteMembers(ofile);
 
123
        string s;
 
124
        ReadDirection::Type2String(GetNameDirection(), &s);
 
125
        (*ofile) << "\t{ NameDirection " << s << " }\n";
 
126
}
 
127
 
 
128
bool C2R2Line::ReadMembers(InputFile *ifile, double format) {
 
129
        if (!T4Line::ReadMembers(ifile, format))
 
130
                return False;
 
131
        if (format >= 1.31) {
 
132
                        string val;
 
133
                        if (!ifile->ReadAttribute("NameDirection", &val))
 
134
                                return False;
 
135
                        UpdateNameDirection(ReadDirection::String2Type(&val));
 
136
                }
 
137
        else
 
138
                        SetNameDirection(ReadDirection::NONE);
 
139
        return True;
 
140
}
 
141