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
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ static const EntReqMapping EntReqMap[] = {
{ Request::Type::ARC_OF_CIRCLE, Entity::Type::ARC_OF_CIRCLE, 3, false, true, false },
{ Request::Type::TTF_TEXT, Entity::Type::TTF_TEXT, 4, false, true, false },
{ Request::Type::IMAGE, Entity::Type::IMAGE, 4, false, true, false },
{ Request::Type::NAMED_PARAMETER, (Entity::Type)0, 0, false, false, false },
};

static void CopyEntityInfo(const EntReqMapping *te, int extraPoints,
Expand Down Expand Up @@ -117,6 +118,9 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
}
break;
}
case Type::NAMED_PARAMETER: {
AddParam(param, h.param(64));
}

default: // most requests don't do anything else
break;
Expand Down Expand Up @@ -221,6 +225,7 @@ std::string Request::DescriptionString() const {
case Type::ARC_OF_CIRCLE: s = "arc-of-circle"; break;
case Type::TTF_TEXT: s = "ttf-text"; break;
case Type::IMAGE: s = "image"; break;
case Type::NAMED_PARAMETER: s = "parameter"; break;
}
}
ssassert(s != NULL, "Unexpected request type");
Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,16 @@ class TextWindow {
// For tangent arc
TANGENT_ARC_RADIUS = 800,
// For helix pitch
HELIX_PITCH = 802
HELIX_PITCH = 802,
PARAMETER_VALUE = 810,
PARAMETER_NAME = 812
};
struct {
bool showAgain;
Edit meaning;
int i;
hGroup group;
hParam parameter;
hRequest request;
hStyle style;
} edit;
Expand Down Expand Up @@ -426,7 +429,12 @@ class TextWindow {
static void ScreenSelectRequest(int link, uint32_t v);
static void ScreenSelectEntity(int link, uint32_t v);
static void ScreenSelectConstraint(int link, uint32_t v);


static void AddNamedParameter(int link, uint32_t v);
static void ScreenEditParamName(int link, uint32_t v);
static void ScreenChangeParamValue(int link, uint32_t v);
static void ScreenDeleteParameter(int link, uint32_t v);

static void ScreenChangeGroupOption(int link, uint32_t v);
static void ScreenColor(int link, uint32_t v);
static void ScreenOpacity(int link, uint32_t v);
Expand Down