LibreCAD
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
trim.cpp
Go to the documentation of this file.
1 #include "trim.h"
2 
3 #include "cad/base/cadentity.h"
4 #include "cad/primitive/line.h"
5 #include "cad/primitive/arc.h"
6 #include "cad/primitive/circle.h"
9 
10 using namespace lc;
11 
12 Trim::Trim(QList<shared_ptr<const lc::entity::CADEntity> > limitingEntities, shared_ptr<const lc::entity::CADEntity> trimmedShape, geo::Coordinate trimPoint) : _limitingEntities(limitingEntities), _trimmedShape(trimmedShape), _trimPoint(trimPoint) {
13 
14 }
15 
16 void Trim::visit(shared_ptr<const lc::Arc> arc) {
17 
18 }
19 void Trim::visit(shared_ptr<const lc::Line> line) {
21  QList<geo::Coordinate> points = im.result();
22  this->_newEntities.clear();
23 
24  if (points.count() > 0) {
25  points.append(this->_trimPoint);
26  qSort(points.begin(), points.end(), lc::geo::CoordinateDistanceSort(line->start()));
27 
28  for (int i = 0; i < points.size(); ++i) {
29  if (points.at(i) == this->_trimPoint) {
30  if (i == 0) {
31  this->_newEntities.append(shared_ptr<const lc::Line>(new Line(points.at(i + 1), line->end())));
32  return;
33  } else if (i == points.size() - 1) {
34  this->_newEntities.append(shared_ptr<const lc::Line>(new Line(line->start(), points.at(i - 1))));
35  return;
36  } else {
37  this->_newEntities.append(shared_ptr<const lc::Line>(new Line(line->start(), points.at(i - 1))));
38  this->_newEntities.append(shared_ptr<const lc::Line>(new Line(points.at(i + 1), line->end())));
39  return;
40  }
41  }
42  }
43  }
44 }
45 void Trim::visit(shared_ptr<const lc::Circle> circle) {
46 
47 }
48 
49 void Trim::visit(shared_ptr<const lc::Ellipse> ellipse) {
50 
51 }
52 
53 void Trim::visit(shared_ptr<const lc::Text> text) {
54 
55 }
56 
57 void Trim::visit(shared_ptr<const lc::Spline> Spline) {
58 
59 }
60 
61 QList<shared_ptr<const lc::entity::CADEntity> > Trim::result() {
62  _trimmedShape->dispatch(*this);
63  return _newEntities;
64 }
65 
66 shared_ptr<const lc::entity::CADEntity> Trim::trimmedShape() const {
67  return this->_trimmedShape;
68 }
69 
calculate intersection points of many entities
Definition: intersect.h:185
std::vector< geo::Coordinate > result() const
Definition: intersect.cpp:606
Definition: cadentity.h:12
QList< shared_ptr< const lc::entity::CADEntity > > _newEntities
Definition: trim.h:28
geo::Coordinate _trimPoint
Definition: trim.h:29
QList< shared_ptr< const lc::entity::CADEntity > > result()
Definition: trim.cpp:61
shared_ptr< const lc::entity::CADEntity > trimmedShape() const
Definition: trim.cpp:66
virtual void visit(shared_ptr< const lc::Line >)
Definition: trim.cpp:19
sort a Collection in order of distance to a specific coordinate
shared_ptr< const lc::entity::CADEntity > _trimmedShape
Definition: trim.h:27
Trim(QList< shared_ptr< const lc::entity::CADEntity > > limitingEntities, shared_ptr< const lc::entity::CADEntity > trimmedShape, geo::Coordinate trimPoint)
Definition: trim.cpp:12
QList< shared_ptr< const lc::entity::CADEntity > > _limitingEntities
Definition: trim.h:26