src/actionsEdit.cc

changeset 804
d8589e8e2973
parent 795
195fa1fff9c3
child 805
d88c0354de97
equal deleted inserted replaced
803:38df1bf5110d 804:d8589e8e2973
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include <limits>
19 #include <QSpinBox> 20 #include <QSpinBox>
20 #include <QCheckBox> 21 #include <QCheckBox>
21 #include <QBoxLayout> 22 #include <QBoxLayout>
22 #include <QClipboard> 23 #include <QClipboard>
24 #include <QInputDialog>
23 #include "mainWindow.h" 25 #include "mainWindow.h"
24 #include "main.h" 26 #include "main.h"
25 #include "ldDocument.h" 27 #include "ldDocument.h"
26 #include "colorSelector.h" 28 #include "colorSelector.h"
27 #include "miscallenous.h" 29 #include "miscallenous.h"
32 #include "ui_replcoords.h" 34 #include "ui_replcoords.h"
33 #include "ui_editraw.h" 35 #include "ui_editraw.h"
34 #include "ui_flip.h" 36 #include "ui_flip.h"
35 #include "ui_addhistoryline.h" 37 #include "ui_addhistoryline.h"
36 38
37 EXTERN_CFGENTRY (String, defaultUser); 39 EXTERN_CFGENTRY (String, defaultUser)
38 40
39 CFGENTRY (Int, roundPosition, 3); 41 CFGENTRY (Int, roundPosition, 3)
40 CFGENTRY (Int, roundMatrix, 4); 42 CFGENTRY (Int, roundMatrix, 4)
43 CFGENTRY (Int, splitLinesSegments, 5)
41 44
42 // ============================================================================= 45 // =============================================================================
43 // 46 //
44 static int copyToClipboard() 47 static int copyToClipboard()
45 { 48 {
776 getCurrentDocument()->insertObj (idx, LDEmptyPtr (spawn<LDEmpty>())); 779 getCurrentDocument()->insertObj (idx, LDEmptyPtr (spawn<LDEmpty>()));
777 780
778 buildObjList(); 781 buildObjList();
779 delete ui; 782 delete ui;
780 } 783 }
784
785 DEFINE_ACTION (SplitLines, 0)
786 {
787 bool ok;
788 int segments = QInputDialog::getInt (g_win, APPNAME, "Amount of segments:", cfg::splitLinesSegments, 0,
789 std::numeric_limits<int>::max(), 1, &ok);
790
791 if (not ok)
792 return;
793
794 cfg::splitLinesSegments = segments;
795
796 for (LDObjectPtr obj : selection())
797 {
798 if (obj->type() != OBJ_Line && obj->type() != OBJ_CondLine)
799 continue;
800
801 QVector<LDObjectPtr> newsegs;
802
803 for (int i = 0; i < segments; ++i)
804 {
805 LDObjectPtr segment;
806
807 if (obj->type() == OBJ_Line)
808 segment = spawn<LDLine>();
809 else
810 segment = spawn<LDCondLine>();
811
812 Vertex v0, v1;
813 v0.apply ([&](Axis ax, double& a) { a = (obj->vertex (0)[ax] + (((obj->vertex (1)[ax] - obj->vertex (0)[ax]) * i) / segments)); });
814 v1.apply ([&](Axis ax, double& a) { a = (obj->vertex (0)[ax] + (((obj->vertex (1)[ax] - obj->vertex (0)[ax]) * (i + 1)) / segments)); });
815 print ("%1, %2\n", v0.toString(true), v1.toString(true));
816 segment->setVertex (0, v0);
817 segment->setVertex (0, v1);
818 segment->setVertex (2, obj->vertex (2));
819 segment->setVertex (3, obj->vertex (3));
820 newsegs << segment;
821 }
822
823 int ln = obj->lineNumber();
824
825 for (LDObjectPtr seg : newsegs)
826 getCurrentDocument()->insertObj (ln++, seg);
827
828 obj->destroy();
829 }
830
831 buildObjList();
832 g_win->refresh();
833 }

mercurial