diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b6f0db..49ba5b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -46,7 +46,7 @@ New export/import features: exported. This format allows to easily hack on triangle mesh data created in SolveSpace, supports colour information and is more space efficient than most other formats. - * Export 2d section: custom styled entities that lie in the same + * Export 2d section: custom styled entities that lie in the same plane as the exported section are included. New rendering features: @@ -68,6 +68,7 @@ New measurement/analysis features: Other new features: * New command-line interface, for batch exporting and more. * The graphical interface now supports HiDPI screens on every OS. + * New option to lock Z axis to be always vertical, like in SketchUp. * New link to match the on-screen size of the sketch with its actual size, "view → set to full scale". * When zooming to fit, constraints are also considered. diff --git a/src/confscreen.cpp b/src/confscreen.cpp index c7e193c..df5a95d 100644 --- a/src/confscreen.cpp +++ b/src/confscreen.cpp @@ -83,6 +83,15 @@ void TextWindow::ScreenChangeBackFaces(int link, uint32_t v) { SS.GW.Invalidate(/*clearPersistent=*/true); } +void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) { + SS.turntableNav = !SS.turntableNav; + if(SS.turntableNav) { + // If turntable nav is being turned on, align view so Z is vertical + SS.GW.AnimateOnto(Quaternion::From(Vector::From(-1, 0, 0), Vector::From(0, 0, 1)), + SS.GW.offset); + } +} + void TextWindow::ScreenChangeShowContourAreas(int link, uint32_t v) { SS.showContourAreas = !SS.showContourAreas; SS.GW.Invalidate(); @@ -306,13 +315,14 @@ void TextWindow::ShowConfiguration() { Printf(false, " %Fd%f%Ll%s check sketch for closed contour%E", &ScreenChangeCheckClosedContour, SS.checkClosedContour ? CHECK_TRUE : CHECK_FALSE); - Printf(false, " %Fd%f%Ll%s enable automatic line constraints%E", - &ScreenChangeAutomaticLineConstraints, - SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE); Printf(false, " %Fd%f%Ll%s show areas of closed contours%E", &ScreenChangeShowContourAreas, SS.showContourAreas ? CHECK_TRUE : CHECK_FALSE); - + Printf(false, " %Fd%f%Ll%s enable automatic line constraints%E", + &ScreenChangeAutomaticLineConstraints, + SS.automaticLineConstraints ? CHECK_TRUE : CHECK_FALSE); + Printf(false, " %Fd%f%Ll%s use turntable mouse navigation%E", &ScreenChangeTurntableNav, + SS.turntableNav ? CHECK_TRUE : CHECK_FALSE); Printf(false, ""); Printf(false, "%Ft autosave interval (in minutes)%E"); Printf(false, "%Ba %d %Fl%Ll%f[change]%E", diff --git a/src/graphicswin.cpp b/src/graphicswin.cpp index f963724..13c2df3 100644 --- a/src/graphicswin.cpp +++ b/src/graphicswin.cpp @@ -427,6 +427,21 @@ void GraphicsWindow::AnimateOntoWorkplane() { Entity *w = SK.GetEntity(ActiveWorkplane()); Quaternion quatf = w->Normal()->NormalGetNum(); + + // Get Z pointing vertical, if we're on turntable nav mode: + if(SS.turntableNav) { + Vector normalRight = quatf.RotationU(); + Vector normalUp = quatf.RotationV(); + Vector normal = normalRight.Cross(normalUp); + if(normalRight.z != 0) { + double theta = atan2(normalUp.z, normalRight.z); + theta -= atan2(1, 0); + normalRight = normalRight.RotatedAbout(normal, theta); + normalUp = normalUp.RotatedAbout(normal, theta); + quatf = Quaternion::From(normalRight, normalUp); + } + } + Vector offsetf = (SK.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1); // If the view screen is open, then we need to refresh it. diff --git a/src/mouse.cpp b/src/mouse.cpp index 72d0f6b..685eaeb 100644 --- a/src/mouse.cpp +++ b/src/mouse.cpp @@ -135,8 +135,14 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown, if(!(shiftDown || ctrlDown)) { double s = 0.3*(PI/180)*scale; // degrees per pixel - projRight = orig.projRight.RotatedAbout(orig.projUp, -s*dx); - projUp = orig.projUp.RotatedAbout(orig.projRight, s*dy); + if(SS.turntableNav) { // lock the Z to vertical + projRight = orig.projRight.RotatedAbout(Vector::From(0, 0, 1), -s * dx); + projUp = orig.projUp.RotatedAbout( + Vector::From(orig.projRight.x, orig.projRight.y, orig.projRight.y), s * dy); + } else { + projRight = orig.projRight.RotatedAbout(orig.projUp, -s * dx); + projUp = orig.projUp.RotatedAbout(orig.projRight, s * dy); + } NormalizeProjectionVectors(); } else if(ctrlDown) { diff --git a/src/solvespace.cpp b/src/solvespace.cpp index 501360e..97bb384 100644 --- a/src/solvespace.cpp +++ b/src/solvespace.cpp @@ -68,6 +68,8 @@ void SolveSpaceUI::Init() { fixExportColors = settings->ThawBool("FixExportColors", true); // Draw back faces of triangles (when mesh is leaky/self-intersecting) drawBackFaces = settings->ThawBool("DrawBackFaces", true); + // Use turntable mouse navigation + turntableNav = settings->ThawBool("TurntableNav", false); // Check that contours are closed and not self-intersecting checkClosedContour = settings->ThawBool("CheckClosedContour", true); // Enable automatic constrains for lines @@ -243,6 +245,8 @@ void SolveSpaceUI::Exit() { settings->FreezeBool("ShowContourAreas", showContourAreas); // Check that contours are closed and not self-intersecting settings->FreezeBool("CheckClosedContour", checkClosedContour); + // Use turntable mouse navigation + settings->FreezeBool("TurntableNav", turntableNav); // Enable automatic constrains for lines settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints); // Export shaded triangles in a 2d view diff --git a/src/solvespace.h b/src/solvespace.h index dce1d17..46d2104 100644 --- a/src/solvespace.h +++ b/src/solvespace.h @@ -324,7 +324,7 @@ class StepFileWriter { public: void ExportSurfacesTo(const Platform::Path &filename); void WriteHeader(); - void WriteProductHeader(); + void WriteProductHeader(); int ExportCurve(SBezier *sb); int ExportCurveLoop(SBezierLoop *loop, bool inner); void ExportSurface(SSurface *ss, SBezierList *sbl); @@ -590,6 +590,7 @@ public: bool drawBackFaces; bool showContourAreas; bool checkClosedContour; + bool turntableNav; bool automaticLineConstraints; bool showToolbar; Platform::Path screenshotFile; diff --git a/src/ui.h b/src/ui.h index 4fef169..cc47938 100644 --- a/src/ui.h +++ b/src/ui.h @@ -425,6 +425,7 @@ public: static void ScreenChangeBackFaces(int link, uint32_t v); static void ScreenChangeShowContourAreas(int link, uint32_t v); static void ScreenChangeCheckClosedContour(int link, uint32_t v); + static void ScreenChangeTurntableNav(int link, uint32_t v); static void ScreenChangeAutomaticLineConstraints(int link, uint32_t v); static void ScreenChangePwlCurves(int link, uint32_t v); static void ScreenChangeCanvasSizeAuto(int link, uint32_t v);