tsc_IEntityFilter interface

tsc_IEntityFilter is an interface class used to filter any type of entity (point, station, line, arc, polyline, etc).  It has one pure virtual function which is used to test the entity for some condition and return a true result to keep the item or a false result to remove it from the list.

virtual bool InFilter (const class tsc_Entity& entityToTest) = 0;

Subclass and implement this interface when it is necessary to filter or search a list of database entities for some specific subset.  A tsc_Entity object is passed into the InFilter function, which returns true or false based on the object.  For instance, it is possible to filter a tsc_PointList and remove points not conforming to some condition; SCAPI will pass each entity in the list to the InFilter function and remove it if false is returned.

The code below illustrates getting a list of the objects currently selected on the map, then removing all objects except for points that are not deleted and that begin with the letter "p".

class MyFilter : public tsc_IEntityFilter 

{

    char firstChar;

    

    bool InFilter(const tsc_Entity& ent) override  // Returns true for the points we want to keep.  

    {

        if (ent.IsPoint() && !((tsc_Point&)ent).IsDeleted())

        {

            tsc_String name = ent.Name().ToLower();

            return (name.Length() > 0) && (name[0] == firstChar);

        }         

        return false;

    }     

    

    tsc_PointList GetRequiredMapPoints()

    {

        tsc_Job job = tsc_Job::CurrentJob();

        tsc_PointList pl = job.Database().MapSelections();

        firstChar = 'p';          

        pl.SelectBy(this);          

        return pl;

    }

};

Of course, the InFilter function does not have to be in the same class as the SelectBy call, and if multiple different filters were required then multiple subclasses of tsc_IEntityFilter could be defined.