Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StyleModule.h « stroke « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 398e4c7ee774e38814c68e397cc894b5b3d32b14 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#pragma once

/** \file
 * \ingroup freestyle
 * \brief Class representing a style module
 */

#include <iostream>
#include <string>

#include "Operators.h"
#include "StrokeLayer.h"
#include "StrokeShader.h"

#include "../system/Interpreter.h"
#include "../system/StringUtils.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

using namespace std;

namespace Freestyle {

class StyleModule {
 public:
  StyleModule(const string &file_name, Interpreter *inter) : _file_name(file_name)
  {
    _always_refresh = false;
    _causal = false;
    _drawable = true;
    _modified = true;
    _displayed = true;
    _inter = inter;
  }

  virtual ~StyleModule()
  {
  }

  StrokeLayer *execute()
  {
    if (!_inter) {
      cerr << "Error: no interpreter was found to execute the script" << endl;
      return NULL;
    }

    if (!_drawable) {
      cerr << "Error: not drawable" << endl;
      return NULL;
    }

    Operators::reset();

    if (interpret()) {
      cerr << "Error: interpretation failed" << endl;
      Operators::reset();
      return NULL;
    }

    Operators::StrokesContainer *strokes_set = Operators::getStrokesSet();
    if (strokes_set->empty()) {
      cerr << "Error: strokes set empty" << endl;
      Operators::reset();
      return NULL;
    }

    StrokeLayer *sl = new StrokeLayer;
    for (Operators::StrokesContainer::iterator it = strokes_set->begin(); it != strokes_set->end();
         ++it) {
      sl->AddStroke(*it);
    }

    Operators::reset();
    return sl;
  }

 protected:
  virtual int interpret()
  {
    return _inter->interpretFile(_file_name);
  }

 public:
  // accessors
  const string getFileName() const
  {
    return _file_name;
  }

  bool getAlwaysRefresh() const
  {
    return _always_refresh;
  }

  bool getCausal() const
  {
    return _causal;
  }

  bool getDrawable() const
  {
    return _drawable;
  }

  bool getModified() const
  {
    return _modified;
  }

  bool getDisplayed() const
  {
    return _displayed;
  }

  // modifiers
  void setFileName(const string &file_name)
  {
    _file_name = file_name;
  }

  void setAlwaysRefresh(bool b = true)
  {
    _always_refresh = b;
  }

  void setCausal(bool b = true)
  {
    _causal = b;
  }

  void setDrawable(bool b = true)
  {
    _drawable = b;
  }

  void setModified(bool b = true)
  {
    if (_always_refresh) {
      return;
    }
    _modified = b;
  }

  void setDisplayed(bool b = true)
  {
    _displayed = b;
  }

 private:
  string _file_name;
  bool _always_refresh;
  bool _causal;
  bool _drawable;
  bool _modified;
  bool _displayed;

 protected:
  Interpreter *_inter;

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StyleModule")
#endif
};

} /* namespace Freestyle */