0032049: Data Exchange - STEP file import problems
authordpasukhi <dpasukhi@opencascade.com>
Sun, 17 Jan 2021 13:27:11 +0000 (16:27 +0300)
committerbugmaster <bugmaster@opencascade.com>
Fri, 22 Jan 2021 10:16:22 +0000 (13:16 +0300)
- Added checking for null objects
- Added support to find layers according to visible attr
- Fixed problem with same names of layers:
 Now, layers are grouped by names and visibility parameter

src/STEPCAFControl/STEPCAFControl_GDTProperty.cxx
src/STEPCAFControl/STEPCAFControl_Reader.cxx
src/XCAFDoc/XCAFDoc_LayerTool.cxx
src/XCAFDoc/XCAFDoc_LayerTool.hxx
tests/bugs/step/bug32049 [new file with mode: 0644]
tests/bugs/step/bug32049_1 [new file with mode: 0644]
tests/de/step_1/A2
tests/de/step_1/A5
tests/de/step_1/C8

index 2c79553fcf61b7ee7047ca517c4d2456533a16a8..6800a448a5c34400900d29077c2b2f4a9d7e4711 100644 (file)
@@ -197,7 +197,7 @@ void STEPCAFControl_GDTProperty::GetDimClassOfTolerance(const Handle(StepShape_L
   Standard_Boolean aFound;
   theHolle = Standard_False;
   //it is not verified information
-  for(Standard_Integer c = 0; c <= 1; c++)
+  for(Standard_Integer c = 0; c <= 1 && !aFormV.IsNull(); c++)
   {
     aFound = Standard_False;
     Standard_Boolean aCaseSens = Standard_False;
index 2772edc2d6ef91ebff737ba066f32eb0b679244e..ae1f11569b727b8a69e961c1dc9e6311cc95ec5f 100644 (file)
@@ -1491,6 +1491,18 @@ Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSe
     Handle(TCollection_HAsciiString) descr = SVPLA->Description();
     Handle(TCollection_HAsciiString) hName = SVPLA->Name();
     TCollection_ExtendedString aLayerName(hName->String());
+    TDF_Label aLayerLabel;
+
+    // check invisibility
+    Standard_Boolean isVisible = Standard_True;;
+    Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
+    for (subs.Start(); subs.More() && isVisible; subs.Next()) {
+      if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility))) continue;
+#ifdef OCCT_DEBUG
+      std::cout << "\tLayer \"" << aLayerName << "\" is invisible" << std::endl;
+#endif
+      isVisible = Standard_False;
+    }
 
     // find a target shape and its label in the document
     for (Standard_Integer j = 1; j <= SVPLA->NbAssignedItems(); j++) {
@@ -1503,20 +1515,13 @@ Standard_Boolean STEPCAFControl_Reader::ReadLayers(const Handle(XSControl_WorkSe
 
       TDF_Label shL;
       if (!STool->Search(S, shL, Standard_True, Standard_True, Standard_True)) continue;
-      LTool->SetLayer(shL, aLayerName);
+      if (aLayerLabel.IsNull())
+        aLayerLabel = LTool->AddLayer(aLayerName, isVisible);
+      LTool->SetLayer(shL, aLayerLabel);
     }
 
-    // check invisibility
-    Interface_EntityIterator subs = WS->Graph().Sharings(SVPLA);
-    for (subs.Start(); subs.More(); subs.Next()) {
-      if (!subs.Value()->IsKind(STANDARD_TYPE(StepVisual_Invisibility))) continue;
-#ifdef OCCT_DEBUG
-      std::cout << "\tLayer \"" << aLayerName << "\" is invisible" << std::endl;
-#endif
-      //TDF_Label InvLayerLab = LTool->FindLayer(aLayerName);
-      TDF_Label InvLayerLab = LTool->AddLayer(aLayerName); //skl for OCC3926
-      TDataStd_UAttribute::Set (InvLayerLab, XCAFDoc::InvisibleGUID());
-    }
+    if (!aLayerLabel.IsNull())
+      LTool->SetVisibility(aLayerLabel, isVisible);
   }
   return Standard_True;
 }
@@ -4181,6 +4186,8 @@ Standard_Boolean STEPCAFControl_Reader::ReadMaterials(const Handle(XSControl_Wor
               for (Standard_Integer idu = 1; idu <= DU->NbElements(); idu++) {
                 Handle(StepBasic_DerivedUnitElement) DUE = DU->ElementsValue(idu);
                 Handle(StepBasic_NamedUnit) NU = DUE->Unit();
+                if (NU.IsNull())
+                  continue;
                 if (NU->IsKind(STANDARD_TYPE(StepBasic_ConversionBasedUnitAndLengthUnit)) ||
                   NU->IsKind(STANDARD_TYPE(StepBasic_SiUnitAndLengthUnit)))
                 {
index a95810b05e23e7bd2e276ac585a874b9b97ab1db..50e92c6d937b2c2e54ab63c0e9d72cdebe9e997a 100644 (file)
@@ -147,14 +147,18 @@ Standard_Boolean XCAFDoc_LayerTool::FindLayer(const TCollection_ExtendedString&
 //purpose  : 
 //=======================================================================
 
-TDF_Label XCAFDoc_LayerTool::FindLayer(const TCollection_ExtendedString& aLayer) const
+TDF_Label XCAFDoc_LayerTool::FindLayer(const TCollection_ExtendedString& aLayer,
+                                       const Standard_Boolean theToFindWithProperty,
+                                       const Standard_Boolean theToFindVisible) const
 {
   TDF_ChildIterator it( Label() );
   TDF_Label lab;
   for (; it.More(); it.Next()) {
     TDF_Label aLabel = it.Value();
     Handle(TDataStd_Name) aName;
-    if ( aLabel.FindAttribute (TDataStd_Name::GetID(), aName) && (aName->Get().IsEqual(aLayer)) ) {
+    if ( aLabel.FindAttribute (TDataStd_Name::GetID(), aName) && (aName->Get().IsEqual(aLayer)) &&
+         (!theToFindWithProperty || (theToFindWithProperty && (IsVisible(aLabel) == theToFindVisible))) )
+    {
       lab =  aLabel;
       break;
     }
@@ -168,18 +172,35 @@ TDF_Label XCAFDoc_LayerTool::FindLayer(const TCollection_ExtendedString& aLayer)
 //purpose  : 
 //=======================================================================
 
-TDF_Label XCAFDoc_LayerTool::AddLayer(const TCollection_ExtendedString& aLayer) const
+TDF_Label XCAFDoc_LayerTool::AddLayer(const TCollection_ExtendedString& theLayer) const
 {
   TDF_Label lab;
-  if ( FindLayer(aLayer, lab) )
+  if ( FindLayer(theLayer, lab) )
     return lab;
   TDF_TagSource aTag;
   TDF_Label aLabel = aTag.NewChild( Label() );
   Handle(TDataStd_Name) aName = new TDataStd_Name;
-  aName->Set(aLabel, aLayer);
+  aName->Set(aLabel, theLayer);
   return aLabel;
 }
 
+//=======================================================================
+//function : AddLayer
+//purpose  : 
+//=======================================================================
+
+TDF_Label XCAFDoc_LayerTool::AddLayer(const TCollection_ExtendedString& theLayer,
+                                      const Standard_Boolean theToFindVisible) const
+{
+  TDF_Label lab = FindLayer(theLayer, Standard_True, theToFindVisible);
+  if (!lab.IsNull())
+    return lab;
+  TDF_TagSource aTag;
+  TDF_Label aLabel = aTag.NewChild(Label());
+  Handle(TDataStd_Name) aName = new TDataStd_Name;
+  aName->Set(aLabel, theLayer);
+  return aLabel;
+}
 
 //=======================================================================
 //function : RemoveLayer
index 6e85a903c852cc689b37978fcc7d6392dcfac8dc..65a1d63f409585425a45ce5f4d60ffb45bab19b5 100644 (file)
@@ -73,14 +73,21 @@ public:
   //! Returns False if Layer is not found in Layertable
   Standard_EXPORT Standard_Boolean FindLayer (const TCollection_ExtendedString& aLayer, TDF_Label& lab) const;
   
-  //! Finds a Layer definition in a Layertable and returns
-  //! its label if found (or Null label else)
-  Standard_EXPORT TDF_Label FindLayer (const TCollection_ExtendedString& aLayer) const;
+  //! Finds a Layer definition in a Layertable by name
+  //! Returns first founded label with the same name if <theToFindWithProperty> is false
+  //! If <theToFindWithProperty> is true returns first label that
+  //! contains or not contains visible attr, according to the <theToFindVisible> parameter
+  Standard_EXPORT TDF_Label FindLayer (const TCollection_ExtendedString& aLayer, const Standard_Boolean theToFindWithProperty = Standard_False, const Standard_Boolean theToFindVisible = Standard_True) const;
   
   //! Adds a Layer definition to a Layertable and returns
   //! its label (returns existing label if the same Layer
   //! is already defined)
-  Standard_EXPORT TDF_Label AddLayer (const TCollection_ExtendedString& aLayer) const;
+  Standard_EXPORT TDF_Label AddLayer (const TCollection_ExtendedString& theLayer) const;
+
+  //! Adds a Layer definition to a Layertable and returns its label
+  //! Returns existing label (if it is already defined)
+  //! of visible or invisible layer, according to <theToFindVisible> parameter
+  Standard_EXPORT TDF_Label AddLayer(const TCollection_ExtendedString& theLayer, const Standard_Boolean theToFindVisible) const;
   
   //! Removes Layer from the Layertable
   Standard_EXPORT void RemoveLayer (const TDF_Label& lab) const;
diff --git a/tests/bugs/step/bug32049 b/tests/bugs/step/bug32049
new file mode 100644 (file)
index 0000000..e1a3eb6
--- /dev/null
@@ -0,0 +1,21 @@
+puts "========================"
+puts "0032049: Data Exchange - STEP file import problems"
+puts "========================"
+
+pload OCAF
+catch { Close D }
+
+# Read file
+ReadStep D [locate_data_file bug32049_sp7_04dx_242.stp]
+
+# Check file
+set xst [ XStat D ] 
+if { [regexp {Number of labels with layer link = 191} $xst] != 1 } {
+  puts "Error: Incorrect number of layer references"
+}
+
+if { [regexp {Number of layers = 5} $xst] != 1 } {
+  puts "Error: incorrect number of layers"
+}
+
+Close D
diff --git a/tests/bugs/step/bug32049_1 b/tests/bugs/step/bug32049_1
new file mode 100644 (file)
index 0000000..be59f4f
--- /dev/null
@@ -0,0 +1,12 @@
+puts "========================"
+puts "0032049: Data Exchange - STEP file import problems"
+puts "========================"
+
+pload OCAF
+
+# Read files
+ReadStep D_1 [locate_data_file bug32049_test.stp]
+ReadStep D_2 [locate_data_file bug32049_sp7_10nx_242.stp]
+
+Close D_1
+Close D_2
index 82c97a88a254026b3aadd4cd4cd67218b6f8cb8c..7e66588eeb9518c4e40bbe30e0cdf70e5eff0a9d 100644 (file)
@@ -1,7 +1,4 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
-puts "TODO CR23096 ALL: LAYERS : Faulty" 
-
-
 set filename tr9_r0701-db.stp
 
 set ref_data {
@@ -15,7 +12,7 @@ LABELS      : N0Labels = 1  ( 1 )  N1Labels = 0  ( 0 )  N2Labels = 0  ( 0 )   To
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 1  ( 1 )
 COLORS      : Colors   = WHITE  ( WHITE )
-NLAYERS     : NLayers  = 1  ( 2 )
-LAYERS      : Layers   = 2  ( {  0} {  2} )
+NLAYERS     : NLayers  = 1  ( 1 )
+LAYERS      : Layers   = 2  ( {  2} )
 
 }
index dc12c8c3d47de27dee47d2a7b1fd52a04b23bfd8..9354f810098fc1a4249efac796492a4e78b1202b 100644 (file)
@@ -1,7 +1,4 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
-puts "TODO CR23096 ALL: LAYERS : Faulty" 
-
-
 set filename tr8_pr3_al.stp
 
 set ref_data {
@@ -15,7 +12,7 @@ LABELS      : N0Labels = 1  ( 1 )  N1Labels = 4  ( 4 )  N2Labels = 0  ( 0 )   To
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 4  ( 4 )
 COLORS      : Colors   = BLUE GREEN RED YELLOW  ( BLUE GREEN RED YELLOW )
-NLAYERS     : NLayers  = 0  ( 1 )
-LAYERS      : Layers   =   ( LayerA )
+NLAYERS     : NLayers  = 0  ( 0 )
+LAYERS      : Layers   =   (  )
 
 }
index ec01885bc3f5da27f12dbd2cd9261fbf68276633..0cf922a741046d3fa683d609725511dba7011524 100644 (file)
@@ -1,7 +1,4 @@
 # !!!! This file is generated automatically, do not edit manually! See end script
-puts "TODO CR23096 ALL: LAYERS : Faulty" 
-
-
 set filename tr10_r0701_db.stp
 
 set ref_data {
@@ -15,7 +12,7 @@ LABELS      : N0Labels = 1  ( 1 )  N1Labels = 0  ( 0 )  N2Labels = 0  ( 0 )   To
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 1  ( 1 )
 COLORS      : Colors   = WHITE  ( WHITE )
-NLAYERS     : NLayers  = 1  ( 2 )
-LAYERS      : Layers   = 2  ( {  0} {  2} )
+NLAYERS     : NLayers  = 1  ( 1 )
+LAYERS      : Layers   = 2  ( {  2} )
 
 }