v2.0
open source Production PLanning
Home
Documentation
Getting started
Modeling guide
User guide
Installation guide
Developer guide
FAQ
C++ API
C++ API - plan.cpp Source File
Main Page
Namespaces
Classes
Files
File List
File Members
src
model
plan.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
* *
3
* Copyright (C) 2007-2012 by Johan De Taeye, frePPLe bvba *
4
* *
5
* This library is free software; you can redistribute it and/or modify it *
6
* under the terms of the GNU Affero General Public License as published *
7
* by the Free Software Foundation; either version 3 of the License, or *
8
* (at your option) any later version. *
9
* *
10
* This library is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU Affero General Public License for more details. *
14
* *
15
* You should have received a copy of the GNU Affero General Public *
16
* License along with this program. *
17
* If not, see <http://www.gnu.org/licenses/>. *
18
* *
19
***************************************************************************/
20
21
#define FREPPLE_CORE
22
#include "
frepple/model.h
"
23
24
namespace
frepple
25
{
26
27
28
DECLARE_EXPORT
Plan* Plan::thePlan;
29
DECLARE_EXPORT
const
MetaCategory
*
Plan::metadata
;
30
31
32
int
Plan::initialize
()
33
{
34
// Initialize the plan metadata.
35
metadata
=
new
MetaCategory
(
"plan"
,
""
);
36
37
// Initialize the Python type
38
PythonType
& x =
PythonExtension<Plan>::getType
();
39
x.
setName
(
"parameters"
);
40
x.
setDoc
(
"frePPLe global settings"
);
41
x.
supportgetattro
();
42
x.
supportsetattro
();
43
int
tmp = x.
typeReady
();
44
const_cast<
MetaCategory
*
>
(
metadata
)->pythonClass = x.
type_object
();
45
46
// Create a singleton plan object
47
// Since we can count on the initialization being executed only once, also
48
// in a multi-threaded configuration, we don't need a more advanced mechanism
49
// to protect the singleton plan.
50
thePlan =
new
Plan
();
51
52
// Add access to the information with a global attribute.
53
return
PyModule_AddObject(PythonInterpreter::getModule(),
54
"settings"
, &
Plan::instance
()) + tmp;
55
}
56
57
58
DECLARE_EXPORT
Plan::~Plan
()
59
{
60
// Closing the logfile
61
Environment::setLogFile(
""
);
62
63
// Clear the pointer to this singleton object
64
thePlan = NULL;
65
}
66
67
68
DECLARE_EXPORT
void
Plan::setCurrent
(
Date
l)
69
{
70
// Update the time
71
cur_Date = l;
72
73
// Let all operationplans check for new ProblemBeforeCurrent and
74
// ProblemBeforeFence problems.
75
for
(Operation::iterator i =
Operation::begin
(); i !=
Operation::end
(); ++i)
76
i->setChanged();
77
}
78
79
80
DECLARE_EXPORT
void
Plan::writeElement
(
XMLOutput
*o,
const
Keyword
& tag,
mode
m)
const
81
{
82
// No references
83
assert(m !=
REFERENCE
);
84
85
// Opening tag
86
if
(m!=
NOHEADER
) o->
BeginObject
(tag);
87
88
// Write all own fields
89
o->
writeElement
(
Tags::tag_name
, name);
90
o->
writeElement
(
Tags::tag_description
, descr);
91
o->
writeElement
(
Tags::tag_current
, cur_Date);
92
Plannable::writeElement
(o, tag);
93
94
// Persist all categories
95
MetaCategory::persist(o);
96
97
o->
EndObject
(tag);
98
}
99
100
101
DECLARE_EXPORT
void
Plan::endElement
(
XMLInput
& pIn,
const
Attribute
& pAttr,
const
DataElement
& pElement)
102
{
103
if
(pAttr.
isA
(
Tags::tag_current
))
104
setCurrent
(pElement.
getDate
());
105
else
if
(pAttr.
isA
(
Tags::tag_description
))
106
pElement >> descr;
107
else
if
(pAttr.
isA
(
Tags::tag_name
))
108
pElement >> name;
109
else
if
(pAttr.
isA
(
Tags::tag_logfile
))
110
Environment::setLogFile(pElement.
getString
());
111
else
112
Plannable::endElement
(pIn, pAttr, pElement);
113
}
114
115
116
DECLARE_EXPORT
void
Plan::beginElement
(
XMLInput
& pIn,
const
Attribute
& pAttr)
117
{
118
const
MetaCategory
*cat = MetaCategory::findCategoryByGroupTag(pIn.
getParentElement
().first.getHash());
119
if
(cat)
120
{
121
if
(cat->
readFunction
)
122
// Hand over control to a registered read controller
123
pIn.
readto
(cat->
readFunction
(cat,pIn.
getAttributes
()));
124
else
125
// There is no controller available.
126
// This piece of code will be used to skip pieces of the XML file that
127
// frePPLe doesn't need to be understand.
128
pIn.
IgnoreElement
();
129
}
130
}
131
132
133
DECLARE_EXPORT
PyObject*
Plan::getattro
(
const
Attribute
& attr)
134
{
135
if
(attr.
isA
(
Tags::tag_name
))
136
return
PythonObject
(
Plan::instance
().
getName
());
137
if
(attr.
isA
(
Tags::tag_description
))
138
return
PythonObject
(
Plan::instance
().
getDescription
());
139
if
(attr.
isA
(
Tags::tag_current
))
140
return
PythonObject
(
Plan::instance
().
getCurrent
());
141
if
(attr.
isA
(
Tags::tag_logfile
))
142
return
PythonObject
(Environment::getLogFile());
143
return
NULL;
144
}
145
146
147
DECLARE_EXPORT
int
Plan::setattro
(
const
Attribute
& attr,
const
PythonObject
& field)
148
{
149
if
(attr.
isA
(
Tags::tag_name
))
150
Plan::instance
().
setName
(field.
getString
());
151
else
if
(attr.
isA
(
Tags::tag_description
))
152
Plan::instance
().
setDescription
(field.
getString
());
153
else
if
(attr.
isA
(
Tags::tag_current
))
154
Plan::instance
().
setCurrent
(field.
getDate
());
155
else
if
(attr.
isA
(
Tags::tag_logfile
))
156
Environment::setLogFile(field.
getString
());
157
else
158
return
-1;
// Error
159
return
0;
// OK
160
}
161
162
}