//----------------------------------------------------------- // Check for bmp element, return false if not //----------------------------------------------------------- short MPMReadHandler::BMPFileInput(char *xName,const Attributes& attrs) { // check for common commands if(BMPFileCommonInput(xName,attrs,POINTSBLOCK)) return TRUE; //----------------------------------------------------------- // Intensity properties for MPM only // vel is handled in main MPMReadHandler //----------------------------------------------------------- // concentration if(strcmp(xName,"Concentration")==0) { ValidateCommand(xName,INTENSITYBLOCK,ANY_DIM); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->concentration; } // not a BMP file element else return FALSE; return TRUE; }
//----------------------------------------------------------- // Check for bmp element, return false if not //----------------------------------------------------------- short CommonReadHandler::BMPFileCommonInput(char *xName,const Attributes& attrs,int expectedBlock) { char *aName,*value; int i,numAttr; double aScaling; //----------------------------------------------------------- // Read BMP file name and resolution //----------------------------------------------------------- if(strcmp(xName,"BMP")==0) { ValidateCommand(xName,expectedBlock,ANY_DIM); block=BMPBLOCK; bwidth=bheight=-1.e9; // < -1.e8 means dimension was not specified bmpFileName[0]=0; bmpAngleFileName[0]=0; xorig=yorig=0.; yflipped=FALSE; zslice=0.; aScaling=ReadUnits(attrs,LENGTH_UNITS); numAttr=attrs.getLength(); #ifdef MPM_CODE rotationAxes[0]=0; // no rotations yet #endif for(i=0;i<numAttr;i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"width")==0) sscanf(value,"%lf",&bwidth); else if(strcmp(aName,"height")==0) sscanf(value,"%lf",&bheight); else if(strcmp(aName,"name")==0) strcpy(bmpFileName,value); else if(strcmp(aName,"angles")==0) strcpy(bmpAngleFileName,value); delete [] aName; delete [] value; } if(bwidth<-1.e8 && bheight<-1.e8) throw SAXException(BMPError("<BMP> must specify width and/or height as size or pixels per mm.",bmpFileName)); bwidth*=aScaling; bheight*=aScaling; if(bmpFileName[0]==0) throw SAXException("<BMP> must specify the file in a name attribute."); } //----------------------------------------------------------- // Set origin on input data //----------------------------------------------------------- else if(strcmp(xName,"Origin")==0) { ValidateCommand(xName,BMPBLOCK,ANY_DIM); aScaling=ReadUnits(attrs,LENGTH_UNITS); numAttr=attrs.getLength(); for(i=0;i<numAttr;i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"x")==0) { sscanf(value,"%lf",&xorig); xorig*=aScaling; } else if(strcmp(aName,"y")==0) { sscanf(value,"%lf",&yorig); yorig*=aScaling; } else if(strcmp(aName,"z")==0) { sscanf(value,"%lf",&zslice); zslice*=aScaling; } else if(strcmp(aName,"flipped")==0) { if(strcmp(value,"yes")==0 || strcmp(value,"Yes")==0 || strcmp(value,"YES")==0 || strcmp(value,"1")==0 ) yflipped=TRUE; else yflipped=FALSE; } delete [] aName; delete [] value; } } //----------------------------------------------------------- // Assign intensity to some material properties //----------------------------------------------------------- else if(strcmp(xName,"Intensity")==0) { ValidateCommand(xName,BMPBLOCK,ANY_DIM); numAttr=attrs.getLength(); int mat=-1; int imin=-1; int imax=-1; minAngle=0.; double maxAngle=0.; char matname[200]; matname[0]=0; for(i=0;i<numAttr;i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"mat")==0) sscanf(value,"%d",&mat); else if(strcmp(aName,"matname")==0) { if(strlen(value)>199) value[200]=0; strcpy(matname,value); } else if(strcmp(aName,"imin")==0) sscanf(value,"%d",&imin); else if(strcmp(aName,"imax")==0) sscanf(value,"%d",&imax); else if(strcmp(aName,"minAngle")==0) sscanf(value,"%lf",&minAngle); else if(strcmp(aName,"maxAngle")==0) sscanf(value,"%lf",&maxAngle); delete [] aName; delete [] value; } // if gave a matname, it takes precedence over mat number if(strlen(matname)>0) mat = matCtrl->GetIDFromNewName(matname); if(imin<0 || imax<0) throw SAXException(BMPError("<Intensity> has incomplete set of attributes.",bmpFileName)); if(imin>=imax) throw SAXException(BMPError("<Intensity> range is not valid.",bmpFileName)); if(mat>=0) { BMPLevel *newLevel=new BMPLevel(mat,imin,imax); if(newLevel==NULL) throw SAXException(BMPError("<Intensity> failed due to memory error.",bmpFileName)); if(currentLevel==NULL) firstLevel=newLevel; else currentLevel->SetNextObject(newLevel); currentLevel=newLevel; block=INTENSITYBLOCK; } else { angleScale=(maxAngle-minAngle)/((double)imax-(double)imin); minIntensity=(double)imin; } } //----------------------------------------------------------- // Intensity properties for both MPM and FEA //----------------------------------------------------------- // thickness else if(strcmp(xName,"Thickness")==0) { ValidateCommand(xName,INTENSITYBLOCK,MUST_BE_2D); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->thickness; gScaling=ReadUnits(attrs,LENGTH_UNITS); } // angle else if(strcmp(xName,"Angle")==0) { ValidateCommand(xName,INTENSITYBLOCK,ANY_DIM); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->angle; } // temperature else if(strcmp(xName,"Temperature")==0) { #ifdef FEA_CODE if(block==THERMAL) return FALSE; #endif ValidateCommand(xName,INTENSITYBLOCK,ANY_DIM); input=DOUBLE_NUM; inputPtr=(char *)¤tLevel->temperature; } else return FALSE; return TRUE; }
// Start a new element void CommonReadHandler::startElement(const XMLCh* const uri,const XMLCh* const localname, const XMLCh* const qname,const Attributes& attrs) { // decode tag name char *xName=XMLString::transcode(localname); input=NO_INPUT; // Handle all elements common between MPM and FEA analysis //------------------------------------------------------- // <Header> elements if(strcmp(xName,"Header")==0) block=HEADER; else if(strcmp(xName,"Description")==0) { if(block!=HEADER) throw SAXException("<Description> must be within the <Header> element."); input=TEXT_BLOCK; inputID=DESCRIPTION; } else if(strcmp(xName,"Analysis")==0) { if(block!=HEADER) throw SAXException("<Analysis> must be within the <Header> element."); input=ANALYSIS_NUM; } // begin a material else if(strcmp(xName,"DevelFlag")==0) { if(block!=HEADER) throw SAXException("<DevelFlag> must be within the <Header> element."); double flagNumDble=ReadNumericAttribute("Number",attrs,(double)0.0); int flagNum=(int)(flagNumDble+0.5); if(flagNum<0 || flagNum>=NUMBER_DEVELOPMENT_FLAGS) throw SAXException("The <DevelFlag> 'Number' must be from 0 to 9"); input=INT_NUM; inputPtr=(char *)&fmobj->dflag[flagNum]; } else if(strcmp(xName,"ConsistentUnits")==0) { if(block!=HEADER) throw SAXException("<ConsistentUnits> must be within the <Header> element."); char length[10],mass[10],timeu[10]; strcpy(length,""); strcpy(mass,""); strcpy(timeu,""); char *aName,*value; int i,numAttr=(int)attrs.getLength(); for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strlen(value)>9) throw SAXException("<ConsistentUnits> length, mass, or time attribute is invalid."); if(strcmp(aName,"length")==0) strcpy(length,value); else if(strcmp(aName,"mass")==0) strcpy(mass,value); else if(strcmp(aName,"time")==0) strcpy(timeu,value); delete [] aName; delete [] value; } if(strlen(length)==0 && strlen(mass)==0 && strlen(timeu)==0) { strcpy(length,"L"); strcpy(mass,"M"); strcpy(timeu,"T"); } if(!UnitsController::SetConsistentUnits(length, mass, timeu)) throw SAXException("Duplicated <ConsistentUnits> command or one of the units is invalid."); } //------------------------------------------------------- // <Mesh> block // Node list else if(strcmp(xName,"NodeList")==0) { ValidateCommand(xName,MESHBLOCK,ANY_DIM); if(meshType!=UNKNOWN_MESH) throw SAXException("<NodeList> can not be used with a generated mesh."); block=NODELIST; meshType=EXPLICIT_MESH; if(theNodes==NULL) theNodes=new NodesController(); } // Element list else if(strcmp(xName,"ElementList")==0) { ValidateCommand(xName,MESHBLOCK,ANY_DIM); if(meshType!=EXPLICIT_MESH) throw SAXException("<ElementList> cannot be used with a generated mesh."); block=ELEMENTLIST; // MPM only uses when in ElementList (which is uncommon because does not suppport GIMP) if(theElems==NULL) theElems=new ElementsController(); } //----------------------------------------------------------- // <GridBCs> section // DisplacementBC section else if(strcmp(xName,"DisplacementBCs")==0) { ValidateCommand(xName,GRIDBCHEADER,ANY_DIM); block=FIXEDNODES; } //------------------------------------------------------- // <Thermal> section // begin Thermal section else if(strcmp(xName,"Thermal")==0) { block=THERMAL; } //------------------------------------------------------- // <Material> Definitions // begin a material else if(strcmp(xName,"Material")==0) { block=MATERIAL; int matID=0; // invalid ID unless it is set char matName[200],*aName,*value; matName[0]=0; // to get the name of the material int i,numAttr=(int)attrs.getLength(); for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"Type")==0) sscanf(value,"%d",&matID); else if(strcmp(aName,"Name")==0) { if(strlen(value)>199) value[200]=0; strcpy(matName,value); } delete [] aName; delete [] value; } if(strlen(matName)==0) throw SAXException("<Material> must be named using 'Name' atttribute."); if(!matCtrl->AddMaterial(matID,matName)) ThrowCatErrorMessage("Invalid material: either undefined type or not allowed for current analysis type",matName); } // begin a material else if(strcmp(xName,"color")==0) { if(block!=MATERIAL) throw SAXException("<color> must be within a <Material> definition."); float redClr=-1.,greenClr=-1.,blueClr=-1.,alpha=1.; char *aName,*value; int i,numAttr=(int)attrs.getLength(); for(i=0; i<numAttr; i++) { aName=XMLString::transcode(attrs.getLocalName(i)); value=XMLString::transcode(attrs.getValue(i)); if(strcmp(aName,"red")==0) sscanf(value,"%f",&redClr); else if(strcmp(aName,"green")==0) sscanf(value,"%f",&greenClr); else if(strcmp(aName,"blue")==0) sscanf(value,"%f",&blueClr); else if(strcmp(aName,"alpha")==0) sscanf(value,"%f",&alpha); delete [] aName; delete [] value; } if(redClr>0.) { if(redClr>1.) redClr=1.; if(greenClr<0.) greenClr=redClr; if(blueClr<0.) blueClr=redClr; if(greenClr>1.) greenClr=1.; if(blueClr>1.) blueClr=1.; if(alpha<0.) alpha=0.; if(alpha>1.) alpha=1.; matCtrl->SetMatColor(redClr,greenClr,blueClr,alpha); } } //------------------------------------------------------- // Analysis-specific elements else if(!myStartElement(xName,attrs)) { // look for material property if(block==MATERIAL) { inputPtr=matCtrl->InputPointer(xName,input,gScaling); if(inputPtr==NULL) { char msg[255]; strcpy(msg,"Unrecognized "); strcat(msg,matCtrl->MaterialType()); strcat(msg," material property was found"); ThrowCatErrorMessage(msg,xName); } } // or an invalid tag else if(!(strcmp(xName,"JANFEAInput")==0)) ThrowCatErrorMessage("Unrecognized input element found",xName); } // delete tag string delete [] xName; }