3434from OCP .STEPCAFControl import STEPCAFControl_Reader
3535from OCP .IFSelect import IFSelect_RetDone
3636from 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
3838from OCP .TopAbs import TopAbs_ShapeEnum
3939
4040
@@ -427,7 +427,7 @@ def get_doc_nodes(doc, leaf=False):
427427 child , XCAFDoc_ColorType .XCAFDoc_ColorSurf , color_subshape
428428 ):
429429 face_color = (
430- * color_subshape .GetRGB ().Values (Quantity_TOC_RGB ),
430+ * color_subshape .GetRGB ().Values (Quantity_TOC_sRGB ),
431431 color_subshape .Alpha (),
432432 )
433433
@@ -442,7 +442,7 @@ def get_doc_nodes(doc, leaf=False):
442442 ):
443443 color_subshapes_set .add (
444444 (
445- * color_subshape .GetRGB ().Values (Quantity_TOC_RGB ),
445+ * color_subshape .GetRGB ().Values (Quantity_TOC_sRGB ),
446446 color_subshape .Alpha (),
447447 )
448448 )
@@ -454,9 +454,9 @@ def get_doc_nodes(doc, leaf=False):
454454 {
455455 "path" : PurePath (node .Id .ToCString ()),
456456 "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 ()),
458458 "color_shape" : (
459- * color_shape .GetRGB ().Values (Quantity_TOC_RGB ),
459+ * color_shape .GetRGB ().Values (Quantity_TOC_sRGB ),
460460 color_shape .Alpha (),
461461 ),
462462 "color_subshapes" : color_subshapes ,
@@ -1972,3 +1972,31 @@ def test_remove_without_parent():
19721972
19731973 assert len (assy .children ) == 1
19741974 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