Mesh: Apply clang-format
This commit is contained in:
@@ -22,15 +22,15 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <algorithm>
|
||||
# include <climits>
|
||||
# include <QBitmap>
|
||||
#include <QBitmap>
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
|
||||
# include <Inventor/SbBox2s.h>
|
||||
# include <Inventor/SoPickedPoint.h>
|
||||
# include <Inventor/details/SoFaceDetail.h>
|
||||
# include <Inventor/events/SoMouseButtonEvent.h>
|
||||
# include <Inventor/nodes/SoCamera.h>
|
||||
#include <Inventor/SbBox2s.h>
|
||||
#include <Inventor/SoPickedPoint.h>
|
||||
#include <Inventor/details/SoFaceDetail.h>
|
||||
#include <Inventor/events/SoMouseButtonEvent.h>
|
||||
#include <Inventor/nodes/SoCamera.h>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
@@ -44,10 +44,10 @@
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/View3DInventor.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
#include <Mod/Mesh/App/Core/MeshKernel.h>
|
||||
#include <Mod/Mesh/App/Core/Iterator.h>
|
||||
#include <Mod/Mesh/App/Core/MeshKernel.h>
|
||||
#include <Mod/Mesh/App/Core/TopoAlgorithm.h>
|
||||
#include <Mod/Mesh/App/MeshFeature.h>
|
||||
|
||||
#include "MeshSelection.h"
|
||||
#include "ViewProvider.h"
|
||||
@@ -60,19 +60,19 @@ using namespace MeshGui;
|
||||
#define CROSS_HOT_X 7
|
||||
#define CROSS_HOT_Y 7
|
||||
|
||||
// clang-format off
|
||||
unsigned char MeshSelection::cross_bitmap[] = {
|
||||
0xc0, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02,
|
||||
0x40, 0x02, 0x40, 0x02, 0x7f, 0xfe, 0x01, 0x80,
|
||||
0x01, 0x80, 0x7f, 0xfe, 0x40, 0x02, 0x40, 0x02,
|
||||
0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0xc0, 0x03
|
||||
};
|
||||
0xc0, 0x03, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02,
|
||||
0x40, 0x02, 0x40, 0x02, 0x7f, 0xfe, 0x01, 0x80,
|
||||
0x01, 0x80, 0x7f, 0xfe, 0x40, 0x02, 0x40, 0x02,
|
||||
0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0xc0, 0x03};
|
||||
|
||||
unsigned char MeshSelection::cross_mask_bitmap[] = {
|
||||
0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03,
|
||||
0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03,
|
||||
0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03
|
||||
};
|
||||
0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03,
|
||||
0xc0, 0x03, 0xc0, 0x03, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xc0, 0x03, 0xc0, 0x03,
|
||||
0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03, 0xc0, 0x03};
|
||||
// clang-format on
|
||||
|
||||
MeshSelection::MeshSelection()
|
||||
{
|
||||
@@ -83,8 +83,9 @@ MeshSelection::~MeshSelection()
|
||||
{
|
||||
if (this->activeCB) {
|
||||
Gui::View3DInventorViewer* viewer = this->getViewer();
|
||||
if (viewer)
|
||||
if (viewer) {
|
||||
stopInteractiveCallback(viewer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ void MeshSelection::setEnabledViewerSelection(bool on)
|
||||
}
|
||||
}
|
||||
|
||||
void MeshSelection::setCallback(SoEventCallbackCB *cb)
|
||||
void MeshSelection::setCallback(SoEventCallbackCB* cb)
|
||||
{
|
||||
selectionCB = cb;
|
||||
}
|
||||
@@ -120,8 +121,9 @@ std::vector<App::DocumentObject*> MeshSelection::getObjects() const
|
||||
// get all objects of the active document
|
||||
else {
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
if (doc)
|
||||
if (doc) {
|
||||
objs = doc->getObjectsOfType(Mesh::Feature::getClassTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
@@ -134,8 +136,9 @@ std::list<ViewProviderMesh*> MeshSelection::getViewProviders() const
|
||||
for (auto obj : objs) {
|
||||
if (obj->isDerivedFrom(Mesh::Feature::getClassTypeId())) {
|
||||
Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(obj);
|
||||
if (vp->isVisible())
|
||||
if (vp->isVisible()) {
|
||||
vps.push_back(static_cast<ViewProviderMesh*>(vp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,12 +153,14 @@ void MeshSelection::setViewer(Gui::View3DInventorViewer* v)
|
||||
Gui::View3DInventorViewer* MeshSelection::getViewer() const
|
||||
{
|
||||
// if a special viewer was set from outside then use this
|
||||
if (ivViewer)
|
||||
if (ivViewer) {
|
||||
return ivViewer;
|
||||
}
|
||||
|
||||
Gui::Document* doc = Gui::Application::Instance->activeDocument();
|
||||
if (!doc)
|
||||
if (!doc) {
|
||||
return nullptr;
|
||||
}
|
||||
Gui::MDIView* view = doc->getActiveView();
|
||||
if (view && view->getTypeId().isDerivedFrom(Gui::View3DInventor::getClassTypeId())) {
|
||||
Gui::View3DInventorViewer* viewer = static_cast<Gui::View3DInventor*>(view)->getViewer();
|
||||
@@ -165,10 +170,12 @@ Gui::View3DInventorViewer* MeshSelection::getViewer() const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer,SoEventCallbackCB *cb)
|
||||
void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer,
|
||||
SoEventCallbackCB* cb)
|
||||
{
|
||||
if (this->activeCB)
|
||||
if (this->activeCB) {
|
||||
return;
|
||||
}
|
||||
viewer->setEditing(true);
|
||||
viewer->addEventCallback(SoMouseButtonEvent::getClassTypeId(), cb, this);
|
||||
this->activeCB = cb;
|
||||
@@ -176,14 +183,15 @@ void MeshSelection::startInteractiveCallback(Gui::View3DInventorViewer* viewer,S
|
||||
|
||||
void MeshSelection::stopInteractiveCallback(Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
if (!this->activeCB)
|
||||
if (!this->activeCB) {
|
||||
return;
|
||||
}
|
||||
viewer->setEditing(false);
|
||||
viewer->removeEventCallback(SoMouseButtonEvent::getClassTypeId(), this->activeCB, this);
|
||||
this->activeCB = nullptr;
|
||||
}
|
||||
|
||||
void MeshSelection::prepareFreehandSelection(bool add,SoEventCallbackCB *cb)
|
||||
void MeshSelection::prepareFreehandSelection(bool add, SoEventCallbackCB* cb)
|
||||
{
|
||||
// a rubberband to select a rectangle area of the meshes
|
||||
Gui::View3DInventorViewer* viewer = this->getViewer();
|
||||
@@ -213,7 +221,9 @@ void MeshSelection::prepareFreehandSelection(bool add,SoEventCallbackCB *cb)
|
||||
viewer->setComponentCursor(custom);
|
||||
};
|
||||
|
||||
QObject::connect(viewer, &Gui::View3DInventorViewer::devicePixelRatioChanged, setComponentCursor);
|
||||
QObject::connect(viewer,
|
||||
&Gui::View3DInventorViewer::devicePixelRatioChanged,
|
||||
setComponentCursor);
|
||||
setComponentCursor();
|
||||
this->addToSelection = add;
|
||||
}
|
||||
@@ -266,15 +276,16 @@ bool MeshSelection::deleteSelection()
|
||||
std::list<ViewProviderMesh*> views = getViewProviders();
|
||||
for (auto view : views) {
|
||||
Mesh::Feature* mf = static_cast<Mesh::Feature*>(view->getObject());
|
||||
unsigned long ct = MeshCore::MeshAlgorithm(mf->Mesh.getValue().getKernel()).
|
||||
CountFacetFlag(MeshCore::MeshFacet::SELECTED);
|
||||
unsigned long ct = MeshCore::MeshAlgorithm(mf->Mesh.getValue().getKernel())
|
||||
.CountFacetFlag(MeshCore::MeshFacet::SELECTED);
|
||||
if (ct > 0) {
|
||||
selected = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!selected)
|
||||
return false; // nothing todo
|
||||
if (!selected) {
|
||||
return false; // nothing todo
|
||||
}
|
||||
|
||||
for (auto view : views) {
|
||||
view->deleteSelection();
|
||||
@@ -350,14 +361,15 @@ void MeshSelection::selectComponent(int size)
|
||||
Mesh::Feature* mf = static_cast<Mesh::Feature*>(view->getObject());
|
||||
const Mesh::MeshObject* mo = mf->Mesh.getValuePtr();
|
||||
|
||||
std::vector<std::vector<Mesh::FacetIndex> > segm;
|
||||
std::vector<std::vector<Mesh::FacetIndex>> segm;
|
||||
MeshCore::MeshComponents comp(mo->getKernel());
|
||||
comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segm);
|
||||
comp.SearchForComponents(MeshCore::MeshComponents::OverEdge, segm);
|
||||
|
||||
std::vector<Mesh::FacetIndex> faces;
|
||||
for (const auto & jt : segm) {
|
||||
if (jt.size() < (Mesh::FacetIndex)size)
|
||||
for (const auto& jt : segm) {
|
||||
if (jt.size() < (Mesh::FacetIndex)size) {
|
||||
faces.insert(faces.end(), jt.begin(), jt.end());
|
||||
}
|
||||
}
|
||||
|
||||
view->addSelection(faces);
|
||||
@@ -371,14 +383,15 @@ void MeshSelection::deselectComponent(int size)
|
||||
Mesh::Feature* mf = static_cast<Mesh::Feature*>(view->getObject());
|
||||
const Mesh::MeshObject* mo = mf->Mesh.getValuePtr();
|
||||
|
||||
std::vector<std::vector<Mesh::FacetIndex> > segm;
|
||||
std::vector<std::vector<Mesh::FacetIndex>> segm;
|
||||
MeshCore::MeshComponents comp(mo->getKernel());
|
||||
comp.SearchForComponents(MeshCore::MeshComponents::OverEdge,segm);
|
||||
comp.SearchForComponents(MeshCore::MeshComponents::OverEdge, segm);
|
||||
|
||||
std::vector<Mesh::FacetIndex> faces;
|
||||
for (const auto & jt : segm) {
|
||||
if (jt.size() > (Mesh::FacetIndex)size)
|
||||
for (const auto& jt : segm) {
|
||||
if (jt.size() > (Mesh::FacetIndex)size) {
|
||||
faces.insert(faces.end(), jt.begin(), jt.end());
|
||||
}
|
||||
}
|
||||
|
||||
view->removeSelection(faces);
|
||||
@@ -441,27 +454,30 @@ void MeshSelection::setRemoveComponentOnClick(bool on)
|
||||
removeComponent = on;
|
||||
}
|
||||
|
||||
void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n)
|
||||
void MeshSelection::selectGLCallback(void* ud, SoEventCallback* n)
|
||||
{
|
||||
// When this callback function is invoked we must leave the edit mode
|
||||
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
|
||||
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
|
||||
MeshSelection* self = static_cast<MeshSelection*>(ud);
|
||||
self->stopInteractiveCallback(view);
|
||||
n->setHandled();
|
||||
std::vector<SbVec2f> polygon = view->getGLPolygon();
|
||||
if (polygon.size() < 3)
|
||||
if (polygon.size() < 3) {
|
||||
return;
|
||||
if (polygon.front() != polygon.back())
|
||||
}
|
||||
if (polygon.front() != polygon.back()) {
|
||||
polygon.push_back(polygon.front());
|
||||
}
|
||||
|
||||
SbVec3f pnt, dir;
|
||||
view->getNearPlane(pnt, dir);
|
||||
Base::Vector3f normal(dir[0],dir[1],dir[2]);
|
||||
Base::Vector3f normal(dir[0], dir[1], dir[2]);
|
||||
|
||||
std::list<ViewProviderMesh*> views = self->getViewProviders();
|
||||
for (auto vp : views) {
|
||||
std::vector<Mesh::FacetIndex> faces;
|
||||
const Mesh::MeshObject& mesh = static_cast<Mesh::Feature*>(vp->getObject())->Mesh.getValue();
|
||||
const Mesh::MeshObject& mesh =
|
||||
static_cast<Mesh::Feature*>(vp->getObject())->Mesh.getValue();
|
||||
const MeshCore::MeshKernel& kernel = mesh.getKernel();
|
||||
|
||||
// simply get all triangles under the polygon
|
||||
@@ -475,20 +491,24 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n)
|
||||
|
||||
if (self->onlyVisibleTriangles) {
|
||||
const SbVec2s& sz = view->getSoRenderManager()->getViewportRegion().getWindowSize();
|
||||
short width,height; sz.getValue(width,height);
|
||||
short width, height;
|
||||
sz.getValue(width, height);
|
||||
std::vector<SbVec2s> pixelPoly = view->getPolygon();
|
||||
SbBox2s rect;
|
||||
for (const auto & p : pixelPoly) {
|
||||
rect.extendBy(SbVec2s(p[0],height-p[1]));
|
||||
for (const auto& p : pixelPoly) {
|
||||
rect.extendBy(SbVec2s(p[0], height - p[1]));
|
||||
}
|
||||
std::vector<Mesh::FacetIndex> rf; rf.swap(faces);
|
||||
std::vector<Mesh::FacetIndex> vf = vp->getVisibleFacetsAfterZoom
|
||||
(rect, view->getSoRenderManager()->getViewportRegion(), view->getSoRenderManager()->getCamera());
|
||||
std::vector<Mesh::FacetIndex> rf;
|
||||
rf.swap(faces);
|
||||
std::vector<Mesh::FacetIndex> vf =
|
||||
vp->getVisibleFacetsAfterZoom(rect,
|
||||
view->getSoRenderManager()->getViewportRegion(),
|
||||
view->getSoRenderManager()->getCamera());
|
||||
|
||||
// get common facets of the viewport and the visible one
|
||||
std::sort(vf.begin(), vf.end());
|
||||
std::sort(rf.begin(), rf.end());
|
||||
std::back_insert_iterator<std::vector<Mesh::FacetIndex> > biit(faces);
|
||||
std::back_insert_iterator<std::vector<Mesh::FacetIndex>> biit(faces);
|
||||
std::set_intersection(vf.begin(), vf.end(), rf.begin(), rf.end(), biit);
|
||||
}
|
||||
|
||||
@@ -507,26 +527,30 @@ void MeshSelection::selectGLCallback(void * ud, SoEventCallback * n)
|
||||
faces.swap(screen);
|
||||
}
|
||||
|
||||
if (self->addToSelection)
|
||||
if (self->addToSelection) {
|
||||
vp->addSelection(faces);
|
||||
else
|
||||
}
|
||||
else {
|
||||
vp->removeSelection(faces);
|
||||
}
|
||||
}
|
||||
|
||||
view->redraw();
|
||||
}
|
||||
|
||||
void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n)
|
||||
void MeshSelection::pickFaceCallback(void* ud, SoEventCallback* n)
|
||||
{
|
||||
// handle only mouse button events
|
||||
if (n->getEvent()->isOfType(SoMouseButtonEvent::getClassTypeId())) {
|
||||
const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent());
|
||||
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
|
||||
const SoMouseButtonEvent* mbe = static_cast<const SoMouseButtonEvent*>(n->getEvent());
|
||||
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
|
||||
|
||||
// Mark all incoming mouse button events as handled, especially, to deactivate the selection node
|
||||
// Mark all incoming mouse button events as handled, especially, to deactivate the selection
|
||||
// node
|
||||
n->getAction()->setHandled();
|
||||
if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) {
|
||||
const SoPickedPoint * point = n->getPickedPoint();
|
||||
if (mbe->getButton() == SoMouseButtonEvent::BUTTON1
|
||||
&& mbe->getState() == SoButtonEvent::DOWN) {
|
||||
const SoPickedPoint* point = n->getPickedPoint();
|
||||
if (!point) {
|
||||
Base::Console().Message("No facet picked.\n");
|
||||
return;
|
||||
@@ -537,28 +561,34 @@ void MeshSelection::pickFaceCallback(void * ud, SoEventCallback * n)
|
||||
// By specifying the indexed mesh node 'pcFaceSet' we make sure that the picked point is
|
||||
// really from the mesh we render and not from any other geometry
|
||||
Gui::ViewProvider* vp = view->getViewProviderByPathFromTail(point->getPath());
|
||||
if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId()))
|
||||
if (!vp || !vp->getTypeId().isDerivedFrom(ViewProviderMesh::getClassTypeId())) {
|
||||
return;
|
||||
}
|
||||
ViewProviderMesh* mesh = static_cast<ViewProviderMesh*>(vp);
|
||||
MeshSelection* self = static_cast<MeshSelection*>(ud);
|
||||
std::list<ViewProviderMesh*> views = self->getViewProviders();
|
||||
if (std::find(views.begin(), views.end(), mesh) == views.end())
|
||||
if (std::find(views.begin(), views.end(), mesh) == views.end()) {
|
||||
return;
|
||||
}
|
||||
const SoDetail* detail = point->getDetail(/*mesh->getShapeNode()*/);
|
||||
if (detail && detail->getTypeId() == SoFaceDetail::getClassTypeId()) {
|
||||
// get the boundary to the picked facet
|
||||
Mesh::FacetIndex uFacet = static_cast<const SoFaceDetail*>(detail)->getFaceIndex();
|
||||
if (self->addToSelection) {
|
||||
if (self->addComponent)
|
||||
if (self->addComponent) {
|
||||
mesh->selectComponent(uFacet);
|
||||
else
|
||||
}
|
||||
else {
|
||||
mesh->selectFacet(uFacet);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (self->removeComponent)
|
||||
if (self->removeComponent) {
|
||||
mesh->deselectComponent(uFacet);
|
||||
else
|
||||
}
|
||||
else {
|
||||
mesh->deselectFacet(uFacet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user