From dialog to tree

Moderator: GiD Team

Post Reply
fabiopf
Posts: 9
Joined: Tue Jun 08, 2021 8:12 pm

From dialog to tree

Post by fabiopf »

Hi guys,

I need to implement a way to store load combinations in the data tree using the new problem type. Combination cases in our solver comprise basically load cases and load factors. The input file is something like this:

<COMBINATION_PARAMETERS>

COMBINATION_NUMBER = 3 ;

COMBINATION_TITLE = comb_3 ;

COMBINATION_GROUP = FEMIXDefaultGroup ;

PHASE_NUMBER = 1 ;

</COMBINATION_PARAMETERS>

<LOAD_CASE_FACTORS>

COUNT = 3 ;

1 1 1.00000000 ;

2 2 1.00000000 ;

3 3 1.00000000 ;

</LOAD_CASE_FACTORS>

In our classic problem type, we have a dialog (see figure 1) to collect this information in the preprocessing phase in GiD:
figure1.png
figure1.png (126.96 KiB) Viewed 2964 times
Note that using this dialog, the user can create a combination by defining a title, group name, load case, a load factor and clicking on “Add”. The user can also remove or edit a combination case.

In our new problem type, we have a node in the data tree called “Load Cases“ (see figure 2), where the user defines a new load case and a node called “Combinations“ (to store the combinations created by the user). My idea is to create a similar window (as the one implemented in the classic problem type) to create combination cases. Thus, once the user closes the dialog, the combinations created in this dialog are stored in the tree as children of the combinations node, figure 2.
figure2.png
figure2.png (47.32 KiB) Viewed 2964 times
Could you please guide me on this task? I do not know how to create this dialog and send the information to the data tree. Could you provide me with an example showing how to do this? Is this the best approach to implement this feature using the new problem type, or do you have another suggestion?
fabiopf
Posts: 9
Joined: Tue Jun 08, 2021 8:12 pm

Re: From dialog to tree

Post by fabiopf »

HI guys,

I think I have a solution for this problem. I will use this dialogue to collect the user information and I will save the data to a file in the project folder. Then, I can merge this file with the one created using the data from the tree for calculation. I do not know if this is the best solution, but I am pretty sure it will work. Please let me know if you have a better idea. Thanks!

Best,
Fabio
User avatar
mrpeyrau
Posts: 4
Joined: Fri Oct 23, 2020 5:22 pm

Re: From dialog to tree

Post by mrpeyrau »

Dear Fabio,

I have prepared a custom example, that should be helpful to you. It is based on 'cmas2d_customlib.gid' problem type installed in 'GiDxxx/problemtypes/Examples' folder.

A new 'container' node, called loadcases, has been added in the cmas2d_customlib.spd file (see loadcases.png image), as follows:

<container n="loadcases" pn="Loadcases">
<container n="combinations" pn="Combinations" state="normal">
<edit_command n="combined_loadcases_win" proc="combinations_win" edit_type="exclusive"/>
</container>
<blockdata n="loadcase" pn="Loadcase" name="Loadcase 1" sequence="1" sequence_type="non_void_deactivated" active="0" editable_name="unique" help="Create a new loadcase for the loads">
<value n="lc_val" pn="Value loadCase" v="1" values="0,1" state="normal"/>
</blockdata>
</container>


The procedure 'combinations_win' has also been added in the .spd file (<procs/> node). This procedure allows to open the Combinations window:

<proc n="combinations_win">
Cmas2d::create_window -widgetp $boundary_conds $domNode
</proc>


Double clicking on the item called 'combinations' opens the Combinations window (see combinations_window.png image). This window allows to define combined loadcases in the data treee. Moreover, double clicking on each new combined loadcase previously created, it is possible to edit and modify its properties.

The following procedures has been added in the cmas2d_customlib.tcl file, for creating the Combinations window and defining the new combinations (<blockdata/> nodes), in the data tree:

proc Cmas2d::create_window { args } {
set doc $gid_groups_conds::doc
set root [$doc documentElement]

set optional {
{ -widgetp widgetp .gid }
}
set compulsory "domNode"
parse_args $optional $compulsory $args

set lcList ""
set xp {/*/container[@n="loadcases"]/container[@n="combinations"]/}
append xp {blockdata[@n="comb"]}
foreach gNode [$root selectNodes $xp] {
lappend lcList [$gNode @name]
}
if {$lcList == ""} {
set clname [= "Combined loadcase 1"]
set n_loadcases 1
} else {
if {[$domNode @name ""] != ""} {
set clname [$domNode @name]
set n_loadcases [$domNode selectNodes {string(value[@n="numloadcases"]/@v)}]
} else {
set numlc [llength $lcList]
set clname [= "Combined loadcase %s" [expr {$numlc+1}]]
while {$clname in $lcList} {
incr numlc
set clname [= "Combined loadcase %s" [expr {$numlc+1}]]
}
set n_loadcases 1
}
}

package require dialogwin

set wp $widgetp
destroy $wp.combined_loadcases
set w [dialogwin_snit $wp.combined_loadcases -title [= "Combinations"] \
-okname [_ "Ok"] -cancelname [_ Cancel] -style ridgeframe \
-grab 0 -callback Cmas2d::create_window_do]
set f [$w giveframe]

set f1 [ttk::labelframe $f.data -relief groove -borderwidth 1 \
-text [= "Combination definition"]]

set cname [ttk::label $f1.cname -text [= "Combination name"]]
set ecname [ttk::entry $f1.ecname -textvariable [$w give_uservar clname]]

$w set_uservar_value clname $clname
$w set_uservar_value numloadcases $n_loadcases

set lnumloadcases [ttk::label $f1.lnumloadcases -text [= "Number of load cases"]]

set spin [spinbox $f1.splay -textvariable [$w give_uservar numloadcases] \
-from 1.000 -to 100000 -increment 1]

grid $f1 -sticky news -ipadx 2 -ipady 2 -padx 2 -pady 2
grid columnconf $f1 1 -weight 1

grid $cname $f1.ecname -sticky nsew -ipadx 2 -ipady 2 -padx 2 -pady 2
grid configure $f1.ecname -columnspan 4

grid $lnumloadcases $spin -sticky nsew -ipadx 2 -ipady 2 -padx 2 -pady 2

grid columnconfigure $f 0 -weight 1
grid rowconfigure $f 0 -weight 1

bind $w <Return> +[list $w invokeok]

set action [$w createwindow]

focus $w
grab $w
}

proc Cmas2d::create_window_do { w } {
if { ![winfo exists $w] } { return }

set action [$w giveaction]
switch -- $action {
1 {
Cmas2d::savedata $w
catch { destroy $w }
}
default {
catch { destroy $w }
}
}
}

proc Cmas2d::savedata { w } {

set doc $gid_groups_conds::doc

foreach node
  • {
    dom createNodeCmd element $node
    }

    set xp {/*/container[@n="loadcases"]/container[@n="combinations"]}
    set domNode [$doc selectNodes $xp]

    set clname [$w give_uservar_value clname]
    set numloadcases [$w give_uservar_value numloadcases]

    set iNode [$domNode selectNodes [format_xpath {//blockdata[@name=%s]} $clname]]

    set exist 0
    if { $iNode != "" } {
    set ret [snit_messageBox -type okcancel -default ok \
    -message [= "Are you sure to modify the '%s' properties?" $clname] -parent $w]
    if { $ret == "cancel" } { return }
    set exist 1
    }

    if { !$exist } {
    $domNode appendFromScript {
    blockdata n comb name [= "%s" $clname] \
    icon weight-18 sequence 1 sequence_type "non_void_deactivated" active 0 \
    editable_name unique state normal \
    tree_state "active,selected,close"
    foreach valueNode [$domNode selectNodes \
    [format_xpath {//blockdata[@name=%s]} $clname]] {
    $valueNode appendFromScript {
    value n numloadcases pn "Number of loads" v $numloadcases state disabled
    }
    $valueNode appendFromScript {
    edit_command n combined_loadcases_win proc combinations_win \
    edit_type exclusive_blockdata
    }
    }
    }
    } else {
    gid_groups_conds::setAttributes [gid_groups_conds::nice_xpath $iNode] \
    [list name [= "%s" $clname]]
    set numloadsNode [$iNode selectNodes {value[@n="numloadcases"]}]
    gid_groups_conds::setAttributes [gid_groups_conds::nice_xpath $numloadsNode] \
    [list v $numloadcases]
    }
    gid_groups_conds::actualize_conditions_window
    }


    I hope this custom example is useful, and please don't hesitate to ask me if you have any doubt regarding it.

    Kind regards,

    Maria Rosa Peyrau Rubio
    Pre and Post-processing Department
    http://www.cimne.com

    Images:
Attachments
new_combined_loadcases.PNG
new_combined_loadcases.PNG (9.44 KiB) Viewed 2774 times
loadcases.PNG
loadcases.PNG (7.08 KiB) Viewed 2774 times
combinations_window.PNG
combinations_window.PNG (5.15 KiB) Viewed 2774 times
Maria Rosa Peyrau Rubio
Dept. Pre and Postprocessing CIMNE
Post Reply