예제 #1
0
		public static StepFile simpleStepRepresentation(){
			StepDataObject entity0 = new StepDataObject("IFCPROJECT",
			                                            StepValue.CreateString("3MD_HkJ6X2EwpfIbCFm0g_"),
			                                            StepValue.CreateLineReference(2),
			                                            StepValue.CreateString("Default Project"),
			                                            StepValue.CreateString("Description of Default Project"),
			                                            StepValue.CreateNull(),
			                                            StepValue.CreateFloat(-22.4),
			                                            StepValue.CreateNull(),
			                                            StepValue.CreateArray(
			                                            	StepValue.CreateLineReference(20)
			                                            ),
			                                            StepValue.CreateLineReference(7)
			                                           );
			StepDataObject entity1 = new StepDataObject("IFCOWNERHISTORY",
			                                            StepValue.CreateLineReference(3),
			                                            StepValue.CreateNestedEntity(new StepDataObject("IFCTEXT",
			                                                                                            StepValue.CreateString("foobar"))),
			                                            StepValue.CreateNull(),
			                                            StepValue.CreateEnum("ADDED"),
			                                            StepValue.CreateNull(),
			                                            StepValue.CreateBoolean(false),
			                                            StepValue.CreateOverridden(),
			                                            StepValue.CreateInteger(1217620436)
			                                           );
			StepFile sf = new StepFile();
			appendHeaderToStepFile(sf, createHeader());
			sf.Data.Add(1, entity0);
			sf.Data.Add(2, entity1);
			return sf;
		}
예제 #2
0
 public static StepValue CreateNestedEntity(StepDataObject obj)
 {
     return(new StepValue(StepToken.StartEntity, obj));
 }
예제 #3
0
		/// <summary>
		/// Populates a .Net instance's properties with the data given in the Step Data Object
		/// </summary>
		/// <param name="obj">The empty .Net instance which will be populated</param>
		/// <param name="sdoId">The unique Id of the StepDataObject</param>
		/// <param name="sdo">The Step Data Object with data to inject into the .Net object</param>
		/// <param name="typeProperties">The type properties applicable to the .Net instance</param>
		private void populateObject(ref Object obj, int sdoId, StepDataObject sdo, IList<PropertyInfo> typeProperties){
			if(obj == null)
				throw new ArgumentNullException("obj");
			if(typeProperties == null || typeProperties.Count < 1)
				throw new ArgumentNullException("typeProperties");
			if(sdo == null)
				throw new ArgumentNullException("sdo");
			if(sdo.Properties == null)
				throw new ArgumentException("sdo.Properties is null");
			
			if(sdo.Properties.Count != typeProperties.Count)
				throw new StepBindingException(String.Format(CultureInfo.InvariantCulture,
				                                                "The number of data values, {0}, provided by the STEP data object, {1}, does not equal the number of properties, {2}, available in the .Net object, {3}",
				                                                sdo.Properties.Count,
				                                                sdo.ObjectName,
				                                                typeProperties.Count,
				                                                obj.GetType().FullName));
			
			for(int propertyIndex = 0; propertyIndex < sdo.Properties.Count; propertyIndex++){
				StepValue sv = sdo.Properties[propertyIndex];
				
				PropertyInfo pi = typeProperties[propertyIndex];
				
				if(pi == null)
					throw new StepBindingException(String.Format(CultureInfo.InvariantCulture,
					                                                "A null property was found at index {0} of the cached properties provided for type {1}",
					                                                propertyIndex,
					                                                obj.GetType().Name));
				
				populateProperty(pi, ref obj, sv, sdoId);
			}
		}
예제 #4
0
		/// <summary>
		/// Converts a StepDataObject to a .Net object, entering the data into its properties
		/// or, for references, adding an entry
		/// </summary>
		/// <param name="sdoId">The unique Id of the Step Data Object being converted</param>
		/// <param name="sdo">The Step Data Object which is to be converted to a .Net object.</param>
		/// <returns></returns>
		private Object bindObject(int sdoId, StepDataObject sdo){
			if(sdo == null) throw new ArgumentNullException("sdo");
			
			string name = sdo.ObjectName;
			
			Object instance = createObject(sdo.ObjectName);
			IList<PropertyInfo> typeProperties;
			
			//get the properties from the cache
			try{
				typeProperties = _cache.getPropertiesOfEntity(instance.GetType());
			}catch(KeyNotFoundException knfe){
				string msg = String.Format(CultureInfo.InvariantCulture,
				                           "Could not find the key {0} in our entityProperties cache", instance.GetType().FullName);
				logger.Error(msg);
				//return instance; //FIXME should we throw an exception instead??
				throw new StepBindingException(msg, knfe);
			}
			
			//debugging
			logger.Debug("Property Names : ");
			foreach(PropertyInfo pi in typeProperties)
				logger.Debug(String.Format("\t{0}", pi.Name));
			
			if(typeProperties.Count != sdo.Properties.Count)
				throw new StepBindingException(String.Format(CultureInfo.InvariantCulture,
				                                                "The number of properties ( {0} ) in the Step entity, {1},  do not equal the number of properties ({2}) in the object, {3}",
				                                                sdo.Properties.Count,
				                                                sdo.ObjectName,
				                                                typeProperties.Count,
				                                                instance.GetType().FullName));
			
			
			populateObject(ref instance, sdoId, sdo, typeProperties);
			
			return instance;
		}
예제 #5
0
		/// <summary>
		/// binds the data from the FILE_NAME object of the STEP HEADER section
		/// </summary>
		/// <param name="sdo"></param>
		/// <param name="header"></param>
		private void bindFileName(StepDataObject sdo, iso_10303_28_header header){
			if(sdo == null) throw new ArgumentNullException("sdo");
			if(header == null) throw new ArgumentNullException("header");
			if(sdo.ObjectName != "FILE_NAME") throw new ArgumentException(String.Format(CultureInfo.InvariantCulture,
			                                                                            "bindFileName(StepDataObject, iso_10303_28_header) should only be called for StepDataObject FILE_NAME, and not {0}",
			                                                                            sdo.ObjectName));
			if(sdo.Properties == null || sdo.Properties.Count != 7) throw new ArgumentException("sdo does not have the correct number of properties");

			header.name = (string)sdo.Properties[0].Value;
			header.time_stamp = (DateTime)sdo.Properties[1].Value;
			header.author = (string)((IList<StepValue>)sdo.Properties[2].Value)[0].Value; //FIXME only copies first value in the array as header.author is a string, and not a list
			header.organization = (string)((IList<StepValue>)sdo.Properties[3].Value)[0].Value; //FIXME only copies first value in the array as header.author is a string, and not a list
			header.preprocessor_version = (string)sdo.Properties[4].Value;
			header.originating_system = (string)sdo.Properties[5].Value;
			header.authorization = (string)sdo.Properties[6].Value;
		}
예제 #6
0
 public static StepValue CreateNestedEntity(StepDataObject obj){
 	return new StepValue(StepToken.StartEntity, obj);
 }
예제 #7
0
 private void SerializeObject(IStepWriter writer, StepDataObject sdo ){
     if( writer == null ) throw new ArgumentNullException("writer");
     if(sdo == null ) throw new ArgumentNullException("sdo");
     
     if(String.IsNullOrEmpty( sdo.ObjectName )) throw new ArgumentNullException("sdo.ObjectName");
     writer.WriteObjectName( sdo.ObjectName );
     writer.WriteStartObject();
     foreach(StepValue sv in sdo.Properties){
         SerializeProperty(writer, sv);
     }
     writer.WriteEndObject();
 }
예제 #8
0
 private void SerializeEntity( IStepWriter writer, int entityId, StepDataObject sdo ){
     if( writer == null ) throw new ArgumentNullException("writer");
     if( sdo == null ) throw new ArgumentNullException( "sdo" );
     
     writer.WriteLineIdentifier( entityId );
     SerializeObject( writer, sdo );
 }
예제 #9
0
		/// <summary>
		/// Attempts to read a nested entity
		/// </summary>
		/// <param name="reader"></param>
		/// <returns></returns>
		private StepDataObject deserializeEntity(IStepReader reader){
			if(reader == null)
				throw new ArgumentNullException( "reader" );
			
			StepDataObject edo = new StepDataObject();
			bool entityStarted = false;
			
			//nested entities are already on the EntityName token
			if(reader.TokenType == StepToken.EntityName)
				edo.ObjectName = getObjectName(reader);
			
			while(reader.Read()){
				logger.Debug(String.Format(CultureInfo.InvariantCulture,
				                           "deserializer read token {0}. value {1}",
				                           reader.TokenType,
				                           reader.Value));
				switch(reader.TokenType){
					case StepToken.EntityName:
						if(!entityStarted)
							edo.ObjectName = getObjectName( reader );
						else //it's a nested entity
							edo.Properties.Add( deserializeNestedEntity( reader ) );
						continue;
					case StepToken.LineReference:
						edo.Properties.Add(deserializeLineReference( reader ));
						continue;
					case StepToken.Enumeration:
					case StepToken.Boolean:
					case StepToken.Integer:
					case StepToken.Float:
					case StepToken.String:
					case StepToken.Date:
						edo.Properties.Add(deserializeProperty( reader ));
						continue;
					case StepToken.StartArray:
						edo.Properties.Add(deserializeArray( reader ));
						continue;
					case StepToken.StartEntity:
						if(!entityStarted)
							entityStarted = true;
						else
							throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture,
							                                                "A token was found which was not expected: {0}",
							                                                reader.TokenType));
						continue;
					case StepToken.Operator:
					case StepToken.Comment:
						continue;
					case StepToken.Overridden:
						edo.Properties.Add(deserializeOverridden());
						continue;
					case StepToken.Null:
						edo.Properties.Add(deserializeNull());
						continue;
					case StepToken.EndEntity:
						return edo;
					case StepToken.EndLine:
					case StepToken.EndSection:
					case StepToken.EndSTEP:
					case StepToken.StartSTEP:
					case StepToken.StartSection:
						throw new StepSerializerException(String.Format(CultureInfo.InvariantCulture,
						                                                "A token was found which was not expected: {0}",
						                                                reader.TokenType));
					default:
						throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture,
						                                                "The {0} ExpressToken type is not yet implemented by deserializeEntity()",
						                                                reader.TokenType));
				}
				//TODO should do some verification here (properties are after entityStart and before EntityEnd etc.)
			}
			throw new StepSerializerException( "The reader reached the end without finding an endEntity token" );
		}
예제 #10
0
		public void AssertObject(string expectedName, int expectedPropertiesCount, StepDataObject actual){
			Assert.IsNotNull(actual);
			Assert.AreEqual(expectedName, actual.ObjectName);
			Assert.IsNotNull(actual.Properties);
			Assert.AreEqual(expectedPropertiesCount, actual.Properties.Count);
		}
예제 #11
0
		internal StepDataObject ExtractObject( Object obj ){
			if(obj == null) throw new ArgumentNullException("entity");
			Type objType = obj.GetType();
			
			StepDataObject sdo = new StepDataObject();
			sdo.ObjectName = GetObjectName( objType );
			
			IList<PropertyInfo> objProps = this._cache.getPropertiesOfEntity(objType);
			foreach(PropertyInfo pi in objProps){
				sdo.Properties.Add( ExtractProperty( obj, pi ) );
			}
			return sdo;
		}
예제 #12
0
		private StepDataObject ExtractFileSchema( iso_10303 iso10303 ){
			if(iso10303 == null) throw new ArgumentNullException( "iso10303" );
			StepDataObject sdo = new StepDataObject();
			sdo.ObjectName = "FILE_SCHEMA";
			sdo.Properties.Add( StepValue.CreateArray( StepValue.CreateString("IFC2X3") ) );
			return sdo;
		}
예제 #13
0
		private StepDataObject ExtractFileName( iso_10303 iso10303 ){
			if(iso10303 == null) throw new ArgumentNullException("iso10303");
			iso_10303_28_header header = iso10303.iso_10303_28_header;
			if(header == null) throw new ArgumentNullException("iso10303.iso_10303_28_header");
			StepDataObject sdo = new StepDataObject();
			sdo.ObjectName = "FILE_NAME";
			
			sdo.Properties.Add( StepValue.CreateString(header.name));
			sdo.Properties.Add( StepValue.CreateDate(header.time_stamp ) );
			
			sdo.Properties.Add( StepValue.CreateArray( StepValue.CreateString( header.author ) ) );
			
			//FIXME header.organization is a string and not a list, but the Step file expects an array
			sdo.Properties.Add( StepValue.CreateArray( StepValue.CreateString( header.organization ) ) );
			
			sdo.Properties.Add( StepValue.CreateString( header.preprocessor_version ));
			sdo.Properties.Add( StepValue.CreateString( header.originating_system ));
			sdo.Properties.Add( StepValue.CreateString( header.authorization ));
			return sdo;
		}