]> OCCT Git - occt.git/commitdiff
0026047: Data Exchange - Lost colors for IGES export
authordpasukhi <dpasukhi@opencascade.com>
Wed, 11 Nov 2020 11:23:30 +0000 (14:23 +0300)
committerdpasukhi <dpasukhi@opencascade.com>
Mon, 23 Nov 2020 08:43:57 +0000 (11:43 +0300)
- Fix problem with write shape with locations ( IGESCAFControl_Writer.cxx )
- Add support for adding sub-shapes (labels) together with sub-shapes without location ( XCAFDoc_ShapeTool.cxx )

src/IGESCAFControl/IGESCAFControl_Writer.cxx
src/XCAFDoc/XCAFDoc_ShapeTool.cxx
tests/bugs/iges/bug26047 [new file with mode: 0644]
tests/de/iges_1/K2
tests/de/iges_1/K3
tests/de/iges_1/L7
tests/de/iges_1/Q6
tests/de/iges_2/B8

index e8a4963bcedff31484c9043c79d9eae844e0f1bd..a67ad2b8360653f3cf1f4b720f76b356cdddf521 100644 (file)
@@ -333,7 +333,9 @@ void IGESCAFControl_Writer::MakeColors (const TopoDS_Shape &S,
     Handle(Transfer_FinderProcess) FP = TransferProcess();
     Handle(IGESData_IGESEntity) ent;
     Handle(TransferBRep_ShapeMapper) mapper = TransferBRep::ShapeMapper ( FP, S );
-    if ( FP->FindTypedTransient ( mapper, STANDARD_TYPE(IGESData_IGESEntity), ent ) ) {
+    Handle(TransferBRep_ShapeMapper) aNoLocMapper = TransferBRep::ShapeMapper(FP, S.Located(TopLoc_Location()));
+    if ( FP->FindTypedTransient ( mapper, STANDARD_TYPE(IGESData_IGESEntity), ent ) || 
+         FP->FindTypedTransient(aNoLocMapper, STANDARD_TYPE(IGESData_IGESEntity), ent)) {
       ent->InitColor ( colent, rank );
       Handle(IGESSolid_Face) ent_f = Handle(IGESSolid_Face)::DownCast(ent);
       if (!ent_f.IsNull())
index 2bc48072599bc1482c340485afa2d7e77ff9e059..5598c85f9f44e0425ce66ef350b764c8adf5a930 100644 (file)
@@ -491,6 +491,13 @@ TDF_Label XCAFDoc_ShapeTool::addShape (const TopoDS_Shape& S, const Standard_Boo
     {
       TopoDS_Shape aSh = A->GetMap().FindKey(i);
       mySubShapes.Bind(aSh,ShapeLabel);
+      //if shape has location, make a reference to the same shape without location
+      if (!aSh.Location().IsIdentity()) {
+        TopoDS_Shape S0 = aSh;
+        TopLoc_Location loc;
+        S0.Location(loc);
+        mySubShapes.Bind(S0, ShapeLabel);
+      }
     }
     //mySubShapes.Bind(ShapeLabel,A->GetMap());
   }
@@ -1088,19 +1095,7 @@ TDF_Label XCAFDoc_ShapeTool::AddSubShape (const TDF_Label &shapeL,
                                           const TopoDS_Shape &sub) const
 {
   TDF_Label L;
-  if (!IsSimpleShape(shapeL) || !IsTopLevel(shapeL))
-    return L;
-
-  if ( FindSubShape ( shapeL, sub, L ) ) return L;
-  
-  if (!IsSubShape(shapeL, sub))
-    return TDF_Label();
-  
-  TDF_TagSource aTag;
-  L = aTag.NewChild(shapeL);
-  
-  TNaming_Builder tnBuild(L);
-  tnBuild.Generated(sub);
+  AddSubShape(shapeL, sub, L);
 
   return L;
 }
@@ -1119,17 +1114,39 @@ Standard_Boolean XCAFDoc_ShapeTool::AddSubShape(const TDF_Label &shapeL,
   if (!IsSimpleShape(shapeL) || !IsTopLevel(shapeL))
     return Standard_False;
 
-  // Try to find already existed subshape
-  if (FindSubShape(shapeL, sub, addedSubShapeL))
+  TopoDS_Shape aSubShape = sub;
+  Standard_Boolean isDefined = Standard_True;
+  if (!IsSubShape(shapeL, sub))
+  {
+    isDefined = Standard_False;
+    // Try to find a subshape as a part of the main shape.
+    // If location of subshape has been removed,
+    // take the shape with the location from the main shape
+    if (sub.Location().IsIdentity())
+    {
+      TDF_LabelSequence aShapeLSeq;
+      for (TopoDS_Iterator it(GetShape(shapeL)); it.More() && !isDefined; it.Next())
+      {
+        TopoDS_Shape aShape = it.Value();
+        if (sub.IsSame(aShape.Located(TopLoc_Location())))
+        {
+          isDefined = Standard_True;
+          aSubShape = aShape;
+        }
+      }
+    }
+  }
+  if (!isDefined)
     return Standard_False;
 
-  if (!IsSubShape(shapeL, sub))
+  // Try to find already existed subshape
+  if (FindSubShape(shapeL, aSubShape, addedSubShapeL))
     return Standard_False;
 
   TDF_TagSource aTag;
   addedSubShapeL = aTag.NewChild(shapeL);
   TNaming_Builder tnBuild(addedSubShapeL);
-  tnBuild.Generated(sub);
+  tnBuild.Generated(aSubShape);
 
   return Standard_True;
 }
diff --git a/tests/bugs/iges/bug26047 b/tests/bugs/iges/bug26047
new file mode 100644 (file)
index 0000000..b490db5
--- /dev/null
@@ -0,0 +1,93 @@
+puts "============"
+puts "0026047: Data Exchange - Lost colors for IGES export"
+puts "============"
+
+pload MODELING VISUALIZATION OCAF XDE
+
+catch { Close D }
+catch { Close D_Cope }
+
+# create original
+box b 0 -20 -10 100 40 20
+compound b b b a
+explode a
+trotate a_1 0 0 0 1 0 0 60
+trotate a_2 0 0 0 1 0 0 -60
+bcommon b a a_1
+bcommon b b a_2
+
+pcylinder c 4 100
+trotate c 0 0 0 0 1 0 90
+
+psphere s 1.4
+ttranslate s 99.2 0 0
+bfuse cx c s
+
+pcone e 60 0.5 101
+trotate e 0 0 0 0 1 0 90
+
+bcommon body b e
+bcut body body c
+bcommon core cx e
+
+text2brep text "CAD Assistant" -font Times -height 10
+ttranslate text 10 -4 10
+prism tr text 0 0 -1
+bfuse body body tr
+
+donly body core
+
+#vdisplay body core
+#vsetcolor body yellow
+#vsetcolor core red
+
+explode body so
+explode body_1 f
+explode core so
+
+NewDocument D
+XAddShape D body_1
+XAddShape D core_1
+
+for {set i 1} {$i <= 26} {incr i} {XSetColor D body_1_$i BLUE}
+XSetColor D body_1_1 E68066
+XSetColor D body_1_9 E68066
+for {set i 10} {$i <= 22} {incr i} {XSetColor D body_1_$i 99B300}
+XSetColor D core_1 1A1AFF
+foreach ff [explode core_1 f] { XSetColor D $ff 1A1AFF ; puts "set color $ff" }
+
+vinit
+vclear 
+XDisplay D -dispMode 1
+vfit
+vdump "$::imagedir/${::casename}_orig.png"
+set aColorOrig [vreadpixel 360 290 rgb name]
+
+# export a copy
+set anIgesCopy "$::imagedir/${::casename}_exported.igs"
+WriteIges D $anIgesCopy
+
+# display an exported model
+ReadIges D_Copy $anIgesCopy
+file delete $anIgesCopy
+
+vinit
+vclear 
+XDisplay D_Copy -dispMode 1
+vfit
+vdump "$::imagedir/${::casename}_exported.png"
+
+# check color
+set aColorNew [vreadpixel 360 290 rgb name]
+if { "$aColorOrig" == "$aColorNew" } {
+  puts "OK: Image of exported model matches original"
+} else {
+  puts "Error: Image of exported model is wrong!"
+}
+
+set xst [ XStat D_Copy 1] 
+regexp {Number +of +labels +with +color +link += +([-0-9.+eE]+)} $xst full nbshcolor_Copy
+
+if {$nbshcolor_Copy != 31} {
+  puts "Error: incorect count of color links to shapes"   
+}
index a69d03a14a49b046f9d2b1f43375703872a75601..7b1dddcb5ae5ede05e6ee41ef41f2d0caae07194 100644 (file)
@@ -10,8 +10,8 @@ TPSTAT      : Faulties = 0  ( 0 )  Warnings = 14  ( 298 )  Summary  = 14  ( 298
 CHECKSHAPE  : Wires    = 0  ( 0 )  Faces    = 0  ( 0 )  Shells   = 0  ( 0 )   Solids   = 0 ( 0 )
 NBSHAPES    : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 568  ( 568 ) 
 STATSHAPE   : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 568  ( 568 )   FreeWire = 0  ( 0 ) 
-TOLERANCE   : MaxTol   =   0.4977710304  (   0.4977710286 )  AvgTol   =   0.00198506744  (  0.001988149118 )
-LABELS      : N0Labels = 568  ( 569 )  N1Labels = 0  ( 1209 )  N2Labels = 0  ( 0 )   TotalLabels = 568  ( 1778 )   NameLabels = 568  ( 569 )   ColorLabels = 568  ( 1777 )   LayerLabels = 568  ( 1777 )
+TOLERANCE   : MaxTol   =   0.4977710304  (   0.4977710286 )  AvgTol   =  0.001985043383  (  0.001988149118 )
+LABELS      : N0Labels = 568  ( 569 )  N1Labels = 0  ( 1210 )  N2Labels = 0  ( 0 )   TotalLabels = 568  ( 1779 )   NameLabels = 568  ( 569 )   ColorLabels = 568  ( 1778 )   LayerLabels = 568  ( 1778 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 1  ( 1 )
 COLORS      : Colors   = YELLOW  ( YELLOW )
index 887a38ffee9fd6de171e8ee739bc7f147bf45623..17e031426d456402fc6d805c6156c82355c0a379 100644 (file)
@@ -10,8 +10,8 @@ TPSTAT      : Faulties = 0  ( 0 )  Warnings = 345  ( 5241 )  Summary  = 345  ( 5
 CHECKSHAPE  : Wires    = 8  ( 12 )  Faces    = 12  ( 12 )  Shells   = 0  ( 0 )   Solids   = 0 ( 0 )
 NBSHAPES    : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 5163  ( 5163 ) 
 STATSHAPE   : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 5163  ( 5163 )   FreeWire = 10  ( 10 ) 
-TOLERANCE   : MaxTol   =   0.9874083984  (   0.9875071265 )  AvgTol   =   0.01115263465  (   0.01115875316 )
-LABELS      : N0Labels = 5392  ( 5458 )  N1Labels = 18  ( 4483 )  N2Labels = 0  ( 0 )   TotalLabels = 5410  ( 9941 )   NameLabels = 5392  ( 5458 )   ColorLabels = 5391  ( 9875 )   LayerLabels = 5391  ( 9875 )
+TOLERANCE   : MaxTol   =   0.9874083984  (   0.9875071265 )  AvgTol   =   0.01115260658  (   0.01115854425 )
+LABELS      : N0Labels = 5392  ( 5458 )  N1Labels = 18  ( 4541 )  N2Labels = 0  ( 0 )   TotalLabels = 5410  ( 9999 )   NameLabels = 5392  ( 5458 )   ColorLabels = 5391  ( 9933 )   LayerLabels = 5391  ( 9933 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 4  ( 4 )
 COLORS      : Colors   = BLACK BLUE CYAN GREEN  ( BLACK BLUE CYAN GREEN )
index 7877c7cbc98296fec0d2b0ac6d83ebb7febd577e..92862df485f2464285ec049fcc94b6b67abb4703 100755 (executable)
@@ -11,7 +11,7 @@ CHECKSHAPE  : Wires    = 0  ( 0 )  Faces    = 0  ( 0 )  Shells   = 0  ( 0 )   So
 NBSHAPES    : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 115  ( 115 ) 
 STATSHAPE   : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 115  ( 115 )   FreeWire = 4  ( 4 ) 
 TOLERANCE   : MaxTol   =   0.4134968839  (   0.4134968924 )  AvgTol   =  0.006591900949  (   0.00663549168 )
-LABELS      : N0Labels = 278  ( 286 )  N1Labels = 6  ( 151 )  N2Labels = 0  ( 0 )   TotalLabels = 284  ( 437 )   NameLabels = 278  ( 286 )   ColorLabels = 270  ( 429 )   LayerLabels = 270  ( 429 )
+LABELS      : N0Labels = 278  ( 286 )  N1Labels = 6  ( 159 )  N2Labels = 0  ( 0 )   TotalLabels = 284  ( 445 )   NameLabels = 278  ( 286 )   ColorLabels = 270  ( 437 )   LayerLabels = 270  ( 437 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 1  ( 1 )
 COLORS      : Colors   = RED  ( RED )
index 2db6f35cf169b5046d118e7262ac7229e3eb4e46..3d6902f3bea88a096a40f88afca9cbfee12878c6 100644 (file)
@@ -12,11 +12,10 @@ CHECKSHAPE  : Wires    = 1  ( 1 )  Faces    = 1  ( 1 )  Shells   = 0  ( 0 )   So
 NBSHAPES    : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 181  ( 181 ) 
 STATSHAPE   : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 181  ( 181 )   FreeWire = 3  ( 3 ) 
 TOLERANCE   : MaxTol   =   0.1814235482  (   0.1814235485 )  AvgTol   =   0.00374562953  (  0.003756748249 )
-LABELS      : N0Labels = 184  ( 359 )  N1Labels = 0  ( 59 )  N2Labels = 0  ( 0 )   TotalLabels = 184  ( 418 )   NameLabels = 184  ( 360 )   ColorLabels = 181  ( 243 )   LayerLabels = 181  ( 243 )
+LABELS      : N0Labels = 184  ( 359 )  N1Labels = 0  ( 139 )  N2Labels = 0  ( 0 )   TotalLabels = 184  ( 498 )   NameLabels = 184  ( 440 )   ColorLabels = 181  ( 323 )   LayerLabels = 181  ( 323 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 1  ( 3 )
 COLORS      : Colors   = WHITE  ( BLACK WHITE YELLOW )
 NLAYERS     : NLayers  = 4  ( 4 )
 LAYERS      : Layers   = 241 5 6 8  ( 241 5 6 8 )
-
 }
index ed372fae5306d4f5123b510eec9d11232636f9a7..6b680a7f6c821f74e3c1131969e9c01c1515cc2b 100644 (file)
@@ -11,12 +11,11 @@ TPSTAT      : Faulties = 0  ( 0 )  Warnings = 293  ( 5002 )  Summary  = 293  ( 5
 CHECKSHAPE  : Wires    = 8  ( 11 )  Faces    = 8  ( 7 )  Shells   = 0  ( 0 )   Solids   = 0 ( 0 )
 NBSHAPES    : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 4729  ( 4729 ) 
 STATSHAPE   : Solid    = 0  ( 0 )  Shell    = 0  ( 0 )  Face     = 4729  ( 4729 )   FreeWire = 18  ( 18 ) 
-TOLERANCE   : MaxTol   =   0.9804479161  (   0.9805459497 )  AvgTol   =   0.01154143018  (    0.0115517576 )
-LABELS      : N0Labels = 5089  ( 5165 )  N1Labels = 26  ( 3878 )  N2Labels = 0  ( 0 )   TotalLabels = 5115  ( 9043 )   NameLabels = 5089  ( 5165 )   ColorLabels = 5086  ( 8967 )   LayerLabels = 5086  ( 8967 )
+TOLERANCE   : MaxTol   =   0.9804479161  (   0.9805459497 )  AvgTol   =   0.01154139976  (   0.01155171873 )
+LABELS      : N0Labels = 5089  ( 5165 )  N1Labels = 26  ( 3936 )  N2Labels = 0  ( 0 )   TotalLabels = 5115  ( 9101 )   NameLabels = 5089  ( 5165 )   ColorLabels = 5086  ( 9025 )   LayerLabels = 5086  ( 9025 )
 PROPS       : Centroid = 0  ( 0 )  Volume   = 0  ( 0 )  Area     = 0  ( 0 )
 NCOLORS     : NColors  = 3  ( 3 )
 COLORS      : Colors   = BLUE CYAN GREEN  ( BLUE CYAN GREEN )
 NLAYERS     : NLayers  = 3  ( 3 )
 LAYERS      : Layers   = 1 200 51  ( 1 200 51 )
-
 }