Skip to content

Commit 499c4e6

Browse files
Create a controller for the files handler package
1 parent 355134e commit 499c4e6

4 files changed

Lines changed: 69 additions & 37 deletions

File tree

kratos.gid/kratos.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ proc Kratos::LoadCommonScripts { } {
196196
uplevel #0 [list source [file join $kratos_private(Path) scripts $filename]]
197197
}
198198
# Common controllers
199-
foreach filename {ApplicationMarketWindow.tcl ExamplesWindow.tcl CommonProcs.tcl PreferencesWindow.tcl TreeInjections.tcl MdpaImportMesh.tcl Drawer.tcl} {
199+
foreach filename {ApplicationMarketWindow.tcl ExamplesWindow.tcl CommonProcs.tcl PreferencesWindow.tcl TreeInjections.tcl MdpaImportMesh.tcl Drawer.tcl ImportFiles.tcl} {
200200
uplevel #0 [list source [file join $kratos_private(Path) scripts Controllers $filename]]
201201
}
202202
# Model class

kratos.gid/scripts/Controllers/CommonProcs.tcl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -555,13 +555,6 @@ proc spdAux::ProcShowInMode { domNode args } {
555555
}
556556
}
557557

558-
proc spdAux::ProcGetFilesValues { } {
559-
lappend listilla "- No file"
560-
lappend listilla {*}[FileSelector::GetAllFiles]
561-
lappend listilla "- Add new file"
562-
return [join $listilla ","]
563-
}
564-
565558
proc spdAux::ProcGetIntervals {domNode args} {
566559
set lista [::spdAux::getIntervals]
567560
if {$lista eq ""} {$domNode setAttribute state "hidden"; spdAux::RequestRefresh}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
# Handle file input
3+
proc ::spdAux::LaunchFileWindow { } {
4+
if {[GiD_Info Project Modelname] eq "UNNAMED"} {
5+
MessageBoxOk [_ "Model error"] [_ "Save your model first"] error
6+
return
7+
}
8+
set FileSelector::callback_after_new_file "::spdAux::SaveModelFile"
9+
set FileSelector::callback_view_file "::spdAux::ViewFile"
10+
set FileSelector::callback_delete_file "::spdAux::DeleteFile"
11+
FileSelector::InitFileHandler
12+
}
13+
14+
proc ::spdAux::ViewFile {file_id} {
15+
exec {*}[auto_execok start] "" [file join [file nativename [GiD_Info Project ModelName].gid] $file_id]
16+
}
17+
18+
proc ::spdAux::LoadModelFiles { {root "" }} {
19+
if {$root eq ""} {
20+
set root [customlib::GetBaseRoot]
21+
customlib::UpdateDocument
22+
}
23+
set files [$root getElementsByTagName "file"]
24+
if {[llength $files] > 0} {
25+
Kratos::LoadImportFiles
26+
foreach elem $files {
27+
FileSelector::AddFile [$elem @n]
28+
}
29+
}
30+
}
31+
32+
proc ::spdAux::SaveModelFile { fileid } {
33+
customlib::UpdateDocument
34+
FileSelector::AddFile $fileid
35+
gid_groups_conds::addF {container[@n='files']} file [list n ${fileid}]
36+
customlib::UpdateDocument
37+
FileSelector::CopyFilesIntoModel [file nativename [GiD_Info Project ModelName] ].gid
38+
}
39+
40+
proc ::spdAux::ProcGetFilesValues { domNode } {
41+
customlib::UpdateDocument
42+
spdAux::LoadModelFiles
43+
lappend listilla "- No file - (add files using File handler toolbar)"
44+
lappend listilla {*}[FileSelector::GetAllFiles]
45+
if {[get_domnode_attribute $domNode v] ni $listilla} {$domNode setAttribute v [lindex $listilla 0]}
46+
return [join $listilla ","]
47+
}
48+
49+
proc ::spdAux::DeleteFile { fileid } {
50+
customlib::UpdateDocument
51+
52+
set used_nodes [[customlib::GetBaseRoot] selectNodes "//value\[@type = 'file' and @v = '$fileid'\]"]
53+
foreach used_node $used_nodes {
54+
W "Warning: Deleted file $fileid was used in [[$used_node parent] @pn] > [$used_node @pn]"
55+
}
56+
57+
set file_node [[customlib::GetBaseRoot] selectNodes "//file\[@n = '$fileid'\]"]
58+
if {$file_node ne ""} {$file_node delete}
59+
RequestRefresh
60+
}
61+
62+
proc spdAux::UpdateFileField { fileid domNode} {
63+
if {$fileid ne ""} {
64+
$domNode setAttribute v $fileid
65+
spdAux::SaveModelFile $fileid
66+
RequestRefresh
67+
}
68+
}

kratos.gid/scripts/spdAuxiliar.tcl

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -436,35 +436,6 @@ proc spdAux::GetAppliedGroups { {root ""} } {
436436
}
437437
return [lsort -unique $group_list]
438438
}
439-
440-
proc spdAux::LoadModelFiles { {root "" }} {
441-
if {$root eq ""} {
442-
set root [customlib::GetBaseRoot]
443-
customlib::UpdateDocument
444-
}
445-
foreach elem [$root getElementsByTagName "file"] {
446-
FileSelector::AddFile [$elem @n]
447-
}
448-
}
449-
450-
proc spdAux::SaveModelFile { fileid } {
451-
customlib::UpdateDocument
452-
FileSelector::AddFile $fileid
453-
gid_groups_conds::addF {container[@n='files']} file [list n ${fileid}]
454-
}
455-
456-
proc spdAux::AddFile { domNode } {
457-
FileSelector::InitWindow "spdAux::UpdateFileField" $domNode
458-
}
459-
460-
proc spdAux::UpdateFileField { fileid domNode} {
461-
if {$fileid ne ""} {
462-
$domNode setAttribute v $fileid
463-
spdAux::SaveModelFile $fileid
464-
RequestRefresh
465-
}
466-
}
467-
468439
proc spdAux::RegisterWindow {window_name} {
469440
variable list_of_windows
470441
lappend list_of_windows $window_name

0 commit comments

Comments
 (0)