Commit 1c16e08e authored by David Thompson's avatar David Thompson
Browse files

Avoid "friending" every operator.

Sessions should not have to make every operator a friend.
This adds methods to the base polygon Operator class to
provide access to the Session's storage.
parent 0600dcc8
......@@ -22,6 +22,16 @@ Session* Operator::polygonSession()
return dynamic_cast<smtk::bridge::polygon::Session*>(this->session());
}
void Operator::addStorage(const smtk::common::UUID& uid, smtk::bridge::polygon::internal::entity::Ptr storage)
{
this->polygonSession()->addStorage(uid, storage);
}
bool Operator::removeStorage(const smtk::common::UUID& uid)
{
return this->polygonSession()->removeStorage(uid);
}
/*
/// A helper to return the polygon entity associated with \a smtkEntity.
internal::Entity* Operator::polygonEntity(const smtk::model::EntityRef& smtkEntity)
......
......@@ -10,7 +10,7 @@
#ifndef __smtk_session_polygon_Operator_h
#define __smtk_session_polygon_Operator_h
#include "smtk/bridge/polygon/Exports.h"
#include "smtk/bridge/polygon/Session.h"
#include "smtk/model/Operator.h"
#include "smtk/model/Manager.h"
......@@ -31,6 +31,17 @@ class SMTKPOLYGONSESSION_EXPORT Operator : public smtk::model::Operator
{
protected:
Session* polygonSession();
void addStorage(const smtk::common::UUID& uid, smtk::bridge::polygon::internal::entity::Ptr storage);
bool removeStorage(const smtk::common::UUID& uid);
template<typename T>
typename T::Ptr findStorage(const smtk::common::UUID& uid)
{ return this->polygonSession()->findStorage<T>(uid); }
template<typename T>
T findOrAddStorage(const smtk::common::UUID& uid)
{ return this->polygonSession()->findOrAddStorage<T>(uid); }
int nextModelNumber()
{ return this->polygonSession()->m_nextModelNumber++; }
/*
internal::Entity* polygonEntity(const smtk::model::EntityRef& smtkEntity);
......
......@@ -53,11 +53,6 @@ public:
protected:
friend class Operator;
friend class CreateModel;
friend class CreateVertices;
friend class CreateEdge;
friend class SplitEdge;
friend class CreateFaces;
friend class internal::pmodel;
Session();
......
......@@ -89,7 +89,7 @@ smtk::model::OperatorResult CreateEdge::operateInternal()
}
internal::pmodel::Ptr storage =
sess->findStorage<internal::pmodel>(
this->findStorage<internal::pmodel>(
parentModel.entity());
bool ok = true;
int numEdges = offsetsItem->numberOfValues();
......@@ -160,7 +160,7 @@ smtk::model::OperatorResult CreateEdge::operateInternal()
for (; edgeOffset < edgeEnd; ++edgeOffset, prev = curr)
{
internal::vertex::Ptr vert =
sess->findStorage<internal::vertex>(modelItem->value(edgeOffset).entity());
this->findStorage<internal::vertex>(modelItem->value(edgeOffset).entity());
if (!vert)
{
ok = false;
......
......@@ -94,7 +94,7 @@ smtk::model::OperatorResult CreateModel::operateInternal()
else
{
std::ostringstream ss;
ss << "model " << sess->m_nextModelNumber++;
ss << "model " << this->nextModelNumber();
modelName = ss.str();
}
......@@ -102,7 +102,7 @@ smtk::model::OperatorResult CreateModel::operateInternal()
smtk::model::Model model = mgr->addModel(/* par. dim. */ 2, /* emb. dim. */ 3, modelName);
storage->setId(model.entity());
storage->setSession(sess);
sess->addStorage(model.entity(), storage);
this->addStorage(model.entity(), storage);
result = this->createResult(smtk::model::OPERATION_SUCCEEDED);
this->addEntityToResult(result, model, CREATED);
model.setFloatProperty("x axis", smtk::model::FloatList(storage->xAxis(), storage->xAxis() + 3));
......
......@@ -47,7 +47,7 @@ smtk::model::OperatorResult CreateVertices::operateInternal()
smtk::model::Manager::Ptr mgr = sess->manager();
smtk::model::Model model = modelItem->value(0);
internal::pmodel::Ptr storage =
sess->findStorage<internal::pmodel>(
this->findStorage<internal::pmodel>(
model.entity());
std::vector<double> pcoords(pointsItem->begin(), pointsItem->end());
smtk::model::Vertices verts =
......
......@@ -49,7 +49,7 @@ smtk::model::OperatorResult SplitEdge::operateInternal()
}
internal::edge::Ptr storage =
sess->findStorage<internal::edge>(
this->findStorage<internal::edge>(
edgeToSplit.entity());
internal::pmodel* mod = storage->parentAs<internal::pmodel>();
if (!storage || !mod)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment