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
////////////////////////////////////////////////////////////////////////////////
23
#include "scaledialog.h"
24
#include "editstubs.h"
29
const int Grid::MAX_POINT_DISTANCE = 50;
30
const int Grid::MIN_POINT_DISTANCE = 1;
31
const int Grid::MAX_GRID_SIZE = 50;
32
const int Grid::MIN_GRID_SIZE = 10;
34
Grid::Grid(Config *c, DrawWindow *d, Viewer *v) {
38
SetPointDistance(config->GetPointDistance());
39
snap = config->GetPointSnapping();
40
showGrid = config->GetShowGrid();
41
gridSize = min(MAX_GRID_SIZE, max(MIN_GRID_SIZE, config->GetGridSize()));
42
defaultPointDistance = pointDistance;
43
defaultGridSize = gridSize;
44
scaleDialog = new ScaleDialog(d->GetWidget());
45
scaleDialog->Initialize();
52
void Grid::SetSnap(bool s) {
53
string txt = "point position is ";
58
mainwindow->SetStatus(&txt);
62
void Grid::PointDistance() {
63
mainwindow->SetStatus("action: point distance");
64
scaleDialog->SetTitle("Point distance");
65
scaleDialog->SetScaleLabel("Point distance (in pixels)");
66
scaleDialog->SetValueChangedCallback(
67
EditStubs::PointDistanceOKCB, this);
68
scaleDialog->SetScaleValues(MIN_POINT_DISTANCE, MAX_POINT_DISTANCE,
69
pointDistance, 0, defaultPointDistance);
73
void Grid::SetPointDistance(int n) {
74
pointDistance = min(MAX_POINT_DISTANCE, max(MIN_POINT_DISTANCE, n));
75
string txt = "point distance set to ";
77
mainwindow->SetStatus(&txt);
80
void Grid::SetShowGrid(bool set) {
81
string txt = "grid is ";
86
mainwindow->SetStatus(&txt);
87
// if no change then don't draw.
94
void Grid::GridSize() {
95
mainwindow->SetStatus("action: grid size");
96
scaleDialog->SetTitle("Grid size");
97
scaleDialog->SetScaleLabel("Grid size (in pixels)");
98
scaleDialog->SetValueChangedCallback(EditStubs::GridSizeOKCB, this);
99
scaleDialog->SetScaleValues(MIN_GRID_SIZE, MAX_GRID_SIZE,
100
gridSize, 0, defaultGridSize);
101
scaleDialog->Popup();
104
void Grid::SetGridSize(int n) {
105
string txt = "grid size set to ";
107
mainwindow->SetStatus(&txt);
108
// if no change then do nothing.
115
gridSize = min(MAX_GRID_SIZE, max(MIN_GRID_SIZE, n));
120
gridSize = min(MAX_GRID_SIZE, max(MIN_GRID_SIZE, n));
123
void Grid::Snap(Point *pt) {
128
int Grid::Snap(int x) {
131
x = (x / pointDistance) * pointDistance;
132
int rest = (save % pointDistance) * 2;
133
if ( rest >= pointDistance)
134
x = x + pointDistance;
139
void Grid::DrawGrid() {
140
Grafport *grafport = viewer->GetGrafport();
141
if (!check(grafport))
143
int width = int(0.5 + grafport->GetWidth());
144
int height = int(0.5 + grafport->GetHeight());
145
int n_x = width / gridSize;
146
int n_y = height / gridSize;
148
for(i=0; i<=n_x; i++) {
149
int x = i * gridSize;
150
grafport->DrawEditDottedGridLine(x, 0, x, height-1);
152
for(i=0; i<=n_y; i++) {
153
int y = i * gridSize;
154
grafport->DrawEditDottedGridLine(0, y, width-1, y);