425 lines
13 KiB
C++
Executable File
425 lines
13 KiB
C++
Executable File
#ifndef __DBLIB_H
|
||
#define __DBLIB_H
|
||
|
||
#ifndef __EXPR_H
|
||
#include <expr.h>
|
||
#endif
|
||
|
||
#ifndef __FRACTION_H
|
||
#include <fraction.h>
|
||
#endif
|
||
|
||
#ifndef __RECARRAY_H
|
||
#include <recarray.h>
|
||
#endif
|
||
|
||
#ifndef __TREE_H
|
||
#include <tree.h>
|
||
#endif
|
||
|
||
#ifndef __MGLIB_H
|
||
#include "../mg/mglib.h"
|
||
#endif
|
||
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TCodice_articolo
|
||
///////////////////////////////////////////////////////////
|
||
|
||
// Codice articolo di magazzino (equivale ad una TString20 )
|
||
class TCodice_articolo : public TFixed_string
|
||
{
|
||
char _str20[21];
|
||
|
||
protected:
|
||
virtual TObject* dup() const { return new TCodice_articolo(_str20); }
|
||
|
||
public:
|
||
TCodice_articolo(const char* s = "") : TFixed_string(_str20, 21)
|
||
{ set(s); }
|
||
TCodice_articolo(const TString& s) : TFixed_string(_str20, 21)
|
||
{ set(s); }
|
||
TCodice_articolo(const TCodice_articolo& s) : TFixed_string(_str20, 21)
|
||
{ set(s); }
|
||
const TString& operator =(const char* s)
|
||
{ return set(s); }
|
||
const TString& operator =(const TString& s)
|
||
{ return set((const char*)s); }
|
||
const TString& operator =(const TCodice_articolo& s)
|
||
{ return set((const char*)s); }
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TCodice_um
|
||
///////////////////////////////////////////////////////////
|
||
|
||
// Codice articolo di magazzino (equivale ad una TString2 )
|
||
class TCodice_um : public TFixed_string
|
||
{
|
||
char _str2[3];
|
||
|
||
protected:
|
||
virtual TObject* dup() const { return new TCodice_um(_str2); }
|
||
|
||
public:
|
||
TCodice_um(const char* s = "") : TFixed_string(_str2, 3)
|
||
{ strncpy(s,2); }
|
||
TCodice_um(const TString& s) : TFixed_string(_str2, 3)
|
||
{ strncpy(s,2); }
|
||
TCodice_um(const TCodice_um& s) : TFixed_string(_str2, 3)
|
||
{ strncpy(s,2); }
|
||
const TString& operator =(const char* s)
|
||
{ strncpy(s,2); return *this; }
|
||
const TString& operator =(const TString& s)
|
||
{ strncpy(s,2); return *this; }
|
||
const TString& operator =(const TCodice_um& s)
|
||
{ strncpy(s,2); return *this; }
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TLavorazione
|
||
///////////////////////////////////////////////////////////
|
||
class TUm_tempo : public TObject
|
||
{
|
||
real _ore;
|
||
public:
|
||
real & converti_in_ore() {return _ore;}
|
||
TUm_tempo(char c);
|
||
~TUm_tempo() {}
|
||
};
|
||
|
||
class TLavorazione : public TRectype
|
||
{
|
||
TString16 _codimp ;
|
||
TToken_string _linee ;
|
||
|
||
protected:
|
||
TObject* dup() const { return new TLavorazione(*this); }
|
||
|
||
public:
|
||
const char* codice() const { return get("CODTAB"); }
|
||
const char* descr() const { return get("S0"); }
|
||
const char* um() const { return get("S6"); }
|
||
TUm_tempo um_temporale() const {return (TUm_tempo)get_char("I7");}
|
||
real prezzo() const;
|
||
|
||
void reset_linee();
|
||
void get_linee();
|
||
void put_linee();
|
||
|
||
int linee_standard() const;
|
||
int linee() const;
|
||
|
||
const char * cod_impianto(int l);
|
||
const char * cod_linea(int l);
|
||
// numero addetti impiegati
|
||
const int raw_numpers_linea(int l);
|
||
const int numpers_linea(int l);
|
||
// produttivit<69>
|
||
real raw_produttiv_linea(int l);
|
||
real produttiv_linea(int l);
|
||
|
||
const int find_linea(const TString& linea);
|
||
bool set_cod_linea(int l, const char *c);
|
||
bool set_numpers_linea(int l, int pers);
|
||
bool set_produttiv_linea(int l, real & prod);
|
||
|
||
// @cmember Legge il file <p f> con il tipo di record
|
||
virtual int read(TBaseisamfile& f, word op = _isequal, word lockop = _nolock);
|
||
// @cmember Legge il file <p f> con il tipo di record alla posizione desiderata
|
||
virtual int readat(TBaseisamfile& f, TRecnotype nrec, word lockop = _nolock);
|
||
// @cmember Aggiunge il record al file
|
||
virtual int write(TBaseisamfile& f) const;
|
||
// @cmember Riscrive il record sul file
|
||
virtual int rewrite(TBaseisamfile& f) const;
|
||
// operatore di copia
|
||
virtual TRectype & operator =(const TRectype& rec);
|
||
|
||
TLavorazione(const char* cod = "") ;
|
||
TLavorazione(const TRectype& rec) ;
|
||
TLavorazione(const TLavorazione& rec) ;
|
||
virtual ~TLavorazione() { }
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TQuantita'
|
||
///////////////////////////////////////////////////////////
|
||
|
||
// Quantita' di un articolo in una certa unita' di misura
|
||
|
||
class TQuantita : public TSortable
|
||
{
|
||
TCodice_articolo _articolo; // Articolo di riferimento
|
||
TCodice_um _um; // Unita' di misura
|
||
real _val; // Valore attuale
|
||
|
||
protected:
|
||
virtual int compare(const TSortable& s) const;
|
||
virtual TObject* dup() const { return new TQuantita(*this); }
|
||
|
||
void copy(const TQuantita& q);
|
||
const fraction& get_factor(const TCodice_um& um) const;
|
||
void convert(real& val, const TCodice_um& from_um, const TCodice_um& to_um) const;
|
||
|
||
void find_umbase(TCodice_um& um) const;
|
||
void find_umdist(TCodice_um& um) const;
|
||
|
||
public:
|
||
virtual bool ok() const { return !_um.blank(); }
|
||
|
||
const TQuantita& operator =(const TQuantita& q)
|
||
{ copy(q); return q; }
|
||
|
||
const TQuantita& operator +=(const real& q);
|
||
const TQuantita& operator -=(const real& q);
|
||
const TQuantita& operator +=(const TQuantita& q);
|
||
const TQuantita& operator -=(const TQuantita& q);
|
||
const TQuantita& operator =(const real& q);
|
||
const TQuantita& operator *=(const real& q);
|
||
const TQuantita& operator /=(const real& q);
|
||
|
||
const TCodice_articolo& articolo() const { return _articolo; }
|
||
const TCodice_um& um() const { return _um; }
|
||
const real& val() const { return _val; }
|
||
real base_val() const;
|
||
|
||
void set_articolo(const TString& art, const TString& um);
|
||
void set_val(const real& val) {_val=val;}
|
||
void set(const TString& art, const TString& um, const real& val)
|
||
{ set_articolo(art, um); _val = val; }
|
||
|
||
void convert2umbase();
|
||
void convert2umdist();
|
||
|
||
void currency2umbase(TCurrency& val) const;
|
||
|
||
TQuantita();
|
||
TQuantita(const TQuantita& q);
|
||
TQuantita(const TString& art, const TString& um, const real& val);
|
||
virtual ~TQuantita();
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDistinta_expr
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TDistinta_expr : public TExpression
|
||
{
|
||
protected:
|
||
virtual bool print_error(const char* msg) const;
|
||
|
||
public:
|
||
TDistinta_expr();
|
||
virtual ~TDistinta_expr() { }
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TDistinta_tree
|
||
///////////////////////////////////////////////////////////
|
||
|
||
enum TExplosion_grouping
|
||
{
|
||
RAGGR_EXP_NONE = 0, // Nessun raggruppamento
|
||
RAGGR_EXP_EACHUM = 1, // Raggruppa ogni articolo per unit<69> di misura
|
||
RAGGR_EXP_BASE = 2, // Non raggruppare ma converti alla UM di base
|
||
RAGGR_EXP_UMBASE = 3, // Raggruppa le unit<69> di misura, esprimendo il totale nella UM di base
|
||
RAGGR_EXP_DIST = 4, // Non raggruppare ma converti alla UM di distinta
|
||
RAGGR_EXP_UMDIST = 5, // Raggruppa le unit<69> di misura, esprimendo il totale nella UM di distinta
|
||
};
|
||
|
||
|
||
// _RADICE : CODICE DELLA DISTINTA AL PRIMO LIVELLO
|
||
// _DISTINTA : CODICE DELLA DISTINTA
|
||
// _MAGAZZINO : CODICE MAGAZZINO/DEPOSITO
|
||
// _LIVELLO : LIVELLO DI GIACENZA
|
||
// _LINEA : CODICE LINEA DI PRODUZIONE
|
||
// _IMPIANTO : CODICE IMPIANTO
|
||
|
||
class TRiga_esplosione;
|
||
class TDistinta_tree : public TBidirectional_tree
|
||
{
|
||
TString _root;
|
||
TToken_string _path;
|
||
int _sort, _max_depth;
|
||
bool _ignore_ghost;
|
||
bool _stop_prod;
|
||
bool _livgiac_on_descr[4];
|
||
|
||
// TDecoder _vars, _mag, _lav;
|
||
TCodgiac_livelli *_livgiac;
|
||
bool _qta_on_descr;
|
||
char _descr_sep;
|
||
|
||
static const TRectype* _curr;
|
||
TToken_string _tmp;
|
||
|
||
TStack _stack;
|
||
TAssoc_array _globals;
|
||
|
||
private:
|
||
TCodgiac_livelli &livgiac() const;
|
||
|
||
protected:
|
||
bool isola_codice(TString& code) const;
|
||
|
||
bool add_child();
|
||
void kill_child();
|
||
|
||
virtual const TRectype& find_head(const TCodice_articolo& art) const;
|
||
virtual const TRectype* find_child(const TCodice_articolo& father, int child) const;
|
||
|
||
// int build_children_pointers(const TCodice_articolo& father, TPointer_array& children) const;
|
||
int build_children_list(const TCodice_articolo& father, TArray& children) const;
|
||
|
||
const TString& get_string(const char* var);
|
||
const real& get_real(const char* var);
|
||
|
||
void evaluate(TDistinta_expr& e);
|
||
real evaluate_numexpr(const char* str);
|
||
void evaluate_strexpr(const char* str, TString& res);
|
||
|
||
bool push_vars();
|
||
void pop_vars();
|
||
int raggruppa(TArray& boom, TExplosion_grouping mode) const;
|
||
|
||
protected: // TTree
|
||
virtual void node2id(const TObject* node, TString& id) const;
|
||
|
||
TObject * get_global(const char* name, word classname);
|
||
TObject * global_default_str(const char* name);
|
||
TObject * global_default_real(const char* name);
|
||
|
||
public:
|
||
TTypeexp get_var_type(const char* var);
|
||
static TLavorazione * find_labor(TRiga_esplosione *l);
|
||
virtual bool goto_root();
|
||
virtual bool goto_firstson();
|
||
virtual bool goto_rbrother();
|
||
virtual bool goto_node(const TString &id);
|
||
virtual bool has_son() const;
|
||
virtual bool has_rbrother() const;
|
||
virtual bool has_root() const;
|
||
virtual bool has_father() const;
|
||
virtual bool has_lbrother() const;
|
||
virtual bool goto_father();
|
||
virtual bool goto_lbrother();
|
||
virtual bool get_description(TString& desc) const;
|
||
virtual TImage* image(bool selected) const;
|
||
virtual TObject* curr_node() const;
|
||
|
||
const TString& describe(const TCodice_articolo& codart) const;
|
||
bool describe(const TCodice_articolo& codart, TString& descr) const;
|
||
|
||
bool set_root(const TQuantita& qta, const char * livgiac ="");
|
||
bool set_root(const TCodice_articolo& art, const char* um = "", real qta = 1.0, const char*livgiac="");
|
||
bool set_root(const TRectype & rec);
|
||
|
||
long find_node(const TCodice_articolo& str, word flags = SCAN_PRE_ORDER);
|
||
|
||
void set_sort_key(int k);
|
||
int get_sort_key() const { return _sort; }
|
||
bool get_ignore_ghost() const { return _ignore_ghost; }
|
||
bool get_stop_prod() const { return _stop_prod; }
|
||
bool get_livgiac_on_descr(int l) const ;
|
||
bool get_qta_on_descr() const {return _qta_on_descr;}
|
||
char get_descr_separator() const {return _descr_sep;}
|
||
|
||
void set_max_depth(int m) { _max_depth = m; }
|
||
int get_max_depth() const { return _max_depth; }
|
||
bool set_ignore_ghost(bool i) { return _ignore_ghost = i; }
|
||
bool set_stop_prod(bool i) { return _stop_prod = i; }
|
||
bool set_livgiac_on_descr(int l, bool on) ;
|
||
bool set_qta_on_descr(bool on) {return _qta_on_descr=on;}
|
||
char set_descr_separator(char on) {return _descr_sep=on;}
|
||
|
||
bool restart(); // reset all and go to root
|
||
int explode(TArray& boom, bool mat_base = FALSE,
|
||
TExplosion_grouping raggr = RAGGR_EXP_NONE,
|
||
int max_depth = 0, const char* filter = NULL,
|
||
int sort_key = 0, bool stop_prod = FALSE);
|
||
|
||
bool path_code(TCodice_articolo& code, const TToken_string &path) const;
|
||
bool path_giaclev(TString& code, int levnum, const TToken_string &path) const;
|
||
|
||
bool father_code(TCodice_articolo& code) const;
|
||
bool father_giaclev(TString& code, int levnum=0) const;
|
||
bool curr_code(TCodice_articolo& code) const {return path_code(code, _path);}
|
||
bool curr_giaclev(TString& code, int levnum=0) const {return path_giaclev(code, levnum, _path);}
|
||
int curr_comp(TString& code) const;
|
||
long curr_sort() const;
|
||
const char* curr_um(TCodice_um& code) const;
|
||
real last_qta(bool vis_ghost = FALSE) const;
|
||
real curr_qta() const;
|
||
int curr_depth() const { return path_depth(_path);}
|
||
char curr_type() const { return path_type(_path);}
|
||
|
||
int path_depth(const TToken_string & path) const;
|
||
char path_type(const TToken_string & path) const;
|
||
|
||
TRiga_esplosione *first_labor(TArray & labors, TExplosion_grouping raggum=RAGGR_EXP_UMBASE);
|
||
TRiga_esplosione *next_labor(TArray & labors);
|
||
TRiga_esplosione *first_critical_labor(TArray & labors, TExplosion_grouping raggum=RAGGR_EXP_UMBASE);
|
||
TRiga_esplosione *next_critical_labor(TArray & labors);
|
||
|
||
bool is_cyclic(const TToken_string& path) const;
|
||
bool is_cyclic() const { return is_cyclic(_path); }
|
||
|
||
bool is_root() const;
|
||
bool is_leaf() const;
|
||
|
||
bool is_mag(const char* c = NULL) const;
|
||
bool is_lav(const char* c = NULL) const;
|
||
char get_type(const char* c = NULL) const;
|
||
|
||
bool is_global(const char* var);
|
||
void clear_globals();
|
||
void set_global(const char* var, const char* val);
|
||
void set_global(const char* var, const real& val);
|
||
|
||
TDistinta_tree();
|
||
virtual ~TDistinta_tree();
|
||
};
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TRiga_esplosione
|
||
///////////////////////////////////////////////////////////
|
||
|
||
struct TExplosion_params;
|
||
|
||
class TRiga_esplosione : public TQuantita
|
||
{
|
||
TToken_string _path;
|
||
TString16 _giac;
|
||
long _sort;
|
||
char _tipo;
|
||
bool _mat_base;
|
||
real _last_qta;
|
||
|
||
protected:
|
||
virtual TObject* dup() const { return new TRiga_esplosione(*this); }
|
||
void init(const TDistinta_tree& tree, bool vis_ghost = FALSE);
|
||
|
||
public:
|
||
const TToken_string& path() const { return _path; }
|
||
const TString& giacenza() const { return _giac; }
|
||
long ordinamento() const { return _sort; }
|
||
int livello() const { return _path.items() - 1; }
|
||
char tipo() const { return _tipo; }
|
||
char mat_base() const { return _mat_base; }
|
||
|
||
void set_tipo(char c) { _tipo = c; }
|
||
void set_mat_base(bool b) { _mat_base = b; }
|
||
void set_path(const char* p) { _path = p;}
|
||
void set_giacenza(const char* g) { _giac = g; }
|
||
// cerca un padre o nonno di uno dei tipi passati
|
||
const char * father(const char * types=NULL);
|
||
const real& last_qta() const { return _last_qta; }
|
||
|
||
TRiga_esplosione();
|
||
TRiga_esplosione(const TDistinta_tree& tree, bool vis_ghost = FALSE);
|
||
TRiga_esplosione(const TRiga_esplosione& re);
|
||
virtual ~TRiga_esplosione() { }
|
||
};
|
||
|
||
#endif
|