/* * Copyright (c) 2015 Tricoire Sebastien 3dsman@free.fr * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages * arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * * 1. The origin of this software must not be misrepresented; you must not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. * 2. Altered source versions must be plainly marked as such, and must not be * misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. * */ #ifndef OE_DOCUMENT_H #define OE_DOCUMENT_H #include #include #include #include "stitchs/OE_stitchs.h" #include "curves/OE_pointcurve.h" #include "instructions/OE_instruction.h" #include "OE_thread.h" #include "OE_pattern.h" class OE_actions; namespace Pakal { class Archive; } class OE_document { public: class ScopeLock : public std::lock_guard { public: ScopeLock(OE_document& doc);// : std::lock_guard(doc.accessLock) {}; }; bool saveToFile(std::string path); bool loadFromFile(std::string path); bool loadFromPES(std::string path); /** Default constructor */ OE_document(); // OE_document(std::string filename); /** Default destructor */ virtual ~OE_document(); void persist(Pakal::Archive* archive); /** \brief the list of stitchs */ std::list stitchs; /** \brief the list of curves */ std::list curves; /** \brief the list of threads */ std::list threads; /** \brief the list of patterns */ std::list patterns; /** \brief the list of selected stitchs */ std::list selectedStitchs; /** \brief the list of selected curves */ std::list selectedCurves; /** \brief the array of points to send to the embroideress */ std::vector instPoints; /** \brief the array of commands to send to the embroideress */ std::vector instCommand; /** \brief the stack of active actions */ std::list activeActionsStack; /** \brief the stack of undoed actions */ std::list undoActionsStack; /** \brief the current points stitched by the embroideress */ unsigned int curPoint = 0; BoundingBox getBound(); vector_2d getHoopSize(); unsigned int getPulseByMm(); vector_2d getZeroPoint(); void setHoopSize(vector_2d hoopSize); void setPulseByMm(unsigned int pbm); void setZeroPoint(vector_2d zeroPoint); bool addCurve(OE_pointcurve * curve); bool addStitch(OE_stitchs * stitch); bool addThread(OE_thread * thread); bool removeCurve(OE_pointcurve * curve); bool removeStitch(OE_stitchs * stitch); bool removeThread(OE_thread * thread); bool refresh(); void lock(); // lock write int trylock(); // try to lock write, return 0 if success void unlock(); // unlock write protected: private: /** \brief Width of the document. */ float width; /** \brief Height of the document. */ float height; unsigned int pulseByMm = 5; float scale = 0.50f; vector_2d hoopSize = vector_2d(150,160) ; vector_2d zeroPoint = vector_2d(0,0) ; std::recursive_mutex accessLock; }; #endif // OE_DOCUMENT_H