From 71b43d4d52f4fa422a4d039d7e68fa5e6997ea18 Mon Sep 17 00:00:00 2001
From: Ivan Mahonin <bh@icystar.com>
Date: May 01 2023 07:52:43 +0000
Subject: #assistants: TAssistantsImage


---

diff --git a/toonz/sources/common/tassistantsimage/tassistantsimage.cpp b/toonz/sources/common/tassistantsimage/tassistantsimage.cpp
new file mode 100644
index 0000000..79bf506
--- /dev/null
+++ b/toonz/sources/common/tassistantsimage/tassistantsimage.cpp
@@ -0,0 +1,33 @@
+
+
+#include "tassistantsimage.h"
+
+//---------------------------------------------------------
+
+TAssistantsImage::TAssistantsImage()
+  { }
+
+//---------------------------------------------------------
+
+TAssistantsImage::TAssistantsImage(const TAssistantsImage &other):
+  m_assistants(*Reader(other))
+  { }
+
+//---------------------------------------------------------
+
+TAssistantsImage::~TAssistantsImage()
+  { }
+
+//---------------------------------------------------------
+
+TImage*
+TAssistantsImage::cloneImage() const
+  { return new TAssistantsImage(*this); }
+
+//---------------------------------------------------------
+
+TRectD
+TAssistantsImage::getBBox() const
+  { return TRectD(); }
+
+//---------------------------------------------------------
diff --git a/toonz/sources/include/tassistantsimage.h b/toonz/sources/include/tassistantsimage.h
new file mode 100644
index 0000000..6848556
--- /dev/null
+++ b/toonz/sources/include/tassistantsimage.h
@@ -0,0 +1,101 @@
+#pragma once
+
+#ifndef TASSISTANTSIMAGE_INCLUDED
+#define TASSISTANTSIMAGE_INCLUDED
+
+#include "timage.h"
+#include "tthreadmessage.h"
+
+#include <QReadLocker>
+#include <QWriteLocker>
+#include <QReadWriteLock>
+
+#include <string>
+
+#undef DVAPI
+#undef DVVAR
+#ifdef TASSISTANTSIMAGE_EXPORTS
+#define DVAPI DV_EXPORT_API
+#define DVVAR DV_EXPORT_VAR
+#else
+#define DVAPI DV_IMPORT_API
+#define DVVAR DV_IMPORT_VAR
+#endif
+
+//-------------------------------------------------------------------
+
+class TAssistantDesc;
+typedef std::vector<TAssistantDesc> TAssistantDescList;
+
+//-------------------------------------------------------------------
+
+class TAssistantDesc {
+public:
+  std::string type;
+  std::vector<TPointD> points;
+  TSmartObjectP handler;
+};
+
+//-------------------------------------------------------------------
+
+//! An image containing an assistants for painting.
+
+class DVAPI TAssistantsImage final : public TImage {
+public:
+  class Reader: public QReadLocker {
+  private:
+    const TAssistantsImage &m_image;
+  public:
+    Reader(const TAssistantsImage &image):
+      QReadLocker(&image.m_rwLock), m_image(image) { }
+    const TAssistantsImage& image() const
+      { return m_image; }
+    const TAssistantDescList& get() const
+      { return m_image.m_assistants; }
+    const TAssistantDescList& operator*() const
+      { return get(); }
+    const TAssistantDescList* operator->() const
+      { return &get(); }
+  };
+
+  class Writer: public QWriteLocker {
+  private:
+    TAssistantsImage &m_image;
+  public:
+    Writer(TAssistantsImage &image):
+      QWriteLocker(&image.m_rwLock), m_image(image) { }
+    TAssistantsImage& image() const
+      { return m_image; }
+    TAssistantDescList& get() const
+      { return m_image.m_assistants; }
+    TAssistantDescList& operator*() const
+      { return get(); }
+    TAssistantDescList* operator->() const
+      { return &get(); }
+  };
+
+private:
+  mutable QReadWriteLock m_rwLock;
+  TAssistantDescList m_assistants;
+
+public:
+  TAssistantsImage();
+  ~TAssistantsImage();
+
+private:
+  //! not implemented
+  TAssistantsImage(const TAssistantsImage &other);
+  TAssistantsImage &operator=(const TAssistantsImage &) { return *this; }
+
+public:
+  //! Return the image type
+  TImage::Type getType() const override { return TImage::ASSISTANTS; }
+
+  //! Return a clone of image
+  TImage* cloneImage() const override;
+
+  //! Return the bbox of the image
+  TRectD getBBox() const override;
+};
+
+#endif
diff --git a/toonz/sources/include/timage.h b/toonz/sources/include/timage.h
index f11660d..63aeff0 100644
--- a/toonz/sources/include/timage.h
+++ b/toonz/sources/include/timage.h
@@ -49,7 +49,8 @@ lines, curves, and shapes or polygon(s),
     RASTER       = 1,  //!< A fullcolor raster image.
     VECTOR       = 2,  //!< A vector image.
     TOONZ_RASTER = 3,  //!< A colormap raster image.
-    MESH         = 4   //!< A textured mesh image.
+    MESH         = 4,  //!< A textured mesh image.
+    ASSISTANTS   = 5   //!< An assistants for painting image.
   };
 
   /*!
diff --git a/toonz/sources/include/tsmartpointer.h b/toonz/sources/include/tsmartpointer.h
index 1f68dc7..ed1e3fc 100644
--- a/toonz/sources/include/tsmartpointer.h
+++ b/toonz/sources/include/tsmartpointer.h
@@ -182,4 +182,8 @@ public:
   }
 };
 
+//=========================================================
+
+typedef TSmartPointerT<TSmartObject> TSmartObjectP;
+
 #endif
diff --git a/toonz/sources/tnzcore/CMakeLists.txt b/toonz/sources/tnzcore/CMakeLists.txt
index e1cdaa2..0ee1d74 100644
--- a/toonz/sources/tnzcore/CMakeLists.txt
+++ b/toonz/sources/tnzcore/CMakeLists.txt
@@ -120,6 +120,7 @@ set(HEADERS ${MOC_HEADERS}
     ../include/tmeshimage.h
     ../include/tgldisplaylistsmanager.h
     ../include/tversion.h
+    ../include/tassistantsimage.h
 )
 
 set(SOURCES
@@ -242,6 +243,7 @@ set(SOURCES
     ../common/tmeshimage/tmeshimage.cpp
     ../common/tmsgcore.cpp
     ../common/tvrender/tfont_qt.cpp
+    ../common/tassistantsimage/tassistantsimage.cpp
 )
 
 if(BUILD_TARGET_WIN)
@@ -282,6 +284,7 @@ add_definitions(
     -DTSOUND_EXPORTS
     -DTIMAGE_IO_EXPORTS
     -DTRASTERIMAGE_EXPORTS
+    -DTASSISTANTSIMAGE_EXPORTS
     -DTVRENDER_EXPORTS
     -DTFLASH_EXPORTS
     -DTROP_EXPORTS