Skip to content

Commit a53e4a0

Browse files
committed
Text window stuff to add, edit, and delete named parameters.
1 parent bbe5172 commit a53e4a0

File tree

3 files changed

+70
-19
lines changed

3 files changed

+70
-19
lines changed

src/request.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
119119
break;
120120
}
121121
case Type::NAMED_PARAMETER: {
122-
hParam p = AddParam(param, h.param(64));
123-
// lets do this without referencing SK
124-
// param *pprt = param->GetParam(p);
125-
SK.GetParam(p)->val = 1234;
122+
AddParam(param, h.param(64));
126123
}
127124

128125
default: // most requests don't do anything else

src/textscreens.cpp

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,15 @@ void TextWindow::ScreenSelectConstraint(int link, uint32_t v) {
223223
void TextWindow::AddNamedParameter(int link, uint32_t v) {
224224
hGroup hg = { v };
225225
SS.UndoRemember();
226-
227226
Request r = {};
228227
r.group = hg;
229228
r.type = Request::Type::NAMED_PARAMETER;
229+
r.str = "Edit_Name";
230230
SK.request.AddAndAssignId(&r);
231231
r.Generate(&SK.entity, &SK.param);
232-
// still need to give the parameter a default (unique) name
233-
232+
hParam hp = r.h.param(64);
233+
SK.GetParam(hp)->val = 123;
234234
SS.MarkGroupDirty(r.group);
235-
// using the GW function won't add to references group
236-
// hRequest hr = SS.GW.AddRequest(Request::Type::NAMED_PARAMETER);
237235
}
238236
void TextWindow::ScreenChangeGroupOption(int link, uint32_t v) {
239237
SS.UndoRemember();
@@ -338,6 +336,29 @@ void TextWindow::ScreenChangePitchOption(int link, uint32_t v) {
338336
}
339337
SS.GW.Invalidate();
340338
}
339+
void TextWindow::ScreenEditParamName(int link, uint32_t v) {
340+
hRequest hr = { v };
341+
Request *r = SK.request.FindByIdNoOops(hr);
342+
SS.TW.ShowEditControl(3, r->str);
343+
SS.TW.edit.meaning = Edit::PARAMETER_NAME;
344+
SS.TW.edit.request = hr;
345+
}
346+
void TextWindow::ScreenChangeParamValue(int link, uint32_t v) {
347+
Group *g = SK.GetGroup(SS.TW.shown.group);
348+
hParam p = { v };
349+
double value = SK.GetParam(p)->val;
350+
SS.TW.ShowEditControl(3, ssprintf("%.8f", value));
351+
SS.TW.edit.meaning = Edit::PARAMETER_VALUE;
352+
SS.TW.edit.group.v = g->h.v;
353+
SS.TW.edit.parameter = p;
354+
}
355+
void TextWindow::ScreenDeleteParameter(int link, uint32_t v) {
356+
hRequest hr = { v };
357+
Request *r = SK.request.FindByIdNoOops(hr);
358+
hParam p = r->h.param(64);
359+
SK.param.RemoveById(p);
360+
SK.request.RemoveById(hr);
361+
}
341362
void TextWindow::ScreenDeleteGroup(int link, uint32_t v) {
342363
SS.UndoRemember();
343364

@@ -545,22 +566,27 @@ void TextWindow::ShowGroupInfo() {
545566

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

551572
int a = 0;
552573
for(auto &r : SK.request) {
553-
// need to filter on whatever request type we use for parameters
574+
// filter on request type for parameters
554575
if(r.group == shown.group && r.type == Request::Type::NAMED_PARAMETER) {
555-
std::string s = r.DescriptionString();
556-
// we need a handle to the parameter to get name/value
557-
// hParam hp =
558-
559-
Printf(false, "%Bp %Fl%Ll%D%f%s%E",
576+
// get the name of our parameter request
577+
std::string s = r.str;
578+
// we need a handle to the parameter to get its value
579+
hParam hp = r.h.param(64);
580+
double value = SK.GetParam(hp)->val;
581+
Printf(false,
582+
"%Bp %Fl%Ll%D%f%s%E %# %E [%Fl%Ll%f%Dchange%E] [%Fl%Ll%D%fdel%E] ",
560583
(a & 1) ? 'd' : 'a',
561584
r.h.v,
562-
(&TextWindow::ScreenSelectRequest),
563-
s.c_str());
585+
&(TextWindow::ScreenEditParamName),
586+
s.c_str(),
587+
value,
588+
&(TextWindow::ScreenChangeParamValue), hp,
589+
r.h.v, &(TextWindow::ScreenDeleteParameter) );
564590
a++;
565591
}
566592
}
@@ -885,6 +911,27 @@ void TextWindow::EditControlDone(std::string s) {
885911
}
886912
break;
887913

914+
case Edit::PARAMETER_NAME:
915+
if(s.empty()) {
916+
Error(_("Parameter name cannot be empty"));
917+
} else {
918+
SS.UndoRemember();
919+
if(Request *r = SK.request.FindByIdNoOops(edit.request)) {
920+
r->str = s;
921+
SS.MarkGroupDirty(r->group);
922+
}
923+
}
924+
break;
925+
926+
case Edit::PARAMETER_VALUE: // by handle (passed in group handle...)
927+
if(Expr *e = Expr::From(s, /*popUpError=*/true)) {
928+
double ev = e->Eval();
929+
Group *g = SK.GetGroup(edit.group);
930+
SK.GetParam(edit.parameter)->val = ev;
931+
SS.MarkGroupDirty(g->h);
932+
}
933+
break;
934+
888935
case Edit::GROUP_COLOR: {
889936
Vector rgb;
890937
if(sscanf(s.c_str(), "%lf, %lf, %lf", &rgb.x, &rgb.y, &rgb.z)==3) {

src/ui.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,13 +350,16 @@ class TextWindow {
350350
// For tangent arc
351351
TANGENT_ARC_RADIUS = 800,
352352
// For helix pitch
353-
HELIX_PITCH = 802
353+
HELIX_PITCH = 802,
354+
PARAMETER_VALUE = 810,
355+
PARAMETER_NAME = 812
354356
};
355357
struct {
356358
bool showAgain;
357359
Edit meaning;
358360
int i;
359361
hGroup group;
362+
hParam parameter;
360363
hRequest request;
361364
hStyle style;
362365
} edit;
@@ -426,7 +429,11 @@ class TextWindow {
426429
static void ScreenSelectRequest(int link, uint32_t v);
427430
static void ScreenSelectEntity(int link, uint32_t v);
428431
static void ScreenSelectConstraint(int link, uint32_t v);
432+
429433
static void AddNamedParameter(int link, uint32_t v);
434+
static void ScreenEditParamName(int link, uint32_t v);
435+
static void ScreenChangeParamValue(int link, uint32_t v);
436+
static void ScreenDeleteParameter(int link, uint32_t v);
430437

431438
static void ScreenChangeGroupOption(int link, uint32_t v);
432439
static void ScreenColor(int link, uint32_t v);

0 commit comments

Comments
 (0)