int CCopyBlock::CopyTagBlocks() { CWaitCursor Wait; // ASSERT(eSrc!=CB_List); //this src type not allowed // ASSERT(eDst!=CB_Tag); //this dst type not allowed ASSERT(pEO); CProfINIFile SrcPF(bSrcDatalib ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName); CheckCopyBlockVer(SrcPF); CProfINIFile DstPF(bDstDatalib ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName); if (!CheckCopyBlockVer(DstPF, true)) return 0; int Cnt = 0; //gs_pTheSFELib->FE_SetHoldGlobalLinks(true); //gs_Exec.SetHoldValidateData(true, true, true); gs_Exec.BeginBulkChange(); Strng Section; if (eSrc==CB_SelectedTag) Section = TempBlockName; else Section.Set("%s(%s)", sSrc(), sModelClass()); char Buff[16384]; DWORD dw = SrcPF.RdSection(Section(), Buff, sizeof(Buff)); ASSERT(dw<sizeof(Buff)-2); //section too large!!! if (eDst==CB_Block) { Strng DstSection; DstSection.Set("%s(%s)", sDst(), sModelClass()); DstPF.WrSection(DstSection(), Buff); } else { Strng_List sStrList; CXM_Route Route; CXM_ObjectData ObjData; char* p = Buff; while (p[0]) { int len = strlen(p); char* Nextp = p; Nextp += (len + 1); char* pp = strchr(p, '='); if (pp) { pp[0] = 0; char* pValue = &pp[1]; char* ppp = strchr(p, '.'); Strng PartTag; PartTag = (ppp==NULL ? p : ppp); for (int i=0; i<TagList.GetSize(); i++) { Strng WrkTag(TagList[i]()); WrkTag += PartTag; //CXM_ObjectTag ObjTag(WrkTag(), 0); //need to use TABOpt_AllInfoOnce because of tags that contain a strList! CXM_ObjectTag ObjTag(WrkTag(), TABOpt_AllInfoOnce);//0);//TABOpt_Exists);//TABOpt_Parms);//TABOpt_ValCnvsOnce); Route.Clear(); if (pEO->XReadTaggedItem(ObjTag, ObjData, Route)) { CPkDataItem * pItem = ObjData.FirstItem(); byte cType = pItem->Type(); PkDataUnion DU; if (IsStrng(cType)) DU.SetTypeString(cType, pValue); else if (IsFloatData(cType)) DU.SetTypeDouble(cType, SafeAtoF(pValue)); else if (IsIntData(cType) && pItem->Contains(PDI_StrList)) { pItem->GetStrList(sStrList); pStrng pS = sStrList.Find(pValue); //const int Indx = (pS==NULL ? 0 : sStrList.Index(pS)); const int Indx = (pS==NULL ? 0 : pS->Index()); DU.SetTypeLong(cType, Indx); } else DU.SetTypeLong(cType, SafeAtoL(pValue)); CXM_ObjectData OD(0, 0, WrkTag(), 0, DU); if (pEO->XWriteTaggedItem(OD, Route)==TOData_NotFound) LogWarning(WrkTag(), 0, "Write tag failed"); else Cnt++; //if (pEO->XWriteTaggedItem(OD, Route)!=TOData_OK) // LogWarning(WrkTag(), 0, "Write tag failed (possibly invalid data)"); } else LogWarning(WrkTag(), 0, "Unable to read tag"); } } p = Nextp; } } //TaggedObject::SetHoldValidateData(false); //gs_Exec.SetHoldValidateData(false, true, true); //gs_pTheSFELib->FE_SetHoldGlobalLinks(false); gs_Exec.EndBulkChange(); //TaggedObject::SetXWritesBusy(false); return Cnt; }
long CSlotConnPrf::Parse(LPCSTR File) { if (!FileExists((LPTSTR)File)) return 1; //m_sTag.FnName((LPTSTR)File); m_bYReversed=false; long RetCode=0; Strng Ext; Ext.FnExt((LPTSTR)File); if (Ext.XStrICmp(".txt")==0 || Ext.XStrICmp(".csv")==0) { FILE *h=fopen(File, "rt"); if (h) { char Buff[4096]; CSVColArray c; int Quote; int nFlds = 0; Buff[0]=0; while (strlen(Buff)==0 && fgets(Buff, sizeof(Buff), h)) XStrLTrim(Buff, " \t\n"); nFlds = ParseCSVTokens(Buff, c, Quote); if (nFlds>0) { if (_stricmp(Buff, "ABS")==0) m_Mode=eABS; else if (_stricmp(Buff, "SCL")==0) m_Mode=eSCL; else if (_stricmp(Buff, "SCL%")==0) m_Mode=eSCLPERC; else if (_stricmp(Buff, "CONTRONIC")==0) m_Mode=eCONTRONIC; else { return 4; goto Leave; } if (m_Mode==eCONTRONIC) { while (fgets(Buff, sizeof(Buff), h)) { int nFlds = ParseTokenList(Buff, c, "=:"); if (nFlds>=3) { CSlotConnPrfPt Pt; Pt.X=(float)SafeAtoF(c[1]); Pt.Y=(float)SafeAtoF(c[2]); m_Points.Add(Pt); } else if (m_Points.GetSize()>0) break; } } else { while (fgets(Buff, sizeof(Buff), h)) { int nFlds = ParseCSVTokens(Buff, c, Quote); if (nFlds>=2) { CSlotConnPrfPt Pt; Pt.X=(float)SafeAtoF(c[0]); Pt.Y=(float)SafeAtoF(c[1]); m_Points.Add(Pt); } else if (m_Points.GetSize()>0) break; } } if (m_Points.GetSize()<2) { RetCode=5; goto Leave; } m_bYReversed=m_Points[0].Y> m_Points[m_Points.GetUpperBound()].Y; fclose(h); } else RetCode=4; } else RetCode=2; Leave: if (h) fclose(h); return RetCode; } else return 3; };