/[ascend]/trunk/pygtk/interface/incidencematrix.cpp
ViewVC logotype

Annotation of /trunk/pygtk/interface/incidencematrix.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 237 - (hide annotations) (download) (as text)
Mon Jan 30 06:10:26 2006 UTC (17 years, 7 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2663 byte(s)
Incidence matrix now reports the mouseover-ed variable on the console
1 johnpye 233 #include "incidencematrix.h"
2    
3     #include <stdexcept>
4     #include <iostream>
5     using namespace std;
6    
7 johnpye 237 #include "variable.h"
8    
9 johnpye 233 IncidencePoint::IncidencePoint(const int&row, const int &col, const IncidencePointType &type) : row(row), col(col), type(type){
10     // constructor, IncidencePoint
11     }
12    
13     IncidencePoint::IncidencePoint(const IncidencePoint &old) : row(old.row), col(old.col), type(old.type){
14     // copy ctor
15     }
16    
17     IncidencePoint::IncidencePoint() : row(-1), col(-1), type(IM_NULL){
18     // default ctor... don't use. need this to keep swig happy for some strange reason.
19     }
20    
21     IncidenceMatrix::IncidenceMatrix(Simulation &sim) : sim(sim){
22     // constructor
23     is_built = FALSE;
24     }
25    
26     IncidenceMatrix::~IncidenceMatrix(){
27     if(is_built){
28     free_incidence_data(&i);
29     }
30     }
31    
32     void
33     IncidenceMatrix::buildPlotData(){
34     int c=-1;
35    
36     cerr << "BUILDPLOTDATA" << endl;
37    
38     slv_system_t sys = sim.getSystem();
39    
40     cerr << "GOT SYSTEM DATA" << endl;
41    
42     if(build_incidence_data(sys,&i)) {
43     cerr << "FAILED TO BUILD INCIDENCE DATA" << endl;
44     free_incidence_data(&i);
45     throw runtime_error("IncidenceMatrix::buildPlotData error calculating grid");
46     return;
47     }
48    
49     for (int r=0; r < i.nprow; r++) {
50     struct rel_relation *rel = i.rlist[i.pr2e[r]];
51     const struct var_variable **vp = rel_incidence_list(rel);
52    
53     if(rel_active(rel)){
54     int nvars = rel_n_incidences(rel);
55     if(rel_included(rel)){
56     for(int v=0; v < nvars; v++ ) {
57     if(var_flags(vp[v]) & VAR_SVAR) {
58     int vndx = var_sindex(vp[v]);
59     c = i.v2pc[vndx];
60     if (i.vfixed[vndx]) {
61     data.push_back(IncidencePoint(r,c,IM_ACTIVE_FIXED));
62     }else{
63     data.push_back(IncidencePoint(r,c,IM_ACTIVE_FREE));
64     }
65     }
66     }
67     }else{ /* hollow squares */
68     for(int v=0; v < nvars; v++ ) {
69     if (var_flags(vp[v]) & VAR_SVAR) {
70     int vndx = var_sindex(vp[v]);
71     c = i.v2pc[vndx];
72     if (i.vfixed[vndx]) {
73     data.push_back(IncidencePoint(r,c,IM_DORMANT_FIXED));
74     } else {
75     data.push_back(IncidencePoint(r,c,IM_DORMANT_FREE));
76     }
77     }
78     }
79     }
80     }
81     }
82    
83     is_built = TRUE;
84     }
85    
86 johnpye 234 const int &
87     IncidenceMatrix::getNumRows() const{
88     return i.nprow;
89     }
90    
91     const int &
92     IncidenceMatrix::getNumCols() const{
93     return i.npcol;
94     }
95    
96 johnpye 233 const vector<IncidencePoint> &
97     IncidenceMatrix::getIncidenceData(){
98     cerr << "GET INCIDENCE DATA" << endl;
99     if(!is_built){
100     buildPlotData();
101     }
102     return data;
103     }
104 johnpye 237
105     const Variable
106     IncidenceMatrix::getVariable(const int &col) const{
107     if(!is_built)throw runtime_error("Not built");
108     if(col < 0 || col >= getNumCols())throw runtime_error("Column out of range");
109     int vindex = i.pc2v[col];
110     struct var_variable *var = i.vlist[vindex];
111    
112     return Variable(&sim, var);
113     }
114    
115    

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22