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
////////////////////////////////////////////////////////////////////////////////
22
//#include "grafport.h"
23
#include "nodeshape.h"
24
#include "shapeview.h"
26
#include "diagramviewer.h"
27
//#include "drawwindow.h"
28
#include "sizeshapecmd.h"
30
// dir = handle nr + 1
32
SizeShapeCmd::SizeShapeCmd(GShape *s, int dir)
33
:Command(s->GetView()->GetViewer()->GetDiagram(),
34
s->GetView()->GetViewer()),
35
fixpoint(*s->GetPosition()),
36
centre(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0),
37
corner(1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
39
if ( ! (shape = dynamic_cast<NodeShape *>(s)) )
40
error("Illegal use of size shape command");
46
constrainX = True; // only change height
50
constrainY = True; // only change width
54
newCentre = oldCentre = *shape->GetPosition();
55
newWidth = oldWidth = shape->GetWidth();
56
newHeight = oldHeight = shape->GetHeight();
60
void SizeShapeCmd::TrackMouse(TrackType aPhase, Point * /* anchorPoint */,
61
Point * /* previousPoint */, Point *nextPoint)
65
GetMainWindow()->SetSizeCursor(direction);
76
GetMainWindow()->SetCursor(MouseCursor::LEFT_PTR);
79
error("unknown track type\n");
85
void SizeShapeCmd::CalcSize(const Point *p) {
87
newWidth = shape->GetWidth();
88
newHeight = shape->GetHeight();
89
tw = shape->GetName()->GetStringWidth();
90
th = shape->GetName()->GetStringHeight();
91
const DPoint c(ScaleCorrect(p->x), ScaleCorrect(p->y));
92
corner.CalcScale(&c, fixpoint.x, fixpoint.y, &newWidth, &newHeight,
93
tw, th, constrainX, constrainY);
94
centre.CalcPoint(&newCentre, fixpoint.x, fixpoint.y,
95
newWidth, newHeight, tw, th);
96
shape->CorrectScale(&newWidth, &newHeight, constrainX, constrainY);
100
void SizeShapeCmd::Draw() {
101
shape->DrawOutLine(newCentre.x, newCentre.y, newWidth, newHeight);
105
void SizeShapeCmd::Execute() {
108
shape->UpdatePosition(&pt);
109
shape->UpdateSize(int(0.5 + newWidth), int(0.5 + newHeight));
110
shape->GetView()->GetViewer()->ShapePositionUpdate(shape);
111
GetMainWindow()->FitDocument();
115
void SizeShapeCmd::UnExecute() {
116
Command::UnExecute();
118
shape->UpdatePosition(&pt);
119
shape->UpdateSize(int(0.5 + oldWidth), int(0.5 + oldHeight));
120
shape->GetView()->GetViewer()->ShapePositionUpdate(shape);