]> OCCT Git - occt-copy.git/commitdiff
0029830: STEPCAFControl_Reader poor performance - quadratic dependence
authormsv <msv@opencascade.com>
Fri, 1 Jun 2018 11:38:39 +0000 (14:38 +0300)
committermsv <msv@opencascade.com>
Fri, 1 Jun 2018 14:12:25 +0000 (17:12 +0300)
The issue has been solved by using the call to SearchUsingMap() in order to quickly find the label of the shape.

src/STEPCAFControl/STEPCAFControl_Reader.cxx

index b1fac42441e5731643f76f56aab01e76262c76a2..531d0d58625435861684d6f51779bf59e2fdaa9c 100644 (file)
@@ -849,21 +849,6 @@ Handle(STEPCAFControl_ExternFile) STEPCAFControl_Reader::ReadExternFile (const S
   return EF;
 }
 
-
-//=======================================================================
-//function : SetColorToSubshape
-//purpose  : auxilary
-//=======================================================================
-static void SetColorToSubshape(const Handle(XCAFDoc_ColorTool) & CTool,
-                              const TopoDS_Shape & S,
-                              const Quantity_Color& col,
-                              const XCAFDoc_ColorType type)
-{
-  for (TopoDS_Iterator it(S); it.More(); it.Next())
-    if (! CTool->SetColor( it.Value(), col, type)) break;
-}
-
-
 //=======================================================================
 //function : findStyledSR
 //purpose  : auxilary
@@ -911,6 +896,8 @@ Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkS
   
   Handle(XCAFDoc_ColorTool) CTool = XCAFDoc_DocumentTool::ColorTool( Doc->Main() );
   if ( CTool.IsNull() ) return Standard_False;
+  Handle(XCAFDoc_ShapeTool) STool = XCAFDoc_DocumentTool::ShapeTool(Doc->Main());
+  if (STool.IsNull()) return Standard_False;
 
   // parse and search for color attributes
   Standard_Integer nb = Styles.NbStyles();
@@ -1002,29 +989,51 @@ Standard_Boolean STEPCAFControl_Reader::ReadColors (const Handle(XSControl_WorkS
       if ( S.IsNull() )
         continue;
       
-      if ( ! SurfCol.IsNull() ) {
-        Quantity_Color col;
-        Styles.DecodeColor ( SurfCol, col );
-        if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorSurf ))
-          SetColorToSubshape( CTool, S, col, XCAFDoc_ColorSurf );
-      }
-      if ( ! BoundCol.IsNull() ) {
-        Quantity_Color col;
-        Styles.DecodeColor ( BoundCol, col );
-        if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
-          SetColorToSubshape(  CTool, S, col, XCAFDoc_ColorCurv );
-      }
-      if ( ! CurveCol.IsNull() ) {
-        Quantity_Color col;
-        Styles.DecodeColor ( CurveCol, col );
-        if ( ! CTool->SetColor ( S, col, XCAFDoc_ColorCurv ))
-          SetColorToSubshape(  CTool, S, col, XCAFDoc_ColorCurv );
-      }
-      if ( !IsVisible ) {
-        // sets the invisibility for shape.
-        TDF_Label aInvL;
-        if ( CTool->ShapeTool()->Search( S, aInvL ) )
-          CTool->SetVisibility( aInvL, Standard_False );
+      if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull() || !IsVisible)
+      {
+        TDF_Label aL;
+        Standard_Boolean isFound = STool->SearchUsingMap(S, aL, Standard_False, Standard_True);
+        if (!SurfCol.IsNull() || !BoundCol.IsNull() || !CurveCol.IsNull())
+        {
+          Quantity_Color aSCol, aBCol, aCCol;
+          if (!SurfCol.IsNull())
+            Styles.DecodeColor(SurfCol, aSCol);
+          if (!BoundCol.IsNull())
+            Styles.DecodeColor(BoundCol, aBCol);
+          if (!CurveCol.IsNull())
+            Styles.DecodeColor(CurveCol, aCCol);
+          if (isFound)
+          {
+            if (!SurfCol.IsNull())
+              CTool->SetColor(aL, aSCol, 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())
+                  CTool->SetColor(aL1, aSCol, 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);
+        }
       }
     }
   }