From 4cb20dc783acf023e23878f807392a002ced498f Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 7 Sep 2016 21:51:05 +0200 Subject: [PATCH] support coloring of mesh segments --- src/Mod/Mesh/Gui/ViewProvider.cpp | 31 +++++++++++++++++++++++++++ src/Mod/Mesh/Gui/ViewProvider.h | 1 + src/Mod/MeshPart/Gui/CMakeLists.txt | 2 ++ src/Mod/MeshPart/Gui/PreCompiled.h | 10 ++++++--- src/Mod/MeshPart/Gui/Tessellation.cpp | 17 +++++++++++++++ 5 files changed, 58 insertions(+), 3 deletions(-) diff --git a/src/Mod/Mesh/Gui/ViewProvider.cpp b/src/Mod/Mesh/Gui/ViewProvider.cpp index 4a138fb94..46c4d6629 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.cpp +++ b/src/Mod/Mesh/Gui/ViewProvider.cpp @@ -1913,6 +1913,37 @@ void ViewProviderMesh::highlightComponents() pcShapeMaterial->diffuseColor.finishEditing(); } +void ViewProviderMesh::highlightSegments(const std::vector& colors) +{ + const Mesh::MeshObject& rMesh = static_cast(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 segm = rMesh.getSegment(i).getIndices(); + float fRed = colors[i].r; + float fGrn = colors[i].g; + float fBlu = colors[i].b; + for (std::vector::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) diff --git a/src/Mod/Mesh/Gui/ViewProvider.h b/src/Mod/Mesh/Gui/ViewProvider.h index f1ff82bf4..95d4ffa5c 100644 --- a/src/Mod/Mesh/Gui/ViewProvider.h +++ b/src/Mod/Mesh/Gui/ViewProvider.h @@ -160,6 +160,7 @@ public: /*! The size of the array must be equal to the number of facets. */ void setFacetTransparency(const std::vector&); void resetFacetTransparency(); + void highlightSegments(const std::vector&); //@} protected: diff --git a/src/Mod/MeshPart/Gui/CMakeLists.txt b/src/Mod/MeshPart/Gui/CMakeLists.txt index 8b49d9725..19a33373a 100644 --- a/src/Mod/MeshPart/Gui/CMakeLists.txt +++ b/src/Mod/MeshPart/Gui/CMakeLists.txt @@ -28,6 +28,8 @@ link_directories(${OCC_LIBRARY_DIR}) set(MeshPartGui_LIBS MeshPart + PartGui + MeshGui FreeCADGui ) diff --git a/src/Mod/MeshPart/Gui/PreCompiled.h b/src/Mod/MeshPart/Gui/PreCompiled.h index 5711c8c84..26f83b65e 100644 --- a/src/Mod/MeshPart/Gui/PreCompiled.h +++ b/src/Mod/MeshPart/Gui/PreCompiled.h @@ -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 // standard @@ -74,7 +78,7 @@ #ifndef __Qt4All__ # include #endif - + #endif //_PreComp_ #endif // __PRECOMPILED_GUI__ diff --git a/src/Mod/MeshPart/Gui/Tessellation.cpp b/src/Mod/MeshPart/Gui/Tessellation.cpp index 108c21d87..3e0aff532 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.cpp +++ b/src/Mod/MeshPart/Gui/Tessellation.cpp @@ -41,6 +41,8 @@ #include #include #include +#include +#include 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(vpm); + PartGui::ViewProviderPart* vppart = dynamic_cast(vpp); + if (vpmesh && vppart) { + vpmesh->highlightSegments(vppart->DiffuseColor.getValues()); + } + } + } } activeDoc->commitTransaction(); }