1.1打开实验电路图文件intCVisualexDoc::OpenText(CStringFName)//打开实验电路图文件{charNowInfo[256];//定义文件句柄,用于存放每一行的最大字符数CVisualexDoc*pDoc=this;FILE*file;//文件指针if((file=fopen(FName,"r"))==NULL){return0;}DObject.RemoveAll();while(!feof(file))//判断是否为文件结尾{fgets(NowInfo,255,file);//读取文件一行//switch(CompObject(NowInfo)){//case0:NowInfo[strlen(NowInfo)-1]=0;strupr(NowInfo);if(strcmp(NowInfo,"[LINE]")==0)//判断读取的东西是否为line{intNum;//线的条数fgets(NowInfo,255,file);//再读一行sscanf(NowInfo,"%d",&Num);//当前行内容表示线数目Lines.RemoveAll();//内存中所有线清空for(inti=0;iReadInfo(file);l->AddActivePoint(pDoc);Lines.Add(l);}}elseif(strcmp(NowInfo,"[bus]")==0)//读取器件{CObjectBus*B=newCObjectBus;//把指针指向一个新的器件B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);//把总线器件对象加入器件表}elseif(strcmp(NowInfo,"[D8253]")==0)//判断读取信息是否为8253芯片信息{D8253*B=newD8253(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}elseif(strcmp(NowInfo,"[D8255]")==0)//如果是8255信息{DComponent*B=newD8255(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}elseif(strcmp(NowInfo,"[D8259]")==0)//如果是8259信息{DComponent*B=newD8259(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}elseif(strcmp(NowInfo,"[D8237]")==0)//如果是8237信息{DComponent*B=newD8237(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}elseif(strcmp(NowInfo,"[D74LS138]")==0)//如果D74LS138信息{DComponent*B=newD74LS138(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}elseif(strcmp(NowInfo,"[DLED]")==0)//如果是DLED信息{DComponent*B=newDLed(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}elseif(strcmp(NowInfo,"[DBUS]")==0)//如果是DBUS信息{DComponent*B=newDBus(this);B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);pCPU=B;}elseif(strcmp(NowInfo,"[8253]")==0){CObject8253*B=newCObject8253;B->ReadInfo(file,pDoc);DObject.Add((CObject*)B);}}}fclose(file);//关闭文件UpdateAllViews(NULL);return1;}1.2添加新线操作voidCVisualexView::AddNewLine(CDC*pDC){point1=point2;CVisualexDoc*pDoc=GetDocument();CLine*pLine=newCLine(point0,point1);//在文档类加一条新直线inti=pDoc->CheckLine(pLine);if(i){pDoc->Lines.RemoveAt(i-1);ReleaseCapture();}else{pLine->LineType=0;pLine->EleCol=2;pDoc->Lines.Add(pLine);pDoc->SetModifiedFlag(TRUE);//设置文档修改标志,当未保存时提示CLineline(point0,point1);line.Draw(pDC);AddActivePointInfo(point0,point1);ReleaseCapture();pDoc->SetModifiedFlag();//设置文档修改标志}Invalidate();}1.3对添加新线的保存操作voidCVisualexDoc::Serialize(CArchive&ar){CStringstr;if(ar.IsStoring()){//TODO:在此添加存储代码//str.Format("%d\n",Lines.Serialize(ar);}else{//TODO:在此添加加载代码CObArraytLines;tLines.Serialize(ar);intsize=(int)tLines.GetSize();inti;for(i=0;iAddActivePoint(this);Lines.Add(l);}}}1.4读取保存的连线操作intCLine::ReadInfo(FILE*file){charNowInfo[255];fgets(NowInfo,255,file);sscanf(NowInfo,"%d,%d;%d,%d",&Start.x,&Start.y,&End.x,&End.y);return0;}