Permalink
Browse files

Add text in DimAligned creation

  • Loading branch information...
feragon committed Jun 20, 2016
1 parent a63cbc6 commit 13aba67468bc8ce86167cbe75fc081be60d23363
View
@@ -210,6 +210,7 @@ void addLCBindings(lua_State *L) {
.addConstructor(LUA_SP(std::shared_ptr<CliCommand>), LUA_ARGS(LuaIntf::_opt<QWidget*>))
.addFunction("addCommand", &CliCommand::addCommand)
.addFunction("write", &CliCommand::write, LUA_ARGS(const char*))
.addFunction("returnText", &CliCommand::returnText)
.endClass()
.beginExtendClass<Toolbar, QDockWidget>("Toolbar")
@@ -4,6 +4,7 @@
CliCommand::CliCommand(QWidget* parent) :
QDockWidget(parent),
ui(new Ui::CliCommand),
_returnText(false),
_historySize(10),
_historyIndex(-1)
{
@@ -48,7 +49,10 @@ void CliCommand::onReturnPressed() {
auto text = ui->command->text();
bool isNumber;
if(text != "") {
if(_returnText) {
emit textEntered(text);
}
else if(text != "") {
_history.push_front(text);
if (_history.size() > _historySize) {
@@ -65,10 +69,10 @@ void CliCommand::onReturnPressed() {
else {
enterCommand(text);
}
_historyIndex = -1;
ui->command->clear();
}
_historyIndex = -1;
ui->command->clear();
}
void CliCommand::keyPressEvent(QKeyEvent *event) {
@@ -151,7 +155,6 @@ void CliCommand::onKeyPressed(QKeyEvent *event) {
break;
default:
ui->command->setFocus();
ui->command->event(event);
break;
}
@@ -161,3 +164,6 @@ void CliCommand::setText(QString text) {
ui->command->setText(text);
}
void CliCommand::returnText(bool returnText) {
_returnText = returnText;
}
@@ -28,6 +28,8 @@ class CliCommand : public QDockWidget {
void write(QString message);
void setText(QString text);
void returnText(bool returnText);
public slots:
void onReturnPressed();
void onKeyPressed(QKeyEvent *event);
@@ -37,6 +39,7 @@ class CliCommand : public QDockWidget {
void coordinateEntered(lc::geo::Coordinate coordinate);
void relativeCoordinateEntered(lc::geo::Coordinate coordinate);
void numberEntered(double number);
void textEntered(QString text);
private:
void enterCommand(QString command);
@@ -46,6 +49,7 @@ class CliCommand : public QDockWidget {
Ui::CliCommand* ui;
std::shared_ptr<QCompleter> _completer;
std::shared_ptr<QStringListModel> _commands;
bool _returnText;
QStringList _history;
int _historySize;
@@ -16,24 +16,26 @@ function DimAlignedOperations:_init(id, isArc)
self.startPoint = nil
self.endPoint = nil
self.textOffset = 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,1), 1, "<>")
self.dimLine = nil
active_widget():tempEntities():addEntity(self.dimAligned)
event.register('point', self)
event.register('mouseMove', self)
event.register('number', self)
event.register('text', self)
message("Click on start point")
end
function DimAlignedOperations:getDimAligned(startPoint, endPoint, textOffset)
function DimAlignedOperations:getDimAligned(startPoint, endPoint, textOffset, text)
local d = active_widget():document()
local layer = d:layerByName("0")
local dim = DimAligned.dimAuto(startPoint, endPoint, textOffset, "<>", layer, MetaInfo())
local dim = DimAligned.dimAuto(startPoint, endPoint, textOffset, text, layer, MetaInfo())
dim:setId(self.dimAligned_id)
return dim
@@ -48,6 +50,8 @@ function DimAlignedOperations:onEvent(eventName, ...)
self:newData(...)
elseif(eventName == "mouseMove") then
self:createTempDimAligned(...)
elseif(eventName == "text") then
self:setText(...)
end
end
@@ -67,10 +71,23 @@ function DimAlignedOperations:newData(data)
else
self.textOffset = data
end
self:createDimAligned()
message("Enter dimension text or leave it empty (<> for value)")
cli_get_text(true)
end
end
function DimAlignedOperations:setText(text)
if(text == "") then
self.text = "<>"
else
self.text = text
end
cli_get_text(false)
self:createDimAligned()
end
function DimAlignedOperations:createTempDimAligned(point)
local startPoint = self.startPoint
local endPoint = self.endPoint
@@ -93,7 +110,7 @@ function DimAlignedOperations:createTempDimAligned(point)
active_widget():tempEntities():removeEntity(self.dimAligned)
self.dimAligned = self:getDimAligned(startPoint, endPoint, textOffset)
self.dimAligned = self:getDimAligned(startPoint, endPoint, textOffset, "<>")
active_widget():tempEntities():addEntity(self.dimAligned)
end
@@ -102,11 +119,12 @@ 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)
local c = self:getDimAligned(self.startPoint, self.endPoint, self.textOffset, self.text)
b:append(c)
b:execute()
event.delete('mouseMove', self)
event.delete('number', self)
event.delete('point', self)
event.delete('text', self)
end
@@ -13,6 +13,10 @@ function add_command(name, callback)
end
end
function cli_get_text(getText)
cliCommand:returnText(getText)
end
local function command(command)
commands[command:toStdString()]()
end
@@ -35,6 +39,10 @@ local function setLastPoint(point)
lastPoint = point
end
local function text(text)
event.trigger("text", text:toStdString())
end
function add_commandline()
cliCommand = lc.CliCommand(mainWindow)
mainWindow:addDockWidget(8, cliCommand)
@@ -43,6 +51,7 @@ function add_commandline()
luaInterface:luaConnect(cliCommand, "coordinateEntered(lc::geo::Coordinate)", coordinate)
luaInterface:luaConnect(cliCommand, "relativeCoordinateEntered(lc::geo::Coordinate)", relativeCoordinate)
luaInterface:luaConnect(cliCommand, "numberEntered(double)", number)
luaInterface:luaConnect(cliCommand, "textEntered(QString)", text)
add_command("LINE", create_line)
add_command("CIRCLE", create_circle)

0 comments on commit 13aba67

Please sign in to comment.