Changeset 999 for cpp/frams/model


Ignore:
Timestamp:
07/13/20 13:51:43 (4 years ago)
Author:
Maciej Komosinski
Message:

More consistent usage of "shapetype" (vs. "shape")

Location:
cpp/frams/model
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/geometry/modelgeoclass.cpp

    r661 r999  
    7474        if (m != NULL)
    7575        {
    76                 if (m->getShapeType() == Model::SHAPE_BALL_AND_STICK)
     76                if (m->getShapeType() == Model::SHAPETYPE_BALL_AND_STICK)
    7777                        {
    7878                        Model *converted = new Model;
  • cpp/frams/model/model.cpp

    r988 r999  
    1717}
    1818
    19 void Model::init(ShapeType sh)
     19void Model::init(ShapeType shtype)
    2020{
    2121        partmappingchanged = 0;
     
    2929        f0map = 0;
    3030        f0genoknown = 1;
    31         shape = SHAPE_UNKNOWN;
    32         declared_shape = sh;
    33 }
    34 
    35 void Model::declareShapeType(ShapeType sh)
    36 {
    37         declared_shape = sh;
     31        shapetype = SHAPETYPE_UNKNOWN;
     32        declared_shapetype = shtype;
     33}
     34
     35void Model::declareShapeType(ShapeType shtype)
     36{
     37        declared_shapetype = shtype;
    3838}
    3939
     
    5656        geno = mod.geno;
    5757        f0genoknown = 0;
    58         shape = mod.shape;
    59         declared_shape = mod.declared_shape;
     58        shapetype = mod.shapetype;
     59        declared_shapetype = mod.declared_shapetype;
    6060        startenergy = mod.startenergy;
    6161        modelfromgenotype = mod.modelfromgenotype;
     
    117117        :autobuildmaps(buildmaps)
    118118{
    119         init(mod.declared_shape);
     119        init(mod.declared_shapetype);
    120120        open(_using_checkpoints, _is_checkpoint);
    121121        internalCopy(mod);
     
    169169        delMap();
    170170        delF0Map();
    171         init(declared_shape);
     171        init(declared_shapetype);
    172172        geno = Geno();
    173173        f0geno = Geno();
     
    340340        f0warnposition = -1;
    341341        MultiMap *convmap = autobuildmaps ? new MultiMap() : NULL;
    342         if (declared_shape == SHAPE_UNKNOWN)
     342        if (declared_shapetype == SHAPETYPE_UNKNOWN)
    343343                f0geno = geno.getConverted(Geno::F0_FORMAT_LIST, convmap, using_checkpoints);
    344344        else
    345                 f0geno = geno.getConverted(genoFormatForShapeType(declared_shape), convmap, using_checkpoints);
     345                f0geno = geno.getConverted(genoFormatForShapeType(declared_shapetype), convmap, using_checkpoints);
    346346        f0genoknown = 1;
    347347        if (f0geno.isInvalid())
     
    351351                return;
    352352        }
    353         if (declared_shape == SHAPE_UNKNOWN)
     353        if (declared_shapetype == SHAPETYPE_UNKNOWN)
    354354                declareShapeType(shapeTypeForGenoFormat(f0geno.getFormat()));
    355355        SString f0txt = f0geno.getGenes();
     
    560560        switch (st)
    561561        {
    562         case SHAPE_BALL_AND_STICK:
     562        case SHAPETYPE_BALL_AND_STICK:
    563563                return "0";
    564         case SHAPE_SOLIDS:
     564        case SHAPETYPE_SOLIDS:
    565565                return "0s";
    566566        default:
     
    572572{
    573573        if (format == "0")
    574                 return SHAPE_BALL_AND_STICK;
     574                return SHAPETYPE_BALL_AND_STICK;
    575575        else if (format == "0s")
    576                 return SHAPE_SOLIDS;
     576                return SHAPETYPE_SOLIDS;
    577577        else
    578                 return SHAPE_UNKNOWN;
     578                return SHAPETYPE_UNKNOWN;
    579579
    580580}
     
    584584        switch (sh)
    585585        {
    586         case SHAPE_BALL_AND_STICK: return "ball-and-stick";
    587         case SHAPE_SOLIDS: return "solid shapes";
    588         case SHAPE_UNKNOWN: return "unknown";
    589 
    590         case SHAPE_ILLEGAL:
     586        case SHAPETYPE_BALL_AND_STICK: return "ball-and-stick";
     587        case SHAPETYPE_SOLIDS: return "solid shapes";
     588        case SHAPETYPE_UNKNOWN: return "unknown";
     589
     590        case SHAPETYPE_ILLEGAL:
    591591        default:
    592592                return "illegal";
     
    894894        int i, k;
    895895        int ret = 1;
    896         shape = SHAPE_UNKNOWN;
     896        shapetype = SHAPETYPE_UNKNOWN;
    897897        updateRefno();
    898898        if ((parts.size() == 0) && (neurons.size() == 0)) return 0;
     
    931931                        if (p->p.y + p->size > bbmax.y) bbmax.y = p->p.y + p->size;
    932932                        if (p->p.z + p->size > bbmax.z) bbmax.z = p->p.z + p->size;
    933                         if (shape == SHAPE_UNKNOWN)
    934                                 shape = (p->shape == Part::SHAPE_BALL_AND_STICK) ? SHAPE_BALL_AND_STICK : SHAPE_SOLIDS;
    935                         else if (shape != SHAPE_ILLEGAL)
     933                        if (shapetype == SHAPETYPE_UNKNOWN)
     934                                shapetype = (p->shape == Part::SHAPE_BALL) ? SHAPETYPE_BALL_AND_STICK : SHAPETYPE_SOLIDS;
     935                        else if (shapetype != SHAPETYPE_ILLEGAL)
    936936                        {
    937                                 if ((p->shape == Part::SHAPE_BALL_AND_STICK) ^ (shape == SHAPE_BALL_AND_STICK))
     937                                if ((p->shape == Part::SHAPE_BALL) ^ (shapetype == SHAPETYPE_BALL_AND_STICK))
    938938                                {
    939                                         shape = SHAPE_ILLEGAL;
     939                                        shapetype = SHAPETYPE_ILLEGAL;
    940940                                        logPrintf("Model", "internalCheck", LOG_WARN, "Inconsistent part shapes (mixed ball-and-stick and solids shape types)%s", nameForErrors().c_str());
    941941                                }
     
    10021002                                if ((check != LIVE_CHECK) && (check != CHECKPOINT_CHECK))
    10031003                                {
    1004                                         if (j->shape == Joint::SHAPE_BALL_AND_STICK)
     1004                                        if (j->shape == Joint::SHAPE_STICK)
    10051005                                        {
    10061006                                                if (j->d() > getMaxJoint().d.x)
     
    10171017                                ret = 0;
    10181018                        }
    1019                         if (shape != SHAPE_ILLEGAL)
     1019                        if (shapetype != SHAPETYPE_ILLEGAL)
    10201020                        {
    1021                                 if ((j->shape == Joint::SHAPE_BALL_AND_STICK) ^ (shape == SHAPE_BALL_AND_STICK))
     1021                                if ((j->shape == Joint::SHAPE_STICK) ^ (shapetype == SHAPETYPE_BALL_AND_STICK))
    10221022                                {
    1023                                         shape = SHAPE_ILLEGAL;
     1023                                        shapetype = SHAPETYPE_ILLEGAL;
    10241024                                        logPrintf("Model", "internalCheck", LOG_WARN, "Inconsistent joint shapes (mixed old and new shapes)%s", nameForErrors().c_str());
    10251025                                }
     
    11091109        }
    11101110
    1111         if (shape == SHAPE_ILLEGAL)
     1111        if (shapetype == SHAPETYPE_ILLEGAL)
    11121112                ret = 0;
    1113         else if ((declared_shape != SHAPE_UNKNOWN) && (declared_shape != shape))
    1114         {
    1115                 logPrintf("Model", "internalCheck", LOG_ERROR, "Model shape type '%s' does not match the declared type '%s'", getShapeTypeName(shape), getShapeTypeName(declared_shape));
     1113        else if ((declared_shapetype != SHAPETYPE_UNKNOWN) && (declared_shapetype != shapetype))
     1114        {
     1115                logPrintf("Model", "internalCheck", LOG_ERROR, "Model shape type '%s' does not match the declared type '%s'", getShapeTypeName(shapetype), getShapeTypeName(declared_shapetype));
    11161116                ret = 0;
    11171117        }
     
    13351335{
    13361336        using_model = converted_model = NULL;
    1337         if (m.getShapeType() == Model::SHAPE_BALL_AND_STICK)
     1337        if (m.getShapeType() == Model::SHAPETYPE_BALL_AND_STICK)
    13381338        {
    13391339                converted_model = new Model;
  • cpp/frams/model/model.h

    r972 r999  
    101101        };
    102102protected:
    103         ShapeType shape;
    104         ShapeType declared_shape;
     103        ShapeType shapetype;
     104        ShapeType declared_shapetype;
    105105
    106106        SString nameForErrors() const;
     
    134134        int isValid() const { return buildstatus == valid; }
    135135        int getErrorPosition(bool includingwarnings = false);
    136         ShapeType getShapeType() const { return shape; }
     136        ShapeType getShapeType() const { return shapetype; }
    137137        bool isUsingCheckpoints() const { return using_checkpoints; }
    138138        bool isCheckpoint() const { return is_checkpoint; }
     
    155155
    156156        /// Create empty model with invalid empty genotype, declaring the shape type for later operations
    157         Model(ShapeType sh = SHAPE_UNKNOWN);
     157        Model(ShapeType sh = SHAPETYPE_UNKNOWN);
    158158
    159159        /// Change the declared shape type of the Model
     
    333333
    334334        /** create new Part and add it to the model. @see addPart()  */
    335         Part *addNewPart(Part::Shape shape = Part::SHAPE_BALL_AND_STICK) { return addPart(new Part(shape)); }
     335        Part *addNewPart(Part::Shape shape = Part::SHAPE_BALL) { return addPart(new Part(shape)); }
    336336        /** create new Joint and add it to the model. @see addJoint() */
    337         Joint *addNewJoint(Part *p1 = NULL, Part *p2 = NULL, Joint::Shape shape = Joint::SHAPE_BALL_AND_STICK) { Joint *j = addJoint(new Joint()); j->shape = shape; if ((p1 != NULL) && (p2 != NULL)) j->attachToParts(p1, p2); return j; }
     337        Joint *addNewJoint(Part *p1 = NULL, Part *p2 = NULL, Joint::Shape shape = Joint::SHAPE_STICK) { Joint *j = addJoint(new Joint()); j->shape = shape; if ((p1 != NULL) && (p2 != NULL)) j->attachToParts(p1, p2); return j; }
    338338        /** create new Neuro and add it to the model. @see addNeuro() */
    339339        Neuro *addNewNeuro() { return addNeuro(new Neuro()); }
  • cpp/frams/model/modelobj.cpp

    r972 r999  
    5858void ModelObj::p_newfromstring(ExtValue *args, ExtValue *ret)
    5959{
    60         *ret = makeDynamicObject(new Model(Geno(args[0].getString()), Model::SHAPE_UNKNOWN));
     60        *ret = makeDynamicObject(new Model(Geno(args[0].getString()), Model::SHAPETYPE_UNKNOWN));
    6161}
    6262
     
    6565        Geno *g = GenoObj::fromObject(args[0].getObject());
    6666        if (g)
    67                 *ret = makeDynamicObject(new Model(*g, Model::SHAPE_UNKNOWN));
     67                *ret = makeDynamicObject(new Model(*g, Model::SHAPETYPE_UNKNOWN));
    6868        else
    6969                ret->setEmpty();
     
    7474        Model *m = NULL;
    7575        if (args[0].getType() == TString)
    76                 m = new Model(Geno(args[0].getString()), Model::SHAPE_UNKNOWN, false, true);
     76                m = new Model(Geno(args[0].getString()), Model::SHAPETYPE_UNKNOWN, false, true);
    7777        else
    7878        {
    7979                Geno *g = GenoObj::fromObject(args[0].getObject(), false);
    8080                if (g)
    81                         m = new Model(*g, Model::SHAPE_UNKNOWN, false, true);
     81                        m = new Model(*g, Model::SHAPETYPE_UNKNOWN, false, true);
    8282                else
    8383                        logPrintf("Model", "newWithCheckpoints", LOG_ERROR, "Geno or string expected, %s found", args[0].typeDescription().c_str());
     
    178178void ModelObj::get_solid_model(ExtValue *ret)
    179179{
    180         if (getShapeType() != Model::SHAPE_BALL_AND_STICK)
     180        if (getShapeType() != Model::SHAPETYPE_BALL_AND_STICK)
    181181                ret->setEmpty();
    182182        Model *m = new Model;
  • cpp/frams/model/modelparts.cpp

    r977 r999  
    629629        switch (sh)
    630630        {
    631         case SHAPE_BALL_AND_STICK: return "ball-and-stick";
     631        case SHAPE_BALL: return "ball[-and-stick]";
    632632        case SHAPE_ELLIPSOID: return "ellipsoid";
    633633        case SHAPE_CUBOID: return "cuboid";
     
    727727        switch (sh)
    728728        {
    729         case SHAPE_BALL_AND_STICK: return "ball-and-stick";
     729        case SHAPE_STICK: return "[ball-and-]stick";
    730730        case SHAPE_FIXED: return "fixed";
    731731        case SHAPE_HINGE_X: return "hinge x";
  • cpp/frams/model/modelparts.h

    r997 r999  
    3434{
    3535public:
    36         enum ShapeType { SHAPE_BALL_AND_STICK = 0, SHAPE_SOLIDS = 1, SHAPE_UNKNOWN, SHAPE_ILLEGAL, ///< 0 and 1 have special significance - these values allow for bit operations.
    37                          SHAPE_FIRST = SHAPE_BALL_AND_STICK, SHAPE_LAST = SHAPE_SOLIDS // for iteration
    38         };
     36        enum ShapeType {
     37                SHAPETYPE_BALL_AND_STICK = 0, SHAPETYPE_SOLIDS = 1, SHAPETYPE_UNKNOWN, SHAPETYPE_ILLEGAL, ///< 0 and 1 have special significance - these values allow for bit operations.
     38                SHAPETYPE_FIRST = SHAPETYPE_BALL_AND_STICK, SHAPETYPE_LAST = SHAPETYPE_SOLIDS // for iteration
     39        };
    3940};
    4041
     
    7374};
    7475
    75 /// Part is the only real physical object in the Framsticks creature.
     76/// Part is the only real physical object in creatures in Framsticks.
    7677/// You can use this class for querying and adjusting constructed
    77 /// model properties
     78/// model properties.
    7879class Part : public PartBase
    7980{
     
    9697        ///
    9798        paInt shape;///default=old Framsticks compatible, do not mix with shapes>0
    98         enum Shape { SHAPE_BALL_AND_STICK = 0, SHAPE_ELLIPSOID = 1, SHAPE_CUBOID = 2, SHAPE_CYLINDER = 3,
    99                      SHAPE_FIRST = SHAPE_BALL_AND_STICK, SHAPE_LAST = SHAPE_CYLINDER // for iteration
     99        enum Shape {
     100                SHAPE_BALL = 0, ///<  for "ball and stick" shape type model only.
     101                SHAPE_ELLIPSOID = 1, SHAPE_CUBOID = 2, SHAPE_CYLINDER = 3,
     102                SHAPE_FIRST = SHAPE_BALL, SHAPE_LAST = SHAPE_CYLINDER // for iteration
    100103        };
    101104        static const char* getShapeName(Shape sh);
     
    110113        double vsize;
    111114
    112         Part(enum Shape s = SHAPE_BALL_AND_STICK);
     115        Part(enum Shape s = SHAPE_BALL);
    113116        Part(const Part &src) :PartBase(getDefaultStyle()) { operator=(src); }
    114117        void operator=(const Part &src);
     
    151154        class Pt3D rot; ///< orientation delta between parts expressed as 3 angles
    152155        enum Shape {
    153                 SHAPE_BALL_AND_STICK = 0, ///<  old Framsticks compatible, creates a physical rod between parts (cylinder or cuboid), do not mix with part.shape>0
     156                SHAPE_STICK = 0, ///<  for "ball and stick" shape type model, creates a physical (cylinder or cuboid) rod between parts. Do not mix with part.shape>0.
    154157                SHAPE_FIXED = 1, ///< merge parts into one physical entity
    155158                SHAPE_HINGE_X = 2, ///< hinge connection, revolving around X axis defined by hinge_pos and hinge_rot
    156159                SHAPE_HINGE_XY = 3, ///< double hinge connection, revolving around X and Y axes defined by hinge_pos and hinge_rot
    157                 SHAPE_FIRST = SHAPE_BALL_AND_STICK, SHAPE_LAST = SHAPE_HINGE_XY // for iteration
     160                SHAPE_FIRST = SHAPE_STICK, SHAPE_LAST = SHAPE_HINGE_XY // for iteration
    158161        };
    159162        paInt shape;///< values of type Shape (paInt for integration with Param)
     
    230233        paInt preflocation;
    231234
    232         enum PrefLocation { PREFER_UNATTACHED=0, PREFER_PART=1, PREFER_JOINT=2 };
    233        
    234         static constexpr int SUPPORTED_SHAPE_BALL_AND_STICK = 1;
    235         static constexpr int SUPPORTED_SHAPE_SOLIDS = 2;
    236         static constexpr int SUPPORTED_SHAPE_ALL = SUPPORTED_SHAPE_BALL_AND_STICK | SUPPORTED_SHAPE_SOLIDS;
     235        enum PrefLocation { PREFER_UNATTACHED = 0, PREFER_PART = 1, PREFER_JOINT = 2 };
     236
     237        static constexpr int SUPPORTED_SHAPETYPE_BALL_AND_STICK = 1;
     238        static constexpr int SUPPORTED_SHAPETYPE_SOLIDS = 2;
     239        static constexpr int SUPPORTED_SHAPETYPE_ALL = SUPPORTED_SHAPETYPE_BALL_AND_STICK | SUPPORTED_SHAPETYPE_SOLIDS;
    237240        paInt supported_shape_types; //< bitfield of 'Model::shape' values: NeuroClass::SUPPORTED_SHAPE_xxx = 1 << Model::SHAPE_xxx
    238241
     
    241244        static constexpr int SUPPORTED_JOINT_HINGE_X = 4;
    242245        static constexpr int SUPPORTED_JOINT_HINGE_XY = 8;
    243         static constexpr int SUPPORTED_JOINT_ALL = SUPPORTED_JOINT_BALL_AND_STICK + SUPPORTED_JOINT_FIXED + SUPPORTED_JOINT_HINGE_X + SUPPORTED_JOINT_HINGE_XY;
     246        static constexpr int SUPPORTED_JOINTSHAPE_ALL = SUPPORTED_JOINT_BALL_AND_STICK + SUPPORTED_JOINT_FIXED + SUPPORTED_JOINT_HINGE_X + SUPPORTED_JOINT_HINGE_XY;
    244247        paInt supported_joint_shapes; //< bitfield of 'Joint::shape' values: NeuroClass::SUPPORTED_JOINT_xxx = 1 << JOINT::SHAPE_xxx
    245248
     
    257260        NeuroClass();
    258261        NeuroClass(ParamEntry *_props, SString _description,
    259                    int _prefinputs, int _prefoutput, int _preflocation, int *_vectordata, bool own_vd = 1, int vhints = 0, int sup_shapes = NeuroClass::SUPPORTED_SHAPE_ALL, int sup_joints = NeuroClass::SUPPORTED_JOINT_ALL);
     262                int _prefinputs, int _prefoutput, int _preflocation, int *_vectordata, bool own_vd = 1, int vhints = 0, int sup_shapes = NeuroClass::SUPPORTED_SHAPETYPE_ALL, int sup_joints = NeuroClass::SUPPORTED_JOINTSHAPE_ALL);
    260263        /** class name for use in Neuro::setClassName(), Neuro::setDetails() (former 'moredata' field),
    261264                eg. "N","-",G" */
  • cpp/frams/model/similarity/simil_model.cpp

    r972 r999  
    534534                return NULL;
    535535        }
    536         Model *m = new Model(*g, Model::SHAPE_UNKNOWN);
     536        Model *m = new Model(*g, Model::SHAPETYPE_UNKNOWN);
    537537        if (!m->isValid())
    538538        {
Note: See TracChangeset for help on using the changeset viewer.