From: nds Date: Thu, 7 Mar 2019 13:13:02 +0000 (+0300) Subject: 0030268: Inspectors - improvements in VInspector plugin X-Git-Url: http://git.dev.opencascade.org/gitweb/?a=commitdiff_plain;h=35f033d2557d55e697d4e8db3931783bf965be30;p=occt-copy.git 0030268: Inspectors - improvements in VInspector plugin #parameters of Graphic3d_MaterialAspect --- diff --git a/tools/VInspector/VInspector_ItemPrs3dAspect.cxx b/tools/VInspector/VInspector_ItemPrs3dAspect.cxx index 2efedca57c..d85d5e08d1 100644 --- a/tools/VInspector/VInspector_ItemPrs3dAspect.cxx +++ b/tools/VInspector/VInspector_ItemPrs3dAspect.cxx @@ -40,6 +40,8 @@ #include #include +int GetMaterialRows() { return 25; } + // ======================================================================= // function : initValue // purpose : @@ -339,7 +341,7 @@ int VInspector_ItemPrs3dAspect::getTableRowCount (const TCollection_AsciiString& else if (theAspectKind == STANDARD_TYPE (Prs3d_DimensionAspect)->Name()) return 10; else if (theAspectKind == STANDARD_TYPE (Prs3d_ShadingAspect)->Name()) - return 17; // TODO: Graphic3d_ShaderProgram, Graphic3d_TextureSet, Graphic3d_MaterialAspect + return 17 + 2 * GetMaterialRows(); // TODO: Graphic3d_ShaderProgram, Graphic3d_TextureSet, Graphic3d_MaterialAspect return 0; } @@ -486,6 +488,20 @@ ViewControl_EditType VInspector_ItemPrs3dAspect::getTableEditType (const int the case 16: return ViewControl_EditType_Bool; default: break; } + + Handle(Prs3d_ShadingAspect) aCustomAspect = Handle(Prs3d_ShadingAspect)::DownCast (anAspect); + Handle(Graphic3d_AspectFillArea3d) aFillAreaAspect = aCustomAspect->Aspect(); + + ViewControl_EditType aType = ViewControl_EditType_None; + // front material + aRow = aRow - 17; + if (getTableEditTypeMaterial (aRow, aType)) + return aType; + + // back material + aRow = aRow - GetMaterialRows(); + if (getTableEditTypeMaterial (aRow, aType)) + return aType; } return ViewControl_EditType_None; @@ -836,7 +852,8 @@ QVariant VInspector_ItemPrs3dAspect::getTableData (const int theRow, else if (theAspectKind == STANDARD_TYPE (Prs3d_ShadingAspect)->Name()) { if (theRole != Qt::DisplayRole && theRole != Qt::BackgroundRole || - (theRole == Qt::BackgroundRole && (isFirstColumn || (aRow != 0 && theRow != 1 && theRow != 2)))) + (theRole == Qt::BackgroundRole && (isFirstColumn || (aRow != 0 && theRow != 1 && theRow != 2 + && !isColorMaterialRow (theRow))))) return QVariant(); Handle(Prs3d_ShadingAspect) aCustomAspect = Handle(Prs3d_ShadingAspect)::DownCast (anAspect); @@ -869,10 +886,22 @@ QVariant VInspector_ItemPrs3dAspect::getTableData (const int theRow, case 14: return isFirstColumn ? QVariant ("ToDrawEdges") : anAspect->ToDrawEdges(); case 15: return isFirstColumn ? QVariant ("ToSuppressBackFaces") : anAspect->ToSuppressBackFaces(); case 16: return isFirstColumn ? QVariant ("ToMapTexture") : anAspect->ToMapTexture(); - default: break; + default: break; } + // front material + aRow = aRow - 17; + const Graphic3d_MaterialAspect& aFrontMaterial = anAspect->FrontMaterial(); + QVariant aValue = getMaterialValue (aRow, theColumn, theRole, aFrontMaterial, "FrontMaterial"); + if (aValue.isValid()) + return aValue; + + // back material + aRow = aRow - GetMaterialRows(); + const Graphic3d_MaterialAspect& aBackMaterial = anAspect->BackMaterial(); + aValue = getMaterialValue (aRow, theColumn, theRole, aBackMaterial, "BackMaterial"); + if (aValue.isValid()) + return aValue; } - return QVariant(); } @@ -1078,10 +1107,165 @@ bool VInspector_ItemPrs3dAspect::setTableData (const int theRow, case 16: anAspect->SetTextureMapOn (theValue.toBool()); break; default: break; } + + // front material + aRow = aRow - 17; + Graphic3d_MaterialAspect& aFrontMaterial = anAspect->ChangeFrontMaterial(); + if (setMaterialValue (aRow, aFrontMaterial, theValue)) + return true; + + // back material + aRow = aRow - GetMaterialRows(); + Graphic3d_MaterialAspect& aBackMaterial = anAspect->ChangeBackMaterial(); + if (setMaterialValue (aRow, aBackMaterial, theValue)) + return true; } return true; } +// ======================================================================= +// function : isColorMaterialRow +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemPrs3dAspect::isColorMaterialRow (const int theRow) const +{ + // front material + int aRow = theRow - 17; + if (aRow >= 8 && aRow <= 12) + return Standard_True; + + // back material + aRow = aRow - GetMaterialRows(); + if (aRow >= 8 && aRow <= 12) + return Standard_True; + + return Standard_False; +} + +// ======================================================================= +// function : getTableEditTypeMaterial +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemPrs3dAspect::getTableEditTypeMaterial (const int theRow, + ViewControl_EditType& theType) const +{ + theType = ViewControl_EditType_None; + + switch (theRow) + { + case 6: + case 7: theType = ViewControl_EditType_Line; break; + + case 8: + case 9: + case 10: + case 11: + case 12: theType = ViewControl_EditType_Color; break; + + case 13: + case 14: + case 15: + case 16: + case 17: theType = ViewControl_EditType_Line; break; + + case 18: + case 19: + case 20: + case 21: theType = ViewControl_EditType_Bool; break; + + default: break; + } + + return theRow < GetMaterialRows(); +} + +// ======================================================================= +// function : getMaterialValue +// purpose : +// ======================================================================= +QVariant VInspector_ItemPrs3dAspect::getMaterialValue (const int theRow, + const int theColumn, + const int theRole, + const Graphic3d_MaterialAspect& theMaterial, + const TCollection_AsciiString& theInfo) const +{ + bool isFirstColumn = theColumn == 0; + + if ((theRole != Qt::DisplayRole && theRole != Qt::BackgroundRole) || + (theRole == Qt::BackgroundRole && (isFirstColumn || (theRow < 8 || theRow > 12)))) + return QVariant(); + + switch (theRow) + { + case 0: return ViewControl_Tools::TableSeparator(); + case 1: return isFirstColumn ? QVariant (theInfo.ToCString()) : QVariant (""); + case 2: return ViewControl_Tools::TableSeparator(); + + case 3: return isFirstColumn ? QVariant ("Name") : QVariant (theMaterial.Name()); //TODO + case 4: return isFirstColumn ? QVariant ("RequestedName") : QVariant (theMaterial.RequestedName()); // TODO + case 5: return isFirstColumn ? QVariant ("MaterialName") : QVariant (theMaterial.MaterialName()); + + case 6: return isFirstColumn ? QVariant ("Transparency") : QVariant (theMaterial.Transparency()); + case 7: return isFirstColumn ? QVariant ("Alpha") : QVariant (theMaterial.Alpha()); + + case 8: return getColorData("Color", Quantity_ColorRGBA (theMaterial.Color()), isFirstColumn, theRole); + case 9: return getColorData("AmbientColor", Quantity_ColorRGBA (theMaterial.AmbientColor()), isFirstColumn, theRole); + case 10: return getColorData("DiffuseColor", Quantity_ColorRGBA (theMaterial.DiffuseColor()), isFirstColumn, theRole); + case 11: return getColorData("SpecularColor", Quantity_ColorRGBA (theMaterial.SpecularColor()), isFirstColumn, theRole); + case 12: return getColorData("EmissiveColor", Quantity_ColorRGBA (theMaterial.EmissiveColor()), isFirstColumn, theRole); + + case 13: return isFirstColumn ? QVariant ("Ambient") : QVariant (theMaterial.Ambient()); + case 14: return isFirstColumn ? QVariant ("Diffuse") : QVariant (theMaterial.Diffuse()); + case 15: return isFirstColumn ? QVariant ("Specular") : QVariant (theMaterial.Specular()); + case 16: return isFirstColumn ? QVariant ("Emissive") : QVariant (theMaterial.Emissive()); + + case 17: return isFirstColumn ? QVariant ("Shininess") : QVariant (theMaterial.Shininess()); + + case 18: return isFirstColumn ? QVariant ("ReflectionMode (Ambient)") : QVariant (theMaterial.ReflectionMode (Graphic3d_TOR_AMBIENT)); + case 19: return isFirstColumn ? QVariant ("ReflectionMode (Diffuse)") : QVariant (theMaterial.ReflectionMode (Graphic3d_TOR_DIFFUSE)); + case 20: return isFirstColumn ? QVariant ("ReflectionMode (Specular)") : QVariant (theMaterial.ReflectionMode (Graphic3d_TOR_SPECULAR)); + case 21: return isFirstColumn ? QVariant ("ReflectionMode (Emissive)") : QVariant (theMaterial.ReflectionMode (Graphic3d_TOR_EMISSION)); + + case 22: return isFirstColumn ? QVariant ("RefractionIndex") : QVariant (theMaterial.RefractionIndex()); + case 23: return isFirstColumn ? QVariant ("BSDF.FresnelCoat.FresnelType()") : QVariant (theMaterial.BSDF().FresnelCoat.FresnelType()); // TODO + case 24: return isFirstColumn ? QVariant ("BSDF.FresnelBase.FresnelType()") : QVariant (theMaterial.BSDF().FresnelBase.FresnelType()); // TODO + } + return QVariant(); +} + +// ======================================================================= +// function : setMaterialValue +// purpose : +// ======================================================================= +Standard_Boolean VInspector_ItemPrs3dAspect::setMaterialValue (const int theRow, + Graphic3d_MaterialAspect& theMaterial, + const QVariant& theValue) const +{ + switch (theRow) + { + case 6: theMaterial.SetTransparency (ViewControl_Tools::ToShortRealValue (theValue)); break; + case 7: theMaterial.SetAlpha (ViewControl_Tools::ToShortRealValue (theValue)); break; + + case 8: theMaterial.SetColor (ViewControl_ColorSelector::StringToColor (theValue.toString())); break; + case 9: theMaterial.SetAmbientColor (ViewControl_ColorSelector::StringToColor (theValue.toString())); break; + case 10: theMaterial.SetDiffuseColor (ViewControl_ColorSelector::StringToColor (theValue.toString())); break; + case 11: theMaterial.SetSpecularColor (ViewControl_ColorSelector::StringToColor (theValue.toString())); break; + case 12: theMaterial.SetEmissiveColor (ViewControl_ColorSelector::StringToColor (theValue.toString())); break; + + case 13: theMaterial.SetAmbient (ViewControl_Tools::ToShortRealValue (theValue)); break; + case 14: theMaterial.SetDiffuse (ViewControl_Tools::ToShortRealValue (theValue)); break; + case 15: theMaterial.SetSpecular (ViewControl_Tools::ToShortRealValue (theValue)); break; + case 16: theMaterial.SetEmissive (ViewControl_Tools::ToShortRealValue (theValue)); break; + case 17: theMaterial.SetShininess (ViewControl_Tools::ToShortRealValue (theValue)); break; + + case 18: theMaterial.SetReflectionMode (Graphic3d_TOR_AMBIENT, theValue.toBool()); break; + case 19: theMaterial.SetReflectionMode (Graphic3d_TOR_DIFFUSE, theValue.toBool()); break; + case 20: theMaterial.SetReflectionMode (Graphic3d_TOR_SPECULAR, theValue.toBool()); break; + case 21: theMaterial.SetReflectionMode (Graphic3d_TOR_EMISSION, theValue.toBool()); break; + } + return theRow < GetMaterialRows(); +} + // ======================================================================= // function : getColorData // purpose : @@ -1101,4 +1285,4 @@ QVariant VInspector_ItemPrs3dAspect::getColorData(const TCollection_AsciiString& return ViewControl_ColorSelector::ColorToString (theColor); return QVariant(); -} \ No newline at end of file +} diff --git a/tools/VInspector/VInspector_ItemPrs3dAspect.hxx b/tools/VInspector/VInspector_ItemPrs3dAspect.hxx index 71f9226dbd..8f34f7ba50 100644 --- a/tools/VInspector/VInspector_ItemPrs3dAspect.hxx +++ b/tools/VInspector/VInspector_ItemPrs3dAspect.hxx @@ -160,6 +160,27 @@ private: const int theStartRow, const QVariant& theValue) const; + //! Returns true if the table value in the row is a color of a material + Standard_Boolean isColorMaterialRow (const int theRow) const; + + //! Returns type of edit control for the material row + //! \param theRow a model index row + //! \param theColumn a model index column + //! \return edit type + Standard_Boolean getTableEditTypeMaterial (const int theRow, + ViewControl_EditType& theType) const; + + //! Returns value of Graphic3d_MaterialAspect for the row + QVariant getMaterialValue (const int theRow, + const int theColumn, + const int theRole, + const Graphic3d_MaterialAspect& theMaterial, + const TCollection_AsciiString& theInfo) const; + + Standard_Boolean setMaterialValue (const int theRow, + Graphic3d_MaterialAspect& theMaterial, + const QVariant& theValue) const; + //! Returns color data depending on parameters //! \param theInfo information value if column is the first one //! \param theColor color value diff --git a/tools/VInspector/VInspector_Window.cxx b/tools/VInspector/VInspector_Window.cxx index 9e45873e7b..48082d7cfe 100644 --- a/tools/VInspector/VInspector_Window.cxx +++ b/tools/VInspector/VInspector_Window.cxx @@ -52,6 +52,7 @@ #include #include +#include #include #include @@ -587,8 +588,12 @@ bool VInspector_Window::OpenFile(const TCollection_AsciiString& theFileName) return isModelUpdated; Handle(AIS_Shape) aPresentation = new AIS_Shape (aShape); - aContext->Display (aPresentation, false); - aContext->Load (aPresentation, -1/*selection mode*/); + + View_Displayer* aDisplayer = myViewWindow->GetDisplayer(); + aDisplayer->DisplayPresentation (aPresentation); + + //aContext->Display (aPresentation, false); + //aContext->Load (aPresentation, -1/*selection mode*/); aContext->UpdateCurrentViewer(); UpdateTreeModel();