Exemplo n.º 1
0
void CCopyBlock::BuildBlockTagsList(char* ModelClass, char* BlockName, BOOL FromDatalib, CSVector& List)
  {
  int Cnt = 0;
  List.SetSize(16);
  Strng Section;
  Section.Set("%s(%s)", BlockName, ModelClass);
  char Buff[16384];
  CProfINIFile PF(FromDatalib ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName);
  CheckCopyBlockVer(PF);
  DWORD dw = PF.RdSection(Section(), Buff, sizeof(Buff));
  ASSERT(dw<sizeof(Buff)-2); //section too large!!!
  char* p = Buff;
  while (p[0])
    {
    int len = strlen(p);
    char* Nextp = p;
    Nextp += (len + 1);
    char* pp = strchr(p, '=');
    if (pp)
      {
      if (Cnt>=List.GetSize())
        List.SetSize(List.GetSize()+8);
      pp[0] = 0;
      char* pValue = &pp[1];
      char* ppp = strchr(p, '.');
      if (ppp)
        List[Cnt].Set("x%s (%s)", ppp, pValue);
      else
        List[Cnt].Set("%s (%s)", p, pValue);
      Cnt++;
      }
    p = Nextp;
    }
  List.SetSize(Cnt);
  }
Exemplo n.º 2
0
BOOL DocRoot::SaveDocument(const char* pszPathName)
  {
  if (gs_Exec.Busy())
    {
    LogError("SysCAD", 0, "Must not be running");
    return False;
    }
  char Fn[512];
  CString TmpFn;
  if (pszPathName==NULL)
    {
    TmpFn=GetTitle();
    pszPathName = TmpFn.GetBuffer(0);
    }
  
  if (strpbrk(pszPathName, ":\\")==NULL)
    {
    strcpy(Fn, PrjFiles());
    strcat(Fn, pszPathName);
    }
  else
    strcpy(Fn, pszPathName);

  CString Ext;
  VERIFY(GetDocTemplate()->GetDocString(Ext, CDocTemplate::filterExt));
  pchar ext=Ext.GetBuffer(0);
  const int l=strlen(Fn);
  const int el=strlen(ext);
  if (l<=el)
    strcat(Fn, ext);
  else if (_stricmp(&Fn[l-el], ext)!=0)
    {
    if (Fn[l-el]=='.')
      Fn[l-el]=0; //"old" or "incorect" extension needs to be replaced
    strcat(Fn, ext);
    }

  FILE* pFile= fopen(Fn, "wt");
  flag b=(pFile!=NULL);

  if (b)
    b=WriteDocument(Fn, pFile);

  if (pFile) 
    fclose(pFile);
  if (b)
    {
    SetPathName(Fn);
    SetModifiedFlag(FALSE);
    gs_pCmd->Print("%s - Saved\n", Fn);
    }
  else
    {
    gs_pCmd->Print("%s - NOT SAVED\n", Fn);
    }
  return b;
  }
Exemplo n.º 3
0
void CCopyBlock::MoveBlockLocation(char* ModelClass, char* BlockName, BOOL ToDatalib)
  {
  Strng s;
  s.Set("%s(%s)", BlockName, ModelClass);
  char Buff1[16];
  CProfINIFile SrcPF(ToDatalib ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName);
  if (!CheckCopyBlockVer(SrcPF, true))
    return;
  if (SrcPF.RdSection(s(), Buff1, sizeof(Buff1))>0)
    {
    char Buff[16384];
    DWORD dw = SrcPF.RdSection(s(), Buff, sizeof(Buff));
    ASSERT(dw<sizeof(Buff)-2); //section too large!!!
    CProfINIFile DstPF(ToDatalib ? PrjFiles() : CfgFiles(), (char*)CopyBlkFileName);
    if (!CheckCopyBlockVer(DstPF, true))
      return;
    DstPF.WrSection(s(), Buff);
    Buff1[0] = 0;
    Buff1[1] = 0;
    SrcPF.WrSection(s(), Buff1);
    }
  }
Exemplo n.º 4
0
BOOL OleDocRoot::OnNewDocument()
  {
  if (!COleLinkingDoc::OnNewDocument())
    return False;
  
  if (gs_Exec.Busy())
    {
    LogError("SysCAD", 0, "Must not be running");
    return False;
    }

  if (gs_pPrj->pPrjDoc==NULL && !gs_pPrj->bDoingLoad)//sPrjFile.Length() > 0)
    {
    LogError("SysCAD", 0, "A project must be opened or a new project created.");
    return False;
    }

  /*CString s = GetTitle();
  Strng T = PrjFiles();
  T += (const char*)s;
  GetDocTemplate()->GetDocString(s, CDocTemplate::filterExt);
  T += (const char*)s;
  SetPathName(T());
  Strng T1,T2;
  T1.FnName(T());
  T2.FnExt(T());
  T = T1;
  T += T2;
  SetTitle(T());*/

  gs_pCmd->ProcessAStr("\x1b"); //Ensure there are no half complete commands
  gs_pCmd->ProcessAStr("\x1b"); //Ensure there are no half complete commands, call more than once!

  CString s;
  GetDocTemplate()->GetDocString(s, CDocTemplate::filterExt);
  m_strReqdPathName = PrjFiles();
  m_strReqdPathName += (LPCTSTR)GetTitle();
  m_strReqdPathName += (LPCTSTR)s;

//  OnAttachDoc();
//  OnActivate(True);

  //gs_pCmd->SetDocForCmds(this);
  //gs_pCmd->ProcessAStr("CLEAR DOCUMENT \r");
  //gs_pCmd->SetDocForCmds(NULL);
  bIsOpen = True;
  return True;
  }
Exemplo n.º 5
0
void CCopyBlock::BuildBlockList(char* ModelClass, CSVector& List, CWordArray& FlagList, int& DefaultIndex)
  {
  DefaultIndex = -1;
  Strng s,Block;
  s.Set("(%s)", ModelClass);
  List.SetSize(16);
  FlagList.SetSize(16);
  int Cnt = 0;
  char Buff[16384];
  char Buff1[16];
  for (int i=0; i<2; i++)
    {
    CProfINIFile PF(i==0 ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName);
    CheckCopyBlockVer(PF);
    DWORD dw = PF.RdSectionNames(Buff, sizeof(Buff));
    ASSERT(dw<sizeof(Buff)-2); //section too large!!!
    char* p = Buff;
    while (p[0])
      {
      int len = strlen(p);
      char* Nextp = p;
      Nextp += (len + 1);
      char* pp = strstr(p, s());
      if (pp)
        {
        if (PF.RdSection(p, Buff1, sizeof(Buff1))>0)
          {
          Block = p;
          Block.SetLength((int)(pp-p));
          if (i==0 || List.Find(Block())<0)
            {
            if (Cnt>=List.GetSize())
              {
              List.SetSize(List.GetSize()+8);
              FlagList.SetSize(FlagList.GetSize()+8);
              }
            List[Cnt] = Block;
            FlagList[Cnt] = (i==0 ? 1 : 0);
            Cnt++;
            }
          }
        }
      p = Nextp;
      }
    }
  List.SetSize(Cnt);
  FlagList.SetSize(Cnt);
  }
Exemplo n.º 6
0
void CCopyBlock::RemoveBlock(char* ModelClass, char* BlockName)
  {
  Strng s;
  s.Set("%s(%s)", BlockName, ModelClass);
  char Buff[16];
  for (int i=0; i<2; i++)
    {
    CProfINIFile PF(i==0 ? CfgFiles() : PrjFiles(), (char*)CopyBlkFileName);
    if (CheckCopyBlockVer(PF, true) && PF.RdSection(s(), Buff, sizeof(Buff))>0)
      {
      Buff[0] = 0;
      Buff[1] = 0;
      PF.WrSection(s(), Buff);
      }
    }
  }
Exemplo n.º 7
0
BOOL DocRoot::OpenDocument(const char* pszPathName)
  {
  if (gs_Exec.Busy())
    {
    LogError("SysCAD", 0, "Must not be running");
    return False;
    }

  SetModifiedFlag(FALSE);
  gs_pPrj->bDocChanged=0;
  
  char Fn[512];
  if (strpbrk(pszPathName, ":\\")==NULL)
    {
    strcpy(Fn, PrjFiles());
    strcat(Fn, pszPathName);
    }
  else
    strcpy(Fn, pszPathName);
  CString Ext;
  VERIFY(GetDocTemplate()->GetDocString(Ext, CDocTemplate::filterExt));
  //GetDocTemplate()->GetDocString(Ext, CDocTemplate::filterExt);
  pchar ext=Ext.GetBuffer(0);
  const int l=strlen(Fn);
  const int el=strlen(ext);
  if (l<=el || (_stricmp(&Fn[l-el], ext)!=0 && Fn[l-el]!='.'))
    strcat(Fn, ext);

  FILE* pFile= fopen(Fn, "rt");
  flag b=(pFile!=NULL);
   
  if (b && !feof(pFile))
    b=ReadDocument(Fn, pFile);

  if (pFile) 
    fclose(pFile);
  if (b)
    {
    SetPathName(Fn);
    //LogNote("Document", 0, "Loaded : %s", Fn); Who really wants to know?
    }
  else
    {
    LogError("Document", 0, "NOT Loaded : %s", Fn);
    }
  return b;
  }
Exemplo n.º 8
0
BOOL DocRoot::OnNewDocument()
  {
  if (!CDocument::OnNewDocument())
    return False;
  
  if (gs_Exec.Busy())
    {
    LogError("SysCAD", 0, "Must not be running");
    return False;
    }

  if (gs_pPrj->pPrjDoc==NULL && !gs_pPrj->bDoingLoad)//sPrjFile.Length() > 0)
    {
    LogError("SysCAD", 0, "A project must be opened or a new project created.");
    return False;
    }

  /*CString s = GetTitle();
  Strng T = PrjFiles();
  T += (const char*)s;
  GetDocTemplate()->GetDocString(s, CDocTemplate::filterExt);
  T += (const char*)s;
  SetPathName(T());
  Strng T1,T2;
  T1.FnName(T());
  T2.FnExt(T());
  T = T1;
  T += T2;
  SetTitle(T());*/

  gs_pCmd->ProcessAStr("\x1b"); //Ensure there are no half complete commands
  gs_pCmd->ProcessAStr("\x1b"); //Ensure there are no half complete commands, call more than once!

  CDocTemplate* pTemplate = GetDocTemplate();
  CString s;
  bool GrfChangeName = false;
  if (1)
    {
    pTemplate->GetDocString(s, CDocTemplate::filterExt);
    if (s==".scg")
      {
      s = "05_Flowsheet.scg";
      SetTitle(s); //this may alter title;
      GrfChangeName = true;
      //ChooseTitle(this, s);
      //SetTitle(s);
      }

    }
  if (!GrfChangeName)
    {
    s = GetTitle();
    Strng T = (const char*)s;
    pTemplate->GetDocString(s, CDocTemplate::filterExt);
    T += (const char*)s;
    SetTitle(T()); //this may alter title;
    }
  Strng PathN = PrjFiles();
  s = GetTitle();
  PathN += (const char*)s;
  SetPathName(PathN()); //do this AFTER SetTitle

  OnAttachDoc();
  OnActivate(True);

  //gs_pCmd->SetDocForCmds(this);
  //gs_pCmd->ProcessAStr("CLEAR DOCUMENT \r");
  //gs_pCmd->SetDocForCmds(NULL);
  bIsOpen = True;
  return True;
  }
Exemplo n.º 9
0
int CLimnStream::LoadArrayData(LPCTSTR RangeName, double Scale, int Cols, int Rows, CArray<double,double> &Data, MLog * pLog)
  {
  int N=0;

  Dbg.PrintLn("LoadArrayData:%s",RangeName);

  CFeed &Fd = *m_pFeed;

  return ::LoadArrayData(PrjFiles(), Fd.m_sSrcName, Fd.m_iSource, RangeName, Scale, Cols, Rows, Data, pLog);

  //CString Fn(PrjFiles());
  //Fn+=Fd.m_sSrcName;
  //switch (Fd.m_iSource)
  //  {
  //  case 0: // CSV
  //    {
  //    Fn+=".";
  //    Fn+=RangeName;
  //    if (Fn.Right(4).CompareNoCase(".CSV")!=0)
  //      Fn+=".CSV";


  //    FILE* f=fopen(Fn, "rt");
  //    if (f)
  //      {
  //      for (int r=0; r<Rows; r++)
  //        {
  //        char Buff[16000];
  //        if (fgets(Buff, sizeof(Buff)-1, f))
  //          {
  //          CSVColArray Tkns;
  //          int NTkns=ParseCSVTokens(Buff, Tkns);
  //          for (int c=0; c<Cols; c++)
  //            Data.SetAtGrow(c + r*Cols, c<NTkns ? SafeAtoF(Tkns[c])*0.01 : 0.0);
  //          }
  //        }
  //      fclose(f);
  //      }
  //    else
  //      {
  //      Log.Message(MMsg_Error, "CSV File %s not opened", Fn);
  //      }
  //    break;
  //    }
  //  case 1: //XLS
  //    {
  //    Log.Message(MMsg_Error, "XLS Files not yet implemented");
  //    break;
  //    }
  //  }

  //for (int r= 0; r< Rows; r++ )
  //  {
  //  Dbg.Print("%s:", RangeName);
  //  for (int c= 0 ; c<Cols; c++ )
  //    Dbg.Print(" %10.4f", Data[xlIndex(r, c, Cols)]);
  //  Dbg.PrintLn("");
  //  }

  //return Data.GetCount();
  }
Exemplo n.º 10
0
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;
  }