Page 1 of 1

Selection of nodes to fill field of tree

Posted: Tue Sep 13, 2022 10:56 am
by tiago_valente
I want to fill a field of data tree with the number of a point in the geometry. Is it possible to add an <edit_command> to call a function to select a point using the graphical interface?

Here is what I was trying to do, but was unable to find a tcl function to call a pick point selection:

<value n="point1" pn="N. point 1" help="Number of the point in the geometry to attribute the value 1 of the load" >
<edit_command n="select_points" pn="Select Points" proc="ProcSelectPoint"/>
</value>

<proc n='ProcSelectPoint' args='args'>
<![CDATA[
SpdAux::ProcSelectPoint $domNode $args
]]>
</proc>

proc SpdAux::ProcSelectPoint {domNode args} {

}

Best regards
Tiago Valente

Re: Selection of nodes to fill field of tree

Posted: Mon Sep 19, 2022 3:32 pm
by escolano
There is in <GiD>scripts/dev_kit.tcl a procedure to facilitate the selection of GiD entities.
proc GidUtils::PickEntities { type selectmode {message {}}}
(see the comment on this file to see its arguments)

e.g.
set id [GidUtils::PickEntities Points single [= "Pick a geometry point"]]
W "the point id is $id"

On the other hand, I think that is not a good idea to add to the customLib tree an item to be filled with the id of a point. The normal way to do it probably is to use a condition that is related to a group name, and add to this group the points you want.

In any case, if do you want to implement your approach, is possible to do something like this:
In the file <problemype>.spd

Code: Select all

<container n="Points_of_loads" pn="Points of loads">
    <value n="point1" pn="N. point 1" v="" string_is="integer_or_void" help="Number of the point in the geometry to attribute the value 1 of the load">
      <edit_command n="select_points" pn="Select Points" proc="MyProcSelectPoint %W" icon="point"/>
    </value>
</container>
and in the file <problemtype.tcl> define this procedure
(it is possible to embed the proc in the xml definition, and the the arguments are implicit, but is better to edit and debug to define the Tcl code in a Tcl file)

Code: Select all

proc MyProcSelectPoint { dom_node } {
    set my_dict ""
    set id [GidUtils::PickEntities Points single [= "Pick a geometry point"]]
    if { $id != "" } {
        set question [$dom_node @n] 
        #Note: in this case we knot that question is 'point1' but this show an use of the dom_node argument
        set my_dict [dict set my_dict point1 $id]
    }
    return [list $my_dict ""]
}
Note: the proc can return a list with a first item that is a dictionary with they - value to be changed in the entry (in this case the key is 'point1' and the value the entity id)

Re: Selection of nodes to fill field of tree

Posted: Mon Sep 19, 2022 5:25 pm
by escolano
I have found another way that was not documented (we will document it)
that do something similar, simply declaring the value of fieldtype='vector, dimensions='1', with attribute pick_point='1'

Code: Select all

<container n="some_points" pn="some points">
  <value n="some_point" pn="Some point" fieldtype="vector" dimensions="1" string_is="integer_or_void" pick_point="1" help="To enter a point"/>
</container>

Re: Selection of nodes to fill field of tree

Posted: Mon Sep 26, 2022 10:37 am
by tiago_valente
Thanks for your help.

I was able to implement the solution that you pointed out.

Best regards