//-- Load a design from a file, loaded design will be selected BOOL CTinyCadDoc::ReadFile(CStream &theArchive, BOOL Details, drawingCollection &drawing) { try { // Save the old layer setting CDrawingObject* obj = NULL; BYTE tp = xNULL; CHeaderStamp oHeader; LONG pos = theArchive.GetPos(); oHeader.Read( theArchive ); if( ! oHeader.IsChecked(false) ) { // Perhaps this is XML? theArchive.Seek(pos); CXMLReader xml( &theArchive ); return ReadFileXML( xml, Details, drawing, FALSE ); } while (tp!=xEndFile) { theArchive >> tp; switch (tp) { case xDesignInformation: GetDetails().Read( theArchive ); break; case xDesignInformation2: GetDetails().ReadEx( theArchive ); m_snap.Load( theArchive, Details ); break; case xOptions: if( Details ) { theOptions.ReadNative( theArchive ); } else { COption().ReadNative( theArchive ); } obj = NULL; break; case xFont: theOptions.LoadFonts(theArchive); obj = NULL; break; case xLineStyle: theOptions.LoadStyles(theArchive); obj = NULL; break; case xFillStyle: theOptions.LoadFillStyles(theArchive); obj = NULL; break; case xMetaFiles: theOptions.LoadMetaFiles(theArchive); obj = NULL; break; case xSymbols: theOptions.LoadSymbols(theArchive); obj = NULL; break; case xLayerTable: { // Read in the number of Layers in this list CString theNewName; WORD NumberOfResources; theArchive >> NumberOfResources; hRESOURCE OldResourceNumber = 0; while (NumberOfResources > 0) { theArchive >> OldResourceNumber; theArchive >> theNewName; NumberOfResources--; } obj = NULL; } break; case xRuler: obj = new CDrawRuler(this,FALSE); break; case xBus: obj = new CDrawLine(this,xBus); break; case xWire: obj = new CDrawLine(this,xWire); break; case xBusName: obj = new CDrawText(this,xBusName); break; case xBusNameEx: obj = new CDrawText(this,xBusNameEx); break; case xLabel: obj = new CDrawLabel(this); break; case xLabelEx: obj = new CDrawLabel(this); break; case xLabelEx2: obj = new CDrawLabel(this); break; case xJunction: obj = new CDrawJunction(this); break; case xNoConnect: obj = new CDrawNoConnect(this); break; case xBusSlash: obj = new CDrawBusSlash(this); break; case xPower: obj = new CDrawPower(this); break; case xPin: case xPinEx: obj = new CDrawPin(this); break; case xLine: obj = new CDrawPolygon(this,xLine); break; case xLineEx: obj = new CDrawPolygon(this,xLineEx); break; case xLineEx2: obj = new CDrawPolygon(this,xLineEx2); break; case xPolygon: obj = new CDrawPolygon(this,xPolygon); break; case xDash: obj = new CDrawPolygon(this,xDash); break; case xText: // The old text type obj = new CDrawText(this,xText); break; case xTextEx: obj = new CDrawText(this,xTextEx); break; case xTextEx2: obj = new CDrawText(this,xTextEx2); break; case xCircle: case xCircleEx: case xCircleEx2: case xCircleEx3: obj = new CDrawSquare(this,xCircleEx3); break; case xSquare: case xSquareEx: case xSquareEx2: case xSquareEx3: obj = new CDrawSquare(this,xSquareEx3); break; case xArc: case xArcEx: case xArcEx2: obj = new CDrawPolygon(this,static_cast<ObjType>(tp)); break; case xMethod: // The old method type case xMethodEx: case xMethodEx2: case xMethodEx3: obj = new CDrawMethod(this); break; case xTag: obj = new CDrawTag(this); break; case xMetaFile: obj = new CDrawMetaFile(this); break; default: obj = NULL; break; } if (obj!=NULL) { // Provide special handling for old objects switch (tp) { case xSquare: case xSquareEx: case xCircle: case xCircleEx: ((CDrawSquare *)obj)->OldLoad(theArchive,tp); break; case xCircleEx2: case xSquareEx2: ((CDrawSquare *)obj)->OldLoad2(theArchive); break; case xMethod: ((CDrawMethod *)obj)->OldLoad(theArchive); break; case xMethodEx: ((CDrawMethod *)obj)->OldLoad2(theArchive); break; case xMethodEx2: ((CDrawMethod *)obj)->OldLoad3(theArchive); break; case xPin: ((CDrawPin *)obj)->OldLoad(theArchive); break; case xLabel: case xLabelEx: case xLabelEx2: ((CDrawLabel *)obj)->Load(theArchive,(ObjType)tp); break; default: obj->Load(theArchive); break; } // Now add object to linked list drawing.insert( drawing.end(), obj ); } } } catch( CException *e) { CString s; CString msg; e->GetErrorMessage( msg.GetBuffer(256), 256, NULL ); msg.ReleaseBuffer(); s.Format(_T("Cannot load file.\r\n%s"), msg ); AfxMessageBox( s ); e->Delete(); } return drawing.size() > 0; }