Boost logo

Boost-Commit :

From: JakeVoytko_at_[hidden]
Date: 2007-08-03 16:06:44


Author: jakevoytko
Date: 2007-08-03 16:06:40 EDT (Fri, 03 Aug 2007)
New Revision: 38426
URL: http://svn.boost.org/trac/boost/changeset/38426

Log:
Started adding clipping to document
Text files modified:
   sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp | 68 +++++++++++++++++++++++++--------------
   sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp | 15 +++++--
   2 files changed, 53 insertions(+), 30 deletions(-)

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/detail/svg_tag.hpp 2007-08-03 16:06:40 EDT (Fri, 03 Aug 2007)
@@ -46,6 +46,8 @@
 protected:
     svg_style style_info;
     std::string id_name;
+ std::string class_name;
+ std::string clip_name;
 
 public:
     virtual void write(std::ostream& rhs) = 0;
@@ -55,11 +57,35 @@
 
     }
 
+ void write_elements(std::ostream& rhs)
+ {
+ if(id_name.size())
+ {
+ rhs << " id=\"" << id_name << "\"";
+ }
+
+ if(class_name.size())
+ {
+ rhs << " class=\"" << class_name << "\"";
+ }
+
+ if(clip_name.size())
+ {
+ rhs << " clip-path=\"" << id_name << "\" ";
+ }
+ }
+
    svg_style& style(){ return style_info; }
    const svg_style& style() const{ return style_info; }
 
    void id(const std::string& _id) { id_name = _id; }
- std::string id( ) { return std::string(id_name); }
+ std::string id( ) { return id_name; }
+
+ void clip(const std::string& _name){ clip_name = _name; }
+ std::string clip( ) { return clip_name; }
+
+ void xml_class(const std::string& _class) { class_name = _class; }
+ std::string xml_class() { return class_name; }
 };
 
 // -----------------------------------------------------------------
@@ -80,7 +106,9 @@
 
     void write(std::ostream& rhs)
     {
- rhs<<"<rect x=\""<<x<<"\""
+ rhs<<"<rect";
+ write_elements(rhs);
+ rhs<<"x=\""<<x<<"\""
                     <<" y=\""<<y<<"\" "
                     <<" width=\""<<width<<"\" "
                     <<" height=\""<<height<<"\"/>"
@@ -105,7 +133,9 @@
 
     void write(std::ostream& rhs)
     {
- rhs<<"<circle cx=\""
+ rhs<<"<circle";
+ write_elements(rhs);
+ rhs<<"cx=\""
            <<x<<"\" cy=\""
            <<y<<"\" r=\""
            <<radius<<"\"/>";
@@ -130,7 +160,9 @@
 
     void write(std::ostream& rhs)
     {
- rhs<<"<line x1=\""<<x1<<"\" y1=\""<<y1<<"\" x2=\""<<x2<<"\" y2=\""
+ rhs<<"<line ";
+ write_elements(rhs);
+ rhs<<"x1=\""<<x1<<"\" y1=\""<<y1<<"\" x2=\""<<x2<<"\" y2=\""
             <<y2<<"\"/>";
     }
 };
@@ -199,7 +231,9 @@
             break;
         }
 
- rhs << "<text x=\"" << x_coord << "\""
+ rhs << "<text ";
+ write_elements(rhs);
+ rhs<<"x=\"" << x_coord << "\""
             <<" y=\"" << y_coord << "\" ";
         
         if(output != "")
@@ -613,7 +647,9 @@
 
     void write(std::ostream& o_str)
     {
- o_str<<"<path d=\"";
+ o_str<<"<path ";
+ write_elements(o_str);
+ o_str<<"d=\"";
            
         for(ptr_vector<path_point>::iterator i = path.begin();
             i!=path.end();
@@ -642,17 +678,9 @@
 {
 private:
     ptr_vector<svg_element> children;
- std::string clip_name;
-
- bool clip_on;
     
 public:
 
- g_element():clip_on(false)
- {
-
- }
-
     svg_element& operator[](unsigned int i)
     {
         return children[i];
@@ -667,6 +695,7 @@
     {
         rhs << "<g ";
 
+ write_elements(rhs);
         style_info.write(rhs);
 
         rhs<< " >" << std::endl;
@@ -703,17 +732,6 @@
         children.clear();
     }
 
- void use_clip(bool _use)
- {
- clip_on = _use;
- }
-
- void clip(const std::string& _name)
- {
- clip_on = true;
- clip_name = _name;
- }
-
     g_element& circle(double x, double y, double radius = 5.)
     {
         children.push_back(new circle_element(x, y, radius));

Modified: sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp
==============================================================================
--- sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp (original)
+++ sandbox/SOC/2007/visualization/boost/svg_plot/svg.hpp 2007-08-03 16:06:40 EDT (Fri, 03 Aug 2007)
@@ -13,6 +13,7 @@
 #include <ostream>
 #include <fstream>
 #include <exception>
+#include <vector>
 
 #include "detail/svg_tag.hpp"
 #include "svg_style.hpp"
@@ -28,6 +29,8 @@
     
     g_element document;
 
+ std::vector<clip_path_element> clip_paths;
+
 private:
 
     // -----------------------------------------------------------------
@@ -35,15 +38,17 @@
     // -----------------------------------------------------------------
     void _write_document(std::ostream& s_out)
     {
- //Write color information
-
- //Write all visual elements
+ //Write clip paths
+ for(size_t i=0; i<clip_paths.size(); ++i)
+ {
+ clip_paths[ (unsigned int)i ].write(s_out);
+ }
+
+ //Write all visual elements
         for(size_t i=0; i<document.size(); ++i)
         {
             document[ (unsigned int)i ].write(s_out);
         }
-
- //end g tag
     }
 
     // -----------------------------------------------------------------


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk