[Bf-blender-cvs] [21de669141d] master: Splines: Function to copy spline settings without data

Hans Goudey noreply at git.blender.org
Wed Jun 2 15:11:46 CEST 2021


Commit: 21de669141dc8cde86eb8edfb18ab614c2b3109e
Author: Hans Goudey
Date:   Wed Jun 2 09:11:35 2021 -0400
Branches: master
https://developer.blender.org/rB21de669141dc8cde86eb8edfb18ab614c2b3109e

Splines: Function to copy spline settings without data

Often you need to copy a spline to do an operation, but don't want
to manually copy over all of the settings. I've already forgotten to
do it once anyway. These functions copy a spline's "settings" into a
new spline, but not the data. I tried to avoid duplicating any copying
so this is easier to extend in the future.

Differential Revision: https://developer.blender.org/D11463

===================================================================

M	source/blender/blenkernel/BKE_spline.hh
M	source/blender/blenkernel/intern/spline_bezier.cc
M	source/blender/blenkernel/intern/spline_nurbs.cc
M	source/blender/blenkernel/intern/spline_poly.cc

===================================================================

diff --git a/source/blender/blenkernel/BKE_spline.hh b/source/blender/blenkernel/BKE_spline.hh
index ef76c699cbb..fc1292e3620 100644
--- a/source/blender/blenkernel/BKE_spline.hh
+++ b/source/blender/blenkernel/BKE_spline.hh
@@ -101,15 +101,14 @@ class Spline {
   Spline(const Type type) : type_(type)
   {
   }
-  Spline(Spline &other)
-      : normal_mode(other.normal_mode),
-        attributes(other.attributes),
-        type_(other.type_),
-        is_cyclic_(other.is_cyclic_)
+  Spline(Spline &other) : attributes(other.attributes), type_(other.type_)
   {
+    copy_base_settings(other, *this);
   }
 
   virtual SplinePtr copy() const = 0;
+  /** Return a new spline with the same type and settings like "cyclic", but without any data. */
+  virtual SplinePtr copy_settings() const = 0;
 
   Spline::Type type() const;
 
@@ -183,6 +182,12 @@ class Spline {
 
  protected:
   virtual void correct_end_tangents() const = 0;
+  /** Copy settings stored in the base spline class. */
+  static void copy_base_settings(const Spline &src, Spline &dst)
+  {
+    dst.normal_mode = src.normal_mode;
+    dst.is_cyclic_ = src.is_cyclic_;
+  }
 };
 
 /**
@@ -236,6 +241,7 @@ class BezierSpline final : public Spline {
 
  public:
   virtual SplinePtr copy() const final;
+  SplinePtr copy_settings() const final;
   BezierSpline() : Spline(Type::Bezier)
   {
   }
@@ -377,6 +383,7 @@ class NURBSpline final : public Spline {
 
  public:
   SplinePtr copy() const final;
+  SplinePtr copy_settings() const final;
   NURBSpline() : Spline(Type::NURBS)
   {
   }
@@ -444,6 +451,7 @@ class PolySpline final : public Spline {
 
  public:
   SplinePtr copy() const final;
+  SplinePtr copy_settings() const final;
   PolySpline() : Spline(Type::Poly)
   {
   }
diff --git a/source/blender/blenkernel/intern/spline_bezier.cc b/source/blender/blenkernel/intern/spline_bezier.cc
index 4f2625c14d3..3c6cf2c78cf 100644
--- a/source/blender/blenkernel/intern/spline_bezier.cc
+++ b/source/blender/blenkernel/intern/spline_bezier.cc
@@ -31,6 +31,14 @@ SplinePtr BezierSpline::copy() const
   return std::make_unique<BezierSpline>(*this);
 }
 
+SplinePtr BezierSpline::copy_settings() const
+{
+  std::unique_ptr<BezierSpline> copy = std::make_unique<BezierSpline>();
+  copy_base_settings(*this, *copy);
+  copy->resolution_ = resolution_;
+  return copy;
+}
+
 int BezierSpline::size() const
 {
   const int size = positions_.size();
diff --git a/source/blender/blenkernel/intern/spline_nurbs.cc b/source/blender/blenkernel/intern/spline_nurbs.cc
index ae691d26cdb..cae206341a0 100644
--- a/source/blender/blenkernel/intern/spline_nurbs.cc
+++ b/source/blender/blenkernel/intern/spline_nurbs.cc
@@ -32,6 +32,16 @@ SplinePtr NURBSpline::copy() const
   return std::make_unique<NURBSpline>(*this);
 }
 
+SplinePtr NURBSpline::copy_settings() const
+{
+  std::unique_ptr<NURBSpline> copy = std::make_unique<NURBSpline>();
+  copy_base_settings(*this, *copy);
+  copy->knots_mode = knots_mode;
+  copy->resolution_ = resolution_;
+  copy->order_ = order_;
+  return copy;
+}
+
 int NURBSpline::size() const
 {
   const int size = positions_.size();
diff --git a/source/blender/blenkernel/intern/spline_poly.cc b/source/blender/blenkernel/intern/spline_poly.cc
index 5c33b0052fc..5f8e81d5ad0 100644
--- a/source/blender/blenkernel/intern/spline_poly.cc
+++ b/source/blender/blenkernel/intern/spline_poly.cc
@@ -28,6 +28,13 @@ SplinePtr PolySpline::copy() const
   return std::make_unique<PolySpline>(*this);
 }
 
+SplinePtr PolySpline::copy_settings() const
+{
+  std::unique_ptr<PolySpline> copy = std::make_unique<PolySpline>();
+  copy_base_settings(*this, *copy);
+  return copy;
+}
+
 int PolySpline::size() const
 {
   const int size = positions_.size();



More information about the Bf-blender-cvs mailing list