Skip to content
Open
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
35 changes: 29 additions & 6 deletions src/graphicswin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct MenuEntry {
#define KC MenuKind::CHECK_MARK
#define KR MenuKind::RADIO_MARK
const MenuEntry Menu[] = {
//lv label cmd accel kind
//lv label cmd accel kind *fn
{ 0, N_("&File"), Command::NONE, 0, KN, NULL },
{ 1, N_("&New"), Command::NEW, C|'n', KN, mFile },
{ 1, N_("&Open..."), Command::OPEN, C|'o', KN, mFile },
Expand All @@ -60,7 +60,8 @@ const MenuEntry Menu[] = {
{ 0, N_("&Edit"), Command::NONE, 0, KN, NULL },
{ 1, N_("&Undo"), Command::UNDO, C|'z', KN, mEdit },
{ 1, N_("&Redo"), Command::REDO, C|'y', KN, mEdit },
{ 1, N_("Re&generate All"), Command::REGEN_ALL, ' ', KN, mEdit },
{ 1, N_("Re&generate All"), Command::REGEN_ALL, C|'r', KN, mEdit },

{ 1, NULL, Command::NONE, 0, KN, NULL },
{ 1, N_("Snap Selection to &Grid"), Command::SNAP_TO_GRID, '.', KN, mEdit },
{ 1, N_("Rotate Imported &90°"), Command::ROTATE_90, '9', KN, mEdit },
Expand All @@ -73,7 +74,7 @@ const MenuEntry Menu[] = {
{ 1, NULL, Command::NONE, 0, KN, NULL },
{ 1, N_("Select &Edge Chain"), Command::SELECT_CHAIN, C|'e', KN, mEdit },
{ 1, N_("Select &All"), Command::SELECT_ALL, C|'a', KN, mEdit },
{ 1, N_("&Unselect All"), Command::UNSELECT_ALL, '\x1b', KN, mEdit },
{ 1, N_("&Unselect All"), Command::ESCAPE_KEY, '\x1b', KN, mEdit }, // x1b = escape key
{ 1, NULL, Command::NONE, 0, KN, NULL },
{ 1, N_("&Line Styles..."), Command::EDIT_LINE_STYLES, 0, KN, mEdit },
{ 1, N_("&View Projection..."), Command::VIEW_PROJECTION, 0, KN, mEdit },
Expand Down Expand Up @@ -141,6 +142,8 @@ const MenuEntry Menu[] = {
{ 1, N_("To&ggle Construction"), Command::CONSTRUCTION, 'g', KN, mReq },
{ 1, N_("Tangent &Arc at Point"), Command::TANGENT_ARC, S|'a', KN, mReq },
{ 1, N_("Split Curves at &Intersection"), Command::SPLIT_CURVES, 'i', KN, mReq },
{ 1, N_("Other Tools"), Command::NONE, 0, KN, NULL },
{ 2, N_("Alternate Tool"), Command::ALTERNATE_TOOL, ' ', KN, mEdit },

{ 0, N_("&Constrain"), Command::NONE, 0, KN, mCon },
{ 1, N_("&Distance / Diameter"), Command::DISTANCE_DIA, 'd', KN, mCon },
Expand Down Expand Up @@ -242,7 +245,7 @@ bool GraphicsWindow::KeyboardEvent(Platform::KeyboardEvent event) {
if(event.key == KeyboardEvent::Key::CHARACTER) {
if(event.chr == '\b') {
// Treat backspace identically to escape.
MenuEdit(Command::UNSELECT_ALL);
SS.GW.CancelPending();
return true;
} else if(event.chr == '=') {
// Treat = as +. This is specific to US (and US-compatible) keyboard layouts,
Expand Down Expand Up @@ -1007,6 +1010,7 @@ void GraphicsWindow::EnsureValidActives() {
void GraphicsWindow::SetWorkplaneFreeIn3d() {
SK.GetGroup(activeGroup)->activeWorkplane = Entity::FREE_IN_3D;
}

hEntity GraphicsWindow::ActiveWorkplane() {
Group *g = SK.group.FindByIdNoOops(activeGroup);
if(g) {
Expand Down Expand Up @@ -1097,11 +1101,16 @@ void GraphicsWindow::MenuEdit(Command id) {
}
}
}
if(SS.GW.pending.operation != Pending::COMMAND) {
// Undo partially completed operation if there is one in process and dont remeber it.
SS.UndoUndo(false);
}
SS.GW.ClearSuper();
SS.TW.HideEditControl();
SS.nakedEdges.Clear();
SS.justExportedInfo.draw = false;
SS.centerOfMass.draw = false;
//SS.GW.pending.operation;
// This clears the marks drawn to indicate which points are
// still free to drag.
for(Param &p : SK.param) {
Expand All @@ -1114,6 +1123,15 @@ void GraphicsWindow::MenuEdit(Command id) {
SS.GW.persistentDirty = true;
break;

// this is the space bar alternative tool menu - switch between the most recent tool and mouse
case Command::ALTERNATE_TOOL:
SS.GW.AlternateTool();
break;

case Command::ESCAPE_KEY:
SS.GW.CancelPending();
break;

case Command::SELECT_ALL: {
for(Entity &e : SK.entity) {
if(e.group != SS.GW.activeGroup) continue;
Expand Down Expand Up @@ -1355,8 +1373,9 @@ void GraphicsWindow::MenuRequest(Command id) {
}
s = _("click top left of image"); goto c;
c:
//SS.GW.activeTool = id;
SS.GW.pending.operation = GraphicsWindow::Pending::COMMAND;
SS.GW.pending.command = id;
SS.GW.pending.command = id;
SS.GW.pending.description = s;
SS.ScheduleShowTW();
SS.GW.Invalidate(); // repaint toolbar
Expand Down Expand Up @@ -1402,11 +1421,15 @@ void GraphicsWindow::MenuRequest(Command id) {

default: ssassert(false, "Unexpected menu ID");
}
// If tool can be used multiple times, mark as active.
if(SS.GW.CheckIfKeepCommandActive(SS.GW.pending.command)) {
SS.GW.activeTool = id;//SS.GW.pending.operation;
}
}

void GraphicsWindow::ClearSuper() {
if(window) window->HideEditor();
ClearPending();
ClearPending(true);
ClearSelection();
hover.Clear();
EnsureValidActives();
Expand Down
68 changes: 59 additions & 9 deletions src/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,15 +467,65 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
}
}

void GraphicsWindow::ClearPending(bool scheduleShowTW) {
void GraphicsWindow::AlternateTool() {
// Switches between most recent tool and the mouse selector
if(SS.GW.activeTool != Command::NONE) {
// need to make sure there is actually a pending action or else it will undo a previous curve
if(pending.command == Command::NONE && pending.operation == Pending::NONE) {
MenuRequest(SS.GW.activeTool);
} else {
SS.GW.CancelPending();
}
SS.GW.Invalidate();
SS.ScheduleShowTW();
}
}


void GraphicsWindow::CancelPending() {
if(pending.operation != Pending::NONE && pending.operation != Pending::COMMAND) {
// undo any pending object and reselect the tool to be used again
SS.GW.MenuEdit(Command::UNSELECT_ALL);
ClearPending(true, false);
MenuRequest(SS.GW.activeTool);
} else
// If there is not an in process object to cancel, unselect the tool
ClearPending(true, false);
Invalidate();
SS.ScheduleShowTW();
}

void GraphicsWindow::ClearPending(bool scheduleShowTW, bool allowCommandToContinue) {
// Clears selected tool or, steps of a tool's use (tow point rectangle).
// Allows tool to be reactivated after use if specified in toolbar.cpp/Toolbar[]
Command temp_store = Command::NONE;
pending.points.Clear();
pending.requests.Clear();
pending = {};
if(pending.command != Command::NONE && allowCommandToContinue) {

if(CheckIfKeepCommandActive(pending.command)) {
temp_store = pending.command;
};
pending = {};
pending.stored_command = temp_store;
// If there is a tool stored, activate it
} else if(pending.stored_command != Command::NONE && allowCommandToContinue) {
temp_store = pending.stored_command;
pending = {};
if(allowCommandToContinue) {
pending.command = temp_store;
pending.operation = Pending::COMMAND;
}
} else {
pending = {};
}

if(scheduleShowTW) {
SS.ScheduleShowTW();
}
}


bool GraphicsWindow::IsFromPending(hRequest r) {
for(auto &req : pending.requests) {
if(req == r) return true;
Expand Down Expand Up @@ -529,11 +579,8 @@ void GraphicsWindow::MouseRightUp(double x, double y) {
pending.operation == Pending::DRAGGING_NEW_POINT
)
{
// Special case; use a right click to stop drawing lines, since
// a left click would draw another one. This is quicker and more
// intuitive than hitting escape. Likewise for other entities
// for consistency.
ClearPending();
// Right click cancels pending operation. Same as escape/backspace.
CancelPending();
return;
}

Expand Down Expand Up @@ -794,6 +841,7 @@ void GraphicsWindow::MouseRightUp(double x, double y) {
hRequest GraphicsWindow::AddRequest(Request::Type type) {
return AddRequest(type, /*rememberForUndo=*/true);
}

hRequest GraphicsWindow::AddRequest(Request::Type type, bool rememberForUndo) {
if(rememberForUndo) SS.UndoRemember();

Expand Down Expand Up @@ -1021,7 +1069,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my, bool shiftDown, bool ct
}
}

pending.operation = Pending::DRAGGING_NEW_POINT;
pending.operation = Pending::DRAGGING_NEW_POINT;
pending.point = lns[1].entity(2);
pending.description = _("click to place other corner of rectangle");
hr = lns[0];
Expand Down Expand Up @@ -1164,13 +1212,15 @@ void GraphicsWindow::MouseLeftDown(double mx, double my, bool shiftDown, bool ct
break;

case Pending::DRAGGING_RADIUS:
ClearPending();
//ClearPending();
break;

case Pending::DRAGGING_NEW_POINT:
case Pending::DRAGGING_NEW_ARC_POINT:
ConstrainPointByHovered(pending.point, &mouse);
ClearPending();
//pending.command = Command::RECTANGLE;
//pending.operation = Pending::COMMAND;
break;

case Pending::DRAGGING_NEW_CUBIC_POINT: {
Expand Down
2 changes: 1 addition & 1 deletion src/solvespace.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class SolveSpaceUI {

void UndoEnableMenus();
void UndoRemember();
void UndoUndo();
void UndoUndo(bool save_undo = true);
void UndoRedo();
void PushFromCurrentOnto(UndoStack *uk);
void PopOntoCurrentFrom(UndoStack *uk);
Expand Down
131 changes: 57 additions & 74 deletions src/toolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,86 +10,69 @@
struct ToolIcon {
std::string name;
Command command;
bool keep_active;
const char *tooltip;
std::shared_ptr<Pixmap> pixmap;
};
static ToolIcon Toolbar[] = {
{ "line", Command::LINE_SEGMENT,
N_("Sketch line segment"), {} },
{ "rectangle", Command::RECTANGLE,
N_("Sketch rectangle"), {} },
{ "circle", Command::CIRCLE,
N_("Sketch circle"), {} },
{ "arc", Command::ARC,
N_("Sketch arc of a circle"), {} },
{ "text", Command::TTF_TEXT,
N_("Sketch curves from text in a TrueType font"), {} },
{ "image", Command::IMAGE,
N_("Sketch image from a file"), {} },
{ "tangent-arc", Command::TANGENT_ARC,
N_("Create tangent arc at selected point"), {} },
{ "bezier", Command::CUBIC,
N_("Sketch cubic Bezier spline"), {} },
{ "point", Command::DATUM_POINT,
N_("Sketch datum point"), {} },
{ "construction", Command::CONSTRUCTION,
N_("Toggle construction"), {} },
{ "trim", Command::SPLIT_CURVES,
N_("Split lines / curves where they intersect"), {} },
{ "", Command::NONE, "", {} },

{ "length", Command::DISTANCE_DIA,
N_("Constrain distance / diameter / length"), {} },
{ "angle", Command::ANGLE,
N_("Constrain angle"), {} },
{ "horiz", Command::HORIZONTAL,
N_("Constrain to be horizontal"), {} },
{ "vert", Command::VERTICAL,
N_("Constrain to be vertical"), {} },
{ "parallel", Command::PARALLEL,
N_("Constrain to be parallel or tangent"), {} },
{ "perpendicular", Command::PERPENDICULAR,
N_("Constrain to be perpendicular"), {} },
{ "pointonx", Command::ON_ENTITY,
N_("Constrain point on line / curve / plane / point"), {} },
{ "symmetric", Command::SYMMETRIC,
N_("Constrain symmetric"), {} },
{ "equal", Command::EQUAL,
N_("Constrain equal length / radius / angle"), {} },
{ "same-orientation",Command::ORIENTED_SAME,
N_("Constrain normals in same orientation"), {} },
{ "other-supp", Command::OTHER_ANGLE,
N_("Other supplementary angle"), {} },
{ "ref", Command::REFERENCE,
N_("Toggle reference dimension"), {} },
{ "", Command::NONE, "", {} },

{ "extrude", Command::GROUP_EXTRUDE,
N_("New group extruding active sketch"), {} },
{ "lathe", Command::GROUP_LATHE,
N_("New group rotating active sketch"), {} },
{ "helix", Command::GROUP_HELIX,
N_("New group helix from active sketch"), {} },
{ "revolve", Command::GROUP_REVOLVE,
N_("New group revolve active sketch"), {} },
{ "step-rotate", Command::GROUP_ROT,
N_("New group step and repeat rotating"), {} },
{ "step-translate", Command::GROUP_TRANS,
N_("New group step and repeat translating"), {} },
{ "sketch-in-plane", Command::GROUP_WRKPL,
N_("New group in new workplane (thru given entities)"), {} },
{ "sketch-in-3d", Command::GROUP_3D,
N_("New group in 3d"), {} },
{ "assemble", Command::GROUP_LINK,
N_("New group linking / assembling file"), {} },
{ "", Command::NONE, "", {} },

{ "in3d", Command::NEAREST_ISO,
N_("Nearest isometric view"), {} },
{ "ontoworkplane", Command::ONTO_WORKPLANE,
N_("Align view to active workplane"), {} },
// name command keep_active tooltip pixmap
{ "line", Command::LINE_SEGMENT, 1, N_("Sketch line segment"), {} },
{ "rectangle", Command::RECTANGLE, 1, N_("Sketch rectangle"), {} },
{ "circle", Command::CIRCLE, 1, N_("Sketch circle"), {} },
{ "arc", Command::ARC, 1, N_("Sketch arc of a circle"), {} },
{ "text", Command::TTF_TEXT, 1, N_("Sketch curves from text in a TrueType font"), {} },
{ "image", Command::IMAGE, 1, N_("Sketch image from a file"), {} },
{ "tangent-arc", Command::TANGENT_ARC, 1, N_("Create tangent arc at selected point"), {} },
{ "bezier", Command::CUBIC, 1, N_("Sketch cubic Bezier spline"), {} },
{ "point", Command::DATUM_POINT, 1, N_("Sketch datum point"), {} },
{ "construction", Command::CONSTRUCTION, 1, N_("Toggle construction"), {} },
{ "trim", Command::SPLIT_CURVES, 1, N_("Split lines / curves where they intersect"), {} },
{ "", Command::NONE, 0, "", {} },

{ "length", Command::DISTANCE_DIA, 1, N_("Constrain distance / diameter / length"), {} },
{ "angle", Command::ANGLE, 1, N_("Constrain angle"), {} },
{ "horiz", Command::HORIZONTAL, 1, N_("Constrain to be horizontal"), {} },
{ "vert", Command::VERTICAL, 1, N_("Constrain to be vertical"), {} },
{ "parallel", Command::PARALLEL, 1, N_("Constrain to be parallel or tangent"), {} },
{ "perpendicular", Command::PERPENDICULAR, 1, N_("Constrain to be perpendicular"), {} },
{ "pointonx", Command::ON_ENTITY, 1, N_("Constrain point on line / curve / plane / point"), {} },
{ "symmetric", Command::SYMMETRIC, 1, N_("Constrain symmetric"), {} },
{ "equal", Command::EQUAL, 1, N_("Constrain equal length / radius / angle"), {} },
{ "same-orientation",Command::ORIENTED_SAME, 1, N_("Constrain normals in same orientation"), {} },
{ "other-supp", Command::OTHER_ANGLE, 1, N_("Other supplementary angle"), {} },
{ "ref", Command::REFERENCE, 1, N_("Toggle reference dimension"), {} },
{ "", Command::NONE, 0, "", {} },

{ "extrude", Command::GROUP_EXTRUDE, 1, N_("New group extruding active sketch"), {} },
{ "lathe", Command::GROUP_LATHE, 1, N_("New group rotating active sketch"), {} },
{ "helix", Command::GROUP_HELIX, 1, N_("New group helix from active sketch"), {} },
{ "revolve", Command::GROUP_REVOLVE, 1, N_("New group revolve active sketch"), {} },
{ "step-rotate", Command::GROUP_ROT, 1, N_("New group step and repeat rotating"), {} },
{ "step-translate", Command::GROUP_TRANS, 1, N_("New group step and repeat translating"), {} },
{ "sketch-in-plane", Command::GROUP_WRKPL, 1, N_("New group in new workplane (thru given entities)"), {} },
{ "sketch-in-3d", Command::GROUP_3D, 1, N_("New group in 3d"), {} },
{ "assemble", Command::GROUP_LINK, 1, N_("New group linking / assembling file"), {} },
{ "", Command::NONE, "", 0, {} },

{ "in3d", Command::NEAREST_ISO, 0, N_("Nearest isometric view"), {} },
{ "ontoworkplane", Command::ONTO_WORKPLANE, 0, N_("Align view to active workplane"), {} },
};


bool GraphicsWindow::CheckIfKeepCommandActive(Command theCom) {
for(ToolIcon &icon : Toolbar) {
if(theCom == icon.command) {
if(icon.keep_active)
return true;
else
return false;
}
}

return false; // no match found
}


void GraphicsWindow::ToolbarDraw(UiCanvas *canvas) {
ToolbarDrawOrHitTest(0, 0, canvas, NULL, NULL, NULL);
}
Expand Down
Loading