1+
2+ proc ::GeoMechanics::PhreaticButton { } {
3+ variable curr_stage
4+ variable state_phreatic_line
5+
6+ # Get the current active stage
7+ set stages [::GeoMechanics::xml::GetStages]
8+ set stage [lindex $stages $curr_stage ]
9+
10+ # If the state is none, the user clicked because he wants to create a phreatic line
11+ if {$state_phreatic_line eq " none" } {
12+
13+ # Get the current stage phreatic points
14+ set current_phreatic_points [::GeoMechanics::xml::GetPhreaticPoints $stage ]
15+ # If there are no phreatic points, create a new line
16+ if {[llength $current_phreatic_points ] eq 0} {
17+ set state_phreatic_line creating
18+ ::GeoMechanics::CreatePhreaticLine $stage
19+ } else {
20+ # If there are phreatic points, display it somehow
21+ ::GeoMechanics::DisplayPhreaticLine
22+ }
23+ } elseif {$state_phreatic_line in [list " creating" " displaying" ]} {
24+ ::GeoMechanics::EndCreatePhreaticLine
25+ }
26+ }
27+
28+ proc ::GeoMechanics::DeletePhreaticButton { } {
29+ variable curr_stage
30+
31+ # Get the current active stage
32+ set stages [::GeoMechanics::xml::GetStages]
33+ set stage [lindex $stages $curr_stage ]
34+
35+ ::GeoMechanics::xml::DeletePhreaticPoints $stage
36+ ::GeoMechanics::EndCreatePhreaticLine
37+ }
38+
39+ proc ::GeoMechanics::CreatePhreaticLine {stage} {
40+ variable state_phreatic_line
41+ variable creating_phreatic_previous_layer
42+ set creating_phreatic_previous_layer [GiD_Layers get to_use]
43+ set stage_name [$stage @name]
44+ if {[GiD_Layers exists PhreaticLine_$stage_name ]} {
45+ GiD_Layers delete PhreaticLine_$stage_name
46+ }
47+ GiD_Layers create PhreaticLine_$stage_name
48+ GiD_Layers edit to_use PhreaticLine_$stage_name
49+ GiD_RegisterEvent GiD_Event_AfterCreateLine ::GeoMechanics::AfterCreatePhreaticLine PROBLEMTYPE Kratos
50+ GiD_Process MEscape Mescape Geometry Create Line
51+ }
52+
53+ proc ::GeoMechanics::AfterCreatePhreaticLine { line } {
54+ variable curr_stage
55+ variable state_phreatic_line
56+ if {$state_phreatic_line eq " creating" } {
57+
58+ # Get the current active stage
59+ set stages [::GeoMechanics::xml::GetStages]
60+ set stage [lindex $stages $curr_stage ]
61+
62+ # Get line points
63+ lassign [GiD_Geometry get line $line ] a b p1 p2
64+ # Get point coordinates
65+ lassign [GiD_Geometry get point $p1 ] a x1 y1 z1
66+ lassign [GiD_Geometry get point $p2 ] a x2 y2 z2
67+ # Add coordinates to xml
68+ if {[llength [::GeoMechanics::xml::GetPhreaticPoints $stage ]] == 0} {
69+ ::GeoMechanics::xml::AddPhreaticPoint $stage $x1 $y1 $z1
70+ }
71+ ::GeoMechanics::xml::AddPhreaticPoint $stage $x2 $y2 $z2
72+ } else {
73+
74+ }
75+
76+ # TODO: at this moment we only allow 2 points, in the future, will see
77+ set num [llength [::GeoMechanics::xml::GetPhreaticPoints $stage ]]
78+ if {$num >= 2} {
79+ ::GeoMechanics::EndCreatePhreaticLine
80+ ::GeoMechanics::DisplayPhreaticLine
81+ }
82+ }
83+ proc ::GeoMechanics::EndCreatePhreaticLine { } {
84+ variable state_phreatic_line
85+ set state_phreatic_line none
86+
87+ # Delete the phreatic line
88+ ::GeoMechanics::DeleteVisiblePhreaticLine
89+
90+ # Delete the lines from the variable list
91+ variable creating_phreatic_previous_layer
92+ GiD_Layers edit to_use $creating_phreatic_previous_layer
93+ catch {GiD_UnRegisterEvent GiD_Event_AfterCreateLine ::GeoMechanics::AfterCreatePhreaticLine PROBLEMTYPE Kratos}
94+ spdAux::RequestRefresh
95+ }
96+
97+ proc ::GeoMechanics::DeleteVisiblePhreaticLine { } {
98+ variable curr_stage
99+
100+ # Get the current active stage
101+ set stages [::GeoMechanics::xml::GetStages]
102+ set stage [lindex $stages $curr_stage ]
103+
104+ set stage_name [$stage @name]
105+ # Delete the lines from the variable list
106+ if {[GiD_Layers exists PhreaticLine_$stage_name ]} {GiD_Layers delete PhreaticLine_$stage_name }
107+ GiD_Process MEscape 'Redraw escape
108+ }
109+
110+ proc ::GeoMechanics::DisplayPhreaticLine {} {
111+ variable state_phreatic_line
112+ set state_phreatic_line displaying
113+
114+ # Get the current active stage
115+ variable curr_stage
116+ set stages [::GeoMechanics::xml::GetStages]
117+ set stage [lindex $stages $curr_stage ]
118+
119+ set stage_name [$stage @name]
120+ set layer_name PhreaticLine_$stage_name
121+ if {[GiD_Layers exists $layer_name ]} {
122+ GiD_Layers delete $layer_name
123+ }
124+ GiD_Layers create $layer_name
125+ # GiD_Layers edit to_use $layer_name
126+ set current_phreatic_points [::GeoMechanics::xml::GetPhreaticPoints $stage ]
127+ set point_list [list ]
128+ foreach point $current_phreatic_points {
129+ lassign $point x y
130+ lappend point_list [GiD_Geometry -v2 create point append $layer_name $x $y 0.0]
131+ }
132+ # set coordinates ""
133+ set ini [lindex $point_list 0]
134+ foreach end [lrange $point_list 1 end] {
135+ GiD_Geometry -v2 create line append stline $layer_name $ini $end
136+ set ini $end
137+ }
138+ GiD_Process MEscape 'Redraw escape
139+ }
0 commit comments