Permalink
Browse files

Preview of line creation

  • Loading branch information...
feragon committed Jun 16, 2016
1 parent d53e26c commit d37ef6dd252f05c7f89a89016a56f2ce2569f890
View
@@ -125,9 +125,11 @@ void CadMdiChild::newDocument() {
_viewer->documentCanvas()->background().connect<LCViewer::Cursor, &LCViewer::Cursor::onDraw>(_cursor.get());
_snapManager->snapPointEvents().connect<LCViewer::Cursor, &LCViewer::Cursor::onSnapPointEvent>(_cursor.get());
_tempEntities = std::make_shared<TempEntities>(_viewer->documentCanvas());
_viewer->documentCanvas()->background().connect<LCViewer::TempEntities, &LCViewer::TempEntities::onDraw>(_tempEntities.get());
//Drag manager
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor, 10);
_viewer->documentCanvas()->background().connect<LCViewer::DragManager, &LCViewer::DragManager::onDraw>(_dragManager.get());
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor, _tempEntities, 10);
_viewer->setDragManager(_dragManager);
_dragPoints = std::make_shared<LCViewer::DragPoints>();
@@ -201,9 +203,11 @@ 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());
_tempEntities = std::make_shared<TempEntities>(_viewer->documentCanvas());
_viewer->documentCanvas()->background().connect<LCViewer::TempEntities, &LCViewer::TempEntities::onDraw>(_tempEntities.get());
//Drag manager
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor, 10);
_viewer->documentCanvas()->background().connect<LCViewer::DragManager, &LCViewer::DragManager::onDraw>(_dragManager.get());
_dragManager = std::make_shared<DragManager>(_viewer->documentCanvas(), _cursor, _tempEntities, 10);
_viewer->setDragManager(_dragManager);
_dragPoints = std::make_shared<LCViewer::DragPoints>();
@@ -432,3 +436,7 @@ void CadMdiChild::keyPressEvent(QKeyEvent *event) {
QWidget::keyPressEvent(event);
emit keyPressed(event);
}
LCViewer::TempEntities_SPtr CadMdiChild::tempEntities() {
return _tempEntities;
}
View
@@ -15,6 +15,7 @@
#include <drawables/gradientbackground.h>
#include <drawables/grid.h>
#include <drawables/dragpoints.h>
#include <drawables/tempentities.h>
#include "operations/operationmanager.h"
#include <managers/snapmanagerimpl.h>
@@ -65,6 +66,7 @@ class CadMdiChild : public QWidget {
lc::StorageManager_SPtr storageManager() const;
LCViewer::LCADViewer* viewer() const {return _viewer;} ;
std::shared_ptr<LCViewer::Cursor> cursor() const;
LCViewer::TempEntities_SPtr tempEntities();
void cancelCurrentOperations();
void import(std::string);
void exportDXF(std::string& str, lc::Version lcv);
@@ -88,6 +90,7 @@ class CadMdiChild : public QWidget {
LCViewer::DragManager_SPtr _dragManager;
LCViewer::DragPoints_SPtr _dragPoints;
lc::StorageManager_SPtr _storageManager;
LCViewer::TempEntities_SPtr _tempEntities;
std::shared_ptr<OperationManager> _operationManager;
View
@@ -173,6 +173,7 @@ void addLCBindings(lua_State *L) {
.addFunction("import", &CadMdiChild::import)
.addFunction("newDocument", &CadMdiChild::newDocument)
.addFunction("setDestroyCallback", &CadMdiChild::setDestroyCallback)
.addFunction("tempEntities", &CadMdiChild::tempEntities)
.addFunction("undoManager", &CadMdiChild::undoManager)
.addFunction("view", &CadMdiChild::view)
.addFunction("viewer", &CadMdiChild::viewer)
@@ -235,6 +236,10 @@ void addLCBindings(lua_State *L) {
.addFunction("groupByName", &ToolbarTab::groupByName)
.endClass()
.beginClass<LCViewer::TempEntities>("TempEntities")
.addFunction("addEntity", &LCViewer::TempEntities::addEntity)
.addFunction("removeEntity", &LCViewer::TempEntities::removeEntity)
.endClass()
.endModule();
}
View
@@ -29,6 +29,7 @@ extern "C"
#include "widgets/clicommand.h"
#include "widgets/toolbar.h"
#include "widgets/toolbartab.h"
#include <drawables/tempentities.h>
Q_DECLARE_METATYPE(lc::geo::Coordinate);
@@ -0,0 +1,73 @@
LineOperations = {}
LineOperations.__index = LineOperations
setmetatable(LineOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function LineOperations:_init(id)
Operations._init(self, id)
self.lastPoint = nil
self.lastLine = nil
self.line_id = ID():id()
event.register('point', self)
message("Click on first point")
end
function LineOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point") then
self:newPoint(...)
elseif(eventName == "mouseMove") then
self:createTempLine(...)
end
end
function LineOperations:newPoint(point)
if(self.lastPoint ~= nil) then
active_widget():tempEntities():removeEntity(self.lastLine)
local b = Builder(active_widget():document())
local l = self:createLine(self.lastPoint, point)
b:append(l)
b:execute()
event.delete('mouseMove', self)
event.delete('point', self)
else
self.lastPoint = point
self.lastLine = self:createLine(point, point)
active_widget():tempEntities():addEntity(self.lastLine)
event.register('mouseMove', self)
message("Click on second point")
end
end
function LineOperations:createTempLine(point)
active_widget():tempEntities():removeEntity(self.lastLine)
self.lastLine = self:createLine(self.lastPoint, point)
active_widget():tempEntities():addEntity(self.lastLine)
end
function LineOperations:createLine(p1, p2)
local d = active_widget():document()
local layer = d:layerByName("0")
local l = Line(Coord(p1:x(), p1:y()), Coord(p2:x(), p2:y()), layer);
l:setId(self.line_id)
return l
end
@@ -1,55 +1,21 @@
require 'actions.event'
require 'actions.lineoperations'
Operations = {}
function Operations:new(id)
local o = {}
Operations.__index = self
setmetatable(o, self)
o.id = id
event.register("command", o)
return o
end
function Operations:onEvent(eventName, ...)
--If current window is focused
if(active_widget().id == self.id) then
if(eventName == "point") then
self:get_line_point(...)
elseif(eventName == "command") then
if(... == "LINE") then
self:create_line()
end
end
end
end
function Operations:create_line()
self.line_vars = {}
self.line_vars['lastPoint'] = nil
message("Draw a line")
message("Click on first point")
event.register('point', self)
Operations.__index = Operations
setmetatable(Operations, {
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function Operations:_init(id)
self.id = id
end
function Operations:get_line_point(point)
if(self.line_vars['lastPoint'] ~= nil) then
local lp = self.line_vars['lastPoint']
local d = active_widget():document()
local b = Builder(d)
local layer = d:layerByName("0")
local l=Line(Coord(lp:x(), lp:y()), Coord(point:x(), point:y()), layer);
b:append(l)
b:execute()
event.delete('point', self)
else
self.line_vars['lastPoint'] = point
message("Click on second point")
end
function Operations:forMe()
return active_widget().id == self.id
end
@@ -7,13 +7,19 @@ local function click()
event.trigger('point', position)
end
local function mouseMove()
local position = active_widget():cursor():position()
event.trigger('mouseMove', position)
end
function new_document()
cadMdiChild = lc.CadMdiChild()
cadMdiChild:newDocument()
cadMdiChild:viewer():autoScale()
cadMdiChild:setDestroyCallback(onMdiChildDestroyed)
luaInterface:luaConnect(cadMdiChild:view(), "mousePressEvent()", click)
luaInterface:luaConnect(cadMdiChild:view(), "mouseMoveEvent()", mouseMove)
luaInterface:connect(cadMdiChild, "keyPressed(QKeyEvent*)", cliCommand, "onKeyPressed(QKeyEvent*)")
return cadMdiChild
@@ -25,6 +31,7 @@ function load_document(fileName)
cadMdiChild:viewer():autoScale()
luaInterface:luaConnect(cadMdiChild:view(), "mousePressEvent()", click)
luaInterface:luaConnect(cadMdiChild:view(), "mouseMoveEvent()", mouseMove)
luaInterface:connect(cadMdiChild, "keyPressed(QKeyEvent*)", cliCommand, "onKeyPressed(QKeyEvent*)")
return cadMdiChild
@@ -7,7 +7,7 @@ function new_file()
cadMdiChild:showMaximized()
id = nextTableId(op)
op[id] = Operations:new(id)
op[id] = Operations(id)
window:widget().id = id
end
@@ -1,3 +1,3 @@
function create_line()
op[active_widget().id]:create_line()
op[active_widget().id] = LineOperations(active_widget().id)
end
@@ -158,9 +158,11 @@ void lua_openlckernel(lua_State* L) {
.endClass()
.beginClass<Snapable>("Snapable")
.endClass()
.beginClass<ID>("ID")
.addFunction("id", &ID::id)
.endClass()
.beginClass<ID>("ID")
.addConstructor(LUA_ARGS(_opt<ID_DATATYPE>))
.addFunction("id", &ID::id)
.addFunction("setId", &ID::setID)
.endClass()
.beginExtendClass<entity::CADEntity, ID>("CADEntity")
.endClass()
.beginExtendClass<entity::Line, entity::CADEntity>("Line")
@@ -35,6 +35,7 @@ managers/EventManager.cpp
managers/dragmanager.cpp
drawitems/lcimage.cpp
drawables/dragpoints.cpp
drawables/tempentities.cpp
)
# HEADER FILES
@@ -76,6 +77,7 @@ events/LocationEvent.h
drawitems/lcimage.h
drawables/dragpoints.h
events/dragpointsevent.h
drawables/tempentities.h
)
# Cairo
@@ -0,0 +1,22 @@
#include "tempentities.h"
using namespace LCViewer;
TempEntities::TempEntities(DocumentCanvas_SPtr docCanvas) : _docCanvas(docCanvas) {
}
void TempEntities::addEntity(lc::entity::CADEntity_CSPtr entity) {
auto drawable = _docCanvas->asDrawable(entity);
_entities.insert(std::dynamic_pointer_cast<const lc::entity::CADEntity>(drawable));
}
void TempEntities::removeEntity(lc::entity::CADEntity_CSPtr entity) {
_entities.remove(entity);
}
void TempEntities::onDraw(DrawEvent const &event) {
_entities.each<const LCViewer::LCVDrawItem>([&](LCViewer::LCVDrawItem_CSPtr entity) {
_docCanvas->drawEntity(entity);
});
}
@@ -0,0 +1,25 @@
#pragma once
#include <cad/base/cadentity.h>
#include <cad/dochelpers/entitycontainer.h>
#include "../drawitems/lcvdrawitem.h"
#include "../events/drawevent.h"
#include "../documentcanvas.h"
namespace LCViewer {
class TempEntities {
public:
TempEntities(DocumentCanvas_SPtr docCanvas);
void addEntity(lc::entity::CADEntity_CSPtr entity);
void removeEntity(lc::entity::CADEntity_CSPtr entity);
void onDraw(DrawEvent const &event);
private:
DocumentCanvas_SPtr _docCanvas;
lc::EntityContainer<lc::entity::CADEntity_CSPtr> _entities;
};
using TempEntities_SPtr = std::shared_ptr<TempEntities>;
}
Oops, something went wrong.

0 comments on commit d37ef6d

Please sign in to comment.