Permalink
Browse files

DimLinear creation

  • Loading branch information...
feragon committed Jun 21, 2016
1 parent 6f8ae9c commit deaa43ebd2719bd89167a3fa48e633199c7d5317
@@ -0,0 +1,121 @@
DimLinearOperations = {}
DimLinearOperations.__index = DimLinearOperations
setmetatable(DimLinearOperations, {
__index = Operations,
__call = function (o, ...)
local self = setmetatable({}, o)
self:_init(...)
return self
end,
})
function DimLinearOperations:_init(id)
Operations._init(self, id)
self.startPoint = nil
self.endPoint = nil
self.middleOfText = nil
self.text = nil
self.dimLinear_id = ID():id()
self.dimLinear = self:getDimLinear(Coord(0,0), Coord(1,0), Coord(1,1), "<>")
self.dimLine = nil
active_widget():tempEntities():addEntity(self.dimLinear)
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
event.register('text', self)
message("Click on start point")
end
function DimLinearOperations:getDimLinear(startPoint, endPoint, middleOfText, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimLinear.dimAuto(startPoint, endPoint, middleOfText, text, layer, MetaInfo())
dim:setId(self.dimLinear_id)
return dim
end
function DimLinearOperations:onEvent(eventName, ...)
if(Operations.forMe(self) == false) then
return
end
if(eventName == "point" or eventName == "number") then
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempDimLinear(...)
elseif(eventName == "text") then
self:setText(...)
end
end
function DimLinearOperations:newData(data)
if(self.startPoint == nil) then
self.startPoint = Operations:getCoordinate(data)
message("Click on end point")
elseif(self.endPoint == nil) then
self.endPoint = Operations:getCoordinate(data)
message("Give dimension height")
elseif(self.middleOfText == nil) then
self.middleOfText = Operations:getCoordinate(data)
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
end
end
function DimLinearOperations:setText(text)
if(text == "") then
self.text = "<>"
else
self.text = text
end
cli_get_text(false)
self:createDimLinear()
end
function DimLinearOperations:createTempDimLinear(point)
local startPoint = self.startPoint
local endPoint = self.endPoint
local middleOfText = self.middleOfText
if(startPoint == nil) then
startPoint = point
elseif(endPoint == nil) then
endPoint = point
elseif(middleOfText == nil) then
middleOfText = point
end
endPoint = endPoint or startPoint:add(Coord(10,0))
middleOfText = middleOfText or startPoint:add(Coord(5,10))
active_widget():tempEntities():removeEntity(self.dimLinear)
self.dimLinear = self:getDimLinear(startPoint, endPoint, middleOfText, "<>")
active_widget():tempEntities():addEntity(self.dimLinear)
end
function DimLinearOperations:createDimLinear()
active_widget():tempEntities():removeEntity(self.dimLinear)
local b = Builder(active_widget():document())
local c = self:getDimLinear(self.startPoint, self.endPoint, self.middleOfText, self.text)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
end
@@ -6,6 +6,7 @@ require 'actions.ellipseoperations'
require 'actions.dimalignedoperations'
require 'actions.dimangularoperations'
require 'actions.dimdiametricoperations'
require 'actions.dimlinearoperations'
Operations = {}
Operations.__index = Operations
@@ -60,6 +60,7 @@ function add_commandline()
add_command("ARCELLIPSE", create_arc_ellipse)
add_command("DIMALIGNED", create_dim_aligned)
add_command("DIMDIAMETRIC", create_dim_diametric)
add_command("DIMLINEAR", create_dim_linear)
event.register("point", setLastPoint)
end
@@ -28,4 +28,7 @@ end
function create_dim_diametric()
op[active_widget().id] = DimDiametricOperations(active_widget().id)
end
function create_dim_linear()
op[active_widget().id] = DimLinearOperations(active_widget().id)
end
View
@@ -74,4 +74,8 @@ function add_toolbar()
local dimDiametric = create_button("", ":/icons/dim_diametric.svg")
quickAccess:addButton(dimGroup, dimDiametric, 0, 1, 1, 1)
luaInterface:luaConnect(dimDiametric, "pressed()", create_dim_diametric)
local dimLinear = create_button("", ":/icons/dim_linear.svg")
quickAccess:addButton(dimGroup, dimLinear, 1, 1, 1, 1)
luaInterface:luaConnect(dimLinear, "pressed()", create_dim_linear)
end
@@ -224,7 +224,8 @@ void lua_openlckernel(lua_State* L) {
const Layer_CSPtr,
const MetaInfo_CSPtr))
.endClass()
.beginExtendClass<entity::DimLinear, entity::CADEntity>("DimLinear_")
.beginExtendClass<entity::DimLinear, entity::CADEntity>("DimLinear")
.addStaticFunction("dimAuto", &entity::DimLinear::dimAuto)
.endClass()
.beginExtendClass<entity::DimAligned, entity::CADEntity>("DimAligned")
.addStaticFunction("dimAuto", &entity::DimAligned::dimAuto)
@@ -158,11 +158,11 @@ static lc::entity::DimLinear_SPtr lua_dimLinear1(lc::geo::Coordinate const& defi
lc::geo::Coordinate const& definitionPoint2, lc::geo::Coordinate const& definitionPoint3, const double angle, const double oblique, const lc::Layer_CSPtr layer, const lc::MetaInfo_CSPtr metaInfo) {
return std::make_shared<lc::entity::DimLinear>(definitionPoint, middleOfText, static_cast<lc::TextConst::AttachmentPoint>(attachmentPoint), textAngle, lineSpacingFactor, static_cast<lc::TextConst::LineSpacingStyle>(lineSpacingStyle), explicitValue, definitionPoint2, definitionPoint3, angle, oblique, layer, metaInfo);
}
static lc::entity::DimLinear_SPtr lua_DimLinear_dimAuto(lc::geo::Coordinate const& p1, lc::geo::Coordinate const& p2, double const textOffset, std::string const& explicitValue, const lc::Layer_CSPtr layer) {
return lc::entity::DimLinear::dimAuto(p1, p2, textOffset, explicitValue, layer, nullptr);
static lc::entity::DimLinear_SPtr lua_DimLinear_dimAuto(lc::geo::Coordinate const& p1, lc::geo::Coordinate const& p2, lc::geo::Coordinate const& p3, std::string const& explicitValue, const lc::Layer_CSPtr layer) {
return lc::entity::DimLinear::dimAuto(p1, p2, p3, explicitValue, layer, nullptr);
}
static lc::entity::DimLinear_SPtr lua_DimLinear_dimAuto1(lc::geo::Coordinate const& p1, lc::geo::Coordinate const& p2, double const textOffset, std::string const& explicitValue, const lc::Layer_CSPtr layer, const lc::MetaInfo_CSPtr metaInfo) {
return lc::entity::DimLinear::dimAuto(p1, p2, textOffset, explicitValue, layer, metaInfo);
static lc::entity::DimLinear_SPtr lua_DimLinear_dimAuto1(lc::geo::Coordinate const& p1, lc::geo::Coordinate const& p2, lc::geo::Coordinate const& p3, std::string const& explicitValue, const lc::Layer_CSPtr layer, const lc::MetaInfo_CSPtr metaInfo) {
return lc::entity::DimLinear::dimAuto(p1, p2, p3, explicitValue, layer, metaInfo);
}
/***
@@ -15,27 +15,8 @@ DimLinear::DimLinear(geo::Coordinate const& definitionPoint, geo::Coordinate con
DimLinear::DimLinear(const DimLinear_CSPtr other, bool sameID) : CADEntity(other, sameID), Dimension(*other), _angle(other->_angle), _oblique(other->_oblique), _definitionPoint2(other->_definitionPoint2), _definitionPoint3(other->_definitionPoint3) {
}
DimLinear_SPtr DimLinear::dimAuto(geo::Coordinate const& p2, geo::Coordinate const& p3, const double textOffset, std::string const& explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) {
const double dx = std::abs(p2.x() - p3.x());
const double dy = std::abs(p2.y() - p3.y());
const bool isHorizontal = dx > dy;
geo::Coordinate p0;
geo::Coordinate pp2;
geo::Coordinate pp3;
geo::Coordinate middletext(p2.mid(p3));
if (isHorizontal) {
p0 = geo::Coordinate(p3.x(), p2.mid(p3).y()).move(geo::Coordinate(0., 1.), textOffset);
middletext = p2.mid(p3).move(geo::Coordinate(0., 1.), textOffset);
} else {
p0 = geo::Coordinate(p3.mid(p2).x(), p3.y()).move(geo::Coordinate(1., 0.), textOffset);
middletext = p2.mid(p3).move(geo::Coordinate(1., 0.), textOffset);
}
return std::make_shared<DimLinear>(p0, middletext, TextConst::AttachmentPoint::Top_center , 0., 0., TextConst::LineSpacingStyle::AtLeast, explicitValue, p2, p3, 0., 0., layer, metaInfo);
DimLinear_SPtr DimLinear::dimAuto(geo::Coordinate const& p1, geo::Coordinate const& p2, geo::Coordinate const &middleOfText, std::string const& explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) {
return std::make_shared<DimLinear>(p1, middleOfText, TextConst::AttachmentPoint::Middle_center , 0., 0., TextConst::LineSpacingStyle::AtLeast, explicitValue, p1, p2, 0., 0., layer, metaInfo);
}
@@ -37,7 +37,7 @@ namespace lc {
/**
* Convenient function
*/
static DimLinear_SPtr dimAuto(geo::Coordinate const &p2, geo::Coordinate const &p3, const double textOffset,
static DimLinear_SPtr dimAuto(geo::Coordinate const &p1, geo::Coordinate const &p2, geo::Coordinate const &middleOfText,
std::string const &explicitValue, const Layer_CSPtr layer,
const MetaInfo_CSPtr metaInfo);

0 comments on commit deaa43e

Please sign in to comment.