~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/dg/addhandlecmd.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 1998, 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 "line.h"
 
23
#include "addhandlecmd.h"
 
24
#include "diagramviewer.h"
 
25
#include "shapeview.h"
 
26
 
 
27
AddHandleCmd::AddHandleCmd(Line *s, int x, int y, unsigned n): 
 
28
                        DragHandleCmd(s, n) { 
 
29
        GetOldPt()->x = x;
 
30
        GetOldPt()->y = y;
 
31
        addPosition = n;
 
32
}
 
33
 
 
34
void AddHandleCmd::Executable() {
 
35
        Erase();
 
36
        GetLine()->AddPoint(GetNewPt(), addPosition);
 
37
        // reset Name Position
 
38
        GetLine()->SetLineNumber(GetLine()->NrPoints()/2);
 
39
        Redraw();
 
40
        // line was straight?
 
41
        if (GetLine()->NrPoints() == 3) {
 
42
                List<GShape *> lines;
 
43
                GetLine()->GetView()->CompleteShapes(&lines, 
 
44
                        GetLine()->GetFromShape(), GetLine()->GetToShape());
 
45
                for (lines.first(); !lines.done(); lines.next()) {
 
46
                        Line *line2 = (Line *)lines.cur();
 
47
                        if (line2->NrPoints() == 2) {
 
48
                                GetLine()->GetView()->MultipleLines(line2);
 
49
                                GetLine()->GetView()->MultipleLinesPosUpdate(line2);
 
50
                                return;
 
51
                        }
 
52
                }
 
53
        }
 
54
        if (Toolkit::EditorWithInterEdgeConnections(GetMainWindow()->GetTool()))
 
55
                GetLine()->GetView()->GetViewer()->ShapePositionUpdate(GetLine());
 
56
}
 
57
 
 
58
void AddHandleCmd::UnExecute() {
 
59
        Command::UnExecute();
 
60
        ReverseDelta();
 
61
        Erase();
 
62
        GetLine()->RemovePoint(addPosition);
 
63
        Redraw();
 
64
        if (GetLine()->NrPoints() == 2) {
 
65
                GetLine()->GetView()->MultipleLines(GetLine());
 
66
                GetLine()->GetView()->MultipleLinesPosUpdate(GetLine());
 
67
        }
 
68
        if (Toolkit::EditorWithInterEdgeConnections(GetMainWindow()->GetTool()))
 
69
                GetLine()->GetView()->GetViewer()->ShapePositionUpdate(GetLine());
 
70
}
 
71
 
 
72
void AddHandleCmd::DrawOutLine(const Point *d) {
 
73
        Point p1 = *GetOldPt() + ScaleCorrect(d);
 
74
        GetView()->Snap(&p1);
 
75
        // get left and rigth points.
 
76
        Point p2 = *(*GetLine()->GetLine())[addPosition-1];
 
77
        Point p3 = *(*GetLine()->GetLine())[addPosition];
 
78
        DrawLines(&p1, &p2, &p3);
 
79
}
 
80
 
 
81
void AddHandleCmd::CalcPoints() {
 
82
        Point pt = *GetOldPt();
 
83
        pt = pt + *GetDelta();
 
84
        if (pt.x <= 0)
 
85
                pt.x = Shape::HANDLE_WIDTH/2;
 
86
        if (pt.y <= 0)
 
87
                pt.y = Shape::HANDLE_WIDTH/2;
 
88
        GetView()->Snap(&pt);
 
89
        GetNewPt()->x = pt.x;
 
90
        GetNewPt()->y = pt.y;
 
91
}
 
92