Commit Graph

43 Commits

Author SHA1 Message Date
d21f445469 PyAPI: remove Python 3.7x compatibility code
This removes Python version checks needed to build with 3.8+ and 3.7x.

Ref D10381
2021-02-12 08:08:15 +11:00
21a2b975b8 Cleanup: Remove using-directive from freestyle headers
The header files in freestyle utilize the using-directive at the global
file scope. This is a bad practice as it pollutes the global name space
causing possible ambiguous reference compilation errors. In particular,
the DNA files that are included by freestyle will cause those ambiguous
reference errors when the developers adds a DNA member with a type name
that also exist in the Freestyle name space, such as Curve and possibly
others.

This patch does the minimal work needed to resolve that by moving the
using-directives from the headers into the corresponding translation
units.

Reviewed By: Brecht

Differential Revision: https://developer.blender.org/D10351
2021-02-08 17:29:42 +02:00
cd9acfed4f Cleanup: use preprocessor version check for PyTypeObject declaration
While `tp_print` was deprecated, Python 3.8+ uses this for
'tp_vectorcall_offset' which wasn't stated in the comment from
efd71aad4f.

Instead of suppressing clang-tidy, use preprocessor a check since
this properly represents the difference between Python versions.
2020-11-11 09:11:21 +11:00
b5d310b569 Cleanup: clang-format 2020-11-10 09:42:03 +11:00
efd71aad4f Cleanup: clang-tidy suppress warnings for PyTypeObject.tp_print
Clang-tidy behavior changes from Python 3.7 to 3.8+ so it's simplest
to suppress the warning in this instance.
2020-11-10 09:40:20 +11:00
e118426e46 Fix T82520: error building freestyle with Python3.8
Caused by 16732def37,
This is a 'Py_ssize_t' in Python 3.8,
replace with zero as this works in both 3.7 and 3.8.
2020-11-09 16:08:29 +11:00
8c846cccd6 Cleanup: clang-format 2020-11-09 15:47:08 +11:00
16732def37 Cleanup: Clang-Tidy modernize-use-nullptr
Replace `NULL` with `nullptr` in C++ code.

No functional changes.
2020-11-06 18:08:25 +01:00
2d1cce8331 Cleanup: make format after SortedIncludes change 2020-03-19 09:33:58 +01:00
9a9f39e466 Cleanup: remove redundant 'char *' casts 2019-12-20 10:42:57 +11:00
d8dbd49a2f Cleanup: style, use braces in source/
Automated using clang-tidy.
2019-05-31 22:55:15 +10:00
e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
de13d0a80c doxygen: add newline after \file
While \file doesn't need an argument, it can't have another doxy
command after it.
2019-02-18 08:22:12 +11:00
eef4077f18 Cleanup: remove redundant doxygen \file argument
Move \ingroup onto same line to be more compact and
make it clear the file is in the group.
2019-02-06 15:45:22 +11:00
744f633986 Cleanup: trailing commas
Needed for clan-format not to wrap onto one line.
2019-02-03 14:59:11 +11:00
65ec7ec524 Cleanup: remove redundant, invalid info from headers
BF-admins agree to remove header information that isn't useful,
to reduce noise.

- BEGIN/END license blocks

  Developers should add non license comments as separate comment blocks.
  No need for separator text.

- Contributors

  This is often invalid, outdated or misleading
  especially when splitting files.

  It's more useful to git-blame to find out who has developed the code.

See P901 for script to perform these edits.
2019-02-02 01:36:28 +11:00
410880552b Cleanup: trailing space for freestyle 2018-06-17 17:05:14 +02:00
64ade99ecc Freestyle: Python API documentation updates.
Fixed dead references of API identifiers (e.g., freestyle.types.Interface0D)
due to relocations of the identifiers into submodules.  Also made various minor
revisions of mark-ups and typos.
2014-09-19 13:41:47 +09:00
252eaed483 Freestyle: use bool instead of int.
Patch contribution by flokkievids (Folkert de Vries).  Thanks!
2014-06-24 23:13:55 +09:00
829a2cc1b0 remove blender foundation copyright from freestyle files.
this can be added back on case-by-case basis, but better not assume ownership of another projects work by default.
2013-03-31 01:11:07 +00:00
4a92d82626 A big code clean-up patch from Bastien Montagne, many thanks! 2013-03-07 23:17:23 +00:00
3df023ae82 Freestyle Python API improvements - part 8.
* Proper handling of keyword arguments was implemented in Operators and ContextFunctions,
as well as in methods of Interface0D, Interface1D, Iterator, their subclasses, Noise and
IntegrationType.

* Operators' methods and functions in the ContextFunctions module were renamed from
CamelCase to lower cases + underscores.  Style modules were updated accordingly.

* Additional code clean-up was also made.
2013-02-24 02:39:38 +00:00
ad7c43744c Added GNU GPL header blocks. 2013-02-23 18:32:28 +00:00
6cd036ab96 Code clean-up: Py_TYPE(self)->tp_name instead of ((PyObject *)self)->ob_type->tp_name. 2013-02-22 01:29:50 +00:00
b4e968391d Attribute renaming: .exact_type_name --> .name. Also did a more generic implementation
of the attribute (meant to be a shortcut of .__class__.__name__).
2013-02-21 21:48:52 +00:00
39f8c6e189 Freestyle Python API improvements - part 5.
Handling of keyword arguments in Python wrapper class constructors was revised.
This revision is mainly focused on Interface0D, Interface1D, Iterator, and
their subclasses, as well as a few additional view map component classes.

Implementation notes: Because of the extensive use of constructor overloading
in the underlying C++ classes, the corresponding Python wrappers try to parse
arguments through multiple calls of PyArg_ParseTupleAndKeywords() if needed.
The downside of this implementation is that most argument errors result in the
same error message ("invalid argument(s)") without indicating what is wrong.
For now this issue is left for future work.

* Now the instantiation of ViewVertex is prohibited since the underlying
C++ class is an abstract class.

* Removed the .cast_to_interface0diterator() method from CurvePointIterator
and StrokeVertexIterator.  Instead the constructor of Interface0DIterator now
accepts the instances of these two iterator classes to construct a nested
Interface0DIterator instance that can be passed to Function0D functor objects.
Specifically, an iterator 'it' is passed to a functor 'func' as follows:

  func(Interface0DIterator(it))

instead of:

  func(it.cast_to_interface0diterator())

* Boolean arguments of class constructors only accept values of boolean type.
Input values of other types are considered as error.

* Additional code clean-up was made.
2013-02-21 02:57:44 +00:00
06c51df4db Made code style clean-up and fixed a typo in a docstring. 2013-02-16 14:22:34 +00:00
731d08d497 Freestyle Python API improvements - part 3.
Major API updates were made to address code review comments.
This revision mostly focuses on Python wrappers of C++ 0D and 1D elements (i.e.,
Interface0D and Interface1D, as well as their subclasses).

* Most getter/setter methods were reimplemented as attributes using PyGetSetDef.
Vector attributes are now implemented based on mathutils callbacks.  Boolean
attributes now only accept boolean values.

* The __getitem__ method was removed and the Sequence protocol was used instead.

* The naming of methods and attributes was fixed to follow the naming conventions
of the Blender Python API (i.e., lower case + underscores for methods and attributes,
and CamelCase for classes).  Some naming inconsistency within the Freestyle Python
API was also addressed.

* The Freestyle API had a number of method names including prefix/suffix "A" and
"B", and their meanings were inconsistent (i.e., referring to different things
depending on the classes).  The names with these two letters were replaced with
more straightforward names.  Also some attribute names were changed so as to indicate
the type of the value (e.g., FEdge.next_fedge instead of FEdge.next_edge) in line
with other names explicitly indicating what the value is (e.g., SVertex.viewvertex).

* In addition, some code clean-up was done in both C++ and Python.

Notes:

In summary, the following irregular naming changes were made through this revision
(those resulting from regular changes of naming conventions are not listed):

- CurvePoint: {A,B} --> {first,second}_svertex
- FEdge: vertex{A,B} --> {first,second}_svertex
- FEdge: {next,previous}Edge --> {next,previous}_fedge
- FEdgeSharp: normal{A,B} --> normal_{right,left}
- FEdgeSharp: {a,b}FaceMark --> face_mark_{right,left}
- FEdgeSharp: {a,b}Material --> material_{right,left}
- FEdgeSharp: {a,b}MaterialIndex --> material_index_{right,left}
- FrsCurve: empty --> is_empty
- FrsCurve: nSegments --> segments_size
- TVertex: mate() --> get_mate()
- ViewEdge: fedge{A,B} --> {first,last}_fedge
- ViewEdge: setaShape, aShape --> occlude
- ViewEdge: {A,B} --> {first,last}_viewvertex
- ViewMap: getScene3dBBox --> scene_bbox
2013-02-14 23:48:34 +00:00
156acd3370 Freestyle Python API improvements - part 1.
* The API syntax of StrokeVertex and StrokeAttribute was updated by means of getter/setter
properties instead of class methods.  Python style modules (including the Parameter Editor
implementation) were updated accordingly.

* Code clean-up was done for a few Python style modules, mostly by removing duplicated
definitions of stroke shaders and fixing indentation.
2013-01-27 20:17:49 +00:00
db158b42de Documentation updates: Replaced "string" with "str". 2010-05-28 18:42:11 +00:00
2212564f18 Fixed invalid use of PyUnicode_FromFormat() where PyUnicode_FromString()
should have been used.
2010-05-23 12:10:31 +00:00
dfe2f8dc03 Merged changes in the trunk up to revision 28247. 2010-04-18 02:03:19 +00:00
d7e08f2d33 Major documentation updates. The original Freestyle API reference
(http://freestyle.sourceforge.net/doc/html/index.html) has been
incorporated into the Blender/Freestyle Python API implementation
in the form of Sphinx-based embedded docstrings.  Some C++-specific
descriptions of classes and functions were revised so that they are
suitable for Python programmers.  Missing docstrings were filled,
and sparse descriptions were extended.  By means of the new
documentation system for Blender, an up-to-date Freestyle Python
API reference will be part of the Blender 2.5 documentation.
2010-04-17 23:47:47 +00:00
069d21dddf Made the Freestyle Python API compatible with Python 3. 2009-09-27 00:32:20 +00:00
e2eb4d567c Fixed the handling of constructor arguments in the following Python
types: Interface0D, SVertex, ViewVertex, StrokeVertex, NonTVertex,
and TVertex.
2009-08-02 22:39:21 +00:00
acf97994bc SWIG/directors dependency removal (cont'd)
* Added to python/BPy_Convert.{cpp,h} 4 utility converters below for
better introspection-based automatic type conversion.

  PyObject * Any_BPy_Interface0D_from_Interface0D( Interface0D& if0D );
  PyObject * Any_BPy_Interface1D_from_Interface1D( Interface1D& if1D );
  PyObject * Any_BPy_FEdge_from_FEdge( FEdge& fe );
  PyObject * Any_BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );

There are 4 corresponding converters without the "Any_" prefix.  All
calls of them in the code base were replaced with these new converters
so that the introspection-based automatic conversion would take place
universally.

* python/BPy_Convert.{cpp,h}: Those C++ to Python converters having
had a "_ptr" suffix were renamed to a name without the suffix, and
their arguments were changed so as to take a reference (e.g.,
ViewVertex&) instead of a pointer (e.g., ViewVertex *).  The changed
converters and their new function prototypes are listed below.  These
converters now return a Python wrapper object that retains the passed
reference, instead of retaining a newly created C++ object by the
converters.

  // Interface0D converters
  PyObject * BPy_Interface0D_from_Interface0D( Interface0D& if0D );
  PyObject * BPy_CurvePoint_from_CurvePoint( CurvePoint& cp );
  PyObject * BPy_StrokeVertex_from_StrokeVertex( StrokeVertex& sv );
  PyObject * BPy_SVertex_from_SVertex( SVertex& sv );
  PyObject * BPy_ViewVertex_from_ViewVertex( ViewVertex& vv );
  PyObject * BPy_TVertex_from_TVertex( TVertex& tv );
  PyObject * BPy_NonTVertex_from_NonTVertex( NonTVertex& ntv );
  // Interface1D converters
  PyObject * BPy_Interface1D_from_Interface1D( Interface1D& if1D );
  PyObject * BPy_Chain_from_Chain( Chain& c );
  PyObject * BPy_FEdge_from_FEdge( FEdge& fe );
  PyObject * BPy_FEdgeSharp_from_FEdgeSharp( FEdgeSharp& fes );
  PyObject * BPy_FEdgeSmooth_from_FEdgeSmooth( FEdgeSmooth& fes );
  PyObject * BPy_Stroke_from_Stroke( Stroke& s );
  PyObject * BPy_ViewEdge_from_ViewEdge( ViewEdge& ve );
  PyObject * BPy_directedViewEdge_from_directedViewEdge( ViewVertex::directedViewEdge& dve );
  // some other converters
  PyObject * BPy_ViewShape_from_ViewShape( ViewShape& vs );
  PyObject * BPy_SShape_from_SShape( SShape& ss );
  PyObject * BPy_FrsMaterial_from_FrsMaterial( FrsMaterial& m );
  PyObject * BPy_StrokeAttribute_from_StrokeAttribute( StrokeAttribute& sa );

* Added a "borrowed" flag to the definitions of Python types being
used to wrap C++ components of Freestyle's internal data structures.
The flag indicates whether or not a Python wrapper object has a
reference to a C++ object that comprises the internal data structures.
The deallocation routines of the Python types check this flag and
release a wrapped C++ object only when it is not part of the internal
data structures.  The following files were modified:

  python/BPy_FrsMaterial.{cpp,h}
  python/BPy_Interface0D.{cpp,h}
  python/BPy_Interface1D.{cpp,h}
  python/BPy_SShape.{cpp,h}
  python/BPy_StrokeAttribute.{cpp,h}
  python/BPy_ViewShape.{cpp,h}
  python/Interface0D/BPy_CurvePoint.cpp
  python/Interface0D/BPy_SVertex.cpp
  python/Interface0D/BPy_ViewVertex.cpp
  python/Interface0D/CurvePoint/BPy_StrokeVertex.cpp
  python/Interface0D/ViewVertex/BPy_NonTVertex.cpp
  python/Interface0D/ViewVertex/BPy_TVertex.cpp
  python/Interface1D/BPy_FEdge.cpp
  python/Interface1D/BPy_FrsCurve.cpp
  python/Interface1D/BPy_Stroke.cpp
  python/Interface1D/BPy_ViewEdge.cpp
  python/Interface1D/Curve/BPy_Chain.cpp
  python/Interface1D/FEdge/BPy_FEdgeSharp.cpp
  python/Interface1D/FEdge/BPy_FEdgeSmooth.cpp

* view_map/Interface[01]D.h, python/BPy_Interface[01]D.cpp: Removed
from the Interface0D and Interface1D C++ classes a back pointer to a
Python wrapper object and all "director" calls.  These classes (and
their subclasses) are used to build Freestyle's main data structures
(such as a view map and strokes) and their class hierarchy is static.
Python wrappers of these C++ classes are only used to access the data
structures from the Python layer, and not intended to extend the data
structures by subclassing the Python wrappers.  Without the necessity
of subclassing in the Python layer, the back pointer to a wrapping
Python object and "director" calls would be useless (actually they
were not used at all), so they were all removed.

* python/Director.{cpp,h}: Removed the definitions of directors that
were no longer used.

* stroke/Stroke.{cpp,h}: Removed an (unused) back pointer to a Python
wrapper object.

* python/BPy_ViewMap.cpp: Fixed a possible null pointer reference.

* python/Interface1D/BPy_FEdge.cpp: Fixed parameter checking in
FEdge___init__().
2009-08-02 16:23:18 +00:00
52f639277b Second attempt to fix a null pointer reference in deallocators of
built-in types (the first was in revision 21877).  When an exception
has raised within from the __init__ method of a user-defined class
derived from a built-in type (e.g., UnaryPredicate0D and
BinaryPredicate1D), some member variables of the base type are
left uninitialized, leading to a null pointer reference in the
"__dealloc__" function in the base type.  To avoid this, pointer
checking was added in the deallocators of those built-in types that
can be used to define a subclass by a user.
2009-07-26 20:20:25 +00:00
69853d3e40 Reverted the change in revision 21877 in Interface0D___dealloc__(). 2009-07-26 17:29:25 +00:00
fec3ddabb1 * Better support for vector-like objects in method arguments.
Now the following methods in the Freestyle Python API accept
not only Blender.Mathutils.Vector instances but also lists and
tuples having an appropriate number of elements.

  FrsNoise::turbulence2()
  FrsNoise::turbulence3()
  FrsNoise::smoothNoise2()
  FrsNoise::smoothNoise3()
  SVertex::__init__()
  SVertex::setPoint3D()
  SVertex::setPoint2D()
  SVertex::AddNormal()
  FEdgeSharp::setNormalA()
  FEdgeSharp::setNormalB()
  FEdgeSmooth::setNormal()
  CalligraphicShader::__init__()
  StrokeAttribute::setAttributeVec2f()
  StrokeAttribute::setAttributeVec3f()
  StrokeAttribute::setColor()
  StrokeVertex::setPoint()

* Added the following converters for the sake of the improvements
mentioned above.

  Vec2f_ptr_from_PyObject()
  Vec3f_ptr_from_PyObject()
  Vec3r_ptr_from_PyObject()
  Vec2f_ptr_from_PyList()
  Vec3f_ptr_from_PyList()
  Vec3r_ptr_from_PyList()
  Vec2f_ptr_from_PyTuple()
  Vec3f_ptr_from_PyTuple()
  Vec3r_ptr_from_PyTuple()

Those converters with the suffixes _PyList and _PyTuple accept
only lists and tuples having an appropriate number of elements,
respectively, while those with the suffix _PyObject accept lists,
tuples, or Blender.Mathutils.Vector instances.

* Fixed a null pointer reference in Interface0D___dealloc__().

* Corrected the names of 3 methods in the FEdgeSmooth class.
2009-07-25 11:27:18 +00:00
68e088f1cf Improvements on error handling in the Python API. 2009-03-29 17:44:14 +00:00
Maxime Curioni
e385d69580 soc-2008-mxcurioni: Made crucial corrections to stabilize the system. Most of the original styles are supported: stroke attributes are correctly taken into account, Python shaders are supported. Added SamplingShader. 2008-08-02 07:39:49 +00:00
Maxime Curioni
51f9082c96 soc-2008-mxcurioni: added (but did not test) NonTVertex and TVertex classes. All Interface0D structures have been implemented 2008-07-25 21:56:06 +00:00
Maxime Curioni
a9789d90ae soc-2008-mxcurioni: renamed all Freestyle API related files with 'BPy_' prefix to avoid library name collision.
Included MediumType's initialization at proper time to avoid Blender's crash.
2008-07-23 07:56:08 +00:00