Author: eudoxos
Date: 2008-09-26 11:42:13 +0200 (Fri, 26 Sep 2008)
New Revision: 1529
Modified:
trunk/core/DefaultContainerImplementations/BodyRedirectionVector.cpp
trunk/gui/py/yadeControl.cpp
trunk/pkg/common/Container/BodyAssocVector.cpp
Log:
1. Avoid compiler warning in optimized builds from pyOmega
2. Body containers now allocate the lowest possible ID for each added body. The
old behavior was to allocate the first free ID greater than the ID of the body,
if it was already set. Please let me know if this is critical for someone. We
can do things like:
# remove all bodies except spheres (changes IDs)
o.bodies.replace([b for o.bodies if b.shape.name=='Sphere'])
Modified: trunk/core/DefaultContainerImplementations/BodyRedirectionVector.cpp
===================================================================
--- trunk/core/DefaultContainerImplementations/BodyRedirectionVector.cpp
2008-09-26 08:02:12 UTC (rev 1528)
+++ trunk/core/DefaultContainerImplementations/BodyRedirectionVector.cpp
2008-09-26 09:42:13 UTC (rev 1529)
@@ -89,8 +89,8 @@
if( used )
{
- unsigned int newPosition = position;
- // finds the first free key, which is bigger than id.
+ // finds the first free key (was: which is bigger than id...
why bigger??)
+ unsigned int newPosition = 0; // was: newPosition=position;
bool newUsed = true;
while( newUsed )
{
Modified: trunk/gui/py/yadeControl.cpp
===================================================================
--- trunk/gui/py/yadeControl.cpp 2008-09-26 08:02:12 UTC (rev 1528)
+++ trunk/gui/py/yadeControl.cpp 2008-09-26 09:42:13 UTC (rev 1529)
@@ -284,6 +284,7 @@
}
body_id_t insert(pyBody b){return proxee->insert(b.proxee);}
python::list insertList(python::list bb){python::list ret; for(int i=0;
i<len(bb); i++){ret.append(insert(python::extract<pyBody>(bb[i])()));} return
ret;}
+ python::list replace(python::list bb){proxee->clear(); return
insertList(bb);}
long length(){return proxee->size();}
void clear(){proxee->clear();}
};
@@ -407,8 +408,7 @@
void run(long int numIter=-1,bool doWait=false){
if(numIter>0)
OMEGA.getRootBody()->stopAtIteration=OMEGA.getCurrentIteration()+numIter;
OMEGA.startSimulationLoop();
- long
toGo=OMEGA.getRootBody()->stopAtIteration-OMEGA.getCurrentIteration();
- LOG_DEBUG("RUN"<<(toGo>0?string("
("+lexical_cast<string>(toGo)+" to go)"):string(""))<<"!");
+
LOG_DEBUG("RUN"<<((OMEGA.getRootBody()->stopAtIteration-OMEGA.getCurrentIteration())>0?string("
("+lexical_cast<string>(OMEGA.getRootBody()->stopAtIteration-OMEGA.getCurrentIteration())+"
to go)"):string(""))<<"!");
if(doWait) wait();
}
void pause(){Py_BEGIN_ALLOW_THREADS; OMEGA.stopSimulationLoop();
Py_END_ALLOW_THREADS; LOG_DEBUG("PAUSE!");}
@@ -545,7 +545,8 @@
.def("__len__",&pyBodyContainer::length)
.def("append",&pyBodyContainer::insert)
.def("append",&pyBodyContainer::insertList)
- .def("clear", &pyBodyContainer::clear);
+ .def("clear", &pyBodyContainer::clear)
+ .def("replace",&pyBodyContainer::replace);
boost::python::class_<pyInteractionContainer>("InteractionContainer",python::init<pyInteractionContainer&>())
.def("__iter__",&pyInteractionContainer::pyIter)
.def("__getitem__",&pyInteractionContainer::pyGetitem)
Modified: trunk/pkg/common/Container/BodyAssocVector.cpp
===================================================================
--- trunk/pkg/common/Container/BodyAssocVector.cpp 2008-09-26 08:02:12 UTC
(rev 1528)
+++ trunk/pkg/common/Container/BodyAssocVector.cpp 2008-09-26 09:42:13 UTC
(rev 1529)
@@ -86,8 +86,8 @@
tmpBii = bodies.find(position);
if( tmpBii != bodies.end() )
{
- unsigned int newPosition = position;
- // finds the first free key, which is bigger than id.
+ // finds the first free key, which is bigger than 0 (was:
newPoistion=position, i.e. greater than id... why?)
+ unsigned int newPosition = 0;
while( bodies.find(newPosition) != bodies.end() )
++newPosition;
//cerr << "WARNING: body id=\"" << position << "\" is already
used. Using first free id=\"" << newPosition << "\", beware - if you are
loading a file, this will break interactions for this body!\n";
_______________________________________________
Mailing list: https://launchpad.net/~yade-dev
Post to : [email protected]
Unsubscribe : https://launchpad.net/~yade-dev
More help : https://help.launchpad.net/ListHelp