Permalink
Browse files

Add render of ByBlock line width and color

  • Loading branch information...
feragon committed Jun 22, 2017
1 parent bcbd9fd commit 162526195623ca6e9ffb6b61a7d3ba1c2a6cbbfe
@@ -48,15 +48,7 @@ void DXFimpl::setBlock(const int _blockHandle) {
}
void DXFimpl::addBlock(const DRW_Block& data) {
auto lw = getLcLineWidth<lc::MetaLineWidth>(data.lWeight);
auto color = icol.intToColor(data.color);
lc::DxfLinePattern_CSPtr lp = nullptr;
if(!(lc::StringHelper::cmpCaseInsensetive()(data.lineType, SKIP_BYLAYER) || lc::StringHelper::cmpCaseInsensetive()(data.lineType, SKIP_CONTINUOUS))) {
lp = _document->linePatternByName(data.lineType);
}
_currentBlock = std::make_shared<lc::Block>(data.name, coord(data.basePoint), color, lw, lp);
_currentBlock = std::make_shared<lc::Block>(data.name, coord(data.basePoint));
_builder->appendMetaData(_currentBlock);
_blocks.insert(std::pair<std::string, lc::Block_CSPtr>(data.name, _currentBlock));
@@ -407,7 +399,14 @@ lc::MetaInfo_SPtr DXFimpl::getMetaInfo(const DRW_Entity& data) const {
}
// Try to find a entities meta color
auto col = icol.intToColor(data.color);
lc::MetaColor_CSPtr col;
if(data.color == BYBLOCK_COLOR) {
col = std::make_shared<const lc::MetaColorByBlock>();
}
else {
col = icol.intToColor(data.color);
}
if (col != nullptr) {
if (mf == nullptr) {
mf = lc::MetaInfo::create();
@@ -681,15 +680,20 @@ void DXFimpl::getEntityAttributes(DRW_Entity *ent, lc::entity::CADEntity_CSPtr e
auto layer_ = entity->layer();
auto metaPen_ = entity->metaInfo<lc::DxfLinePattern>(lc::DxfLinePattern::LCMETANAME());
auto metaWidth_ = entity->metaInfo<lc::MetaLineWidthByValue>(lc::MetaLineWidthByValue::LCMETANAME());
auto metaColor_ = entity->metaInfo<lc::MetaColor>(lc::MetaColor::LCMETANAME());
auto metaColorByBlock_ = entity->metaInfo<lc::MetaColorByValue>(lc::MetaColorByValue::LCMETANAME());
ent->layer = layer_->name();
if(metaColor_!=nullptr) {
if(metaColorByBlock_ != nullptr) {
ent->color = BYBLOCK_COLOR;
}
else {
auto metaColor_ = entity->metaInfo<lc::MetaColorByValue>(lc::MetaColorByValue::LCMETANAME());
lc::iColor col;
auto color_ = col.colorToInt(metaColor_);
ent->color = color_;
}
if(metaPen_!=nullptr) {
ent->lineType = metaPen_->name();
}
@@ -1081,21 +1085,6 @@ void DXFimpl::writeBlock(const lc::Block_CSPtr block) {
drwBlock.basePoint.y = block->base().y();
drwBlock.basePoint.z = block->base().z();
if(block->color() != nullptr) {
lc::iColor col;
auto color_ = col.colorToInt(block->color()->color());
drwBlock.color = color_;
}
if(block->linePattern() != nullptr) {
drwBlock.lineType = block->linePattern()->name();
}
auto lineWidth = std::dynamic_pointer_cast<const lc::MetaLineWidthByValue>(block->lineWidth());
if(lineWidth != nullptr) {
drwBlock.lWeight = static_cast<DRW_LW_Conv::lineWidth>(widthToInt(lineWidth->width()));
}
dxfW->writeBlock(&drwBlock);
for(auto entity : _document->entitiesByBlock(block).asVector()) {
@@ -20,6 +20,8 @@
#include <tuple>
#include <cad/meta/block.h>
#define BYBLOCK_COLOR 0
static const char *const SKIP_BYLAYER = "BYLAYER";
static const char *const SKIP_CONTINUOUS = "CONTINUOUS";
@@ -160,7 +160,7 @@ lc::MetaInfo_SPtr lc::FileLibs::LibOpenCad::metaInfo(const CADGeometry* geometry
auto metaInfo = MetaInfo::create();
auto color = geometry->getColor();
metaInfo->add(std::make_shared<lc::MetaColor>(lc::Color(color.R, color.G, color.B)));
metaInfo->add(std::make_shared<lc::MetaColorByValue>(lc::Color(color.R, color.G, color.B)));
metaInfo->add(std::make_shared<lc::MetaLineWidthByValue>(geometry->getThickness()));
@@ -36,7 +36,7 @@ DxfLinePattern_CSPtr MetaInfoManager::linePattern() const {
return _linePattern;
}
MetaColor_CSPtr MetaInfoManager::color() const {
MetaColorByValue_CSPtr MetaInfoManager::color() const {
return _color;
}
@@ -48,7 +48,7 @@ void MetaInfoManager::setLinePattern(const DxfLinePattern_CSPtr& linePattern) {
_linePattern = linePattern;
}
void MetaInfoManager::setColor(const MetaColor_CSPtr& color) {
void MetaInfoManager::setColor(const MetaColorByValue_CSPtr& color) {
_color = color;
}
@@ -22,7 +22,7 @@ namespace lc {
MetaInfo_CSPtr metaInfo();
DxfLinePattern_CSPtr linePattern() const;
MetaColor_CSPtr color() const;
MetaColorByValue_CSPtr color() const;
MetaLineWidth_CSPtr lineWidth() const;
private:
@@ -35,11 +35,11 @@ namespace lc {
MetaInfo_SPtr addMetaType(MetaInfo_SPtr metaInfo, EntityMetaType_CSPtr metaType);
void setLinePattern(const DxfLinePattern_CSPtr& linePattern);
void setColor(const MetaColor_CSPtr& color);
void setColor(const MetaColorByValue_CSPtr& color);
void setLineWidth(const MetaLineWidth_CSPtr& lineWidth);
DxfLinePattern_CSPtr _linePattern;
MetaColor_CSPtr _color;
MetaColorByValue_CSPtr _color;
MetaLineWidth_CSPtr _lineWidth;
};
@@ -97,15 +97,15 @@ void ColorSelect::updateMetaInfoManager() {
_metaInfoManager->setColor(metaColor());
}
lc::MetaColor_CSPtr ColorSelect::metaColor() {
lc::MetaColorByValue_CSPtr ColorSelect::metaColor() {
if(currentText() == BY_LAYER) {
return nullptr;
}
if(currentText() == BY_BLOCK) {
return nullptr;
}
return std::make_shared<const lc::MetaColor>(color());
return std::make_shared<const lc::MetaColorByValue>(color());
}
lc::Color ColorSelect::color() {
@@ -43,7 +43,7 @@ namespace lc {
* \brief Returns selected color
* \return Shared pointer to MetaColor
*/
lc::MetaColor_CSPtr metaColor();
lc::MetaColorByValue_CSPtr metaColor();
/**
* \brief Returns selected color
@@ -55,12 +55,12 @@ void LCLua::importLCKernel() {
)
.endClass()
.beginExtendClass<MetaColor, DocumentMetaType>("DocumentMetaColor")
.addConstructor(LUA_SP(MetaColor_SPtr), LUA_ARGS(const Color))
.beginExtendClass<MetaColorByValue, DocumentMetaType>("DocumentMetaColor")
.addConstructor(LUA_SP(MetaColorByValue_SPtr), LUA_ARGS(const Color))
.endClass()
.beginExtendClass<MetaColor, EntityMetaType>("EntityMetaColor")
.addConstructor(LUA_SP(MetaColor_SPtr), LUA_ARGS(const Color))
.beginExtendClass<MetaColorByValue, EntityMetaType>("EntityMetaColor")
.addConstructor(LUA_SP(MetaColorByValue_SPtr), LUA_ARGS(const Color))
.endClass()
.beginExtendClass<MetaLineWidthByBlock, MetaType>("MetaLineWidthByBlock")
@@ -113,7 +113,7 @@ namespace lc {
/**
* Retreive meta information back from this entity
* returns nullptr when the specific meta info wasn't found
* example: auto metaData = myEntity.metaInfo<lc::MetaColor>(lc::MetaInfo::_COLOR);
* example: auto metaData = myEntity.metaInfo<lc::MetaColorByValue>(lc::MetaInfo::_COLOR);
*/
template<typename T>
const std::shared_ptr<const T> metaInfo(std::string metaName) const {
@@ -1,12 +1,8 @@
#include "block.h"
lc::Block::Block(std::string name, lc::geo::Coordinate base,
lc::MetaColor_CSPtr color, lc::MetaLineWidth_CSPtr lineWidth, lc::DxfLinePattern_CSPtr linePattern) :
lc::Block::Block(std::string name, lc::geo::Coordinate base) :
_name(name),
_base(base),
_color(color),
_lineWidth(lineWidth),
_linePattern(linePattern) {
_base(base) {
}
const std::string lc::Block::id() const {
@@ -19,16 +15,4 @@ const std::string lc::Block::name() const {
const lc::geo::Coordinate& lc::Block::base() const {
return _base;
}
const lc::MetaColor_CSPtr& lc::Block::color() const {
return _color;
}
const lc::EntityMetaType_CSPtr& lc::Block::lineWidth() const {
return _lineWidth;
}
const lc::DxfLinePattern_CSPtr& lc::Block::linePattern() const {
return _linePattern;
}
}
@@ -12,23 +12,16 @@
namespace lc {
class Block : public DocumentMetaType {
public:
Block(std::string name, geo::Coordinate base,
lc::MetaColor_CSPtr color, lc::MetaLineWidth_CSPtr lineWidth, lc::DxfLinePattern_CSPtr linePattern);
Block(std::string name, geo::Coordinate base);
const std::string id() const override;
const std::string name() const override;
const geo::Coordinate& base() const;
const MetaColor_CSPtr& color() const;
const EntityMetaType_CSPtr& lineWidth() const;
const DxfLinePattern_CSPtr& linePattern() const;
private:
std::string _name;
geo::Coordinate _base;
lc::MetaColor_CSPtr _color; //TODO: that's should probably be changed to a pointer to lc::Color
lc::MetaLineWidth_CSPtr _lineWidth;
lc::DxfLinePattern_CSPtr _linePattern;
};
using Block_SPtr = std::shared_ptr<Block>;
Oops, something went wrong.

0 comments on commit 1625261

Please sign in to comment.