Permalink
Browse files

Improve selection of drag points and add points for all entities

  • Loading branch information...
feragon committed May 30, 2016
1 parent b963920 commit 73347ed3098a260e8b65d0fc81f1619a9ac0a583
View
@@ -123,11 +123,11 @@ void CadMdiChild::newDocument() {
_snapManager->snapPointEvents().connect<LCViewer::Cursor, &LCViewer::Cursor::onSnapPointEvent>(_cursor.get());
//Drag manager
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor);
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor, 10);
_viewer->documentCanvas()->background().connect<LCViewer::DragManager, &LCViewer::DragManager::onDraw>(_dragManager.get());
_viewer->setDragManager(_dragManager);
_dragPoints = std::make_shared<LCViewer::DragPoints>(10);
_dragPoints = std::make_shared<LCViewer::DragPoints>();
_dragManager->dragPointsEvent().connect<LCViewer::DragPoints, &LCViewer::DragPoints::setPoints>(_dragPoints.get());
_viewer->documentCanvas()->background().connect<LCViewer::DragPoints, &LCViewer::DragPoints::onDraw>(_dragPoints.get());
@@ -197,11 +197,11 @@ void CadMdiChild::import(std::string str) {
_snapManager->snapPointEvents().connect<LCViewer::Cursor, &LCViewer::Cursor::onSnapPointEvent>(_cursor.get());
//Drag manager
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor);
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor, 10);
_viewer->documentCanvas()->background().connect<LCViewer::DragManager, &LCViewer::DragManager::onDraw>(_dragManager.get());
_viewer->setDragManager(_dragManager);
_dragPoints = std::make_shared<LCViewer::DragPoints>(10);
_dragPoints = std::make_shared<LCViewer::DragPoints>();
_dragManager->dragPointsEvent().connect<LCViewer::DragPoints, &LCViewer::DragPoints::setPoints>(_dragPoints.get());
_viewer->documentCanvas()->background().connect<LCViewer::DragPoints, &LCViewer::DragPoints::onDraw>(_dragPoints.get());
@@ -1,4 +1,5 @@
#include <cad/math/lcmath.h>
#include <stdlib.h>
#include "geoarc.h"
using namespace lc;
@@ -169,4 +170,16 @@ bool Arc::isAngleBetween(double angle) const {
} else {
return _startAngle < cAngle && cAngle < _endAngle;
}*/
}
double Arc::angle() const {
return Math::correctAngle(std::abs(_endAngle - _startAngle));
}
double Arc::bulge() const {
double bulge = std::tan(angle()/4.0);
if(CCW()) bulge *= -1;
return bulge;
}
@@ -130,6 +130,9 @@ namespace lc {
bool isAngleBetween(double angle) const;
virtual void accept(GeoEntityVisitor &v) const override { v.visit(*this); }
double angle() const;
double bulge() const;
private:
friend std::ostream& operator<<(std::ostream& os, const Arc& a) {
os << "Arc(center=" << a._center << " radius=" << a._radius << " startAngle=" << a._startAngle << " endAngle=" << a._endAngle << " ccw=" << a._CCW << ")";
@@ -62,15 +62,7 @@ void Builder::processInternal() {
document()->addDocumentMetaType(metaData);
}
std::vector<entity::CADEntity_CSPtr> entitySet;
for (auto it = _stack.begin(); it != _stack.end(); ++it) {
// Get looping stack, we currently support only one single loop!!
std::vector<Base_SPtr> stack(_stack.begin(), it);
entitySet = (*it)->process(document(), entitySet, _workingBuffer, _entitiesThatNeedsRemoval, stack);
}
_workingBuffer.insert(_workingBuffer.end(), entitySet.begin(), entitySet.end());
processStack();
auto ec = document()->entityContainer();
@@ -134,3 +126,19 @@ Builder& Builder::appendMetaData(DocumentMetaType_CSPtr metaData) {
_metaDataThatNeedsUpdate.push_back(metaData);
return *this;
}
void Builder::processStack() {
std::vector<entity::CADEntity_CSPtr> entitySet;
for (auto it = _stack.begin(); it != _stack.end(); ++it) {
// Get looping stack, we currently support only one single loop!!
std::vector<Base_SPtr> stack(_stack.begin(), it);
entitySet = (*it)->process(document(), entitySet, _workingBuffer, _entitiesThatNeedsRemoval, stack);
}
_stack.clear();
_workingBuffer.insert(_workingBuffer.end(), entitySet.begin(), entitySet.end());
}
@@ -96,6 +96,8 @@ namespace lc {
virtual void undo() const;
virtual void redo() const;
void processStack();
protected:
virtual void processInternal();
@@ -14,6 +14,11 @@ Arc::Arc(const geo::Coordinate &center, double radius, double startAngle, double
isCCW) {
}
Arc::Arc(const geo::Arc &a, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) :
CADEntity(layer, metaInfo),
geo::Arc(a) {
}
Arc::Arc(const Arc_CSPtr other, bool sameID) : CADEntity(other, sameID),
geo::Arc(other->center(), other->radius(), other->startAngle(),
other->endAngle(), other->CCW()) {
@@ -127,3 +132,24 @@ CADEntity_CSPtr Arc::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) co
}
std::map<unsigned int, lc::geo::Coordinate> Arc::dragPoints() const {
std::map<unsigned int, lc::geo::Coordinate> dragPoints;
dragPoints[0] = startP();
dragPoints[1] = endP();
return dragPoints;
}
CADEntity_CSPtr Arc::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
try {
auto newEntity = std::make_shared<Arc>(geo::Arc::createArcBulge(dragPoints.at(0), dragPoints.at(1), bulge()), layer(), metaInfo());
newEntity->setID(id());
return newEntity;
}
catch(std::out_of_range& e) {
return shared_from_this();
}
}
@@ -10,10 +10,11 @@
#include "cad/math/quadratic_math.h"
#include "cad/meta/layer.h"
#include "cad/interface/snapable.h"
#include "cad/interface/draggable.h"
namespace lc {
namespace entity {
class Arc : public std::enable_shared_from_this<Arc>, public CADEntity, public geo::Arc, public Snapable {
class Arc : public std::enable_shared_from_this<Arc>, public CADEntity, public geo::Arc, public Snapable, public Draggable {
public:
/**
* @brief Arc, Default Arc constructor
@@ -41,6 +42,8 @@ namespace lc {
const Layer_CSPtr layer,
const MetaInfo_CSPtr metaInfo);
Arc(const geo::Arc &a, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo);
Arc(const Arc_CSPtr other, bool sameID = false);
public:
@@ -95,6 +98,10 @@ namespace lc {
virtual void dispatch(EntityDispatch &ed) const override {
ed.visit(shared_from_this());
}
public:
virtual std::map<unsigned int, lc::geo::Coordinate> dragPoints() const override;
virtual CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override;
};
using Arc_SPtr = std::shared_ptr<Arc>;
using Arc_CSPtr = std::shared_ptr<const Arc>;
@@ -1,3 +1,4 @@
#include <map>
#include "cad/primitive/dimaligned.h"
@@ -67,4 +68,38 @@ const geo::Coordinate& DimAligned::definitionPoint2() const noexcept {
}
const geo::Coordinate& DimAligned::definitionPoint3() const noexcept {
return _definitionPoint3;
}
}
std::map<unsigned int, geo::Coordinate> DimAligned::dragPoints() const {
std::map<unsigned int, geo::Coordinate> dragPoints;
dragPoints[0] = definitionPoint();
dragPoints[1] = middleOfText();
dragPoints[2] = _definitionPoint2;
dragPoints[3] = _definitionPoint3;
return dragPoints;
}
CADEntity_CSPtr DimAligned::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
try {
auto newEntity = std::make_shared<DimAligned>(dragPoints.at(0),
dragPoints.at(1),
attachmentPoint(),
textAngle(),
lineSpacingFactor(),
lineSpacingStyle(),
explicitValue(),
dragPoints.at(2),
dragPoints.at(3),
layer(),
metaInfo());
newEntity->setID(id());
return newEntity;
}
catch(std::out_of_range& e) {
return shared_from_this();
}
}
@@ -8,11 +8,12 @@
#include "cad/vo/entitycoordinate.h"
#include "cad/math/lcmath.h"
#include <cad/primitive/point.h>
#include "cad/interface/draggable.h"
namespace lc {
namespace entity {
class DimAligned : public std::enable_shared_from_this<DimAligned>, public CADEntity, public Dimension, virtual public Visitable {
class DimAligned : public std::enable_shared_from_this<DimAligned>, public CADEntity, public Dimension, virtual public Visitable, public Draggable {
public:
@@ -93,6 +94,9 @@ namespace lc {
virtual void dispatch(EntityDispatch &ed) const override {
ed.visit(shared_from_this());
}
public:
virtual std::map<unsigned int, lc::geo::Coordinate> dragPoints() const override;
virtual CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override;
};
using DimAligned_SPtr = std::shared_ptr<DimAligned>;
using DimAligned_CSPtr = std::shared_ptr<const DimAligned>;
@@ -97,3 +97,40 @@ geo::Coordinate DimAngular::defLine21() const {
geo::Coordinate DimAngular::defLine22() const {
return _defLine22;
}
std::map<unsigned int, geo::Coordinate> DimAngular::dragPoints() const {
std::map<unsigned int, geo::Coordinate> dragPoints;
dragPoints[0] = definitionPoint();
dragPoints[1] = middleOfText();
dragPoints[2] = _defLine11;
dragPoints[3] = _defLine12;
dragPoints[4] = _defLine21;
dragPoints[5] = _defLine22;
return dragPoints;
}
CADEntity_CSPtr DimAngular::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
try {
auto newEntity = std::make_shared<DimAngular>(dragPoints.at(0),
dragPoints.at(1),
attachmentPoint(),
textAngle(),
lineSpacingFactor(),
lineSpacingStyle(),
explicitValue(),
dragPoints.at(2),
dragPoints.at(3),
dragPoints.at(4),
dragPoints.at(5),
layer(),
metaInfo());
newEntity->setID(id());
return newEntity;
}
catch(std::out_of_range& e) {
return shared_from_this();
}
}
@@ -8,10 +8,11 @@
#include "cad/vo/entitycoordinate.h"
#include "cad/math/lcmath.h"
#include <cad/primitive/point.h>
#include "cad/interface/draggable.h"
namespace lc {
namespace entity {
class DimAngular : public std::enable_shared_from_this<DimAngular>, public CADEntity, public Dimension, virtual public Visitable {
class DimAngular : public std::enable_shared_from_this<DimAngular>, public CADEntity, public Dimension, virtual public Visitable, public Draggable {
public:
@@ -97,6 +98,10 @@ namespace lc {
virtual void dispatch(EntityDispatch &ed) const override {
ed.visit(shared_from_this());
}
public:
virtual std::map<unsigned int, lc::geo::Coordinate> dragPoints() const override;
virtual CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override;
};
using DimAngular_SPtr = std::shared_ptr<DimAngular>;
using DimAngular_CSPtr = std::shared_ptr<const DimAngular>;
@@ -69,4 +69,36 @@ double DimDiametric::leader() const {
geo::Coordinate DimDiametric::definitionPoint2() const {
return _definitionPoint2;
}
std::map<unsigned int, geo::Coordinate> DimDiametric::dragPoints() const {
std::map<unsigned int, geo::Coordinate> dragPoints;
dragPoints[0] = definitionPoint();
dragPoints[1] = middleOfText();
dragPoints[2] = _definitionPoint2;
return dragPoints;
}
CADEntity_CSPtr DimDiametric::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
try {
auto newEntity = std::make_shared<DimDiametric>(dragPoints.at(0),
dragPoints.at(1),
attachmentPoint(),
textAngle(),
lineSpacingFactor(),
lineSpacingStyle(),
explicitValue(),
dragPoints.at(2),
leader(),
layer(),
metaInfo());
newEntity->setID(id());
return newEntity;
}
catch(std::out_of_range& e) {
return shared_from_this();
}
}
@@ -8,10 +8,11 @@
#include "cad/vo/entitycoordinate.h"
#include "cad/math/lcmath.h"
#include <cad/primitive/point.h>
#include "cad/interface/draggable.h"
namespace lc {
namespace entity {
class DimDiametric : public std::enable_shared_from_this<DimDiametric>, public CADEntity, public Dimension, virtual public Visitable {
class DimDiametric : public std::enable_shared_from_this<DimDiametric>, public CADEntity, public Dimension, virtual public Visitable, public Draggable {
public:
/**
@@ -106,6 +107,10 @@ namespace lc {
virtual void dispatch(EntityDispatch &ed) const override {
ed.visit(shared_from_this());
}
public:
virtual std::map<unsigned int, lc::geo::Coordinate> dragPoints() const override;
virtual CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const override;
};
using DimDiametric_SPtr = std::shared_ptr<DimDiametric>;
using DimDiametric_CSPtr = std::shared_ptr<const DimDiametric>;
Oops, something went wrong.

0 comments on commit 73347ed

Please sign in to comment.