Permalink
Browse files

Move entities

  • Loading branch information...
feragon committed Jun 27, 2016
1 parent a383f5a commit afff78ab96c7f3117f69c08875b5e0e62abdcf37
View
@@ -439,3 +439,7 @@ void CadMdiChild::keyPressEvent(QKeyEvent *event) {
LCViewer::TempEntities_SPtr CadMdiChild::tempEntities() {
return _tempEntities;
}
std::vector<lc::entity::CADEntity_SPtr> CadMdiChild::selection() {
return viewer()->documentCanvas()->selection().asVector();
}
View
@@ -68,6 +68,7 @@ class CadMdiChild : public QWidget {
LCViewer::LCADViewer* viewer() const {return _viewer;}
std::shared_ptr<LCViewer::Cursor> cursor() const;
LCViewer::TempEntities_SPtr tempEntities();
std::vector<lc::entity::CADEntity_SPtr> selection();
void cancelCurrentOperations();
void import(std::string);
void exportDXF(std::string& str, DXF::version lcv);
View
@@ -4,6 +4,7 @@
namespace LuaIntf {
LUA_USING_SHARED_PTR_TYPE(std::shared_ptr)
LUA_USING_LIST_TYPE(std::vector)
}
void luaOpenQtBridge(lua_State *L) {
@@ -175,6 +176,7 @@ void addLCBindings(lua_State *L) {
.addFunction("document", &CadMdiChild::document)
.addProperty("id", &CadMdiChild::id, &CadMdiChild::setId)
.addFunction("import", &CadMdiChild::import)
.addFunction("selection", &CadMdiChild::selection)
.addFunction("newDocument", &CadMdiChild::newDocument)
.addFunction("setDestroyCallback", &CadMdiChild::setDestroyCallback)
.addFunction("tempEntities", &CadMdiChild::tempEntities)
@@ -191,6 +193,7 @@ void addLCBindings(lua_State *L) {
.addFunction("x", &LCViewer::LCADViewer::x)
.addFunction("y", &LCViewer::LCADViewer::y)
.addFunction("autoScale", &LCViewer::LCADViewer::autoScale)
.addFunction("setOperationActive", &LCViewer::LCADViewer::setOperationActive)
.endClass()
.beginClass<LuaInterface>("LuaInterface")
View
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="256"
height="256"
viewBox="0 0 72.248892 72.248892"
id="svg4295"
version="1.1"
inkscape:version="0.91 r13725"
sodipodi:docname="modify_b.svg"
inkscape:export-filename="D:\LC_Recources\icons\selectinverted.png"
inkscape:export-xdpi="11.25"
inkscape:export-ydpi="11.25">
<metadata
id="metadata4325">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs4323" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1176"
id="namedview4321"
showgrid="true"
units="px"
inkscape:snap-grids="true"
inkscape:zoom="3.7226562"
inkscape:cx="128"
inkscape:cy="128"
inkscape:window-x="-4"
inkscape:window-y="-4"
inkscape:window-maximized="1"
inkscape:current-layer="svg4295"
inkscape:object-nodes="true"
inkscape:snap-object-midpoints="false"
showguides="false">
<inkscape:grid
type="xygrid"
id="grid4867" />
</sodipodi:namedview>
<g
id="g7715"
transform="translate(0,2.257778)">
<circle
r="5.6444449"
cy="31.608892"
cx="15.804445"
id="path10169"
style="opacity:1;fill:#00ff7f;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:2.25777793;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:8;stroke-opacity:1" />
<path
sodipodi:nodetypes="cccccccc"
inkscape:connector-curvature="0"
id="path5315"
d="M 41.568659,52.51323 30.384992,41.329564 35.182698,38.144816 17.621309,33.355348 22.410778,50.916736 25.662727,46.186238 36.77919,57.302698 41.568659,52.51323"
style="fill:#ffffff;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
inkscape:connector-curvature="0"
id="path7713"
d="M 20.320001,29.351113 56.444448,11.28889"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
sodipodi:nodetypes="cccc"
inkscape:connector-curvature="0"
id="path6026"
d="M 63.217781,7.9022227 57.472119,16.882999 52.702292,7.912251 63.217781,7.9022227"
style="fill:#00ff7f;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:2.25777793;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>
View
@@ -14,6 +14,7 @@
<file alias="dim_angular.svg">icons/dim_angular.svg</file>
<file alias="spline.svg">icons/spline.svg</file>
<file alias="quit.svg">icons/quit.svg</file>
<file alias="polylines.svg">icons/polylines.svg</file>
<file alias="polylines.svg">icons/polylines.svg</file>
<file alias="modify.svg">icons/modify.svg</file>
</qresource>
</RCC>
@@ -0,0 +1,97 @@
MoveOperation = {}
MoveOperation.__index = MoveOperation
setmetatable(MoveOperation, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function MoveOperation:_init(id)
Operations._init(self, id)
self.selection = active_widget():selection()
message(tostring(#self.selection) .. " items selected")
if(#self.selection > 0) then
self.origin = nil
self.tempEntities = {}
event.register('point', self)
event.register('mouseMove', self)
message("Give origin point")
else
self.finished = true
event.trigger('operationFinished')
end
end
function MoveOperation:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:tempMove(...)
end
end
function MoveOperation:newData(point)
if(self.origin == nil) then
self.origin = Operations:getCoordinate(point)
message("Give destination point")
elseif(Operations:getCoordinate(point) ~= nil) then
local offset = point:sub(self.origin)
local b = Builder(active_widget():document())
for k, entity in pairs(self.selection) do
b:append(entity)
end
b:push()
b:move(offset)
b:execute()
self:close()
end
end
function MoveOperation:tempMove(point)
if(self.origin ~= nil) then
for k, entity in pairs(self.tempEntities) do
active_widget():tempEntities():removeEntity(entity)
end
self.tempEntities = {}
local offset = point:sub(self.origin)
for k, entity in pairs(self.selection) do
local newEntity = entity:move(offset)
active_widget():tempEntities():addEntity(newEntity)
table.insert(self.tempEntities, newEntity)
end
end
end
function MoveOperation:close()
if(not self.finished) then
self.finished = true
for k, entity in pairs(self.tempEntities) do
active_widget():tempEntities():removeEntity(entity)
end
event.delete('mouseMove', self)
event.delete('point', self)
event.trigger('operationFinished')
end
end
@@ -11,6 +11,8 @@ require 'actions.dimradialoperations'
require 'actions.splineoperations'
require 'actions.lwpolylineoperations'
require 'actions.moveoperation'
Operations = {}
Operations.__index = Operations
@@ -64,5 +64,7 @@ function add_commandline()
add_command("DIMRADIAL", create_dim_radial)
add_command("SPLINE", create_spline)
add_command("MOVE", move_selected_entities)
event.register("point", setLastPoint)
end
View
@@ -4,6 +4,8 @@ local function remove_operation_group()
if(group ~= nil) then
tab:removeGroup(group)
end
active_widget():viewer():setOperationActive(false)
end
local function finish_operation()
@@ -21,6 +23,13 @@ local function create_cancel_button()
luaInterface:luaConnect(cancelButton, "pressed()", finish_operation)
end
local function new_operation()
finish_operation()
create_cancel_button()
active_widget():viewer():setOperationActive(true)
end
event.register("operationFinished", remove_operation_group)
function create_line()
@@ -100,3 +109,8 @@ function create_lw_polyline()
op[active_widget().id] = LWPolylineOperations(active_widget().id)
end
function move_selected_entities()
new_operation()
op[active_widget().id] = MoveOperation(active_widget().id)
end
View
@@ -91,4 +91,13 @@ function add_toolbar()
local dimRadial = create_button("", ":/icons/dim_radial.svg")
quickAccess:addButton(dimGroup, dimRadial, 2, 0, 1, 1)
luaInterface:luaConnect(dimRadial, "pressed()", create_dim_radial)
--
-- Modify
--
local modifyGroup = quickAccess:addGroup("Modify")
local moveButton = create_button("", ":/icons/modify.svg")
quickAccess:addButton(modifyGroup, moveButton, 0, 0, 1, 1)
luaInterface:luaConnect(moveButton, "pressed()", move_selected_entities)
end
@@ -174,6 +174,7 @@ void lua_openlckernel(lua_State* L) {
.addFunction("setId", &ID::setID)
.endClass()
.beginExtendClass<entity::CADEntity, ID>("CADEntity")
.addFunction("move", &entity::CADEntity::move)
.endClass()
.beginExtendClass<entity::Line, entity::CADEntity>("Line")
.addConstructor(LUA_SP(entity::Line_SPtr), LUA_ARGS(
View
@@ -18,7 +18,7 @@
using namespace LCViewer;
LCADViewer::LCADViewer(QWidget *parent) :
QWidget(parent), _docCanvas(nullptr), _mouseScrollKeyActive(false), _disableSelection(false), _scale(1.0), _zoomMin(0.05), _zoomMax(20.0), _scaleLineWidth(false) {
QWidget(parent), _docCanvas(nullptr), _mouseScrollKeyActive(false), _disableSelection(false), _operationActive(false), _scale(1.0), _zoomMin(0.05), _zoomMax(20.0), _scaleLineWidth(false) {
setMouseTracking(true);
this->_altKeyActive = false;
@@ -180,26 +180,29 @@ void LCADViewer::mouseMoveEvent(QMouseEvent *event) {
void LCADViewer::mousePressEvent(QMouseEvent *event) {
QWidget::mousePressEvent(event);
_dragManager->onMousePress();
_disableSelection = _dragManager->entityDragged();
if(!_operationActive) {
_dragManager->onMousePress();
_disableSelection = _dragManager->entityDragged();
startSelectPos = event->pos();
startSelectPos = event->pos();
posX = event->x();
posY = event->y();
posX = event->x();
posY = event->y();
_docCanvas->device_to_user(&posX, &posY);
emit mousePressEvent();
switch (event->buttons()) {
case Qt::MiddleButton: {
_mouseScrollKeyActive = true;
}
break;
}
switch (event->buttons()) {
case Qt::MiddleButton: {
_mouseScrollKeyActive = true;
} break;
if (!_ctrlKeyActive) {
_docCanvas->removeSelection();
}
}
if(!_ctrlKeyActive) {
_docCanvas->removeSelection();
}
_docCanvas->device_to_user(&posX, &posY);
emit mousePressEvent();
}
@@ -238,6 +241,14 @@ double LCADViewer::y() {
return posY;
}
void LCADViewer::setOperationActive(bool operationActive) {
_operationActive = operationActive;
if(operationActive == false) {
documentCanvas()->removeSelection();
}
}
void LCADViewer::paintEvent(QPaintEvent *p) {
if (p->rect().width() == 0 || p->rect().height() == 0) {
return;
View
@@ -71,6 +71,8 @@ class LCADViewer : public QWidget {
double x();
double y();
void setOperationActive(bool operationActive);
protected:
void paintEvent(QPaintEvent*);
virtual void mousePressEvent(QMouseEvent* event);
@@ -103,6 +105,8 @@ class LCADViewer : public QWidget {
bool _mouseScrollKeyActive;
bool _disableSelection;
bool _operationActive;
std::map<LcPainter*, QImage*> imagemaps;
double _scale;

0 comments on commit afff78a

Please sign in to comment.