Permalink
Browse files

Allow access to current selection and move lines with cursor

  • Loading branch information...
feragon committed May 16, 2016
1 parent d3142fb commit b963920f7b187452e57835609b9773c55e3c4928
View
@@ -122,6 +122,15 @@ void CadMdiChild::newDocument() {
_viewer->documentCanvas()->background().connect<LCViewer::Cursor, &LCViewer::Cursor::onDraw>(_cursor.get());
_snapManager->snapPointEvents().connect<LCViewer::Cursor, &LCViewer::Cursor::onSnapPointEvent>(_cursor.get());
//Drag manager
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor);
_viewer->documentCanvas()->background().connect<LCViewer::DragManager, &LCViewer::DragManager::onDraw>(_dragManager.get());
_viewer->setDragManager(_dragManager);
_dragPoints = std::make_shared<LCViewer::DragPoints>(10);
_dragManager->dragPointsEvent().connect<LCViewer::DragPoints, &LCViewer::DragPoints::setPoints>(_dragPoints.get());
_viewer->documentCanvas()->background().connect<LCViewer::DragPoints, &LCViewer::DragPoints::onDraw>(_dragPoints.get());
// Undo manager takes care that we can undo/redo entities within a document
_undoManager = std::make_shared<lc::UndoManagerImpl>(10);
_document->commitProcessEvent().connect<lc::UndoManagerImpl, &lc::UndoManagerImpl::on_CommitProcessEvent>(_undoManager.get());
@@ -134,6 +143,7 @@ void CadMdiChild::newDocument() {
auto layer = std::make_shared<lc::Layer>("0", lc::Color(1., 1., 1., 1.));
auto al = std::make_shared<lc::operation::AddLayer>(_document, layer);
al->execute();
_undoManager->removeUndoables(); //Prevent undo of default layer creation
// Create a cross at position 0,0
//auto builder = std::make_shared<lc::operation::Builder>(document());
@@ -186,6 +196,15 @@ void CadMdiChild::import(std::string str) {
_viewer->documentCanvas()->background().connect<LCViewer::Cursor, &LCViewer::Cursor::onDraw>(_cursor.get());
_snapManager->snapPointEvents().connect<LCViewer::Cursor, &LCViewer::Cursor::onSnapPointEvent>(_cursor.get());
//Drag manager
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor);
_viewer->documentCanvas()->background().connect<LCViewer::DragManager, &LCViewer::DragManager::onDraw>(_dragManager.get());
_viewer->setDragManager(_dragManager);
_dragPoints = std::make_shared<LCViewer::DragPoints>(10);
_dragManager->dragPointsEvent().connect<LCViewer::DragPoints, &LCViewer::DragPoints::setPoints>(_dragPoints.get());
_viewer->documentCanvas()->background().connect<LCViewer::DragPoints, &LCViewer::DragPoints::onDraw>(_dragPoints.get());
// Undo manager takes care that we can undo/redo entities within a document
_undoManager = std::make_shared<lc::UndoManagerImpl>(10);
_document->commitProcessEvent().connect<lc::UndoManagerImpl, &lc::UndoManagerImpl::on_CommitProcessEvent>(_undoManager.get());
View
@@ -13,6 +13,7 @@
#include <managers/snapmanager.h>
#include <drawables/gradientbackground.h>
#include <drawables/grid.h>
#include <drawables/dragpoints.h>
#include "operations/operationmanager.h"
#include <managers/snapmanagerimpl.h>
@@ -64,6 +65,8 @@ class CadMdiChild : public QWidget {
std::shared_ptr<LCViewer::GradientBackground> _gradientBackground;
std::shared_ptr<LCViewer::Cursor> _cursor;
LCViewer::SnapManagerImpl_SPtr _snapManager;
LCViewer::DragManager_SPtr _dragManager;
LCViewer::DragPoints_SPtr _dragPoints;
lc::StorageManager_SPtr _storageManager;
std::shared_ptr<OperationManager> _operationManager;
@@ -17,6 +17,13 @@ namespace lc {
*/
AddEntityEvent(entity::CADEntity_CSPtr cadEntity) : _cadEntity(cadEntity) {
}
/*!
* \brief Returns the entity without cast.
* \return CADEntity_CSPtr Entity.
*/
const entity::CADEntity_CSPtr entity() const {
return _cadEntity;
}
/*!
* \brief Returns the entity.
@@ -0,0 +1,16 @@
#pragma once
#include <map>
#include "cad/vo/entitycoordinate.h"
#include "cad/base/cadentity.h"
namespace lc {
class Draggable {
public:
virtual std::map<unsigned int, lc::geo::Coordinate> dragPoints() const = 0;
virtual lc::entity::CADEntity_CSPtr setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const = 0;
};
using Draggable_SPtr = std::shared_ptr<Draggable>;
using Draggable_CSPtr = std::shared_ptr<const Draggable>;
}
@@ -88,3 +88,24 @@ CADEntity_CSPtr Line::modify(Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) c
newEntity->setID(this->id());
return newEntity;
}
std::map<unsigned int, lc::geo::Coordinate> Line::dragPoints() const {
std::map<unsigned int, lc::geo::Coordinate> points;
points[0] = start();
points[1] = end();
return points;
}
CADEntity_CSPtr Line::setDragPoints(std::map<unsigned int, lc::geo::Coordinate> dragPoints) const {
try {
auto newEntity = std::make_shared<Line>(dragPoints.at(0), dragPoints.at(1), layer(), metaInfo());
newEntity->setID(this->id());
return newEntity;
}
catch(const std::out_of_range& e) {
//A point was not in the map, don't change the entity
return shared_from_this();
}
}
@@ -8,6 +8,7 @@
#include "cad/geometry/geovector.h"
#include "cad/base/cadentity.h"
#include "cad/interface/snapable.h"
#include "cad/interface/draggable.h"
#include "cad/vo/entitycoordinate.h"
#include "cad/meta/layer.h"
@@ -22,7 +23,7 @@ namespace lc {
* \author R. van Twisk
* \date 2012-04-16
*/
class Line : public std::enable_shared_from_this<Line>, public CADEntity, public geo::Vector, public Snapable {
class Line : public std::enable_shared_from_this<Line>, public CADEntity, public geo::Vector, public Snapable, public Draggable {
public:
/*!
* \brief Construct a new line
@@ -64,6 +65,10 @@ namespace lc {
virtual geo::Coordinate nearestPointOnPath(const geo::Coordinate &coord) const override;
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;
public:
/**
* @brief move, moves by an offset
@@ -32,7 +32,9 @@ drawables/lccursor.cpp
documentcanvas.cpp
managers/snapmanagerimpl.cpp
managers/EventManager.cpp
managers/dragmanager.cpp
drawitems/lcimage.cpp
drawables/dragpoints.cpp
)
# HEADER FILES
@@ -69,8 +71,12 @@ documentcanvas.h
managers/snapmanager.h
managers/snapmanagerimpl.h
managers/EventManager.h
managers/dragmanager.h
events/LocationEvent.h
drawitems/lcimage.h)
drawitems/lcimage.h
drawables/dragpoints.h
events/dragpointsevent.h
)
# Cairo
find_package(PkgConfig)
Oops, something went wrong.

0 comments on commit b963920

Please sign in to comment.