Skip to content

Commit

Permalink
Mesh: [skip ci] add command to split a mesh into its components
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Nov 21, 2020
1 parent 99e9b4d commit 20649ec
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/Mod/Mesh/Gui/Command.cpp
Expand Up @@ -1821,6 +1821,52 @@ bool CmdMeshMerge::isActive(void)

//--------------------------------------------------------------------------------------

DEF_STD_CMD_A(CmdMeshSplitComponents)

CmdMeshSplitComponents::CmdMeshSplitComponents()
: Command("Mesh_SplitComponents")
{
sAppModule = "Mesh";
sGroup = QT_TR_NOOP("Mesh");
sMenuText = QT_TR_NOOP("Split by components");
sToolTipText = QT_TR_NOOP("Split selected mesh into its components");
sWhatsThis = "Mesh_SplitComponents";
sStatusTip = sToolTipText;
//sPixmap = "Mesh_SplitComponents";
}

void CmdMeshSplitComponents::activated(int)
{
App::Document *pcDoc = App::GetApplication().getActiveDocument();
if (!pcDoc)
return;

openCommand("Mesh split");
std::vector<App::DocumentObject*> objs = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
for (std::vector<App::DocumentObject*>::const_iterator it = objs.begin(); it != objs.end(); ++it) {
const MeshObject& mesh = static_cast<Mesh::Feature*>(*it)->Mesh.getValue();
std::vector<std::vector<unsigned long> > comps = mesh.getComponents();

for (const auto comp : comps ) {
std::unique_ptr<MeshObject> kernel(mesh.meshFromSegment(comp));
kernel->setTransform(mesh.getTransform());

Mesh::Feature* feature = static_cast<Mesh::Feature*>(pcDoc->addObject("Mesh::Feature", "Component"));
feature->Mesh.setValuePtr(kernel.release());
}
}

updateActive();
commitCommand();
}

bool CmdMeshSplitComponents::isActive(void)
{
return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 1;
}

//--------------------------------------------------------------------------------------

DEF_STD_CMD_A(CmdMeshScale)

CmdMeshScale::CmdMeshScale()
Expand Down Expand Up @@ -1909,5 +1955,6 @@ void CreateMeshCommands(void)
rcCmdMgr.addCommand(new CmdMeshSegmentation());
rcCmdMgr.addCommand(new CmdMeshSegmentationBestFit);
rcCmdMgr.addCommand(new CmdMeshMerge());
rcCmdMgr.addCommand(new CmdMeshSplitComponents());
rcCmdMgr.addCommand(new CmdMeshScale());
}
1 change: 1 addition & 0 deletions src/Mod/Mesh/Gui/Workbench.cpp
Expand Up @@ -226,6 +226,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< cutting
<< "Separator"
<< "Mesh_Merge"
<< "Mesh_SplitComponents"
<< "Separator";
Gui::CommandManager& mgr = Gui::Application::Instance->commandManager();
if (mgr.getCommandByName("MeshPart_CreateFlatMesh"))
Expand Down

0 comments on commit 20649ec

Please sign in to comment.