/** NodeContainer.cpp * J Scott Cameron * * Implements a class that contains a single genetic image */ #include "NodeContainer.h" /*Default Contructor */ NodeContainer::NodeContainer() { } /* parameterized constructor */ NodeContainer::NodeContainer(PopulationContainer* PC, Node* N) { pc = PC; n = tree_copy(N,NULL); cx = cy = 0.0f; height = width = 200; xscale = yscale = 1.0f; /* create bitmap image */ updateMap(); } /* copy constructor */ NodeContainer::NodeContainer(NodeContainer* nc) { pc = nc->pc; n = tree_copy(nc->n,NULL); cx = nc->cx; cy = nc->cy; xscale = nc->xscale; yscale = nc->yscale; height = width = 80; /* create bitmap image */ updateMap(); } /* destructor */ NodeContainer::~NodeContainer() { // delete(n); DeleteObject(bitmap); } /* calls the bitmap generator in the Population container */ void NodeContainer::updateMap() { DeleteObject(bitmap); bitmap = pc->getBitmapFromNode(n,width,height,cx,cy,xscale,yscale); } /* changes the height/width fields and regenerates image */ void NodeContainer::changeSize(int x, int y) { width = x; height = y; updateMap(); } /* saves node info */ void NodeContainer::save(string filename) { ofstream out(filename.c_str()); out << n->print(); } /* constrcuts node from a file */ NodeContainer::NodeContainer(PopulationContainer* PC, string filename) { pc = PC; n = open(filename); cx = cy = 0.0f; height = width = 200; xscale = 1.0f; yscale = 1.0f; updateMap(); } /* constrcuts node from a file with a specific height/width*/ NodeContainer::NodeContainer(PopulationContainer* PC, string filename, int Width, int Height) { pc = PC; n = open(filename); cx = cy = 0.0f; height = Height; width = Width; xscale = 1.0f; yscale =1.0f; updateMap(); } /*creates a node from a string description*/ Node* NodeContainer::open(string filename) { ifstream in(filename.c_str()); string buffer; string final; in >> buffer; while(buffer.length() > 0) { final += buffer; in >> buffer; } int index = -1; return pc->P->open(NULL,&final,&index); }