replace boolean to check for inside/outside cutting with enum values
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user