Jump to content

Traverse wire to source


Recommended Posts

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 by vugie
Link to comment

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.

Link to comment

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:

post-121-124994005499_thumb.png

PJM

Link to comment

I think that this is what you are asking for:

post-121-124994005499_thumb.png

PJM

This is not required as:

Terminals[] Property

Property 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)

  • Like 1
Link to comment

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...

Link to comment

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 by vugie
  • Like 1
Link to comment

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.

Link to comment

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.

Link to comment

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

Link to comment

...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.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.