added support for inverting circular primitives

Tue, 19 Jun 2018 23:18:58 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Tue, 19 Jun 2018 23:18:58 +0300
changeset 1412
f5eb947a2e7f
parent 1411
b48f3fd2664b
child 1413
6b0ca41c158f

added support for inverting circular primitives

src/algorithms/invert.cpp file | annotate | diff | comparison | revisions
src/dialogs/circularprimitiveeditor.cpp file | annotate | diff | comparison | revisions
src/dialogs/circularprimitiveeditor.ui file | annotate | diff | comparison | revisions
src/linetypes/circularprimitive.cpp file | annotate | diff | comparison | revisions
src/linetypes/circularprimitive.h file | annotate | diff | comparison | revisions
--- a/src/algorithms/invert.cpp	Tue Jun 19 22:45:10 2018 +0300
+++ b/src/algorithms/invert.cpp	Tue Jun 19 23:18:58 2018 +0300
@@ -17,6 +17,7 @@
  */
 
 #include "../linetypes/modelobject.h"
+#include "../linetypes/circularprimitive.h"
 #include "../lddocument.h"
 #include "../glShared.h"
 
@@ -128,6 +129,15 @@
 			reference->setInverted(not reference->isInverted());
 		}
 	}
+	else if (obj->type() == LDObjectType::CircularPrimitive)
+	{
+		auto primitive = static_cast<LDCircularPrimitive*>(obj);
+
+		if (primitive->isFlat())
+			primitive->setTransformationMatrix(primitive->transformationMatrix() * ::flipmatrix(Y));
+		else
+			primitive->setInverted(not primitive->isInverted());
+	}
 }
 
 /*
--- a/src/dialogs/circularprimitiveeditor.cpp	Tue Jun 19 22:45:10 2018 +0300
+++ b/src/dialogs/circularprimitiveeditor.cpp	Tue Jun 19 23:18:58 2018 +0300
@@ -120,6 +120,11 @@
 				this->primitive->setTransformationMatrix(newMatrix);
 		}
 	);
+	connect(ui.inverted, &QCheckBox::clicked, [&](bool checked)
+	{
+		if (this->primitive)
+			this->primitive->setInverted(checked);
+	});
 	// Connect the reset button, "reset button" here meaning any button with the reset role.
 	connect(
 		ui.buttonBox,
@@ -176,6 +181,7 @@
 		});
 		withSignalsBlocked(ui.color, [&](){ ui.color->setColor(primitive->color()); });
 		withSignalsBlocked(ui.matrix, [&](){ ui.matrix->setMatrix(primitive->transformationMatrix()); });
+		withSignalsBlocked(ui.inverted, [&](){ ui.inverted->setChecked(primitive->isInverted()); });
 	}
 }
 
--- a/src/dialogs/circularprimitiveeditor.ui	Tue Jun 19 22:45:10 2018 +0300
+++ b/src/dialogs/circularprimitiveeditor.ui	Tue Jun 19 23:18:58 2018 +0300
@@ -66,6 +66,13 @@
        </property>
       </widget>
      </item>
+     <item row="3" column="1">
+      <widget class="QCheckBox" name="inverted">
+       <property name="text">
+        <string>Inverted</string>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>
--- a/src/linetypes/circularprimitive.cpp	Tue Jun 19 22:45:10 2018 +0300
+++ b/src/linetypes/circularprimitive.cpp	Tue Jun 19 23:18:58 2018 +0300
@@ -68,6 +68,20 @@
 	return true;
 }
 
+bool LDCircularPrimitive::isFlat() const
+{
+	switch (m_type)
+	{
+	case PrimitiveModel::Cylinder:
+	case PrimitiveModel::CylinderClosed:
+	case PrimitiveModel::CylinderOpen:
+		return false;
+
+	default:
+		return true;
+	}
+}
+
 void LDCircularPrimitive::rasterize(
 	DocumentManager* context,
 	Winding /* parentWinding */,
--- a/src/linetypes/circularprimitive.h	Tue Jun 19 22:45:10 2018 +0300
+++ b/src/linetypes/circularprimitive.h	Tue Jun 19 23:18:58 2018 +0300
@@ -19,6 +19,7 @@
 	QString asText() const override;
 	void getVertices(DocumentManager *context, QSet<Vertex>& verts) const override;
 	bool isRasterizable() const override;
+	bool isFlat() const;
 	void rasterize(
 		DocumentManager* context,
 		Winding parentWinding,

mercurial