File: other.cpp

package info (click to toggle)
fityk 0.4.4-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,472 kB
  • ctags: 2,617
  • sloc: cpp: 19,705; sh: 5,965; xml: 2,325; yacc: 356; makefile: 183; lex: 178
file content (201 lines) | stat: -rw-r--r-- 4,901 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
// This file is part of fityk program. Copyright (C) Marcin Wojdyr
#include "common.h"
RCSID ("$Id: other.cpp,v 1.11 2004/10/27 13:06:46 wojdyr Exp $")

#include "other.h"
#include <stdio.h>
#include <fstream>
#include "ffunc.h"
#include "data.h"
#include "sum.h"
#include "ui.h"
#include "v_fit.h"
#include "manipul.h"
#ifdef USE_XTAL
    #include "crystal.h"
#endif
#include "pcore.h"

using namespace std;

ApplicationLogic *AL;


void ApplicationLogic::reset_all (bool finish) 
{
    delete my_manipul;
    delete fitMethodsContainer;
    purge_all_elements(cores);
    cores.clear();
    delete params;
    if (finish)
        return;
    fitMethodsContainer = new FitMethodsContainer;
    my_manipul = new Manipul;
    params = new Parameters;
    append_core();
}


void ApplicationLogic::dump_all_as_script (string filename)
{
    ofstream os(filename.c_str(), ios::out);
    if (!os) {
        warn ("Can't open file: " + filename);
        return;
    }
    os << fityk_version_line << endl;
    os << "####### Dump time: " << time_now() << endl << endl;
    params->export_as_script(os);
    os << endl;

    for (int i = 0; i != size(cores); i++) {
        if (cores.size() > 1) 
            os << endl << "### core of plot #" << i << endl;
        if (i != 0)
            os << "d.activate *::" << endl; 
        cores[i]->export_as_script(os);
        os << endl;
    }
    if (active_core != size(cores) - 1)
        os << "d.activate " << active_core << ":: # set active" << endl; 
    os << "o.plot " << my_core->view.str() << endl;

    fitMethodsContainer->export_methods_settings_as_script(os);
    os << "f.method " << my_fit->symbol <<" ### back to current method\n";
    os << endl;
    os << endl << "####### End of dump " << endl; 
}

void ApplicationLogic::activate(int p, int d)
{
    if (p != -1)
        activate_core(p);
    cores[active_core]->activate_data(d);
}

void ApplicationLogic::remove(int p, int d)
{
    if (p != -1 && d == -1) //eg. ! 2::
        remove_core(p);
    else if (p != -1 && d != -1) { //eg. ! 2::3
        if (p < 0 || p >= size(cores)) {
            warn("No such plot: " + S(p));
            return;
        }
        cores[p]->remove_data(d);
    }
    else if (p == -1) //eg. ! ::  or  ! ::3
        my_core->remove_data(d);
}

bool ApplicationLogic::activate_core(int p)
{
    if (p < 0 || p >= size(cores)) {
        warn("No such plot: " + S(p));
        return false;
    }

    if (p == active_core) 
        return true;

    active_core = p;
    c_was_changed = true;
    cores[active_core]->set_my_vars();
    return true;
}

int ApplicationLogic::append_core()
{
    cores.push_back(new PlotCore(params));
    active_core = cores.size() - 1;
    c_was_changed = true;
    cores[active_core]->set_my_vars();
    return active_core;
}

int ApplicationLogic::append_data(int p)
{
    if (p != -1)
        activate_core(p);
    return my_core->append_data(); 
}

void ApplicationLogic::remove_core(int p)
{
    if (p >= 0 && p < size(cores)) {
        if (p == active_core) 
            active_core = p > 0 ? p-1 : 0;
        purge_element(cores, p);
        if (cores.empty()) //it should not be empty
            cores.push_back(new PlotCore(params));
        c_was_changed = true;
        cores[active_core]->set_my_vars();
    }
    else
        warn("Not a plot number: " + S(p));
}

bool ApplicationLogic::was_changed() const
{ 
    return c_was_changed || params->was_changed() 
           || get_active_core()->was_changed();
}

void ApplicationLogic::was_plotted() 
{ 
    c_was_changed = false;
    params->was_plotted();
    cores[active_core]->was_plotted();
}

const PlotCore *ApplicationLogic::get_core(int n) const
{
    return (n >= 0 && n < size(cores)) ?  cores[n] : 0;
}


int ApplicationLogic::refs_to_a (Pag p) const
{
    int n = 0;
    for (vector<PlotCore*>::const_iterator i = cores.begin(); i != cores.end();
                                                                        i++)
        n += (*i)->sum->refs_to_ag(p);
    return n;
}

string ApplicationLogic::descr_refs_to_a (Pag p) const
{
    string s = "";
    for (vector<PlotCore*>::const_iterator i = cores.begin(); i != cores.end();
                                                                        i++)
        s += (*i)->sum->descr_refs_to_ag(p);
    return s;
}

void ApplicationLogic::synch_after_rm_a (Pag p)
{
    for (vector<PlotCore*>::iterator i = cores.begin(); i != cores.end(); i++)
        (*i)->sum->synch_after_rm_ag(p);
}


//==================================================================

DotSet *
set_class_p (char c)
{
    switch (c) {
        case 'd': return my_data;
        case 'f': return my_fit;
        case 's': return my_sum;
        case 'm': return my_manipul;
#ifdef USE_XTAL
        case 'c': return my_crystal;
#endif //USE_XTAL
        case 'o': return getUI();
        default : return 0;
    }
}