Skip to content

Commit

Permalink
Add checkbox to control automatic line constraints
Browse files Browse the repository at this point in the history
Signed-off-by: Sergiusz Bazanski <q3k@q3k.org>
  • Loading branch information
q3k authored and whitequark committed Feb 11, 2019
1 parent b2418a0 commit 9e51288
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -33,6 +33,8 @@ New constraint features:
in the text window.
* When selecting an entity, the constraints applied to it can be selected
in the text window.
* It is now possible to turn off automatic creation of horizontal/vertical
constraints on line segments.

New export/import features:
* Three.js: allow configuring projection for exported model, and initially
Expand Down
8 changes: 8 additions & 0 deletions src/confscreen.cpp
Expand Up @@ -93,6 +93,11 @@ void TextWindow::ScreenChangeCheckClosedContour(int link, uint32_t v) {
SS.GW.Invalidate();
}

void TextWindow::ScreenChangeAutomaticLineConstraints(int link, uint32_t v) {
SS.automaticLineConstraints = !SS.automaticLineConstraints;
SS.GW.Invalidate();
}

void TextWindow::ScreenChangeShadedTriangles(int link, uint32_t v) {
SS.exportShadedTriangles = !SS.exportShadedTriangles;
SS.GW.Invalidate();
Expand Down Expand Up @@ -301,6 +306,9 @@ 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);
Expand Down
33 changes: 17 additions & 16 deletions src/graphicswin.cpp
Expand Up @@ -1283,26 +1283,27 @@ void GraphicsWindow::ToggleBool(bool *v) {
}

bool GraphicsWindow::SuggestLineConstraint(hRequest request, Constraint::Type *type) {
if(LockedInWorkplane()) {
Entity *ptA = SK.GetEntity(request.entity(1)),
*ptB = SK.GetEntity(request.entity(2));
if(!(LockedInWorkplane() && SS.automaticLineConstraints))
return false;

Expr *au, *av, *bu, *bv;
Entity *ptA = SK.GetEntity(request.entity(1)),
*ptB = SK.GetEntity(request.entity(2));

ptA->PointGetExprsInWorkplane(ActiveWorkplane(), &au, &av);
ptB->PointGetExprsInWorkplane(ActiveWorkplane(), &bu, &bv);
Expr *au, *av, *bu, *bv;

double du = au->Minus(bu)->Eval();
double dv = av->Minus(bv)->Eval();
ptA->PointGetExprsInWorkplane(ActiveWorkplane(), &au, &av);
ptB->PointGetExprsInWorkplane(ActiveWorkplane(), &bu, &bv);

const double TOLERANCE_RATIO = 0.02;
if(fabs(dv) > LENGTH_EPS && fabs(du / dv) < TOLERANCE_RATIO) {
*type = Constraint::Type::VERTICAL;
return true;
} else if(fabs(du) > LENGTH_EPS && fabs(dv / du) < TOLERANCE_RATIO) {
*type = Constraint::Type::HORIZONTAL;
return true;
}
double du = au->Minus(bu)->Eval();
double dv = av->Minus(bv)->Eval();

const double TOLERANCE_RATIO = 0.02;
if(fabs(dv) > LENGTH_EPS && fabs(du / dv) < TOLERANCE_RATIO) {
*type = Constraint::Type::VERTICAL;
return true;
} else if(fabs(du) > LENGTH_EPS && fabs(dv / du) < TOLERANCE_RATIO) {
*type = Constraint::Type::HORIZONTAL;
return true;
}
return false;
}
4 changes: 4 additions & 0 deletions src/solvespace.cpp
Expand Up @@ -70,6 +70,8 @@ void SolveSpaceUI::Init() {
drawBackFaces = settings->ThawBool("DrawBackFaces", true);
// Check that contours are closed and not self-intersecting
checkClosedContour = settings->ThawBool("CheckClosedContour", true);
// Enable automatic constrains for lines
automaticLineConstraints = settings->ThawBool("AutomaticLineConstraints", true);
// Draw closed polygons areas
showContourAreas = settings->ThawBool("ShowContourAreas", false);
// Export shaded triangles in a 2d view
Expand Down Expand Up @@ -241,6 +243,8 @@ void SolveSpaceUI::Exit() {
settings->FreezeBool("ShowContourAreas", showContourAreas);
// Check that contours are closed and not self-intersecting
settings->FreezeBool("CheckClosedContour", checkClosedContour);
// Enable automatic constrains for lines
settings->FreezeBool("AutomaticLineConstraints", automaticLineConstraints);
// Export shaded triangles in a 2d view
settings->FreezeBool("ExportShadedTriangles", exportShadedTriangles);
// Export pwl curves (instead of exact) always
Expand Down
1 change: 1 addition & 0 deletions src/solvespace.h
Expand Up @@ -590,6 +590,7 @@ class SolveSpaceUI {
bool drawBackFaces;
bool showContourAreas;
bool checkClosedContour;
bool automaticLineConstraints;
bool showToolbar;
Platform::Path screenshotFile;
RgbaColor backgroundColor;
Expand Down
1 change: 1 addition & 0 deletions src/ui.h
Expand Up @@ -425,6 +425,7 @@ class TextWindow {
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 ScreenChangeAutomaticLineConstraints(int link, uint32_t v);
static void ScreenChangePwlCurves(int link, uint32_t v);
static void ScreenChangeCanvasSizeAuto(int link, uint32_t v);
static void ScreenChangeCanvasSize(int link, uint32_t v);
Expand Down

0 comments on commit 9e51288

Please sign in to comment.