1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
#include "Patch.h"
#include "i18n.h"
#include "ipatch.h"
#include "selectionlib.h"
#include "command/ExecutionNotPossible.h"
#include "patch/Patch.h"
#include "patch/PatchNode.h"
#include "selection/algorithm/Primitives.h"
#include "selection/shaderclipboard/ShaderClipboard.h"
#include "patch/algorithm/Prefab.h"
#include "patch/algorithm/General.h"
namespace selection
{
namespace algorithm
{
void invertPatch(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchInvert");
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.invertMatrix(); } );
SceneChangeNotify();
}
void redispersePatchRows(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchRedisperseRows");
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.redisperseRows(); });
}
void redispersePatchCols(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchRedisperseColumns");
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.redisperseColumns(); });
}
void transposePatch(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchTranspose");
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.transposeMatrix(); });
}
patch::CapType getPatchCapTypeForString(const std::string& capTypeStr)
{
if (capTypeStr == "bevel") return patch::CapType::Bevel;
if (capTypeStr == "invertedbevel") return patch::CapType::InvertedBevel;
if (capTypeStr == "endcap") return patch::CapType::EndCap;
if (capTypeStr == "invertedendcap") return patch::CapType::InvertedEndCap;
if (capTypeStr == "cylinder") return patch::CapType::Cylinder;
throw std::logic_error("Invalid cap type encountered: " + capTypeStr);
}
void capPatch(const cmd::ArgumentList& args)
{
if (GlobalSelectionSystem().getSelectionInfo().patchCount == 0)
{
throw cmd::ExecutionNotPossible(_("Cannot create caps, no patches selected."));
}
if (args.empty())
{
rWarning() << "Usage: CapSelectedPatches <bevel|invertedbevel|endcap|invertedendcap|cylinder>" << std::endl;
return;
}
try
{
// Parse the type
auto capType = getPatchCapTypeForString(args[0].getString());
UndoableCommand undo("patchCreateCaps");
auto patchNodes = getSelectedPatches();
for (const auto& patchNode : patchNodes)
{
patch::algorithm::createCaps(patchNode->getPatch(), patchNode->getParent(),
capType, GlobalShaderClipboard().getShaderName());
}
}
catch (const std::logic_error& ex)
{
rError() << ex.what() << std::endl;
}
}
void insertPatchColumnsAtEnd()
{
UndoableCommand undo("patchInsertColumnsAtEnd");
// true = insert, true = columns, false = end
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(true, true, false); });
}
void insertPatchColumnsAtBeginning()
{
UndoableCommand undo("patchInsertColumnsAtBeginning");
// true = insert, true = columns, true = at beginning
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(true, true, true); });
}
void insertPatchRowsAtEnd()
{
UndoableCommand undo("patchInsertRowsAtEnd");
// true = insert, false = rows, false = at end
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(true, false, false); });
}
void insertPatchRowsAtBeginning()
{
UndoableCommand undo("patchInsertRowsAtBeginning");
// true = insert, false = rows, true = at beginning
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(true, false, true); });
}
void deletePatchColumnsFromBeginning(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchDeleteColumnsFromBeginning");
// false = delete, true = columns, true = at beginning
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(false, true, true); });
}
void deletePatchColumnsFromEnd(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchDeleteColumnsFromEnd");
// false = delete, true = columns, false = at end
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(false, true, false); });
}
void deletePatchRowsFromBeginning(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchDeleteRowsFromBeginning");
// false = delete, false = rows, true = at beginning
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(false, false, true); });
}
void deletePatchRowsFromEnd(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchDeleteRowsFromEnd");
// false = delete, false = rows, false = at end
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.insertRemove(false, false, false); });
}
void appendPatchColumnsAtBeginning(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchAppendColumnsAtBeginning");
// true = columns, true = at the beginning
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.appendPoints(true, true); });
}
void appendPatchColumnsAtEnd(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchAppendColumnsAtEnd");
// true = columns, false = at the end
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.appendPoints(true, false); });
}
void appendPatchRowsAtBeginning(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchAppendRowsAtBeginning");
// false = rows, true = at the beginning
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.appendPoints(false, true); });
}
void appendPatchRowsAtEnd(const cmd::ArgumentList& args)
{
UndoableCommand undo("patchAppendRowsAtEnd");
// false = rows, false = at the end
GlobalSelectionSystem().foreachPatch([&] (IPatch& patch) { patch.appendPoints(false, false); });
}
/**
* greebo: Note: I chose to populate a list first, because otherwise the visitor
* class would get stuck in a loop (as the newly created patches get selected,
* and they are thickened as well, and again and again).
*/
void thickenPatches(const cmd::ArgumentList& args)
{
if (GlobalSelectionSystem().getSelectionInfo().patchCount == 0)
{
throw cmd::ExecutionNotPossible(_("Cannot thicken patch. Nothing selected."));
}
// Check arguments
if (args.size() != 3)
{
rWarning() << "Usage: ThickenSelectedPatches <thickness> <create_seams:1|0> <axis:0|1|2>" << std::endl;
return;
}
float thickness = static_cast<float>(args[0].getDouble());
bool createSeams = args[1].getInt() != 0;
int axis = args[2].getInt();
UndoableCommand undo("patchThicken");
auto patches = getSelectedPatches();
for (const PatchNodePtr& patch : patches)
{
patch::algorithm::thicken(patch, thickness, createSeams, axis);
}
}
} // namespace
} // namespace
|