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

« back to all changes in this revision

Viewing changes to src/sd/bv/scdandline.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 2002, Universiteit Twente.
 
5
// Author: David N. Jansen (dnjansen@cs.utwente.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 "scdandline.h"
 
23
#include "nodeshape.h"
 
24
 
 
25
 
 
26
SCDAndLine::SCDAndLine(ShapeView *v, Grafport *g, GShape *node1,
 
27
                List<Point *> *aline, bool Curved)
 
28
:
 
29
        Line(v, g, node1, node1, aline, Curved)
 
30
{
 
31
        CalcEndPoints();
 
32
        CalcPosition();
 
33
        SetEnd2(LineEnd::FILLED_ARROW);
 
34
}
 
35
 
 
36
 
 
37
SCDAndLine::SCDAndLine(ShapeView *v, Grafport *g, GShape *node1, bool Curved)
 
38
:
 
39
        Line(v, g, node1, node1, Curved)
 
40
{
 
41
        if ( node1 )
 
42
                CalcEndPoints();
 
43
        SetEnd2(LineEnd::FILLED_ARROW);
 
44
}
 
45
 
 
46
 
 
47
SCDAndLine::~SCDAndLine() {
 
48
}
 
49
 
 
50
 
 
51
 
 
52
/* virtual */ void SCDAndLine::CalcEndPoints() {
 
53
        Line::CalcEndPoints();
 
54
//      // ... but end points have to be on the child area's border instead of
 
55
//      // the (outer) boundary.
 
56
//      NodeShape *shape = dynamic_cast<NodeShape *>(GetFromShape());
 
57
//      if ( ! shape )
 
58
//              return;
 
59
//      List<Point *> *lin = GetLine();
 
60
//      int len = lin->count();
 
61
//
 
62
//      // The code below is copied and adapted from NodeShape::GiveOrthoSnp()
 
63
//      // and ShapeType::GiveOrthoSnp().
 
64
//      const Point *to = (*lin)[1], *pos = shape->GetPosition();
 
65
//      DPoint p1(shape->GetShapeType()->GetChildArea()->GiveOrthoSnp(
 
66
//      //                               ^^^^^^^^^^^^^^
 
67
//              to->x - pos->x, to->y - pos->y,
 
68
//              shape->GetWidth(), shape->GetHeight(),
 
69
//              shape->GetName()->GetStringWidth(),
 
70
//              shape->GetName()->GetStringHeight()));
 
71
//      p1.x += pos->x;
 
72
//      p1.y += pos->y;
 
73
//
 
74
//      const Point *from = (*lin)[len-2];
 
75
//      DPoint p2(shape->GetShapeType()->GetChildArea()->GiveOrthoSnp(
 
76
//      //                               ^^^^^^^^^^^^^^
 
77
//              from->x - pos->x, from->y - pos->y,
 
78
//              shape->GetWidth(), shape->GetHeight(),
 
79
//              shape->GetName()->GetStringWidth(),
 
80
//              shape->GetName()->GetStringHeight()));
 
81
//      p2.x += pos->x;
 
82
//      p2.y += pos->y;
 
83
//
 
84
//      (*lin)[0]->Set(int(0.5 + p1.x), int(0.5 + p1.y));
 
85
//      (*lin)[len-1]->Set(int(0.5 + p2.x), int(0.5 + p2.y));
 
86
//
 
87
//      /// maybe one also wants to set the points (*line)[1] and (*line)[len-2]
 
88
//      /// if len > 3.
 
89
}
 
90
 
 
91
 
 
92
/* virtual */ void SCDAndLine::CalcPosition() {
 
93
        // line points have to lie in the child area of the corresponding shape.
 
94
        Line::CalcPosition();
 
95
        NodeShape *shape = dynamic_cast<NodeShape *>(GetFromShape());
 
96
        if ( ! shape )
 
97
                return;
 
98
        List <Point *> *lin = GetLine();
 
99
        const Polygon *ca = shape->GetShapeType()->GetChildArea();
 
100
        const Point *pos = shape->GetPosition();
 
101
 
 
102
        for ( int i = lin->count() ; --i >= 0 ; ) {
 
103
                Point to = *(*lin)[i];
 
104
                to -= *pos;
 
105
                if ( ! ca->IsInside(to.x, to.y,
 
106
                                shape->GetWidth(), shape->GetHeight(),
 
107
                                shape->GetName()->GetStringWidth(),
 
108
                                shape->GetName()->GetStringHeight()) ) {
 
109
                        DPoint p(ca->GiveOrthoSnp(to.x, to.y,
 
110
                                        shape->GetWidth(), shape->GetHeight(),
 
111
                                        shape->GetName()->GetStringWidth(),
 
112
                                        shape->GetName()->GetStringHeight()));
 
113
                        p.x += pos->x;
 
114
                        p.y += pos->y;
 
115
                        (*lin)[i]->Set(int(0.5 + p.x), int(0.5 + p.y));
 
116
                }
 
117
        }
 
118
}