### Author Topic: Constant screen point (translated from WCS)  (Read 215 times)

0 Members and 1 Guest are viewing this topic.

#### Grrr1337

• Bull Frog
• Posts: 453
##### Constant screen point (translated from WCS)
« on: December 05, 2017, 08:14:29 am »
Hey guys,

I'm trying to figure out is there a way to:
Translate a given [WCS] point to a point on-screen (WcsPt->ScreenPt),
and then reconvert it back to WCS (ScreenPt->WcsPt).
Which would basically result to a constant position on the screen, while scrolling and panning.

I've assembled a quick test function to help you visualise the result you got:
Code - Auto/Visual Lisp: [Select]
`(defun C:test ( / p s g )  (setq p (getpoint "\nPick a point: "))  (setq p (WcsPt->ScreenPt p)) ; convert to Screen Point  (princ "\nTrapped in (grread) loop - please scroll and pan.") (redraw)  (while (not s)    (setq g (grread t))    (and (or (equal g '(2 13)) (= (car g) 25)) (setq s t)) ; enter/RMB to exit    (and (= (car g) 5) ; cursor      ; (LM:grx p 5 1) ; constant WCS point      (LM:grx         (ScreenPt->WcsPt p) ; Reconvert to WCS point ; should be constant Screen Point        5 1      )     ); and  ); while  (princ "\nLoop complete.") (redraw)  (princ)); defun ;; grX  -  Lee Mac ;; p - [lst] WCS point at which to display 'X';; s - [int] size of point (in pixels);; c - [int] ACI colour of point;; Returns supplied WCS point. (defun LM:grx ( p s c / -s r q )  (setq r (/ (getvar 'viewsize) (cadr (getvar 'screensize)))    q (trans p 0 3)    -s (- s)  )  (grvecs    (list c      (list -s -s) (list s  s) (list -s (1+ -s)) (list (1- s)  s) (list (1+ -s) -s) (list s (1-  s))      (list -s  s) (list s -s) (list -s (1-  s)) (list (1- s) -s) (list (1+ -s)  s) (list s (1+ -s))    )    (list      (list r  0. 0. (car  q))      (list 0. r  0. (cadr q))      (list 0. 0. r  0.)      (list 0. 0. 0. 1.)    )  )  p)`

But I'm not sure how to write the (WcsPt->ScreenPt) and (ScreenPt->WcsPt),
my guess is by using the:
Code: [Select]
`(/ (getvar 'viewsize) (cadr (getvar 'screensize))`from the (grdrawpoint) technique.

#### ribarm

• Water Moccasin
• Posts: 1710
• Marko Ribar, architect
##### Re: Constant screen point (translated from WCS)
« Reply #1 on: December 05, 2017, 10:35:33 am »
As from what I understood, you only need to use trans function... (trans p 1 2)  and (trans p 2 0)... But all this is unnecessary as you only need to provide point in WCS as argument for (LM:grx)... So perhaps :

Code - Auto/Visual Lisp: [Select]
`(defun C:test ( / p s g )  (setq p (getpoint "\nPick a point: "))  ;  (setq p (WcsPt->ScreenPt p)) ; convert to Screen Point  (setq p (trans p 1 2)) ; convert from UCS to DCS (display coord sys)  (princ "\nTrapped in (grread) loop - please scroll and pan.") (redraw)  (while (not s)    (setq g (grread t))    (and (or (equal g '(2 13)) (= (car g) 25)) (setq s t)) ; enter/RMB to exit    (and (= (car g) 5) ; cursor      ; (LM:grx p 5 1) ; constant WCS point      ;|      (LM:grx         (ScreenPt->WcsPt p) ; Reconvert to WCS point ; should be constant Screen Point        5 1      )      |;      (LM:grx         (trans p 2 0) ; Reconvert to WCS point ; should be constant Screen Point        5 1      )    ); and  ); while  (princ "\nLoop complete.") (redraw)  (princ)); defun `

But the result is equal to :

Code - Auto/Visual Lisp: [Select]
`(defun C:test ( / p s g )  (setq p (getpoint "\nPick a point: "))  ;  (setq p (WcsPt->ScreenPt p)) ; convert to Screen Point  (setq p (trans p 1 0)) ; convert from UCS to WCS  (princ "\nTrapped in (grread) loop - please scroll and pan.") (redraw)  (while (not s)    (setq g (grread t))    (and (or (equal g '(2 13)) (= (car g) 25)) (setq s t)) ; enter/RMB to exit    (and (= (car g) 5) ; cursor      (LM:grx p 5 1) ; constant WCS point      ;|      (LM:grx         (ScreenPt->WcsPt p) ; Reconvert to WCS point ; should be constant Screen Point        5 1      )      |;    ); and  ); while  (princ "\nLoop complete.") (redraw)  (princ)); defun `

I hope it has some meaning, otherwise I don't quite understand what do you need to achieve...
Marko Ribar, d.i.a. (graduated engineer of architecture)

#### Grrr1337

• Bull Frog
• Posts: 453
##### Re: Constant screen point (translated from WCS)
« Reply #2 on: December 05, 2017, 11:27:54 am »
I hope it has some meaning, otherwise I don't quite understand what do you need to achieve...

Just tried to figure out a substitute for a modeless dialog by utilising (LM:GrText) and this technique, so the shown information "locks" at the screen position.

#### VovKa

• Swamp Rat
• Posts: 873
• Ukraine
##### Re: Constant screen point (translated from WCS)
« Reply #3 on: December 05, 2017, 12:25:04 pm »
Code: [Select]
`(defun vk_GetPixelSize () (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE"))))(defun vk_Point2Pixel (p)  (mapcar '+   (getvar "SCREENSIZE")   (mapcar '/ (mapcar '- p (getvar "VIEWCTR")) (list (vk_GetPixelSize) (vk_GetPixelSize)))  ))(defun vk_Pixel2Point (p)  (mapcar '+   (getvar "VIEWCTR")   (mapcar '* (mapcar '- p (getvar "SCREENSIZE")) (list (vk_GetPixelSize) (vk_GetPixelSize)))  ))`

#### Grrr1337

• Bull Frog
• Posts: 453
##### Re: Constant screen point (translated from WCS)
« Reply #4 on: December 05, 2017, 12:43:08 pm »
Wow,
Vovka your suggestion worked like a charm!
Now people can dock information on the screen (by combining this with (LM:GrText)), while using (grread) or reactors...

This thread resulted when I wanted to help a user from another forum, who complained about (acet-ui-status) that supported only 3 lines of text.
And it seemed that (acet-ui-status) was the only way[?] to display info from a modeless dialog, without annoying the user while working.

#### Lee Mac

• Seagull
• Posts: 11854
• AutoCAD 2015 Windows 7 London, England
##### Re: Constant screen point (translated from WCS)
« Reply #5 on: December 05, 2017, 01:13:38 pm »
FWIW, there is also (acet-geom-pixel-unit) which will return the same as (/ (getvar 'viewsize) (cadr (getvar 'screensize)))

#### Grrr1337

• Bull Frog
• Posts: 453
##### Re: Constant screen point (translated from WCS)
« Reply #6 on: December 05, 2017, 08:05:28 pm »
Thanks for the info Lee, although I try to avoid if possible acet-*** functions, since Michael wrote that its like "building a castle on floating sand"

#### MP

• Seagull
• Posts: 17015
• brevity != aggression
##### Re: Constant screen point (translated from WCS)
« Reply #7 on: December 06, 2017, 12:13:12 am »
Close:

Quote from: MP
Analogous to building a house on quick sand.

My opinion hasn't changed.
\|// Set goal. Experiment tirelessly until
|oo| practice has become expertise.  Loop.

#### Grrr1337

• Bull Frog
• Posts: 453
##### Re: Constant screen point (translated from WCS)
« Reply #8 on: December 07, 2017, 07:25:52 pm »
Soo heres a sample for you guys, incase you still didn't got the idea for usage [requires (LM:GrText) defined]:

Code - Auto/Visual Lisp: [Select]
`; test for (WcsPt<->ScreenPt)(defun C:test ( / str col vec p s g e )   (and    (setq vec (LM:GrText str))    (setq p (getpoint "\nPick a point for text location: "))    (setq p (WcsPt<->ScreenPt p T)) ; convert to Screen Point    (princ "\nTrapped in (grread) loop - please scroll, pan and hover over some object.")     (progn      (redraw)      (while (not s)        (setq g (grread t))        (and (or (equal g '(2 13)) (= (car g) 25)) (setq s t)) ; enter/RMB to exit        (and (= (car g) 5) ; cursor          (or            (and               (setq e (car (nentselp (cadr g))))              (setq vec                 (LM:GrText                   (strcat                     "Object relies on layer: " (cdr (assoc 8 (entget e)))                    "\nObject's entity type: " (cdr (assoc 0 (entget e)))                    "\nNow I'll just put a bunch of rows..."                    "\n...................................."                    "\n...................................."                    "\n...................................."                    "\n...................................."                    "\n..................................:)"                  )                )              )              (setq col 2)            )            (and              (setq vec                 (LM:GrText                  (strcat                     "\nBTW you could use this technique"                    "\nas a modeless dialog substitute"                    "\nwithin a reactor."                    "\n\nThis is awesome!"                  )                )              )              (setq col 1)            )          )          (progn (redraw)            (if vec (LM:DisplayGrText (WcsPt<->ScreenPt p nil) vec col 15 -31))          )        ); and      ); while      s    ); progn    (princ "\nLoop complete.") (redraw)  ); and  (princ)); defun  ; Translation between WCS point and Pixel - vice versa; p - point [pixel or WCS]; b - boolean [T/nil] | T = WcsPt->ScreenPt, nil = ScreenPt->WcsPt(defun WcsPt<->ScreenPt ( p b / vsz scz vct pixelsz )  ; Vovka ; https://www.theswamp.org/index.php?topic=53702.0  (mapcar 'set '(vsz scz vct) (mapcar 'getvar '(viewsize screensize viewctr)))  (setq pixelsz (/ vsz (cadr scz)))  (if b     (mapcar '+ scz (mapcar '/ (mapcar '- p vct) (list pixelsz pixelsz))) ; vk_Point2Pixel    (mapcar '+ vct (mapcar '* (mapcar '- p scz) (list pixelsz pixelsz))) ; vk_Pixel2Point  ); if); defun  ;; Display GrText  -  Lee Mac;; pnt  -  cursor point in UCS;; vec  -  GrText vector list;; col  -  Text Colour (ACI Colour);; xof  -  x-offset from cursor in pixels;; yof  -  y-offset from cursor in pixels (defun LM:DisplayGrText ( pnt vec col xof yof / scl )  (setq scl (/ (getvar 'viewsize) (cadr (getvar 'screensize)))    pnt (trans pnt 1 2)  )  (grvecs (cons col vec)    (list      (list scl 0.0 0.0 (+ (car  pnt) (* xof scl)))      (list 0.0 scl 0.0 (+ (cadr pnt) (* yof scl)))      (list 0.0 0.0 scl 0.0)      '(0.0 0.0 0.0 1.0)    )  ))`

I've condensed Vovka's functions and left his nickname and link to the thread inside the subfunction (I hope he's ok with that).
I know I mentioned reactors (and it could be used the same way) although I'm uploading a demo with grread usage.
You can see I'm scrolling 'n' panning and the LM:Grtext stays in a constant position.

« Last Edit: December 07, 2017, 07:33:49 pm by Grrr1337 »