]> OCCT Git - occt.git/commitdiff
0032977: OCC V7.5, V7.6 cannot read STEP color correctly for the root label, but...
authorona <olga.nikonova@opencascade.com>
Tue, 11 Oct 2022 12:43:39 +0000 (15:43 +0300)
committerVadim Glukhikh <vadim.glukhikh@opencascade.com>
Mon, 21 Nov 2022 16:41:08 +0000 (19:41 +0300)
- color overriding mechanism is implemented for assembles, parts and instances

src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/STEPConstruct/STEPConstruct_Styles.cxx
src/STEPConstruct/STEPConstruct_Styles.hxx
src/XCAFDoc/XCAFDoc_ShapeTool.cxx
tests/bugs/step/bug32977 [new file with mode: 0644]
tests/de/step_2/K4
tests/de/step_2/K5

index 6c2ccfa8b49df6394a90f056ad4e87dadb1e0297..a211ebbb945360a8baf967037f36a69e38ea1874 100644 (file)
 #include <StepVisual_TessellatedCurveSet.hxx>
 #include <StepVisual_CoordinatesList.hxx>
 #include <NCollection_Vector.hxx>
+#include <StepVisual_OverRidingStyledItem.hxx>
+#include <StepVisual_ContextDependentOverRidingStyledItem.hxx>
+#include <StepRepr_ShapeRepresentationRelationshipWithTransformation.hxx>
+#include <StepRepr_ItemDefinedTransformation.hxx>
 
 #include <TColgp_HArray1OfXYZ.hxx>
 #include <BRepBuilderAPI_MakeEdge.hxx>
@@ -937,6 +941,306 @@ static void propagateColorToParts(const Handle(XCAFDoc_ShapeTool)& theSTool,
       propagateColorToParts(theSTool, theCTool, anOriginalL);
   }
 }
+
+//=======================================================================
+//function : SetAssemblyComponentStyle
+//purpose  : auxiliary: set override style for assembly components
+//=======================================================================
+
+static void SetAssemblyComponentStyle(const Handle(Transfer_TransientProcess) &theTP,
+                                      const Handle(XCAFDoc_ColorTool)& theCTool, 
+                                      const STEPConstruct_Styles& theStyles,
+                                      const Handle(StepVisual_ContextDependentOverRidingStyledItem)& theStyle)
+{
+  if (theStyle.IsNull()) return;
+
+  Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol, aRenderCol;
+  Standard_Real aRenderTransp;
+  // check if it is component style
+  Standard_Boolean anIsComponent = Standard_False;
+  if (!theStyles.GetColors(theStyle, aSurfCol, aBoundCol, aCurveCol, aRenderCol, aRenderTransp, anIsComponent))
+    return;
+
+  const Interface_Graph& aGraph = theTP->Graph();
+  TopLoc_Location aLoc; // init;
+  // find shape
+  TopoDS_Shape aShape;
+  Handle(Transfer_Binder) aBinder;
+  Handle(StepShape_ShapeRepresentation) aRepr = Handle(StepShape_ShapeRepresentation)::DownCast(theStyle->ItemAP242 ().Value ());
+  if (aRepr.IsNull())
+    return;
+  Handle(StepRepr_ShapeRepresentationRelationship) aSRR;
+  Interface_EntityIterator aSubs = theTP->Graph().Sharings(aRepr);
+  for (aSubs.Start(); aSubs.More(); aSubs.Next()) {
+    const Handle(Standard_Transient)& aSubsVal = aSubs.Value();
+    if (aSubsVal->IsKind (STANDARD_TYPE(StepRepr_ShapeRepresentationRelationship)))
+    {
+      // NB: C cast is used instead of DownCast() to improve performance on some cases.
+      // This saves ~10% of elapsed time on "testgrid perf de bug29* -parallel 0".
+      aSRR = (StepRepr_ShapeRepresentationRelationship*)(aSubsVal.get());
+    }
+  }
+
+  aBinder = theTP->Find(aSRR);
+  if (!aBinder.IsNull() ) {
+    aShape = TransferBRep::ShapeResult (aBinder);
+  }
+  if (aShape.IsNull())
+    return;     
+
+  //get transformation
+  aSubs = aGraph.Shareds (theStyle);
+  aSubs.Start();
+  for(; aSubs.More(); aSubs.Next())
+  {
+    Handle(StepRepr_ShapeRepresentationRelationshipWithTransformation) aRelation = Handle(StepRepr_ShapeRepresentationRelationshipWithTransformation)::DownCast (aSubs.Value ());
+    if(aRelation.IsNull()) continue;
+
+    auto aTransf = aRelation->TransformationOperator ();
+    if(auto anItemTransf = aTransf.ItemDefinedTransformation ())
+    {
+      Handle(StepGeom_Axis2Placement3d) anAxp1 = Handle(StepGeom_Axis2Placement3d)::DownCast(anItemTransf->TransformItem1 ());
+      Handle(StepGeom_Axis2Placement3d) anAxp2 = Handle(StepGeom_Axis2Placement3d)::DownCast(anItemTransf->TransformItem2 ());
+
+      if(!anAxp1.IsNull() && !anAxp2.IsNull())
+      {
+        Handle(Geom_Axis2Placement) anOrig = StepToGeom::MakeAxis2Placement (anAxp1);
+        Handle(Geom_Axis2Placement) aTarg = StepToGeom::MakeAxis2Placement (anAxp2);
+        gp_Ax3 anAx3Orig(anOrig->Ax2());
+        gp_Ax3 anAx3Targ(aTarg->Ax2());
+
+        gp_Trsf aTr1;
+        aTr1.SetTransformation(anAx3Targ, anAx3Orig);
+        TopLoc_Location aLoc1 (aTr1);
+        aLoc = aLoc.Multiplied(aLoc1);
+      }
+    }
+  }
+
+  aShape.Location( aLoc, Standard_False );
+
+  if(!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull())
+  {
+    Quantity_Color aSCol,aBCol,aCCol,aRCol;
+    Quantity_ColorRGBA aFullSCol;
+    if(!aSurfCol.IsNull()) {
+      theStyles.DecodeColor(aSurfCol,aSCol);
+      aFullSCol = Quantity_ColorRGBA(aSCol);
+    }
+    if(!aBoundCol.IsNull())
+      theStyles.DecodeColor(aBoundCol,aBCol);
+    if(!aCurveCol.IsNull())
+      theStyles.DecodeColor(aCurveCol,aCCol);
+    if(!aRenderCol.IsNull()) {
+      theStyles.DecodeColor(aRenderCol,aRCol);
+      aFullSCol = Quantity_ColorRGBA(aRCol,static_cast<float>(1.0f - aRenderTransp));
+    }
+
+    if(!aSurfCol.IsNull() || !aRenderCol.IsNull())
+      theCTool->SetInstanceColor(aShape,XCAFDoc_ColorSurf,aFullSCol);
+    if(!aBoundCol.IsNull())
+      theCTool->SetInstanceColor(aShape,XCAFDoc_ColorCurv,aBCol);
+    if(!aCurveCol.IsNull())
+      theCTool->SetInstanceColor(aShape,XCAFDoc_ColorCurv,aCCol);
+  }
+}
+
+//=======================================================================
+//function : SetStyle
+//purpose  : auxiliary: set style for parts and instances
+//=======================================================================
+
+static void SetStyle(const Handle(XSControl_WorkSession) &theWS, 
+                     const XCAFDoc_DataMapOfShapeLabel& theMap, 
+                     const Handle(XCAFDoc_ColorTool)& theCTool, 
+                     const Handle(XCAFDoc_ShapeTool)& theSTool, 
+                     const STEPConstruct_Styles& theStyles, 
+                     const Handle(TColStd_HSequenceOfTransient)& theHSeqOfInvisStyle, 
+                     const Handle(StepVisual_StyledItem)& theStyle)
+{
+  if (theStyle.IsNull()) return;
+
+  const Handle(Transfer_TransientProcess) &aTP = theWS->TransferReader()->TransientProcess();
+  if (Handle(StepVisual_OverRidingStyledItem) anOverridingStyle = Handle(StepVisual_OverRidingStyledItem)::DownCast (theStyle))
+  {
+    SetStyle (theWS, theMap, theCTool, theSTool, theStyles, theHSeqOfInvisStyle, anOverridingStyle->OverRiddenStyle ());
+    if (Handle(StepVisual_ContextDependentOverRidingStyledItem) anAssemblyComponentStyle = Handle(StepVisual_ContextDependentOverRidingStyledItem)::DownCast (theStyle))
+    {
+      SetAssemblyComponentStyle (aTP, theCTool, theStyles,anAssemblyComponentStyle);
+      return;
+    }
+  }
+
+  Standard_Boolean anIsVisible = Standard_True;
+  // check the visibility of styled item.
+  for (Standard_Integer si = 1; si <= theHSeqOfInvisStyle->Length(); si++) {
+    if (theStyle != theHSeqOfInvisStyle->Value(si))
+      continue;
+    // found that current style is invisible.
+    anIsVisible = Standard_False;
+    break;
+  }
+  Handle(StepVisual_Colour) aSurfCol, aBoundCol, aCurveCol, aRenderCol;
+  Standard_Real aRenderTransp;
+  // check if it is component style
+  Standard_Boolean anIsComponent = Standard_False;
+  if (!theStyles.GetColors(theStyle, aSurfCol, aBoundCol, aCurveCol, aRenderCol, aRenderTransp, anIsComponent) && anIsVisible)
+    return;
+
+  // collect styled items
+  NCollection_Vector<StepVisual_StyledItemTarget> anItems;
+  if (!theStyle->ItemAP242().IsNull()) {
+    anItems.Append(theStyle->ItemAP242());
+  }
+
+  for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
+    Standard_Integer anIndex = aTP->MapIndex(anItems.Value(itemIt).Value());
+    TopoDS_Shape aS;
+    if (anIndex > 0) {
+      Handle(Transfer_Binder) aBinder = aTP->MapItem(anIndex);
+      aS = TransferBRep::ShapeResult(aBinder);
+    }
+    Standard_Boolean isSkipSHUOstyle = Standard_False;
+    // take shape with real location.
+    while (anIsComponent) {
+    // take SR of NAUO
+    Handle(StepShape_ShapeRepresentation) aSR;
+    findStyledSR(theStyle, aSR);
+    // search for SR along model
+    if (aSR.IsNull())
+      break;
+    Interface_EntityIterator aSubs = theWS->HGraph()->Graph().Sharings(aSR);
+    Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
+    for (aSubs.Start(); aSubs.More(); aSubs.Next()) {
+      aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(aSubs.Value());
+      if (aSDR.IsNull())
+        continue;
+      StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
+      Handle(StepRepr_ProductDefinitionShape) PDS =
+      Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
+      if (PDS.IsNull())
+        continue;
+      StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
+
+      Handle(StepRepr_AssemblyComponentUsage) ACU =
+      Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
+      if (ACU.IsNull())
+        continue;
+      // PTV 10.02.2003 skip styled item that refer to SHUO
+      if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
+        isSkipSHUOstyle = Standard_True;
+        break;
+      }
+      Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
+      Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
+      if (NAUO.IsNull())
+        continue;
+
+      TopoDS_Shape aSh;
+      // PTV 10.02.2003 to find component of assembly CORRECTLY
+      STEPConstruct_Tool aTool(theWS);
+      TDF_Label aShLab = STEPCAFControl_Reader::FindInstance(NAUO, theCTool->ShapeTool(), aTool, theMap);
+      aSh = theCTool->ShapeTool()->GetShape(aShLab);
+      if (!aSh.IsNull()) {
+        aS = aSh;
+        break;
+      }
+    }
+    break;
+  }
+  if (isSkipSHUOstyle)
+    continue; // skip styled item which refer to SHUO
+
+  if (aS.IsNull())
+    continue;
+
+  if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull() || !anIsVisible)
+  {
+    TDF_Label aL;
+    Standard_Boolean isFound = theSTool->SearchUsingMap(aS, aL, Standard_False, Standard_True);
+    if (!aSurfCol.IsNull() || !aBoundCol.IsNull() || !aCurveCol.IsNull() || !aRenderCol.IsNull())
+    {
+      Quantity_Color aSCol, aBCol, aCCol, aRCol;
+      Quantity_ColorRGBA aFullSCol;
+      if (!aSurfCol.IsNull()) {
+        theStyles.DecodeColor(aSurfCol, aSCol);
+        aFullSCol = Quantity_ColorRGBA(aSCol);
+      }
+      if (!aBoundCol.IsNull())
+        theStyles.DecodeColor(aBoundCol, aBCol);
+      if (!aCurveCol.IsNull())
+        theStyles.DecodeColor(aCurveCol, aCCol);
+      if (!aRenderCol.IsNull()) {
+        theStyles.DecodeColor(aRenderCol, aRCol);
+        aFullSCol = Quantity_ColorRGBA(aRCol, static_cast<float>(1.0f - aRenderTransp));
+      }
+      if (isFound)
+      {
+        if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
+          theCTool->SetColor(aL, aFullSCol, XCAFDoc_ColorSurf);
+        if (!aBoundCol.IsNull())
+          theCTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
+        if (!aCurveCol.IsNull())
+          theCTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv);
+      }
+      else
+      {
+        for (TopoDS_Iterator it(aS); it.More(); it.Next())
+        {
+          TDF_Label aL1;
+          if (theSTool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
+          {
+            if (!aSurfCol.IsNull() || !aRenderCol.IsNull())
+              theCTool->SetColor(aL1, aFullSCol, XCAFDoc_ColorSurf);
+            if (!aBoundCol.IsNull())
+              theCTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
+            if (!aCurveCol.IsNull())
+              theCTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv);
+          }
+        }
+      }
+    }
+    if (!anIsVisible)
+    {
+      // sets the invisibility for shape.
+      if (isFound)
+        theCTool->SetVisibility(aL, Standard_False);
+      }
+    }
+  }
+}
+
+//=======================================================================
+//function : IsOverriden
+//purpose  : auxiliary: check that style is overridden
+//=======================================================================
+
+static Standard_Boolean IsOverriden(const Interface_Graph& theGraph, 
+                                    const Handle(StepVisual_StyledItem)& theStyle, 
+                                    Standard_Boolean theIsRoot)
+{
+  Interface_EntityIterator aSubs = theGraph.Sharings (theStyle);
+  aSubs.Start();
+  for(; aSubs.More(); aSubs.Next())
+  {
+    Handle(StepVisual_OverRidingStyledItem) anOverRidingStyle = Handle(StepVisual_OverRidingStyledItem)::DownCast (aSubs.Value ());
+    if(!anOverRidingStyle.IsNull())
+    {
+      if(!theIsRoot)
+      {
+        return Standard_True;
+      }
+      // for root style returns true only if it is overridden by other root style
+      auto anItem = anOverRidingStyle->ItemAP242 ().Value ();
+      if(!anItem.IsNull() && anItem->IsKind(STANDARD_TYPE(StepShape_ShapeRepresentation)))
+      {
+        return Standard_True;
+      }
+    }
+  }
+  return Standard_False;
+}
+
 //=======================================================================
 //function : ReadColors
 //purpose  : 
@@ -961,152 +1265,36 @@ Standard_Boolean STEPCAFControl_Reader::ReadColors(const Handle(XSControl_WorkSe
   Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
   if (STool.IsNull()) return Standard_False;
 
+  const Interface_Graph& aGraph = Styles.Graph ();
+  
   // parse and search for color attributes
-  Standard_Integer nb = Styles.NbStyles();
-  for (Standard_Integer i = 1; i <= nb; i++) {
-    Handle(StepVisual_StyledItem) style = Styles.Style(i);
-    if (style.IsNull()) continue;
-
-    Standard_Boolean IsVisible = Standard_True;
-    // check the visibility of styled item.
-    for (Standard_Integer si = 1; si <= aHSeqOfInvisStyle->Length(); si++) {
-      if (style != aHSeqOfInvisStyle->Value(si))
-        continue;
-      // found that current style is invisible.
-      IsVisible = Standard_False;
-      break;
-    }
-
-    Handle(StepVisual_Colour) SurfCol, BoundCol, CurveCol, RenderCol;
-    Standard_Real RenderTransp;
-    // check if it is component style
-    Standard_Boolean IsComponent = Standard_False;
-    if (!Styles.GetColors(style, SurfCol, BoundCol, CurveCol, RenderCol, RenderTransp, IsComponent) && IsVisible)
-      continue;
-
-    // collect styled items
-    NCollection_Vector<StepVisual_StyledItemTarget> anItems;
-    if (!style->ItemAP242().IsNull()) {
-      anItems.Append(style->ItemAP242());
+  Standard_Integer nb = Styles.NbRootStyles();
+  // apply root styles earlier, as they can be overridden
+  // function IsOverriden for root style returns true only if it is overridden by other root style
+  Standard_Boolean anIsRootStyle = Standard_True;
+  for(Standard_Integer i = 1; i <= nb; i++)
+  {
+    Handle(StepVisual_StyledItem) Style = Styles.RootStyle(i);
+    // check that style is overridden by other root style
+    if (!IsOverriden (aGraph, Style, anIsRootStyle))
+    {
+      SetStyle (WS, myMap, CTool, STool, Styles, aHSeqOfInvisStyle, Style);
     }
+  }
 
-    const Handle(Transfer_TransientProcess) &TP = WS->TransferReader()->TransientProcess();
-    for (Standard_Integer itemIt = 0; itemIt < anItems.Length(); itemIt++) {
-      Standard_Integer index = TP->MapIndex(anItems.Value(itemIt).Value());
-      TopoDS_Shape S;
-      if (index > 0) {
-        Handle(Transfer_Binder) binder = TP->MapItem(index);
-        S = TransferBRep::ShapeResult(binder);
-      }
-      Standard_Boolean isSkipSHUOstyle = Standard_False;
-      // take shape with real location.
-      while (IsComponent) {
-        // take SR of NAUO
-        Handle(StepShape_ShapeRepresentation) aSR;
-        findStyledSR(style, aSR);
-        // search for SR along model
-        if (aSR.IsNull())
-          break;
-        Interface_EntityIterator subs = WS->HGraph()->Graph().Sharings(aSR);
-        Handle(StepShape_ShapeDefinitionRepresentation) aSDR;
-        for (subs.Start(); subs.More(); subs.Next()) {
-          aSDR = Handle(StepShape_ShapeDefinitionRepresentation)::DownCast(subs.Value());
-          if (aSDR.IsNull())
-            continue;
-          StepRepr_RepresentedDefinition aPDSselect = aSDR->Definition();
-          Handle(StepRepr_ProductDefinitionShape) PDS =
-            Handle(StepRepr_ProductDefinitionShape)::DownCast(aPDSselect.PropertyDefinition());
-          if (PDS.IsNull())
-            continue;
-          StepRepr_CharacterizedDefinition aCharDef = PDS->Definition();
-
-          Handle(StepRepr_AssemblyComponentUsage) ACU =
-            Handle(StepRepr_AssemblyComponentUsage)::DownCast(aCharDef.ProductDefinitionRelationship());
-          if (ACU.IsNull())
-            continue;
-          // PTV 10.02.2003 skip styled item that refer to SHUO
-          if (ACU->IsKind(STANDARD_TYPE(StepRepr_SpecifiedHigherUsageOccurrence))) {
-            isSkipSHUOstyle = Standard_True;
-            break;
-          }
-          Handle(StepRepr_NextAssemblyUsageOccurrence) NAUO =
-            Handle(StepRepr_NextAssemblyUsageOccurrence)::DownCast(ACU);
-          if (NAUO.IsNull())
-            continue;
-
-          TopoDS_Shape aSh;
-          // PTV 10.02.2003 to find component of assembly CORRECTLY
-          STEPConstruct_Tool Tool(WS);
-          TDF_Label aShLab = FindInstance(NAUO, CTool->ShapeTool(), Tool, myMap);
-          aSh = CTool->ShapeTool()->GetShape(aShLab);
-          if (!aSh.IsNull()) {
-            S = aSh;
-            break;
-          }
-        }
-        break;
-      }
-      if (isSkipSHUOstyle)
-        continue; // skip styled item which refer to SHUO
-
-      if (S.IsNull())
-        continue;
-
-      if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !RenderCol.IsNull() || !IsVisible)
-      {
-        TDF_Label aL;
-        Standard_Boolean isFound = STool->SearchUsingMap(S, aL, Standard_False, Standard_True);
-        if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !RenderCol.IsNull())
-        {
-          Quantity_Color aSCol, aBCol, aCCol, aRCol;
-          Quantity_ColorRGBA aFullSCol;
-          if (!SurfCol.IsNull()) {
-            Styles.DecodeColor(SurfCol, aSCol);
-            aFullSCol = Quantity_ColorRGBA(aSCol);
-          }
-          if (!BoundCol.IsNull())
-            Styles.DecodeColor(BoundCol, aBCol);
-          if (!CurveCol.IsNull())
-            Styles.DecodeColor(CurveCol, aCCol);
-          if (!RenderCol.IsNull()) {
-            Styles.DecodeColor(RenderCol, aRCol);
-            aFullSCol = Quantity_ColorRGBA(aRCol, static_cast<float>(1.0f - RenderTransp));
-          }
-          if (isFound)
-          {
-            if (!SurfCol.IsNull() || !RenderCol.IsNull())
-              CTool->SetColor(aL, aFullSCol, XCAFDoc_ColorSurf);
-            if (!BoundCol.IsNull())
-              CTool->SetColor(aL, aBCol, XCAFDoc_ColorCurv);
-            if (!CurveCol.IsNull())
-              CTool->SetColor(aL, aCCol, XCAFDoc_ColorCurv);
-          }
-          else
-          {
-            for (TopoDS_Iterator it(S); it.More(); it.Next())
-            {
-              TDF_Label aL1;
-              if (STool->SearchUsingMap(it.Value(), aL1, Standard_False, Standard_True))
-              {
-                if (!SurfCol.IsNull() || !RenderCol.IsNull())
-                  CTool->SetColor(aL1, aFullSCol, XCAFDoc_ColorSurf);
-                if (!BoundCol.IsNull())
-                  CTool->SetColor(aL1, aBCol, XCAFDoc_ColorCurv);
-                if (!CurveCol.IsNull())
-                  CTool->SetColor(aL1, aCCol, XCAFDoc_ColorCurv);
-              }
-            }
-          }
-        }
-        if (!IsVisible)
-        {
-          // sets the invisibility for shape.
-          if (isFound)
-            CTool->SetVisibility(aL, Standard_False);
-        }
-      }
+  nb = Styles.NbStyles();
+  // apply leaf styles, they can override root styles
+  anIsRootStyle = Standard_False;
+  for(Standard_Integer i = 1; i <= nb; i++)
+  {
+    Handle(StepVisual_StyledItem) Style = Styles.Style(i);
+    // check that style is overridden
+    if (!IsOverriden (aGraph, Style, anIsRootStyle))
+    {
+      SetStyle (WS, myMap, CTool, STool, Styles, aHSeqOfInvisStyle, Style);
     }
   }
+  
   CTool->ReverseChainsOfTreeNodes();
 
   // some colors can be attached to assemblies, propagate them to components
index 71caf4ca0c0ca9c96380958df0097edba68e2917..09c0efcabb5998b4c5be53055d247c25c95c1301 100644 (file)
@@ -68,6 +68,8 @@
 #include <XSControl_TransferReader.hxx>
 #include <XSControl_TransferWriter.hxx>
 #include <XSControl_WorkSession.hxx>
+#include <StepVisual_ContextDependentOverRidingStyledItem.hxx>
+#include <StepShape_ShapeRepresentation.hxx>
 
 //=======================================================================
 //function : STEPConstruct_Styles
@@ -124,6 +126,26 @@ Handle(StepVisual_StyledItem) STEPConstruct_Styles::Style (const Standard_Intege
   return Handle(StepVisual_StyledItem)::DownCast ( myStyles.FindKey(i) );
 }
 
+//=======================================================================
+//function : NbRootStyles
+//purpose  : 
+//=======================================================================
+
+Standard_Integer STEPConstruct_Styles::NbRootStyles () const
+{
+  return myRootStyles.Extent();
+}
+
+//=======================================================================
+//function : RootStyle
+//purpose  : 
+//=======================================================================
+
+Handle(StepVisual_StyledItem) STEPConstruct_Styles::RootStyle (const Standard_Integer i) const
+{
+  return Handle(StepVisual_StyledItem)::DownCast ( myRootStyles.FindKey(i) );
+}
+
 
 //=======================================================================
 //function : ClearStyles
@@ -134,6 +156,7 @@ void STEPConstruct_Styles::ClearStyles ()
 {
   myStyles.Clear();
   myPSA.Clear();
+  myRootStyles.Clear();
 }
 
 
@@ -344,13 +367,15 @@ Standard_Boolean STEPConstruct_Styles::LoadStyles ()
 {
   myStyles.Clear();
   myPSA.Clear();
-  
+  myRootStyles.Clear();
+    
   // find all MDGPRs and DMs and collect all defined styles in myStyles
   Handle(Interface_InterfaceModel) model = Model();
   Standard_Integer nb = model->NbEntities();
   Handle(Standard_Type) tMDGPR = STANDARD_TYPE(StepVisual_MechanicalDesignGeometricPresentationRepresentation);
   Handle(Standard_Type) tDM = STANDARD_TYPE(StepVisual_DraughtingModel);
   Handle(Standard_Type) tSI = STANDARD_TYPE(StepVisual_StyledItem);
+  Handle(Standard_Type) tSR = STANDARD_TYPE(StepShape_ShapeRepresentation);
   for (Standard_Integer i = 1; i <= nb; i ++)
   {
     Handle(Standard_Transient) enti = model->Value(i);
@@ -364,13 +389,26 @@ Standard_Boolean STEPConstruct_Styles::LoadStyles ()
         Handle(StepVisual_StyledItem) style = 
           Handle(StepVisual_StyledItem)::DownCast ( container->ItemsValue(j) );
         if ( style.IsNull() ) continue;
-        myStyles.Add ( style );
+        auto anItem = style->ItemAP242 ().Value ();
+        if (!anItem.IsNull() && anItem->IsKind(tSR))
+        {
+          myRootStyles.Add (style);
+        }
+        else
+        {
+          myStyles.Add (style);
+        }
       }
     }
-    else if (enti->DynamicType() == tSI)
+    else if (enti->IsKind (STANDARD_TYPE(StepVisual_StyledItem)))
     {
       Handle(StepVisual_StyledItem) aStyledItem = Handle(StepVisual_StyledItem)::DownCast (enti);
-      if (!myStyles.Contains (aStyledItem))
+      auto anItem = aStyledItem->ItemAP242 ().Value ();
+      if (!anItem.IsNull() && anItem->IsKind(tSR) && !myRootStyles.Contains (aStyledItem))
+      {
+        myRootStyles.Add (aStyledItem);
+      }
+      else if (!myStyles.Contains (aStyledItem))
       {
         myStyles.Add (aStyledItem);
       }
index 722561d51fa81f81f136840720f3d1eee50c9852..5fc2cd6c865ca02a879cf0f453e97bb8fd11b42c 100644 (file)
@@ -69,6 +69,12 @@ public:
   
   //! Returns style with given index
   Standard_EXPORT Handle(StepVisual_StyledItem) Style (const Standard_Integer i) const;
+
+  //! Returns number of override styles
+  Standard_EXPORT Standard_Integer NbRootStyles() const;
+  
+  //! Returns override style with given index
+  Standard_EXPORT Handle(StepVisual_StyledItem) RootStyle (const Standard_Integer i) const;
   
   //! Clears all defined styles and PSA sequence
   Standard_EXPORT void ClearStyles();
@@ -159,6 +165,7 @@ private:
 
   TColStd_IndexedDataMapOfTransientTransient myMapOfStyles;
   TColStd_IndexedMapOfTransient myStyles;
+  TColStd_IndexedMapOfTransient myRootStyles;
   TColStd_SequenceOfTransient myPSA;
 
 
index b226c6f133fe4b43d54a2a8b3143174c7ffa72e7..85e3ecc0e39a539eb149a6060fbb7941f7954ded 100644 (file)
@@ -48,6 +48,7 @@
 #include <XCAFDoc_GraphNode.hxx>
 #include <XCAFDoc_Location.hxx>
 #include <XCAFDoc_ShapeMapTool.hxx>
+#include <TopLoc_Datum3D.hxx>
 
 IMPLEMENT_DERIVED_ATTRIBUTE_WITH_TYPE(XCAFDoc_ShapeTool,TDataStd_GenericEmpty,"xcaf","ShapeTool")
 
@@ -1602,6 +1603,33 @@ Standard_Boolean XCAFDoc_ShapeTool::RemoveSHUO (const TDF_Label& L) const
 //purpose  : auxiliary
 //=======================================================================
 
+static Standard_Boolean IsEqual (const TopLoc_Location& theLoc1, const TopLoc_Location& theLoc2)
+{
+  if (theLoc1.IsEqual (theLoc2)) {return Standard_True; }
+  if (theLoc1.IsIdentity() || theLoc2.IsIdentity()) {return Standard_False; }
+  const Handle(TopLoc_Datum3D)& aDatum1 = theLoc1.FirstDatum();
+  const Handle(TopLoc_Datum3D)& aDatum2 = theLoc2.FirstDatum();
+  if (aDatum1 && aDatum2)
+  {
+    NCollection_Mat4<double> aMat41;
+    NCollection_Mat4<double> aMat42;
+    theLoc1.FirstDatum()->Transformation().GetMat4(aMat41);
+    theLoc2.FirstDatum()->Transformation().GetMat4(aMat42);
+    if ( !aMat41.IsEqual (aMat42)) {return Standard_False; }
+  }
+  else if (aDatum1 || aDatum2) {return Standard_False; }
+  if (theLoc1.FirstPower()  != theLoc2.FirstPower()  ) {return Standard_False; }
+  else { return IsEqual (theLoc1.NextLocation(), theLoc2.NextLocation());}
+}
+
+static Standard_Boolean IsSame (const TopoDS_Shape& theShape1, const TopoDS_Shape& theShape2)
+{
+  
+  return theShape1.TShape() == theShape2.TShape()
+        && theShape1.Orientation() == theShape2.Orientation()
+        && IsEqual (theShape1.Location(), theShape2.Location());
+}
+
 static Standard_Boolean checkForShape (const TopoDS_Shape& theShape,
                                        const TopoDS_Shape& theCurSh,
                                        const TDF_Label& theUserL,
@@ -1616,7 +1644,7 @@ static Standard_Boolean checkForShape (const TopoDS_Shape& theShape,
   aCompLoc = aCompLoc.Multiplied( theCurSh.Location() );
   aSupLoc = aSupLoc.Multiplied( aCompLoc );
   aCopySh.Location( aSupLoc, Standard_False );
-  if ( aCopySh.IsSame( theShape ) ) {
+  if ( IsSame ( theShape, aCopySh ) ) {
     theLabels.Prepend( theUserL );
     return Standard_True;
   }
diff --git a/tests/bugs/step/bug32977 b/tests/bugs/step/bug32977
new file mode 100644 (file)
index 0000000..3948aeb
--- /dev/null
@@ -0,0 +1,58 @@
+puts "===================================="
+puts "0032977: OCC V7.5, V7.6 cannot read STEP color correctly for the root label, but v6.8 can"
+puts "===================================="
+puts ""
+
+pload ALL
+
+# Read files
+# Check colors number
+
+ReadStep D1 [locate_data_file bug32977_1.stp]
+set info1 [XStat D1]
+regexp {Number +of +colors += +([-0-9.+eE]+)} $info1 full nbcolor
+regexp {Number +of +colors += +[-0-9.+eE]+\n([^\n]*)} $info1 full colors
+if {[string compare ${colors} "RED BLACK GRAY74 GRAY26 "] != 0} {
+    puts "Error: not expected colors ${colors}"
+  }
+if {$nbcolor != 4} {
+    puts "Error: not expected number of colors"
+  } 
+  
+ReadStep D2 [locate_data_file bug32977_2.step]
+set info2 [XStat D2]
+regexp {Number +of +colors += +([-0-9.+eE]+)} $info2 full nbcolor
+regexp {Number +of +colors += +[-0-9.+eE]+\n([^\n]*)} $info2 full colors
+if {[string compare ${colors} "LIGHTSTEELBLUE2 WHITE VIOLETRED3 GRAY25 "] != 0} {
+    puts "Error: not expected colors ${colors}"
+  }
+if {$nbcolor != 4} {
+    puts "Error: not expected number of colors"
+  } 
+  
+ReadStep D3 [locate_data_file trj10_pm8-id-214.stp]
+set info3 [XStat D3]
+regexp {Number +of +colors += +([-0-9.+eE]+)} $info3 full nbcolor
+regexp {Number +of +colors += +[-0-9.+eE]+\n([^\n]*)} $info3 full colors
+if {[string compare ${colors} "MAGENTA RED ORANGERED ORANGE DEEPSKYBLUE2 GREEN "] != 0} {
+    puts "Error: not expected colors ${colors}"
+  }
+if {$nbcolor != 6} {
+    puts "Error: not expected number of colors"
+  } 
+
+vinit View1
+XDisplay D1 -dispmode 1
+vfit
+checkview -screenshot -3d -path ${imagedir}/${test_image}1.png
+
+vclear
+XDisplay D2 -dispmode 1
+vfit
+checkview -screenshot -3d -path ${imagedir}/${test_image}2.png
+
+vclear
+XDisplay D3 -dispmode 1
+vfit
+checkview -screenshot -3d -path ${imagedir}/${test_image}3.png
+
index 50f99b358e649c713d197279be09bf2c276ffe61..8671a0efe7d57405640bdc9f2792449fb4c0d5c5 100644 (file)
@@ -8,10 +8,10 @@ CHECKSHAPE  : Wires    = 0  ( 0 )  Faces    = 0  ( 0 )  Shells   = 0  ( 0 )   So
 NBSHAPES    : Solid    = 3  ( 3 )  Shell    = 3  ( 3 )  Face     = 492  ( 492 ) 
 STATSHAPE   : Solid    = 57  ( 57 )  Shell    = 57  ( 57 )  Face     = 1894  ( 1894 )   FreeWire = 0  ( 0 ) 
 TOLERANCE   : MaxTol   =         1e-007  (         1e-007 )  AvgTol   =          1e-007  (          1e-007 )
-LABELS      : N0Labels = 5  ( 5 )  N1Labels = 31  ( 31 )  N2Labels = 0  ( 0 )   TotalLabels = 36  ( 36 )   NameLabels = 36  ( 36 )   ColorLabels = 3  ( 3 )   LayerLabels = 0  ( 0 )
+LABELS      : N0Labels = 5  ( 5 )  N1Labels = 32  ( 32 )  N2Labels = 0  ( 0 )   TotalLabels = 37  ( 37 )   NameLabels = 36  ( 36 )   ColorLabels = 4  ( 4 )   LayerLabels = 0  ( 0 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
-NCOLORS     : NColors  = 3  ( 3 )
-COLORS      : Colors   = CYAN GREEN YELLOW  ( CYAN GREEN YELLOW )
+NCOLORS     : NColors  = 4  ( 4 )
+COLORS      : Colors   = CYAN GREEN RED YELLOW  ( CYAN GREEN RED YELLOW )
 NLAYERS     : NLayers  = 0  ( 0 )
 LAYERS      : Layers   =   (  )
 
index a09559240c0b8418740060ef3eb6e6717185d856..62dfab9afa9e59f2c1709df689020be46ae57f45 100644 (file)
@@ -8,10 +8,10 @@ CHECKSHAPE  : Wires    = 0  ( 0 )  Faces    = 0  ( 0 )  Shells   = 0  ( 0 )   So
 NBSHAPES    : Solid    = 3  ( 3 )  Shell    = 3  ( 3 )  Face     = 492  ( 492 ) 
 STATSHAPE   : Solid    = 57  ( 57 )  Shell    = 57  ( 57 )  Face     = 1894  ( 1894 )   FreeWire = 0  ( 0 ) 
 TOLERANCE   : MaxTol   =         1e-007  (         1e-007 )  AvgTol   =          1e-007  (          1e-007 )
-LABELS      : N0Labels = 5  ( 5 )  N1Labels = 31  ( 31 )  N2Labels = 0  ( 0 )   TotalLabels = 36  ( 36 )   NameLabels = 36  ( 36 )   ColorLabels = 3  ( 3 )   LayerLabels = 0  ( 0 )
+LABELS      : N0Labels = 5  ( 5 )  N1Labels = 32  ( 32 )  N2Labels = 0  ( 0 )   TotalLabels = 37  ( 37 )   NameLabels = 36  ( 36 )   ColorLabels = 4  ( 4 )   LayerLabels = 0  ( 0 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
-NCOLORS     : NColors  = 3  ( 3 )
-COLORS      : Colors   = CYAN GREEN YELLOW  ( CYAN GREEN YELLOW )
+NCOLORS     : NColors  = 4  ( 4 )
+COLORS      : Colors   = CYAN GREEN RED YELLOW  ( CYAN GREEN RED YELLOW )
 NLAYERS     : NLayers  = 0  ( 0 )
 LAYERS      : Layers   =   (  )