Skip to content

Commit 06a1f80

Browse files
committed
Add optional helix pitch constraint.
1 parent f6bb0a2 commit 06a1f80

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

src/group.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,12 @@ void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
813813
AddEq(l, (EC(axis.z))->Minus(EP(6)), 5);
814814
#undef EC
815815
#undef EP
816+
if(type == Type::HELIX) {
817+
if(valB != 0.0) {
818+
AddEq(l, Expr::From(h.param(7))->Times(Expr::From(PI))->
819+
Minus(Expr::From(h.param(3))->Times(Expr::From(valB))), 6);
820+
}
821+
}
816822
} else if(type == Type::EXTRUDE) {
817823
if(predef.entityB != Entity::FREE_IN_3D) {
818824
// The extrusion path is locked along a line, normal to the

src/textscreens.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,23 @@ void TextWindow::ScreenChangeGroupScale(int link, uint32_t v) {
299299
SS.TW.edit.meaning = Edit::GROUP_SCALE;
300300
SS.TW.edit.group.v = v;
301301
}
302+
void TextWindow::ScreenChangeHelixPitch(int link, uint32_t v) {
303+
Group *g = SK.GetGroup(SS.TW.shown.group);
304+
double pitch = g->valB/SS.MmPerUnit();
305+
SS.TW.ShowEditControl(3, ssprintf("%.8f", pitch));
306+
SS.TW.edit.meaning = Edit::HELIX_PITCH;
307+
SS.TW.edit.group.v = v;
308+
}
309+
void TextWindow::ScreenChangePitchOption(int link, uint32_t v) {
310+
Group *g = SK.GetGroup(SS.TW.shown.group);
311+
if(g->valB == 0.0) {
312+
g->valB = SK.GetParam(g->h.param(7))->val * PI /
313+
(SK.GetParam(g->h.param(3))->val);
314+
} else {
315+
g->valB = 0.0;
316+
}
317+
SS.GW.Invalidate();
318+
}
302319
void TextWindow::ScreenDeleteGroup(int link, uint32_t v) {
303320
SS.UndoRemember();
304321

@@ -398,6 +415,26 @@ void TextWindow::ShowGroupInfo() {
398415
}
399416
Printf(false, "");
400417

418+
if(g->type == Group::Type::HELIX) {
419+
Printf(false, "%Ft pitch - length per turn%E");
420+
421+
if (fabs(g->valB) != 0.0) {
422+
Printf(false, " %Ba %# %Fl%Ll%f%D[change]%E",
423+
g->valB / SS.MmPerUnit(),
424+
&TextWindow::ScreenChangeHelixPitch, g->h.v);
425+
} else {
426+
Printf(false, " %Ba %# %E",
427+
SK.GetParam(g->h.param(7))->val * PI /
428+
( (SK.GetParam(g->h.param(3))->val) * SS.MmPerUnit() ),
429+
&TextWindow::ScreenChangeHelixPitch, g->h.v);
430+
}
431+
Printf(false, " %Fd%f%LP%s fixed",
432+
&TextWindow::ScreenChangePitchOption,
433+
g->valB != 0 ? CHECK_TRUE : CHECK_FALSE);
434+
435+
Printf(false, ""); // blank line
436+
}
437+
401438
if(g->type == Group::Type::EXTRUDE || g->type == Group::Type::LATHE ||
402439
g->type == Group::Type::REVOLVE || g->type == Group::Type::LINKED ||
403440
g->type == Group::Type::HELIX) {
@@ -789,6 +826,15 @@ void TextWindow::EditControlDone(std::string s) {
789826
}
790827
break;
791828

829+
case Edit::HELIX_PITCH: // stored in valB
830+
if(Expr *e = Expr::From(s, /*popUpError=*/true)) {
831+
double ev = e->Eval();
832+
Group *g = SK.GetGroup(edit.group);
833+
g->valB = ev * SS.MmPerUnit();
834+
SS.MarkGroupDirty(g->h);
835+
}
836+
break;
837+
792838
case Edit::GROUP_COLOR: {
793839
Vector rgb;
794840
if(sscanf(s.c_str(), "%lf, %lf, %lf", &rgb.x, &rgb.y, &rgb.z)==3) {

src/ui.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,9 @@ class TextWindow {
342342
VIEW_PROJ_RIGHT = 702,
343343
VIEW_PROJ_UP = 703,
344344
// For tangent arc
345-
TANGENT_ARC_RADIUS = 800
345+
TANGENT_ARC_RADIUS = 800,
346+
// For helix pitch
347+
HELIX_PITCH = 802
346348
};
347349
struct {
348350
bool showAgain;
@@ -473,6 +475,8 @@ class TextWindow {
473475
static void ScreenChangeExprA(int link, uint32_t v);
474476
static void ScreenChangeGroupName(int link, uint32_t v);
475477
static void ScreenChangeGroupScale(int link, uint32_t v);
478+
static void ScreenChangeHelixPitch(int link, uint32_t v);
479+
static void ScreenChangePitchOption(int link, uint32_t v);
476480
static void ScreenChangeLightDirection(int link, uint32_t v);
477481
static void ScreenChangeLightIntensity(int link, uint32_t v);
478482
static void ScreenChangeLightAmbient(int link, uint32_t v);

0 commit comments

Comments
 (0)