polish Mesh workbench

This commit is contained in:
wmayer
2018-09-18 14:53:37 +02:00
parent b05f234fac
commit 4c8e70b9a3
4 changed files with 160 additions and 77 deletions

View File

@@ -78,7 +78,8 @@
using namespace Mesh;
// deprecated
#if 0
DEF_STD_CMD_A(CmdMeshTransform);
CmdMeshTransform::CmdMeshTransform()
@@ -157,6 +158,61 @@ bool CmdMeshDemolding::isActive(void)
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshToolMesh);
CmdMeshToolMesh::CmdMeshToolMesh()
:Command("Mesh_ToolMesh")
{
sAppModule = "Mesh";
sGroup = QT_TR_NOOP("Mesh");
sMenuText = QT_TR_NOOP("Segment by tool mesh");
sToolTipText = QT_TR_NOOP("Creates a segment from a given tool mesh");
sWhatsThis = "Mesh_ToolMesh";
sStatusTip = QT_TR_NOOP("Creates a segment from a given tool mesh");
}
void CmdMeshToolMesh::activated(int)
{
std::vector<App::DocumentObject*> fea = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
if ( fea.size() == 2 )
{
std::string fName = getUniqueObjectName("MeshSegment");
App::DocumentObject* mesh = fea.front();
App::DocumentObject* tool = fea.back();
openCommand("Segment by tool mesh");
doCommand(Doc, "import Mesh");
doCommand(Gui, "import MeshGui");
doCommand(Doc,
"App.activeDocument().addObject(\"Mesh::SegmentByMesh\",\"%s\")\n"
"App.activeDocument().%s.Source = App.activeDocument().%s\n"
"App.activeDocument().%s.Tool = App.activeDocument().%s\n",
fName.c_str(), fName.c_str(), mesh->getNameInDocument(), fName.c_str(), tool->getNameInDocument() );
commitCommand();
updateActive();
App::Document* pDoc = getDocument();
App::DocumentObject * pObj = pDoc->getObject( fName.c_str() );
if ( pObj )
{
doCommand(Gui,"Gui.hide(\"%s\")", mesh->getNameInDocument());
doCommand(Gui,"Gui.hide(\"%s\")", tool->getNameInDocument());
getSelection().clearSelection();
}
}
}
bool CmdMeshToolMesh::isActive(void)
{
// Check for the selected mesh feature (all Mesh types)
return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2;
}
#endif
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshUnion);
CmdMeshUnion::CmdMeshUnion()
@@ -716,7 +772,7 @@ bool CmdMeshPolySegm::isActive(void)
}
//--------------------------------------------------------------------------------------
#if 0
DEF_STD_CMD_A(CmdMeshPolySelect);
CmdMeshPolySelect::CmdMeshPolySelect()
@@ -767,7 +823,7 @@ bool CmdMeshPolySelect::isActive(void)
return false;
}
#endif
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshAddFacet);
@@ -1039,60 +1095,6 @@ bool CmdMeshPolySplit::isActive(void)
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshToolMesh);
CmdMeshToolMesh::CmdMeshToolMesh()
:Command("Mesh_ToolMesh")
{
sAppModule = "Mesh";
sGroup = QT_TR_NOOP("Mesh");
sMenuText = QT_TR_NOOP("Segment by tool mesh");
sToolTipText = QT_TR_NOOP("Creates a segment from a given tool mesh");
sWhatsThis = "Mesh_ToolMesh";
sStatusTip = QT_TR_NOOP("Creates a segment from a given tool mesh");
}
void CmdMeshToolMesh::activated(int)
{
std::vector<App::DocumentObject*> fea = Gui::Selection().getObjectsOfType(Mesh::Feature::getClassTypeId());
if ( fea.size() == 2 )
{
std::string fName = getUniqueObjectName("MeshSegment");
App::DocumentObject* mesh = fea.front();
App::DocumentObject* tool = fea.back();
openCommand("Segment by tool mesh");
doCommand(Doc, "import Mesh");
doCommand(Gui, "import MeshGui");
doCommand(Doc,
"App.activeDocument().addObject(\"Mesh::SegmentByMesh\",\"%s\")\n"
"App.activeDocument().%s.Source = App.activeDocument().%s\n"
"App.activeDocument().%s.Tool = App.activeDocument().%s\n",
fName.c_str(), fName.c_str(), mesh->getNameInDocument(), fName.c_str(), tool->getNameInDocument() );
commitCommand();
updateActive();
App::Document* pDoc = getDocument();
App::DocumentObject * pObj = pDoc->getObject( fName.c_str() );
if ( pObj )
{
doCommand(Gui,"Gui.hide(\"%s\")", mesh->getNameInDocument());
doCommand(Gui,"Gui.hide(\"%s\")", tool->getNameInDocument());
getSelection().clearSelection();
}
}
}
bool CmdMeshToolMesh::isActive(void)
{
// Check for the selected mesh feature (all Mesh types)
return getSelection().countObjectsOfType(Mesh::Feature::getClassTypeId()) == 2;
}
//--------------------------------------------------------------------------------------
DEF_STD_CMD_A(CmdMeshEvaluation);
CmdMeshEvaluation::CmdMeshEvaluation()
@@ -1455,7 +1457,9 @@ void CmdMeshBoundingBox::activated(int)
Base::Console().Message("Boundings: Min=<%f,%f,%f>, Max=<%f,%f,%f>\n",
box.MinX,box.MinY,box.MinZ,box.MaxX,box.MaxY,box.MaxZ);
QString bound = QObject::tr("Min=<%1,%2,%3>\n\nMax=<%4,%5,%6>")
QString bound = qApp->translate("Mesh_BoundingBox", "Boundings of %1:")
.arg(QString::fromUtf8((*it)->Label.getValue()));
bound += QString::fromLatin1("\n\nMin=<%1,%2,%3>\n\nMax=<%4,%5,%6>")
.arg(box.MinX).arg(box.MinY).arg(box.MinZ)
.arg(box.MaxX).arg(box.MaxY).arg(box.MaxZ);
QMessageBox::information(Gui::getMainWindow(), QObject::tr("Boundings"), bound);
@@ -1703,6 +1707,9 @@ bool CmdMeshScale::isActive(void)
void CreateMeshCommands(void)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
//rcCmdMgr.addCommand(new CmdMeshDemolding());
//rcCmdMgr.addCommand(new CmdMeshToolMesh());
//rcCmdMgr.addCommand(new CmdMeshTransform());
rcCmdMgr.addCommand(new CmdMeshImport());
rcCmdMgr.addCommand(new CmdMeshExport());
rcCmdMgr.addCommand(new CmdMeshVertexCurvature());
@@ -1710,17 +1717,14 @@ void CreateMeshCommands(void)
rcCmdMgr.addCommand(new CmdMeshUnion());
rcCmdMgr.addCommand(new CmdMeshDifference());
rcCmdMgr.addCommand(new CmdMeshIntersection());
rcCmdMgr.addCommand(new CmdMeshDemolding());
rcCmdMgr.addCommand(new CmdMeshPolySegm());
rcCmdMgr.addCommand(new CmdMeshPolySelect());
//rcCmdMgr.addCommand(new CmdMeshPolySelect());
rcCmdMgr.addCommand(new CmdMeshAddFacet());
rcCmdMgr.addCommand(new CmdMeshPolyCut());
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());
rcCmdMgr.addCommand(new CmdMeshEvaluateFacet());
rcCmdMgr.addCommand(new CmdMeshEvaluateSolid());

View File

@@ -1024,7 +1024,7 @@ void ViewProviderMesh::selectGLCallback(void * ud, SoEventCallback * n)
n->setHandled();
std::vector<SbVec2f> clPoly = view->getGLPolygon();
if (clPoly.size() != 1)
if (clPoly.size() != 2)
return;
const SoEvent* ev = n->getEvent();

View File

@@ -184,18 +184,46 @@ Gui::MenuItem* Workbench::setupMenuBar() const
// boolean
Gui::MenuItem* boolean = new Gui::MenuItem;
boolean->setCommand("Boolean");
*boolean << "Mesh_Union" << "Mesh_Intersection" << "Mesh_Difference";
*boolean << "Mesh_Union"
<< "Mesh_Intersection"
<< "Mesh_Difference";
// cutting
Gui::MenuItem* cutting = new Gui::MenuItem;
cutting->setCommand("Cutting");
*cutting << "Mesh_PolyCut"
<< "Mesh_PolySplit"
<< "Mesh_PolySegm"
<< "Mesh_PolyTrim"
<< "Mesh_TrimByPlane"
<< "Mesh_SectionByPlane";
mesh->setCommand("&Meshes");
*mesh << "Mesh_Import" << "Mesh_Export" << "Mesh_FromPartShape" << "Separator"
<< analyze << "Mesh_HarmonizeNormals" << "Mesh_FlipNormals" << "Separator"
<< "Mesh_FillupHoles" << "Mesh_FillInteractiveHole" << "Mesh_RemoveComponents"
<< "Mesh_RemoveCompByHand" << "Mesh_AddFacet" << "Mesh_Smoothing" << "Mesh_Scale"
<< "Separator" << "Mesh_BuildRegularSolid" << boolean << "Separator"
<< "Mesh_Merge" << "Mesh_PolySelect" << "Mesh_PolyCut"
<< "Mesh_PolySplit" << "Mesh_PolySegm" << "Mesh_PolyTrim" << "Separator"
<< "Mesh_TrimByPlane" << "Mesh_SectionByPlane" << "Mesh_Segmentation"
<< "Mesh_VertexCurvature";
*mesh << "Mesh_Import"
<< "Mesh_Export"
<< "Mesh_FromPartShape"
<< "Separator"
<< analyze
<< "Mesh_VertexCurvature"
<< "Mesh_HarmonizeNormals"
<< "Mesh_FlipNormals"
<< "Separator"
<< "Mesh_FillupHoles"
<< "Mesh_FillInteractiveHole"
<< "Mesh_AddFacet"
<< "Mesh_RemoveComponents"
<< "Mesh_RemoveCompByHand"
<< "Mesh_Segmentation"
<< "Separator"
<< "Mesh_Smoothing"
<< "Mesh_Scale"
<< "Separator"
<< "Mesh_BuildRegularSolid"
<< boolean
<< cutting
<< "Separator"
<< "Mesh_Merge"
<< "Separator";
Gui::CommandManager& mgr = Gui::Application::Instance->commandManager();
if (mgr.getCommandByName("MeshPart_CreateFlatMesh"))
*mesh << "MeshPart_CreateFlatMesh";

View File

@@ -25,6 +25,7 @@
#ifndef _PreComp_
# include <QApplication>
# include <QMessageBox>
# include <QPushButton>
#endif
#include <Mod/Mesh/App/MeshFeature.h>
@@ -95,6 +96,38 @@ void CmdMeshPartTrimByPlane::activated(int)
return;
}
QMessageBox msgBox(Gui::getMainWindow());
msgBox.setIcon(QMessageBox::Question);
msgBox.setWindowTitle(qApp->translate("MeshPart_TrimByPlane","Trim by plane"));
msgBox.setText(qApp->translate("MeshPart_TrimByPlane","Select the side you want to keep."));
QPushButton* inner = msgBox.addButton(qApp->translate("MeshPart_TrimByPlane","Inner"), QMessageBox::ActionRole);
QPushButton* outer = msgBox.addButton(qApp->translate("MeshPart_TrimByPlane","Outer"), QMessageBox::ActionRole);
QPushButton* both = msgBox.addButton(qApp->translate("MeshPart_TrimByPlane","Both"), QMessageBox::ActionRole);
msgBox.setDefaultButton(inner);
msgBox.exec();
QAbstractButton* click = msgBox.clickedButton();
enum Side {
Inner,
Outer,
Both
};
Side side;
if (inner == click) {
side = Inner;
}
else if (outer == click) {
side = Outer;
}
else if (both == click) {
side = Both;
}
else {
// abort
return;
}
Base::Placement plm = static_cast<App::GeoFeature*>(plane.front())->Placement.getValue();
Base::Vector3d normal(0,0,1);
plm.getRotation().multVec(normal, normal);
@@ -135,9 +168,27 @@ void CmdMeshPartTrimByPlane::activated(int)
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();
if (side == Inner) {
mesh->trim(polygon2d, proj, Mesh::MeshObject::INNER);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
}
else if (side == Outer) {
mesh->trim(polygon2d, proj, Mesh::MeshObject::OUTER);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
}
else if (side == Both) {
Mesh::MeshObject copy(*mesh);
mesh->trim(polygon2d, proj, Mesh::MeshObject::INNER);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
copy.trim(polygon2d, proj, Mesh::MeshObject::OUTER);
App::Document* doc = (*it)->getDocument();
Mesh::Feature* fea = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature"));
fea->Label.setValue((*it)->Label.getValue());
Mesh::MeshObject* feamesh = fea->Mesh.startEditing();
feamesh->swap(copy);
fea->Mesh.finishEditing();
}
(*it)->purgeTouched();
}
commitCommand();