Permalink
Browse files

Spline creation

  • Loading branch information...
feragon committed Jun 22, 2016
1 parent 45c1cd9 commit 91d7255442100cf687e74a64a4a18b97f3f36b1c
View
@@ -239,6 +239,7 @@ void addLCBindings(lua_State *L) {
.addFunction("addGroup", &ToolbarTab::addGroup)
.addFunction("buttonByText", &ToolbarTab::buttonByText)
.addFunction("groupByName", &ToolbarTab::groupByName)
.addFunction("removeGroup", &ToolbarTab::removeGroup)
.endClass()
.beginClass<LCViewer::TempEntities>("TempEntities")
View
@@ -0,0 +1,80 @@
<?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="quit.svg"
inkscape:export-filename="D:\LC_Recources\icons\setrelzero24.png"
inkscape:export-xdpi="8.4375"
inkscape:export-ydpi="8.4375">
<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></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="64.067155"
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>
<rect
inkscape:export-ydpi="192.85715"
inkscape:export-xdpi="192.85715"
inkscape:export-filename="/home/prar/LibreCAD editado/res/ui/layeradd.png"
ry="0"
y="0.28222224"
x="-3.9451482e-009"
height="71.966675"
width="71.966667"
id="rect3021-8-3-9-7-5-6-2-2-1-4-4-9-9-39-0"
style="color:#000000;display:inline;overflow:visible;visibility:visible;opacity:0;fill:none;stroke:#000000;stroke-width:0.5329293;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
<path
style="fill:#00ff7f;fill-rule:evenodd;stroke:#000000;stroke-width:1.69333351;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 10.580605,24.949016 24.949017,10.580606 36.124448,21.756036 47.299877,10.580606 61.668288,24.949016 50.492859,36.124447 61.668288,47.299878 47.299876,61.668288 36.124447,50.492857 24.949017,61.668289 10.580606,47.299878 21.756036,36.124447 10.580605,24.949016"
id="path10912"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccccccccccc" />
</svg>
View
@@ -0,0 +1,71 @@
<?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="spline.svg"
inkscape:export-filename="E:\icons\offset.png"
inkscape:export-xdpi="8.4375"
inkscape:export-ydpi="8.4375">
<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></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">
<inkscape:grid
type="xygrid"
id="grid4867" />
</sodipodi:namedview>
<path
style="fill:none;stroke:#000000;stroke-width:2.25777793;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 64.346497,32.67277 C 62.675964,60.909459 52.085019,56.951524 40.505288,39.996807 23.475534,13.75587 14.557657,6.7980837 10.550958,11.514653 -0.45139088,22.363434 25.925247,71.971622 36.470609,60.34121 c 7.125975,-8.65563 0.231583,-40.966325 12.470828,-41.270151 6.397844,0.101782 15.452404,-0.294906 15.40506,13.601711 z"
id="path6292-2"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccc"
inkscape:export-filename="/tmp/splinePoints.png"
inkscape:export-xdpi="209.60698"
inkscape:export-ydpi="209.60698" />
</svg>
View
@@ -12,5 +12,7 @@
<file alias="dim_linear.svg">icons/dim_linear.svg</file>
<file alias="dim_diametric.svg">icons/dim_diametric.svg</file>
<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>
</qresource>
</RCC>
View
@@ -27,12 +27,12 @@ void Toolbar::removeTab(QWidget *page) {
ui->tabWidget->removeTab(index);
}
QWidget *Toolbar::tabByName(const char *name) {
ToolbarTab* Toolbar::tabByName(const char *name) {
auto nbTab = ui->tabWidget->count();
for(int i = 0; i < nbTab; i++) {
if(ui->tabWidget->tabText(i) == name) {
return ui->tabWidget->widget(i);
return dynamic_cast<ToolbarTab*>(ui->tabWidget->widget(i));
}
}
View
@@ -1,6 +1,7 @@
#pragma once
#include <QDockWidget>
#include "toolbartab.h"
namespace Ui {
class Toolbar;
@@ -14,7 +15,7 @@ class Toolbar : public QDockWidget {
void addTab(const char* name, QWidget* page);
void removeTab(QWidget* page);
QWidget* tabByName(const char* name);
ToolbarTab* tabByName(const char* name);
private:
Ui::Toolbar *ui;
@@ -55,9 +55,9 @@ QGroupBox* ToolbarTab::groupByName(const char* groupName) {
auto nbGroups = _layout->count();
for (int i = 0; i < nbGroups; i++) {
auto groupBox = dynamic_cast<QGroupBox*>(_layout->itemAt(i));
auto groupBox = dynamic_cast<QGroupBox*>(_layout->itemAt(i)->widget());
if(groupBox && groupBox->title() == groupName) {
if (groupBox && groupBox->title() == groupName) {
return groupBox;
}
}
@@ -77,4 +77,12 @@ QPushButton *ToolbarTab::buttonByText(QGroupBox* groupBox, const char* buttonTex
}
return nullptr;
}
void ToolbarTab::removeGroup(QGroupBox *group) {
if(group == nullptr) {
return;
}
delete group;
}
@@ -25,6 +25,8 @@ class ToolbarTab : public QWidget {
QGroupBox* groupByName(const char* groupName);
QPushButton* buttonByText(QGroupBox* groupBox, const char* buttonText);
void removeGroup(QGroupBox* group);
private:
Ui::ToolbarTab* ui;
QHBoxLayout* _layout;
@@ -8,6 +8,7 @@ require 'actions.dimangularoperations'
require 'actions.dimdiametricoperations'
require 'actions.dimlinearoperations'
require 'actions.dimradialoperations'
require 'actions.splineoperations'
Operations = {}
Operations.__index = Operations
@@ -0,0 +1,94 @@
SplineOperations = {}
SplineOperations.__index = SplineOperations
setmetatable(SplineOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function SplineOperations:_init(id)
Operations._init(self, id)
self.points = {}
self.spline_id = ID():id()
self.spline = self:getSpline({Coord(0,0)})
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
message("Add a new point")
end
function SplineOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point") then
self:newPoint(...)
elseif(eventName == "mouseMove") then
self:createTempSpline(...)
end
end
function SplineOperations:newPoint(point)
table.insert(self.points, point)
end
function SplineOperations:getSpline(points)
local d = active_widget():document()
local layer = d:layerByName("0")
local s = Spline(points, {}, {}, 1, false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, layer, MetaInfo())
s:setId(self.spline_id)
return s
end
function SplineOperations:createTempSpline(point)
active_widget():tempEntities():removeEntity(self.spline)
local points = {}
for k, v in pairs(self.points) do
points[k] = v
end
table.insert(points, point)
self.spline = self:getSpline(points)
active_widget():tempEntities():addEntity(self.spline)
end
function SplineOperations:createSpline()
local b = Builder(active_widget():document())
local s = self:getSpline(self.points)
b:append(s)
b:execute()
active_widget():tempEntities():removeEntity(self.spline)
self.finished = true
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
end
function SplineOperations:close()
if(not self.finished) then
if(#self.points > 1) then
self:createSpline()
else
active_widget():tempEntities():removeEntity(self.spline)
self.finished = true
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
end
end
end
@@ -62,6 +62,7 @@ function add_commandline()
add_command("DIMDIAMETRIC", create_dim_diametric)
add_command("DIMLINEAR", create_dim_linear)
add_command("DIMRADIAL", create_dim_radial)
add_command("SPLINE", create_spline)
event.register("point", setLastPoint)
end
View
@@ -1,8 +1,22 @@
local function finish_operation()
message(tostring(active_widget().id))
if(op[active_widget().id] ~= nil) then
op[active_widget().id]:close()
end
local tab = toolbar:tabByName("Quick Access")
local group = tab:groupByName("Current operation")
if(group ~= nil) then
tab:removeGroup(group)
end
end
local function create_cancel_button()
local tab = toolbar:tabByName("Quick Access")
local operationGroup = tab:addGroup("Current operation")
local cancelButton = create_button("", ":/icons/quit.svg")
tab:addButton(operationGroup, cancelButton, 0, 0, 1, 1)
luaInterface:luaConnect(cancelButton, "pressed()", finish_operation)
end
function create_line()
@@ -53,4 +67,10 @@ end
function create_dim_radial()
finish_operation()
op[active_widget().id] = DimRadialOperations(active_widget().id)
end
function create_spline()
finish_operation()
create_cancel_button()
op[active_widget().id] = SplineOperations(active_widget().id)
end
Oops, something went wrong.

0 comments on commit 91d7255

Please sign in to comment.