TBC Macros and Extensions

 View Only
Expand all | Collapse all

How to Pan and Zoom in 2D and 3D Views

  • 1.  How to Pan and Zoom in 2D and 3D Views

    Posted 01-05-2025 21:51

    Hey everyone,

    I have a need to move my 2D view to a specific location and zoom to a certain level. However, I couldn't figure out which method to call to make it happen. 

    I looked at the Trimble.Vce.UI.Hoops.Hoops2dView namespace and tried using "SetCameraUpVector," but it does not seem to do anything.

     This is strange because using "SetCameraUpVector" does rotate the view. Any help would be appreciated.



    ------------------------------
    Vitalii Vovk
    ------------------------------


  • 2.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-06-2025 21:28

    I did some more digging today and found a few useful methods that will help me get by. However,

    I haven't yet found a way to zoom or scale the view exactly the way I had envisioned. I'm still open to suggestions if anyone has ideas or examples to share!

    clr.AddReference("Trimble.Vce.UI.UIManager")
    from Trimble.Vce.UI.UIManager import UIEvents, TrimbleOffice
    from Trimble.Vce.Geometry import Point3D
    
    
    
    activeForm = TrimbleOffice.TheOffice.MainWindow.AppViewManager.ActiveView
    
    point = Point3D(-500, -500, 0)  
    point2 = Point3D(500, 500, 0)  
    
    # Moves the view by the specified delta 
    test1 = activeForm.PanView(10, 10, 0)  
    
    # Centers the view at the specified world coordinate point
    test2 = activeForm.CenterView(point)  
    
    # Retrieves  visible area in world coordinates (min and max points)
    test3 = activeForm.GetViewExtents()  
    
    # Sets the view extents using the specified minimum and maximum points in world coordinates
    test4 = activeForm.SetViewExtents(point, point2)  
    
    # Retrieves the current view state with parameters 
    test5 = activeForm.GetViewState()  


    ------------------------------
    Vitalii Vovk
    ------------------------------



  • 3.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-13-2025 17:36

    Hello Vitalii,

    I think this code should do what you are looking for:

    view = (Trimble.Vce.UI.UIManager.TrimbleOffice.TheOffice.MainWindow.AppViewManager.ActiveView as I2DGraphicsForm).Viewing;
    
    view.SetTransformationMatrix(left, bottom, right, top);
    view.SetCameraToArea(left, bottom, right, top);

    The 'Viewing' member has the type 'I2DViewing'. I2DGraphicsForm is defined in Trimble.Vce.UI.UIManager and I2DViewing is defined in Trimble.Vce.UI.Hoops. 

    Hope this helps!



    ------------------------------
    Arturas Grigorjevas
    ------------------------------



  • 4.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-13-2025 19:22

    What's the difference between

    activeForm.SetViewExtents(point, point2)
    
    activeForm.Viewing.SetCameraToArea(double worldLeft, double worldBottom, double worldRight, double worldTop)  #which basically is Trimble.Vce.UI.HoopsControls.HoopsPlanView.SetCameraToArea

    except that in the first one you give it two Point3D's and the second takes the same x and y but as doubles.



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



  • 5.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-13-2025 19:12
    Edited by Ronny Schneider 01-13-2025 19:22

    Hi Vitalii,

    just got back from vacation. You really just need it for Hoops2dView, not Hoops3dView?

    What is it that you can't achieve with the "SetViewExtents"? What exact scaling do you try to achieve?



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



  • 6.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-13-2025 17:36

    Hello Vitalii,

    I think this code should do what you are looking for:

    var view = (Trimble.Vce.UI.UIManager.TrimbleOffice.TheOffice.MainWindow.AppViewManager.ActiveView as I2DGraphicsForm).Viewing;
    
    view.SetTransformationMatrix(left, bottom, right, top);
    view.SetCameraToArea(left, bottom, right, top);

    The 'Viewing' member is of the type 'I2DViewing'. I2DGraphicsForm is defined in Trimble.Vce.UI.UIManager and I2DViewing is defined in Trimble.Vce.UI.Hoops. 

    Hope this helps!



    ------------------------------
    Arturas Grigorjevas
    ------------------------------



  • 7.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-16-2025 20:15

    Thank you @Arturas Grigorjevas!  I will play with these classes over the weekend



    ------------------------------
    Vitalii Vovk
    ------------------------------



  • 8.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-16-2025 20:28

    I wanted to move the screen to a specific location and set it to a specific size, either on the horizontal or vertical side of the screen.

     This is a simplified version of the class that I ended up using.

    class MoveView:
        def __init__(self, *args, **kwargs):
            self.activeForm = TrimbleOffice.TheOffice.MainWindow.AppViewManager.ActiveView
    
    
        def panView(self, delta_X, delta_Y):
            self.activeForm.PanView(delta_X, delta_X, 0)
    
        def panViewToP(self, newCenterPoint):
            curCenterPoint = self.getCenterPointScreen()   
            delta_Vector = curCenterPoint - newCenterPoint
            # Correct axis values
            delta_X = delta_Vector.X
            delta_Y = delta_Vector.Y  # Fixed Y-axis reference
            # Apply panning
            self.activeForm.PanView(delta_X, delta_Y, 0)
            return True
    
        def getCenterPointScreen(self):
            pMin, pMax = self.activeForm.GetViewExtents()
            screen_vector = pMax - pMin
            screen_vector.To2D()
            screen_vector.Length = screen_vector.Length / 2  # Scale vector length
            curCenterPoint =  pMin + screen_vector
            curCenterPoint.Z = 0.0
            return curCenterPoint
    
    
        def moveView(self, newCenterPoint):
            # Center view to the new point
            self.activeForm.CenterView(newCenterPoint)
            return True
    
    
        def adjustViewSize(self, length, x_Axis = True):
            side_length = length/2 #half side length of desired axis
            curCenterPoint = self.getCenterPointScreen()
            pMin, pMax = self.activeForm.GetViewExtents()
    
            yAxis_halfLength = curCenterPoint.Y - side_length
            p_center_btm_yAxis = Point3D(curCenterPoint.X, yAxis_halfLength )
            v_yAxis = p_center_btm_yAxis - curCenterPoint # venctor pointing alon Y-axis
    
            #adjustment  angle for fliping size requirement from X-axis to Y-axis
            ang_adjustment = Math.PI/2 if x_Axis else 0  
    
            v_screenDiagonal = pMin - curCenterPoint #vector along diagonal of the scren from center to the btm left corner
            v_screenDiagonal.To2D()
    
            # find horizontal angle between vectors and adjust if needed
            ang = abs(Vector3D.HzAngleBetween(v_screenDiagonal, v_yAxis))
            ang = ang_adjustment - ang
    
            cos = 1 if Math.Cos(ang) == 0 else Math.Cos(ang)
            #find hypothenus legth of triangle that would be correct diagonal size from center to btm left corner of the screen
            half_diagonal_length =  side_length / cos 
            v_screenDiagonal.Length = half_diagonal_length #adjust diagonal vector to the correct size
    
            #find new min and max poins for the screen
            new_pMin = curCenterPoint + v_screenDiagonal
            v_screenDiagonal.Rotate180()
            new_Pmax = curCenterPoint + v_screenDiagonal
            self.activeForm.SetViewExtents(new_pMin, new_Pmax)
            return True


    ------------------------------
    Vitalii Vovk
    ------------------------------



  • 9.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-16-2025 21:06

    I see. Especially with a rotated view this becomes tricky if the original SetViewExtends is not sufficient. I'll have to contemplate about this a bit more.

    your 

    def getCenterPointScreen

    can probably be shortened to

    pMin, pMax = v.GetViewExtents()
    curCenterPoint = Point3D.MidPoint(pMin, pMax)

    for a Planview the extend coordinates should return as 2D with Z=0 anyway.



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



  • 10.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-16-2025 21:28

    Good catch!  

    curCenterPoint = Point3D.MidPoint(pMin, pMax)


    ------------------------------
    Vitalii Vovk
    ------------------------------



  • 11.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-19-2025 21:38
    Edited by Ronny Schneider 01-21-2025 23:06

    The following might be a bit shorter version of what you tried above.

                        # bl - bottom left; br - bottom right; tr - top right
                        cgrav = Point3D.MidPoint(bl, tr)                    
                        # rotation between target view and unrotated view
                        rot = Vector3D(bl, br).Azimuth - Vector3D(1,0,0).Azimuth
                        # temp vector for view extends from bottom left to top right
                        vbltr = Vector3D(bl, tr)
                        # rotate the temp vector to standard/unrotated orientation
                        vbltr.RotateAboutZ(rot)
                        
                        # set the view extends with the temp vector in unrotated state
                        activeForm.SetViewExtents(bl, bl + vbltr) # that will reset the view rotation and won't center the view properly
                        activeForm.CenterView(cgrav)
                        
                        # reset the view rotation 
                        activeForm.SetCameraUpVector(Vector3D(br, tr))

    I came across the same issue while trying to batch export the background imagery along a long stretch of road as georeferenced images while using my rotated plot frames as reference. You need those images if you want to plot the background imagery, the plot routine ignores the map background.

    The issue is the half-heartedly thrown in plan-view rotation. It works, but that's about it, hasn't been touched/improved since it was introduced with V5.52. Without extra macros, that allow i.e. to align a view properly to a line/rectangle, it's still pretty useless. And as we've demonstrated here the Hoops2dView.SetViewExtends doesn't account properly for it either. Surface legends get screwed up and so on.

    Furthermore, what I tried to do, to export a rotated geo-referenced image with Hoops2dView.ViewCaptureNoUI, that is aligned to a rotated view, doesn't work either. The world file is generated without the rotation and the imported image gets distorted. Will have to jump through more hoops to get this working.

    Will have to report another bug to our dealer, that the "capture image" command doesn't account for the rotated plan view, if you don't use a plotbox. If you do use a rotated plotbox it will reset the view rotation first, before exporting a correctly trimmed/rotated image with a correct worldfile. Haven't found the assembly yet they're using for that, it can't be the Hoops2dView.ViewCaptureNoUI.



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



  • 12.  RE: How to Pan and Zoom in 2D and 3D Views

    Posted 01-19-2025 22:25

    Thank you, as always, @Ronny Schneider !



    ------------------------------
    Vitalii Vovk
    ------------------------------