Skip to content

Commit

Permalink
Allow access to current selection and move lines with cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
feragon committed May 16, 2016
1 parent d3142fb commit b963920
Show file tree
Hide file tree
Showing 17 changed files with 613 additions and 206 deletions.
19 changes: 19 additions & 0 deletions lcUI/cadmdichild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions lcUI/cadmdichild.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions lckernel/cad/events/addentityevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions lckernel/cad/interface/draggable.h
Original file line number Diff line number Diff line change
@@ -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>;
}
21 changes: 21 additions & 0 deletions lckernel/cad/primitive/line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
7 changes: 6 additions & 1 deletion lckernel/cad/primitive/line.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lcviewernoqt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit b963920

Please sign in to comment.