]> git.tdb.fi Git - r2c2.git/blobdiff - source/designer/selectionwrap.cpp
Allow objects to override the shape specified in their type
[r2c2.git] / source / designer / selectionwrap.cpp
index fcc4df6b2a7fc561915a22e008782be322773b27..79268743b20de383d176fd46c63ac5549a03b38b 100644 (file)
@@ -18,6 +18,8 @@ SelectionWrap::~SelectionWrap()
 {
        for(map<const ObjectType *, GL::Mesh *>::iterator i=meshes.begin(); i!=meshes.end(); ++i)
                delete i->second;
+       for(map<const Object *, GL::Mesh *>::iterator i=transient_meshes.begin(); i!=transient_meshes.end(); ++i)
+               delete i->second;
 }
 
 void SelectionWrap::render(GL::Renderer &renderer, const GL::Tag &) const
@@ -40,13 +42,30 @@ void SelectionWrap::selection_changed()
        {
                Wrap wrap;
                wrap.object = *i;
-               wrap.mesh = &get_mesh((*i)->get_type());
+               wrap.mesh = &get_mesh(**i);
                wraps.push_back(wrap);
        }
+
+       set<const Object *> cobjects(objects.begin(), objects.end());
+       for(map<const Object *, GL::Mesh *>::iterator i=transient_meshes.begin(); i!=transient_meshes.end(); )
+       {
+               if(!cobjects.count(i->first))
+               {
+                       delete i->second;
+                       transient_meshes.erase(i++);
+               }
+               else
+                       ++i;
+       }
 }
 
-GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type)
+const GL::Mesh &SelectionWrap::get_mesh(const Object &obj)
 {
+       map<const Object *, GL::Mesh *>::iterator i = transient_meshes.find(&obj);
+       if(i!=transient_meshes.end())
+               return *i->second;
+
+       const ObjectType &type = obj.get_type();
        map<const ObjectType *, GL::Mesh *>::iterator j = meshes.find(&type);
        if(j!=meshes.end())
                return *j->second;
@@ -55,7 +74,7 @@ GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type)
        GL::MeshBuilder bld(*mesh);
        bld.color(0.0f, 1.0f, 0.0f, 1.0f);
 
-       const Shape *shape = type.get_shape();
+       const Shape *shape = obj.get_shape();
        if(!shape)
                throw logic_error("No shape");
        
@@ -70,7 +89,10 @@ GL::Mesh &SelectionWrap::get_mesh(const ObjectType &type)
        bld.vertex(min_pt.x-0.005, max_pt.y+0.005);
        bld.end();
 
-       meshes[&type] = mesh;
+       if(shape!=type.get_shape())
+               transient_meshes[&obj] = mesh;
+       else
+               meshes[&type] = mesh;
 
        return *mesh;
 }