2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2012-12-28 20:21:05 +00:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup freestyle
|
|
|
|
|
* \brief Class representing a style module
|
2012-12-28 20:21:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "Operators.h"
|
|
|
|
|
#include "StrokeLayer.h"
|
|
|
|
|
#include "StrokeShader.h"
|
|
|
|
|
|
|
|
|
|
#include "../system/Interpreter.h"
|
|
|
|
|
#include "../system/StringUtils.h"
|
2008-04-30 15:41:54 +00:00
|
|
|
|
2024-11-13 13:39:49 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
2013-05-13 22:58:27 +00:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
using namespace std;
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
namespace Freestyle {
|
|
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
class StyleModule {
|
|
|
|
|
public:
|
2012-12-28 20:21:05 +00:00
|
|
|
StyleModule(const string &file_name, Interpreter *inter) : _file_name(file_name)
|
|
|
|
|
{
|
|
|
|
|
_always_refresh = false;
|
|
|
|
|
_causal = false;
|
|
|
|
|
_drawable = true;
|
|
|
|
|
_modified = true;
|
|
|
|
|
_displayed = true;
|
|
|
|
|
_inter = inter;
|
2009-04-08 17:32:56 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-03-29 16:50:54 +02:00
|
|
|
virtual ~StyleModule() {}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-07-19 18:52:32 +09:00
|
|
|
StrokeLayer *execute()
|
2012-12-28 20:21:05 +00:00
|
|
|
{
|
|
|
|
|
if (!_inter) {
|
|
|
|
|
cerr << "Error: no interpreter was found to execute the script" << endl;
|
2023-08-01 21:15:52 +10:00
|
|
|
return nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (!_drawable) {
|
|
|
|
|
cerr << "Error: not drawable" << endl;
|
2023-08-01 21:15:52 +10:00
|
|
|
return nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Operators::reset();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
if (interpret()) {
|
|
|
|
|
cerr << "Error: interpretation failed" << endl;
|
|
|
|
|
Operators::reset();
|
2023-08-01 21:15:52 +10:00
|
|
|
return nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Operators::StrokesContainer *strokes_set = Operators::getStrokesSet();
|
|
|
|
|
if (strokes_set->empty()) {
|
|
|
|
|
cerr << "Error: strokes set empty" << endl;
|
|
|
|
|
Operators::reset();
|
2023-08-01 21:15:52 +10:00
|
|
|
return nullptr;
|
2012-12-28 20:21:05 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
StrokeLayer *sl = new StrokeLayer;
|
|
|
|
|
for (Operators::StrokesContainer::iterator it = strokes_set->begin(); it != strokes_set->end();
|
2019-05-31 22:51:19 +10:00
|
|
|
++it)
|
|
|
|
|
{
|
2012-12-28 20:21:05 +00:00
|
|
|
sl->AddStroke(*it);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
Operators::reset();
|
|
|
|
|
return sl;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-26 01:23:27 +00:00
|
|
|
protected:
|
2012-12-28 20:21:05 +00:00
|
|
|
virtual int interpret()
|
|
|
|
|
{
|
|
|
|
|
return _inter->interpretFile(_file_name);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-26 01:23:27 +00:00
|
|
|
public:
|
2012-12-28 20:21:05 +00:00
|
|
|
// accessors
|
|
|
|
|
const string getFileName() const
|
|
|
|
|
{
|
|
|
|
|
return _file_name;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool getAlwaysRefresh() const
|
|
|
|
|
{
|
|
|
|
|
return _always_refresh;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool getCausal() const
|
|
|
|
|
{
|
|
|
|
|
return _causal;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool getDrawable() const
|
|
|
|
|
{
|
|
|
|
|
return _drawable;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool getModified() const
|
|
|
|
|
{
|
|
|
|
|
return _modified;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
bool getDisplayed() const
|
|
|
|
|
{
|
|
|
|
|
return _displayed;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
// modifiers
|
|
|
|
|
void setFileName(const string &file_name)
|
|
|
|
|
{
|
|
|
|
|
_file_name = file_name;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void setAlwaysRefresh(bool b = true)
|
|
|
|
|
{
|
|
|
|
|
_always_refresh = b;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void setCausal(bool b = true)
|
|
|
|
|
{
|
|
|
|
|
_causal = b;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void setDrawable(bool b = true)
|
|
|
|
|
{
|
|
|
|
|
_drawable = b;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void setModified(bool b = true)
|
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (_always_refresh) {
|
2012-12-28 20:21:05 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-12-28 20:21:05 +00:00
|
|
|
_modified = b;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-12-28 20:21:05 +00:00
|
|
|
void setDisplayed(bool b = true)
|
|
|
|
|
{
|
|
|
|
|
_displayed = b;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2008-04-30 15:41:54 +00:00
|
|
|
private:
|
2012-12-28 20:21:05 +00:00
|
|
|
string _file_name;
|
|
|
|
|
bool _always_refresh;
|
|
|
|
|
bool _causal;
|
|
|
|
|
bool _drawable;
|
|
|
|
|
bool _modified;
|
|
|
|
|
bool _displayed;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-07-26 01:23:27 +00:00
|
|
|
protected:
|
2012-12-28 20:21:05 +00:00
|
|
|
Interpreter *_inter;
|
2013-05-13 22:58:27 +00:00
|
|
|
|
|
|
|
|
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StyleModule")
|
2008-04-30 15:41:54 +00:00
|
|
|
};
|
|
|
|
|
|
2013-04-09 00:46:49 +00:00
|
|
|
} /* namespace Freestyle */
|