Permalink
Browse files

DimAngular fix

  • Loading branch information...
feragon committed Jun 20, 2016
1 parent 72ed3de commit 6f8ae9cfba13508f605d48550b5601818f385434
@@ -13,13 +13,13 @@ setmetatable(DimAngularOperations, {
function DimAngularOperations:_init(id)
Operations._init(self, id)
self.startPoint = nil
self.endPoint = nil
self.textOffset = nil
self.centerPoint = nil
self.firstPoint = nil
self.secondPoint = nil
self.text = nil
self.dimAngular_id = ID():id()
self.dimAngular = self:getDimAngular(Coord(0,0), Coord(1,1), 1, "<>")
self.dimAngular = self:getDimAngular(Coord(0,0), Coord(1,0), Coord(1,1), "<>")
self.dimLine = nil
active_widget():tempEntities():addEntity(self.dimAngular)
@@ -29,14 +29,13 @@ function DimAngularOperations:_init(id)
event.register('number', self)
event.register('text', self)
message("Todo: fix DimAuto for DimAngular")
message("Click on start point")
message("Click on center point")
end
function DimAngularOperations:getDimAngular(startPoint, endPoint, textOffset, text)
function DimAngularOperations:getDimAngular(certerPoint, firstPoint, secondPoint, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimAngular.dimAuto(startPoint, endPoint, textOffset, text, layer, MetaInfo())
local dim = DimAngular.dimAuto(certerPoint, firstPoint, secondPoint, text, layer, MetaInfo())
dim:setId(self.dimAngular_id)
return dim
@@ -57,21 +56,16 @@ function DimAngularOperations:onEvent(eventName, ...)
end
function DimAngularOperations: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)
self.dimLine = Line(self.startPoint, self.endPoint, Layer("Temp", Color(0,0,0,0)))
message("Give dimension height")
elseif(self.textOffset == nil) then
if(type(data) == "userdata") then
self.textOffset = self.dimLine:nearestPointOnPath(data):distanceTo(data)
else
self.textOffset = data
end
if(self.centerPoint == nil) then
self.centerPoint = Operations:getCoordinate(data)
message("Click on first point")
elseif(self.firstPoint == nil) then
self.firstPoint = Operations:getCoordinate(data)
message("Click on second point")
elseif(self.secondPoint == nil) then
self.secondPoint = Operations:getCoordinate(data)
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
@@ -90,28 +84,24 @@ function DimAngularOperations:setText(text)
end
function DimAngularOperations:createTempDimAngular(point)
local startPoint = self.startPoint
local endPoint = self.endPoint
local textOffset = self.textOffset
if(startPoint == nil) then
startPoint = point
elseif(endPoint == nil) then
endPoint = point
if(startPoint:x() == endPoint:x() and startPoint:y() == endPoint:y()) then
endPoint = endPoint:add(Coord(0.001,0.001))
end
elseif(textOffset == nil) then
textOffset = self.dimLine:nearestPointOnPath(point):distanceTo(point)
local centerPoint = self.centerPoint
local firstPoint = self.firstPoint
local secondPoint = self.secondPoint
if(centerPoint == nil) then
centerPoint = point
elseif(firstPoint == nil) then
firstPoint = point
elseif(secondPoint == nil) then
secondPoint = point
end
endPoint = endPoint or startPoint:add(Coord(10,0))
textOffset = textOffset or 10
firstPoint = firstPoint or centerPoint:add(Coord(-1, 1))
secondPoint = secondPoint or centerPoint:add(Coord(1, 1))
active_widget():tempEntities():removeEntity(self.dimAngular)
self.dimAngular = self:getDimAngular(startPoint, endPoint, textOffset, "<>")
self.dimAngular = self:getDimAngular(centerPoint, firstPoint, secondPoint, "<>")
active_widget():tempEntities():addEntity(self.dimAngular)
end
@@ -120,7 +110,7 @@ function DimAngularOperations:createDimAngular()
active_widget():tempEntities():removeEntity(self.dimAngular)
local b = Builder(active_widget():document())
local c = self:getDimAngular(self.startPoint, self.endPoint, self.textOffset, self.text)
local c = self:getDimAngular(self.centerPoint, self.firstPoint, self.secondPoint, self.text)
b:append(c)
b:execute()
@@ -37,14 +37,10 @@ DimAngular::DimAngular(const DimAngular_CSPtr other, bool sameID) :
_defLine22(other->_defLine22) {
}
DimAngular_SPtr DimAngular::dimAuto(geo::Coordinate const& p2, geo::Coordinate const& p3, double const textOffset, std::string const& explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) {
DimAngular_SPtr DimAngular::dimAuto(geo::Coordinate const& center, geo::Coordinate const& p1, geo::Coordinate const& p2, std::string const& explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) {
geo::Coordinate middletext(p1.mid(p2));
geo::Coordinate dir = (p3 - p2).rotate(0.5 * M_PI);
geo::Coordinate p0 = p3.move(dir, textOffset);
geo::Coordinate middletext(p2.mid(p3).move(dir, textOffset));
return std::make_shared<DimAngular>(p0, middletext, TextConst::AttachmentPoint::Top_center, 0., 0., TextConst::LineSpacingStyle::AtLeast, explicitValue, p2, p3, p3, p3, layer, metaInfo);
return std::make_shared<DimAngular>(center, middletext, TextConst::AttachmentPoint::Top_center, 0., 0., TextConst::LineSpacingStyle::AtLeast, explicitValue, center, p1, center, p2, layer, metaInfo);
}
@@ -35,8 +35,8 @@ namespace lc {
DimAngular(const DimAngular_CSPtr other, bool sameID = false);
static DimAngular_SPtr dimAuto(geo::Coordinate const &p1, geo::Coordinate const &p2,
double const textOffset, std::string const &explicitValue,
static DimAngular_SPtr dimAuto(geo::Coordinate const &center, geo::Coordinate const &p1,
geo::Coordinate const &p2, std::string const &explicitValue,
const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo);
public:

0 comments on commit 6f8ae9c

Please sign in to comment.