1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
/*
* KSeg
* Copyright (C) 1999-2006 Ilya Baran
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Send comments and/or bug reports to:
* ibaran@mit.edu
*/
#include "G_object.H"
#include <stdio.h>
G_object::G_object()
{
}
G_object::~G_object()
{
}
void G_object::tempTransform(const ViewTransform &trans)
{
G_geometry *geo = getGeoRef();
geo->translate(G_point(trans.offsetX, trans.offsetY));
geo->scale(G_point(0, 0), trans.zoom);
}
void G_valueObject::tempTransform(const ViewTransform &trans)
{
pos.translate(G_point(trans.offsetX, trans.offsetY));
pos.scale(G_point(0, 0), trans.zoom);
}
void G_object::draw(QPainter &p)
{
getGeoRef()->draw(p, *(where->getDrawstyle()), where->getSelected());
}
void G_object::update()
{
}
//this function is used by subclasses.
void G_object::updateTransform()
{
switch(where->getDescendType()) {
case G_TRANSLATED:
getGeoRef()->translate(parent(2)->getPoint() - parent(1)->getPoint());
break;
case G_ROTATED: {
double angle;
if(where->getParents().count() == 3) {
if(fabs(parent(2)->getNumValue()) >= BIG) {
where->setExists(false);
return;
}
angle = (360. - parent(2)->getNumValue()) / 180. * M_PI;
}
else {
G_point v1 = parent(4)->getPoint() - parent(3)->getPoint();
G_point v2 = parent(2)->getPoint() - parent(3)->getPoint();
angle = asin((v2 % v1) / sqrt(v1.lengthsq() * v2.lengthsq()));
if(v2 * v1 < 0) angle = M_PI - angle;
}
getGeoRef()->rotate(parent(1)->getPoint(), angle);
break;
}
case G_SCALED: {
double scale;
if(where->getParents().count() == 3) {
scale = parent(2)->getNumValue();
if(fabs(scale) >= BIG) {
where->setExists(false);
return;
}
}
else {
scale = parent(3)->getSegment().length() /
parent(2)->getSegment().length();
}
getGeoRef()->scale(parent(1)->getPoint(), scale);
break;
}
case G_REFLECTED:
getGeoRef()->reflect(*(parent(1)->getStraightRef()));
break;
}
if(!getGeoRef()->isValid()) where->setExists(false);
}
|