34
34
from OCP .STEPCAFControl import STEPCAFControl_Reader
35
35
from OCP .IFSelect import IFSelect_RetDone
36
36
from OCP .TDF import TDF_ChildIterator
37
- from OCP .Quantity import Quantity_ColorRGBA , Quantity_TOC_RGB
37
+ from OCP .Quantity import Quantity_ColorRGBA , Quantity_TOC_sRGB
38
38
from OCP .TopAbs import TopAbs_ShapeEnum
39
39
40
40
@@ -427,7 +427,7 @@ def get_doc_nodes(doc, leaf=False):
427
427
child , XCAFDoc_ColorType .XCAFDoc_ColorSurf , color_subshape
428
428
):
429
429
face_color = (
430
- * color_subshape .GetRGB ().Values (Quantity_TOC_RGB ),
430
+ * color_subshape .GetRGB ().Values (Quantity_TOC_sRGB ),
431
431
color_subshape .Alpha (),
432
432
)
433
433
@@ -442,7 +442,7 @@ def get_doc_nodes(doc, leaf=False):
442
442
):
443
443
color_subshapes_set .add (
444
444
(
445
- * color_subshape .GetRGB ().Values (Quantity_TOC_RGB ),
445
+ * color_subshape .GetRGB ().Values (Quantity_TOC_sRGB ),
446
446
color_subshape .Alpha (),
447
447
)
448
448
)
@@ -454,9 +454,9 @@ def get_doc_nodes(doc, leaf=False):
454
454
{
455
455
"path" : PurePath (node .Id .ToCString ()),
456
456
"name" : TCollection_ExtendedString (name_att .Get ()).ToExtString (),
457
- "color" : (* color .GetRGB ().Values (Quantity_TOC_RGB ), color .Alpha ()),
457
+ "color" : (* color .GetRGB ().Values (Quantity_TOC_sRGB ), color .Alpha ()),
458
458
"color_shape" : (
459
- * color_shape .GetRGB ().Values (Quantity_TOC_RGB ),
459
+ * color_shape .GetRGB ().Values (Quantity_TOC_sRGB ),
460
460
color_shape .Alpha (),
461
461
),
462
462
"color_subshapes" : color_subshapes ,
@@ -1972,3 +1972,31 @@ def test_remove_without_parent():
1972
1972
1973
1973
assert len (assy .children ) == 1
1974
1974
assert len (assy .objects ) == 1
1975
+
1976
+
1977
+ def test_step_color (tmp_path_factory ):
1978
+ """
1979
+ Checks color handling for STEP export.
1980
+ """
1981
+
1982
+ # Use a temporary directory
1983
+ tmpdir = tmp_path_factory .mktemp ("out" )
1984
+ step_color_path = os .path .join (tmpdir , "step_color.step" )
1985
+
1986
+ # Create a simple assembly with color
1987
+ assy = cq .Assembly ()
1988
+ assy .add (cq .Workplane ().box (10 , 10 , 10 ), color = cq .Color (0.47 , 0.253 , 0.18 , 1.0 ))
1989
+
1990
+ success = exportStepMeta (assy , step_color_path )
1991
+ assert success
1992
+
1993
+ # Read the file as a string and check for the correct colors
1994
+ with open (step_color_path , "r" ) as f :
1995
+ step_content = f .readlines ()
1996
+
1997
+ # Step through and try to find the COLOUR line
1998
+ for line in step_content :
1999
+ if "COLOUR_RGB(''," in line :
2000
+ assert "0.47" in line
2001
+ assert "0.25" in line
2002
+ assert "0.18" in line
0 commit comments