LCOV - code coverage report
Current view: top level - geom - CASourceFeature.cpp (source / functions) Hit Total Coverage
Test: coverage_sk.info Lines: 25 77 32.5 %
Date: 2020-06-30 00:58:45 Functions: 8 12 66.7 %
Branches: 19 127 15.0 %

           Branch data     Line data    Source code
       1                 :            : #include "CASourceFeature.hpp"
       2                 :            : #include "BasicTopologyEntity.hpp"
       3                 :            : #include "Body.hpp"
       4                 :            : #include "RefEntityName.hpp"
       5                 :            : #include "CastTo.hpp"
       6                 :            : #include "CubitMessage.hpp"
       7                 :            : #include "TDSourceFeature.hpp"
       8                 :            : 
       9                 :      26892 : CubitAttrib* CASourceFeature_creator(RefEntity* entity, const CubitSimpleAttrib &p_csa)
      10                 :            : {
      11         [ +  - ]:      26892 :   return new CASourceFeature(entity, p_csa);
      12                 :            : }
      13                 :            : 
      14                 :      26892 : CASourceFeature::CASourceFeature(RefEntity* new_attrib_owner,
      15                 :            :                                  const CubitSimpleAttrib& csa_ptr)
      16                 :      26892 :                                  : CubitAttrib(new_attrib_owner)
      17                 :            : {
      18                 :      26892 :     sourceFeature = GeometryFeatureEngine::FEATURE_UNDEFINED;
      19                 :            : 
      20 [ +  - ][ -  + ]:      26892 :     if(!csa_ptr.isEmpty())
      21                 :            :     {
      22                 :            : 
      23         [ #  # ]:          0 :       const std::vector<CubitString>& cs_list = csa_ptr.string_data_list();
      24                 :            : 
      25                 :            :       // step over the attribute type
      26                 :            :       // now read name / option pairs
      27 [ #  # ][ #  # ]:          0 :       if(cs_list.size()==2)
      28                 :            :       {
      29 [ #  # ][ #  # ]:          0 :         CubitString cs = cs_list[1];
      30 [ #  # ][ #  # ]:          0 :           if (cs.length() == 0)
      31 [ #  # ][ #  # ]:          0 :               PRINT_WARNING("Empty feature attribute for %s %d.\n",
         [ #  # ][ #  # ]
                 [ #  # ]
      32                 :            :               attribOwnerEntity->class_name(),
      33         [ #  # ]:          0 :               attribOwnerEntity->id());
      34                 :            :           else
      35 [ #  # ][ #  # ]:          0 :               sourceFeature = string_to_feature_type(cs);
         [ #  # ][ #  # ]
      36                 :            :       }
      37                 :            :       else
      38                 :          0 :           deleteAttrib = CUBIT_TRUE;
      39                 :            :     }
      40                 :      26892 : }
      41                 :            : 
      42                 :      80676 : CASourceFeature::~CASourceFeature()
      43                 :            : {
      44         [ -  + ]:      53784 : }
      45                 :            : 
      46                 :          0 : CubitStatus CASourceFeature::actuate()
      47                 :            : {
      48         [ #  # ]:          0 :     if (hasActuated == CUBIT_TRUE)
      49                 :          0 :         return CUBIT_SUCCESS;
      50                 :            : 
      51                 :            :     // create a TDSourceFeature for the entity, if it doesn't already
      52                 :            :     // exist
      53                 :            :     TDSourceFeature *source_feature_data = 
      54                 :          0 :         (TDSourceFeature *) attrib_owner()->get_TD(&TDSourceFeature::is_source_feature);
      55                 :            : 
      56         [ #  # ]:          0 :     if (!source_feature_data) 
      57                 :            :     {
      58                 :            :         // else make a new one
      59         [ #  # ]:          0 :         TDSourceFeature* new_tool_data = new TDSourceFeature(sourceFeature);
      60                 :          0 :         attrib_owner()->add_TD(new_tool_data);
      61                 :            :     }
      62                 :            : 
      63                 :          0 :     delete_attrib(CUBIT_TRUE);
      64                 :          0 :     hasActuated = CUBIT_TRUE;
      65                 :            : 
      66                 :          0 :     return CUBIT_SUCCESS;
      67                 :            : }
      68                 :            : 
      69                 :      26892 : CubitStatus CASourceFeature::update()
      70                 :            : {
      71         [ -  + ]:      26892 :     if(hasUpdated)
      72                 :          0 :         return CUBIT_SUCCESS;
      73                 :            : 
      74                 :            :     // set the updated flag
      75                 :      26892 :     hasUpdated = CUBIT_TRUE;
      76                 :            : 
      77                 :            :     // if the owner has a unique id, save it, otherwise delete this one
      78                 :            :     TDSourceFeature *source_feature_data = 
      79                 :      26892 :         (TDSourceFeature *) attrib_owner()->get_TD(&TDSourceFeature::is_source_feature);
      80                 :            : 
      81         [ +  - ]:      26892 :     if (!source_feature_data)
      82                 :      26892 :         delete_attrib(CUBIT_TRUE);
      83                 :            :     else
      84                 :            :     {
      85         [ #  # ]:          0 :         if (delete_attrib() == CUBIT_TRUE)
      86                 :          0 :             delete_attrib(CUBIT_FALSE);
      87                 :            : 
      88                 :          0 :         sourceFeature = source_feature_data->source_feature();
      89                 :            :     }
      90                 :            : 
      91                 :      26892 :     return CUBIT_SUCCESS;
      92                 :            : }
      93                 :            : 
      94                 :          0 : CubitStatus CASourceFeature::reset()
      95                 :            : {
      96                 :          0 :     sourceFeature = GeometryFeatureEngine::FEATURE_UNDEFINED;
      97                 :            : 
      98                 :          0 :     hasUpdated = CUBIT_FALSE;
      99                 :          0 :     return CUBIT_SUCCESS;
     100                 :            : }
     101                 :            : 
     102                 :      26892 : CubitSimpleAttrib CASourceFeature::cubit_simple_attrib()
     103                 :            : {
     104         [ +  - ]:      26892 :     std::vector<CubitString> cs_list;
     105                 :            : 
     106                 :            :     // pack the string list:
     107                 :            :     // character type of this CA
     108 [ +  - ][ +  - ]:      26892 :     cs_list.push_back(att_internal_name());
         [ +  - ][ +  - ]
     109                 :            : 
     110                 :            :     // name, option pairs
     111 [ +  - ][ +  - ]:      26892 :     cs_list.push_back(feature_type_to_string(sourceFeature));
                 [ +  - ]
     112                 :            : 
     113 [ +  - ][ +  - ]:      26892 :     return CubitSimpleAttrib(&cs_list, NULL, NULL);
     114                 :            : }
     115                 :            : 
     116                 :            : 
     117                 :          0 : void CASourceFeature::print()
     118                 :            : {
     119                 :            :     // print info on this attribute
     120         [ #  # ]:          0 :     PRINT_INFO("CASourceFeature: owner = %s %d; feature: ",
     121         [ #  # ]:          0 :         attribOwnerEntity->class_name(), attribOwnerEntity->id());
     122 [ #  # ][ #  # ]:          0 :     PRINT_INFO("%s ", feature_type_to_string(sourceFeature).c_str());
         [ #  # ][ #  # ]
                 [ #  # ]
     123                 :            : 
     124 [ #  # ][ #  # ]:          0 :     PRINT_INFO("\n");
     125                 :          0 : }
     126                 :            : 
     127                 :            : GeometryFeatureEngine::FeatureType 
     128                 :          0 : CASourceFeature::string_to_feature_type(CubitString value_in)
     129                 :            : {
     130                 :            :     /*
     131                 :            :     FEATURE_UNDEFINED,
     132                 :            :     FEATURE_HOLE,       
     133                 :            :     FEATURE_ROUND,      
     134                 :            :     FEATURE_CHAMFER,    
     135                 :            :     FEATURE_SLOT ,      
     136                 :            :     FEATURE_CUT,
     137                 :            :     FEATURE_IMPRINT
     138                 :            :     */
     139 [ #  # ][ #  # ]:          0 :     if(value_in == "IMPRINT")
     140                 :          0 :         return GeometryFeatureEngine::FEATURE_IMPRINT;
     141 [ #  # ][ #  # ]:          0 :     else if(value_in == "HOLE")
     142                 :          0 :         return GeometryFeatureEngine::FEATURE_HOLE;
     143 [ #  # ][ #  # ]:          0 :     else if(value_in == "ROUND")
     144                 :          0 :         return GeometryFeatureEngine::FEATURE_ROUND;
     145 [ #  # ][ #  # ]:          0 :     else if(value_in == "CHAMFER")
     146                 :          0 :         return GeometryFeatureEngine::FEATURE_CHAMFER;
     147 [ #  # ][ #  # ]:          0 :     else if(value_in == "SLOT")
     148                 :          0 :         return GeometryFeatureEngine::FEATURE_SLOT;
     149 [ #  # ][ #  # ]:          0 :     else if(value_in == "CUT")
     150                 :          0 :         return GeometryFeatureEngine::FEATURE_CUT;
     151                 :            :     else
     152                 :          0 :         return GeometryFeatureEngine::FEATURE_UNDEFINED;
     153                 :            : }
     154                 :            : 
     155                 :            : // returning a cubit simple attribute string for the input feature type
     156                 :            : CubitString
     157                 :      26892 : CASourceFeature::feature_type_to_string(GeometryFeatureEngine::FeatureType type_in)
     158                 :            : {
     159   [ -  -  -  -  :      26892 :     switch(type_in)
                -  -  + ]
     160                 :            :     {
     161                 :            :     case GeometryFeatureEngine::FEATURE_IMPRINT:
     162                 :          0 :         return "IMPRINT";
     163                 :            :     case GeometryFeatureEngine::FEATURE_HOLE:
     164                 :          0 :         return "HOLE";
     165                 :            :     case GeometryFeatureEngine::FEATURE_ROUND:
     166                 :          0 :         return "ROUND";
     167                 :            :     case GeometryFeatureEngine::FEATURE_CHAMFER:
     168                 :          0 :         return "CHAMFER";
     169                 :            :     case GeometryFeatureEngine::FEATURE_SLOT:
     170                 :          0 :         return "SLOT";
     171                 :            :     case GeometryFeatureEngine::FEATURE_CUT:
     172                 :          0 :         return "CUT";
     173                 :            :     default:
     174                 :      26892 :         return "";
     175                 :            :     }
     176 [ +  - ][ +  - ]:       6540 : }

Generated by: LCOV version 1.11