Added demote function for making conditional lines normal lines

Sat, 18 May 2013 21:35:55 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 18 May 2013 21:35:55 +0300
changeset 214
28e0b37156be
parent 213
a4113545242c
child 215
eab460199114

Added demote function for making conditional lines normal lines

src/configDialog.cpp file | annotate | diff | comparison | revisions
src/extprogs.cpp file | annotate | diff | comparison | revisions
src/file.cpp file | annotate | diff | comparison | revisions
src/gui.cpp file | annotate | diff | comparison | revisions
src/gui_editactions.cpp file | annotate | diff | comparison | revisions
src/ldtypes.cpp file | annotate | diff | comparison | revisions
src/ldtypes.h file | annotate | diff | comparison | revisions
--- a/src/configDialog.cpp	Fri May 17 11:53:28 2013 +0300
+++ b/src/configDialog.cpp	Sat May 18 21:35:55 2013 +0300
@@ -129,7 +129,7 @@
 		"not set, edge lines take their color as defined in LDConfig.ldr");
 	cb_blackEdges->setChecked (gl_blackedges);
 	
-	cb_schemanticInline = new QCheckBox ("Schemantic insertion only");
+	cb_schemanticInline = new QCheckBox ("Scemantic insertion only");
 	cb_schemanticInline->setChecked (edit_schemanticinline);
 	cb_colorBFC->setWhatsThis ("When inserting objects through inlining, file "
 		"inserting or through external programs, all non-schemantics (those without "
--- a/src/extprogs.cpp	Fri May 17 11:53:28 2013 +0300
+++ b/src/extprogs.cpp	Sat May 18 21:35:55 2013 +0300
@@ -231,7 +231,7 @@
 	// Insert the new objects
 	g_win->sel ().clear ();
 	for (LDObject* obj : objs) {
-		if (!obj->isSchemantic ()) {
+		if (!obj->isScemantic ()) {
 			delete obj;
 			continue;
 		}
--- a/src/file.cpp	Fri May 17 11:53:28 2013 +0300
+++ b/src/file.cpp	Sat May 18 21:35:55 2013 +0300
@@ -128,6 +128,7 @@
 		if (lastpos > 0) {
 			str dirname = g_curfile->m_filename.substr (0, lastpos);
 			str partpath = fmt ("%s" DIRSLASH "%s", dirname.c (), relpath.c ());
+			printf ("try %s\n", partpath.c ());
 			FILE* fp = fopen (partpath, "r");
 			
 			if (fp != null)
@@ -135,7 +136,8 @@
 		}
 	}
 	
-	FILE* fp = fopen (relpath.chars (), "r");
+	printf ("try %s\n", relpath.chars ());
+	FILE* fp = fopen (relpath, "r");
 	str fullPath;
 	
 	if (fp != null)
@@ -144,21 +146,18 @@
 	if (~io_ldpath.value) {
 		// Try with just the LDraw path first
 		fullPath = fmt ("%s" DIRSLASH "%s", io_ldpath.value.chars(), relpath.chars());
+		printf ("try %s\n", fullPath.chars ());
 		
 		fp = fopen (fullPath, "r");
 		if (fp != null)
 			return fp;
 		
 		if (subdirs) {
-			char const* saSubdirectories[] = {
-				"parts",
-				"p",
-			};
-			
-			for (char const* sSubdir : saSubdirectories) {
+			for (auto subdir : initlist<const char*> ({"parts", "p"})) {
 				fullPath = fmt ("%s" DIRSLASH "%s" DIRSLASH "%s",
-					io_ldpath.value.chars(), sSubdir, relpath.chars());
+					io_ldpath.value.chars(), subdir, relpath.chars());
 				
+				printf ("try %s\n", fullPath.chars ());
 				fp = fopen (fullPath.chars (), "r");
 				
 				if (fp)
--- a/src/gui.cpp	Fri May 17 11:53:28 2013 +0300
+++ b/src/gui.cpp	Sat May 18 21:35:55 2013 +0300
@@ -226,6 +226,7 @@
 	addMenuAction ("visibility");			// Toggle Visibility
 	addMenuAction ("replaceCoords");		// Replace Coordinates
 	addMenuAction ("flip");				// Flip
+	addMenuAction ("demote");				// Demote Conditional Lines
 	
 	// Move menu
 	initMenu ("&Move");
--- a/src/gui_editactions.cpp	Fri May 17 11:53:28 2013 +0300
+++ b/src/gui_editactions.cpp	Sat May 18 21:35:55 2013 +0300
@@ -759,4 +759,25 @@
 	
 	History::addEntry (history);
 	g_win->fullRefresh ();
+}
+
+MAKE_ACTION (demote, "Demote conditional lines", "demote", "Demote conditional lines down to normal lines.", (0)) {
+	EditHistory* history = new EditHistory;
+	
+	vector<LDObject*> sel = g_win->sel ();
+	for (LDObject* obj : sel) {
+		if (obj->getType () != LDObject::CondLine)
+			continue;
+		
+		ulong idx = obj->getIndex (g_curfile);
+		LDObject* cache = obj->clone ();
+		LDLine* repl = static_cast<LDCondLine*> (obj)->demote ();
+		
+		history->addEntry (cache, repl, idx);
+		g_win->R ()->compileObject (repl);
+		delete cache;
+	}
+	
+	History::addEntry (history);
+	g_win->refresh ();
 }
\ No newline at end of file
--- a/src/ldtypes.cpp	Fri May 17 11:53:28 2013 +0300
+++ b/src/ldtypes.cpp	Sat May 18 21:35:55 2013 +0300
@@ -182,10 +182,13 @@
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
 void LDObject::replace (LDObject* replacement) {
-	// Replace all instances of the old object with the new object
-	for (LDObject*& obj : g_curfile->m_objs)
-		if (obj == this)
+	// Replace the instance of the old object with the new object
+	for (LDObject*& obj : g_curfile->m_objs) {
+		if (obj == this) {
 			obj = replacement;
+			break;
+		}
+	}
 	
 	// Remove the old object
 	delete this;
@@ -793,4 +796,14 @@
 	return invertLine (this);
 }
 
-HistoryEntry* LDVertex::invert () { return null; }
\ No newline at end of file
+HistoryEntry* LDVertex::invert () { return null; }
+
+// =============================================================================
+LDLine* LDCondLine::demote () {
+	LDLine* repl = new LDLine;
+	memcpy (repl->coords, coords, sizeof coords);
+	repl->color = color;
+	
+	replace (repl);
+	return repl;
+}
\ No newline at end of file
--- a/src/ldtypes.h	Fri May 17 11:53:28 2013 +0300
+++ b/src/ldtypes.h	Sat May 18 21:35:55 2013 +0300
@@ -42,9 +42,9 @@
 #define LDOBJ_COLORED LDOBJ_SETCOLORED (true)
 #define LDOBJ_UNCOLORED LDOBJ_SETCOLORED (false)
 
-#define LDOBJ_CUSTOM_SCHEMANTIC virtual bool isSchemantic () const
-#define LDOBJ_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return true; }
-#define LDOBJ_NON_SCHEMANTIC LDOBJ_CUSTOM_SCHEMANTIC { return false; }
+#define LDOBJ_CUSTOM_SCEMANTIC virtual bool isScemantic () const
+#define LDOBJ_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return true; }
+#define LDOBJ_NON_SCEMANTIC LDOBJ_CUSTOM_SCEMANTIC { return false; }
 
 #define LDOBJ_SETMATRIX(V) virtual bool hasMatrix () const { return V; }
 #define LDOBJ_HAS_MATRIX LDOBJ_SETMATRIX (true)
@@ -149,7 +149,7 @@
 	virtual bool isColored () const { return false; }
 	
 	// Does this object have meaning in the part model?
-	virtual bool isSchemantic () const { return false; }
+	virtual bool isScemantic () const { return false; }
 	
 	// Returns a sample object by the given value
 	static LDObject* getDefault (const LDObject::Type type);
@@ -187,7 +187,7 @@
 	LDOBJ (Gibberish)
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_NO_MATRIX
 	
 	LDGibberish (str _zContent, str _zReason);
@@ -209,7 +209,7 @@
 	LDOBJ (Empty)
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
-	LDOBJ_NON_SCHEMANTIC
+	LDOBJ_NON_SCEMANTIC
 	LDOBJ_NO_MATRIX
 };
 
@@ -224,7 +224,7 @@
 	LDOBJ (Comment)
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
-	LDOBJ_NON_SCHEMANTIC
+	LDOBJ_NON_SCEMANTIC
 	LDOBJ_NO_MATRIX
 	
 	LDComment (str text) : text (text) {}
@@ -245,7 +245,7 @@
 	LDOBJ (BFC)
 	LDOBJ_VERTICES (0)
 	LDOBJ_UNCOLORED
-	LDOBJ_CUSTOM_SCHEMANTIC { return (type == InvertNext); }
+	LDOBJ_CUSTOM_SCEMANTIC { return (type == InvertNext); }
 	LDOBJ_NO_MATRIX
 	
 	LDBFC (const LDBFC::Type type) : type (type) {}
@@ -266,7 +266,7 @@
 	LDOBJ (Subfile)
 	LDOBJ_VERTICES (0)
 	LDOBJ_COLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_HAS_MATRIX
 	
 	str fileName; // Filename of the subpart (TODO: rid this too - use fileInfo->fileName instead)
@@ -289,7 +289,7 @@
 	LDOBJ (Line)
 	LDOBJ_VERTICES (2)
 	LDOBJ_COLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_NO_MATRIX
 	
 	LDLine (vertex v1, vertex v2);
@@ -306,8 +306,10 @@
 	LDOBJ (CondLine)
 	LDOBJ_VERTICES (4)
 	LDOBJ_COLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_NO_MATRIX
+	
+	LDLine* demote ();
 };
 
 // =============================================================================
@@ -322,7 +324,7 @@
 	LDOBJ (Triangle)
 	LDOBJ_VERTICES (3)
 	LDOBJ_COLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_NO_MATRIX
 	
 	LDTriangle (vertex _v0, vertex _v1, vertex _v2) {
@@ -343,7 +345,7 @@
 	LDOBJ (Quad)
 	LDOBJ_VERTICES (4)
 	LDOBJ_COLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_NO_MATRIX
 	
 	// Split this quad into two triangles (note: heap-allocated)
@@ -363,7 +365,7 @@
 	LDOBJ (Vertex)
 	LDOBJ_VERTICES (0) // TODO: move pos to vaCoords[0]
 	LDOBJ_COLORED
-	LDOBJ_NON_SCHEMANTIC
+	LDOBJ_NON_SCEMANTIC
 	LDOBJ_NO_MATRIX
 	
 	vertex pos;
@@ -393,7 +395,7 @@
 	LDOBJ (Radial)
 	LDOBJ_VERTICES (0)
 	LDOBJ_COLORED
-	LDOBJ_SCHEMANTIC
+	LDOBJ_SCEMANTIC
 	LDOBJ_HAS_MATRIX
 	
 	LDRadial::Type radType;

mercurial