Commit 80454fce authored by twanvl's avatar twanvl

Symmetry actions now work; reflection symmetry is forced to use a multiple of two copies

parent 53ee9924
......@@ -474,7 +474,12 @@ void SymmetryMoveAction::move(const Vector2D& deltaDelta) {
SymmetryTypeAction::SymmetryTypeAction(SymbolSymmetry& symmetry, SymbolSymmetryType type)
: symmetry(symmetry), type(type)
, old_name(symmetry.name)
, copies(symmetry.copies)
{
if (type == SYMMETRY_REFLECTION && symmetry.copies % 2 == 1) {
// make sure it is a multiple of two
copies = copies / 2 * 2;
}
// update name?
if (old_name == symmetry.expectedName()) {
swap(symmetry.kind, type);
......@@ -489,15 +494,21 @@ String SymmetryTypeAction::getName(bool to_undo) const {
void SymmetryTypeAction::perform(bool to_undo) {
swap(symmetry.kind, type);
swap(symmetry.copies, copies);
swap(symmetry.name, old_name);
}
// ----------------------------------------------------------------------------- : Change symmetry copies
SymmetryCopiesAction::SymmetryCopiesAction(SymbolSymmetry& symmetry, int copies)
: symmetry(symmetry), copies(copies)
SymmetryCopiesAction::SymmetryCopiesAction(SymbolSymmetry& symmetry, int copies_)
: symmetry(symmetry), copies(copies_)
, old_name(symmetry.name)
{
if (symmetry.kind == SYMMETRY_REFLECTION && copies % 2 == 1) {
// make sure it is a multiple of two
if (copies > symmetry.copies) copies++;
else copies--;
}
// update name?
if (old_name == symmetry.expectedName()) {
swap(symmetry.copies, copies);
......
......@@ -210,6 +210,7 @@ class SymmetryTypeAction : public Action {
SymbolSymmetry& symmetry;
SymbolSymmetryType type;
String old_name;
int copies; /// may be changed to make it a multiple of two
};
// ----------------------------------------------------------------------------- : Change symmetry copies
......
......@@ -10,6 +10,7 @@
#include <gui/symbol/selection.hpp>
#include <gui/util.hpp>
#include <data/action/symbol.hpp>
#include <data/action/symbol_part.hpp>
#include <gfx/gfx.hpp>
#include <render/symbol/filter.hpp>
#include <util/error.hpp>
......@@ -75,6 +76,16 @@ void SymbolPartList::onAction(const Action& action, bool undone) {
updateParts(selection.get());
return;
}
TYPE_CASE_(action, SymmetryTypeAction) {
if (typing_in) cursor = typing_in->name.size(); // can change the name
Refresh(false);
return;
}
TYPE_CASE_(action, SymmetryCopiesAction) {
if (typing_in) cursor = typing_in->name.size();
Refresh(false);
return;
}
}
wxSize SymbolPartList::DoGetBestSize() const {
......
......@@ -57,7 +57,8 @@ void SymbolSymmetryEditor::initUI(wxToolBar* tb, wxMenuBar* mb) {
copies->SetHelpText(_HELP_("copies"));
copies->SetSize(50, -1);
tb->AddSeparator();
tb->AddTool(ID_ADD_SYMMETRY, _TOOL_("add symmetry"), load_resource_tool_image(_("symmetry_add")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("add symmetry"), _HELP_("add symmetry"));
tb->AddTool(ID_ADD_SYMMETRY, _TOOL_("add symmetry"), load_resource_tool_image(_("symmetry_add")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("add symmetry"), _HELP_("add symmetry"));
tb->AddTool(ID_REMOVE_SYMMETRY, _TOOL_("remove symmetry"), load_resource_tool_image(_("symmetry_remove")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("remove symmetry"), _HELP_("remove symmetry"));
tb->AddSeparator();
tb->AddTool(ID_SYMMETRY_ROTATION, _TOOL_("rotation"), load_resource_image(_("symmetry_rotation")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("rotation"), _HELP_("rotation"));
tb->AddTool(ID_SYMMETRY_REFLECTION, _TOOL_("reflection"), load_resource_image(_("symmetry_reflection")), wxNullBitmap, wxITEM_CHECK, _TOOLTIP_("reflection"), _HELP_("reflection"));
......@@ -72,6 +73,7 @@ void SymbolSymmetryEditor::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
tb->DeleteTool(ID_SYMMETRY_REFLECTION);
tb->DeleteTool(ID_SYMMETRY_ROTATION);
tb->DeleteTool(ID_ADD_SYMMETRY);
tb->DeleteTool(ID_REMOVE_SYMMETRY);
// HACK: hardcoded size of rest of toolbar
tb->DeleteToolByPos(7); // delete separator
tb->DeleteToolByPos(7); // delete separator
......@@ -93,6 +95,8 @@ void SymbolSymmetryEditor::onUpdateUI(wxUpdateUIEvent& ev) {
}
} else if (ev.GetId() == ID_ADD_SYMMETRY) {
ev.Enable(true);
} else if (ev.GetId() == ID_REMOVE_SYMMETRY) {
ev.Enable(symmetry);
} else {
ev.Enable(false); // we don't know about this item
}
......@@ -122,6 +126,10 @@ void SymbolSymmetryEditor::onCommand(int id) {
getSymbol()->actions.add(new GroupSymbolPartsAction(*getSymbol(), control.selected_parts.get(), symmetry));
control.selected_parts.select(symmetry);
control.Refresh(false);
} else if (id == ID_REMOVE_SYMMETRY) {
getSymbol()->actions.add(new UngroupSymbolPartsAction(*getSymbol(), control.selected_parts.get()));
symmetry = SymbolSymmetryP();
control.Refresh(false);
}
}
......
......@@ -129,8 +129,8 @@ void SymbolViewer::combineSymbolPart(DC& dc, const SymbolPart& part, bool& paint
Matrix2D old_m = multiply;
Vector2D old_o = origin;
int copies = s->kind == SYMMETRY_REFLECTION ? s->copies / 2 * 2 : s->copies;
if (copies > 1) ++in_symmetry;
FOR_EACH_CONST_REVERSE(p, s->parts) {
if (copies > 1) ++in_symmetry;
for (int i = copies - 1 ; i >= 0 ; --i) {
if (i == 0) --in_symmetry;
if (s->clip) {
......@@ -323,8 +323,9 @@ void SymbolViewer::highlightPart(DC& dc, const SymbolSymmetry& sym, HighlightSty
// draw 'spokes'
double angle = atan2(sym.handle.y, sym.handle.x);
dc.SetPen(wxPen(color, sym.kind == SYMMETRY_ROTATION ? 1 : 3));
for (int i = 0; i < sym.copies ; ++i) {
double a = angle + (i + 0.5) * 2 * M_PI / sym.copies;
int copies = sym.kind == SYMMETRY_REFLECTION ? sym.copies / 2 * 2 : sym.copies;
for (int i = 0; i < copies ; ++i) {
double a = angle + (i + 0.5) * 2 * M_PI / copies;
Vector2D dir(cos(a), sin(a));
Vector2D dir2 = rotation.tr(sym.center + 2 * dir);
dc.DrawLine(center.x, center.y, dir2.x, dir2.y);
......
......@@ -96,6 +96,7 @@ tool/group IMAGE "tool/group.png"
tool/ungroup IMAGE "tool/ungroup.png"
tool/symmetry_add IMAGE "tool/symmetry_add.png"
tool/symmetry_remove IMAGE "tool/symmetry_remove.png"
combine_or IMAGE "../common/combine_or.png"
combine_sub IMAGE "../common/combine_sub.png"
......
......@@ -158,6 +158,7 @@ enum ChildMenuID {
, ID_SYMMETRY_REFLECTION
, ID_SYMMETRY_MAX
, ID_ADD_SYMMETRY
, ID_REMOVE_SYMMETRY
, ID_COPIES
// On cards panel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment