Changeset 975 for cpp/frams/_demos/genoconv_test.cpp
- Timestamp:
- 07/06/20 23:32:03 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/_demos/genoconv_test.cpp
r972 r975 107 107 } 108 108 109 /// Sample Geno converter producing "f0s" genotype from the textual list of shapes, eg. "/*shapes*/ball,cube,cube" 110 class GenoConv_Test4 : public GenoConverter 111 { 112 public: 113 GenoConv_Test4() 114 { 115 name = "Test Converter #4"; 116 in_format = "shapes"; 117 out_format = "0s"; 118 mapsupport = 1; 119 } 120 SString convert(SString &in, MultiMap *map, bool using_checkpoints); 121 ~GenoConv_Test4() {} 122 }; 123 124 SString GenoConv_Test4::convert(SString &in, MultiMap *map, bool using_checkpoints) 125 { 126 SString result; 127 int numparts=0; 128 int input_pos=0, prev_input_pos=0; SString word; 129 while(in.getNextToken(input_pos,word,',')) 130 { 131 Part::Shape sh; 132 if (word=="cube") 133 sh = Part::SHAPE_CUBOID; 134 else if (word=="ball") 135 sh = Part::SHAPE_ELLIPSOID; 136 else if (word=="cylinder") 137 sh = Part::SHAPE_CYLINDER; 138 else 139 return ""; 140 SString add; 141 add+=SString::sprintf("p:x=%g,sh=%d\n",numparts*2.0f,sh); 142 if (numparts>0) 143 add+=SString::sprintf("j:p1=%d,p2=%d,sh=1\n",numparts-1,numparts); 144 if (map) // fill in the map only if requested 145 map->add(prev_input_pos, prev_input_pos+word.length()-1, result.length(),result.length()+add.length()-1); 146 result+=add; 147 numparts++; 148 prev_input_pos = input_pos; 149 } 150 return result; 151 } 152 109 153 110 154 /////////////////////////////////////////////// … … 118 162 static int goodWidthForFormat(const SString& genotype_format) 119 163 { 120 return genotype_format == "0"? 45 : 15; // more space for long f0 lines164 return Geno::formatIsOneOf(genotype_format, Geno::F0_FORMAT_LIST) ? 45 : 15; // more space for long f0 lines 121 165 } 122 166 … … 134 178 gcm.addConverter(new GenoConv_Test2()); 135 179 gcm.addConverter(new GenoConv_Test3()); 180 gcm.addConverter(new GenoConv_Test4()); 136 181 Geno::useConverters(&gcm); 137 182 … … 154 199 else 155 200 src = "X"; 156 SString dst = (argc > 2) ? *argv[2] : '0';201 SString dst = (argc > 2) ? argv[2] : Geno::F0_FORMAT_LIST; 157 202 bool using_checkpoints = (argc > 3) ? (strcmp(argv[3], "checkpoints") == 0) : false; 158 203 … … 162 207 MultiMap m; 163 208 Geno g2 = g1.getConverted(dst, &m, using_checkpoints); 164 printf("*** Converted to f%s:\n", dst.c_str());209 printf("*** Converted:\n"); 165 210 printGen(g2); 166 211
Note: See TracChangeset
for help on using the changeset viewer.