Highlighting entities in GiD

Moderator: GiD Team

mlucio
Posts: 3
Joined: Mon Jun 15, 2020 9:29 am

Highlighting entities in GiD

Postby mlucio » Fri Aug 14, 2020 12:27 pm

Hi,

I have a double question concerning GiD pre-pro.

1.

Let's say I have a surface which is "linked" (i.e. is somehow related) to some lines not necessarily belonging to the surface. I would like to develop a tool that allows to highlight the lines linked to the surface when clicking on the surface itself.
As a nice-to-have, I would also like to have the selected surface being highlighted, in a different way (for instance by being "filled" with some color different from the one used to highlight lines).

For the moment, I can select the surface by clicking on it and retrieve all the information I need. In particular, I end up with the identifing numbers of the lines which are linked to the surface. To do that, I developed a specific tool accessed via a customized menu.
That was the easy part. Now, I would like to highlight the lines corresponding to these numbers.

Of course, I would also need the lines (and the surface) to be un-highlighted when escaping the selection tool (typically, by pressing the 'esc' key).

Do you have any idea/suggestion on the way I could accomplish that?


2.

As a first try, I simply tried to redraw those lines by using "GiD_openGL" commands but nothing is drawn. I post my code hereafter. Could you tell me what is wrong with it?


Thank you very much in advance.

ML

-----
CODE:
-----

foreach ln $lignes_char {
# --- Retrieving the coordinates of the points defining line 'ln' ---
set infoLine [GiD_Info list_entities lines $ln]
set indexPts [lsearch $infoLine "Points:"]

set pt1 [lindex $infoLine [expr $indexPts+1]]
set pt2 [lindex $infoLine [expr $indexPts+2]]

set infoPt1 [GiD_Info list_entities points $pt1]
set infoPt2 [GiD_Info list_entities points $pt2]

set indexCoord1 [lsearch $infoPt1 "Coord:"]
set xr1 [lindex $infoPt1 [expr $indexCoord1+1]]
set yr1 [lindex $infoPt1 [expr $indexCoord1+2]]
set zr1 [lindex $infoPt1 [expr $indexCoord1+3]]

set indexCoord2 [lsearch $infoPt2 "Coord:"]
set xr2 [lindex $infoPt2 [expr $indexCoord1+1]]
set yr2 [lindex $infoPt2 [expr $indexCoord1+2]]
set zr2 [lindex $infoPt2 [expr $indexCoord1+3]]
# ---

# --- Retrieving screen coordinates from 'world' coordinates ---
set vec1 [GiD_OpenGL project "$xr1 $xr2 $xr3"]
set vec2 [GiD_OpenGL project "$xr2 $yr2 $zr2"]

set x1 [lindex $vec1 0]
set y1 [lindex $vec1 1]
set z1 [lindex $vec1 2]

set x2 [lindex $vec2 0]
set y2 [lindex $vec2 1]
set z2 [lindex $vec2 2]
# ---

# --- Draw a red line connecting the two points (does not work) ---
GiD_OpenGL draw -begin lines
GiD_OpenGL draw -vertex [list $x1 $y1 $z1]
GiD_OpenGL draw -vertex [list $x2 $y2 $z2]
GiD_OpenGL draw -color [list 1.000 0.000 0.000]
GiD_OpenGL draw -linewidth 1.0
GiD_OpenGL draw -end
# ---
}
User avatar
escolano
Posts: 1699
Joined: Thu Sep 18, 2014 3:31 pm

Re: Highlighting entities in GiD

Postby escolano » Mon Aug 17, 2020 12:05 pm

A simple way could be
set line_ids {1 5}
GiD_Process 'View SelectEntities Lines {*]$line_ids

then the line 1 and 5 will be selected and highlight in red until a 'Escape' word is processed

It is also possible to do the approach 2, and draw with a procedure that use GiD_OpenGL commands
but you must register the procedure that do this draw to be called each redraw
Note: "GiD_OpenGL drawentity" facilitate draw an existing GiD entity

proc YourDrawProcedure { } {
#... your drawn code...
drawopengl draw -color {0.0 1.0 0.0} ;#green
GiD_OpenGL drawentity line {1 5}
}

set register_id [GiD_OpenGL register YourDrawProcedure]

(and after unregister $register_id to finish this draw)
mlucio
Posts: 3
Joined: Mon Jun 15, 2020 9:29 am

Re: Highlighting entities in GiD

Postby mlucio » Mon Aug 17, 2020 4:36 pm

Dear Escolano,

thank you very much for your answer! :)

What you suggested for approach "1" worked! However, I may have oversimplified my question a little bit. Actually, there are also points and surfaces which can be linked to the selected surface. When doing what you suggest I have the impression that only the entities concerned by the first "View" call are highlighted. Is it possible to make multiple "View" calls (and without un-highlighting 'previous' entities)? For instance, something like:

GiD_Process View SelectEntities Points {*}$pts
GiD_Process View SelectEntities Lines {*}$lns
GiD_Process View SelectEntities Surfaces {*}$surfs

Tnx!

ML
User avatar
escolano
Posts: 1699
Joined: Thu Sep 18, 2014 3:31 pm

Re: Highlighting entities in GiD

Postby escolano » Tue Sep 01, 2020 2:19 pm

To select multiple entity types must use the keyword AllTypes

Code: Select all

GiD_Process 'View SelectEntities AllTypes Points {*}$pts Lines {*}$lns Surfaces {*}$surfs
mlucio
Posts: 3
Joined: Mon Jun 15, 2020 9:29 am

Re: Highlighting entities in GiD

Postby mlucio » Thu Sep 24, 2020 10:06 am

Thank you very much! :)

Just a last question (maybe)...

Here is the code I wrote:

GiD_Process MEscape SelectEntities justone Surfaces
vwait ::GidPriv(selection)
set selection [eval lrange $::GidPriv(selection) 1 end]

set info [GiD_Info list_entities surfaces $selection]

set indexNumEntity [lsearch $info "Num:"]
set numEntity [lindex $info [expr $indexNumEntity+1]]

set indexGeo [lsearch $info "material:"]
set geo [lindex $info [expr $indexGeo+1]]

set geoName [lindex [.central.s info materials] [expr $geo-1]]
set infoGeo [GiD_Info materials $geoName]

set indexTypGeo [lsearch $infoGeo "type_de_section"]
set typGeo [lindex $infoGeo [expr $indexTypGeo+1]]

set index_points_c [lsearch $infoGeo "points_c"]
set index_lignes_c [lsearch $infoGeo "lignes_c"]
set index_surfaces_c [lsearch $infoGeo "surfaces_c"]

set points_c [lindex $infoGeo [expr $index_points_c+1]]
set lignes_c [lindex $infoGeo [expr $index_lignes_c+1]]
set surf_c [lindex $infoGeo [expr $index_surfaces_c+1]]

GiD_Process View SelectEntities AllTypes Points {*}$points_c Lines {*}$lignes_c Surfaces {*}$surf_c

This works as expected, i.e. I select a surface --> I get the related entities highlighted --> I press esc --> I escape the selection tool. It would be interesting, however, that I could continue selecting entities (and seing related entities, of course) before I decide to "fully" escape. Otherwise, I have to re-enter the selection tool everytime I want information on a new entity. In meta-programming, what I'm looking for is something like:

while (not user escape)

GiD_Process MEscape SelectEntities justone Surfaces
vwait ::GidPriv(selection)
set selection [eval lrange $::GidPriv(selection) 1 end]

set info [GiD_Info list_entities surfaces $selection]

set indexNumEntity [lsearch $info "Num:"]
set numEntity [lindex $info [expr $indexNumEntity+1]]

set indexGeo [lsearch $info "material:"]
set geo [lindex $info [expr $indexGeo+1]]

set geoName [lindex [.central.s info materials] [expr $geo-1]]
set infoGeo [GiD_Info materials $geoName]

set indexTypGeo [lsearch $infoGeo "type_de_section"]
set typGeo [lindex $infoGeo [expr $indexTypGeo+1]]

set index_points_c [lsearch $infoGeo "points_c"]
set index_lignes_c [lsearch $infoGeo "lignes_c"]
set index_surfaces_c [lsearch $infoGeo "surfaces_c"]

set points_c [lindex $infoGeo [expr $index_points_c+1]]
set lignes_c [lindex $infoGeo [expr $index_lignes_c+1]]
set surf_c [lindex $infoGeo [expr $index_surfaces_c+1]]

GiD_Process View SelectEntities AllTypes Points {*}$points_c Lines {*}$lignes_c Surfaces {*}$surf_c

end while

Is it possible to achieve something like this, or similar? Thank you in advance for your precious help!

ML

Return to “Customization”

Who is online

Users browsing this forum: No registered users and 2 guests