News:

BB code in posts seems to be working again!
I haven't turned on every single tag, so please let me know if there are any that are used/needed but not activated.

Main Menu

Direction of last segment of multi-segment connector?

Started by Rich_Cohen, June 30, 2012, 12:34:02 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Rich_Cohen

I'm trying to develop logic that will automatically position a text box near the end of a connector.  The desired position depends on which way the last segment of the connector points.  Since these connectors are all straight lines, the simplest approach would use the relative positions of the last two points in the connector's geometry table.  Now I know how to use SEGMENTCOUNT to determine how many rows are in the geometry table and I know that geometry1.x4 will return the value of x for the 4th row in the table, but how do I do the same thing for row n where n = SEGMENTCOUNT + 1?  I couldn't find a way.

After a lot of experimenting I did find an alternative that works, but if feels kludgy:

ANGLEALONGPATH(Geometry1.Path,0.5,SEGMENTCOUNT(Geometry1.Path))/PI()

This will return a value from 1 to -1 where 1 is left, .5 is up, 0 is right and -.5 is down.  I can test for this and the rest works fine.  However it feels kludgy and I'm concerned there will be a performance problem if I put this code into 4 or 6 cells in every one of hundreds of connectors.  At alternative would be a Visual BASIC function that only updates the style sheet on command.  I might go that route, but I'm looking for something elegant that will modify my text positions as I move connectors around.

Any ideas or comments?   I'll post my finished connector here in a few days regardless of the results.


Rich_Cohen

Yes, that was a help.  Thank you.  As you can see, I had already discovered the ANGLEALONGPATH, but I didn't realize I could make it work as simply as in that example.  It also confirms that my approach is not as kludgy as I believed.

Rich_Cohen

Hi everyone.  I promised I'd post my connector when I was finished.  Here it is.  I'm a data modeler and I draw large diagrams with with boxes and lines.  The boxes are Entities of interest to the business and the lines are relationships.  The way I do it each relationship has two names so it can be read in either direction.  For that I needed two labels per connector.  I got the clues for doing 2 labels in a 2-year old thread on this forum, but I had to do a lot of work to figure it out and make it do what I wanted.  The second issue is that I wanted each label to be positioned horizontally next to the connector and the appropriate box.  The problem was that the desired position depends on which face of the box is connected.  I'd already figured out that ANGLEALONGPATH was the key, but the help I got here confirmed that and helped me understand how to make it work smoothly.

If you open the code for the black connector in the sample, you'll see the code I wrote.  The key code is in the user cells and the X and Y controls.  Two user cells determine the direction of the to and from ends of the connector.  I do it once and reuse the result many times.  The X and Y controls determine which quadrant the connector end is in and adjusts the text position appropriately.  I could have put the quadrant determination into the user cells, but I felt it would be clearer to test for position in degrees in the control cells.  It also made the code more extensible if I ever need to work with something other than rectangles.

Figuring out how to manage the second text box took some time because the samples I found didn't work smoothly and had some code I could not easily understand.  By the way, to see the shape sheet for the second text field, you need to click on the "To" field and open its shape sheet.  Once I worked things out, the only special code needed is found into the PinX and PinY cells of the second text box.  These link the text field to the to end of the parent connector.

Now for the fun part!  My original code worked fine except when a connector is nearly a straight line.  When the jog is less than .25" some funny things happen.  To see this, open the sample and move the Process box to the left with the arrow key.  The same thing happens for a horizontal connector.  It took a lot of time to pin down the problem.  First I discovered that the height and width cells in the Shape Transform section will not return a absolute value of less that .25".  Thats why I added my own user-defined height and width cells.  Then I found that even with my own correct values at hand, my logic insisted in adjusting the text position in an unwanted manner.  I eventually had to write additional logic to counteract this effect.  That extra logic is at the end of each of the control cell functions for the black connector and has been removed for the red connector to display the misbehavior.  If anyone can explain what is happening or show me a better way of preventing it, I'd appreciate that.

Meanwhile, enjoy my code.  I hope some of you find it useful.   Thanks to Visio Guy for the example and to Aledlund for giving me the link.  I'm probably going to enhance this some day with extra features, but right now I've got a 200 entity Enterprise Logical Data Model to put together.  That will go a lot easier with this new connector.

Browser ID: smf (possibly_robot)
Templates: 4: index (default), Display (default), GenericControls (default), GenericControls (default).
Sub templates: 6: init, html_above, body_above, main, body_below, html_below.
Language files: 4: index+Modifications.english (default), Post.english (default), Editor.english (default), Drafts.english (default).
Style sheets: 4: index.css, attachments.css, jquery.sceditor.css, responsive.css.
Hooks called: 186 (show)
Files included: 34 - 1306KB. (show)
Memory used: 1062KB.
Tokens: post-login.
Cache hits: 14: 0.00119s for 26,766 bytes (show)
Cache misses: 3: (show)
Queries used: 15.

[Show Queries]