Permalink
Browse files

Create access to custom entities which are not managed by a plugin

  • Loading branch information...
feragon committed Jul 12, 2017
1 parent 88cc116 commit 9cb267378da4c8d557ec13acce0d22b2f123deec
@@ -28,7 +28,7 @@ bool CustomEntityBuilder::checkValues() {
return InsertBuilder::checkValues() &&
_snapFunction.isValid() && _snapFunction.isFunction() &&
_nearestPointFunction.isValid() && _nearestPointFunction.isFunction() &&
_dragPointsFunction.isValid() && _dragPointsFunction.isFunction();
_dragPointsFunction.isValid() && _dragPointsFunction.isFunction() &&
_newDragPointsFunction.isValid() && _newDragPointsFunction.isFunction();
}
@@ -139,6 +139,7 @@ void LCLua::importLCKernel() {
.beginClass<Document>("Document")
.addFunction("layerByName", &Document::layerByName)
.addFunction("entitiesByLayer", &Document::entitiesByLayer)
.addFunction("waitingCustomEntities", &Document::waitingCustomEntities)
.endClass()
.beginExtendClass<DocumentImpl, Document>("DocumentImpl")
@@ -1,7 +1,10 @@
#include <string>
#include <unordered_map>
#include <cad/meta/customentitystorage.h>
#include "documentimpl.h"
#include <cad/primitive/insert.h>
#include <cad/primitive/customentity.h>
using namespace lc;
@@ -34,24 +37,36 @@ void DocumentImpl::commit(operation::DocumentOperation_SPtr operation) {
}
void DocumentImpl::insertEntity(const entity::CADEntity_CSPtr cadEntity) {
if(cadEntity->block() != nullptr) {
}
if (_storageManager->entityByID(cadEntity->id()) != nullptr) {
_storageManager->removeEntity(cadEntity);
RemoveEntityEvent event(cadEntity);
removeEntityEvent()(event);
removeEntity(cadEntity);
}
_storageManager->insertEntity(cadEntity);
AddEntityEvent event(cadEntity);
addEntityEvent()(event);
auto insert = std::dynamic_pointer_cast<const entity::Insert>(cadEntity);
if(insert != nullptr && std::dynamic_pointer_cast<const entity::CustomEntity>(cadEntity) == nullptr) {
auto ces = std::dynamic_pointer_cast<const CustomEntityStorage>(insert->displayBlock());
if(ces != nullptr) {
_waitingCustomEntities[ces->pluginName()][insert->id()] = insert;
}
}
}
void DocumentImpl::removeEntity(const entity::CADEntity_CSPtr entity) {
_storageManager->removeEntity(entity);
RemoveEntityEvent event(entity);
removeEntityEvent()(event);
auto insert = std::dynamic_pointer_cast<const entity::Insert>(entity);
if(insert != nullptr && std::dynamic_pointer_cast<const entity::CustomEntity>(entity) == nullptr) {
auto ces = std::dynamic_pointer_cast<const CustomEntityStorage>(insert->displayBlock());
if(ces != nullptr) {
_waitingCustomEntities[ces->pluginName()].erase(insert->id());
}
}
}
@@ -154,3 +169,7 @@ EntityContainer<entity::CADEntity_CSPtr> DocumentImpl::entitiesByBlock(const Blo
std::vector<Block_CSPtr> DocumentImpl::blocks() const {
return _storageManager->metaTypes<const Block>();
}
std::map<ID_DATATYPE, entity::Insert_CSPtr> DocumentImpl::waitingCustomEntities(const std::string& pluginName) {
return _waitingCustomEntities[pluginName];
}
@@ -64,12 +64,16 @@ namespace lc {
virtual StorageManager_SPtr storageManager() const;
public:
std::map<ID_DATATYPE, entity::Insert_CSPtr> waitingCustomEntities(const std::string& pluginName) override;
std::vector<Block_CSPtr> blocks() const override;
private:
std::mutex _documentMutex;
// AI am considering remove the shared_ptr from this one so we can never get a shared object from it
StorageManager_SPtr _storageManager;
std::map<std::string, std::map<ID_DATATYPE, entity::Insert_CSPtr>> _waitingCustomEntities;
};
}
@@ -210,6 +210,12 @@ namespace lc {
* @return all blocks
*/
virtual std::vector<Block_CSPtr> blocks() const = 0;
/**
* @return all the custom entities which aren't managed by a plugin
*/
virtual std::map<ID_DATATYPE, entity::Insert_CSPtr> waitingCustomEntities(const std::string& pluginName) = 0;
public:
friend class lc::operation::DocumentOperation;

0 comments on commit 9cb2673

Please sign in to comment.