00001 00007 #include "selection.h" 00008 #include <QtGui/qpainter.h> 00009 #include <fstream> 00010 #include <iostream> 00011 #include <ostream> 00012 #include "shape.h" 00013 #include "rectangle.h" 00014 00015 Selection::Selection() 00016 { 00017 // prevent dangling pointers 00018 m_shape = NULL; 00019 } 00020 00021 Selection::~Selection() 00022 { 00023 } 00024 00025 Shape* Selection::AllocateShape(SHAPE_TYPE type) 00026 { 00027 Shape *f; 00028 switch (type) { 00029 case RECTANGLE : 00030 f = new Rectangle(); 00031 break; 00032 00033 default: 00034 f = NULL; 00035 break; 00036 } 00037 return f; 00038 } 00039 00040 void Selection::HandleNewShape(Shape* s) 00041 { 00042 if (m_shape) { 00043 delete m_shape; 00044 m_shape = 0; 00045 } 00046 m_shape = s; 00047 } 00048 00049 Shape* Selection::GetShape() 00050 { 00051 if (m_shape) { 00052 return m_shape; 00053 } else { 00054 return NULL; 00055 } 00056 } 00057 00058 00059 double Selection::SumValues(Image* pData) 00060 { 00061 00062 double s = 0; 00063 if (m_shape) { 00064 s = m_shape->SumValues(pData); 00065 } 00066 return s; 00067 } 00068 00069 void Selection::Draw(QPainter* p, int fact) 00070 { 00071 if (m_shape) { 00072 m_shape->Draw(p,fact); 00073 } 00074 } 00075 00076 double Selection::GetSurface() 00077 { 00078 double size = 0; 00079 if (m_shape) { 00080 size = m_shape->GetSurface(); 00081 } 00082 return size; 00083 } 00084 00085 bool Selection::Save(std::ofstream& f) 00086 { 00087 return false; 00088 } 00089 00090 bool Selection::Read(std::ifstream& f) 00091 { 00092 return false; 00093 } 00094