Norm Kirchner Posted August 8, 2009 Report Share Posted August 8, 2009 Has anyone worked up the algorithm needed to take a terminal and find it's root source of data? IOW, if I have the terminal of a sub-vi that is wired to a FP control terminal through many structures, is the code out there needed to trace the wire back to where the data originated? Thanks Quote Link to comment
vugie Posted August 10, 2009 Report Share Posted August 10, 2009 (edited) Terminal has a property Connected wire . You take a wire and get its Terminals[]. The first terminal in this array is always a source terminal (terminals has also Is source? property) - let's call it STerm. Now you have to go through all GObjects on the same diagram. You have four cases here: GObject is either Control, Constant, Node or FlatSequence. Two former have single Terminal property (according to AQ you can typecast Constant to Control making it one case), two latter have Terminals[] property. So for each GObject of these types you have to go through all its terminals (one or more) comparing their references to STerm. It may appear that node you found is a loop or other structure. In this case if you like to search further for the source you have to specify class of terminal reference to OuterTerminal, take Tunnel property, then its Inside Terminals[] property and recursively go further. In simple form I'm doing something similar here in Generate Objects and Links.vi Edited August 10, 2009 by vugie Quote Link to comment
gb119 Posted August 10, 2009 Report Share Posted August 10, 2009 On a related topic, does anyone have a good algorithm for working out (given a set of co-ordinates) on which segment of a wire a mouse click has been made and therefore which drain terminal that segment is connected to ? This is kind of important if one wants to insert a node into a wire between the source and only one specific drain terminal. Terminal has a property Connected wire . You take a wire and get its Terminals[]. The first terminal in this array is always a source terminal (terminals has also Is source? property) - let's call it STerm. Now you have to go through all GObjects on the same diagram. You have four cases here: GObject is either Control, Constant, Node or FlatSequence. Two former have single Terminal property (according to AQ you can typecast Constant to Control making it one case), two latter have Terminals[] property. So for each GObject of these types you have to go through all its terminals (one or more) comparing their references to STerm. It may appear that node you found is a loop or other structure. In this case if you like to search further for the source you have to specify class of terminal reference to OuterTerminal, take Tunnel property, then its Inside Terminals[] property and recursively go further. Quote Link to comment
PJM_labview Posted August 10, 2009 Report Share Posted August 10, 2009 On a related topic, does anyone have a good algorithm for working out (given a set of co-ordinates) on which segment of a wire a mouse click has been made and therefore which drain terminal that segment is connected to ? This is kind of important if one wants to insert a node into a wire between the source and only one specific drain terminal. I think that this is what you are asking for: PJM Quote Link to comment
vugie Posted August 10, 2009 Report Share Posted August 10, 2009 I think that this is what you are asking for: PJM This is not required as: Terminals[] PropertyProperty of Wire. References to the terminals connected by this wire. The first one is always the source, if one exists. (from documentation)But I guess that gb119 would be more interested in this: Joints[] Property Property of Wire. Returns an array of all joints (intersections, bends and end points) of the wire. The output of this property is an array of clusters, where each cluster represents one joint of the wire. The cluster can be interpreted as follows: The Position is the X,Y position on the block diagram of this joint. The Type indicates whether this joint is a bend in the wire, a fork of the wire, a connection to a terminal or a loose end of the wire. Up/Down/Left/Right are indexes into the array for the joints that are next along the wire in the respective direction from the current joint. The Flags are defined as follows: 0x1 Joint is connected to one of the terminals of the signal. 0x2 Used for optimizing redraw of signals. Do not modify. 0x4 Used for optimizing redraw of signals. Do not modify. 0x8 Joint is currently selected on the block diagram. If any edge connected to the joint (up, down, left or right) is selected, this bit will be set. 0x10 Right edge is selected 0x20 Down edge is selected 0x40 Used for optimizing routing. Do not modify. 0x80 Used for optimizing routing. Do not modify. 0x100 Joint is loose (meaning it is not anywhere along a path between two joints that are both connected to terminals). Do not modify. 0x200 Joint is on path (opposite of "loose"). Used during path and split algorithms. Do not modify. 0x400 Unused 0x800 Unused 0x1000 During the most recent edit operation, this joint was shifted horizontally (cleared when wire table is rebuilt at the end of every edit operation) 0x2000 During the most recent edit operation, this joint was shifted vertically (cleared when wire table is rebuilt at the end of every edit operation) 1 Quote Link to comment
Yair Posted August 11, 2009 Report Share Posted August 11, 2009 Also, the wire segments (I think) have a flags property where bit 4 says whether it's selected or not. It might also help. Quote Link to comment
gb119 Posted August 11, 2009 Report Share Posted August 11, 2009 Also, the wire segments (I think) have a flags property where bit 4 says whether it's selected or not. It might also help. Hmmm, that all helps, but it looks like a routine that then traverses the wire to work out which terminal(s) are down-wire of a selected segment is still needed. I'll add it to my l"interesting things to look at when I have time" list... Quote Link to comment
vugie Posted August 11, 2009 Report Share Posted August 11, 2009 (edited) Also, the wire segments (I think) have a flags property where bit 4 says whether it's selected or not. It might also help. No such object as wire segment exist according to my knowledge. Only joints. Segment is only visual representation of connections between joints. Joint may be either bend, junction, end or loose end. From the joint wire may go to up, down, left and right (any combination for junctions, two directions for bends and one for ends). If selected segment of the wire is a connection of given joint, its 4th bit (0x8) is set to 1. Only in this case bits 5th and 6th (0x10 and 0x20) have sense. 0 for 0x10 means that left joint side is selected (if present) and 1 means that right joint side is selected. Similarly for 0x20 bit for up and down respectively. Note that bits 0x10 and 0x20 have not much sense for junctions - where segments may be selected in up to 4 directions. Two bits are simply too less to describe such situation. Two figure out what is the situation with selection for junction you have to follow the wire further to the next bend and read it out from the bend. What if you have few 4-directional junctions in row? I don't know. But gb119, what do you exactly need it for? Is Selected property and then first element of Terms[] property not enough to get a source of selected wire? Edited August 11, 2009 by vugie 1 Quote Link to comment
Yair Posted August 11, 2009 Report Share Posted August 11, 2009 vugie, you're right. I was thinking of the same thing you posted in your original reply. I even saw the text you quoted, but for some reason it didn't register as being the same thing. Quote Link to comment
gb119 Posted August 11, 2009 Report Share Posted August 11, 2009 But gb119, what do you exactly need it for? Is Selected property and then first element of Terms[] property not enough to get a source of selected wire? This is thinking about right click framework plugins for inserting code into a wire - but if the wire is branched you need to know which bit of the branch you are trying to break into - i.e. inserting before a branch point or after a branch point makes a difference to the code. Quote Link to comment
vugie Posted August 12, 2009 Report Share Posted August 12, 2009 This is thinking about right click framework plugins for inserting code into a wire - but if the wire is branched you need to know which bit of the branch you are trying to break into - i.e. inserting before a branch point or after a branch point makes a difference to the code. It won't be trivial. You have to make sure that only one segment is selected (two neigbouring joints have 0x8 flag set), follow the wire in direction of source to find eventual junctions, follow in opposite direction to find all sink terminals... And remember that the only way to change anything in the wire is to delete it and then recreate. Quote Link to comment
gb119 Posted August 12, 2009 Report Share Posted August 12, 2009 It won't be trivial. Yup, that's why I thought I'd ask if anyone wither had already done it or knew of a smarter way to do it.... Quote Link to comment
Rolf Kalbermatter Posted August 17, 2009 Report Share Posted August 17, 2009 Terminal has a property Connected wire . You take a wire and get its Terminals[]. The first terminal in this array is always a source terminal (terminals has also Is source? property) - let's call it STerm. Now you have to go through all GObjects on the same diagram. You have four cases here: GObject is either Control, Constant, Node or FlatSequence. Two former have single Terminal property (according to AQ you can typecast Constant to Control making it one case), two latter have Terminals[] property. So for each GObject of these types you have to go through all its terminals (one or more) comparing their references to STerm. It may appear that node you found is a loop or other structure. In this case if you like to search further for the source you have to specify class of terminal reference to OuterTerminal, take Tunnel property, then its Inside Terminals[] property and recursively go further. In simple form I'm doing something similar here in Generate Objects and Links.vi I have found that having a wire and getting its Terms[] property you can get directly to the object (node, terminal or whatever) that wire is connected to. For Control class (Control & Indicator terminals) the Term is directly the control (cast it using To more specific class) while for other objects you can use the Owner Property to get at the node, structure or whatever that owns the term. As to the first element in a Terms[] array always being a source, that is not entirely true. If the wire has no source at all (broken wire) the first element will be one of the sinks it is connected to. Rolf Kalbermatter Quote Link to comment
vugie Posted August 17, 2009 Report Share Posted August 17, 2009 ...while for other objects you can use the Owner Property to get at the node, structure or whatever that owns the term. Good point. Why I didn't find something so obvious? As to the first element in a Terms[] array always being a source, that is not entirely true. If the wire has no source at all (broken wire) the first element will be one of the sinks it is connected to. Also when there is more than one source (also broken wire), the rest of sources may be anywhere in the array. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.