Permalink
Browse files

Fix DimAligned direction

  • Loading branch information...
feragon committed Jun 21, 2016
1 parent deaa43e commit 4ca23e67424d5d70e3265a02bf7ad544adb6d129
@@ -15,11 +15,11 @@ function DimAlignedOperations:_init(id)
self.startPoint = nil
self.endPoint = nil
self.textOffset = nil
self.middleOfText = nil
self.text = nil
self.dimAligned_id = ID():id()
self.dimAligned = self:getDimAligned(Coord(0,0), Coord(1,1), 1, "<>")
self.dimAligned = self:getDimAligned(Coord(0,0), Coord(1,0), Coord(1,1), "<>")
self.dimLine = nil
active_widget():tempEntities():addEntity(self.dimAligned)
@@ -32,10 +32,10 @@ function DimAlignedOperations:_init(id)
message("Click on start point")
end
function DimAlignedOperations:getDimAligned(startPoint, endPoint, textOffset, text)
function DimAlignedOperations:getDimAligned(startPoint, endPoint, middleOfText, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimAligned.dimAuto(startPoint, endPoint, textOffset, text, layer, MetaInfo())
local dim = DimAligned.dimAuto(startPoint, endPoint, middleOfText, text, layer, MetaInfo())
dim:setId(self.dimAligned_id)
return dim
@@ -65,12 +65,8 @@ function DimAlignedOperations:newData(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
elseif(self.middleOfText == nil) then
self.middleOfText = Operations:getCoordinate(data)
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
@@ -91,7 +87,7 @@ end
function DimAlignedOperations:createTempDimAligned(point)
local startPoint = self.startPoint
local endPoint = self.endPoint
local textOffset = self.textOffset
local middleOfText = self.middleOfText
if(startPoint == nil) then
startPoint = point
@@ -101,16 +97,16 @@ function DimAlignedOperations:createTempDimAligned(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)
elseif(middleOfText == nil) then
middleOfText = point
end
endPoint = endPoint or startPoint:add(Coord(10,0))
textOffset = textOffset or 10
middleOfText = middleOfText or startPoint:add(Coord(5,10))
active_widget():tempEntities():removeEntity(self.dimAligned)
self.dimAligned = self:getDimAligned(startPoint, endPoint, textOffset, "<>")
self.dimAligned = self:getDimAligned(startPoint, endPoint, middleOfText, "<>")
active_widget():tempEntities():addEntity(self.dimAligned)
end
@@ -119,7 +115,7 @@ function DimAlignedOperations:createDimAligned()
active_widget():tempEntities():removeEntity(self.dimAligned)
local b = Builder(active_widget():document())
local c = self:getDimAligned(self.startPoint, self.endPoint, self.textOffset, self.text)
local c = self:getDimAligned(self.startPoint, self.endPoint, self.middleOfText, self.text)
b:append(c)
b:execute()
@@ -183,11 +183,11 @@ static lc::entity::DimAligned_SPtr lua_dimAligned1(lc::geo::Coordinate const& de
explicitValue, definitionPoint2, definitionPoint3, layer, metaInfo);
}
static lc::entity::DimAligned_SPtr lua_DimAligned_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::DimAligned::dimAuto(p1, p2, textOffset, explicitValue, layer, nullptr);
static lc::entity::DimAligned_SPtr lua_DimAligned_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::DimAligned::dimAuto(p1, p2, p3, explicitValue, layer, nullptr);
}
static lc::entity::DimAligned_SPtr lua_DimAligned_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::DimAligned::dimAuto(p1, p2, textOffset, explicitValue, layer, metaInfo);
static lc::entity::DimAligned_SPtr lua_DimAligned_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::DimAligned::dimAuto(p1, p2, p3, explicitValue, layer, metaInfo);
}
/***
* |~\. _ _ /\ _ _ | _ _
@@ -17,14 +17,21 @@ DimAligned::DimAligned(geo::Coordinate const& definitionPoint, geo::Coordinate c
DimAligned::DimAligned(const DimAligned_CSPtr other, bool sameID) : CADEntity(other, sameID), Dimension(*other), _definitionPoint2(other->_definitionPoint2), _definitionPoint3(other->_definitionPoint3) {
}
DimAligned_SPtr DimAligned::dimAuto(geo::Coordinate const& p2, geo::Coordinate const& p3, double const textOffset, std::string const& explicitValue, const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo) {
DimAligned_SPtr DimAligned::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) {
auto nearestPoint = geo::Vector(p1, p2).nearestPointOnPath(middleOfText);
auto distance = nearestPoint.distanceTo(middleOfText);
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));
geo::Coordinate dir;
if(((p2.x() - p1.x()) * (middleOfText.y() - p1.y()) - (p2.y() - p1.y()) * (middleOfText.x() - p1.x())) >= 0) {
dir = (p2 - p1).rotate(0.5 * M_PI);
}
else {
dir = (p2 - p1).rotate(-0.5 * M_PI);
}
geo::Coordinate p0 = p2.move(dir, distance);
return std::make_shared<DimAligned>(p0, middletext, TextConst::AttachmentPoint::Top_center , 0., 0., TextConst::LineSpacingStyle::AtLeast, explicitValue, p2, p3, layer, metaInfo);
return std::make_shared<DimAligned>(p0, middleOfText, TextConst::AttachmentPoint::Top_center , 0., 0., TextConst::LineSpacingStyle::AtLeast, explicitValue, p1, p2, layer, metaInfo);
}
@@ -36,7 +36,7 @@ namespace lc {
DimAligned(const DimAligned_CSPtr other, bool sameID = false);
static DimAligned_SPtr dimAuto(geo::Coordinate const &p1, geo::Coordinate const &p2,
double const textOffset, std::string const &explicitValue,
geo::Coordinate const &middleOfText, std::string const &explicitValue,
const Layer_CSPtr layer, const MetaInfo_CSPtr metaInfo);
public:

0 comments on commit 4ca23e6

Please sign in to comment.