Permalink
Browse files

DxfLinePattern line width support

  • Loading branch information...
feragon committed Jul 22, 2016
1 parent d824af7 commit 6c86b3962c7994e7cfb24e0fa718efd251834ed1
Showing with 36 additions and 29 deletions.
  1. +17 −6 lckernel/cad/meta/dxflinepattern.cpp
  2. +5 −6 lckernel/cad/meta/dxflinepattern.h
  3. +14 −17 lcviewernoqt/documentcanvas.cpp
@@ -9,17 +9,18 @@
using namespace lc;
DxfLinePattern::DxfLinePattern(const std::string &name, const std::string &description, const std::vector<double> &path, const double length) :
_name(name), _description(description), _path(path), _lcPattern(generatePattern(path, length)), _length(length) {
DxfLinePattern::DxfLinePattern(const std::string &name, const std::string &description, const std::vector<double> &path, const double length, const double lineWidth) :
_name(name), _description(description), _path(path), _length(length) {
assert(!StringHelper::isBlank(name) > 0 && "Name of DxfLinePattern must be given");
// Continues has a path length of 0 assert(_path.size() > 0 && "Path length must be > 0");
_lcPatterns[lineWidth] = generatePattern(path, length, lineWidth);
}
double DxfLinePattern::calculatePathLength(const std::vector<double> &_path) {
return std::fabs(std::accumulate(_path.begin(), _path.end(), 0.));
}
std::vector<double> DxfLinePattern::generatePattern(const std::vector<double> &dxfPattern, const double length) const {
std::vector<double> DxfLinePattern::generatePattern(const std::vector<double> &dxfPattern, const double length, const double lineWidth) const {
// DXF Linestyle Pattern is as follows
// Parameters pattern – is a list of float values, elements > 0 are solid line segments, elements < 0 are gaps and elements = 0 are points. pattern[0] = total pattern length in drawing units
// w need to generate them as follows:
@@ -39,13 +40,13 @@ std::vector<double> DxfLinePattern::generatePattern(const std::vector<double> &d
for (auto d : dxfPattern) {
if (d == 0.) { // dot
if (isInk) {
dxfPat.push_back(.1);
dxfPat.push_back(lineWidth);
} else {
dxfPat.push_back(0.);
dxfPat.push_back(.1);
dxfPat.push_back(lineWidth);
isInk = !isInk;
}
d = last + 0.1;
d = last + 1;
} else if (d < 0.) { // skip
if (isInk) {
dxfPat.push_back(0.);
@@ -76,3 +77,13 @@ std::vector<double> DxfLinePattern::generatePattern(const std::vector<double> &d
return dxfPat;
}
const std::vector<double> DxfLinePattern::lcPattern(double lineWidth) const {
try {
return _lcPatterns.at(lineWidth);
}
catch (std::out_of_range &e) {
auto pattern = generatePattern(_path, _length, lineWidth);
_lcPatterns[lineWidth] = pattern;
return pattern;
}
}
@@ -8,6 +8,7 @@
#include "cad/const.h"
#include <cassert>
#include <vector>
#include <map>
namespace lc {
/**
@@ -20,7 +21,7 @@ namespace lc {
DxfLinePattern() {}
DxfLinePattern(const std::string &_name, const std::string &_description, const std::vector<double> &_path, const double length);
DxfLinePattern(const std::string &_name, const std::string &_description, const std::vector<double> &_path, const double length, const double lineWidth = 1);
virtual ~DxfLinePattern() = default;
@@ -58,17 +59,15 @@ namespace lc {
return "_LINEPATTERN";
}
std::vector<double> generatePattern(const std::vector<double> & dxfPattern, const double length) const;
std::vector<double> generatePattern(const std::vector<double> & dxfPattern, const double length, const double lineWidth) const;
const std::vector<double> &lcPattern() const {
return _lcPattern;
}
const std::vector<double> lcPattern(double lineWidth = 1) const;
private:
std::string _name;
std::string _description;
std::vector<double> _path;
std::vector<double> _lcPattern;
mutable std::map<double, std::vector<double>> _lcPatterns;
double _length;
};
using DxfLinePattern_SPtr = std::shared_ptr<DxfLinePattern>;
@@ -361,28 +361,25 @@ void DocumentCanvas::drawEntity(LCVDrawItem_CSPtr entity) {
// Used to give the illusation from slightly thinner lines. Not sure yet what to d with it and if I will keep it
double alpha_compensation = 0.9;
// Decide on line width
// Decide on line width
// We multiply for now by 3 to ensure that 1mm lines will still appear thicker on screen
// TODO: Find a better algo
double width;
if (entityLineWidth != nullptr) {
// We multiply for now by 3 to ensure that 1mm lines will still appear thicker on screen
// TODO: Find a better algo
double width = entityLineWidth->width() * 1.5;
// Is this correct? May be we should decide on a different minimum width then 0.1, because may be on some devices 0.11 isn't visible?
painter.line_width(std::max(width, MINIMUM_READER_LINEWIDTH));
width = entityLineWidth->width() * 1.5;
} else {
// We multiply for now by 3 to ensure that 1mm lines will still appear thicker on screen
// TODO: Find a better algo
double width = layer->lineWidth().width() * 1.5;
// Is this correct? May be we should decide on a different minimum width then 0.1, because may be on some devices 0.11 isn't visible?
painter.line_width(std::max(width, MINIMUM_READER_LINEWIDTH));
width = layer->lineWidth().width() * 1.5;
}
// Is this correct? May be we should decide on a different minimum width then 0.1, because may be on some devices 0.11 isn't visible?
painter.line_width(std::max(width, MINIMUM_READER_LINEWIDTH));
if (entityLinePattern != nullptr && entityLinePattern->lcPattern().size()>0) {
const double* path = &entityLinePattern->lcPattern()[0];
painter.set_dash(path, entityLinePattern->lcPattern().size(), 0., true);
if (entityLinePattern != nullptr && entityLinePattern->lcPattern(width).size()>0) {
auto path = entityLinePattern->lcPattern(width);
painter.set_dash(&path[0], path.size(), 0., true);
}
else if(layer->linePattern() != nullptr && layer->linePattern()->lcPattern().size() > 0) {
const double* path = &layer->linePattern()->lcPattern()[0];
painter.set_dash(path, layer->linePattern()->lcPattern().size(), 0., true);
else if(layer->linePattern() != nullptr && layer->linePattern()->lcPattern(width).size() > 0) {
auto path = layer->linePattern()->lcPattern(width);
painter.set_dash(&path[0], path.size(), 0., true);
}
// Decide what color to render the entity into

0 comments on commit 6c86b39

Please sign in to comment.