00001 #ifndef __LINE_H 00002 #define __LINE_H 00003 00004 #include "windows_defs.h" 00005 00006 #include <vector> 00007 #include <cstdlib> 00008 #include <typeinfo> 00009 00010 #include <qcolor.h> 00011 #include "xmlserializeable.h" 00012 00019 class GV_EXPORT DspAttr { 00020 public: 00021 QColor color; 00022 short width; 00023 Qt::PenStyle style; 00024 00025 DspAttr( ) : 00026 color( QColor( 61, 221,37 ) ), 00027 width( 1 ), 00028 style( Qt::SolidLine ) { 00029 } 00030 }; 00031 00038 class GV_EXPORT Shape { 00039 public: 00040 DspAttr mAttr; 00041 virtual ~Shape( ) { 00042 } 00043 virtual DspAttr& getAttr( ) { 00044 return mAttr; 00045 } 00046 }; 00047 00048 00053 class GV_EXPORT Node : public Shape, public XMLSerializeable { 00054 public: 00055 double x; 00056 double y; 00057 double z; 00058 00059 Node( ) : 00060 x( 0.0 ), 00061 y( 0.0 ), 00062 z( 0.0 ) { 00063 } 00064 00065 virtual ~Node( ) { 00066 } 00067 00068 virtual bool toXML( QDomDocument &doc, 00069 QDomElement &elem, 00070 std::string id = "" ) { 00071 QDomElement base = doc.createElement( "Node" ); 00072 if ( id != "" ) 00073 base.setAttribute( "id", id.c_str() ); 00074 elem.appendChild( base ); 00075 00076 writeDoubleTag( doc, base, "X", x ); 00077 writeDoubleTag( doc, base, "Y", y ); 00078 writeDoubleTag( doc, base, "Z", z ); 00079 00080 return true; 00081 } 00082 00083 virtual bool fromXML( QDomElement &elem ) { 00084 std::string name = "Node"; 00085 if ( name.compare( (const char*)elem.tagName() ) ) 00086 return false; 00087 00088 x = readDoubleTag( elem, "X" ); 00089 y = readDoubleTag( elem, "Y" ); 00090 z = readDoubleTag( elem, "Z" ); 00091 return true; 00092 } 00093 }; 00094 00095 00100 class GV_EXPORT Line : public Shape, public XMLSerializeable { 00101 protected: 00102 00103 std::vector<Node> mNodeSet; 00104 00105 virtual bool nodesetFromXML( QDomElement &elem ); 00106 virtual bool nodesetToXML( QDomDocument &doc, 00107 QDomElement &elem ); 00108 00109 public: 00110 virtual ~Line( ) { 00111 mNodeSet.clear(); 00112 } 00113 00114 virtual bool fromXML( QDomElement &elem ); 00115 virtual bool toXML( QDomDocument &doc, 00116 QDomElement &elem, 00117 std::string id = "" ); 00118 00119 // virtual DspAttr& getAttr( ) { return mAttr; } 00120 void setAttr( DspAttr &attr ) { 00121 mAttr = attr; 00122 } 00123 00124 Node& operator[]( int inode ) const { 00125 return(Node&)mNodeSet[inode]; 00126 } 00127 00128 Node& getNode( int inode ) const { 00129 return(Node&)mNodeSet[inode]; 00130 } 00131 00132 std::vector<Node>& nodeset( ) { 00133 return mNodeSet; 00134 } 00135 unsigned int size( ) const { 00136 return mNodeSet.size(); 00137 } 00138 void delNode( unsigned int inode ) { 00139 if ( inode < mNodeSet.size() ) 00140 mNodeSet.erase( mNodeSet.begin() + inode ); 00141 } 00142 }; 00143 00147 class GV_EXPORT Rect : public Shape, public XMLSerializeable { 00148 public: 00149 double x; 00150 double y; 00151 double w; 00152 double h; 00153 00154 bool toXML( QDomDocument &doc, 00155 QDomElement &elem, 00156 std::string id="" ) { 00157 QDomElement base = doc.createElement( "Rect" ); 00158 if ( id != "" ) 00159 base.setAttribute( "id", id.c_str() ); 00160 elem.appendChild( base ); 00161 00162 writeDoubleTag( doc, base, "X", x ); 00163 writeDoubleTag( doc, base, "Y", y ); 00164 writeDoubleTag( doc, base, "W", w ); 00165 writeDoubleTag( doc, base, "H", h ); 00166 return true; 00167 } 00168 00169 bool fromXML( QDomElement &elem ) { 00170 if ( std::string( "Rect" ).compare( (const char*)elem.tagName() ) ) 00171 return false; 00172 00173 x = readDoubleTag( elem, "X" ); 00174 y = readDoubleTag( elem, "Y" ); 00175 w = readDoubleTag( elem, "W" ); 00176 h = readDoubleTag( elem, "H" ); 00177 return true; 00178 } 00179 }; 00180 00181 #endif 00182 00183 00184 00185
Home |
Search |
Disclaimers & Privacy |
Contact Us GLIMSView Maintainer: dsoltesz@usgs.gov |