replace boolean to check for inside/outside cutting with enum values

This commit is contained in:
wmayer
2018-09-18 18:25:51 +02:00
parent 2290a37a83
commit 644cfa06bb
16 changed files with 248 additions and 72 deletions

View File

@@ -916,8 +916,8 @@ void DefineNodesCallback(void * ud, SoEventCallback * n)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineNodesCallback,ud);
n->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
Gui::SelectionRole role;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&role);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())

View File

@@ -141,8 +141,8 @@ void TaskCreateNodeSet::DefineNodesCallback(void * ud, SoEventCallback * n)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), DefineNodesCallback,ud);
n->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
Gui::SelectionRole role;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&role);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())
@@ -155,8 +155,7 @@ void TaskCreateNodeSet::DefineNodesCallback(void * ud, SoEventCallback * n)
for (std::vector<SbVec2f>::const_iterator it = clPoly.begin(); it != clPoly.end(); ++it)
polygon.Add(Base::Vector2d((*it)[0],(*it)[1]));
taskBox->DefineNodes(polygon,proj,clip_inner);
taskBox->DefineNodes(polygon,proj,role == Gui::SelectionRole::Inner ? true : false);
}
void TaskCreateNodeSet::DefineNodes(const Base::Polygon2d &polygon,const Gui::ViewVolumeProjection &proj,bool inner)

View File

@@ -743,7 +743,8 @@ void CmdMeshPolySegm::activated(int)
Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
viewer->setEditing(true);
viewer->startSelection(Gui::View3DInventorViewer::Clip);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::segmMeshCallback);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
MeshGui::ViewProviderMeshFaceSet::segmMeshCallback);
}
else {
return;
@@ -898,10 +899,12 @@ void CmdMeshPolyCut::activated(int)
viewer->setEditing(true);
Gui::PolyClipSelection* clip = new Gui::PolyClipSelection();
clip->setRole(Gui::SelectionRole::Split, true);
clip->setColor(0.0f,0.0f,1.0f);
clip->setLineWidth(1.0f);
viewer->navigationStyle()->startSelection(clip);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::clipMeshCallback);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
MeshGui::ViewProviderMeshFaceSet::clipMeshCallback);
}
else {
return;
@@ -954,9 +957,14 @@ void CmdMeshPolyTrim::activated(int)
if (view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
viewer->setEditing(true);
viewer->startSelection(Gui::View3DInventorViewer::Clip);
Gui::PolyClipSelection* clip = new Gui::PolyClipSelection();
clip->setRole(Gui::SelectionRole::Split, true);
clip->setColor(0.0f,0.0f,1.0f);
clip->setLineWidth(1.0f);
viewer->navigationStyle()->startSelection(clip);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
MeshGui::ViewProviderMeshFaceSet::trimMeshCallback);
MeshGui::ViewProviderMeshFaceSet::trimMeshCallback);
}
else {
return;
@@ -1066,7 +1074,8 @@ void CmdMeshPolySplit::activated(int)
Gui::View3DInventorViewer* viewer = ((Gui::View3DInventor*)view)->getViewer();
viewer->setEditing(true);
viewer->startSelection(Gui::View3DInventorViewer::Clip);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), MeshGui::ViewProviderMeshFaceSet::partMeshCallback);
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(),
MeshGui::ViewProviderMeshFaceSet::partMeshCallback);
}
else {
return;

View File

@@ -27,6 +27,7 @@
# include <stdlib.h>
# include <QAction>
# include <QMenu>
# include <QTimer>
# include <Inventor/SbBox2s.h>
# include <Inventor/SbLine.h>
# include <Inventor/SbPlane.h>
@@ -813,6 +814,58 @@ void ViewProviderMesh::showOpenEdges(bool show)
(void)show;
}
namespace MeshGui {
class MeshSplit {
public:
MeshSplit(ViewProviderMesh* mesh,
const std::vector<SbVec2f>& poly,
const Gui::ViewVolumeProjection& proj)
: mesh(mesh)
, poly(poly)
, proj(proj)
{
}
~MeshSplit() {
}
void cutMesh() {
Gui::Document* gui = mesh->getDocument();
gui->openCommand("Cut");
ViewProviderMesh* copy = makeCopy();
mesh->cutMesh(poly, proj, false);
copy->cutMesh(poly, proj, true);
gui->commitCommand();
delete this;
}
void trimMesh() {
Gui::Document* gui = mesh->getDocument();
gui->openCommand("Trim");
ViewProviderMesh* copy = makeCopy();
mesh->trimMesh(poly, proj, false);
copy->trimMesh(poly, proj, true);
gui->commitCommand();
delete this;
}
ViewProviderMesh* makeCopy() const {
Gui::Document* gui = mesh->getDocument();
App::Document* doc = gui->getDocument();
Mesh::Feature* cpy = static_cast<Mesh::Feature*>(doc->addObject("Mesh::Feature"));
Mesh::Feature* org = static_cast<Mesh::Feature*>(mesh->getObject());
cpy->Label.setValue(org->Label.getValue());
cpy->Mesh.setValue(org->Mesh.getValue());
return static_cast<ViewProviderMesh*>(gui->getViewProvider(cpy));
}
private:
ViewProviderMesh* mesh;
Gui::ViewVolumeProjection proj;
std::vector<SbVec2f> poly;
};
}
void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
{
// show the wait cursor because this could take quite some time
@@ -824,8 +877,8 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), clipMeshCallback,ud);
n->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
Gui::SelectionRole role;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&role);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())
@@ -834,6 +887,7 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
if (!views.empty()) {
Gui::Application::Instance->activeDocument()->openCommand("Cut");
bool commitCommand = false;
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(*it);
if (self->getEditingMode() > -1) {
@@ -843,11 +897,31 @@ void ViewProviderMesh::clipMeshCallback(void * ud, SoEventCallback * n)
Gui::ViewVolumeProjection proj(vv);
proj.setTransform(static_cast<Mesh::Feature*>(self->getObject())->
Placement.getValue().toMatrix());
self->cutMesh(clPoly, proj, clip_inner);
if (role == Gui::SelectionRole::Inner) {
self->cutMesh(clPoly, proj, true);
commitCommand = true;
}
else if (role == Gui::SelectionRole::Outer) {
self->cutMesh(clPoly, proj, false);
commitCommand = true;
}
else if (role == Gui::SelectionRole::Split) {
// We must delay the split because it adds a new
// node to the scenegraph which cannot be done while
// traversing it
Gui::TimerFunction* func = new Gui::TimerFunction();
func->setAutoDelete(true);
MeshSplit* split = new MeshSplit(self, clPoly, proj);
func->setFunction(boost::bind(&MeshSplit::cutMesh, split));
QTimer::singleShot(0, func, SLOT(timeout()));
}
}
}
Gui::Application::Instance->activeDocument()->commitCommand();
if (commitCommand)
Gui::Application::Instance->activeDocument()->commitCommand();
else
Gui::Application::Instance->activeDocument()->abortCommand();
view->redraw();
}
@@ -864,8 +938,8 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), trimMeshCallback,ud);
n->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
Gui::SelectionRole role;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&role);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())
@@ -873,7 +947,8 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n)
std::vector<Gui::ViewProvider*> views = view->getViewProvidersOfType(ViewProviderMesh::getClassTypeId());
if (!views.empty()) {
Gui::Application::Instance->activeDocument()->openCommand("Cut");
Gui::Application::Instance->activeDocument()->openCommand("Trim");
bool commitCommand = false;
for (std::vector<Gui::ViewProvider*>::iterator it = views.begin(); it != views.end(); ++it) {
ViewProviderMesh* self = static_cast<ViewProviderMesh*>(*it);
if (self->getEditingMode() > -1) {
@@ -883,11 +958,31 @@ void ViewProviderMesh::trimMeshCallback(void * ud, SoEventCallback * n)
Gui::ViewVolumeProjection proj(vv);
proj.setTransform(static_cast<Mesh::Feature*>(self->getObject())->
Placement.getValue().toMatrix());
self->trimMesh(clPoly, proj, clip_inner);
if (role == Gui::SelectionRole::Inner) {
self->trimMesh(clPoly, proj, true);
commitCommand = true;
}
else if (role == Gui::SelectionRole::Outer) {
self->trimMesh(clPoly, proj, false);
commitCommand = true;
}
else if (role == Gui::SelectionRole::Split) {
// We must delay the split because it adds a new
// node to the scenegraph which cannot be done while
// traversing it
Gui::TimerFunction* func = new Gui::TimerFunction();
func->setAutoDelete(true);
MeshSplit* split = new MeshSplit(self, clPoly, proj);
func->setFunction(boost::bind(&MeshSplit::trimMesh, split));
QTimer::singleShot(0, func, SLOT(timeout()));
}
}
}
Gui::Application::Instance->activeDocument()->commitCommand();
if (commitCommand)
Gui::Application::Instance->activeDocument()->commitCommand();
else
Gui::Application::Instance->activeDocument()->abortCommand();
view->redraw();
}
@@ -904,8 +999,8 @@ void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), partMeshCallback,ud);
cb->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
Gui::SelectionRole role;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&role);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())
@@ -941,7 +1036,10 @@ void ViewProviderMesh::partMeshCallback(void * ud, SoEventCallback * cb)
plm.invert();
MeshCore::MeshKernel copyToolMesh(toolMesh);
copyToolMesh.Transform(plm.toMatrix());
that->splitMesh(copyToolMesh, cNormal, clip_inner);
if (role == Gui::SelectionRole::Inner)
that->splitMesh(copyToolMesh, cNormal, true);
else
that->splitMesh(copyToolMesh, cNormal, false);
}
}
}
@@ -965,8 +1063,8 @@ void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb)
view->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), segmMeshCallback,ud);
cb->setHandled();
SbBool clip_inner;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&clip_inner);
Gui::SelectionRole role;
std::vector<SbVec2f> clPoly = view->getGLPolygon(&role);
if (clPoly.size() < 3)
return;
if (clPoly.front() != clPoly.back())
@@ -1002,7 +1100,10 @@ void ViewProviderMesh::segmMeshCallback(void * ud, SoEventCallback * cb)
plm.invert();
MeshCore::MeshKernel copyToolMesh(toolMesh);
copyToolMesh.Transform(plm.toMatrix());
that->segmentMesh(copyToolMesh, cNormal, clip_inner);
if (role == Gui::SelectionRole::Inner)
that->segmentMesh(copyToolMesh, cNormal, true);
else
that->segmentMesh(copyToolMesh, cNormal, false);
}
}
}

View File

@@ -158,6 +158,8 @@ public:
std::vector<unsigned long> getFacetsOfRegion(const SbViewportRegion&, const SbViewportRegion&, SoCamera*) const;
std::vector<unsigned long> getVisibleFacetsAfterZoom(const SbBox2s&, const SbViewportRegion&, SoCamera*) const;
std::vector<unsigned long> getVisibleFacets(const SbViewportRegion&, SoCamera*) const;
virtual void cutMesh(const std::vector<SbVec2f>& picked, const Base::ViewProjMethod& proj, SbBool inner);
virtual void trimMesh(const std::vector<SbVec2f>& picked, const Base::ViewProjMethod& proj, SbBool inner);
virtual void removeFacets(const std::vector<unsigned long>&);
/*! The size of the array must be equal to the number of facets. */
void setFacetTransparency(const std::vector<float>&);
@@ -174,8 +176,6 @@ protected:
void onChanged(const App::Property* prop);
virtual void showOpenEdges(bool);
void setOpenEdgeColorFrom(const App::Color& col);
virtual void cutMesh(const std::vector<SbVec2f>& picked, const Base::ViewProjMethod& proj, SbBool inner);
virtual void trimMesh(const std::vector<SbVec2f>& picked, const Base::ViewProjMethod& proj, SbBool inner);
virtual void splitMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner);
virtual void segmentMesh(const MeshCore::MeshKernel& toolMesh, const Base::Vector3f& normal, SbBool inner);
virtual void faceInfo(unsigned long facet);

View File

@@ -192,9 +192,8 @@ Gui::MenuItem* Workbench::setupMenuBar() const
Gui::MenuItem* cutting = new Gui::MenuItem;
cutting->setCommand("Cutting");
*cutting << "Mesh_PolyCut"
<< "Mesh_PolySplit"
<< "Mesh_PolySegm"
<< "Mesh_PolyTrim"
//<< "Mesh_PolySegm"
<< "Mesh_TrimByPlane"
<< "Mesh_SectionByPlane";

View File

@@ -102,26 +102,20 @@ void CmdMeshPartTrimByPlane::activated(int)
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);
QPushButton* split = msgBox.addButton(qApp->translate("MeshPart_TrimByPlane","Split"), QMessageBox::ActionRole);
msgBox.setDefaultButton(inner);
msgBox.exec();
QAbstractButton* click = msgBox.clickedButton();
enum Side {
Inner,
Outer,
Both
};
Side side;
Gui::SelectionRole role;
if (inner == click) {
side = Inner;
role = Gui::SelectionRole::Inner;
}
else if (outer == click) {
side = Outer;
role = Gui::SelectionRole::Outer;
}
else if (both == click) {
side = Both;
else if (split == click) {
role = Gui::SelectionRole::Split;
}
else {
// abort
@@ -168,15 +162,15 @@ void CmdMeshPartTrimByPlane::activated(int)
polygon2d.Add(Base::Vector2d(p3.x, p3.y));
polygon2d.Add(Base::Vector2d(p4.x, p4.y));
if (side == Inner) {
if (role == Gui::SelectionRole::Inner) {
mesh->trim(polygon2d, proj, Mesh::MeshObject::INNER);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
}
else if (side == Outer) {
else if (role == Gui::SelectionRole::Outer) {
mesh->trim(polygon2d, proj, Mesh::MeshObject::OUTER);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();
}
else if (side == Both) {
else if (role == Gui::SelectionRole::Split) {
Mesh::MeshObject copy(*mesh);
mesh->trim(polygon2d, proj, Mesh::MeshObject::INNER);
static_cast<Mesh::Feature*>(*it)->Mesh.finishEditing();