File: base_type.cc

package info (click to toggle)
kig 4%3A25.08.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,716 kB
  • sloc: cpp: 41,465; xml: 851; python: 486; perl: 23; sh: 17; makefile: 3
file content (99 lines) | stat: -rw-r--r-- 3,107 bytes parent folder | download | duplicates (3)
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
// SPDX-FileCopyrightText: 2003 Dominique Devriese <devriese@kde.org>

// SPDX-License-Identifier: GPL-2.0-or-later

#include "base_type.h"

#include "bogus_imp.h"
#include "line_imp.h"
#include "object_calcer.h"
#include "point_imp.h"

#include "../misc/common.h"

ObjectABType::ObjectABType(const char *fulltypename, const ArgsParser::spec *spec, int n)
    : ArgsParserObjectType(fulltypename, spec, n)
{
}

ObjectABType::~ObjectABType()
{
}

ObjectImp *ObjectABType::calc(const Args &parents, const KigDocument &) const
{
    if (!margsparser.checkArgs(parents))
        return new InvalidImp;

    Coordinate a = static_cast<const PointImp *>(parents[0])->coordinate();
    Coordinate b = static_cast<const PointImp *>(parents[1])->coordinate();

    return calcx(a, b);
}

bool ObjectABType::canMove(const ObjectTypeCalcer &o) const
{
    return isFreelyTranslatable(o);
    /*
     * as observed by domi: this object is actually movable also
     * if one point is FreelyTranslatable and the other is
     * only movable, but then the "move" itself requires some
     * trickery.
     */
}

bool ObjectABType::isFreelyTranslatable(const ObjectTypeCalcer &o) const
{
    std::vector<ObjectCalcer *> parents = o.parents();
    return parents[0]->isFreelyTranslatable() && parents[1]->isFreelyTranslatable();
}

void ObjectABType::move(ObjectTypeCalcer &o, const Coordinate &to, const KigDocument &d) const
{
    std::vector<ObjectCalcer *> parents = o.parents();
    assert(margsparser.checkArgs(parents));
    const Coordinate a = static_cast<const PointImp *>(parents[0]->imp())->coordinate();
    const Coordinate b = static_cast<const PointImp *>(parents[1]->imp())->coordinate();
    const Coordinate dist = b - a;
    if (parents[0]->canMove())
        parents[0]->move(to, d);
    if (parents[1]->canMove())
        parents[1]->move(to + dist, d);
}

ObjectLPType::ObjectLPType(const char *fullname, const ArgsParser::spec *spec, int n)
    : ArgsParserObjectType(fullname, spec, n)
{
}

ObjectLPType::~ObjectLPType()
{
}

ObjectImp *ObjectLPType::calc(const Args &args, const KigDocument &) const
{
    if (!margsparser.checkArgs(args))
        return new InvalidImp;
    LineData l = static_cast<const AbstractLineImp *>(args[0])->data();
    Coordinate c = static_cast<const PointImp *>(args[1])->coordinate();
    return calc(l, c);
}

const Coordinate ObjectABType::moveReferencePoint(const ObjectTypeCalcer &o) const
{
    std::vector<ObjectCalcer *> parents = o.parents();
    assert(margsparser.checkArgs(parents));
    return static_cast<const PointImp *>(parents[0]->imp())->coordinate();
}

std::vector<ObjectCalcer *> ObjectABType::movableParents(const ObjectTypeCalcer &ourobj) const
{
    std::vector<ObjectCalcer *> parents = ourobj.parents();
    std::set<ObjectCalcer *> ret;
    std::vector<ObjectCalcer *> tmp = parents[0]->movableParents();
    ret.insert(tmp.begin(), tmp.end());
    tmp = parents[1]->movableParents();
    ret.insert(tmp.begin(), tmp.end());
    ret.insert(parents.begin(), parents.end());
    return std::vector<ObjectCalcer *>(ret.begin(), ret.end());
}