support coloring of mesh segments

This commit is contained in:
wmayer 2016-09-07 21:51:05 +02:00
parent 361951eac3
commit 4cb20dc783
5 changed files with 58 additions and 3 deletions

View File

@ -1913,6 +1913,37 @@ void ViewProviderMesh::highlightComponents()
pcShapeMaterial->diffuseColor.finishEditing();
}
void ViewProviderMesh::highlightSegments(const std::vector<App::Color>& colors)
{
const Mesh::MeshObject& rMesh = static_cast<Mesh::Feature*>(pcObject)->Mesh.getValue();
unsigned long numSegm = rMesh.countSegments();
if (numSegm == colors.size()) {
// Colorize the components
pcMatBinding->value = SoMaterialBinding::PER_FACE;
int uCtFacets = (int)rMesh.countFacets();
pcShapeMaterial->diffuseColor.setNum(uCtFacets);
SbColor* cols = pcShapeMaterial->diffuseColor.startEditing();
for (unsigned long i=0; i<numSegm; i++) {
std::vector<unsigned long> segm = rMesh.getSegment(i).getIndices();
float fRed = colors[i].r;
float fGrn = colors[i].g;
float fBlu = colors[i].b;
for (std::vector<unsigned long>::iterator it = segm.begin(); it != segm.end(); ++it) {
cols[*it].setValue(fRed,fGrn,fBlu);
}
}
pcShapeMaterial->diffuseColor.finishEditing();
}
else if (colors.size() == 1) {
pcMatBinding->value = SoMaterialBinding::OVERALL;
float fRed = colors[0].r;
float fGrn = colors[0].g;
float fBlu = colors[0].b;
pcShapeMaterial->diffuseColor.setValue(fRed,fGrn,fBlu);
}
}
// ------------------------------------------------------
PROPERTY_SOURCE(MeshGui::ViewProviderIndexedFaceSet, MeshGui::ViewProviderMesh)

View File

@ -160,6 +160,7 @@ public:
/*! The size of the array must be equal to the number of facets. */
void setFacetTransparency(const std::vector<float>&);
void resetFacetTransparency();
void highlightSegments(const std::vector<App::Color>&);
//@}
protected:

View File

@ -28,6 +28,8 @@ link_directories(${OCC_LIBRARY_DIR})
set(MeshPartGui_LIBS
MeshPart
PartGui
MeshGui
FreeCADGui
)

View File

@ -30,11 +30,15 @@
#ifdef FC_OS_WIN32
# define MeshExport __declspec(dllimport)
# define PartExport __declspec(dllimport)
# define MeshGuiExport __declspec(dllimport)
# define PartGuiExport __declspec(dllimport)
# define MeshPartAppExport __declspec(dllimport)
# define MeshPartGuiExport __declspec(dllexport)
#else // for Linux
# define MeshExport
# define PartExport
# define MeshGuiExport
# define PartGuiExport
# define MeshPartAppExport
# define MeshPartGuiExport
#endif
@ -45,8 +49,8 @@
#endif
#ifdef _PreComp_
// Python
// Python
#include <Python.h>
// standard
@ -74,7 +78,7 @@
#ifndef __Qt4All__
# include <Gui/Qt4All.h>
#endif
#endif //_PreComp_
#endif // __PRECOMPILED_GUI__

View File

@ -41,6 +41,8 @@
#include <Gui/ViewProvider.h>
#include <Gui/WaitCursor.h>
#include <Mod/Part/App/PartFeature.h>
#include <Mod/Mesh/Gui/ViewProvider.h>
#include <Mod/Part/Gui/ViewProvider.h>
using namespace MeshPartGui;
@ -327,6 +329,21 @@ bool Tessellation::accept()
}
}
Gui::Command::doCommand(Gui::Command::Doc, (const char*)cmd.toUtf8());
// if Standard mesher is used and face colors should be applied
if (method == 0) { // Standard
if (ui->meshShapeColors->isChecked()) {
Gui::ViewProvider* vpm = Gui::Application::Instance->getViewProvider
(activeDoc->getActiveObject());
Gui::ViewProvider* vpp = Gui::Application::Instance->getViewProvider
(activeDoc->getObject(shape.toLatin1()));
MeshGui::ViewProviderMesh* vpmesh = dynamic_cast<MeshGui::ViewProviderMesh*>(vpm);
PartGui::ViewProviderPart* vppart = dynamic_cast<PartGui::ViewProviderPart*>(vpp);
if (vpmesh && vppart) {
vpmesh->highlightSegments(vppart->DiffuseColor.getValues());
}
}
}
}
activeDoc->commitTransaction();
}