Made object names accessible from within style modules.

ViewShape objects in the view map, as well as SShape objects
that can be retrieved with ViewShape::sshape(), now have a
getName() method that returns the name of the object from
which each shape is created.  For instance, visible feature
edges of specific mesh objects (e.g., Cube.001 and Cube.002)
can be selected using custom predicate ObjectNamesUP1D as
follows:

class ObjectNamesUP1D(UnaryPredicate1D):
    def __init__(self, names):
        UnaryPredicate1D.__init__(self)
        self._names = names
    def getName(self):
        return "ObjectNamesUP1D"
    def __call__(self, viewEdge):
        return viewEdge.viewShape().getName() in self._names

upred = AndUP1D(QuantitativeInvisibilityUP1D(0),
                ObjectNamesUP1D(["Cube.001", "Cube.002"]))
Operators.select(upred)
This commit is contained in:
2010-05-23 17:11:44 +00:00
parent 2212564f18
commit 96e79172a0
10 changed files with 75 additions and 8 deletions

View File

@@ -411,6 +411,7 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
0);
// sets the id of the rep
rep->setId(Id(id, 0));
rep->setName(obi->ob->id.name+2);
const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]),
Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2]));

View File

@@ -229,6 +229,37 @@ static PyObject * SShape_setId( BPy_SShape *self , PyObject *args) {
Py_RETURN_NONE;
}
static char SShape_getName___doc__[] =
".. method:: getName()\n"
"\n"
" Returns the name of the SShape.\n"
"\n"
" :return: The name string.\n"
" :rtype: str\n";
static PyObject * SShape_getName( BPy_SShape *self ) {
return PyUnicode_FromString( self->ss->getName().c_str() );
}
static char SShape_setName___doc__[] =
".. method:: setName(name)\n"
"\n"
" Sets the name of the SShape.\n"
"\n"
" :arg name: A name string.\n"
" :type name: str\n";
static PyObject * SShape_setName( BPy_SShape *self , PyObject *args) {
char *s;
if(!( PyArg_ParseTuple(args, "s", &s) ))
return NULL;
self->ss->setName(s);
Py_RETURN_NONE;
}
// const Material & material (unsigned i) const
// const vector< Material > & materials () const
// void SetMaterials (const vector< Material > &iMaterials)
@@ -244,6 +275,8 @@ static PyMethodDef BPy_SShape_methods[] = {
{"getEdgeList", ( PyCFunction ) SShape_getEdgeList, METH_NOARGS, SShape_getEdgeList___doc__},
{"getId", ( PyCFunction ) SShape_getId, METH_NOARGS, SShape_getId___doc__},
{"setId", ( PyCFunction ) SShape_setId, METH_VARARGS, SShape_setId___doc__},
{"getName", ( PyCFunction ) SShape_getName, METH_NOARGS, SShape_getName___doc__},
{"setName", ( PyCFunction ) SShape_setName, METH_VARARGS, SShape_setName___doc__},
{NULL, NULL, 0, NULL}
};

View File

@@ -153,6 +153,18 @@ static PyObject * ViewShape_getId( BPy_ViewShape *self ) {
return BPy_Id_from_Id( id );
}
static char ViewShape_getName___doc__[] =
".. method:: getName()\n"
"\n"
" Returns the name of the ViewShape.\n"
"\n"
" :return: The name string.\n"
" :rtype: str\n";
static PyObject * ViewShape_getName( BPy_ViewShape *self ) {
return PyUnicode_FromString( self->vs->getName().c_str() );
}
static char ViewShape_setSShape___doc__[] =
".. method:: setSShape(iSShape)\n"
"\n"
@@ -282,6 +294,7 @@ static PyMethodDef BPy_ViewShape_methods[] = {
{"vertices", ( PyCFunction ) ViewShape_vertices, METH_NOARGS, ViewShape_vertices___doc__},
{"edges", ( PyCFunction ) ViewShape_edges, METH_NOARGS, ViewShape_edges___doc__},
{"getId", ( PyCFunction ) ViewShape_getId, METH_NOARGS, ViewShape_getId___doc__},
{"getName", ( PyCFunction ) ViewShape_getName, METH_NOARGS, ViewShape_getName___doc__},
{"setSShape", ( PyCFunction ) ViewShape_setSShape, METH_VARARGS, ViewShape_setSShape___doc__},
{"setVertices", ( PyCFunction ) ViewShape_setVertices, METH_VARARGS, ViewShape_setVertices___doc__},
{"setEdges", ( PyCFunction ) ViewShape_setEdges, METH_VARARGS, ViewShape_setEdges___doc__},

View File

@@ -50,6 +50,7 @@ public:
: BaseObject()
{
_Id = iBrother._Id;
_Name = iBrother._Name;
if(0 == iBrother._FrsMaterial)
_FrsMaterial = 0;
else
@@ -60,11 +61,13 @@ public:
inline void swap(Rep& ioOther){
std::swap(_BBox,ioOther._BBox);
std::swap(_Id, ioOther._Id);
std::swap(_Name, ioOther._Name);
std::swap(_FrsMaterial,ioOther._FrsMaterial);
}
Rep& operator=(const Rep& iBrother){
if(&iBrother != this){
_Id = iBrother._Id;
_Name = iBrother._Name;
if(0 == iBrother._FrsMaterial)
_FrsMaterial = 0;
else{
@@ -108,11 +111,13 @@ public:
/*! Returns the rep bounding box */
virtual const BBox<Vec3r>& bbox() const {return _BBox;}
inline Id getId() const {return _Id;}
inline const string& getName() const {return _Name;}
inline const FrsMaterial * frs_material() const {return _FrsMaterial;}
/*! Sets the Rep bounding box */
virtual void setBBox(const BBox<Vec3r>& iBox) {_BBox = iBox;}
inline void setId(const Id& id) {_Id = id;}
inline void setName(const string& name) {_Name = name;}
inline void setFrsMaterial(const FrsMaterial& iMaterial)
{
_FrsMaterial = new FrsMaterial(iMaterial);
@@ -121,6 +126,7 @@ public:
private:
BBox<Vec3r> _BBox;
Id _Id;
string _Name;
FrsMaterial *_FrsMaterial;
};

View File

@@ -936,6 +936,7 @@ private:
vector<SVertex*> _verticesList; // list of all vertices
vector<FEdge*> _edgesList; // list of all edges
Id _Id;
string _Name;
BBox<Vec3r> _BBox;
vector<FrsMaterial> _FrsMaterials;
@@ -961,6 +962,7 @@ public:
{
userdata = 0;
_Id = iBrother._Id;
_Name = iBrother._Name;
_BBox = iBrother.bbox();
_FrsMaterials = iBrother._FrsMaterials;
@@ -1416,10 +1418,14 @@ public:
inline float importance() const {return _importance;}
/*! Returns the Id of the Shape. */
inline Id getId() const { return _Id; }
/*! Returns the name of the Shape. */
inline const string& getName() const { return _Name; }
/* Modififers */
/*! Sets the Id of the shape.*/
inline void setId(Id id) {_Id = id;}
/*! Sets the name of the shape.*/
inline void setName(const string& name) {_Name = name;}
/*! Sets the list of materials for the shape */
inline void setFrsMaterials(const vector<FrsMaterial>& iMaterials) {_FrsMaterials = iMaterials;}
inline void setViewShape(ViewShape *iShape) {_ViewShape = iShape;}

View File

@@ -1252,6 +1252,8 @@ public:
inline vector<ViewEdge*>& edges() {return _Edges;}
/*! Returns the ViewShape id. */
inline Id getId() const {return _SShape->getId();}
/*! Returns the ViewShape id. */
inline const string& getName() const {return _SShape->getName();}
/* modifiers */
/*! Sets the SShape on top of which the ViewShape is built. */

View File

@@ -56,6 +56,7 @@ void ViewMapBuilder::computeInitialViewEdges(WingedEdge& we)
// create the embedding
psShape = new SShape;
psShape->setId((*it)->GetId());
psShape->setName((*it)->getName());
psShape->setFrsMaterials((*it)->frs_materials()); // FIXME
// create the view shape

View File

@@ -475,6 +475,7 @@ WShape * WShape::duplicate()
WShape::WShape(WShape& iBrother)
{
_Id = iBrother.GetId();
_Name = iBrother._Name;
_FrsMaterials = iBrother._FrsMaterials;
_meanEdgeSize = iBrother._meanEdgeSize;
iBrother.bbox(_min, _max);

View File

@@ -156,10 +156,10 @@ public:
increment();
return *this;
}
virtual incoming_edge_iterator operator++(int) // op<EFBFBD>rateur correspondant <20> i++
{ // c.a.d qui renvoie la valeur *puis* incr<63>mente.
incoming_edge_iterator tmp = *this; // C'est pour cela qu'on stocke la valeur
increment(); // dans un temporaire.
virtual incoming_edge_iterator operator++(int) // operator corresponding to i++
{
incoming_edge_iterator tmp = *this;
increment();
return tmp;
}
@@ -231,10 +231,10 @@ public:
increment();
return *this;
}
virtual face_iterator operator++(int) // op<EFBFBD>rateur correspondant <20> i++
{ // c.a.d qui renvoie la valeur *puis* incr<63>mente.
face_iterator tmp = *this; // C'est pour cela qu'on stocke la valeur
increment(); // dans un temporaire.
virtual face_iterator operator++(int) // operator corresponding to i++
{
face_iterator tmp = *this;
increment();
return tmp;
}
@@ -699,6 +699,7 @@ protected:
vector<WEdge*> _EdgeList;
vector<WFace*> _FaceList;
int _Id;
string _Name;
static unsigned _SceneCurrentId;
Vec3r _min;
Vec3r _max;
@@ -752,6 +753,7 @@ public:
inline const FrsMaterial& frs_material(unsigned i) const {return _FrsMaterials[i];}
inline const vector<FrsMaterial>& frs_materials() const {return _FrsMaterials;}
inline const real getMeanEdgeSize() const {return _meanEdgeSize;}
inline const string& getName() const {return _Name;}
/*! modifiers */
static inline void setCurrentId(const unsigned id) { _SceneCurrentId = id; }
inline void setEdgeList(const vector<WEdge*>& iEdgeList) {_EdgeList = iEdgeList;}
@@ -761,6 +763,7 @@ public:
inline void setBBox(const Vec3r& min, const Vec3r& max) {_min = min; _max=max;}
inline void setFrsMaterial(const FrsMaterial& frs_material, unsigned i) {_FrsMaterials[i]=frs_material;}
inline void setFrsMaterials(const vector<FrsMaterial>& iMaterials) {_FrsMaterials = iMaterials;}
inline void setName(const string& name) {_Name = name;}
/*! designed to build a specialized WFace
* for use in MakeFace

View File

@@ -26,6 +26,7 @@ void WXEdgeBuilder::visitIndexedFaceSet(IndexedFaceSet& ifs)
WXShape *shape = new WXShape;
buildWShape(*shape, ifs);
shape->setId(ifs.getId().getFirst());
shape->setName(ifs.getName());
//ifs.setId(shape->GetId());
}