00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 #include "thirdparty/Group.h"
00024 
00025 namespace cmlabs {
00026 
00027 Group::Group() {
00028         direction = 0;
00029 }
00030 
00031 Group::Group(JString xml) {
00032         if (!Object::fromXML(xml)) {
00033                 direction = 0;
00034         }
00035 }
00036 
00037 Group::Group(XMLNode* node) {
00038         if (!fromXML(node)) {
00039                 direction = 0;
00040         }
00041 }
00042 
00043 Group::Group(JString idstring, JTime t, int cmx, int cmy, int w, int h, int angle) {
00044         id = idstring;
00045         time = t;
00046         cm = Point(cmx, cmy);
00047         size = Size(w, h);
00048         direction = angle;
00049 }
00050 
00051 Group::~Group() {}
00052 
00053 Object* Group::clone() const {
00054         Group* fv = new Group();
00055         *fv = *this;
00056         return fv;
00057 }
00058 
00059 JString Group::print() {
00060         return JString::format(" '%s' JTime(%s) CM(%s) Size(%s) Angle(%.3f) Points(%d) Vector(%d)",
00061                 (char*) id, (char*) time.printTime(),
00062                 (char*) cm.print(), (char*) size.print(),
00063                 direction, pointVector.getSize(), vector.getSize());
00064 }
00065 
00066 JString Group::toXML() {
00067         return JString::format("<group id=\"%s\" angle=\"%f\">%s%s%s%s%s</group>",
00068                 (char*) id.xmlStringEncode(), direction,
00069                 (char*) time.toXML(),
00070                 (char*) cm.toXML(),
00071                 (char*) size.toXML(),
00072                 (char*) pointVector.toXML(),
00073                 (char*) vector.toXML());
00074 }
00075 
00076 bool Group::fromXML(XMLNode* node) {
00077         if (node == NULL) {
00078                 return false;
00079         }
00080         if (!node->getTag().equalsIgnoreCase("group"))
00081                 return false;
00082 
00083         direction = node->getAttribute("angle").toDouble();
00084         id = node->getAttribute("id");
00085         
00086         XMLNode* xmlNode;
00087 
00088         ObjectCollection* oc = node->getChildTags();
00089         if (oc != NULL) {
00090                 for (int n=0; n<oc->getCount(); n++) {
00091                         xmlNode = (XMLNode*) oc->get(n);
00092                         if (xmlNode != NULL) {
00093                         
00094                                 if (xmlNode->getTag().equalsIgnoreCase("time")) {
00095                                         if (!time.fromXML(xmlNode))
00096                                                 return false;
00097                                 }
00098                                 else if (xmlNode->getTag().equalsIgnoreCase("point")) {
00099                                         if (!cm.fromXML(xmlNode))
00100                                                 return false;
00101                                 }
00102                                 else if (xmlNode->getTag().equalsIgnoreCase("size")) {
00103                                         if (!size.fromXML(xmlNode))
00104                                                 return false;
00105                                 }
00106                                 else if (xmlNode->getTag().equalsIgnoreCase("vector")) {
00107 
00108                                         if (!xmlNode->getAttribute("type").equalsIgnoreCase("point")) {
00109                                                 if (!pointVector.fromXML(xmlNode))
00110                                                         return false;
00111                                         }
00112                                         else if (!xmlNode->getAttribute("type").equalsIgnoreCase("double")) {
00113                                                 if (!vector.fromXML(xmlNode))
00114                                                         return false;
00115                                         }
00116                                 }
00117                         }
00118                 }
00119         }
00120 
00121         return true;
00122 }
00123 
00124 }