def getColor(self, shape): # Get the part color #string_seq = self.layer_tool.GetObject().GetLayers(shape) color = Quantity_Color() self.color_tool.GetColor(shape, XCAFDoc_ColorSurf, color) logger.debug("color: %i, %i, %i", color.Red(), color.Green(), color.Blue()) return color
def test_wrap_enum(self) -> None: """check that enum integer values match c++ name""" red = Quantity_Color(Quantity_NameOfColor.Quantity_NOC_RED) self.assertEqual(red.Red(), 1.0) self.assertEqual(red.Green(), 0.0) self.assertEqual(red.Blue(), 0.0) green = Quantity_Color(Quantity_NameOfColor.Quantity_NOC_GREEN) self.assertEqual(green.Red(), 0.0) self.assertEqual(green.Green(), 1.0) self.assertEqual(green.Blue(), 0.0) blue = Quantity_Color(Quantity_NameOfColor.Quantity_NOC_BLUE) self.assertEqual(blue.Red(), 0.0) self.assertEqual(blue.Green(), 0.0) self.assertEqual(blue.Blue(), 1.0) white = Quantity_Color(Quantity_NameOfColor.Quantity_NOC_WHITE) self.assertEqual(white.Red(), 1.0) self.assertEqual(white.Green(), 1.0) self.assertEqual(white.Blue(), 1.0)
def getSubShapes(lab, loc): global cnt, lvl cnt += 1 print("\n[%d] level %d, handling LABEL %s\n" % (cnt, lvl, get_label_name(lab))) print() print(lab.DumpToString()) print() print("Is Assembly :", shape_tool.IsAssembly(lab)) print("Is Free :", shape_tool.IsFree(lab)) print("Is Shape :", shape_tool.IsShape(lab)) print("Is Compound :", shape_tool.IsCompound(lab)) print("Is Component :", shape_tool.IsComponent(lab)) print("Is SimpleShape :", shape_tool.IsSimpleShape(lab)) print("Is Reference :", shape_tool.IsReference(lab)) users = TDF_LabelSequence() users_cnt = shape_tool.GetUsers(lab, users) print("Nr Users :", users_cnt) l_subss = TDF_LabelSequence() shape_tool.GetSubShapes(lab, l_subss) print("Nb subshapes :", l_subss.Length()) l_comps = TDF_LabelSequence() shape_tool.GetComponents(lab, l_comps) print("Nb components :", l_comps.Length()) print() if shape_tool.IsAssembly(lab): l_c = TDF_LabelSequence() shape_tool.GetComponents(lab, l_c) for i in range(l_c.Length()): label = l_c.Value(i + 1) if shape_tool.IsReference(label): print("\n######## reference label :", label) label_reference = TDF_Label() shape_tool.GetReferredShape(label, label_reference) loc = shape_tool.GetLocation(label) print(" loc :", loc) trans = loc.Transformation() print(" tran form :", trans.Form()) rot = trans.GetRotation() print(" rotation :", rot) print(" X :", rot.X()) print(" Y :", rot.Y()) print(" Z :", rot.Z()) print(" W :", rot.W()) tran = trans.TranslationPart() print(" translation :", tran) print(" X :", tran.X()) print(" Y :", tran.Y()) print(" Z :", tran.Z()) locs.append(loc) print(">>>>") lvl += 1 getSubShapes(label_reference, loc) lvl -= 1 print("<<<<") locs.pop() elif shape_tool.IsSimpleShape(lab): print("\n######## simpleshape label :", lab) shape = shape_tool.GetShape(lab) print(" all ass locs :", locs) loc = TopLoc_Location() for i in range(len(locs)): print(" take loc :", locs[i]) loc = loc.Multiplied(locs[i]) trans = loc.Transformation() print(" FINAL loc :") print(" tran form :", trans.Form()) rot = trans.GetRotation() print(" rotation :", rot) print(" X :", rot.X()) print(" Y :", rot.Y()) print(" Z :", rot.Z()) print(" W :", rot.W()) tran = trans.TranslationPart() print(" translation :", tran) print(" X :", tran.X()) print(" Y :", tran.Y()) print(" Z :", tran.Z()) shape = BRepBuilderAPI_Transform(shape, loc.Transformation()).Shape() c = Quantity_Color() colorSet = False if (color_tool.GetInstanceColor(shape, 0, c) or color_tool.GetInstanceColor(shape, 1, c) or color_tool.GetInstanceColor(shape, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab, 0, c) or color_tool.GetColor(lab, 1, c) or color_tool.GetColor(lab, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # n = c.Name(c.Red(), c.Green(), c.Blue()) # print(' color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # Display shape display.DisplayColoredShape(shape, c) for i in range(l_subss.Length()): lab = l_subss.Value(i + 1) print("\n######## simpleshape subshape label :", lab) shape = shape_tool.GetShape(lab) c = Quantity_Color() colorSet = False if (color_tool.GetInstanceColor(shape, 0, c) or color_tool.GetInstanceColor(shape, 1, c) or color_tool.GetInstanceColor(shape, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab, 0, c) or color_tool.GetColor(lab, 1, c) or color_tool.GetColor(lab, 2, c)): for i in (0, 1, 2): color_tool.SetInstanceColor(shape, i, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # n = c.Name(c.Red(), c.Green(), c.Blue()) # print(' color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) # Display shape display.DisplayColoredShape(shape, c)
def _get_sub_shapes(lab, loc): #global cnt, lvl #cnt += 1 #print("\n[%d] level %d, handling LABEL %s\n" % (cnt, lvl, _get_label_name(lab))) # print() # print(lab.DumpToString()) # print() #print("Is Assembly :", shape_tool.IsAssembly(lab)) #print("Is Free :", shape_tool.IsFree(lab)) #print("Is Shape :", shape_tool.IsShape(lab)) #print("Is Compound :", shape_tool.IsCompound(lab)) #print("Is Component :", shape_tool.IsComponent(lab)) #print("Is SimpleShape :", shape_tool.IsSimpleShape(lab)) #print("Is Reference :", shape_tool.IsReference(lab)) #users = TDF_LabelSequence() #users_cnt = shape_tool.GetUsers(lab, users) #print("Nr Users :", users_cnt) l_subss = TDF_LabelSequence() shape_tool.GetSubShapes(lab, l_subss) #print("Nb subshapes :", l_subss.Length()) l_comps = TDF_LabelSequence() shape_tool.GetComponents(lab, l_comps) #print("Nb components :", l_comps.Length()) # print() name = lab.GetLabelName() print("Name :", name) if shape_tool.IsAssembly(lab): l_c = TDF_LabelSequence() shape_tool.GetComponents(lab, l_c) for i in range(l_c.Length()): label = l_c.Value(i + 1) if shape_tool.IsReference(label): # print("\n######## reference label :", label) label_reference = TDF_Label() shape_tool.GetReferredShape(label, label_reference) loc = shape_tool.GetLocation(label) #print(" loc :", loc) #trans = loc.Transformation() #print(" tran form :", trans.Form()) #rot = trans.GetRotation() #print(" rotation :", rot) #print(" X :", rot.X()) #print(" Y :", rot.Y()) #print(" Z :", rot.Z()) #print(" W :", rot.W()) #tran = trans.TranslationPart() #print(" translation :", tran) #print(" X :", tran.X()) #print(" Y :", tran.Y()) #print(" Z :", tran.Z()) locs.append(loc) # print(">>>>") #lvl += 1 _get_sub_shapes(label_reference, loc) #lvl -= 1 # print("<<<<") locs.pop() elif shape_tool.IsSimpleShape(lab): # print("\n######## simpleshape label :", lab) shape = shape_tool.GetShape(lab) #print(" all ass locs :", locs) loc = TopLoc_Location() for l in locs: #print(" take loc :", l) loc = loc.Multiplied(l) #trans = loc.Transformation() #print(" FINAL loc :") #print(" tran form :", trans.Form()) #rot = trans.GetRotation() #print(" rotation :", rot) #print(" X :", rot.X()) #print(" Y :", rot.Y()) #print(" Z :", rot.Z()) #print(" W :", rot.W()) #tran = trans.TranslationPart() #print(" translation :", tran) #print(" X :", tran.X()) #print(" Y :", tran.Y()) #print(" Z :", tran.Z()) c = Quantity_Color(0.5, 0.5, 0.5, Quantity_TOC_RGB) # default color colorSet = False if (color_tool.GetInstanceColor(shape, 0, c) or color_tool.GetInstanceColor(shape, 1, c) or color_tool.GetInstanceColor(shape, 2, c)): color_tool.SetInstanceColor(shape, 0, c) color_tool.SetInstanceColor(shape, 1, c) color_tool.SetInstanceColor(shape, 2, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab, 0, c) or color_tool.GetColor(lab, 1, c) or color_tool.GetColor(lab, 2, c)): color_tool.SetInstanceColor(shape, 0, c) color_tool.SetInstanceColor(shape, 1, c) color_tool.SetInstanceColor(shape, 2, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) shape_disp = BRepBuilderAPI_Transform( shape, loc.Transformation()).Shape() if not shape_disp in output_shapes: output_shapes[shape_disp] = [lab.GetLabelName(), c] for i in range(l_subss.Length()): lab_subs = l_subss.Value(i + 1) # print("\n######## simpleshape subshape label :", lab) shape_sub = shape_tool.GetShape(lab_subs) c = Quantity_Color(0.5, 0.5, 0.5, Quantity_TOC_RGB) # default color colorSet = False if (color_tool.GetInstanceColor(shape_sub, 0, c) or color_tool.GetInstanceColor(shape_sub, 1, c) or color_tool.GetInstanceColor(shape_sub, 2, c)): color_tool.SetInstanceColor(shape_sub, 0, c) color_tool.SetInstanceColor(shape_sub, 1, c) color_tool.SetInstanceColor(shape_sub, 2, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab_subs, 0, c) or color_tool.GetColor(lab_subs, 1, c) or color_tool.GetColor(lab_subs, 2, c)): color_tool.SetInstanceColor(shape, 0, c) color_tool.SetInstanceColor(shape, 1, c) color_tool.SetInstanceColor(shape, 2, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) shape_to_disp = BRepBuilderAPI_Transform( shape_sub, loc.Transformation()).Shape() # position the subshape to display if not shape_to_disp in output_shapes: output_shapes[shape_to_disp] = [lab_subs.GetLabelName(), c]
def _get_sub_shapes(lab, loc): l_subss = TDF_LabelSequence() shape_tool.GetSubShapes(lab, l_subss) #print("Nb subshapes :", l_subss.Length()) l_comps = TDF_LabelSequence() shape_tool.GetComponents(lab, l_comps) #print("Nb components :", l_comps.Length()) #print() name = lab.GetLabelName() print("Name :", name) if shape_tool.IsAssembly(lab): l_c = TDF_LabelSequence() shape_tool.GetComponents(lab, l_c) for i in range(l_c.Length()): label = l_c.Value(i + 1) if shape_tool.IsReference(label): label_reference = TDF_Label() shape_tool.GetReferredShape(label, label_reference) loc = shape_tool.GetLocation(label) locs.append(loc) _get_sub_shapes(label_reference, loc) locs.pop() elif shape_tool.IsSimpleShape(lab): shape = shape_tool.GetShape(lab) loc = TopLoc_Location() for l in locs: loc = loc.Multiplied(l) c = Quantity_Color(0.5, 0.5, 0.5, Quantity_TOC_RGB) # default color colorSet = False if (color_tool.GetInstanceColor(shape, 0, c) or color_tool.GetInstanceColor(shape, 1, c) or color_tool.GetInstanceColor(shape, 2, c)): color_tool.SetInstanceColor(shape, 0, c) color_tool.SetInstanceColor(shape, 1, c) color_tool.SetInstanceColor(shape, 2, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' Instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab, 0, c) or color_tool.GetColor(lab, 1, c) or color_tool.GetColor(lab, 2, c)): color_tool.SetInstanceColor(shape, 0, c) color_tool.SetInstanceColor(shape, 1, c) color_tool.SetInstanceColor(shape, 2, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' Shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) shape_disp = BRepBuilderAPI_Transform( shape, loc.Transformation()).Shape() if not shape_disp in output_shapes: output_shapes[shape_disp] = [lab.GetLabelName(), c] for i in range(l_subss.Length()): lab_subs = l_subss.Value(i + 1) shape_sub = shape_tool.GetShape(lab_subs) c = Quantity_Color(0.5, 0.5, 0.5, Quantity_TOC_RGB) # default color colorSet = False if (color_tool.GetInstanceColor(shape_sub, 0, c) or color_tool.GetInstanceColor(shape_sub, 1, c) or color_tool.GetInstanceColor(shape_sub, 2, c)): color_tool.SetInstanceColor(shape_sub, 0, c) color_tool.SetInstanceColor(shape_sub, 1, c) color_tool.SetInstanceColor(shape_sub, 2, c) colorSet = True n = c.Name(c.Red(), c.Green(), c.Blue()) print(' Instance color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) if not colorSet: if (color_tool.GetColor(lab_subs, 0, c) or color_tool.GetColor(lab_subs, 1, c) or color_tool.GetColor(lab_subs, 2, c)): color_tool.SetInstanceColor(shape, 0, c) color_tool.SetInstanceColor(shape, 1, c) color_tool.SetInstanceColor(shape, 2, c) n = c.Name(c.Red(), c.Green(), c.Blue()) print(' Shape color Name & RGB: ', c, n, c.Red(), c.Green(), c.Blue()) shape_to_disp = BRepBuilderAPI_Transform( shape_sub, loc.Transformation()).Shape() # position the subshape to display if not shape_to_disp in output_shapes: output_shapes[shape_to_disp] = [ lab_subs.GetLabelName(), c ]
def get_occ_color(ais: AIS_ColoredShape) -> QColor: color = Quantity_Color() ais.Color(color) return QColor.fromRgbF(color.Red(), color.Green(), color.Blue())