/*
* This file is part of project OpenEmbroidery. It's copyrighted by
* the contributors recorded in the version control history of the file.
* Original project location https://code.electrolab.fr/openEmbroidery/openEmbroidery_software
*
* SPDX-License-Identifier: CECILL-2.1
* License-Filename: Licence_CeCILL_V2.1-en.txt
*/

#pragma once

#include "OE_utils.h"
#include "OE_thread.h"
#include <stdint.h>
#include <set>

namespace Pakal { class Archive; }

class OE_base
{
	public:
		/** Default constructor */
		OE_base();
		/** Default destructor */
		virtual ~OE_base();

		void persist(Pakal::Archive* archive);

		bool getNeedRefresh();
		void setNeedRefresh();
		
		/** \brief add and remove dependency from the set
		 * \param object -> the dependency object
		 */		
		void addDependency(OE_base * object);
		void removeDependency(OE_base * object);
		/** \brief call all parent of an object to signal the dependency
		 */
		virtual void refreshDependency();
		
		/** \brief the function called by a reference object when he's deleted
		 * \param object -> the reference object
		 */	
		virtual void delDependency(OE_base * /*object*/){}

		/** \brief calculate the object bounding box
		 * \param xMin,yMin,xMax,yMax -> pointers to the bouding box variables to set
		 */		
		virtual BoundingBox getBound() = 0;
		
		/** \brief check if the object is valid. */
		virtual bool check() = 0;
		
		virtual void refresh(float dpi, bool force = false) = 0;
		
	protected:
	
		std::set<OE_base*> dependency;

		/** \brief Tight bounding box of the object [minx,miny,maxx,maxy]. */
		BoundingBox bounds;
		
		/** \brief flag to know who must be refreeshed */
		bool needRefresh;
		
		/** \brief check if a point is in a given bounding box
		 * \param pt -> the point
		 * \param bounds -> an array representing the bounding box
		 * \return true if the point is inside the bounding box
		 */
		static bool ptInBounds( vector_2d pt, float* bounds);
    private:
		
};

