Added polygon bordering function

Thu, 21 Mar 2013 03:20:02 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Thu, 21 Mar 2013 03:20:02 +0200
changeset 57
6e89589f1fe8
parent 56
64899ff3bcb3
child 58
4db04d4857c0

Added polygon bordering function

gui.cpp file | annotate | diff | comparison | revisions
gui.h file | annotate | diff | comparison | revisions
icons/delete.png file | annotate | diff | comparison | revisions
icons/make-borders.png file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
--- a/gui.cpp	Thu Mar 21 02:48:09 2013 +0200
+++ b/gui.cpp	Thu Mar 21 03:20:02 2013 +0200
@@ -99,6 +99,7 @@
 	MAKE_ACTION (inline,		"Inline",		"inline",		"Inline selected subfiles.")
 	MAKE_ACTION (splitQuads,	"Split Quads",	"quad-split",	"Split quads into triangles.")
 	MAKE_ACTION (setContents,	"Set Contents",	"set-contents",	"Set the raw code of this object.")
+	MAKE_ACTION (makeBorders,	"Make Borders",	"make-borders",	"Add borders around given polygons.")
 	
 	MAKE_ACTION (newSubfile,	"New Subfile",	"add-subfile",	"Creates a new subfile reference.")
 	MAKE_ACTION (newLine,		"New Line", 	"add-line",		"Creates a new line.")
@@ -173,6 +174,7 @@
 	qEditMenu->addAction (qAct_inline);			// Inline
 	qEditMenu->addAction (qAct_splitQuads);		// Split Quads
 	qEditMenu->addAction (qAct_setContents);	// Set Contents
+	qEditMenu->addAction (qAct_makeBorders);	// Make Borders
 	
 	// Help menu
 	qHelpMenu = menuBar ()->addMenu (tr ("&Help"));
@@ -212,6 +214,7 @@
 	qEditToolBar->addAction (qAct_inline);
 	qEditToolBar->addAction (qAct_splitQuads);
 	qEditToolBar->addAction (qAct_setContents);
+	qEditToolBar->addAction (qAct_makeBorders);
 	addToolBar (qEditToolBar);
 }
 
@@ -432,20 +435,7 @@
 	if (qObjList->selectedItems().size() != 1)
 		return;
 	
-	ulong ulIndex;
-	LDObject* obj = nullptr;
-	
-	QTreeWidgetItem* item = qObjList->selectedItems()[0];
-	for (ulIndex = 0; ulIndex < g_CurrentFile->objects.size(); ++ulIndex) {
-		obj = g_CurrentFile->objects[ulIndex];
-		
-		if (obj->qObjListEntry == item)
-			break;
-	}
-	
-	if (ulIndex >= g_CurrentFile->objects.size())
-		return;
-	
+	LDObject* obj = getSelectedObjects ()[0];
 	SetContentsDialog::staticDialog (obj, this);
 }
 
@@ -494,6 +484,48 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+void ForgeWindow::slot_makeBorders () {
+	vector<LDObject*> objs = getSelectedObjects ();
+	
+	// Delete the objects that were being selected
+	for (std::size_t i = 0; i < objs.size(); ++i) {
+		LDObject* obj = objs[i];
+		
+		if (obj->getType() != OBJ_Quad && obj->getType() != OBJ_Triangle)
+			continue;
+		
+		short dNumLines;
+		LDLine* lines[4];
+		
+		if (obj->getType() == OBJ_Quad) {
+			dNumLines = 4;
+			
+			LDQuad* quad = static_cast<LDQuad*> (obj);
+			lines[0] = new LDLine (quad->vaCoords[0], quad->vaCoords[1]);
+			lines[1] = new LDLine (quad->vaCoords[1], quad->vaCoords[2]);
+			lines[2] = new LDLine (quad->vaCoords[2], quad->vaCoords[3]);
+			lines[3] = new LDLine (quad->vaCoords[3], quad->vaCoords[0]);
+		} else {
+			dNumLines = 3;
+			
+			LDTriangle* tri = static_cast<LDTriangle*> (obj);
+			lines[0] = new LDLine (tri->vaCoords[0], tri->vaCoords[1]);
+			lines[1] = new LDLine (tri->vaCoords[1], tri->vaCoords[2]);
+			lines[2] = new LDLine (tri->vaCoords[2], tri->vaCoords[0]); 
+		}
+		
+		for (short i = 0; i < dNumLines; ++i) {
+			lines[i]->dColor = dEdgeColor;
+			g_CurrentFile->addObject (lines[i]);
+		}
+	}
+	
+	refresh ();
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 void ForgeWindow::buildObjList () {
 	if (!g_CurrentFile)
 		return;
--- a/gui.h	Thu Mar 21 02:48:09 2013 +0200
+++ b/gui.h	Thu Mar 21 03:20:02 2013 +0200
@@ -59,7 +59,7 @@
 	QAction* qAct_cut, *qAct_copy, *qAct_paste, *qAct_delete;
 	QAction* qAct_newSubfile, *qAct_newLine, *qAct_newTriangle, *qAct_newQuad;
 	QAction* qAct_newCondLine, *qAct_newComment, *qAct_newVertex;
-	QAction* qAct_splitQuads, *qAct_setContents, *qAct_inline;
+	QAction* qAct_splitQuads, *qAct_setContents, *qAct_inline, *qAct_makeBorders;
 	QAction* qAct_settings;
 	QAction* qAct_help, *qAct_about, *qAct_aboutQt;
 	QAction* qAct_setColor;
@@ -100,6 +100,7 @@
 	void slot_inline ();
 	void slot_splitQuads ();
 	void slot_setContents ();
+	void slot_makeBorders ();
 	
 	void slot_cut ();
 	void slot_copy ();
Binary file icons/delete.png has changed
Binary file icons/make-borders.png has changed
--- a/ldtypes.cpp	Thu Mar 21 02:48:09 2013 +0200
+++ b/ldtypes.cpp	Thu Mar 21 03:20:02 2013 +0200
@@ -238,6 +238,13 @@
 	delete this;
 }
 
+LDLine::LDLine (vertex v1, vertex v2) {
+	commonInit ();
+	
+	vaCoords[0] = v1;
+	vaCoords[1] = v2;
+}
+
 LDObject::~LDObject () {}
 LDComment::~LDComment () {}
 LDCondLine::~LDCondLine () {}
--- a/ldtypes.h	Thu Mar 21 02:48:09 2013 +0200
+++ b/ldtypes.h	Thu Mar 21 03:20:02 2013 +0200
@@ -164,6 +164,7 @@
 class LDLine : public LDObject {
 public:
 	IMPLEMENT_LDTYPE (Line)
+	LDLine (vertex v1, vertex v2);
 	
 	vertex vaCoords[2]; // End points of this line
 };

mercurial