Start adding text window UI for showing and editing named parameters.… by phkahler · Pull Request #1489 · solvespace/solvespace · GitHub
Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/request.cpp
3 changes: 2 additions & 1 deletion src/sketch.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class Request {
CIRCLE = 400,
ARC_OF_CIRCLE = 500,
TTF_TEXT = 600,
IMAGE = 700
IMAGE = 700,
NAMED_PARAMETER = 800
};

Request::Type type;
Expand Down
91 changes: 88 additions & 3 deletions src/textscreens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,19 @@ void TextWindow::ScreenSelectConstraint(int link, uint32_t v) {
sel.constraint.v = v;
SS.GW.selection.Add(&sel);
}

void TextWindow::AddNamedParameter(int link, uint32_t v) {
hGroup hg = { v };
SS.UndoRemember();
Request r = {};
r.group = hg;
r.type = Request::Type::NAMED_PARAMETER;
r.str = "Edit_Name";
SK.request.AddAndAssignId(&r);
r.Generate(&SK.entity, &SK.param);
hParam hp = r.h.param(64);
SK.GetParam(hp)->val = 123;
SS.MarkGroupDirty(r.group);
}
void TextWindow::ScreenChangeGroupOption(int link, uint32_t v) {
SS.UndoRemember();
Group *g = SK.GetGroup(SS.TW.shown.group);
Expand Down Expand Up @@ -324,6 +336,29 @@ void TextWindow::ScreenChangePitchOption(int link, uint32_t v) {
}
SS.GW.Invalidate();
}
void TextWindow::ScreenEditParamName(int link, uint32_t v) {
hRequest hr = { v };
Request *r = SK.request.FindByIdNoOops(hr);
SS.TW.ShowEditControl(3, r->str);
SS.TW.edit.meaning = Edit::PARAMETER_NAME;
SS.TW.edit.request = hr;
}
void TextWindow::ScreenChangeParamValue(int link, uint32_t v) {
Group *g = SK.GetGroup(SS.TW.shown.group);
hParam p = { v };
double value = SK.GetParam(p)->val;
SS.TW.ShowEditControl(3, ssprintf("%.8f", value));
SS.TW.edit.meaning = Edit::PARAMETER_VALUE;
SS.TW.edit.group.v = g->h.v;
SS.TW.edit.parameter = p;
}
void TextWindow::ScreenDeleteParameter(int link, uint32_t v) {
hRequest hr = { v };
Request *r = SK.request.FindByIdNoOops(hr);
hParam p = r->h.param(64);
SK.param.RemoveById(p);
SK.request.RemoveById(hr);
}
void TextWindow::ScreenDeleteGroup(int link, uint32_t v) {
SS.UndoRemember();

Expand All @@ -344,6 +379,7 @@ void TextWindow::ScreenDeleteGroup(int link, uint32_t v) {
// group if it was removed.
SS.GW.ClearSuper();
}

void TextWindow::ShowGroupInfo() {
Group *g = SK.GetGroup(shown.group);
const char *s = "???";
Expand Down Expand Up @@ -527,14 +563,42 @@ void TextWindow::ShowGroupInfo() {
Printf(false, "'force NURBS surfaces to triangle mesh'.");
}


list_items:
Printf(false, "");
Printf(false, "%Ft parameters in group %E [%Fl%Ll%D%fadd%E]",
g->h.v, &TextWindow::AddNamedParameter);

int a = 0;
for(auto &r : SK.request) {
// filter on request type for parameters
if(r.group == shown.group && r.type == Request::Type::NAMED_PARAMETER) {
// get the name of our parameter request
std::string s = r.str;
// we need a handle to the parameter to get its value
hParam hp = r.h.param(64);
double value = SK.GetParam(hp)->val;
Printf(false,
"%Bp %Fl%Ll%D%f%s%E %# %E [%Fl%Ll%f%Dchange%E] [%Fl%Ll%D%fdel%E] ",
(a & 1) ? 'd' : 'a',
r.h.v,
&(TextWindow::ScreenEditParamName),
s.c_str(),
value,
&(TextWindow::ScreenChangeParamValue), hp,
r.h.v, &(TextWindow::ScreenDeleteParameter) );
a++;
}
}
if(a == 0) Printf(false, "%Ba (none)");

Printf(false, "");
Printf(false, "%Ft requests in group");

int a = 0;
a = 0;
for(auto &r : SK.request) {

if(r.group == shown.group) {
if(r.group == shown.group && r.type != Request::Type::NAMED_PARAMETER) {
std::string s = r.DescriptionString();
Printf(false, "%Bp %Fl%Ll%D%f%h%s%E",
(a & 1) ? 'd' : 'a',
Expand Down Expand Up @@ -847,6 +911,27 @@ void TextWindow::EditControlDone(std::string s) {
}
break;

case Edit::PARAMETER_NAME:
if(s.empty()) {
Error(_("Parameter name cannot be empty"));
} else {
SS.UndoRemember();
if(Request *r = SK.request.FindByIdNoOops(edit.request)) {
r->str = s;
SS.MarkGroupDirty(r->group);
}
}
break;

case Edit::PARAMETER_VALUE: // by handle (passed in group handle...)
if(Expr *e = Expr::From(s, /*popUpError=*/true)) {
double ev = e->Eval();
Group *g = SK.GetGroup(edit.group);
SK.GetParam(edit.parameter)->val = ev;
SS.MarkGroupDirty(g->h);
}
break;

case Edit::GROUP_COLOR: {
Vector rgb;
if(sscanf(s.c_str(), "%lf, %lf, %lf", &rgb.x, &rgb.y, &rgb.z)==3) {
Expand Down
12 changes: 10 additions & 2 deletions src/ui.h