command to creation section from plane and mesh

This commit is contained in:
wmayer
2017-02-19 14:05:00 +01:00
parent 845d6766f9
commit 46f5554c43
3 changed files with 205 additions and 57 deletions

View File

@@ -943,61 +943,7 @@ CmdMeshTrimByPlane::CmdMeshTrimByPlane()
void CmdMeshTrimByPlane::activated(int)
{
Base::Type partType = Base::Type::fromName("Part::Plane");
std::vector<App::DocumentObject*> plane = getSelection().getObjectsOfType(partType);
if (plane.empty()) {
QMessageBox::warning(Gui::getMainWindow(),
qApp->translate("Mesh_TrimByPlane", "Select plane"),
qApp->translate("Mesh_TrimByPlane", "Please select a plane at which you trim the mesh."));
return;
}
Base::Placement plm = static_cast<App::GeoFeature*>(plane.front())->Placement.getValue();
Base::Vector3d normal(0,0,1);
plm.getRotation().multVec(normal, normal);
Base::Vector3d up(-1,0,0);
plm.getRotation().multVec(up, up);
Base::Vector3d view(0,1,0);
plm.getRotation().multVec(view, view);
Base::Vector3d base = plm.getPosition();
Base::Rotation rot(Base::Vector3d(0,0,1), view);
Base::Matrix4D mat;
rot.getValue(mat);
Base::ViewProjMatrix proj(mat);
openCommand("Trim with plane");
std::vector<App::DocumentObject*> docObj = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
for (std::vector<App::DocumentObject*>::iterator it = docObj.begin(); it != docObj.end(); ++it) {
Mesh::MeshObject* mesh = static_cast<Mesh::Feature*>(*it)->Mesh.startEditing();
Base::BoundBox3d bbox = mesh->getBoundBox();
double len = bbox.CalcDiagonalLength();
// project center of bbox onto plane and use this as base point
Base::Vector3d cnt = bbox.GetCenter();
double dist = (cnt-base)*normal;
base = cnt - normal * dist;
Base::Vector3d p1 = base + up * len;
Base::Vector3d p2 = base - up * len;
Base::Vector3d p3 = p2 + normal * len;
Base::Vector3d p4 = p1 + normal * len;
p1 = mat * p1;
p2 = mat * p2;
p3 = mat * p3;
p4 = mat * p4;
Base::Polygon2d polygon2d;
polygon2d.Add(Base::Vector2d(p1.x, p1.y));
polygon2d.Add(Base::Vector2d(p2.x, p2.y));
polygon2d.Add(Base::Vector2d(p3.x, p3.y));
polygon2d.Add(Base::Vector2d(p4.x, p4.y));
Mesh::MeshObject::CutType type = Mesh::MeshObject::INNER;
mesh->trim(polygon2d, proj, type);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
(*it)->purgeTouched();
}
commitCommand();
doCommand(Doc,"import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_TrimByPlane')\n");
}
bool CmdMeshTrimByPlane::isActive(void)
@@ -1011,6 +957,34 @@ bool CmdMeshTrimByPlane::isActive(void)
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshSectionByPlane);
CmdMeshSectionByPlane::CmdMeshSectionByPlane()
: Command("Mesh_SectionByPlane")
{
sAppModule = "Mesh";
sGroup = QT_TR_NOOP("Mesh");
sMenuText = QT_TR_NOOP("Create section from mesh and plane");
sToolTipText = QT_TR_NOOP("Section from mesh and plane");
sStatusTip = QT_TR_NOOP("Section from mesh and plane");
}
void CmdMeshSectionByPlane::activated(int)
{
doCommand(Doc,"import MeshPartGui, FreeCADGui\nFreeCADGui.runCommand('MeshPart_SectionByPlane')\n");
}
bool CmdMeshSectionByPlane::isActive(void)
{
// Check for the selected mesh feature (all Mesh types)
if (getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) != 1)
return false;
return true;
}
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshPolySplit);
CmdMeshPolySplit::CmdMeshPolySplit()
@@ -1696,6 +1670,7 @@ void CreateMeshCommands(void)
rcCmdMgr.addCommand(new CmdMeshPolySplit());
rcCmdMgr.addCommand(new CmdMeshPolyTrim());
rcCmdMgr.addCommand(new CmdMeshTrimByPlane());
rcCmdMgr.addCommand(new CmdMeshSectionByPlane());
rcCmdMgr.addCommand(new CmdMeshToolMesh());
rcCmdMgr.addCommand(new CmdMeshTransform());
rcCmdMgr.addCommand(new CmdMeshEvaluation());

View File

@@ -190,7 +190,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Mesh_FillupHoles" << "Mesh_FillInteractiveHole" << "Mesh_RemoveComponents"
<< "Mesh_RemoveCompByHand" << "Mesh_AddFacet" << "Mesh_Smoothing" << "Separator"
<< "Mesh_BuildRegularSolid" << boolean << "Separator" << "Mesh_Merge" << "Mesh_PolySelect" << "Mesh_PolyCut"
<< "Mesh_PolySplit" << "Mesh_PolySegm" << "Mesh_PolyTrim" << "Mesh_TrimByPlane" << "Mesh_Segmentation"
<< "Mesh_PolySplit" << "Mesh_PolySegm" << "Mesh_PolyTrim" << "Separator"
<< "Mesh_TrimByPlane" << "Mesh_SectionByPlane" << "Mesh_Segmentation"
<< "Mesh_VertexCurvature";
return root;
}