Skip to content

Commit

Permalink
+ edit command for meshes to display components
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Feb 20, 2015
1 parent 18f1cf7 commit 312f63e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Mod/Mesh/App/Mesh.h
Expand Up @@ -189,7 +189,7 @@ class MeshExport MeshObject : public Data::ComplexGeoData
* Checks for the given facet indices what will be the degree for each point
* when these facets are removed from the mesh kernel.
* The point degree information is stored in \a point_degree. The return value
* gices the number of points which will have a degree of zero.
* gives the number of points which will have a degree of zero.
*/
unsigned long getPointDegree(const std::vector<unsigned long>& facets,
std::vector<unsigned long>& point_degree) const;
Expand Down
36 changes: 36 additions & 0 deletions src/Mod/Mesh/Gui/ViewProvider.cpp
Expand Up @@ -24,6 +24,8 @@
#include "PreCompiled.h"

#ifndef _PreComp_
# include <stdlib.h>
# include <QAction>
# include <QMenu>
# include <Inventor/SbBox2s.h>
# include <Inventor/SbLine.h>
Expand Down Expand Up @@ -572,17 +574,28 @@ bool ViewProviderMesh::exportToVrml(const char* filename, const MeshCore::Materi
return false;
}

void ViewProviderMesh::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
ViewProviderGeometryObject::setupContextMenu(menu, receiver, member);
QAction* act = menu->addAction(QObject::tr("Display components"), receiver, member);
act->setData(QVariant((int)ViewProvider::Color));
}

bool ViewProviderMesh::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Transform)
return ViewProviderGeometryObject::setEdit(ModNum);
else if (ModNum == ViewProvider::Color)
highlightComponents();
return true;
}

void ViewProviderMesh::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Transform)
ViewProviderGeometryObject::unsetEdit(ModNum);
else if (ModNum == ViewProvider::Color)
unhighlightSelection();
}

bool ViewProviderMesh::createToolMesh(const std::vector<SbVec2f>& rclPoly, const SbViewVolume& vol,
Expand Down Expand Up @@ -1667,6 +1680,29 @@ void ViewProviderMesh::unhighlightSelection()
pcShapeMaterial->diffuseColor.setValue(c.r,c.g,c.b);
}

void ViewProviderMesh::highlightComponents()
{
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue();
std::vector<std::vector<unsigned long> > comps = rMesh.getComponents();

// Colorize the components
pcMatBinding->value = SoMaterialBinding::PER_FACE;
int uCtFacets = (int)rMesh.countFacets();
pcShapeMaterial->diffuseColor.setNum(uCtFacets);

SbColor* cols = pcShapeMaterial->diffuseColor.startEditing();
for (std::vector<std::vector<unsigned long> >::iterator it = comps.begin(); it != comps.end(); ++it) {
float fMax = (float)RAND_MAX;
float fRed = (float)rand()/fMax;
float fGrn = (float)rand()/fMax;
float fBlu = (float)rand()/fMax;
for (std::vector<unsigned long>::iterator jt = it->begin(); jt != it->end(); ++jt) {
cols[*jt].setValue(fRed,fGrn,fBlu);
}
}
pcShapeMaterial->diffuseColor.finishEditing();
}

// ------------------------------------------------------

PROPERTY_SOURCE(MeshGui::ViewProviderIndexedFaceSet, MeshGui::ViewProviderMesh)
Expand Down
2 changes: 2 additions & 0 deletions src/Mod/Mesh/Gui/ViewProvider.h
Expand Up @@ -129,6 +129,7 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject
/// returns a list of all possible modes
virtual std::vector<std::string> getDisplayModes(void) const;
bool exportToVrml(const char* filename, const MeshCore::Material&, bool binary=false) const;
void setupContextMenu(QMenu*, QObject*, const char*);

/** @name Editing */
//@{
Expand Down Expand Up @@ -169,6 +170,7 @@ class MeshGuiExport ViewProviderMesh : public Gui::ViewProviderGeometryObject
virtual void selectArea(short, short, short, short, const SbViewportRegion&, SoCamera*);
void highlightSelection();
void unhighlightSelection();
void highlightComponents();

virtual SoShape* getShapeNode() const;
virtual SoNode* getCoordNode() const;
Expand Down

0 comments on commit 312f63e

Please sign in to comment.