public void Serialize(IStepWriter writer, StepFile step){ if(writer == null) throw new ArgumentNullException("writer"); if(step == null) throw new ArgumentNullException("step"); writer.WriteStartStep(); SerializeHeader(writer, step.Header); SerializeData(writer, step.Data); writer.WriteEndStep(); }
public iso_10303 Bind(StepFile step){ if(step == null) throw new ArgumentNullException("step"); if(step.Data == null) throw new ArgumentNullException("step.Data"); if(step.Header == null) throw new ArgumentNullException("step.Header"); iso_10303 iso10303 = new iso_10303(); //TODO fill in meta data from STEP header iso10303.iso_10303_28_header = new iso_10303_28_header(); foreach(StepDataObject sdo in step.Header){ logger.Debug("Found header object : " + sdo.ObjectName); if(sdo.ObjectName == "FILE_NAME") bindFileName(sdo, iso10303.iso_10303_28_header); } iso10303.uos = new uos1(); IDictionary<int, Entity> entities = new SortedDictionary<int, Entity>(); //try and instantiate a type for each STEP entity //and fill its properties foreach(KeyValuePair<int, StepDataObject> kvp in step.Data){ if(kvp.Value == null) continue; Object o = this.bindObject(kvp.Key, kvp.Value); //TODO check that instance type is derived from Entity. Entity e = o as Entity; logger.Debug("Adding a deserialized item. Item Id : " + kvp.Key ); entities.Add( kvp.Key, e ); } logger.Info(String.Format(CultureInfo.InvariantCulture, "Deserialized {0} entities", entities.Count )); LinkReferences( entities ); Entity[] items = new Entity[entities.Count]; entities.Values.CopyTo( items, 0 ); ((uos1)iso10303.uos).Items = items; //clear object links so there's no issues next time this method is run this._objectLinks = new List<StepEntityReference>(); return iso10303; }
/// <summary> /// Extracts StepDataObjects from a .Net object /// </summary> /// <param name="iso10303"></param> /// <returns></returns> public StepFile Extract(iso_10303 iso10303){ if(iso10303 == null) throw new ArgumentNullException("iso10303"); if(iso10303.iso_10303_28_header == null) throw new ArgumentNullException("iso10303.iso_10303_28_header"); if(iso10303.uos == null) throw new ArgumentNullException("iso10303.uos"); StepFile stepFile = new StepFile(); //header stepFile.Header.Add( GenerateFileDescription( ) ); stepFile.Header.Add( ExtractFileName( iso10303 ) ); stepFile.Header.Add( ExtractFileSchema( iso10303 ) ); //data uos1 uos1 = iso10303.uos as uos1; if(uos1 == null){ //no data logger.Error( "Extract(iso_10303) could not extract, as iso10303.uos was not a type of uos1" ); return stepFile; } //putting the entities in a dictionary so we can deal with references foreach(Entity e in uos1.Items){ if(!this._entityRegister.isAlreadyRegistered(e)){ this._entityRegister.RegisterEntity( e ); this._queuedEntities.Enqueue( e ); } } while(this._queuedEntities.Count > 0){ Entity e = this._queuedEntities.Dequeue(); int entityId = this._entityRegister.getEntityId(e); StepDataObject sdo = this.ExtractObject( e ); stepFile.Data.Add( entityId, sdo ); } //clear entityQueue, so next time this method is run it starts empty this._entityRegister = new StepBinderEntityRegister(); return stepFile; }
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; }
private static void appendHeaderToStepFile(StepFile sf, IList<StepDataObject> header){ foreach(StepDataObject sdo in header){ sf.Header.Add(sdo); } }
public StepFile Deserialize(IStepReader reader) { if( reader == null ) throw new ArgumentNullException( "reader" ); StepFile step = new StepFile(); while(reader.Read()){ switch(reader.TokenType){ case StepToken.EntityName: step.Header.Add( deserializeEntity( reader ) ); continue; case StepToken.LineIdentifier: int objectNumber = getObjectNumber( reader ); step.Data.Add( objectNumber, deserializeEntity( reader ) ); continue; default: continue; } } //TODO should try to create the tree here. Need to handle circular references though. return step; }