Data Exchange, Step - Vis Material support #447

- Introduced STEPConstruct_RenderingProperties class to handle rendering properties in STEP format.
- Implemented constructors for initializing rendering properties from various sources including STEP entities, RGBA colors, and XCAF materials.
- Added methods to set and retrieve ambient, diffuse, and specular reflectance values, along with transparency and rendering method.
- Integrated functionality to create corresponding STEP and XCAF material entities.
This commit is contained in:
Pasukhin Dmitry
2025-04-09 12:46:48 +01:00
committed by GitHub
parent 74176f3b21
commit 7c8a432c8e
29 changed files with 2186 additions and 125 deletions
@@ -1024,17 +1024,11 @@ static void SetAssemblyComponentStyle(
if (theStyle.IsNull())
return;
Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol, aRenderCol;
Standard_Real aRenderTransp;
Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol;
STEPConstruct_RenderingProperties aRenderProps;
// check if it is component style
Standard_Boolean anIsComponent = Standard_False;
if (!theStyles.GetColors(theStyle,
aSurfCol,
aBoundCol,
aCurveCol,
aRenderCol,
aRenderTransp,
anIsComponent))
if (!theStyles.GetColors(theStyle, aSurfCol, aBoundCol, aCurveCol, aRenderProps, anIsComponent))
return;
const Interface_Graph& aGraph = theTP->Graph();
@@ -1103,7 +1097,7 @@ static void SetAssemblyComponentStyle(
aShape.Location(aLoc, Standard_False);
if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull())
if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || aRenderProps.IsDefined())
{
Quantity_Color aSCol, aBCol, aCCol, aRCol;
Quantity_ColorRGBA aFullSCol;
@@ -1116,13 +1110,12 @@ static void SetAssemblyComponentStyle(
theStyles.DecodeColor(aBoundCol, aBCol);
if (!aCurveCol.IsNull())
theStyles.DecodeColor(aCurveCol, aCCol);
if (!aRenderCol.IsNull())
if (aRenderProps.IsDefined())
{
theStyles.DecodeColor(aRenderCol, aRCol);
aFullSCol = Quantity_ColorRGBA(aRCol, static_cast<float>(1.0f - aRenderTransp));
aFullSCol = aRenderProps.GetRGBAColor();
}
if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
if (!aSurfCol.IsNull() || aRenderProps.IsDefined())
theCTool->SetInstanceColor(aShape, XCAFDoc_ColorSurf, aFullSCol);
if (!aBoundCol.IsNull())
theCTool->SetInstanceColor(aShape, XCAFDoc_ColorCurv, aBCol);
@@ -1182,17 +1175,12 @@ static void SetStyle(const Handle(XSControl_WorkSession)& theWS,
anIsVisible = Standard_False;
break;
}
Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol, aRenderCol;
Standard_Real aRenderTransp;
Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol;
// check if it is component style
Standard_Boolean anIsComponent = Standard_False;
if (!theStyles.GetColors(theStyle,
aSurfCol,
aBoundCol,
aCurveCol,
aRenderCol,
aRenderTransp,
anIsComponent)
Standard_Boolean anIsComponent = Standard_False;
STEPConstruct_RenderingProperties aRenderProps;
if (!theStyles.GetColors(theStyle, aSurfCol, aBoundCol, aCurveCol, aRenderProps, anIsComponent)
&& anIsVisible)
return;
@@ -1272,12 +1260,13 @@ static void SetStyle(const Handle(XSControl_WorkSession)& theWS,
if (aS.IsNull())
continue;
if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull()
if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || aRenderProps.IsDefined()
|| !anIsVisible)
{
TDF_Label aL;
Standard_Boolean isFound = theSTool->SearchUsingMap(aS, aL, Standard_False, Standard_True);
if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull())
if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull()
|| aRenderProps.IsDefined())
{
Quantity_Color aSCol, aBCol, aCCol, aRCol;
Quantity_ColorRGBA aFullSCol;
@@ -1290,14 +1279,13 @@ static void SetStyle(const Handle(XSControl_WorkSession)& theWS,
theStyles.DecodeColor(aBoundCol, aBCol);
if (!aCurveCol.IsNull())
theStyles.DecodeColor(aCurveCol, aCCol);
if (!aRenderCol.IsNull())
if (aRenderProps.IsDefined())
{
theStyles.DecodeColor(aRenderCol, aRCol);
aFullSCol = Quantity_ColorRGBA(aRCol, static_cast<float>(1.0f - aRenderTransp));
aFullSCol = aRenderProps.GetRGBAColor();
}
if (isFound)
{
if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
if (!aSurfCol.IsNull() || aRenderProps.IsDefined())
theCTool->SetColor(aL, aFullSCol, XCAFDoc_ColorSurf);
if (!aBoundCol.IsNull())
theCTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
@@ -1311,7 +1299,7 @@ static void SetStyle(const Handle(XSControl_WorkSession)& theWS,
TDF_Label aL1;
if (theSTool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
{
if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
if (!aSurfCol.IsNull() || aRenderProps.IsDefined())
theCTool->SetColor(aL1, aFullSCol, XCAFDoc_ColorSurf);
if (!aBoundCol.IsNull())
theCTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
@@ -2012,11 +2000,11 @@ Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(
break;
}
Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol, RenderCol;
Standard_Real RenderTransp;
Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol;
// check if it is component style
Standard_Boolean IsComponent = Standard_False;
if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, RenderCol, RenderTransp, IsComponent)
Standard_Boolean IsComponent = Standard_False;
STEPConstruct_RenderingProperties aRenderProps;
if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, aRenderProps, IsComponent)
&& IsVisible)
continue;
if (!IsComponent)
@@ -2056,7 +2044,7 @@ Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(
continue;
}
// now set the style to the SHUO main label.
if (!SurfCol.IsNull() || !RenderCol.IsNull())
if (!SurfCol.IsNull() || aRenderProps.IsDefined())
{
Quantity_Color col;
Quantity_ColorRGBA colRGBA;
@@ -2065,10 +2053,9 @@ Standard_Boolean STEPCAFControl_Reader::ReadSHUOs(
Styles.DecodeColor(SurfCol, col);
colRGBA = Quantity_ColorRGBA(col);
}
if (!RenderCol.IsNull())
if (aRenderProps.IsDefined())
{
Styles.DecodeColor(RenderCol, col);
colRGBA = Quantity_ColorRGBA(col, static_cast<float>(1.0 - RenderTransp));
colRGBA = aRenderProps.GetRGBAColor();
}
CTool->SetColor(aLabelForStyle, colRGBA, XCAFDoc_ColorSurf);
}
@@ -250,6 +250,7 @@ STEPCAFControl_Writer::STEPCAFControl_Writer()
mySHUOMode(Standard_True),
myGDTMode(Standard_True),
myMatMode(Standard_True),
myVisMatMode(Standard_False),
myIsCleanDuplicates(Standard_False)
{
STEPCAFControl_Controller::Init();
@@ -268,6 +269,7 @@ STEPCAFControl_Writer::STEPCAFControl_Writer(const Handle(XSControl_WorkSession)
mySHUOMode(Standard_True),
myGDTMode(Standard_True),
myMatMode(Standard_True),
myVisMatMode(Standard_False),
myIsCleanDuplicates(Standard_False)
{
STEPCAFControl_Controller::Init();
@@ -1192,8 +1194,9 @@ static void MakeSTEPStyles(STEPConstruct_Styles& theStyle
STEPConstruct_DataMapOfAsciiStringTransient& theDPDCs,
STEPConstruct_DataMapOfPointTransient& theColRGBs,
const Handle(XCAFDoc_ShapeTool)& theShTool,
const XCAFPrs_Style* theInherit = 0,
const Standard_Boolean theIsComponent = Standard_False)
const XCAFPrs_Style* theInherit,
const Standard_Boolean theIsComponent,
const Standard_Boolean theVisMaterialMode)
{
// skip already processed shapes
if (!theMap.Add(theShape))
@@ -1212,6 +1215,8 @@ static void MakeSTEPStyles(STEPConstruct_Styles& theStyle
aStyle.SetColorCurv(anOwnStyle.GetColorCurv());
if (anOwnStyle.IsSetColorSurf())
aStyle.SetColorSurf(anOwnStyle.GetColorSurfRGBA());
if (!anOwnStyle.Material().IsNull())
aStyle.SetMaterial(anOwnStyle.Material());
}
// translate colors to STEP
@@ -1251,22 +1256,31 @@ static void MakeSTEPStyles(STEPConstruct_Styles& theStyle
const Handle(StepRepr_RepresentationItem)& anItem =
Handle(StepRepr_RepresentationItem)::DownCast(anEntIter.Value());
Handle(StepVisual_PresentationStyleAssignment) aPSA;
if (aStyle.IsVisible() || !aSurfColor.IsNull() || !aCurvColor.IsNull())
if (aStyle.IsVisible() || !aSurfColor.IsNull() || !aCurvColor.IsNull()
|| (theVisMaterialMode && !aStyle.Material().IsNull() && !aStyle.Material()->IsEmpty()))
{
aPSA = theStyles.MakeColorPSA(anItem,
aSurfColor,
aCurvColor,
aSurfColor,
aRenderTransp,
theIsComponent);
STEPConstruct_RenderingProperties aRenderProps;
if (theVisMaterialMode && !aStyle.Material().IsNull() && !aStyle.Material()->IsEmpty())
{
aRenderProps.Init(aStyle.Material());
}
else if (aRenderTransp > 0.0)
{
aRenderProps.Init(aStyle.GetColorSurfRGBA());
}
aPSA =
theStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aRenderProps, theIsComponent);
}
else
{
// default white color
aSurfColor =
theStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE), theDPDCs, theColRGBs);
aPSA =
theStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aSurfColor, 0.0, theIsComponent);
aPSA = theStyles.MakeColorPSA(anItem,
aSurfColor,
aCurvColor,
STEPConstruct_RenderingProperties(),
theIsComponent);
if (theIsComponent)
setDefaultInstanceColor(theOverride, aPSA);
@@ -1296,7 +1310,9 @@ static void MakeSTEPStyles(STEPConstruct_Styles& theStyle
theDPDCs,
theColRGBs,
theShTool,
(aHasOwn ? &aStyle : 0));
(aHasOwn ? &aStyle : 0),
Standard_False,
theVisMaterialMode);
}
}
@@ -1417,7 +1433,8 @@ Standard_Boolean STEPCAFControl_Writer::writeColors(const Handle(XSControl_WorkS
ColRGBs,
aSTool,
0,
anIsComponent);
anIsComponent,
GetVisualMaterialMode());
const Handle(XSControl_TransferWriter)& aTW = theWS->TransferWriter();
const Handle(Transfer_FinderProcess)& aFP = aTW->FinderProcess();
@@ -2019,8 +2036,13 @@ static Standard_Boolean createSHUOStyledItem(const XCAFPrs_Style& theStyle,
aSurfColor = aStyles.EncodeColor(Quantity_Color(Quantity_NOC_WHITE));
isSetDefaultColor = Standard_True;
}
STEPConstruct_RenderingProperties aRenderProps;
if (aRenderTransp > 0.0)
{
aRenderProps.Init(theStyle.GetColorSurfRGBA());
}
Handle(StepVisual_PresentationStyleAssignment) aPSA =
aStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aSurfColor, aRenderTransp, isComponent);
aStyles.MakeColorPSA(anItem, aSurfColor, aCurvColor, aRenderProps, isComponent);
Handle(StepVisual_StyledItem) anOverride; // null styled item
// find the repr item of the shape
@@ -4268,7 +4290,7 @@ Standard_Boolean STEPCAFControl_Writer::writeDGTsAP242(const Handle(XSControl_Wo
Handle(StepRepr_RepresentationItem) anItem = NULL;
myGDTPrsCurveStyle->SetValue(
1,
aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor, aCurvColor, 0.0));
aStyles.MakeColorPSA(anItem, aCurvColor, aCurvColor, STEPConstruct_RenderingProperties()));
for (Interface_EntityIterator aModelIter = aModel->Entities();
aModelIter.More() && myGDTCommonPDS.IsNull();
aModelIter.Next())
@@ -221,11 +221,19 @@ public:
Standard_Boolean GetDimTolMode() const { return myGDTMode; }
//! Set dimtolmode for indicate write D&GTs or not.
//! Set flag for indicate write material or not.
void SetMaterialMode(const Standard_Boolean theMaterialMode) { myMatMode = theMaterialMode; }
Standard_Boolean GetMaterialMode() const { return myMatMode; }
//! Set flag for indicate write visual material or not.
void SetVisualMaterialMode(const Standard_Boolean theVisualMaterialMode)
{
myVisMatMode = theVisualMaterialMode;
}
Standard_Boolean GetVisualMaterialMode() const { return myVisMatMode; }
//! Set clean duplicates flag.
//! If set to True, duplicates will be removed from the model.
//! @param theCleanDuplicates the flag to set.
@@ -394,6 +402,7 @@ private:
MoniTool_DataMapOfShapeTransient myMapCompMDGPR;
Standard_Boolean myGDTMode;
Standard_Boolean myMatMode;
Standard_Boolean myVisMatMode;
Standard_Boolean myIsCleanDuplicates;
NCollection_Vector<Handle(StepRepr_RepresentationItem)> myGDTAnnotations;
Handle(StepVisual_DraughtingModel) myGDTPresentationDM;