# HG changeset patch # User Santeri Piippo # Date 1380812826 -10800 # Node ID e964085e6913c0b116d437f66ea327da5ee1f9fa # Parent 7d1b5ecd76c00e6158b26a7ab074aec0d9616192 Added a new editing mode for drawing circles. diff -r 7d1b5ecd76c0 -r e964085e6913 changelog.txt --- a/changelog.txt Sun Sep 22 23:27:07 2013 +0300 +++ b/changelog.txt Thu Oct 03 18:07:06 2013 +0300 @@ -9,6 +9,7 @@ - Converted the configuration code to use QSettings, in practice this means the configuration file moved to the registry under Windows and into ~/.config/LDForge under Linux. Unfortunately this means settings get lost during transition from version 0.2 and 0.3. +- Added a new editing mode for drawing circles. - Corrections to the primitive generator: - Fixed: "Hi-Res" was not prepended to the names of 48/ primitives. - Fixed: Checking the Hi-Res option would not allow segment values over 16. diff -r 7d1b5ecd76c0 -r e964085e6913 icons/mode-circle.png Binary file icons/mode-circle.png has changed diff -r 7d1b5ecd76c0 -r e964085e6913 ldforge.qrc --- a/ldforge.qrc Sun Sep 22 23:27:07 2013 +0300 +++ b/ldforge.qrc Thu Oct 03 18:07:06 2013 +0300 @@ -66,6 +66,7 @@ ./icons/line.png ./icons/mail.png ./icons/make-borders.png + ./icons/mode-circle.png ./icons/mode-draw.png ./icons/mode-select.png ./icons/move-x-neg.png diff -r 7d1b5ecd76c0 -r e964085e6913 src/actions.h --- a/src/actions.h Sun Sep 22 23:27:07 2013 +0300 +++ b/src/actions.h Thu Oct 03 18:07:06 2013 +0300 @@ -58,6 +58,7 @@ act (SelectByType) act (ModeDraw) act (ModeSelect) +act (ModeCircle) act (SetDrawDepth) act (SetColor) act (Autocolor) diff -r 7d1b5ecd76c0 -r e964085e6913 src/gldraw.cpp --- a/src/gldraw.cpp Sun Sep 22 23:27:07 2013 +0300 +++ b/src/gldraw.cpp Thu Oct 03 18:07:06 2013 +0300 @@ -50,6 +50,12 @@ {{ 0, -1, 0 }, Z, Y, false, true }, }; +static const matrix g_circleDrawTransforms[3] = { + { 2, 0, 0, 0, 1, 0, 0, 0, 2 }, + { 2, 0, 0, 0, 0, 2, 0, 1, 0 }, + { 0, 1, 0, 2, 0, 0, 0, 0, 2 }, +}; + cfg (String, gl_bgcolor, "#CCCCD9"); cfg (String, gl_maincolor, "#707078"); cfg (Float, gl_maincolor_alpha, 1.0); @@ -532,7 +538,6 @@ // If we're drawing, draw the vertices onto the screen. if (editMode() == Draw) { - const short blipsize = 8; int numverts = 4; if (!m_rectdraw) @@ -579,21 +584,49 @@ paint.drawPolygon (poly, numverts); // Draw vertex blips - pen = m_thinBorderPen; - pen.setWidth (1); - paint.setPen (pen); - paint.setBrush (QColor (64, 192, 0)); - - for (ushort i = 0; i < numverts; ++i) { + for (int i = 0; i < numverts; ++i) { QPoint& blip = poly[i]; - paint.drawEllipse (blip.x() - blipsize / 2, blip.y() - blipsize / 2, - blipsize, blipsize); - + drawBlip (paint, blip); + // Draw their coordinates paint.drawText (blip.x(), blip.y() - 8, polyverts[i].stringRep (true)); } } } + elif (editMode() == CircleMode) + { // If we have not specified the center point of the circle yet, preview it on the screen. + if (m_drawedVerts.size() == 0) + drawBlip (paint, coordconv3_2 (m_hoverpos)); + else + { QVector verts; + const double dist = circleDrawDist(); + const int segs = lores; + const double angleUnit = (2 * pi) / segs; + Axis relX, relY; + getRelativeAxes (relX, relY); + + for (int i = 0; i < segs; ++i) + { vertex v = g_origin; + v[relX] = m_drawedVerts[0][relX] + (cos (i * angleUnit) * dist); + v[relY] = m_drawedVerts[0][relY] + (sin (i * angleUnit) * dist); + verts << v; + } + + QVector points; + for (const vertex& v : verts) + { QPoint point = coordconv3_2 (v); + drawBlip (paint, point); + points << point; + } + + QPen pen = m_thinBorderPen; + pen.setWidth (2); + pen.setColor (luma (m_bgcolor) < 40 ? Qt::white : Qt::black); + paint.setPen (pen); + paint.setBrush (Qt::NoBrush); + paint.drawPolygon (QPolygon (points)); + } + } } // Camera icons @@ -668,6 +701,17 @@ // ============================================================================= // ----------------------------------------------------------------------------- +void GLRenderer::drawBlip (QPainter& paint, QPoint pos) const +{ QPen pen = m_thinBorderPen; + const int blipsize = 8; + pen.setWidth (1); + paint.setPen (pen); + paint.setBrush (QColor (64, 192, 0)); + paint.drawEllipse (pos.x() - blipsize / 2, pos.y() - blipsize / 2, blipsize, blipsize); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- QColor GLRenderer::getTextPen () const { return m_darkbg ? Qt::white : Qt::black; } @@ -855,7 +899,16 @@ addDrawnVertex (m_hoverpos); break; - + + case CircleMode: + if (m_drawedVerts.size() == 2) + { endDraw (true); + return; + } + + addDrawnVertex (m_hoverpos); + break; + case Select: if (!drawOnly()) { if (m_totalmove < 10) @@ -898,7 +951,7 @@ closest = pos3d; valid = true; - /* If it's only 4 pixels away, I think we found our vertex now. */ + // If it's only 4 pixels away, I think we found our vertex now. if (distsq <= 16.0f) // 4.0f ** 2 break; } @@ -1175,6 +1228,7 @@ break; case Draw: + case CircleMode: // Cannot draw into the free camera - use top instead. if (m_camera == Free) setCamera (Top); @@ -1222,46 +1276,75 @@ // Clean the selection and create the object List& verts = m_drawedVerts; LDObject* obj = null; - - if (m_rectdraw) { - LDQuad* quad = new LDQuad; - - // Copy the vertices from m_rectverts - updateRectVerts(); - - for (int i = 0; i < quad->vertices(); ++i) - quad->setVertex (i, m_rectverts[i]); - - quad->setColor (maincolor); - obj = quad; - } else { - switch (verts.size()) { - case 1: - // 1 vertex - add a vertex object - obj = new LDVertex; - static_cast (obj)->pos = verts[0]; - obj->setColor (maincolor); - break; - - case 2: - // 2 verts - make a line - obj = new LDLine (verts[0], verts[1]); - obj->setColor (edgecolor); - break; + + switch (editMode()) + { case Draw: + if (m_rectdraw) { + LDQuad* quad = new LDQuad; + + // Copy the vertices from m_rectverts + updateRectVerts(); + + for (int i = 0; i < quad->vertices(); ++i) + quad->setVertex (i, m_rectverts[i]); + + quad->setColor (maincolor); + obj = quad; + } else { + switch (verts.size()) { + case 1: + // 1 vertex - add a vertex object + obj = new LDVertex; + static_cast (obj)->pos = verts[0]; + obj->setColor (maincolor); + break; - case 3: - case 4: - obj = (verts.size() == 3) ? - static_cast (new LDTriangle) : - static_cast (new LDQuad); - - obj->setColor (maincolor); - for (ushort i = 0; i < obj->vertices(); ++i) - obj->setVertex (i, verts[i]); - break; + case 2: + // 2 verts - make a line + obj = new LDLine (verts[0], verts[1]); + obj->setColor (edgecolor); + break; + + case 3: + case 4: + obj = (verts.size() == 3) ? + static_cast (new LDTriangle) : + static_cast (new LDQuad); + + obj->setColor (maincolor); + for (ushort i = 0; i < obj->vertices(); ++i) + obj->setVertex (i, verts[i]); + break; + } } + break; + + case CircleMode: + { const staticCameraMeta* cam = &g_staticCameras[m_camera]; + const double dist = circleDrawDist(); + + matrix transform = g_circleDrawTransforms[camera() % 3]; + for (int i = 0; i < 9; ++i) + { if (transform[i] == 2) + transform[i] = dist; + elif (transform[i] == 1 && camera() >= 3) + transform[i] = -1; + } + + LDSubfile* ref = new LDSubfile; + ref->setFileInfo (findLoadedFile ("4-4edge.dat")); + ref->setTransform (transform); + ref->setPosition (m_drawedVerts[0]); + ref->setColor (maincolor); + obj = ref; + } + break; + + case Select: + assert (false); + return; } - + if (obj) { g_win->beginAction (null); file()->addObject (obj); @@ -1276,6 +1359,27 @@ // ============================================================================= // ----------------------------------------------------------------------------- +double GLRenderer::circleDrawDist() const +{ assert (m_drawedVerts.size() >= 1); + const vertex& v1 = (m_drawedVerts.size() == 2) ? m_drawedVerts[1] : m_hoverpos; + Axis relX, relY; + getRelativeAxes (relX, relY); + + const double dx = m_drawedVerts[0][relX] - v1[relX]; + const double dy = m_drawedVerts[0][relY] - v1[relY]; + return sqrt ((dx * dx) + (dy * dy)); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- +void GLRenderer::getRelativeAxes (Axis& relX, Axis& relY) const +{ const staticCameraMeta* cam = &g_staticCameras[m_camera]; + relX = cam->axisX; + relY = cam->axisY; +} + +// ============================================================================= +// ----------------------------------------------------------------------------- static List getVertices (LDObject* obj) { List verts; diff -r 7d1b5ecd76c0 -r e964085e6913 src/gldraw.h --- a/src/gldraw.h Sun Sep 22 23:27:07 2013 +0300 +++ b/src/gldraw.h Thu Oct 03 18:07:06 2013 +0300 @@ -34,7 +34,8 @@ enum EditMode { Select, - Draw + Draw, + CircleMode, }; // Meta for overlays @@ -150,12 +151,16 @@ void compileVertex (const vertex& vrt); // Compile a single vertex to a list vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point - LDOverlay* findOverlayObject (Camera cam); + LDOverlay* findOverlayObject (Camera cam); void updateRectVerts(); void pick (uint mouseX, uint mouseY); // Perform object selection void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list QColor getTextPen() const; // Determine which color to draw text with - + void getRelativeAxes (Axis& relX, Axis& relY) const; + + void drawBlip (QPainter& paint, QPoint pos) const; + double circleDrawDist() const; + private slots: void slot_toolTipTimer(); }; diff -r 7d1b5ecd76c0 -r e964085e6913 src/gui.cpp --- a/src/gui.cpp Sun Sep 22 23:27:07 2013 +0300 +++ b/src/gui.cpp Thu Oct 03 18:07:06 2013 +0300 @@ -64,11 +64,6 @@ #define act(N) extern_cfg (KeySequence, key_##N); #include "actions.h" -const char* g_modeActionNames[] = { - "modeSelect", - "modeDraw", -}; - // ============================================================================= // ----------------------------------------------------------------------------- ForgeWindow::ForgeWindow() { @@ -606,6 +601,7 @@ contextMenu->addAction (ACTION (ClearOverlay)); contextMenu->addAction (ACTION (ModeSelect)); contextMenu->addAction (ACTION (ModeDraw)); + contextMenu->addAction (ACTION (ModeCircle)); if (R()->camera() != GL::Free) { contextMenu->addSeparator(); @@ -644,6 +640,7 @@ const EditMode mode = R()->editMode(); ACTION (ModeSelect)->setChecked (mode == Select); ACTION (ModeDraw)->setChecked (mode == Draw); + ACTION (ModeCircle)->setChecked (mode == CircleMode); } // ============================================================================= diff -r 7d1b5ecd76c0 -r e964085e6913 src/gui_actions.cpp --- a/src/gui_actions.cpp Sun Sep 22 23:27:07 2013 +0300 +++ b/src/gui_actions.cpp Thu Oct 03 18:07:06 2013 +0300 @@ -520,6 +520,12 @@ // ============================================================================= // ----------------------------------------------------------------------------- +DEFINE_ACTION (ModeCircle, CTRL (3)) +{ g_win->R()->setEditMode (CircleMode); +} + +// ============================================================================= +// ----------------------------------------------------------------------------- DEFINE_ACTION (SetDrawDepth, 0) { if (g_win->R()->camera() == GL::Free) return; diff -r 7d1b5ecd76c0 -r e964085e6913 ui/ldforge.ui --- a/ui/ldforge.ui Sun Sep 22 23:27:07 2013 +0300 +++ b/ui/ldforge.ui Thu Oct 03 18:07:06 2013 +0300 @@ -14,7 +14,7 @@ - + :/icons/ldforge.png:/icons/ldforge.png @@ -70,7 +70,7 @@ 0 0 900 - 22 + 26 @@ -82,7 +82,7 @@ Open Recent... - + :/icons/open-recent.png:/icons/open-recent.png @@ -395,6 +395,7 @@ + @@ -409,7 +410,7 @@ - + :/icons/brick.png:/icons/brick.png @@ -424,7 +425,7 @@ - + :/icons/file-open.png:/icons/file-open.png @@ -439,7 +440,7 @@ - + :/icons/file-save.png:/icons/file-save.png @@ -454,7 +455,7 @@ - + :/icons/file-save-as.png:/icons/file-save-as.png @@ -466,7 +467,7 @@ - + :/icons/file-import.png:/icons/file-import.png @@ -475,7 +476,7 @@ - + :/icons/file-export.png:/icons/file-export.png @@ -484,7 +485,7 @@ - + :/icons/settings.png:/icons/settings.png @@ -499,7 +500,7 @@ - + :/icons/settings.png:/icons/settings.png @@ -511,7 +512,7 @@ - + :/icons/radial.png:/icons/radial.png @@ -523,7 +524,7 @@ - + :/icons/exit.png:/icons/exit.png @@ -546,7 +547,7 @@ true - + :/icons/axes.png:/icons/axes.png @@ -558,7 +559,7 @@ true - + :/icons/wireframe.png:/icons/wireframe.png @@ -570,7 +571,7 @@ true - + :/icons/bfc-view.png:/icons/bfc-view.png @@ -579,7 +580,7 @@ - + :/icons/overlay.png:/icons/overlay.png @@ -588,7 +589,7 @@ - + :/icons/overlay-clear.png:/icons/overlay-clear.png @@ -597,7 +598,7 @@ - + :/icons/screencap.png:/icons/screencap.png @@ -611,7 +612,7 @@ - + :/icons/add-line.png:/icons/add-line.png @@ -620,7 +621,7 @@ - + :/icons/add-subfile.png:/icons/add-subfile.png @@ -629,7 +630,7 @@ - + :/icons/add-triangle.png:/icons/add-triangle.png @@ -638,7 +639,7 @@ - + :/icons/add-quad.png:/icons/add-quad.png @@ -647,7 +648,7 @@ - + :/icons/add-condline.png:/icons/add-condline.png @@ -656,7 +657,7 @@ - + :/icons/add-comment.png:/icons/add-comment.png @@ -665,7 +666,7 @@ - + :/icons/add-bfc.png:/icons/add-bfc.png @@ -674,7 +675,7 @@ - + :/icons/add-vertex.png:/icons/add-vertex.png @@ -683,7 +684,7 @@ - + :/icons/undo.png:/icons/undo.png @@ -695,7 +696,7 @@ - + :/icons/redo.png:/icons/redo.png @@ -707,7 +708,7 @@ - + :/icons/cut.png:/icons/cut.png @@ -719,7 +720,7 @@ - + :/icons/copy.png:/icons/copy.png @@ -734,7 +735,7 @@ - + :/icons/paste.png:/icons/paste.png @@ -746,7 +747,7 @@ - + :/icons/delete.png:/icons/delete.png @@ -758,7 +759,7 @@ - + :/icons/select-all.png:/icons/select-all.png @@ -767,7 +768,7 @@ - + :/icons/select-color.png:/icons/select-color.png @@ -776,7 +777,7 @@ - + :/icons/select-type.png:/icons/select-type.png @@ -791,7 +792,7 @@ true - + :/icons/mode-select.png:/icons/mode-select.png @@ -803,7 +804,7 @@ true - + :/icons/mode-draw.png:/icons/mode-draw.png @@ -817,7 +818,7 @@ - + :/icons/palette.png:/icons/palette.png @@ -829,7 +830,7 @@ - + :/icons/autocolor.png:/icons/autocolor.png @@ -841,7 +842,7 @@ - + :/icons/uncolorize.png:/icons/uncolorize.png @@ -853,7 +854,7 @@ - + :/icons/inline.png:/icons/inline.png @@ -865,7 +866,7 @@ - + :/icons/inline-deep.png:/icons/inline-deep.png @@ -877,7 +878,7 @@ - + :/icons/invert.png:/icons/invert.png @@ -886,7 +887,7 @@ - + :/icons/radial.png:/icons/radial.png @@ -895,7 +896,7 @@ - + :/icons/quad-split.png:/icons/quad-split.png @@ -907,7 +908,7 @@ - + :/icons/set-contents.png:/icons/set-contents.png @@ -919,7 +920,7 @@ - + :/icons/make-borders.png:/icons/make-borders.png @@ -931,7 +932,7 @@ - + :/icons/corner-verts.png:/icons/corner-verts.png @@ -943,7 +944,7 @@ - + :/icons/round-coords.png:/icons/round-coords.png @@ -955,7 +956,7 @@ - + :/icons/visibility.png:/icons/visibility.png @@ -967,7 +968,7 @@ - + :/icons/replace-coords.png:/icons/replace-coords.png @@ -979,7 +980,7 @@ - + :/icons/flip.png:/icons/flip.png @@ -999,7 +1000,7 @@ - + :/icons/ytruder.png:/icons/ytruder.png @@ -1011,7 +1012,7 @@ - + :/icons/rectifier.png:/icons/rectifier.png @@ -1023,7 +1024,7 @@ - + :/icons/intersector.png:/icons/intersector.png @@ -1035,7 +1036,7 @@ - + :/icons/isecalc.png:/icons/isecalc.png @@ -1047,7 +1048,7 @@ - + :/icons/coverer.png:/icons/coverer.png @@ -1067,7 +1068,7 @@ false - + :/icons/help.png:/icons/help.png @@ -1076,7 +1077,7 @@ - + :/icons/ldforge.png:/icons/ldforge.png @@ -1093,7 +1094,7 @@ true - + :/icons/grid-coarse.png:/icons/grid-coarse.png @@ -1108,7 +1109,7 @@ true - + :/icons/grid-medium.png:/icons/grid-medium.png @@ -1120,7 +1121,7 @@ true - + :/icons/grid-fine.png:/icons/grid-fine.png @@ -1134,7 +1135,7 @@ - + :/icons/arrow-up.png:/icons/arrow-up.png @@ -1143,7 +1144,7 @@ - + :/icons/arrow-down.png:/icons/arrow-down.png @@ -1152,7 +1153,7 @@ - + :/icons/move-x-neg.png:/icons/move-x-neg.png @@ -1161,7 +1162,7 @@ - + :/icons/move-x-pos.png:/icons/move-x-pos.png @@ -1170,7 +1171,7 @@ - + :/icons/move-y-neg.png:/icons/move-y-neg.png @@ -1179,7 +1180,7 @@ - + :/icons/move-y-pos.png:/icons/move-y-pos.png @@ -1188,7 +1189,7 @@ - + :/icons/move-z-neg.png:/icons/move-z-neg.png @@ -1197,7 +1198,7 @@ - + :/icons/move-z-pos.png:/icons/move-z-pos.png @@ -1256,7 +1257,7 @@ - + :/icons/file-new.png:/icons/file-new.png @@ -1278,9 +1279,21 @@ Go to Line... + + + true + + + + :/icons/mode-circle.png:/icons/mode-circle.png + + + Circle Mode + + - +