From f6973d90548ca5c12b3f325168f1fa64e71c7c98 Mon Sep 17 00:00:00 2001 From: kgv Date: Thu, 23 May 2019 22:46:58 +0300 Subject: [PATCH] 0030738: Data Exchange - XCAFDoc_ShapeTool::updateComponent() is too long Cache subshapes list into map instead of re-iterating it multiple times within the loop. Avoid iteration at all if modified state has been already detected. XCAFDoc now returns GUIDs by const reference instead of a copy. --- src/XCAFDoc/XCAFDoc.cxx | 100 +++++++++++++++--------------- src/XCAFDoc/XCAFDoc.hxx | 83 +++++++------------------ src/XCAFDoc/XCAFDoc_ShapeTool.cxx | 28 +++++---- 3 files changed, 89 insertions(+), 122 deletions(-) diff --git a/src/XCAFDoc/XCAFDoc.cxx b/src/XCAFDoc/XCAFDoc.cxx index 222fb7aa92..a60b110204 100644 --- a/src/XCAFDoc/XCAFDoc.cxx +++ b/src/XCAFDoc/XCAFDoc.cxx @@ -25,9 +25,9 @@ //purpose : //======================================================================= -Standard_GUID XCAFDoc::ShapeRefGUID () +const Standard_GUID& XCAFDoc::ShapeRefGUID () { - static Standard_GUID ID ("5b896afe-3adf-11d4-b9b7-0060b0ee281b"); + static const Standard_GUID ID ("5b896afe-3adf-11d4-b9b7-0060b0ee281b"); return ID; } @@ -37,9 +37,9 @@ Standard_GUID XCAFDoc::ShapeRefGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::AssemblyGUID () +const Standard_GUID& XCAFDoc::AssemblyGUID () { - static Standard_GUID ID ("5b896b00-3adf-11d4-b9b7-0060b0ee281b"); + static const Standard_GUID ID ("5b896b00-3adf-11d4-b9b7-0060b0ee281b"); return ID; } @@ -49,9 +49,9 @@ Standard_GUID XCAFDoc::AssemblyGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::ExternRefGUID () +const Standard_GUID& XCAFDoc::ExternRefGUID () { - static Standard_GUID ID ("6b896b01-3adf-11d4-b9b7-0060b0ee281b"); + static const Standard_GUID ID ("6b896b01-3adf-11d4-b9b7-0060b0ee281b"); return ID; } @@ -61,11 +61,11 @@ Standard_GUID XCAFDoc::ExternRefGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::ColorRefGUID (const XCAFDoc_ColorType type) +const Standard_GUID& XCAFDoc::ColorRefGUID (const XCAFDoc_ColorType type) { - static Standard_GUID IDcol ("efd212e4-6dfd-11d4-b9c8-0060b0ee281b"); - static Standard_GUID IDcolSurf ("efd212e5-6dfd-11d4-b9c8-0060b0ee281b"); - static Standard_GUID IDcolCurv ("efd212e6-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID IDcol ("efd212e4-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID IDcolSurf ("efd212e5-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID IDcolCurv ("efd212e6-6dfd-11d4-b9c8-0060b0ee281b"); switch ( type ) { default: @@ -81,10 +81,10 @@ Standard_GUID XCAFDoc::ColorRefGUID (const XCAFDoc_ColorType type) //purpose : //======================================================================= -Standard_GUID XCAFDoc::DimTolRefGUID() +const Standard_GUID& XCAFDoc::DimTolRefGUID() { - //static Standard_GUID IDDimTol("58ed092d-44de-11d8-8776-001083004c77"); - static Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b"); + //static const Standard_GUID IDDimTol("58ed092d-44de-11d8-8776-001083004c77"); + static const Standard_GUID ID("efd212e9-6dfd-11d4-b9c8-0060b0ee281b"); //return IDDimTol; return ID; } @@ -94,9 +94,9 @@ Standard_GUID XCAFDoc::DimTolRefGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::DimensionRefFirstGUID() +const Standard_GUID& XCAFDoc::DimensionRefFirstGUID() { - static Standard_GUID ID("efd212e3-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd212e3-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -105,9 +105,9 @@ Standard_GUID XCAFDoc::DimensionRefFirstGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::DimensionRefSecondGUID() +const Standard_GUID& XCAFDoc::DimensionRefSecondGUID() { - static Standard_GUID ID("efd212e0-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd212e0-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -116,9 +116,9 @@ Standard_GUID XCAFDoc::DimensionRefSecondGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::GeomToleranceRefGUID() +const Standard_GUID& XCAFDoc::GeomToleranceRefGUID() { - static Standard_GUID ID("efd213e3-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd213e3-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -127,9 +127,9 @@ Standard_GUID XCAFDoc::GeomToleranceRefGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::DatumRefGUID() +const Standard_GUID& XCAFDoc::DatumRefGUID() { - static Standard_GUID ID("efd212e2-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd212e2-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -139,10 +139,10 @@ Standard_GUID XCAFDoc::DatumRefGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::DatumTolRefGUID() +const Standard_GUID& XCAFDoc::DatumTolRefGUID() { - //static Standard_GUID IDDimTol("58ed092d-44de-11d8-8776-001083004c77"); - static Standard_GUID ID("efd212e7-6dfd-11d4-b9c8-0060b0ee281b"); + //static const Standard_GUID IDDimTol("58ed092d-44de-11d8-8776-001083004c77"); + static const Standard_GUID ID("efd212e7-6dfd-11d4-b9c8-0060b0ee281b"); //return IDDimTol; return ID; } @@ -153,9 +153,9 @@ Standard_GUID XCAFDoc::DatumTolRefGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::LayerRefGUID () +const Standard_GUID& XCAFDoc::LayerRefGUID () { - static Standard_GUID ID ("efd212e8-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID ("efd212e8-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -165,9 +165,9 @@ Standard_GUID XCAFDoc::LayerRefGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::MaterialRefGUID () +const Standard_GUID& XCAFDoc::MaterialRefGUID () { - static Standard_GUID ID ("efd212f7-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID ("efd212f7-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -177,9 +177,9 @@ Standard_GUID XCAFDoc::MaterialRefGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::NoteRefGUID() +const Standard_GUID& XCAFDoc::NoteRefGUID() { - static Standard_GUID ID ("F3599E50-F84A-493e-8D1B-1284E79322F1"); + static const Standard_GUID ID ("F3599E50-F84A-493e-8D1B-1284E79322F1"); return ID; } @@ -188,9 +188,9 @@ Standard_GUID XCAFDoc::NoteRefGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::InvisibleGUID () +const Standard_GUID& XCAFDoc::InvisibleGUID () { - static Standard_GUID ID ("5b896aff-3adf-11d4-b9b7-0060b0ee281b"); + static const Standard_GUID ID ("5b896aff-3adf-11d4-b9b7-0060b0ee281b"); return ID; } @@ -200,9 +200,9 @@ Standard_GUID XCAFDoc::InvisibleGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::ColorByLayerGUID () +const Standard_GUID& XCAFDoc::ColorByLayerGUID () { - static Standard_GUID ID ("279e8c1e-70af-4130-b626-9cc52a537db8"); + static const Standard_GUID ID ("279e8c1e-70af-4130-b626-9cc52a537db8"); return ID; } @@ -212,9 +212,9 @@ Standard_GUID XCAFDoc::ColorByLayerGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::SHUORefGUID () +const Standard_GUID& XCAFDoc::SHUORefGUID () { - static Standard_GUID ID ("efd212ea-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID ("efd212ea-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -223,9 +223,9 @@ Standard_GUID XCAFDoc::SHUORefGUID () //purpose : //======================================================================= -Standard_GUID XCAFDoc::ViewRefGUID() +const Standard_GUID& XCAFDoc::ViewRefGUID() { - static Standard_GUID ID("efd213e5-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd213e5-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -234,9 +234,9 @@ Standard_GUID XCAFDoc::ViewRefGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::ViewRefShapeGUID() +const Standard_GUID& XCAFDoc::ViewRefShapeGUID() { - static Standard_GUID ID("efd213e6-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd213e6-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -245,9 +245,9 @@ Standard_GUID XCAFDoc::ViewRefShapeGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::ViewRefGDTGUID() +const Standard_GUID& XCAFDoc::ViewRefGDTGUID() { - static Standard_GUID ID("efd213e7-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd213e7-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -256,9 +256,9 @@ Standard_GUID XCAFDoc::ViewRefGDTGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::ViewRefPlaneGUID() +const Standard_GUID& XCAFDoc::ViewRefPlaneGUID() { - static Standard_GUID ID("efd213e9-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd213e9-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } @@ -267,9 +267,9 @@ Standard_GUID XCAFDoc::ViewRefPlaneGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::ViewRefNoteGUID() +const Standard_GUID& XCAFDoc::ViewRefNoteGUID() { - static Standard_GUID ID("C814ACC6-43AC-4812-9B2A-4E9A2A549354"); + static const Standard_GUID ID("C814ACC6-43AC-4812-9B2A-4E9A2A549354"); return ID; } @@ -278,9 +278,9 @@ Standard_GUID XCAFDoc::ViewRefNoteGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::ViewRefAnnotationGUID() +const Standard_GUID& XCAFDoc::ViewRefAnnotationGUID() { - static Standard_GUID ID("A2B5BA42-DD00-43f5-8882-4B5F8E76B9D2"); + static const Standard_GUID ID("A2B5BA42-DD00-43f5-8882-4B5F8E76B9D2"); return ID; } @@ -289,8 +289,8 @@ Standard_GUID XCAFDoc::ViewRefAnnotationGUID() //purpose : //======================================================================= -Standard_GUID XCAFDoc::LockGUID() +const Standard_GUID& XCAFDoc::LockGUID() { - static Standard_GUID ID("efd213eb-6dfd-11d4-b9c8-0060b0ee281b"); + static const Standard_GUID ID("efd213eb-6dfd-11d4-b9c8-0060b0ee281b"); return ID; } diff --git a/src/XCAFDoc/XCAFDoc.hxx b/src/XCAFDoc/XCAFDoc.hxx index 7f09f721ac..52169374e1 100644 --- a/src/XCAFDoc/XCAFDoc.hxx +++ b/src/XCAFDoc/XCAFDoc.hxx @@ -68,105 +68,68 @@ public: //! class for containing GraphNodes. //! Returns GUID for UAttribute identifying assembly - Standard_EXPORT static Standard_GUID AssemblyGUID(); + Standard_EXPORT static const Standard_GUID& AssemblyGUID(); //! Returns GUID for TreeNode representing assembly link - Standard_EXPORT static Standard_GUID ShapeRefGUID(); + Standard_EXPORT static const Standard_GUID& ShapeRefGUID(); //! Return GUIDs for TreeNode representing specified types of colors - Standard_EXPORT static Standard_GUID ColorRefGUID (const XCAFDoc_ColorType type); + Standard_EXPORT static const Standard_GUID& ColorRefGUID (const XCAFDoc_ColorType type); //! Return GUIDs for TreeNode representing specified types of DGT - Standard_EXPORT static Standard_GUID DimTolRefGUID(); + Standard_EXPORT static const Standard_GUID& DimTolRefGUID(); //! Return GUIDs for TreeNode representing specified types of Dimension - Standard_EXPORT static Standard_GUID DimensionRefFirstGUID() ; + Standard_EXPORT static const Standard_GUID& DimensionRefFirstGUID() ; //! Return GUIDs for TreeNode representing specified types of Dimension - Standard_EXPORT static Standard_GUID DimensionRefSecondGUID() ; + Standard_EXPORT static const Standard_GUID& DimensionRefSecondGUID() ; //! Return GUIDs for TreeNode representing specified types of GeomTolerance - Standard_EXPORT static Standard_GUID GeomToleranceRefGUID() ; + Standard_EXPORT static const Standard_GUID& GeomToleranceRefGUID() ; //! Return GUIDs for TreeNode representing specified types of datum - Standard_EXPORT static Standard_GUID DatumRefGUID(); + Standard_EXPORT static const Standard_GUID& DatumRefGUID(); //! Return GUIDs for TreeNode representing connections Datum-Toler - Standard_EXPORT static Standard_GUID DatumTolRefGUID(); + Standard_EXPORT static const Standard_GUID& DatumTolRefGUID(); - Standard_EXPORT static Standard_GUID LayerRefGUID(); + Standard_EXPORT static const Standard_GUID& LayerRefGUID(); - Standard_EXPORT static Standard_GUID MaterialRefGUID(); + Standard_EXPORT static const Standard_GUID& MaterialRefGUID(); //! Return GUIDs for representing notes - Standard_EXPORT static Standard_GUID NoteRefGUID(); + Standard_EXPORT static const Standard_GUID& NoteRefGUID(); - Standard_EXPORT static Standard_GUID InvisibleGUID(); + Standard_EXPORT static const Standard_GUID& InvisibleGUID(); - Standard_EXPORT static Standard_GUID ColorByLayerGUID(); + Standard_EXPORT static const Standard_GUID& ColorByLayerGUID(); //! Returns GUID for UAttribute identifying external reference on no-step file - Standard_EXPORT static Standard_GUID ExternRefGUID(); + Standard_EXPORT static const Standard_GUID& ExternRefGUID(); //! Returns GUID for UAttribute identifying specified higher usage occurrence - Standard_EXPORT static Standard_GUID SHUORefGUID(); + Standard_EXPORT static const Standard_GUID& SHUORefGUID(); //! Return GUIDs for TreeNode representing specified types of View - Standard_EXPORT static Standard_GUID ViewRefGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefGUID(); //! Return GUIDs for TreeNode representing specified types of View - Standard_EXPORT static Standard_GUID ViewRefShapeGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefShapeGUID(); //! Return GUIDs for TreeNode representing specified types of View - Standard_EXPORT static Standard_GUID ViewRefGDTGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefGDTGUID(); //! Return GUIDs for TreeNode representing specified types of View - Standard_EXPORT static Standard_GUID ViewRefPlaneGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefPlaneGUID(); //! Return GUIDs for GraphNode representing specified types of View - Standard_EXPORT static Standard_GUID ViewRefNoteGUID(); - Standard_EXPORT static Standard_GUID ViewRefAnnotationGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefNoteGUID(); + Standard_EXPORT static const Standard_GUID& ViewRefAnnotationGUID(); //! Returns GUID for UAttribute identifying lock flag - Standard_EXPORT static Standard_GUID LockGUID(); - -protected: - - - - - -private: - - - - -friend class XCAFDoc_DocumentTool; -friend class XCAFDoc_Location; -friend class XCAFDoc_Color; -friend class XCAFDoc_DimTol; -friend class XCAFDoc_Datum; -friend class XCAFDoc_Material; -friend class XCAFDoc_Volume; -friend class XCAFDoc_Area; -friend class XCAFDoc_Centroid; -friend class XCAFDoc_ClippingPlaneTool; -friend class XCAFDoc_ShapeTool; -friend class XCAFDoc_ShapeMapTool; -friend class XCAFDoc_ColorTool; -friend class XCAFDoc_DimTolTool; -friend class XCAFDoc_LayerTool; -friend class XCAFDoc_MaterialTool; -friend class XCAFDoc_GraphNode; -friend class XCAFDoc_Editor; -friend class XCAFDoc_ViewTool; + Standard_EXPORT static const Standard_GUID& LockGUID(); }; - - - - - - #endif // _XCAFDoc_HeaderFile diff --git a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx index 87ab94fc97..a2dbd3dce8 100644 --- a/src/XCAFDoc/XCAFDoc_ShapeTool.cxx +++ b/src/XCAFDoc/XCAFDoc_ShapeTool.cxx @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -1971,6 +1972,7 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe // Get the currently stored compound for the assembly TopoDS_Shape aCurrentRootShape; GetShape(theItemLabel, aCurrentRootShape); + TopTools_MapOfOrientedShape aCurrentRootShapeMap (aCurrentRootShape.NbChildren()); // Get components of the assembly TDF_LabelSequence aComponentLabs; @@ -1982,7 +1984,7 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe // Compare the number of components in XDE structure with the number of // components in topological structure. A component may happen to be removed, // so we have to update the assembly compound - Standard_Integer aNumTopoComponents = aCurrentRootShape.NbChildren(); + const Standard_Integer aNumTopoComponents = aCurrentRootShape.NbChildren(); // if ( aNumTopoComponents != aComponentLabs.Length() ) isModified = Standard_True; @@ -2021,21 +2023,23 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe else { // Search for a part in the actual compound of the ultimate assembly. - // If the part is there, then the compound is up-to-date, so it does - // not require rebuilding - Standard_Boolean isPartFound = Standard_False; - for ( TopoDS_Iterator aTopoIt(aCurrentRootShape); aTopoIt.More(); aTopoIt.Next() ) + // If the part is there, then the compound is up-to-date, so it does not require rebuilding + if (!isModified) { - if ( aTopoIt.Value() == aComponentShape ) + if (aCurrentRootShapeMap.IsEmpty()) { - isPartFound = Standard_True; - break; + // optimize search for next labels in aComponentLabs + for (TopoDS_Iterator aTopoIt(aCurrentRootShape); aTopoIt.More(); aTopoIt.Next()) + { + aCurrentRootShapeMap.Add (aTopoIt.Value()); + } + } + if (!aCurrentRootShapeMap.Contains (aComponentShape)) + { + // Part has been modified somewhere, so the compound has to be rebuilt + isModified = Standard_True; } } - - if ( !isPartFound && !isModified ) - isModified = Standard_True; // Part has been modified somewhere, so the compound - // has to be rebuilt } // Fill the list of shapes composing a new compound for the assembly