Permalink
Browse files

Add LinePattern ByBlock render, add render of ByBlock entities in ByL…

…ayer insert, fix dxf save
  • Loading branch information...
feragon committed Jun 24, 2017
1 parent 2269ec9 commit 3cdaa75ae79ac7474d7b21400bae73c3c4a90f7c
Showing with 313 additions and 186 deletions.
  1. +37 −17 lcDXFDWG/libdxfrw/dxfimpl.cpp
  2. +1 −0 lcDXFDWG/libdxfrw/dxfimpl.h
  3. +2 −1 lcUI/dialogs/addlayerdialog.cpp
  4. +2 −2 lcUI/dialogs/addlinepatterndialog.cpp
  5. +3 −3 lcUI/dialogs/addlinepatterndialog.h
  6. +8 −2 lcUI/dialogs/linepatternmanager.cpp
  7. +2 −2 lcUI/managers/metainfomanager.cpp
  8. +3 −3 lcUI/managers/metainfomanager.h
  9. +17 −4 lcUI/widgets/colorselect.cpp
  10. +1 −1 lcUI/widgets/colorselect.h
  11. +7 −3 lcUI/widgets/linepatternmodel.cpp
  12. +2 −2 lcUI/widgets/linepatternmodel.h
  13. +2 −2 lcUI/widgets/linepatternpainter.cpp
  14. +3 −3 lcUI/widgets/linepatternpainter.h
  15. +10 −4 lcUI/widgets/linepatternselect.cpp
  16. +1 −1 lcUI/widgets/linepatternselect.h
  17. +8 −1 lcadluascript/lckernelbridge.cpp
  18. +2 −2 lckernel/cad/builders/layer.cpp
  19. +3 −3 lckernel/cad/builders/layer.h
  20. +2 −2 lckernel/cad/builders/linepattern.cpp
  21. +3 −3 lckernel/cad/builders/linepattern.h
  22. +7 −7 lckernel/cad/dochelpers/documentimpl.cpp
  23. +2 −2 lckernel/cad/dochelpers/documentimpl.h
  24. +2 −2 lckernel/cad/dochelpers/storagemanagerimpl.cpp
  25. +1 −1 lckernel/cad/dochelpers/storagemanagerimpl.h
  26. +2 −2 lckernel/cad/document/document.h
  27. +1 −1 lckernel/cad/document/storagemanager.h
  28. +6 −6 lckernel/cad/events/addlinepatternevent.h
  29. +5 −5 lckernel/cad/events/removelinepatternevent.h
  30. +8 −8 lckernel/cad/events/replacelinepatternevent.h
  31. +30 −6 lckernel/cad/meta/dxflinepattern.cpp
  32. +48 −49 lckernel/cad/meta/dxflinepattern.h
  33. +6 −2 lckernel/cad/meta/layer.cpp
  34. +8 −3 lckernel/cad/meta/layer.h
  35. +47 −16 lcviewernoqt/documentcanvas.cpp
  36. +2 −2 unittest/lckernel/builders/buildertest.cpp
  37. +1 −1 unittest/ui/dialogs/addlinepatterndialog.h
  38. +12 −6 unittest/ui/testcolorselect.cpp
  39. +1 −1 unittest/ui/testlayers.cpp
  40. +5 −5 unittest/ui/testlinepatterns.cpp
@@ -389,7 +389,7 @@ lc::MetaInfo_SPtr DXFimpl::getMetaInfo(const DRW_Entity& data) const {
std::shared_ptr<lc::MetaInfo> mf = nullptr;
// Try to find a entities meta line weight
auto lw = getLcLineWidth<lc::EntityMetaType>(data.lWeight);
auto lw = getLcLineWidth<lc::MetaLineWidth>(data.lWeight);
if (lw != nullptr) {
if (mf == nullptr) {
mf = lc::MetaInfo::create();
@@ -417,15 +417,23 @@ lc::MetaInfo_SPtr DXFimpl::getMetaInfo(const DRW_Entity& data) const {
// Most likely a lot of entities within a drawing will be 'BYLAYER' and with the CONTINUOUS linetype.
// These are the default's for LibreCAD
// One thing we need to solve is when entities within a block are loaded and use the BY_LAYER line type and styles
// I will solve that during block importing.
if (!(lc::StringHelper::cmpCaseInsensetive()(data.lineType, SKIP_BYLAYER) || lc::StringHelper::cmpCaseInsensetive()(data.lineType, SKIP_CONTINUOUS))) {
lc::DxfLinePattern_CSPtr linePattern = nullptr;
if(data.lineType == LTYPE_BYBLOCK) {
linePattern = std::make_shared<lc::DxfLinePatternByBlock>();
}
else if (!(lc::StringHelper::cmpCaseInsensetive()(data.lineType, SKIP_BYLAYER) || lc::StringHelper::cmpCaseInsensetive()(data.lineType, SKIP_CONTINUOUS))) {
linePattern = _document->linePatternByName(data.lineType);
}
if(linePattern != nullptr) {
if (mf == nullptr) {
mf = lc::MetaInfo::create();
}
mf->add(_document->linePatternByName(data.lineType));
mf->add(linePattern);
}
return mf;
}
@@ -442,7 +450,7 @@ std::vector<lc::geo::Coordinate> DXFimpl::coords(std::vector<DRW_Coord *> coordL
}
void DXFimpl::addLType(const DRW_LType& data) {
std::make_shared<lc::operation::AddLinePattern>(_document, std::make_shared<lc::DxfLinePattern>(data.name, data.desc, data.path, data.length))->execute();
std::make_shared<lc::operation::AddLinePattern>(_document, std::make_shared<lc::DxfLinePatternByValue>(data.name, data.desc, data.path, data.length))->execute();
}
/**
@@ -678,27 +686,39 @@ void DXFimpl::writeInsert(const lc::entity::Insert_CSPtr i) {
void DXFimpl::getEntityAttributes(DRW_Entity *ent, lc::entity::CADEntity_CSPtr entity) {
auto layer_ = entity->layer();
auto metaPen_ = entity->metaInfo<lc::DxfLinePattern>(lc::DxfLinePattern::LCMETANAME());
auto metaWidth_ = entity->metaInfo<lc::MetaLineWidthByValue>(lc::MetaLineWidthByValue::LCMETANAME());
auto metaColorByBlock_ = entity->metaInfo<lc::MetaColorByValue>(lc::MetaColorByValue::LCMETANAME());
auto lpByValue = entity->metaInfo<lc::DxfLinePatternByValue>(lc::DxfLinePattern::LCMETANAME());
auto lpByBlock = entity->metaInfo<lc::DxfLinePatternByBlock>(lc::DxfLinePattern::LCMETANAME());
auto metaWidthByValue = entity->metaInfo<lc::MetaLineWidthByValue>(lc::MetaLineWidth::LCMETANAME());
auto metaWidthByBlock = entity->metaInfo<lc::MetaLineWidthByBlock>(lc::MetaLineWidth::LCMETANAME());
auto metaColorByBlock = entity->metaInfo<lc::MetaColorByBlock>(lc::MetaColor::LCMETANAME());
auto metaColorByValue = entity->metaInfo<lc::MetaColorByValue>(lc::MetaColor::LCMETANAME());
ent->layer = layer_->name();
if(metaColorByBlock_ != nullptr) {
if(metaColorByBlock != nullptr) {
ent->color = BYBLOCK_COLOR;
}
else {
auto metaColor_ = entity->metaInfo<lc::MetaColorByValue>(lc::MetaColorByValue::LCMETANAME());
else if(metaColorByValue != nullptr) {
lc::iColor col;
auto color_ = col.colorToInt(metaColor_);
auto color_ = col.colorToInt(metaColorByValue->color());
ent->color = color_;
}
if(metaPen_!=nullptr) {
ent->lineType = metaPen_->name();
if(lpByValue != nullptr) {
ent->lineType = lpByValue->name();
}
else if(lpByBlock != nullptr) {
ent->lineType = LTYPE_BYBLOCK;
}
if(metaWidthByValue != nullptr) {
ent->lWeight = static_cast<DRW_LW_Conv::lineWidth>(widthToInt(metaWidthByValue->width()));
}
if(metaWidth_!=nullptr) {
ent->lWeight = static_cast<DRW_LW_Conv::lineWidth>(widthToInt(metaWidth_->width()));
else if(metaWidthByBlock != nullptr) {
ent->lWeight = DRW_LW_Conv::lineWidth::widthByBlock;
}
}
@@ -21,6 +21,7 @@
#include <cad/meta/block.h>
#define BYBLOCK_COLOR 0
#define LTYPE_BYBLOCK "ByBlock"
static const char *const SKIP_BYLAYER = "BYLAYER";
static const char *const SKIP_CONTINUOUS = "CONTINUOUS";
@@ -1,3 +1,4 @@
#include <QtWidgets/QMessageBox>
#include "addlayerdialog.h"
#include "ui_addlayerdialog.h"
@@ -51,7 +52,7 @@ void AddLayerDialog::accept() {
return;
}
auto linePattern = linePatternSelect->linePattern();
auto linePattern = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(linePatternSelect->linePattern());
lc::Layer_CSPtr layer;
auto lineWidth = std::dynamic_pointer_cast<const lc::MetaLineWidthByValue>(lineWidthSelect->lineWidth());
@@ -5,7 +5,7 @@ AddLinePatternDialog::AddLinePatternDialog(lc::Document_SPtr document, QWidget *
AddLinePatternDialog(document, nullptr, parent) {
}
AddLinePatternDialog::AddLinePatternDialog(lc::Document_SPtr document, lc::DxfLinePattern_CSPtr linePattern, QWidget *parent) :
AddLinePatternDialog::AddLinePatternDialog(lc::Document_SPtr document, lc::DxfLinePatternByValue_CSPtr linePattern, QWidget *parent) :
QDialog(parent),
ui(new Ui::AddLinePatternDialog),
_document(document),
@@ -69,7 +69,7 @@ void AddLinePatternDialog::generatePreview() {
}
}
_linePattern = std::make_shared<lc::DxfLinePattern>(
_linePattern = std::make_shared<lc::DxfLinePatternByValue>(
name,
ui->description->text().toStdString(),
path,
@@ -41,7 +41,7 @@ class AddLinePatternDialog : public QDialog {
* \param linePattern Line pattern to edit
* \param parent Parent widget
*/
AddLinePatternDialog(lc::Document_SPtr document, lc::DxfLinePattern_CSPtr linePattern, QWidget* parent = 0);
AddLinePatternDialog(lc::Document_SPtr document, lc::DxfLinePatternByValue_CSPtr linePattern, QWidget* parent = 0);
private slots:
/**
@@ -81,6 +81,6 @@ class AddLinePatternDialog : public QDialog {
private:
lc::Document_SPtr _document;
lc::DxfLinePattern_CSPtr _linePattern;
lc::DxfLinePattern_CSPtr _oldLinePattern;
lc::DxfLinePatternByValue_CSPtr _linePattern;
lc::DxfLinePatternByValue_CSPtr _oldLinePattern;
};
@@ -47,7 +47,10 @@ void LinePatternManager::on_editButton_pressed() {
}
auto row = select->selectedRows().first().row();
auto linePattern = _model->linePatternAt(row);
auto linePattern = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(_model->linePatternAt(row));
if(linePattern == nullptr) {
return;
}
auto dialog = new AddLinePatternDialog(_document, linePattern, this);
dialog->show();
@@ -63,7 +66,10 @@ void LinePatternManager::on_lpView_doubleClicked(const QModelIndex &index) {
return;
}
auto linePattern = _model->linePatternAt(index.row());
auto linePattern = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(_model->linePatternAt(index.row()));
if(!linePattern) {
return;
}
auto dialog = new AddLinePatternDialog(_document, linePattern, this);
dialog->show();
@@ -36,7 +36,7 @@ DxfLinePattern_CSPtr MetaInfoManager::linePattern() const {
return _linePattern;
}
MetaColorByValue_CSPtr MetaInfoManager::color() const {
MetaColor_CSPtr MetaInfoManager::color() const {
return _color;
}
@@ -48,7 +48,7 @@ void MetaInfoManager::setLinePattern(const DxfLinePattern_CSPtr& linePattern) {
_linePattern = linePattern;
}
void MetaInfoManager::setColor(const MetaColorByValue_CSPtr& color) {
void MetaInfoManager::setColor(const MetaColor_CSPtr& color) {
_color = color;
}
@@ -22,7 +22,7 @@ namespace lc {
MetaInfo_CSPtr metaInfo();
DxfLinePattern_CSPtr linePattern() const;
MetaColorByValue_CSPtr color() const;
MetaColor_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 MetaColorByValue_CSPtr& color);
void setColor(const MetaColor_CSPtr& color);
void setLineWidth(const MetaLineWidth_CSPtr& lineWidth);
DxfLinePattern_CSPtr _linePattern;
MetaColorByValue_CSPtr _color;
MetaColor_CSPtr _color;
MetaLineWidth_CSPtr _lineWidth;
};
@@ -19,6 +19,8 @@ ColorSelect::ColorSelect(lc::ui::MetaInfoManager_SPtr metaInfoManager, QWidget *
}
addItem(CUSTOM);
setColor(Color(255, 255, 255));
insertSeparator(count());
for(auto color : QColor::colorNames()){
@@ -84,8 +86,19 @@ void ColorSelect::setColor(lc::Color color) {
void ColorSelect::setMetaInfoManager(lc::ui::MetaInfoManager_SPtr metaInfoManager) {
_metaInfoManager = metaInfoManager;
if(metaInfoManager != nullptr && metaInfoManager->color() != nullptr) {
setColor(metaInfoManager->color()->color());
if(metaInfoManager != nullptr) {
if(metaInfoManager->color() == nullptr) {
setCurrentText(BY_LAYER);
}
else if(std::dynamic_pointer_cast<const lc::MetaColorByBlock>(metaInfoManager->color())) {
setCurrentText(BY_BLOCK);
}
else {
auto colorByValue = std::dynamic_pointer_cast<const lc::MetaColorByValue>(metaInfoManager->color());
if(colorByValue != nullptr) {
setColor(colorByValue->color());
}
}
}
}
@@ -97,12 +110,12 @@ void ColorSelect::updateMetaInfoManager() {
_metaInfoManager->setColor(metaColor());
}
lc::MetaColorByValue_CSPtr ColorSelect::metaColor() {
lc::MetaColor_CSPtr ColorSelect::metaColor() {
if(currentText() == BY_LAYER) {
return nullptr;
}
if(currentText() == BY_BLOCK) {
return nullptr;
return std::make_shared<lc::MetaColorByBlock>();
}
return std::make_shared<const lc::MetaColorByValue>(color());
@@ -43,7 +43,7 @@ namespace lc {
* \brief Returns selected color
* \return Shared pointer to MetaColor
*/
lc::MetaColorByValue_CSPtr metaColor();
lc::MetaColor_CSPtr metaColor();
/**
* \brief Returns selected color
@@ -4,7 +4,7 @@ LinePatternModel::LinePatternModel(QObject *parent) :
QAbstractTableModel(parent) {
}
void LinePatternModel::setLinePatterns(std::vector<lc::DxfLinePattern_CSPtr> linePatterns) {
void LinePatternModel::setLinePatterns(std::vector<lc::DxfLinePatternByValue_CSPtr> linePatterns) {
beginResetModel();
_linePatterns = linePatterns;
@@ -33,9 +33,13 @@ QVariant LinePatternModel::data(const QModelIndex &index, int role) const {
if(role == Qt::DecorationRole && index.column() == PREVIEW) {
QPixmap pixmap(PREVIEW_WIDTH, PREVIEW_HEIGHT);
auto painter = LinePatternPainter(&pixmap, linePattern);
painter.drawLinePattern();
auto linePatternByValue = std::dynamic_pointer_cast<const lc::DxfLinePatternByValue>(linePattern);
if(linePatternByValue != nullptr) {
auto painter = LinePatternPainter(&pixmap, linePatternByValue);
painter.drawLinePattern();
}
return pixmap;
}
@@ -37,7 +37,7 @@ class LinePatternModel : public QAbstractTableModel {
* \param linePatterns New list of DxfLinePatterns
* Update the list
*/
void setLinePatterns(std::vector<lc::DxfLinePattern_CSPtr> linePatterns);
void setLinePatterns(std::vector<lc::DxfLinePatternByValue_CSPtr> linePatterns);
/**
* \brief Return line pattern at specific row.
@@ -53,5 +53,5 @@ class LinePatternModel : public QAbstractTableModel {
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
private:
std::vector<lc::DxfLinePattern_CSPtr> _linePatterns;
std::vector<lc::DxfLinePatternByValue_CSPtr> _linePatterns;
};
@@ -1,12 +1,12 @@
#include "linepatternpainter.h"
LinePatternPainter::LinePatternPainter(QPaintDevice *device, lc::DxfLinePattern_CSPtr linePattern, int width) :
LinePatternPainter::LinePatternPainter(QPaintDevice *device, lc::DxfLinePatternByValue_CSPtr linePattern, int width) :
_device(device),
_linePattern(linePattern),
_width(width) {
}
LinePatternPainter::LinePatternPainter(QPaintDevice *device, double width, lc::DxfLinePattern_CSPtr linePattern) :
LinePatternPainter::LinePatternPainter(QPaintDevice *device, double width, lc::DxfLinePatternByValue_CSPtr linePattern) :
_device(device),
_linePattern(linePattern),
_width(width) {
@@ -15,22 +15,22 @@ class LinePatternPainter {
* \param linePattern LinePattern to paint
* \param width Width of the line (optional)
*/
LinePatternPainter(QPaintDevice* device, lc::DxfLinePattern_CSPtr linePattern, int width = 1);
LinePatternPainter(QPaintDevice* device, lc::DxfLinePatternByValue_CSPtr linePattern, int width = 1);
/**
* \brief Constructor used to paint line width
* \param device Pointer to QPaintDevice
* \param width Width of the line
* \param linePattern LinePattern to paint (optional)
*/
LinePatternPainter(QPaintDevice* device, double width, lc::DxfLinePattern_CSPtr linePattern = nullptr);
LinePatternPainter(QPaintDevice* device, double width, lc::DxfLinePatternByValue_CSPtr linePattern = nullptr);
/**
* \brief Paint line
*/
void drawLinePattern();
private:
QPaintDevice* _device;
lc::DxfLinePattern_CSPtr _linePattern;
lc::DxfLinePatternByValue_CSPtr _linePattern;
int _width;
};
Oops, something went wrong.

0 comments on commit 3cdaa75

Please sign in to comment.