📄 object.class
字号:
local offset = $T_is_style
if "`all'`classmv'" !="" {
._post_changes classmv `offset' `reset'
local offset = `offset' + 0`.classmv.arrnels'
}
if "`all'`instancemv'"!="" {
._post_changes instancemv `offset' `reset'
local offset = `offset' + 0`.instancemv.arrnels'
}
if "`all'`dynamicmv'" !="" {
._post_changes dynamicmv `offset' `reset'
}
end
program define _set_changed
global T_changed 0
global T_changed_p1 0
forvalues j = 1/$T_numctrls {
if `"${T_v`j'}"' != `"${T_hv`j'}"' {
global T_changed 1
if `j' > 1 {
global T_changed_p1 1
continue, break
}
}
}
class exit = $T_changed
end
/* Style DBs have a pick list at the top that allows the style being edited
on the DB to be changed. Handle any such change here.
Also declares styles in the scheme if an edit has occured and there are
any named styles that own the object in the DB.
*/
program define _post_style
if "`reset'" != "" {
local h "h" /* resetting original val */
}
if `"${T_v1}"' != `"${T_hv1}"' {
.setstyle, style(${T_`h'v1})
_gm_log $T_Name.setstyle, style(${T_`h'v1})
}
end
program define _post_changes
args array offset reset
if "`reset'" != "" { /* resetting original val */
local h "h"
}
if "`.`array'.isa'" != "array" {
exit
}
/* set up for logging */
local 0 , `array'
syntax [, CLASSMV DYNAMICMV INSTANCEMV * ]
if "`classmv'`dynamicmv'`instancemv'" == "" {
local name $T_SubNm
local Xname $T_Name
}
else {
local name $T_SubNm.`array'
local Xname $T_Name.`array'
}
local log $T_TopNm.__LOG
forvalues i = 1/`.`array'.arrnels' {
local j = `i' + 0`offset'
if `"${T_v`j'}"' == `"${T_hv`j'}"' {
continue /* Continue */
}
capture _cls nameoflocal `array'[`i']
local attrib `r(name)'
if "`attrib'" == "" { /* for arrays */
local attrib `array'[`i']
}
local 0 , `.`attrib'.isa'
syntax [ , STRING DOUBLE CLASS * ]
if "`string'`double'`class'" == "" {
continue /* Continue */
}
/* try ._set_name */
capture ._set_`attrib' ${T_`h'v`j'}
if ! _rc {
_gm_log $T_Name._set_`attrib' ${T_`h'v`j'}
continue /* Continue */
}
if "`.`attrib'.isa'" == "string" {
.`attrib' = `"${T_`h'v`j'}"'
_gm_log $T_Name.`attrib' = `"${T_`h'v`j'}"'
continue /* Continue */
}
if "`.`attrib'.isa'" == "double" {
capture confirm number ${T_`h'v`j'}
if _rc {
continue /* warn ? */
}
.`attrib' = ${T_`h'v`j'}
_gm_log $T_Name.`attrib' = ${T_`h'v`j'}
continue /* Continue */
}
if "`.`attrib'.isa'" == "class" {
if `.`attrib'.isofclass code' {
/* should work, but compound quotes fail
here
local res `.`attrib'.codeof `"${T_v`j'}"''
*/
local res `.`attrib'.codeof "${T_`h'v`j'}"'
if "`res'" != "" {
.`attrib'.current = `res'
_gm_log $T_Name.`attrib'.current = `res'
}
continue /* Continue */
}
if `.`attrib'.isofclass style' & ///
0`.`attrib'.hasstyles' {
.`attrib'.setstyle, style(${T_`h'v`j'})
_gm_log $T_Name.`attrib'.setstyle, style(${T_`h'v`j'})
}
}
}
end
program define _array_db
gettoken array 0 : 0 , parse(" ,")
syntax [, Name(string) * ]
global T_Name `name' /* just easier */
local tnels 0`.`array'.arrnels'
if `tnels' > 400 {
di as error "style has too many attributes for a dialog box"
exit 198
}
global T_percol = 1 + int( (`tnels'-1) / /*
*/ (1 + int((`tnels'-1) / `.dbstyle.ctrls_per_col')) )
/* place controls for array obs */
local ymax 0
._place_controls_from x y ymax : `array' `.dbstyle.xspace' 0 0
global T_numctrls `.`array'.arrnels'
._place_ok_cancel ymax : `.dbstyle.xspace' `ymax'
local ysz = `ymax' + `.dbstyle.ysize' + 2 * `.dbstyle.yspace' + 8
local xsz = `x' + `.dbstyle.ctrlsize' + `.dbstyle.txtsize' + /*
*/ `.dbstyle.xgap' + `.dbstyle.xspace'
/* put up the dialog box */
capture window dialog "array: `name'" . . `xsz' `ysz'
local rc = _rc /* leave if cancelled */
if `rc' == 3098 {
._style_cleanup
exit
}
if `._set_changed' {
local hold_name $T_Name
global T_Name `._holdername nogscope'
_post_changes `array' /* post changes */
global T_Name hold_name
}
if "$T_drawobj" != "" & $T_changed { /* redraw if changed */
.${T_drawobj}.drawgraph
global T_changed 0
}
/* run a sub-view dialog box if
* requested */
local xpnd = `rc'-3000
if `xpnd' >= 1 & `xpnd' <= `.`array'.arrnels' {
._run_view "`array'[`xpnd']" , `options' name(`name'[`xpnd'])
_array_db `array' , name(`name') /* rerun db */
}
end
program define _run_view
gettoken attrib 0 : 0 , parse(" ,")
syntax [, * ]
._style_cleanup /* cleanup current db */
if "`.`attrib'.isa'" == "array" {
._array_db `attrib', `options' /* run array db */
}
else {
local hold_scheme `c(curscm)'
if "`.`attrib'._scheme.isa'" != "" {
set curscm `.`attrib'._scheme.objkey'
}
.`attrib'.dialog_box, `options' /* run class db */
set curscm `hold_scheme'
}
end
program define _db_apply
/* post changes and possibly
* redraw */
global T_changed 0
._post_all, $T_opts
if "$T_drawobj" != "" & $T_changed {
local holdscm `c(curscm)'
.${T_drawobj}.drawgraph
set curscm `holdscm'
global T_changed 0
}
end
program define _copy_style_db
local y `.dbstyle.yspace'
local x0 `.dbstyle.xspace'
local ysize `.dbstyle.ysize'
local ctrlsz `.dbstyle.ctrlsize'
global T_text1 "Copy of style `.stylename'"
window control static T_text1 `x0' `y' /*
*/ `=`ctrlsz'+`.dbstyle.txtsize'' `ysize' left
local y = `y' + `ysize' + `.dbstyle.yspace'
global T_newname
window control edit `x0' `y' `ctrlsz' `ysize' T_newname
global T_text2 "new name (optional)"
window control static T_text2 `=`x0'+`.dbstyle.xgap'+`ctrlsz'' /*
*/ `y' `=`.dbstyle.txtsize'+`.dbstyle.xspace'' `ysize'
/* OK, Cancel buttons */
._place_ok_cancel y : `x0' `y'
local ysz = `y' + `ysize' + 2 * `.dbstyle.yspace' + 8
local xsz = `x' + `ctrlsz' + `.dbstyle.txtsize' + /*
*/ `.dbstyle.xgap' + 3*`.dbstyle.xspace'
capture noisily window dialog "Make copy of style" . . `xsz' `ysz'
local rc = _rc
if `rc' != 3098 { /* OK, not cancelled */
._process_copy
}
capture mac drop T_newname
capture mac drop T_text1
capture mac drop T_text2
end
program define _process_copy
local named_somewhere 0`._any_named_styles `._holdername''
if `named_somewhere' & "$T_newname" == "" {
di as error "must name styles that are contained in other" /*
*/ " named styles"
exit /* EXIT */
}
if "$T_newname" == "" & ! 0`.namedstyle' {
exit /* already an unnamed style */
}
if `named_somewhere' | "$T_newname" != "" {
global T_log2scm 1
capture _gm_log $T_Name.remake_as_copy $T_newname
local rc = _rc
capture mac drop T_log2scm
if `rc' {
exit `rc'
}
if ! `named_somewhere' {
_gm_log $T_Name.setstyle, style($T_newname)
}
}
else {
_gm_log $T_Name.remake_as_copy $T_newname
}
.remake_as_copy $T_newname
end
program define _topname
gettoken token 0 : 0 , parse(" .")
while "`token'" != "" {
if "`token'" == "Global" {
local prefix Global.
}
else if "`token'" == "Local" {
local prefix Local.
}
else if "`token'" != "." {
local topname `prefix'`token'
class exit `"`topname'"' // Done
}
gettoken token 0 : 0 , parse(" .")
}
end
program define _restname
local skiplist . Global Local
local rest $T_Name
local ct 0
gettoken token rest : rest , parse(" .")
while "`token'" != "" & `ct' < 2 {
if ! `:list posof "`token'" in skiplist' {
local ++ct
}
if `ct' < 2 {
gettoken token rest : rest , parse(" .")
}
}
if `ct' == 2 {
class exit `".`token'`rest'"'
}
end
program define _holdername
local rest $T_Name
if "`0'" != "nogscope" {
local holder Global
}
gettoken tok rest : rest , parse(" .")
while "`rest'" != "" {
if "`tok'" != "." {
local holder `holder'.`tok'
}
gettoken tok rest : rest , parse(" .")
}
local last `tok' /* assumes no trailing .'s */
class exit `"`holder'"'
end
program define _lastname
local rest $T_Name
gettoken tok rest : rest , parse(" .")
while "`rest'" != "" {
if "`tok'" != "." {
local holder `holder'.`tok'
}
gettoken tok rest : rest , parse(" .")
}
local last `tok' /* assumes no trailing .'s */
class exit `"`last'"'
end
/* Returns 1 if any of the objects holding the current object are a named
style, 0 otherwise.
*/
program define _any_named_styles
args rest
local name
gettoken tok rest : rest , parse(" .")
while "`tok'" != "" {
if "`tok'" != "." {
local name `name'.`tok'
if 0``name'.namedstyle' {
class exit = 1
exit /* EXIT */
}
}
gettoken tok rest : rest , parse(" .")
}
class exit = 0
end
program define _style_cleanup
capture mac drop T_percol
capture mac drop T_cancel
capture mac drop T_ok
* capture mac drop T_apply
capture mac drop T_txt*
capture mac drop T_v*
capture mac drop T_hv*
capture mac drop T_act*
capture mac drop T_codes*
capture mac drop T_Name
capture mac drop T_TopNm
capture mac drop T_SubNm
/* just leave behind since these need to span recursions
capture mac drop T_drawobj
capture mac drop T_curobj
capture mac drop T_changed
capture mac drop T_changed_p1
capture mac drop T_opts
capture mac drop T_is_style
capture mac drop T_numctrls
*/
end
/*
program define db
.dialog_box `0'
end
*/
/* unused would have to be changed to reference styles in schemes
/* -------------------------------------------------------------------------*/
/*
Removes all named styles referenced by the object or anything it
contains recursively.
*/
program define clearstyles
if `.isofclass style' {
if "`._styles.isa'" == "array" {
while 0`._styles.arrnels' > 0 {
._styles.Arrpop
}
while 0`._refs.arrnels' > 0 {
._refs.Arrpop
}
}
}
forvalues i=1/0`.instancemv.arrnels' {
if index("`.instancemv[`i'].isa'", "class") {
.instancemv[`i'].clearstyles
}
}
forvalues i=1/0`.dynamicmv.arrnels' {
if index("`.dynamicmv[`i'].isa'", "class") {
.dynamicmv[`i'].clearstyles
}
}
forvalues i=1/0`.classmv.arrnels' {
if index("`.classmv[`i'].isa'", "class") {
.classmv[`i'].clearstyles
}
}
end
*/
/* -------------------------------------------------------------------------*/
/* Recursively drill objects that might contain styles and reset all those of
the specified style and style name to reference the same thing (the first
one found.
*/
program define _gr_link_wrk
args class style
foreach arr in instancemv dynamicmv {
._gr_link_wrk_arr `arr'
}
end
program define _gr_link_wrk_arr
args arr
forvalues i=1/0`.`arr'.arrnels' {
local attrib `arr'[`i']
if "`.`attrib'.isa'" == "array" {
._gr_link_wrk_arr `attrib'
}
if "`.`attrib'.isa'" != "class" {
continue /* Continue */
}
if "`.`attrib'.classname'" == "`class'" & /*
*/ "`.`attrib'.stylename'" == "`style'" {
if "$T_linkstyle" == "" {
global T_linkstyle `.`attrib'.objkey'
}
else {
.`attrib'.ref = .${T_linkstyle}.ref
}
}
else {
if 0`.`attrib'._style_drillable' {
.`attrib'._gr_link_wrk `class' `style'
}
}
}
end
program define _style_drillable
if "`.isa'" != "class" {
class exit = 0
}
if `.isofclass serset' {
class exit = 1
}
if `.isofclass cell' {
class exit = 1
}
if `.isofclass view' {
class exit = 1
}
if `.isofclass subview' {
class exit = 1
}
if `.isofclass style' {
class exit = 1
}
class exit = 0
end
/* -------------------------------------------------------------------------*/
/* Creates a common axis for everything found at or below the specified
object. May be called repeatedly to give many objects a common axis and
plotregion.
*/
program define _gr_axes_wrk
args class style
foreach arr in instancemv dynamicmv {
._gr_axes_wrk_arr `arr'
}
end
program define _gr_axes_wrk_arr
args arr
forvalues i=1/0`.`arr'.arrnels' {
local attrib `arr'[`i']
if "`.`attrib'.isa'" == "array" {
._gr_link_wrk_arr `attrib'
continue /* Continue */
}
if "`.`attrib'.isa'" != "class" {
continue /* Continue */
}
if 0`.`attrib'.isofclass axis' {
_axis_set_ranges $T_plreg `attrib'.plotregion
/* don't copy series held in scale */
/*
.`attrib'.plotregion.ref = .$T_plreg.ref
/* scales below */
*/
local pos `.`attrib'.position.snm'
local ord = /*
*/ cond("`pos'"=="left" | "`pos'"=="right", "y", "x")
if "${T_`ord'axis}" == "" {
global T_`ord'axis `.`attrib'.objkey'
}
else {
.`attrib'.ref = .${T_`ord'axis}.ref
}
continue /* Continue */
}
if 0`.`attrib'.isofclass plotregion' {
_axis_set_ranges $T_plreg `attrib'
.`attrib'.xscale.ref = .$T_plreg.xscale.ref
.`attrib'.yscale.ref = .$T_plreg.yscale.ref
continue /* Continue */
}
if 0`.`attrib'.isofclass view' | /*
*/ 0`.`attrib'.isofclass cell' {
.`attrib'._gr_axes_wrk `class' `style'
}
}
end
program define _axis_set_ranges
args shared from
.`shared'.xscale.addmin `.`from'.xscale.min'
.`shared'.xscale.addmax `.`from'.xscale.max'
.`shared'.yscale.addmin `.`from'.yscale.min'
.`shared'.yscale.addmax `.`from'.yscale.max'
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -