summaryrefslogtreecommitdiffstats
path: root/kplato/kptrelation.h
blob: c84b7cf883d23a6b6e8162f8e86870392a00c381 (plain)
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
114
115
/* This file is part of the KDE project
   Copyright (C) 2001 Thomas Zander zander@kde.org
   Copyright (C) 2004 Dag Andersen <danders@get2net.dk>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KPTRELATION_H
#define KPTRELATION_H

#include "kptduration.h"

#include <tqstring.h>

class TQCanvas;
class TQDomElement;

namespace KPlato
{

class Node;
class Project;
class PertCanvas;

/**
  * The relation class couples a 2 nodes together which are dependent on each other.
  * If for example you have a project to build a house, the node that represents the 
  * adding of the roof is dependent on the node that represents the building of the walls.
  * The roof can't be put up if the walls are not there yet.
  * We actually have a number of relationtypes so this relation can be used in different manners.
  */
class Relation {
public:
    enum Type { FinishStart, FinishFinish, StartStart };

    Relation(Node *parent, Node *child, Type type, Duration lag);
    Relation(Node *parent=0, Node *child=0, Type type=FinishStart);
    Relation(Relation *rel);
    
    /** 
    *  When deleted the relation will remove itself from 
    *  the parent- and child nodes lists
    */
    virtual ~Relation();

    void setType(Type );
    Type type() const { return m_type; }

    /** returns the lag.
    *  The lag of a relation is the time it takes between the parent starting/stopping
    *  and the start of the child.
    */
    const Duration &lag() const { return m_lag; }
    void setLag(Duration lag) { m_lag = lag; }

    /**
     * @return The parent dependent node.
     */
    Node *parent() const { return m_parent; }
    /**
     * @return The child dependent node.
     */
    Node *child() const { return m_child; }

    enum Result {
        SUCCESS = 0l,
        HASCHILDREN = 1l,
        NOTIMPL = 2l
    };

    bool load(TQDomElement &element, Project &project);
    void save(TQDomElement &element) const;
    
protected: // variables
    Node *m_parent;
    Node *m_child;
    Type m_type;
    Duration m_lag;

private:
    TQString m_parentId;
    
#ifndef NDEBUG
public:
    void printDebug(TQCString indent);
#endif

};

class ProxyRelation : public Relation
{
public:
    ProxyRelation(Node *parent, Node *child, Relation::Type type, Duration lag) 
    : Relation(parent, child, type, lag) 
    {}

    ~ProxyRelation() { m_parent = 0; m_child = 0;}
};

}  //KPlato namespace

#endif