From b4ea012edc8db184dc1db92e154541601e0c8268 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 3 Aug 2015 15:46:30 -0300 Subject: [PATCH] Mesh: Added Mesh Merge command This command joins selected mesh objects into one --- src/Mod/Mesh/Gui/Command.cpp | 42 ++++++++++++++++++++++++++++++++++ src/Mod/Mesh/Gui/Workbench.cpp | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index 49dd640b7..9e2f54dc4 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -1632,6 +1632,47 @@ bool CmdMeshSegmentation::isActive(void) (Mesh::Feature::getClassTypeId()) == 1; } + +//-------------------------------------------------------------------------------------- + +DEF_STD_CMD_A(CmdMeshMerge); + +CmdMeshMerge::CmdMeshMerge() + :Command("Mesh_Merge") +{ + sAppModule = "Mesh"; + sGroup = QT_TR_NOOP("Mesh"); + sMenuText = QT_TR_NOOP("Merge"); + sToolTipText = "Merges selected meshes into one"; + sWhatsThis = "Mesh_Merge"; + sStatusTip = sToolTipText; +} + +void CmdMeshMerge::activated(int iMsg) +{ + App::Document *pcDoc = App::GetApplication().getActiveDocument(); + if (!pcDoc) + return; + openCommand("Mesh merge"); + Mesh::MeshObject* newMesh = new(Mesh::MeshObject); + std::vector objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId()); + for (std::vector::const_iterator it = objs.begin(); it != objs.end(); ++it) { + const MeshObject& mesh = static_cast(*it)->Mesh.getValue(); + MeshCore::MeshKernel kernel = mesh.getKernel(); + newMesh->addMesh(kernel); + } + Mesh::Feature *pcFeature = (Mesh::Feature*)pcDoc->addObject("Mesh::Feature", "Mesh"); + pcFeature->Mesh.setValue(*newMesh); + updateActive(); + commitCommand(); +} + +bool CmdMeshMerge::isActive(void) +{ + return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) >= 2; +} + + void CreateMeshCommands(void) { Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager(); @@ -1667,4 +1708,5 @@ void CreateMeshCommands(void) rcCmdMgr.addCommand(new CmdMeshFromGeometry()); rcCmdMgr.addCommand(new CmdMeshFromPartShape()); rcCmdMgr.addCommand(new CmdMeshSegmentation()); + rcCmdMgr.addCommand(new CmdMeshMerge()); } diff --git a/src/Mod/Mesh/Gui/Workbench.cpp b/src/Mod/Mesh/Gui/Workbench.cpp index 12254a334..87f9457c5 100644 --- a/src/Mod/Mesh/Gui/Workbench.cpp +++ b/src/Mod/Mesh/Gui/Workbench.cpp @@ -189,7 +189,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << analyze << "Mesh_HarmonizeNormals" << "Mesh_FlipNormals" << "Separator" << "Mesh_FillupHoles" << "Mesh_FillInteractiveHole" << "Mesh_RemoveComponents" << "Mesh_RemoveCompByHand" << "Mesh_AddFacet" << "Mesh_Smoothing" << "Separator" - << "Mesh_BuildRegularSolid" << boolean << "Separator" << "Mesh_PolySelect" << "Mesh_PolyCut" + << "Mesh_BuildRegularSolid" << boolean << "Separator" << "Mesh_Merge" << "Mesh_PolySelect" << "Mesh_PolyCut" << "Mesh_PolySplit" << "Mesh_PolySegm" << "Mesh_PolyTrim" << "Mesh_TrimByPlane" << "Mesh_Segmentation" << "Mesh_VertexCurvature"; return root;