Adding objects now actually updates the bounding box like it should be.

Fri, 03 May 2013 18:49:23 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Fri, 03 May 2013 18:49:23 +0300
changeset 153
03a7bdcce50d
parent 152
552e46650a95
child 154
cc53e5cbad54

Adding objects now actually updates the bounding box like it should be.

file.cpp file | annotate | diff | comparison | revisions
file.h file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gui_actions.cpp file | annotate | diff | comparison | revisions
history.cpp file | annotate | diff | comparison | revisions
zz_addObjectDialog.cpp file | annotate | diff | comparison | revisions
--- a/file.cpp	Fri May 03 18:30:38 2013 +0300
+++ b/file.cpp	Fri May 03 18:49:23 2013 +0300
@@ -610,14 +610,22 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 ulong OpenFile::addObject (LDObject* obj) {
-	if (this != g_CurrentFile) {
-		objects.push_back (obj);
-		return objects.size() - 1;
-	}
+	objects.push_back (obj);
+	
+	if (this == g_CurrentFile)
+		g_BBox.calcObject (obj);
 	
-	const ulong ulSpot = g_ForgeWindow->getInsertionPoint ();
-	objects.insert (objects.begin() + ulSpot, obj);
-	return ulSpot;
+	return objects.size() - 1;
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
+void OpenFile::insertObj (const ulong pos, LDObject* obj) {
+	objects.insert (objects.begin () + pos, obj);
+	
+	if (this == g_CurrentFile)
+		g_BBox.calcObject (obj);
 }
 
 // =============================================================================
@@ -635,6 +643,10 @@
 	
 	// Erase it from memory
 	objects.erase (objects.begin() + ulIndex);
+	
+	// Update the bounding box
+	if (this == g_CurrentFile)
+		g_BBox.calculate ();
 }
 
 // =============================================================================
--- a/file.h	Fri May 03 18:30:38 2013 +0300
+++ b/file.h	Fri May 03 18:49:23 2013 +0300
@@ -50,7 +50,7 @@
 	// Perform safety checks. Do this before closing any files!
 	bool safeToClose ();
 	
-	// Adds an object to this file at the appropriate location.
+	// Adds an object to this file at the end of the file.
 	ulong addObject (LDObject* obj);
 	
 	// Deletes the given object from the object chain.
@@ -63,9 +63,7 @@
 		return objects[pos];
 	}
 	
-	void insertObj (const ulong pos, LDObject* obj) {
-		objects.insert (objects.begin () + pos, obj);
-	}
+	void insertObj (const ulong pos, LDObject* obj);
 };
 
 // Close all current loaded files and start off blank.
--- a/gldraw.cpp	Fri May 03 18:30:38 2013 +0300
+++ b/gldraw.cpp	Fri May 03 18:49:23 2013 +0300
@@ -56,6 +56,9 @@
 cfg (bool, gl_selflash, false);
 cfg (int, gl_camera, GLRenderer::Free);
 
+// CameraIcon::img is a heap-allocated QPixmap because otherwise it gets
+// initialized before program gets to main() and constructs a QApplication
+// and Qt doesn't like that.
 struct CameraIcon {
 	QPixmap* img;
 	QRect srcRect, destRect, selRect;
--- a/gui_actions.cpp	Fri May 03 18:30:38 2013 +0300
+++ b/gui_actions.cpp	Fri May 03 18:49:23 2013 +0300
@@ -373,7 +373,7 @@
 	pQuad->vaCoords[2] = {-1.0f, 0.0f, -1.0f};
 	pQuad->vaCoords[3] = { 1.0f, 0.0f, -1.0f};
 	
-	g_CurrentFile->addObject (pQuad);
+	g_CurrentFile->insertObj (g_ForgeWindow->getInsertionPoint (), pQuad);
 	History::addEntry (new AddHistory ({(ulong)pQuad->getIndex (g_CurrentFile)}, {pQuad->clone ()}));
 	g_ForgeWindow->refresh ();
 }
@@ -388,7 +388,7 @@
 	pRad->dRingNum = 2;
 	pRad->dSegments = 16;
 	
-	g_CurrentFile->addObject (pRad);
+	g_CurrentFile->insertObj (g_ForgeWindow->getInsertionPoint (), pRad);
 	History::addEntry (new AddHistory ({(ulong)pRad->getIndex (g_CurrentFile)}, {pRad->clone ()}));
 	g_ForgeWindow->refresh ();
 }
--- a/history.cpp	Fri May 03 18:30:38 2013 +0300
+++ b/history.cpp	Fri May 03 18:49:23 2013 +0300
@@ -97,7 +97,7 @@
 	for (ulong i = 0; i < cache.size(); ++i) {
 		ulong idx = cache.size() - i - 1;
 		LDObject* obj = cache[idx]->clone ();
-		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + indices[idx], obj);
+		g_CurrentFile->insertObj (indices[idx], obj);
 	}
 	
 	g_ForgeWindow->refresh ();
@@ -217,7 +217,7 @@
 		ulong idx = ulaIndices[i];
 		LDObject* obj = paObjs[i]->clone ();
 		
-		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx, obj);
+		g_CurrentFile->insertObj (idx, obj);
 	}
 	
 	g_ForgeWindow->refresh ();
@@ -258,7 +258,7 @@
 		std::vector<LDTriangle*> paTriangles = pQuad->splitToTriangles ();
 		
 		g_CurrentFile->objects[idx] = paTriangles[0];
-		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx + 1, paTriangles[1]);
+		g_CurrentFile->insertObj (idx + 1, paTriangles[1]);
 		delete pQuad;
 	}
 	
@@ -277,7 +277,7 @@
 	
 	for (ulong i = 0; i < ulaRefIndices.size(); ++i) {
 		LDSubfile* obj = paRefs[i]->clone ();
-		g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ulaRefIndices[i], obj);
+		g_CurrentFile->insertObj (ulaRefIndices[i], obj);
 	}
 	
 	g_ForgeWindow->refresh ();
@@ -292,7 +292,7 @@
 		vector<LDObject*> objs = ref->inlineContents (bDeep, false);
 		
 		for (LDObject* obj : objs)
-			g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + idx++, obj);
+			g_CurrentFile->insertObj (idx++, obj);
 		
 		g_CurrentFile->forgetObject (ref);
 		delete ref;
--- a/zz_addObjectDialog.cpp	Fri May 03 18:30:38 2013 +0300
+++ b/zz_addObjectDialog.cpp	Fri May 03 18:49:23 2013 +0300
@@ -432,7 +432,8 @@
 		break;
 	}
 	
-	ulong idx = g_CurrentFile->addObject (obj);
+	ulong idx = g_ForgeWindow->getInsertionPoint ();
+	g_CurrentFile->insertObj (idx, obj);
 	History::addEntry (new AddHistory ({idx}, {obj->clone ()}));
 	g_ForgeWindow->refresh ();
 }
\ No newline at end of file

mercurial