Page Index Toggle Pages: 1 [2] 3  Send TopicPrint
Very Hot Topic (More than 25 Replies) Moving link lables (Read 16432 times)
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #15 - Aug 17th, 2010 at 2:34pm
Print Post  
It should work if you implement either a copy constructor or DiagramItem.Clone() override in the custom link class.

Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #16 - Aug 17th, 2010 at 9:58pm
Print Post  
Thank you Stoyan, I will try that ..
. is there a way to place link labels at a desired proper position... please see the image that I will send through email. somehow  the link labels don’t start at the position that we would like to have it..
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #17 - Aug 18th, 2010 at 5:16am
Print Post  
The base link class sets its label position to the middle control point or to the center of its middle segment:

Code
Select All
Point pos = points.Count % 2 == 1
	? points[points.Count / 2]
	: Utilities.Mid(points[points.Count / 2 - 1], points[points.Count / 2]);

Rect bounds = GetBounds();
TextBlock.Margin = new Thickness(pos.X - bounds.X - TextBlock.ActualWidth / 2, pos.Y - bounds.Y - TextBlock.ActualHeight, 0, 0); 



I suppose you need this as one-time initialization, so you could set the label position in response to LinkCreated. Additionally, use a translate-transform as in the sample, instead of Margins.

Perhaps it would be better to keep the custom label position as a relative distance from the point found by the code above, and update the absolute position from the UpdateTextLayout override. Then the label will follow the link if the user moves a control point. Otherwise, it keeps its position relative to the top-left of the link's bounding rectangle.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #18 - Sep 2nd, 2010 at 9:13pm
Print Post  
Hi Stoyan,
I implemented this code.. however I get this Compile time error..
Error2'MindFusion.Diagramming.Silverlight.Utilities' does not contain a definition for 'Mid'
am I missing some dll or its version... when do you guys plan to release the next version of Diagramlitedll?

  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #19 - Sep 3rd, 2010 at 5:37am
Print Post  
Hi Don,

Mid just returns the geometric middle of two points, i.e. new Point((p1.X + p2.X) / 2, (p1.Y + p2.Y) / 2).

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #20 - Sep 5th, 2010 at 9:02pm
Print Post  
Hi Stoyan, I implemented everything you said.. And something’s work great but not all..
1) When I create a link that was saved earlier in the database.. I create and set the text block margins like this..


List<Point> points = link2.ControlPoints;
                       Point midPoint = new Point(
                           (points[0].X + points[points.Count - 1].X) / 2,
                           ((points[0].Y + points[points.Count - 1].Y) / 2));

                       Rect bounds = link2.GetBounds();

                       link2.TextBlock.Margin = new Thickness(midPoint.X - bounds.X - link2.TextBlock.ActualWidth / 2, midPoint.Y - bounds.Y - link2.TextBlock.ActualHeight, 0, 0);

And this works great..

After I draw all the nodes and links I go to the database again and make a call to get the users last saved geometry (if available). This geometry stores the control points and label position. I then set those settings like this..
  RouteLabelLocation lableLocation = routeGeometry.labelLocation;
                           if (lableLocation.xCoordinate != 0 && lableLocation.yCoordinate != 0)
                           {

                               link.TextBlock.Margin = new Thickness(lableLocation.xCoordinate, lableLocation.yCoordinate, 0, 0);
                                                         }
                           link.UpdateFromPoints();

Somehow the user set label positions are not reflected.

2) When the user drags the labels there is a gap between the mouse cursor and the label. Like a huge gap sometimes 100 pixel differences. This started only after I started setting the margins.. What code changes should I do to make the label follow the mouse co-ordinates? 
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #21 - Sep 6th, 2010 at 11:52am
Print Post  
Hi Don,

2) I think you can't set negative margins, and that prevents the label from moving past the left or top of the link's bounding rectangle, and that's why our developer changed the sample to use a TranslateTransform.

1) Calling UpdateFromPoints will also run the UpdateTextLayout method. Make sure the label is not centered again when that happens. Perhaps you should add a new field to your link class to store the label position, and make UpdateTextLayout set the label's TranslateTransform to the value of this field. Then you'll only have to make sure that it is initialized to the link's center when a new link is created, and change the movement and db-loading code to set that field's value and call UpdateTextLayout.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #22 - Sep 8th, 2010 at 9:32pm
Print Post  
Thanks Stoyan.. I have implemented this.. it seems to work ok.. There are a few pixel difference between what I save and retrieve.. I am not sure if I am doing the right thing.. I am saving the Top and Y co-ordinate and Left for X co-ordinate.

when will you release the production version of the dll whereby we will be able to double click the link label and Raise the routes double click event handler?
  

Don Almeida.
Back to top
 
IP Logged
 
donalmeida
Junior Member
**
Offline


Yay...

Posts: 65
Joined: Oct 6th, 2009
Re: Moving link lables
Reply #23 - Sep 14th, 2010 at 8:38pm
Print Post  
Hey Stoyan, when will you include double clicking the link label and raising the link double click event handler?
  

Don Almeida.
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #24 - Sep 15th, 2010 at 10:00am
Print Post  
In version 1.8 later this month.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #25 - Sep 16th, 2010 at 6:20pm
Print Post  
This build raises LinkDoubleClicked for the label too:
https://mindfusion.eu/_beta/diaglite18_dblclick.zip

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
dolfandon
Junior Member
**
Offline



Posts: 51
Location: Northern Virginia
Joined: Mar 12th, 2009
Re: Moving link lables
Reply #26 - Sep 28th, 2010 at 3:36pm
Print Post  
OK, I implemented the beta control and now I have an issue when I multi-select the routes. I am setting the select property within the control and I get a null pointer exception.

       public bool IsSelected
       {
           get { return isSelected; }
           set
           {
               isSelected = value;
               if (value)
               {
                   Selected = true;
                   TextBlock.FontWeight = FontWeights.ExtraBold;
               }
               else
               {
                   Selected = false;
                   TextBlock.FontWeight = FontWeights.Normal;
               }
           }
       }

System.NullReferenceException was unhandled by user code
  Message="Object reference not set to an instance of an object."
  StackTrace:
      at MindFusion.Diagramming.Silverlight.Selection.RemoveItem(DiagramItem item)
      at MindFusion.Diagramming.Silverlight.DiagramItem.set_Selected(Boolean value)
      at ProcessDesigner.ViewModel.CustomDiagramLink.set_IsSelected(Boolean value)
      at ProcessDesigner.MainPage.diagram_LinkSelected(Object sender, LinkEventArgs e)
      at MindFusion.Diagramming.Silverlight.Diagram.OnLinkSelected(LinkEventArgs e)
      at MindFusion.Diagramming.Silverlight.Diagram.x687b9b7bc932d66f(DiagramItem xccb63ca5f63dc470)
      at MindFusion.Diagramming.Silverlight.DiagramItem.x5db081b43af662f4(Boolean x8f9d3ffcb9383cde)
      at MindFusion.Diagramming.Silverlight.Selection.xc72e48b5cfcebb45(DiagramItem xccb63ca5f63dc470)
      at MindFusion.Diagramming.Silverlight.Selection.x5de01b52457c5b58(Rect x26545669838eb36e)
      at MindFusion.Diagramming.Silverlight.Selection.EndDrag(InteractionState ist)
      at MindFusion.Diagramming.Silverlight.InteractionState.Commit(Point currentPoint)
      at MindFusion.Diagramming.Silverlight.BehaviorBase.OnMouseUp(MouseButtonEventArgs e)
      at MindFusion.Diagramming.Silverlight.Diagram.x66c89b500bffc63d(Object xe0292b9ed559da7d, MouseButtonEventArgs xfbf34718e704c6bc)
      at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
      at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
  InnerException:


Don
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #27 - Sep 28th, 2010 at 5:45pm
Print Post  
Are you setting Selected = false for some links from the LinkSelected handler? That might not be safe if the control loops over the selection collections at that time, e.g. when doing multiple selection. Instead, try unselecting the links from SelectionChanged, which is raised just once after drawing the selection rectangle. If you need to disable multiple selection, set diagram.Selection.AllowMultipleSelection = false.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
dolfandon
Junior Member
**
Offline



Posts: 51
Location: Northern Virginia
Joined: Mar 12th, 2009
Re: Moving link lables
Reply #28 - Sep 30th, 2010 at 6:42pm
Print Post  
OK, yea that was it. I was setting selected in mouse down of the custom links. Can I take a node out of the hit test? I.E. make it pass through.

Note: I tried setting the IsHitTestVisable property of the swim lanes but it still doesn't pass the double click to the link underneath.
« Last Edit: Sep 30th, 2010 at 7:47pm by dolfandon »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Moving link lables
Reply #29 - Oct 1st, 2010 at 8:03am
Print Post  
This version should ignore items whose Is-HitTestVisible property is disabled:
https://mindfusion.eu/_beta/diaglite18_hittest.zip

Now that seems to differ from Locked only in not raising click events.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1 [2] 3 
Send TopicPrint