12 using namespace entity;
21 const Layer_CSPtr layer,
22 const MetaInfo_CSPtr metaInfo,
23 const Block_CSPtr block) :
27 _elevation(elevation),
30 _extrusionDirection(extrusionDirection) {
37 _vertex(other->_vertex),
38 _width(other->_width),
39 _elevation(other->_elevation),
40 _tickness(other->_tickness),
41 _closed(other->_closed),
42 _extrusionDirection(other->_extrusionDirection) {
47 std::vector<LWVertex2D> newVertex;
53 newEntity->setID(this->
id());
58 std::vector<LWVertex2D> newVertex;
68 std::vector<LWVertex2D> newVertex;
70 newVertex.emplace_back(
vertex.location().rotate(rotation_center, rotation_angle),
vertex.bulge(),
79 std::vector<LWVertex2D> newVertex;
80 if (scale_factor.
x() != scale_factor.
y()) {
84 newVertex.emplace_back(
vertex.location().scale(scale_center, scale_factor),
vertex.bulge() * scale_factor.
x(),
102 area = area.
merge((*it)->boundingBox());
109 CADEntity_CSPtr
LWPolyline::modify(Layer_CSPtr layer,
const MetaInfo_CSPtr metaInfo, Block_CSPtr block)
const {
110 auto newEntity = std::make_shared<LWPolyline>(
121 newEntity->setID(this->
id());
128 auto lastPoint = itr;
130 while (itr !=
vertex().end()) {
131 if (lastPoint->bulge() != 0.) {
132 _entities.push_back(std::make_shared<const Arc>(
148 if (lastPoint->bulge() != 0.) {
149 _entities.push_back(std::make_shared<const Arc>(
163 double minDistanceToSnap,
164 int maxNumberOfSnapPoints)
const {
165 std::vector<EntityCoordinate> points;
168 for (
auto &geoItem : entities) {
169 if (
auto vector = std::dynamic_pointer_cast<const geo::Vector>(geoItem)) {
170 points.emplace_back(vector->start(), -1);
171 points.emplace_back(vector->end(), -2);
172 }
else if (
auto arc = std::dynamic_pointer_cast<const geo::Arc>(geoItem)) {
173 points.emplace_back(arc->startP(), -3);
174 points.emplace_back(arc->endP(), -4);
175 points.emplace_back(arc->center(), -5);
179 if (arc->isAngleBetween(.5 *
M_PI)) {
181 points.emplace_back(coord, 1);
184 if (arc->isAngleBetween(0)) {
186 points.emplace_back(coord, 2);
189 if (arc->isAngleBetween(
M_PI)) {
191 points.emplace_back(coord, 3);
194 if (arc->isAngleBetween(-.5 *
M_PI)) {
196 points.emplace_back(coord, 4);
199 std::cerr <<
"Unknown entity found in LWPolyline during snapPoints generation" << std::endl;
207 if (
auto &arc = std::get<2>(info)) {
208 const double a = (npoe - arc->center()).angle();
209 if (arc->isAngleBetween(a)) {
210 points.emplace_back(npoe, -6);
212 }
else if (
auto &vector = std::get<1>(info)) {
213 if (vector->nearestPointOnEntity(coord).distanceTo(coord) < minDistanceToSnap) {
214 points.emplace_back(npoe, -7);
221 points.emplace_back(npoe, -1);
231 return std::get<0>(info);
238 double minimumDistance = std::numeric_limits<double>::max();
239 std::shared_ptr<const geo::Vector> nearestVector =
nullptr;
240 std::shared_ptr<const geo::Arc> nearestArc =
nullptr;
242 for (
auto &geoItem : entities) {
243 if (
auto vector = std::dynamic_pointer_cast<const geo::Vector>(geoItem)) {
244 auto npoe = vector->nearestPointOnPath(coord);
246 if (thisDistance < minimumDistance) {
247 minimumDistance = thisDistance;
248 nearestCoordinate = npoe;
249 nearestVector = vector;
251 }
else if (
auto arc = std::dynamic_pointer_cast<const geo::Arc>(geoItem)) {
252 auto npoe = arc->nearestPointOnPath(coord);
254 if (thisDistance < minimumDistance) {
255 minimumDistance = thisDistance;
256 nearestCoordinate = npoe;
260 std::cerr <<
"Unknown entity found in LWPolyline during boundingBox generation" << std::endl;
263 return std::make_tuple(nearestCoordinate, nearestVector, nearestArc);
268 std::map<unsigned int, geo::Coordinate>
dragPoints;
272 dragPoints[i] =
vertex.location();
282 std::vector<LWVertex2D> newVertex;
291 newEntity->setID(
id());
294 catch(std::out_of_range& e) {
295 return shared_from_this();
virtual CADEntity_CSPtr modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo, Block_CSPtr block) const override
modify Return a new entity with the same ID bit with possible modified metainfo and/pr layer informat...
geo::Coordinate const & extrusionDirection() const
virtual CADEntity_CSPtr scale(const geo::Coordinate &scale_center, const geo::Coordinate &scale_factor) const override
scale, scales the entity
virtual CADEntity_CSPtr move(const geo::Coordinate &offset) const override
move, moves by an offset
static const uint16_t LOGICAL
double x() const
Returns x of Coordinate.
std::vector< LWVertex2D > const & vertex() const
static const uint16_t ON_ENTITYPATH
Layer_CSPtr layer() const
layer return the layer this entity is placed on
double y() const
Returns y of Coordinate.
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate &coord) const override
Find the nearest point on the path for this entity for the coordinate coord The path of a entity that...
Area merge(const Area &other) const
merge two area's and expand if required to largest containing area
virtual std::map< unsigned int, lc::geo::Coordinate > dragPoints() const override
Get all points of the entity that can be dragged.
static Arc createArcBulge(const Coordinate &p1, const Coordinate &p2, const double bulge)
MetaInfo_CSPtr metaInfo() const
static const uint16_t ON_ENTITY
LWPolyline(const std::vector< LWVertex2D > &vertex, double width, double elevation, double tickness, bool closed, geo::Coordinate const &extrusionDirection, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo=nullptr, const Block_CSPtr block=nullptr)
virtual CADEntity_CSPtr rotate(const geo::Coordinate &rotation_center, const double rotation_angle) const override
rotate, rotate operation
static void snapPointsCleanup(std::vector< EntityCoordinate > &points, const geo::Coordinate &reference, const unsigned int maxNumberOfSnapPoints, const double minDistanceToSnap)
std::tuple< geo::Coordinate, std::shared_ptr< const geo::Vector >, std::shared_ptr< const geo::Arc > > nearestPointOnPath2(const geo::Coordinate &coord) const
const geo::Coordinate _extrusionDirection
virtual CADEntity_CSPtr setDragPoints(std::map< unsigned int, lc::geo::Coordinate > dragPoints) const override
Return modified entity.
std::vector< CADEntity_CSPtr > _entities
Block_CSPtr block() const
Return the current entity block.
virtual const geo::Area boundingBox() const override
boundingBox of the entity
const uint16_t constrain() const
virtual CADEntity_CSPtr copy(const geo::Coordinate &offset) const override
copy, copies by an offset
const std::vector< LWVertex2D > _vertex
double distanceTo(const geo::Coordinate &c) const
virtual std::vector< EntityCoordinate > snapPoints(const geo::Coordinate &coord, const SimpleSnapConstrain &constrain, double minDistanceToSnap, int maxNumberOfSnapPoints) const override
Find a number of snap points the line has available This function returns a ordered list...
void generateEntities()
Generate entities of the polyline.
std::vector< CADEntity_CSPtr > const asEntities() const