Mon, 16 Jun 2014 17:55:10 +0300
- added split lines action, doesn't yet work very well
src/actionsEdit.cc | file | annotate | diff | comparison | revisions | |
src/mainWindow.h | file | annotate | diff | comparison | revisions | |
ui/ldforge.ui | file | annotate | diff | comparison | revisions |
--- a/src/actionsEdit.cc Mon Jun 16 15:32:33 2014 +0300 +++ b/src/actionsEdit.cc Mon Jun 16 17:55:10 2014 +0300 @@ -16,10 +16,12 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +#include <limits> #include <QSpinBox> #include <QCheckBox> #include <QBoxLayout> #include <QClipboard> +#include <QInputDialog> #include "mainWindow.h" #include "main.h" #include "ldDocument.h" @@ -34,10 +36,11 @@ #include "ui_flip.h" #include "ui_addhistoryline.h" -EXTERN_CFGENTRY (String, defaultUser); +EXTERN_CFGENTRY (String, defaultUser) -CFGENTRY (Int, roundPosition, 3); -CFGENTRY (Int, roundMatrix, 4); +CFGENTRY (Int, roundPosition, 3) +CFGENTRY (Int, roundMatrix, 4) +CFGENTRY (Int, splitLinesSegments, 5) // ============================================================================= // @@ -778,3 +781,53 @@ buildObjList(); delete ui; } + +DEFINE_ACTION (SplitLines, 0) +{ + bool ok; + int segments = QInputDialog::getInt (g_win, APPNAME, "Amount of segments:", cfg::splitLinesSegments, 0, + std::numeric_limits<int>::max(), 1, &ok); + + if (not ok) + return; + + cfg::splitLinesSegments = segments; + + for (LDObjectPtr obj : selection()) + { + if (obj->type() != OBJ_Line && obj->type() != OBJ_CondLine) + continue; + + QVector<LDObjectPtr> newsegs; + + for (int i = 0; i < segments; ++i) + { + LDObjectPtr segment; + + if (obj->type() == OBJ_Line) + segment = spawn<LDLine>(); + else + segment = spawn<LDCondLine>(); + + Vertex v0, v1; + v0.apply ([&](Axis ax, double& a) { a = (obj->vertex (0)[ax] + (((obj->vertex (1)[ax] - obj->vertex (0)[ax]) * i) / segments)); }); + v1.apply ([&](Axis ax, double& a) { a = (obj->vertex (0)[ax] + (((obj->vertex (1)[ax] - obj->vertex (0)[ax]) * (i + 1)) / segments)); }); + print ("%1, %2\n", v0.toString(true), v1.toString(true)); + segment->setVertex (0, v0); + segment->setVertex (0, v1); + segment->setVertex (2, obj->vertex (2)); + segment->setVertex (3, obj->vertex (3)); + newsegs << segment; + } + + int ln = obj->lineNumber(); + + for (LDObjectPtr seg : newsegs) + getCurrentDocument()->insertObj (ln++, seg); + + obj->destroy(); + } + + buildObjList(); + g_win->refresh(); +}
--- a/src/mainWindow.h Mon Jun 16 15:32:33 2014 +0300 +++ b/src/mainWindow.h Mon Jun 16 17:55:10 2014 +0300 @@ -287,6 +287,7 @@ void slot_actionDrawAngles(); void slot_actionRandomColors(); void slot_actionOpenSubfiles(); + void slot_actionSplitLines(); protected: void closeEvent (QCloseEvent* ev);
--- a/ui/ldforge.ui Mon Jun 16 15:32:33 2014 +0300 +++ b/ui/ldforge.ui Mon Jun 16 17:55:10 2014 +0300 @@ -75,8 +75,8 @@ <rect> <x>0</x> <y>0</y> - <width>233</width> - <height>436</height> + <width>99</width> + <height>99</height> </rect> </property> <attribute name="label"> @@ -230,6 +230,7 @@ <addaction name="actionFlip"/> <addaction name="actionDemote"/> <addaction name="actionOpenSubfiles"/> + <addaction name="actionSplitLines"/> <addaction name="separator"/> <addaction name="actionVisibilityHide"/> <addaction name="actionVisibilityToggle"/> @@ -1419,12 +1420,17 @@ </action> <action name="actionOpenSubfiles"> <property name="text"> - <string>Open Subfiles</string> + <string>Open Subfiles for Editing</string> </property> <property name="toolTip"> <string>Opens the documents used by the selected subparts for editing.</string> </property> </action> + <action name="actionSplitLines"> + <property name="text"> + <string>Split Lines...</string> + </property> + </action> </widget> <resources> <include location="../ldforge.qrc"/>