TBC Macros and Extensions

 View Only
Expand all | Collapse all

how to use the Wpf:StationEdit

  • 1.  how to use the Wpf:StationEdit

    Posted 01-21-2021 14:49
    Hi,
    how do I tell the Wpf:StationEdit which alignment/line to use and to show the value on screen like the "explore object" function. Right now the mouse cursor disappears when the focus is on that field.
    I guess I have to have some kind of "def self.stationedit.OnLoad" with some TBC capture mouse function.

    I guess something similar can be done with the coordinate edit to achieve a view like with the ANZ-Toolbox "Measure Surface" tool.


    ------------------------------
    Ronny Schneider
    ------------------------------


  • 2.  RE: how to use the Wpf:StationEdit

    Posted 01-22-2021 08:16
    The StationEdit control has a property called "StationProvider". Set that to the alignment you want the station to be measured from. If the command lets you select this line, then set this property in the ValueChanged event (of the line's SelectEntity or ComboBoxEntityPicker control)

    ------------------------------
    Gary Lantaff
    ------------------------------



  • 3.  RE: how to use the Wpf:StationEdit

    Posted 01-23-2021 03:12
    Thanks Gary,
    that works.
    For other interested users:
    in the Xaml:
    <Wpf:SelectEntity x:Name="linepicker1"/>
    <Wpf:StationEdit x:Name="station" />​

    in the .py

        def OnLoad(self, cmd, buttons, event):
            self.Caption = cmd.Command.Caption
            self.lType = clr.GetClrType(IPolyseg)
    
            self.linepicker1.IsEntityValidCallback=self.IsValid
            self.linepicker1.ValueChanged += self.lineChanged
    
        def IsValid(self, serial):
            o=self.currentProject.Concordance.Lookup(serial)
            if isinstance(o, self.lType):
                return True
            return False
    
        def lineChanged(self, ctrl, e):
            l1=self.linepicker1.Entity
            if l1 != None:
                self.station.StationProvider = l1
    


    Any idea on how that cursor with the running values works.

    I assume something with

    self.coordpick1.MouseMoveInViewEvent += self.coordpick1update


    I just haven't figured out yet how to get the current/running cursor coordinate and how to add the text along the crosshair.



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 4.  RE: how to use the Wpf:StationEdit

    Posted 01-25-2021 09:34
    There is a helper method in BaseCommands that makes adding the text easy.

    clr.AddReference("Trimble.Vce.UI.BaseCommands")
    from Trimble.Vce.UI.BaseCommands import ExploreObjectControlHelper

    In the OnLoad method, hook up a cursor callback.

    self.startStaCtl.ShowGdiCursor += self.DrawCustomCursor

    When the user moves the mouse, this method will be called.

    def DrawCustomCursor(self, sender, e):
    if not isinstance(e.MessagingView, clr.GetClrType(I2DProjection)):
    return
    ExploreObjectControlHelper.DrawCursorText(e.MessagingView, e.MousePosition, 10, "Hello\nWorld");


    ------------------------------
    Gary Lantaff
    ------------------------------



  • 5.  RE: how to use the Wpf:StationEdit

    Posted 01-28-2021 23:19
    Thanks Gary,
    that works, I just had to figure out how to convert the view to world coordinates.
        def OnLoad(self, cmd, buttons, event):
            self.Caption = cmd.Command.Caption
            wv = self.currentProject [Project.FixedSerial.WorldView]
            self.coordpick1.ShowGdiCursor += self.DrawCustomCursor
    
        def DrawCustomCursor(self, sender, e):
            if not isinstance(e.MessagingView, clr.GetClrType(I2DProjection)):
                return
            tt = Point3D(e.MousePosition.X, e.MousePosition.Y, 0)
            tt = self.coordpick1.WindowToWorldSpaceTransform(tt, False, e.MessagingView.PageToWorld)
            ExploreObjectControlHelper.DrawCursorText(e.MessagingView, e.MousePosition, 10, "X: " + str(tt.X) + "\nY: " + str(tt.Y));
    ​



    ------------------------------
    Ronny Schneider
    ------------------------------



  • 6.  RE: how to use the Wpf:StationEdit

    Posted 06-26-2023 19:32

    Hi Ronny, 

    Do you know how to also display the station/distance of the StationEdit on the cursor live? 

    At the moment the distance is only displayed when I click on the mouse, but not live. 

    I can compute the closest point with "tt" but the station doesn't seem to be accurate once the cursor is too far from the line. 

        def DrawCustomCursor(self, sender, e):
            if not isinstance(e.MessagingView, clr.GetClrType(I2DProjection)):
                return
            dist = self.statctrl.Distance 
            tt = Point3D(e.MousePosition.X, e.MousePosition.Y, 0)
            tt = self.statctrl.WindowToWorldSpaceTransform(tt, False, e.MessagingView.PageToWorld)
     
     
            ExploreObjectControlHelper.DrawCursorText(e.MessagingView, e.MousePosition, 10, "X: " + str(tt.X) + "\nY: " + str(tt.Y) + "\nDist: " + str(dist))


    ------------------------------
    ANDY ZHOU
    ------------------------------



  • 7.  RE: how to use the Wpf:StationEdit

    Posted 06-26-2023 21:00

    Hello Andy,

    you'll have to compute the chainage with each mouse move. Not sure if there is a better solution.

    i.e. add in OnLoad

            self.startstation.MouseMoveInViewEvent += self.updatestation

    and as separate function that's been called with each mouse move

        def updatestation(self, sender, e):
            if not isinstance(sender, clr.GetClrType(I2DProjection)):
                return
            tt = Point3D(e.Location.X, e.Location.Y, 0)
            tt = self.startstation.WindowToWorldSpaceTransform(tt, False, sender.PageToWorld)
            sta = self.startstation.FindAnchorPoint(tt)[1] # returns a tuple - 1 is the chainage/station and 2 the offset
            self.startstation.Distance = sta    # updating the value shown in the station edit


    ------------------------------
    Ronny Schneider
    ------------------------------



  • 8.  RE: how to use the Wpf:StationEdit

    Posted 06-27-2023 00:15

    As always, thank you! That worked



    ------------------------------
    ANDY ZHOU
    ------------------------------