What is an Item Tag?
This does not mean item tags are only restricted to that purpose and can be extended to include significantly more details and information.
Developers have the freedom to include additional information that would better improve the user's visual understanding of items in their drawing.
Item tags can not only exist in space but can also be manipulated by the user. For example, position and rotation can be adjusted using animations, similar to snappers.
Take note that the ItemTag class does not contain all the necessary information required to build the graphics to be displayed. Instead, ItemTag instances also contain a reference to an ItemTagInfo instance, which handles all of that information. This is further explained in the ItemTagInfo section.
As item tags are textual representations of parts, item tags can’t exist without being related to any parts. The creation of item tags is generally handled using interfaces available in the Part class. This is further explored in the Creation of Item Tags section.
It is also possible to manually change what is displayed by the item tags in the drawing. This can be done in the Calculation dialog, by overriding a part's ind. tag cell.
Creation of Item Tags
/** * After get parts. Do dynamic tagging here. */ public void afterGetParts(PartsEnv env) { ... for (part in env) if (part) { str key = part.itemTagKey(); ... if (key !in itemTags) { ItemTag tag = part.createItemTag(); //Creation of item tag here. putItemTag(tag); } else { ... }
taggableSnapper.cm
From this, we can see that item tags are created from parts.createItemTag()
. This is an interface that allows developers to control what type of item tags are generated using those parts, based on what is returned in this method.
/** * Item tag. Create new tag. */ extend public ItemTag createItemTag() { ItemTagInfo info = itemTagInfo(); return ItemTag(owner, info, drawPos=(0, 0, 0), rot=0deg, key=itemTagKey()); }
The acceptItemTags()
method must be overridden to return true before any item tags can be generated. The Part
class also contains several other methods that are important to creating and manipulating item tags. Refer to cm/core/part/part.cm for the full list.
/** * Item tag key. The local key to look up correct Tag from the symbol. */ extend public str itemTagKey() { return "A"; } /** * Item tag info key. The global key to look up correct TagInfo from parts. */ extend public str itemTagInfoKey() { return flattenableKey(); } /** * Item tag default TagInfo. */ extend public ItemTagInfo createItemTagInfo() { if (owner) return owner.createItemTagInfo(this, itemTagKey(), itemTagInfoKey()); return null; } /** * Accept item tags for this part. */ extend public bool acceptItemTags() { if (data.itemTagInfo()) return true; return owner and owner.acceptItemTags(); }
ItemTagInfo
This is not the case as ItemTag has its own key (we’ll refer to this as itemTagKey) and ItemTagInfo has its own key (we’ll refer to this as itemTagInfoKey). The diagram below should help illustrate the relationship between item tags and their info.
ItemTagInfo
are stored in a weak value map that is placed in the world auxillary and can be accessed globally./** * The map to store in World. */ public class ItemTagInfoMap { public str->ItemTagInfo info(weakValue=true); public constructor() {} }
This is because we want to reuse the same repeated information with different item tags that refer to the same parts. Different item tags should be able to refer to the same ItemTagInfo. As long as we have the correct itemTagInfo key, we are able to access the same itemTagInfo instance from different item tags by retrieving it from this map.
/** * Get the ItemTagInfo from world. */ public ItemTagInfo worldItemTagInfo(World world, str key) { if (!world) world = session.mainWorld(); if (world) { Object map = world.getAuxillary(cItemTagInfoKey); if (map as ItemTagInfoMap) { return map.info.get(key); } } return null; } /** * Put the ItemTagInfo in world auxillary. */ public ItemTagInfo worldPutItemTagInfo(World world, ItemTagInfo info) { if (!info) return null; str key = info.key; if (!world) world = session.mainWorld(); if (world) { Object map = world.getAuxillary(cItemTagInfoKey); if (!map) { map = new ItemTagInfoMap(); world.putAuxillary(cItemTagInfoKey, map); } if (map as ItemTagInfoMap) { map.info.put(key, info); return info; } } return null; }
Item Tag Visibility
Like any graphical object existing in space, visibility of item tags can be restricted to specific view modes with the use of layers.
/** * Visibility layers in 2D. */ public LayerExpr visibility2D() { LayerExpr layer; if (info and info.layer) layer = info.layer; else if (owner and owner.visibility2D) layer = owner.visibility2D; return categories.any() ? or(layer, layerSet(categories)) : layer; }
By default, this method checks the item tag's info for any layer expressions associated with it. A good interface to control which layers your item tags are visible in is the following method in ItemTagInfo.
/** * The layer the text should be shown in drawing. */ extend public LayerExpr layer() { return null; }
For more information on layers and visibility, refer to Visibility: Layers, View Modes, and LayerExpr
Leader Item Tag
An ItemTag class with a leader arrow to specific features on a Snapper can be found in 'cm/core/itemTag/leaderItemTag.cm'. In addition to the ItemTag behaviors, this subclass allows for better alignment, referencing, and visibility when using ItemTags on products within CET.
Comments
0 comments
Please sign in to leave a comment.