diff options
author | David Crocker <dcrocker@eschertech.com> | 2020-03-26 17:45:22 +0300 |
---|---|---|
committer | David Crocker <dcrocker@eschertech.com> | 2020-03-26 17:45:22 +0300 |
commit | ee519544acbee712ff1b9acf94a4bff83114aa85 (patch) | |
tree | 5ef60a2369903f2d0235b838c77c624fd05c8aef /src/GCodes/ObjectTracker.h | |
parent | d2d3da87b8c0c495bb23e935391a8373bbed9128 (diff) |
Partially implemented object cancellation
M486 implemented, but parsing object names in comments not done yet
Diffstat (limited to 'src/GCodes/ObjectTracker.h')
-rw-r--r-- | src/GCodes/ObjectTracker.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/GCodes/ObjectTracker.h b/src/GCodes/ObjectTracker.h new file mode 100644 index 00000000..8e492610 --- /dev/null +++ b/src/GCodes/ObjectTracker.h @@ -0,0 +1,99 @@ +/* + * ObjectTracker.h + * + * Created on: 24 Mar 2020 + * Author: David + */ + +#ifndef SRC_GCODES_OBJECTTRACKER_H_ +#define SRC_GCODES_OBJECTTRACKER_H_ + +#include <RepRapFirmware.h> +#include "GCodeResult.h" +#include "RestorePoint.h" +#include <ObjectModel/ObjectModel.h> +#include <General/StringBuffer.h> + +#if TRACK_OBJECT_NAMES + +struct ObjectDirectoryEntry INHERIT_OBJECT_MODEL +{ + const char *name; // pointer to the object name within the string buffer + float x[2], y[2]; // lowest and highest extrusion coordinates + + void Init(const char *label) noexcept; + void UpdateObjectCoordinates(const float coords[]) noexcept; + +protected: + DECLARE_OBJECT_MODEL + OBJECT_MODEL_ARRAY(x) + OBJECT_MODEL_ARRAY(y) +}; + +#endif + +class ObjectTracker +#if TRACK_OBJECT_NAMES + INHERIT_OBJECT_MODEL +#endif +{ +public: + ObjectTracker() noexcept + : numObjects(0) +#if TRACK_OBJECT_NAMES + , objectNames(stringBufferStorage, ARRAY_SIZE(stringBufferStorage)) +#endif + { } + + void Init() noexcept; + bool IsCurrentObjectCancelled() const noexcept { return currentObjectCancelled; } + bool IsFirstMoveSincePrintingResumed() const noexcept { return printingJustResumed; } + void DoneMoveSincePrintingResumed() noexcept { printingJustResumed = false; } + GCodeResult HandleM486(GCodeBuffer& gb, const StringRef &reply) THROWS(GCodeException); // Handle M486 + const RestorePoint& GetInitialPosition() const noexcept { return rp; } + void SetVirtualTool(int toolNum) noexcept { virtualToolNumber = toolNum; } + +#if TRACK_OBJECT_NAMES + void StartObject(GCodeBuffer& gb, const char *label) noexcept; + void StopObject(GCodeBuffer& gb) noexcept; + void UpdateObjectCoordinates(const float coords[]) noexcept; +#endif + +protected: + +#if TRACK_OBJECT_NAMES + DECLARE_OBJECT_MODEL + OBJECT_MODEL_ARRAY(objects) +#endif + +private: + typedef Bitmap<uint32_t> ObjectCancellationBitmap; // Type of a bitmap used to represent objects on the build plate that have been cancelled + + void ChangeToObject(GCodeBuffer& gb, int i) noexcept; + void StopPrinting(GCodeBuffer& gb) noexcept; + void ResumePrinting(GCodeBuffer& gb) noexcept; + +#if TRACK_OBJECT_NAMES + void CreateObject(unsigned int number, const char *label) noexcept; + void SetObjectName(unsigned int number, const char *label) noexcept; +#endif + + RestorePoint rp; // The user coordinates at the point of restarting moves after skipping an object + ObjectCancellationBitmap objectsCancelled; // Which object numbers have been cancelled. The number of bits in this is the maximum number of objects we can track. + unsigned int numObjects; // How many objects we know about, if known + int currentObjectNumber; // the current object number, or a negative value if it isn't an object + int virtualToolNumber; // the number of the tool that was active when we cancelled an object + +#if TRACK_OBJECT_NAMES + ObjectDirectoryEntry objectDirectory[MaxTrackedObjects]; + StringBuffer objectNames; + char stringBufferStorage[ObjectNamesStringSpace]; + bool usingM486Naming; +#endif + + bool usingM486Labelling; + bool currentObjectCancelled; // true if the current object should not be printed + bool printingJustResumed; // true if we have just restarted printing +}; + +#endif /* SRC_GCODES_OBJECTTRACKER_H_ */ |