- Timestamp:
- 04/11/16 02:07:03 (9 years ago)
- Location:
- cpp/frams/model
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/model/model.cpp
r458 r495 326 326 } 327 327 mh.reset(); 328 if (singleStepBuild(line, autobuildmaps ? (&frommap) : 0)==-1)328 if (singleStepBuild(line,lnum,autobuildmaps ? (&frommap) : 0) == -1) 329 329 { 330 330 buildstatus=invalid; 331 logPrintf("Model","build",LOG_ERROR,332 geno.getName().len()?"illegal f0 code at line %d (%s)":"illegal f0 code at line %d",333 lnum,geno.getName().c_str());334 331 f0errorposition=lastpos; 335 332 if (convmap) delete convmap; … … 407 404 modelparam.select(this); 408 405 modelparam.save2(mod_props,handle_defaults ? &defaultmodel : NULL,true,!handle_defaults); 409 if (mod_props.len()> 0) //are there any non-default values?406 if (mod_props.len()>1) //are there any non-default values? ("\n" is empty) 410 407 { 411 408 gen+="m:"; … … 513 510 { 514 511 if (buildstatus!=building) 515 logPrintf("Model","close",LOG_WARN," unexpected close() - no open()");512 logPrintf("Model","close",LOG_WARN,"Unexpected close() - no open()"); 516 513 if (internalcheck(1)>0) 517 514 { … … 557 554 } 558 555 559 int Model::singleStepBuild(const SString &line,const MultiRange* srcrange) 560 { 556 int Model::singleStepBuild(const SString &singleline,const MultiRange* srcrange) 557 { 558 return singleStepBuild(singleline,0,srcrange); 559 } 560 561 int Model::singleStepBuild(const SString &singleline,int line_num,const MultiRange* srcrange) 562 { 563 SString error_message; 564 int result=singleStepBuildNoLog(singleline,error_message,srcrange); 565 if (result<0) 566 { 567 if (error_message.len()==0) // generic error when no detailed message is available 568 error_message="Invalid f0 code"; 569 if (line_num>0) 570 error_message+=SString::sprintf(", line #%d",line_num); 571 error_message+=nameForErrors(); 572 logPrintf("Model","build",LOG_ERROR,"%s",error_message.c_str()); 573 } 574 return result; 575 } 576 577 int Model::singleStepBuildNoLog(const SString &line,SString& error_message,const MultiRange* srcrange) 578 { 579 error_message=SString::empty(); 561 580 int pos=0; const char*t=line.c_str(); 562 581 for (;*t;t++,pos++) … … 570 589 partparam.select(p); 571 590 pos+=2; 572 if (partparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete p; return -1;}591 if (partparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete p; error_message="Invalid 'p:'"; return -1;} 573 592 p->o.rotate(p->rot); 574 593 parts+=p; … … 582 601 modelparam.select(this); 583 602 pos+=2; 584 if (modelparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1;603 if (modelparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) { error_message="Invalid 'm:'"; return -1;} 585 604 return 0; 586 605 } … … 592 611 pos+=2; 593 612 j->owner=this; 594 if (jointparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete j; return -1;} 595 if ((j->p1_refno>=0)&&(j->p1_refno<getPartCount())&& 596 (j->p2_refno>=0)&&(j->p2_refno<getPartCount())) 613 if (jointparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete j; error_message="Invalid 'j:'"; return -1;} 614 bool p1_ok=false, p2_ok=false; 615 if ((p1_ok=((j->p1_refno>=0)&&(j->p1_refno<getPartCount())))&& 616 (p2_ok=((j->p2_refno>=0)&&(j->p2_refno<getPartCount())))) 597 617 { 598 618 addJoint(j); … … 609 629 { 610 630 delete j; 611 logPrintf("Model","build",LOG_ERROR, 612 "invalid part reference for joint #%d",getJointCount()-1); 631 error_message=SString::sprintf("Invalid reference to Part #%d",p1_ok?j->p1_refno:j->p2_refno); 613 632 return -1; 614 633 } … … 620 639 neuroparam.select(nu); 621 640 pos+=2; 622 if (neuroparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete nu; return -1;}641 if (neuroparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) {delete nu; error_message="Invalid 'n:'"; return -1;} 623 642 #ifdef MODEL_V1_COMPATIBLE 624 643 if (nu->neuro_refno>=0) // parent specified... … … 684 703 ncparam.select(&c); 685 704 pos+=2; 686 if (ncparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) return -1; 687 if ((c.n1_refno>=0)&&(c.n1_refno<getNeuroCount())&&(c.n2_refno>=0)&&(c.n2_refno<getNeuroCount())) 705 if (ncparam.load2(line,pos) & ParamInterface::LOAD2_PARSE_FAILED) { error_message="Invalid 'c:'"; return -1; } 706 bool n1_ok=false,n2_ok=false; 707 if ((n1_ok=((c.n1_refno>=0)&&(c.n1_refno<getNeuroCount()))) 708 && (n2_ok=((c.n2_refno>=0)&&(c.n2_refno<getNeuroCount())))) 688 709 { 689 710 Neuro *na=getNeuro(c.n1_refno); … … 694 715 return 0; 695 716 } 696 logPrintf("Model","build",LOG_ERROR, 697 "invalid neuron connection #%d <- #%d",c.n1_refno,c.n2_refno); 717 error_message=SString::sprintf("Invalid reference to Neuro #%d",n1_ok ? c.n2_refno : c.n1_refno); 698 718 return -1; 699 719 } … … 783 803 { 784 804 logPrintf("Model","internalCheck",LOG_ERROR, 785 "illegal N-N connection #%d (reference to #%d) (%s)",786 i,n->conn_refno,(const char*)geno.getName());805 "illegal N-N connection #%d (reference to #%d)%s", 806 i,n->conn_refno,nameForErrors().c_str()); 787 807 return 0; 788 808 } … … 853 873 if (var -> field < getMin ## template () . field) \ 854 874 { var->field= getMin ## template () . field; \ 855 logPrintf("Model","internalCheck",LOG_WARN,# field " too small in " # template " #%d (adjusted)",i);} \875 logPrintf("Model","internalCheck",LOG_WARN,# field " too small in " # template " #%d (adjusted)",i);} \ 856 876 else if (var -> field > getMax ## template () . field) \ 857 877 { var->field= getMax ## template () . field; \ 858 logPrintf("Model","internalCheck",LOG_WARN,# field " too big in " # template " #%d (adjusted)",i);}878 logPrintf("Model","internalCheck",LOG_WARN,# field " too big in " # template " #%d (adjusted)",i);} 859 879 860 880 #define LINKFLAG 0x8000000 … … 866 886 for (i=0;i<getJointCount();i++) getJoint(i)->refno=i; 867 887 for (i=0;i<getNeuroCount();i++) getNeuro(i)->refno=i; 888 } 889 890 SString Model::nameForErrors() const 891 { 892 if (geno.getName().len()>0) 893 return SString::sprintf(" in '%s'",geno.getName().c_str()); 894 return SString::empty(); 868 895 } 869 896 … … 912 939 { 913 940 shape=SHAPE_ILLEGAL; 914 logPrintf("Model","internalCheck",LOG_WARN,"Inconsistent part shapes (mixed old and new shapes) ");941 logPrintf("Model","internalCheck",LOG_WARN,"Inconsistent part shapes (mixed old and new shapes)%s",nameForErrors().c_str()); 915 942 } 916 943 } … … 942 969 ret=0; 943 970 logPrintf("Model","internalCheck",LOG_ERROR, 944 " delta joint cycle detected at joint#%d (%s)",945 i, geno.getName().c_str());971 "Delta joint cycle detected at Joint #%d%s", 972 i,nameForErrors().c_str()); 946 973 } 947 974 j->resetDeltaMarkers(); … … 978 1005 { 979 1006 ret=0; 980 logPrintf("Model","internalCheck",LOG_ERROR,"delta too big in joint #%d (%s)", 981 i,geno.getName().c_str()); 1007 logPrintf("Model","internalCheck",LOG_ERROR,"Delta too big in Joint #%d%s",i,nameForErrors().c_str()); 982 1008 } 983 1009 else if (j->d()<getMinJoint().d.x) 984 1010 { 985 1011 ret=0; 986 logPrintf("Model","internalCheck",LOG_ERROR,"delta too small in joint #%d (%s)", 987 i,geno.getName().c_str()); 1012 logPrintf("Model","internalCheck",LOG_ERROR,"delta too small in Joint #%d%s",i,nameForErrors().c_str()); 988 1013 } 989 1014 } … … 992 1017 else 993 1018 { 994 logPrintf("Model","internalCheck",LOG_ERROR,"illegal part references in joint #%d (%s)", 995 i,geno.getName().c_str()); 1019 logPrintf("Model","internalCheck",LOG_ERROR,"Illegal part references in Joint #%d%s",i,nameForErrors().c_str()); 996 1020 ret=0; 997 1021 } … … 1001 1025 { 1002 1026 shape=SHAPE_ILLEGAL; 1003 logPrintf("Model","internalCheck",LOG_WARN,"Inconsistent joint shapes (mixed old and new shapes) ");1027 logPrintf("Model","internalCheck",LOG_WARN,"Inconsistent joint shapes (mixed old and new shapes)%s",nameForErrors().c_str()); 1004 1028 } 1005 1029 } … … 1071 1095 if (!(p->flags&LINKFLAG)) 1072 1096 { 1073 logPrintf("Model","internalCheck",LOG_ERROR,"not all parts connected (eg.#0-#%d) (%s)", 1074 i,geno.getName().c_str()); 1097 logPrintf("Model","internalCheck",LOG_ERROR,"Not all parts connected (eg. Part #0 and Part #%d)%s",i,nameForErrors().c_str()); 1075 1098 ret=0; 1076 1099 break; … … 1084 1107 if (j->p1_refno==j->p2_refno) 1085 1108 { 1086 logPrintf("Model","internalCheck",LOG_ERROR,"illegal self connection, joint #%d (%s)", 1087 i,geno.getName().c_str()); 1109 logPrintf("Model","internalCheck",LOG_ERROR,"Illegal self connection, Joint #%d%s",i,nameForErrors().c_str()); 1088 1110 ret=0; 1089 1111 break; … … 1095 1117 || ((j->p1_refno==j2->p2_refno)&&(j->p2_refno==j2->p1_refno))) 1096 1118 { 1097 logPrintf("Model","internalCheck",LOG_ERROR,"illegal duplicate joints #%d and #%d (%s)", 1098 i,k,geno.getName().c_str()); 1119 logPrintf("Model","internalCheck",LOG_ERROR,"Illegal duplicate Joint #%d and Joint #%d%s",i,k,nameForErrors().c_str()); 1099 1120 ret=0; 1100 1121 break; … … 1125 1146 { 1126 1147 if (buildstatus==building) 1127 logPrintf("Model","getGeno",LOG_WARN," model was not completed - missing close()");1148 logPrintf("Model","getGeno",LOG_WARN,"Model was not completed - missing close()"); 1128 1149 if (buildstatus!=valid) 1129 1150 return Geno("",'0',"","invalid"); -
cpp/frams/model/model.h
r408 r495 124 124 125 125 void updateNeuroRefno(); // set Neuro::refno for all neurons 126 SString nameForErrors() const; 126 127 int internalcheck(int final); 127 128 … … 275 276 or negative value. reference number can be used to access 276 277 the item using getPart(int), getJoint(int) and getNeuroItem(int) methods. 278 @param line_num optional line number used in error messages 277 279 @param srcrange source genotype range which will be mapped to this element 278 280 */ 279 int singleStepBuild(const SString &singleline,const MultiRange* srcrange=0); 281 int singleStepBuild(const SString &singleline,int line_num,const MultiRange* srcrange=NULL); 282 /** Execute single line of <B>f0</B> genotype - compatiblity variant */ 283 int singleStepBuild(const SString &singleline,const MultiRange* srcrange=NULL); 284 /** Execute single line of <B>f0</B> genotype - low level variant, used by Model::build(), error messages returned as string instead of calling logger */ 285 int singleStepBuildNoLog(const SString &singleline,SString& error_message,const MultiRange* srcrange=0); 280 286 281 287 /// separate build stages (for future use)
Note: See TracChangeset
for help on using the changeset viewer.