2004-11-29 09:52:49 +00:00
|
|
|
#include "calib01.h"
|
|
|
|
|
2004-12-01 14:57:03 +00:00
|
|
|
#include <tree.h>
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAnal_msk
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool TAnal_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
int TAnal_msk::compute_offset() const
|
2004-11-29 09:52:49 +00:00
|
|
|
{
|
2004-12-01 10:56:41 +00:00
|
|
|
int delta = 0;
|
|
|
|
RCT rct; xvt_vobj_get_client_rect(TASK_WIN, &rct);
|
|
|
|
if (rct.right > 720)
|
|
|
|
delta = (rct.right - 720) / 2 / CHARX;
|
|
|
|
return delta;
|
|
|
|
}
|
2004-11-29 09:52:49 +00:00
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
TAnal_msk::TAnal_msk(const char* name)
|
|
|
|
{
|
|
|
|
const TFilename outname = "anal.msk";
|
|
|
|
TFilename inpname = name; inpname.ext("msk");
|
|
|
|
inpname.custom_path();
|
|
|
|
|
|
|
|
ofstream out(outname);
|
|
|
|
|
|
|
|
int delta = compute_offset();
|
|
|
|
TString line;
|
2004-11-29 09:52:49 +00:00
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
TScanner inp(inpname);
|
|
|
|
while (!inp.eof())
|
2004-11-29 09:52:49 +00:00
|
|
|
{
|
2004-12-01 10:56:41 +00:00
|
|
|
line = inp.line();
|
|
|
|
if (line.starts_with("PR "))
|
2004-11-29 09:52:49 +00:00
|
|
|
{
|
2004-12-01 10:56:41 +00:00
|
|
|
TToken_string l(line, ' ');
|
|
|
|
l.strip_d_spaces();
|
|
|
|
int x = l.get_int(1);
|
|
|
|
if (x >= 0)
|
2004-11-29 09:52:49 +00:00
|
|
|
{
|
2004-12-01 10:56:41 +00:00
|
|
|
x += delta;
|
|
|
|
l.add(x, 1);
|
|
|
|
line = l;
|
2004-11-29 09:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-01 10:56:41 +00:00
|
|
|
out << line << endl;
|
2004-11-29 09:52:49 +00:00
|
|
|
}
|
2004-12-01 10:56:41 +00:00
|
|
|
out.close();
|
2004-11-29 09:52:49 +00:00
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
read_mask(outname, 0, 0);
|
|
|
|
xvt_fsys_removefile(outname);
|
2004-11-29 09:52:49 +00:00
|
|
|
}
|
|
|
|
|
2004-12-01 14:57:03 +00:00
|
|
|
short TAnal_msk::create_tree_field()
|
|
|
|
{
|
|
|
|
short id = 0;
|
|
|
|
const int delta = compute_offset();
|
|
|
|
if (delta > 0)
|
|
|
|
{
|
|
|
|
id = 99;
|
|
|
|
add_tree(id, 0, 0, 1, delta*2, -1);
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSimple_anal_tree
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TSimple_anal_tree : public TBidirectional_tree
|
|
|
|
{
|
|
|
|
TLocalisamfile _file;
|
|
|
|
TString16 _key_field, _des_field;
|
|
|
|
|
|
|
|
TRecnotype _curr;
|
|
|
|
TString _str_curr;
|
|
|
|
|
|
|
|
void update_curr();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void node2id(const TObject* node, TString& id) const;
|
|
|
|
|
|
|
|
virtual bool goto_firstson();
|
|
|
|
virtual bool goto_rbrother();
|
|
|
|
virtual bool goto_node(const TString &id);
|
|
|
|
virtual TObject* curr_node() const;
|
|
|
|
virtual bool goto_father();
|
|
|
|
virtual bool goto_lbrother();
|
|
|
|
virtual bool get_description(TString& desc) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool goto_root();
|
|
|
|
|
|
|
|
TSimple_anal_tree(int logicnum);
|
|
|
|
};
|
|
|
|
|
|
|
|
void TSimple_anal_tree::update_curr()
|
|
|
|
{
|
|
|
|
_curr = _file.recno();
|
|
|
|
_str_curr.format("%ld", _curr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TSimple_anal_tree::node2id(const TObject* node, TString& id) const
|
|
|
|
{
|
|
|
|
id = *(TString*)node;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::goto_root()
|
|
|
|
{
|
|
|
|
const int err = _file.first();
|
|
|
|
if (err == NOERR)
|
|
|
|
update_curr();
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::goto_firstson()
|
|
|
|
{
|
|
|
|
int err = _file.readat(_curr);
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString pref = _file.curr().get(_key_field);
|
|
|
|
err = _file.next();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString now = _file.curr().get(_key_field);
|
|
|
|
if (now.starts_with(pref))
|
|
|
|
update_curr();
|
|
|
|
else
|
|
|
|
err = _iskeynotfound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::goto_rbrother()
|
|
|
|
{
|
|
|
|
int err = _file.readat(_curr);
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString pref = _file.curr().get(_key_field);
|
|
|
|
err = _file.next();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString now = _file.curr().get(_key_field);
|
|
|
|
if (now.len() == pref.len())
|
|
|
|
update_curr();
|
|
|
|
else
|
|
|
|
err = _iskeynotfound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::goto_node(const TString &id)
|
|
|
|
{
|
|
|
|
const int err = _file.readat(atol(id));
|
|
|
|
if (err == NOERR)
|
|
|
|
update_curr();
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::goto_father()
|
|
|
|
{
|
|
|
|
int err = _file.readat(_curr);
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString pref = _file.curr().get(_key_field);
|
|
|
|
while (err == NOERR)
|
|
|
|
{
|
|
|
|
err = _file.prev();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString prev = _file.curr().get(_key_field);
|
|
|
|
if (prev.len() < pref.len())
|
|
|
|
{
|
|
|
|
update_curr();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::goto_lbrother()
|
|
|
|
{
|
|
|
|
int err = _file.readat(_curr);
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString pref = _file.curr().get(_key_field);
|
|
|
|
err = _file.prev();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TString prev = _file.curr().get(_key_field);
|
|
|
|
if (prev.len() == pref.len())
|
|
|
|
update_curr();
|
|
|
|
else
|
|
|
|
err = _iskeynotfound;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
TObject* TSimple_anal_tree::curr_node() const
|
|
|
|
{
|
|
|
|
return (TObject*)&_str_curr;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TSimple_anal_tree::get_description(TString& desc) const
|
|
|
|
{
|
|
|
|
int err = ((TLocalisamfile&)_file).readat(_curr);
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
desc = _file.curr().get(_key_field);
|
|
|
|
desc << ' ' << _file.curr().get(_des_field);
|
|
|
|
}
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
TSimple_anal_tree::TSimple_anal_tree(int logicnum)
|
|
|
|
: _file(logicnum)
|
|
|
|
{
|
|
|
|
_key_field = _file.curr().fieldname(0);
|
|
|
|
_des_field = "DESCR";
|
|
|
|
}
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TSimple_anal_msk
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TSimple_anal_msk::get_key_fields(TString& key1, TString& key2) const
|
|
|
|
{
|
|
|
|
const RecDes& des = prefix().get_recdes(get_logicnum());
|
|
|
|
|
|
|
|
const KeyDes k1 = des.Ky[0];
|
|
|
|
key1 = des.Fd[k1.FieldSeq[0] % MaxFields].Name;
|
|
|
|
|
|
|
|
const KeyDes k2 = des.Ky[1];
|
|
|
|
key2 = des.Fd[k2.FieldSeq[0] % MaxFields].Name;
|
|
|
|
}
|
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
int TSimple_anal_msk::get_key_len(int level, TConfig& cfg) const
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
for (int i = 1; i <= level; i++)
|
|
|
|
{
|
|
|
|
const TString& picture = cfg.get(get_key_var(), NULL, i);
|
|
|
|
len += picture.len();
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
void TSimple_anal_msk::create_key_browse(TEdit_field& kfld, int level, TConfig& cfg)
|
|
|
|
{
|
|
|
|
TString16 key1, key2;
|
|
|
|
get_key_fields(key1, key2);
|
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
const TString q(get_key_len(level, cfg), '?');
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
TFilename tmp; tmp.temp();
|
|
|
|
ofstream out(tmp);
|
2004-12-01 10:56:41 +00:00
|
|
|
out << "US " << get_logicnum() << " SE " << key1 << "?=\"" << q << '"' << endl;
|
2004-11-29 09:52:49 +00:00
|
|
|
out << "KE 1" << endl;
|
|
|
|
|
|
|
|
int from = 1, to = 1;
|
2004-12-01 10:56:41 +00:00
|
|
|
for (int i = 1; i <= level; i++)
|
2004-11-29 09:52:49 +00:00
|
|
|
{
|
|
|
|
const TString& picture = cfg.get(get_key_var(), NULL, i);
|
|
|
|
const TString& prompt = cfg.get(get_des_var(), NULL, i);
|
|
|
|
to = from + picture.len()-1;
|
|
|
|
TString field; field.format("%s[%d,%d]", (const char*)key1, from, to);
|
2004-12-01 10:56:41 +00:00
|
|
|
out << "IN " << field << ' ' << get_key_id(i-1) << endl;
|
|
|
|
out << "DI \"" << prompt << '@' << (to-from+1) << "\" " << field << endl;
|
|
|
|
out << "OU " << get_key_id(i-1) << ' ' << field << endl;
|
2004-11-29 09:52:49 +00:00
|
|
|
from = to+1;
|
|
|
|
}
|
|
|
|
out << "DI \"Descrizione@50\" " << key2 << endl;
|
|
|
|
out << "OU " << get_des_id(level-1) << ' ' << key2 << endl;
|
|
|
|
out << "CH " << (level == 1 ? "RE" : "NO") << endl;
|
|
|
|
out << "EN" << endl;
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
TScanner scan(tmp);
|
|
|
|
while (scan.pop() != "EN")
|
|
|
|
kfld.parse_item(scan);
|
|
|
|
|
|
|
|
xvt_fsys_removefile(tmp);
|
|
|
|
}
|
|
|
|
|
2004-12-01 10:56:41 +00:00
|
|
|
void TSimple_anal_msk::create_des_browse(TEdit_field& kfld, int level, TConfig& cfg)
|
|
|
|
{
|
|
|
|
TString16 key1, key2;
|
|
|
|
get_key_fields(key1, key2);
|
|
|
|
|
|
|
|
const TString q(get_key_len(level, cfg), '?');
|
|
|
|
|
|
|
|
TFilename tmp; tmp.temp();
|
|
|
|
ofstream out(tmp);
|
|
|
|
out << "US " << get_logicnum() << " KE 2" << " SE " << key1 << "?=\"" << q << '"' << endl;
|
|
|
|
out << "KE 2" << endl;
|
|
|
|
|
|
|
|
out << "DI \"Descrizione@50\" " << key2 << endl;
|
|
|
|
out << "IN " << key2 << ' ' << kfld.dlg() << endl;
|
|
|
|
out << "OU " << kfld.dlg() << ' ' << key2 << endl;
|
|
|
|
|
|
|
|
int from = 1, to = 1;
|
|
|
|
for (int i = 1; i <= level; i++)
|
|
|
|
{
|
|
|
|
const TString& picture = cfg.get(get_key_var(), NULL, i);
|
|
|
|
const TString& prompt = cfg.get(get_des_var(), NULL, i);
|
|
|
|
to = from + picture.len()-1;
|
|
|
|
TString field; field.format("%s[%d,%d]", (const char*)key1, from, to);
|
|
|
|
out << "DI \"" << prompt << '@' << (to-from+1) << "\" " << field << endl;
|
|
|
|
out << "OU " << get_key_id(i-1) << ' ' << field << endl;
|
|
|
|
from = to+1;
|
|
|
|
}
|
|
|
|
out << "CH NO" << endl;
|
|
|
|
out << "EN" << endl;
|
|
|
|
out.close();
|
|
|
|
|
|
|
|
TScanner scan(tmp);
|
|
|
|
while (scan.pop() != "EN")
|
|
|
|
kfld.parse_item(scan);
|
|
|
|
|
|
|
|
xvt_fsys_removefile(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
int TSimple_anal_msk::create_key_fields()
|
|
|
|
{
|
|
|
|
TConfig cfg(CONFIG_DITTA, "ca");
|
|
|
|
const char* keyvar = get_key_var();
|
|
|
|
const char* desvar = get_des_var();
|
|
|
|
|
|
|
|
int maxkeylen = 0, maxdeslen = 0;
|
|
|
|
int level;
|
|
|
|
for (level = 1; ; level++)
|
|
|
|
{
|
|
|
|
const TString& prompt = cfg.get(desvar, NULL, level);
|
|
|
|
if (prompt.blank())
|
|
|
|
break;
|
|
|
|
const TString& picture = cfg.get(keyvar, NULL, level);
|
|
|
|
const int keylen = picture.len();
|
|
|
|
const int deslen = prompt.len();
|
|
|
|
if (keylen > maxkeylen) maxkeylen = keylen;
|
|
|
|
if (deslen > maxdeslen) maxdeslen = deslen;
|
|
|
|
}
|
|
|
|
maxdeslen++;
|
2004-12-01 10:56:41 +00:00
|
|
|
const int tab0 = compute_offset()+2;
|
|
|
|
const int tab1 = tab0 + maxdeslen + maxkeylen + 4;
|
2004-11-29 09:52:49 +00:00
|
|
|
for (int i = 1; i < level; i++)
|
|
|
|
{
|
|
|
|
const short kid = get_key_id(i-1);
|
|
|
|
CHECKD(kid > 100, "Invalid field id:", kid);
|
|
|
|
|
|
|
|
const TString& picture = cfg.get(keyvar, NULL, i);
|
|
|
|
TString80 prompt = cfg.get(desvar, NULL, i);
|
|
|
|
prompt.left_just(maxdeslen);
|
|
|
|
TEdit_field& kfld = add_string(kid, 0, prompt, tab0, i, picture.len(), "B");
|
|
|
|
create_key_browse(kfld, i, cfg);
|
|
|
|
|
|
|
|
const short did = get_des_id(i-1);
|
|
|
|
if (did > kid)
|
|
|
|
{
|
2004-12-01 10:56:41 +00:00
|
|
|
TEdit_field& dfld = add_string(did, 0, "", tab1, i, 50, "B", 72+tab0-tab1);
|
|
|
|
create_des_browse(dfld, i, cfg);
|
2004-11-29 09:52:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
2004-12-01 14:57:03 +00:00
|
|
|
short TSimple_anal_msk::create_tree_field()
|
|
|
|
{
|
|
|
|
const short tree_id = TAnal_msk::create_tree_field();
|
|
|
|
if (tree_id != 0)
|
|
|
|
{
|
|
|
|
TSimple_anal_tree* t = new TSimple_anal_tree(get_logicnum());
|
|
|
|
tfield(tree_id).set_tree(t);
|
|
|
|
t->goto_root();
|
|
|
|
t->expand();
|
|
|
|
}
|
|
|
|
return tree_id;
|
|
|
|
}
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
TSimple_anal_msk::TSimple_anal_msk(const char* name) : TAnal_msk(name)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAnal_app
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TRelation* TAnal_app::create_relation() const
|
|
|
|
{
|
|
|
|
return new TRelation(_msk->get_logicnum());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnal_app::user_create()
|
|
|
|
{
|
|
|
|
_msk = create_mask();
|
|
|
|
_rel = create_relation();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnal_app::user_destroy()
|
|
|
|
{
|
|
|
|
if (_msk != NULL)
|
|
|
|
delete _msk;
|
|
|
|
if (_rel != NULL)
|
|
|
|
delete _rel;
|
|
|
|
return true;
|
|
|
|
}
|