@@ -1301,13 +1301,15 @@ def __init__(self, materiallib, name, props=None, material_update=True):
1301
1301
self ._material_appearance .append (self ._props ["AttachedData" ]["MatAppearanceData" ]["Red" ])
1302
1302
self ._material_appearance .append (self ._props ["AttachedData" ]["MatAppearanceData" ]["Green" ])
1303
1303
self ._material_appearance .append (self ._props ["AttachedData" ]["MatAppearanceData" ]["Blue" ])
1304
+ self ._material_appearance .append (self ._props ["AttachedData" ]["MatAppearanceData" ].get ("Transparency" , 0.0 ))
1304
1305
else :
1305
1306
vals = list (CSS4_COLORS .values ())
1306
1307
if (materiallib ._color_id ) >= len (vals ):
1307
1308
materiallib ._color_id = 0
1308
1309
h = vals [materiallib ._color_id ].lstrip ("#" )
1309
1310
self ._material_appearance = list (int (h [i : i + 2 ], 16 ) for i in (0 , 2 , 4 ))
1310
1311
materiallib ._color_id += 1
1312
+ self ._material_appearance .append (0 )
1311
1313
self ._props ["AttachedData" ] = OrderedDict (
1312
1314
{
1313
1315
"MatAppearanceData" : OrderedDict (
@@ -1316,6 +1318,7 @@ def __init__(self, materiallib, name, props=None, material_update=True):
1316
1318
"Red" : self ._material_appearance [0 ],
1317
1319
"Green" : self ._material_appearance [1 ],
1318
1320
"Blue" : self ._material_appearance [2 ],
1321
+ "Transparency" : self ._material_appearance [3 ],
1319
1322
}
1320
1323
)
1321
1324
}
@@ -1366,46 +1369,61 @@ def _update_material(self):
1366
1369
1367
1370
@property
1368
1371
def material_appearance (self ):
1369
- """Material Appearance specified as an RGB list.
1372
+ """Material appearance specified as a list where the first three items are
1373
+ RGB color and the fourth one is transparency.
1370
1374
1371
1375
Returns
1372
1376
-------
1373
1377
list
1374
- Color of the material in RGB. Values are in the range ``[0, 255]``.
1378
+ Color of the material in RGB and transparency.
1379
+ Color values are in the range ``[0, 255]``.
1380
+ Transparency is a float in the range ``[0,1]``.
1375
1381
1376
1382
Examples
1377
1383
--------
1378
- Create a new material with color ``[0, 153, 153]`` (darker cyan).
1384
+ Create a material with color ``[0, 153, 153]`` (darker cyan) and transparency ``0.5`` .
1379
1385
1380
1386
>>> from pyaedt import Hfss
1381
1387
>>> hfss = Hfss(specified_version="2021.2")
1382
1388
>>> mat1 = hfss.materials.add_material("new_material")
1383
- >>> rgbcolor = mat1.material_appearance
1384
- >>> mat1.material_appearance = [0, 153, 153]
1389
+ >>> appearance_props = mat1.material_appearance
1390
+ >>> mat1.material_appearance = [0, 153, 153, 0.5 ]
1385
1391
"""
1386
1392
return self ._material_appearance
1387
1393
1388
1394
@material_appearance .setter
1389
- def material_appearance (self , rgb ):
1390
- if not isinstance (rgb , (list , tuple )):
1391
- raise TypeError ("`material_apperance` must be a list or tuple" )
1392
- if len (rgb ) != 3 :
1393
- raise ValueError ("`material_appearance` must be three items (RGB)" )
1394
- value_int = []
1395
- for rgb_item in rgb :
1396
- rgb_int = int (rgb_item )
1397
- if rgb_int < 0 or rgb_int > 255 :
1398
- raise ValueError ("RGB value must be between 0 and 255" )
1399
- value_int .append (rgb_int )
1400
- self ._material_appearance = value_int
1395
+ def material_appearance (self , appearance_props ):
1396
+ if not isinstance (appearance_props , (list , tuple )):
1397
+ raise TypeError ("`material_appearance` must be a list or tuple." )
1398
+ if len (appearance_props ) != 3 and len (appearance_props ) != 4 :
1399
+ raise ValueError ("`material_appearance` must be four items (R, G, B, transparency)." )
1400
+ elif len (appearance_props ) == 3 :
1401
+ transparency_value = self .material_appearance [3 ]
1402
+ msg = "Only RGB specified. Transparency is set to " + str (transparency_value )
1403
+ self .logger .info (msg )
1404
+ appearance_props .append (transparency_value )
1405
+ value = []
1406
+ for i in range (len (appearance_props )):
1407
+ if i < 3 :
1408
+ rgb_int = int (appearance_props [i ])
1409
+ if rgb_int < 0 or rgb_int > 255 :
1410
+ raise ValueError ("RGB value must be between 0 and 255." )
1411
+ value .append (rgb_int )
1412
+ else :
1413
+ transparency = float (appearance_props [i ])
1414
+ if transparency < 0 or transparency > 1 :
1415
+ raise ValueError ("Transparency value must be between 0 and 1." )
1416
+ value .append (transparency )
1417
+ self ._material_appearance = value
1401
1418
self ._props ["AttachedData" ] = OrderedDict (
1402
1419
{
1403
1420
"MatAppearanceData" : OrderedDict (
1404
1421
{
1405
1422
"property_data" : "appearance_data" ,
1406
- "Red" : value_int [0 ],
1407
- "Green" : value_int [1 ],
1408
- "Blue" : value_int [2 ],
1423
+ "Red" : value [0 ],
1424
+ "Green" : value [1 ],
1425
+ "Blue" : value [2 ],
1426
+ "Transparency" : value [3 ],
1409
1427
}
1410
1428
)
1411
1429
}
0 commit comments