Merge pull request #13332 from wwmayer/fix_material_issues

Fix material issues
This commit is contained in:
Chris Hennes
2024-04-15 10:33:29 -05:00
committed by GitHub
25 changed files with 469 additions and 508 deletions

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ViewProviderDocumentObjectPy"
Father="ViewProviderGeometryObjectPy"
Name="ViewProviderFemConstraintPy"
Twin="ViewProviderFemConstraint"
TwinPointer="ViewProviderFemConstraint"
Include="Mod/Fem/Gui/ViewProviderFemConstraint.h"
Namespace="FemGui"
FatherInclude="Gui/ViewProviderDocumentObjectPy.h"
FatherInclude="Gui/ViewProviderGeometryObjectPy.h"
FatherNamespace="Gui">
<Documentation>
<Author Licence="LGPL" Name="Mario Passaglia" EMail="mpassaglia@cbc.uba.ar" />

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ViewProviderDocumentObjectPy"
Father="ViewProviderGeometryObjectPy"
Name="ViewProviderFemMeshPy"
Twin="ViewProviderFemMesh"
TwinPointer="ViewProviderFemMesh"
Include="Mod/Fem/Gui/ViewProviderFemMesh.h"
Namespace="FemGui"
FatherInclude="Gui/ViewProviderDocumentObjectPy.h"
FatherInclude="Gui/ViewProviderGeometryObjectPy.h"
FatherNamespace="Gui"
Constructor="false"
Delete="false">

View File

@@ -353,7 +353,6 @@ ViewProviderMesh::~ViewProviderMesh()
void ViewProviderMesh::onChanged(const App::Property* prop)
{
// we're going to change the number of colors to one
// if (prop == &ShapeAppearance || prop == &ShapeMaterial) {
if (prop == &ShapeAppearance) {
pcMatBinding->value = SoMaterialBinding::OVERALL;
}
@@ -397,9 +396,6 @@ void ViewProviderMesh::onChanged(const App::Property* prop)
if (prop == &ShapeAppearance) {
setOpenEdgeColorFrom(ShapeAppearance.getDiffuseColor());
}
// else if (prop == &ShapeMaterial) {
// setOpenEdgeColorFrom(ShapeMaterial.getValue().diffuseColor);
// }
}
ViewProviderGeometryObject::onChanged(prop);

View File

@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<GenerateModel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="generateMetaModel_Module.xsd">
<PythonExport
Father="ViewProviderDocumentObjectPy"
Father="ViewProviderGeometryObjectPy"
Name="ViewProviderMeshPy"
Twin="ViewProviderMesh"
TwinPointer="ViewProviderMesh"
Include="Mod/Mesh/Gui/ViewProvider.h"
Namespace="MeshGui"
FatherInclude="Gui/ViewProviderDocumentObjectPy.h"
FatherInclude="Gui/ViewProviderGeometryObjectPy.h"
FatherNamespace="Gui">
<Documentation>
<Author Licence="LGPL" Name="Werner Mayer" EMail="wmayer@users.sourceforge.net" />

View File

@@ -925,7 +925,7 @@ void CmdPartSection::activated(int iMsg)
doCommand(Doc,"App.activeDocument().%s.Tool = App.activeDocument().%s",FeatName.c_str(),ToolName.c_str());
doCommand(Gui,"Gui.activeDocument().hide('%s')",BaseName.c_str());
doCommand(Gui,"Gui.activeDocument().hide('%s')",ToolName.c_str());
doCommand(Gui,"Gui.activeDocument().%s.LineColor = Gui.activeDocument().%s.ShapeAppearance.DiffuseColor",FeatName.c_str(),BaseName.c_str());
doCommand(Gui,"Gui.activeDocument().%s.LineMaterial = Gui.activeDocument().%s.ShapeAppearance[0]",FeatName.c_str(),BaseName.c_str());
updateActive();
commitCommand();
}

View File

@@ -28,10 +28,11 @@
#include <App/Document.h>
#include <App/DocumentObject.h>
#include <App/DocumentObserver.h>
#include <Base/Exception.h>
#include <Base/Interpreter.h>
#include <Gui/Application.h>
#include <Gui/Command.h>
#include <Gui/CommandT.h>
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/SelectionObject.h>
@@ -368,19 +369,19 @@ void CmdPartRefineShape::activated(int iMsg)
openCommand(QT_TRANSLATE_NOOP("Command", "Refine shape"));
std::for_each(objs.begin(), objs.end(), [](App::DocumentObject* obj) {
try {
doCommand(Doc,"App.ActiveDocument.addObject('Part::Refine','%s').Source="
"App.ActiveDocument.%s\n"
"App.ActiveDocument.ActiveObject.Label="
"App.ActiveDocument.%s.Label\n"
"Gui.ActiveDocument.%s.hide()\n",
obj->getNameInDocument(),
obj->getNameInDocument(),
obj->getNameInDocument(),
obj->getNameInDocument());
App::DocumentObjectT objT(obj);
Gui::cmdAppDocumentArgs(obj->getDocument(), "addObject('Part::Refine','%s')",
obj->getNameInDocument());
Gui::cmdAppDocumentArgs(obj->getDocument(), "ActiveObject.Source = %s",
objT.getObjectPython());
Gui::cmdAppDocumentArgs(obj->getDocument(), "ActiveObject.Label = %s.Label",
objT.getObjectPython());
Gui::cmdAppObjectHide(obj);
copyVisual("ActiveObject", "ShapeAppearance", obj->getNameInDocument());
copyVisual("ActiveObject", "LineColor", obj->getNameInDocument());
copyVisual("ActiveObject", "PointColor", obj->getNameInDocument());
auto newObj = App::GetApplication().getActiveDocument()->getActiveObject();
Gui::copyVisualT(newObj->getNameInDocument(), "ShapeAppearance", obj->getNameInDocument());
Gui::copyVisualT(newObj->getNameInDocument(), "LineColor", obj->getNameInDocument());
Gui::copyVisualT(newObj->getNameInDocument(), "PointColor", obj->getNameInDocument());
}
catch (const Base::Exception& e) {
Base::Console().Warning("%s: %s\n", obj->Label.getValue(), e.what());

View File

@@ -716,22 +716,20 @@ void PartGui::DlgProjectionOnSurface::higlight_object(Part::Feature* iCurrentObj
}
auto index = anIndices.FindIndex(currentShape);
//set color
PartGui::ViewProviderPartExt* vp = dynamic_cast<PartGui::ViewProviderPartExt*>(Gui::Application::Instance->getViewProvider(iCurrentObject));
if (vp)
{
std::vector<App::Color> colors;
App::Color defaultColor;
if (currentShapeType == TopAbs_FACE)
{
colors = vp->DiffuseColor.getValues();
defaultColor = vp->ShapeAppearance.getDiffuseColor();
}
else if ( currentShapeType == TopAbs_EDGE )
{
colors = vp->LineColorArray.getValues();
defaultColor = vp->LineColor.getValue();
}
// set color
auto vp = dynamic_cast<PartGui::ViewProviderPartExt*>(
Gui::Application::Instance->getViewProvider(iCurrentObject));
if (vp) {
std::vector<App::Color> colors;
App::Color defaultColor;
if (currentShapeType == TopAbs_FACE) {
colors = vp->DiffuseColor.getValues();
defaultColor = vp->ShapeAppearance.getDiffuseColor();
}
else if (currentShapeType == TopAbs_EDGE) {
colors = vp->LineColorArray.getValues();
defaultColor = vp->LineColor.getValue();
}
if (static_cast<Standard_Integer>(colors.size()) != anIndices.Extent()) {
colors.resize(anIndices.Extent(), defaultColor);

View File

@@ -77,8 +77,9 @@ QIcon ViewProviderAttachExtension::extensionMergeColorfullOverlayIcons (const QI
void ViewProviderAttachExtension::extensionUpdateData(const App::Property* prop)
{
if (getExtendedViewProvider()->getObject()->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) {
auto* attach = getExtendedViewProvider()->getObject()->getExtensionByType<Part::AttachExtension>();
auto obj = getExtendedViewProvider()->getObject();
if (obj && obj->hasExtension(Part::AttachExtension::getExtensionClassTypeId())) {
auto* attach = obj->getExtensionByType<Part::AttachExtension>();
if(attach) {
if( prop == &(attach->AttachmentSupport) ||

View File

@@ -96,6 +96,19 @@ FC_LOG_LEVEL_INIT("Part", true, true)
using namespace PartGui;
// Helper functions to consistently convert between float and long
namespace {
float fromPercent(long value)
{
return static_cast<float>(value) / 100.0F;
}
long toPercent(float value)
{
return static_cast<long>(100.0 * value + 0.5);
}
}
PROPERTY_SOURCE(PartGui::ViewProviderPartExt, Gui::ViewProviderGeometryObject)
@@ -318,28 +331,32 @@ void ViewProviderPartExt::onChanged(const App::Property* prop)
else if (prop == &DiffuseColor) {
setHighlightedFaces(DiffuseColor.getValues());
}
// else if (prop == &ShapeMaterial) {
// pcFaceBind->value = SoMaterialBinding::OVERALL;
// ViewProviderGeometryObject::onChanged(prop);
// App::Color c = ShapeAppearance.getDiffuseColor();
// c.a = Transparency.getValue()/100.0f;
// DiffuseColor.setValue(c);
// }
else if (prop == &ShapeAppearance) {
pcFaceBind->value = SoMaterialBinding::OVERALL;
ViewProviderGeometryObject::onChanged(prop);
// While restoring a document do not override the
// DiffuseColor that has already been restored
if (!isRestoring()) {
App::Color c = ShapeAppearance.getDiffuseColor();
c.a = fromPercent(Transparency.getValue());
DiffuseColor.setValue(c);
}
}
else if (prop == &Transparency) {
// const App::Material& Mat = ShapeMaterial.getValue();
// long value = (long)(100*Mat.transparency);
// if (value != Transparency.getValue()) {
// float trans = Transparency.getValue()/100.0f;
// auto colors = DiffuseColor.getValues();
// for (auto &c : colors)
// c.a = trans;
// DiffuseColor.setValues(colors);
//
// App::PropertyContainer* parent = ShapeMaterial.getContainer();
// ShapeMaterial.setContainer(nullptr);
// ShapeMaterial.setTransparency(trans);
// ShapeMaterial.setContainer(parent);
// }
const App::Material& Mat = ShapeAppearance[0];
long value = toPercent(Mat.transparency);
if (value != Transparency.getValue()) {
float trans = fromPercent(Transparency.getValue());
auto colors = DiffuseColor.getValues();
for (auto &c : colors)
c.a = trans;
DiffuseColor.setValues(colors);
App::PropertyContainer* parent = ShapeAppearance.getContainer();
ShapeAppearance.setContainer(nullptr);
ShapeAppearance.setTransparency(trans);
ShapeAppearance.setContainer(parent);
}
}
else if (prop == &Lighting) {
if (Lighting.getValue() == 0)
@@ -847,6 +864,21 @@ void ViewProviderPartExt::updateData(const App::Property* prop)
Gui::ViewProviderGeometryObject::updateData(prop);
}
void ViewProviderPartExt::startRestoring()
{
Gui::ViewProviderGeometryObject::startRestoring();
}
void ViewProviderPartExt::finishRestoring()
{
// The ShapeAppearance property is restored after DiffuseColor
// and currently sets a single color.
// In case DiffuseColor has defined multiple colors they will
// be passed to the scene graph now.
DiffuseColor.touch();
Gui::ViewProviderGeometryObject::finishRestoring();
}
void ViewProviderPartExt::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QIcon iconObject = mergeGreyableOverlayIcons(Gui::BitmapFactory().pixmap("Part_ColorFace.svg"));

View File

@@ -99,6 +99,12 @@ public:
void updateData(const App::Property*) override;
/** @name Restoring view provider from document load */
//@{
void startRestoring() override;
void finishRestoring() override;
//@}
/** @name Selection handling
* This group of methods do the selection handling.
* Here you can define how the selection for your ViewProfider

View File

@@ -101,6 +101,10 @@ ViewProviderDatum::~ViewProviderDatum()
void ViewProviderDatum::attach(App::DocumentObject *obj)
{
if (auto geo = dynamic_cast<App::GeoFeature*>(obj)) {
geo->setMaterialAppearance(ShapeAppearance[0]);
}
ViewProviderGeometryObject::attach ( obj );
// TODO remove this field (2015-09-08, Fat-Zer)

View File

@@ -125,6 +125,14 @@ void ViewProviderShapeBinder::unsetEdit(int ModNum) {
PartGui::ViewProviderPart::unsetEdit(ModNum);
}
void ViewProviderShapeBinder::attach(App::DocumentObject *obj)
{
if (auto geo = dynamic_cast<App::GeoFeature*>(obj)) {
geo->setMaterialAppearance(ShapeAppearance[0]);
}
ViewProviderPart::attach(obj);
}
void ViewProviderShapeBinder::highlightReferences(bool on)
{
App::GeoFeature* obj = nullptr;
@@ -221,6 +229,9 @@ ViewProviderSubShapeBinder::ViewProviderSubShapeBinder() {
void ViewProviderSubShapeBinder::attach(App::DocumentObject* obj) {
UseBinderStyle.setValue(boost::istarts_with(obj->getNameInDocument(), "binder"));
if (auto geo = dynamic_cast<App::GeoFeature*>(obj)) {
geo->setMaterialAppearance(ShapeAppearance[0]);
}
ViewProviderPart::attach(obj);
}

View File

@@ -44,6 +44,7 @@ public:
protected:
bool setEdit(int ModNum) override;
void unsetEdit(int ModNum) override;
void attach(App::DocumentObject *obj) override;
private:
std::vector<App::Color> originalLineColors;