Blender  V2.93
StyleModule.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include <iostream>
25 #include <string>
26 
27 #include "Operators.h"
28 #include "StrokeLayer.h"
29 #include "StrokeShader.h"
30 
31 #include "../system/Interpreter.h"
32 #include "../system/StringUtils.h"
33 
34 #ifdef WITH_CXX_GUARDEDALLOC
35 # include "MEM_guardedalloc.h"
36 #endif
37 
38 using namespace std;
39 
40 namespace Freestyle {
41 
42 class StyleModule {
43  public:
44  StyleModule(const string &file_name, Interpreter *inter) : _file_name(file_name)
45  {
46  _always_refresh = false;
47  _causal = false;
48  _drawable = true;
49  _modified = true;
50  _displayed = true;
51  _inter = inter;
52  }
53 
54  virtual ~StyleModule()
55  {
56  }
57 
59  {
60  if (!_inter) {
61  cerr << "Error: no interpreter was found to execute the script" << endl;
62  return NULL;
63  }
64 
65  if (!_drawable) {
66  cerr << "Error: not drawable" << endl;
67  return NULL;
68  }
69 
71 
72  if (interpret()) {
73  cerr << "Error: interpretation failed" << endl;
75  return NULL;
76  }
77 
78  Operators::StrokesContainer *strokes_set = Operators::getStrokesSet();
79  if (strokes_set->empty()) {
80  cerr << "Error: strokes set empty" << endl;
82  return NULL;
83  }
84 
85  StrokeLayer *sl = new StrokeLayer;
86  for (Operators::StrokesContainer::iterator it = strokes_set->begin(); it != strokes_set->end();
87  ++it) {
88  sl->AddStroke(*it);
89  }
90 
92  return sl;
93  }
94 
95  protected:
96  virtual int interpret()
97  {
98  return _inter->interpretFile(_file_name);
99  }
100 
101  public:
102  // accessors
103  const string getFileName() const
104  {
105  return _file_name;
106  }
107 
108  bool getAlwaysRefresh() const
109  {
110  return _always_refresh;
111  }
112 
113  bool getCausal() const
114  {
115  return _causal;
116  }
117 
118  bool getDrawable() const
119  {
120  return _drawable;
121  }
122 
123  bool getModified() const
124  {
125  return _modified;
126  }
127 
128  bool getDisplayed() const
129  {
130  return _displayed;
131  }
132 
133  // modifiers
134  void setFileName(const string &file_name)
135  {
136  _file_name = file_name;
137  }
138 
139  void setAlwaysRefresh(bool b = true)
140  {
141  _always_refresh = b;
142  }
143 
144  void setCausal(bool b = true)
145  {
146  _causal = b;
147  }
148 
149  void setDrawable(bool b = true)
150  {
151  _drawable = b;
152  }
153 
154  void setModified(bool b = true)
155  {
156  if (_always_refresh) {
157  return;
158  }
159  _modified = b;
160  }
161 
162  void setDisplayed(bool b = true)
163  {
164  _displayed = b;
165  }
166 
167  private:
168  string _file_name;
169  bool _always_refresh;
170  bool _causal;
171  bool _drawable;
172  bool _modified;
173  bool _displayed;
174 
175  protected:
177 
178 #ifdef WITH_CXX_GUARDEDALLOC
179  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StyleModule")
180 #endif
181 };
182 
183 } /* namespace Freestyle */
Read Guarded memory(de)allocation.
Class gathering stroke creation algorithms.
Class to define a layer of strokes.
Class defining StrokeShader.
void reset()
clear internal cached data and reset random seed
vector< Stroke * > StrokesContainer
Definition: Operators.h:53
void AddStroke(Stroke *iStroke)
Definition: StrokeLayer.h:93
bool getAlwaysRefresh() const
Definition: StyleModule.h:108
void setCausal(bool b=true)
Definition: StyleModule.h:144
bool getDrawable() const
Definition: StyleModule.h:118
void setAlwaysRefresh(bool b=true)
Definition: StyleModule.h:139
bool getDisplayed() const
Definition: StyleModule.h:128
void setDrawable(bool b=true)
Definition: StyleModule.h:149
void setFileName(const string &file_name)
Definition: StyleModule.h:134
virtual int interpret()
Definition: StyleModule.h:96
bool getModified() const
Definition: StyleModule.h:123
const string getFileName() const
Definition: StyleModule.h:103
void setModified(bool b=true)
Definition: StyleModule.h:154
void setDisplayed(bool b=true)
Definition: StyleModule.h:162
bool getCausal() const
Definition: StyleModule.h:113
Interpreter * _inter
Definition: StyleModule.h:176
StrokeLayer * execute()
Definition: StyleModule.h:58
StyleModule(const string &file_name, Interpreter *inter)
Definition: StyleModule.h:44
inherits from class Rep
Definition: AppCanvas.cpp:32