#ifndef MODGMT_OBJECTS_H #define MODGMT_OBJECTS_H #include #include #include #include #include #include "common.h" #include "modgmt_structs.h" // Centimeters to GMT points scale factor // 1 inch = 72 pt = 2.54 cm --> 1 cm = 72/2.54 pt // GMT's own scaling factor is 0.06 inline static double cm2GMT(double cm) { static const double scale=(72.0/2.54)/0.06; return cm*scale; } template class ObjectGMTClass: public ObjectBase { static_assert(std::is_base_of::value,"Template parameter of ObjectGMTClass must be gmt_struct-derived type"); const static std::string type; GMTStruct s; public: // Constructor ObjectGMTClass(const GMTStruct& n):s(n) {} // Pure virtual overrides ObjectBase* Copy() const override {return new ObjectGMTClass(s);} bool Print() const override { COUT(NORMAL)< ObjectGMTCoord; template<> inline ObjectBase* ObjectGMTCoord::OGet(const std::string& name) const { if("n"==name || "number"==name) return new ObjectReal(s); return 0; } // GMTRegion typedef ObjectGMTClass ObjectGMTRegion; template<> inline ObjectBase* ObjectGMTRegion::OGet(const std::string& name) const { if("xb"==name) return new ObjectGMTCoord(s.xb); if("xe"==name) return new ObjectGMTCoord(s.xe); if("yb"==name) return new ObjectGMTCoord(s.yb); if("ye"==name) return new ObjectGMTCoord(s.ye); return 0; } // GMTProjection typedef ObjectGMTClass ObjectGMTProjection; template<> inline ObjectBase* ObjectGMTProjection::OGet(const std::string& name) const { if("xb"==name) return new ObjectGMTCoord(s.region.xb); if("xe"==name) return new ObjectGMTCoord(s.region.xe); if("yb"==name) return new ObjectGMTCoord(s.region.yb); if("ye"==name) return new ObjectGMTCoord(s.region.ye); if("width"==name) return new ObjectReal(s.rwidth); if("height"==name) return new ObjectReal(s.rheight); if("region"==name) return new ObjectGMTRegion(s.region); return 0; } // GMTColor typedef ObjectGMTClass ObjectGMTColor; template<> inline ObjectBase* ObjectGMTColor::OGet(const std::string& name) const { if("gray"==name || "grey"==name) return new ObjectReal(s.Gray()); if("r"==name || "red"==name) return new ObjectReal(s.R()); if("g"==name || "green"==name) return new ObjectReal(s.G()); if("b"==name || "blue"==name) return new ObjectReal(s.B()); if("h"==name || "hue"==name) return new ObjectReal(s.H()); if("s"==name || "saturation"==name) return new ObjectReal(s.S()); if("v"==name || "value"==name) return new ObjectReal(s.V()); if("c"==name || "cyan"==name) return new ObjectReal(s.C()); if("m"==name || "magenta"==name) return new ObjectReal(s.M()); if("y"==name || "yellow"==name) return new ObjectReal(s.Y()); if("k"==name || "black"==name) return new ObjectReal(s.K()); if("t"==name || "transparency"==name) return new ObjectReal(s.transparency); return 0; } // GMTDash typedef ObjectGMTClass ObjectGMTDash; // GMTPen typedef ObjectGMTClass ObjectGMTPen; template<> inline ObjectBase* ObjectGMTPen::OGet(const std::string& name) const { if("w"==name || "width"==name) return new ObjectReal(s.width); if("c"==name || "color"==name) return new ObjectGMTColor(s.color); if("d"==name || "dash"==name) return new ObjectGMTDash(s.dash); return 0; } // GMTFont typedef ObjectGMTClass ObjectGMTFont; template<> inline ObjectBase* ObjectGMTFont::OGet(const std::string& name) const { if("s"==name || "size"==name) return new ObjectReal(s.size); if("f"==name || "family"==name)return new ObjectString(s.family); if("c"==name || "color"==name) return new ObjectGMTColor(s.color); return 0; } // GMTLayer typedef ObjectGMTClass ObjectGMTLayer; template<> inline ObjectBase* ObjectGMTLayer::OGet(const std::string& name) const { if("proj"==name || "projection"==name) return new ObjectGMTProjection(s.proj); if("w"==name || "width"==name) return new ObjectReal(s.proj.rwidth); if("h"==name || "height"==name) return new ObjectReal(s.proj.rheight); if("shiftx"==name) return new ObjectReal(s.shiftx); if("shifty"==name) return new ObjectReal(s.shifty); return 0; } template<> const int8_t* ObjectGMTLayer::Blob(size_t* size) const; template<> void ObjectGMTLayer::DeallocBlob(const int8_t* ptr) const; #endif