示例#1
0
文件: Unit.cpp 项目: BRAT-DEV/main
//----------------------------------------
bool CUnit::HasDateRef(CDate* dateRef /*= NULL*/, CStringArray* array /*= NULL*/) const
{
  if (!IsDate())
  {
    return false;
  }

  CStringArray ar;

  ar.ExtractStrings(GetText().c_str(), ' ');

  size_t len = ar.size();


  if (len <= 2)
  {
    return false;
  }

  int32_t index = ar.FindIndex("since");

  if (index < 0)
  {
    return false;
  }

  CDate dateTmp;

  int32_t result = BRATHL_ERROR;
  std::string strDate;

  for (uint32_t i = index + 1 ; i < ar.size() ; i++)
  {
    strDate.append(ar.at(i));
    strDate.append(" ");

  }

  strDate = CTools::StringTrim(strDate);
  
  result = dateTmp.SetDate(strDate.c_str());

  if (result == BRATHL_SUCCESS)
  {
    if (dateRef != NULL)
    {
      *dateRef = dateTmp;
    }
  }
  
  if (array != NULL)
  {
    array->Insert(ar);
  }

  return (result == BRATHL_SUCCESS);
}
void
ESSimpleRenderView::AddText(_string sStyleName, _string sText, bool bLineBreak, COLORREF crText, _Size szText, float fCX, float fPosX /*= 0.0f*/, int nVAlign, int nHAlign, bool bRedraw){
	ESSimpleRenderView_TextStyle* pStyle = (ESSimpleRenderView_TextStyle*)GetTextStyleByName(sStyleName.c_str());
	if( !pStyle ) return;
	/*
	if( !m_pLastLine ){
		m_pLastLine					= new RenderLine();
		m_pRootLine->m_pNextLine	= m_pLastLine;
		m_pLastLine->m_bLineBreak	= bLineBreak;
		bLineBreak					= false;
		}*/

	CStringArray arrStrings;
	StringHelper::Split(&sText, _T("\r\n"), arrStrings);

	RenderItemText* pItemNew	= NULL;
	RenderItem*		pItemPrev	= NULL;
	RenderLine*		pLine		= m_pLastLine;
	bool			bNewLine	= false;

	if( !pLine || pLine->m_bLineBreak ){
		RenderLine* pNewLine	= new RenderLine();
		pNewLine->m_pPrevLine	= pLine;

		if( !pLine ){
			m_pLastLine					= pNewLine;
			m_pRootLine->m_pNextLine	= m_pLastLine;
			m_pLastLine->m_bLineBreak	= bLineBreak;
			}
		else{
			pLine->m_pNextLine			= pNewLine;
			}

		pLine					= pNewLine;
		bNewLine				= true;
		}

	pItemPrev = pLine->m_pFirstItem;
	if( pItemPrev ){
		while(pItemPrev->m_pNext)
			pItemPrev = pItemPrev->m_pNext;
		}

	int nHeightOld	= pLine->m_szLine.cy; 
	for(int i=0; i<arrStrings.size(); i++){
		RenderItemText* pItemNew	= new RenderItemText();
		pItemNew->m_pLine			= pLine;
		pItemNew->m_pStyle			= pStyle;
		pItemNew->m_sText			= arrStrings.at(i);
		pItemNew->m_sTextLocal		= pItemNew->m_sText;
		ESLocalizationMan::ParseText(pItemNew->m_sTextLocal);
		pItemNew->m_nHAlign			= nHAlign;
		pItemNew->m_nVAlign			= nVAlign;
		pItemNew->m_crText			= crText;
		pItemNew->m_fPosX			= fPosX;
		pItemNew->m_fCX				= fCX;

		pStyle->m_font.GetTextSize(&pItemNew->m_sTextLocal, pItemNew->m_szText);
		pItemNew->m_szItem			= pItemNew->m_szText;
		pItemNew->m_szItem.cy		+= 2*m_nTextMarginTopBottom;
		
		if( i > 0 ){
			// Break line on previous item.
			pItemPrev->m_bBreakLine	= true;
			// Set offset of item.
			pItemNew->m_ptOffset.SetPoint(0, pLine->m_szLine.cy);
			// Set size of line height.
			pLine->m_szLine.cy		+= pItemNew->m_szText.cy;
			}
		else{
			pLine->m_szLine.cx		+= pItemNew->m_szItem.cx;
			pLine->m_szLine.cy		= std::max(pLine->m_szLine.cy, pItemNew->m_szItem.cy);
			}
		
		if( pItemPrev )
			pItemPrev->m_pNext = pItemNew;
		else
			pLine->m_pFirstItem = pItemNew;
		pItemNew->m_pPrev = pItemPrev;
		pItemPrev = pItemNew;		
		}

	CalcLineSize(pLine);
	if( bNewLine ){
		m_nContentHeight	+= pLine->m_szLine.cy;
		m_pLastLine			= pLine;
		}
	else
		m_nContentHeight	+= (pLine->m_szLine.cy - nHeightOld);

	m_nTopFullOffsetY	= 0;
	if( m_szView.cy != m_nContentHeight ){
		m_szView.cy		= m_nContentHeight;
		if( IsCreated() )
			AdjustScrollBarPos(bRedraw);
		}

	pLine->m_bLineBreak = bLineBreak;
	if( bRedraw ){
		_Rect rcLine;
		if( IsLineVisible(pLine, rcLine) )
			RedrawRect(rcLine, false);
		//Redraw(true);
		}
	}
示例#3
0
文件: Plot.cpp 项目: adakite/main
//----------------------------------------
void CPlot::GetInfo()
{

  CUnit unitXRead;
  CUnit unitYRead;

  string unitXStr;
  string unitYStr;

  bool assignYUnit = true;
  bool assignYTitle = true;
  bool assignXUnit = true;
  bool assignXTitle = true;

  CObArray allInternalFiles(false);


  GetAllInternalFiles(allInternalFiles);
  int32_t nrFiles = allInternalFiles.size();

  //int32_t iField = 0;
  int32_t nrFields = m_fields.size();
  CObArray::iterator itField;
  CObArray::iterator itFile;

  CStringArray plotFieldNames;

  for (itField = m_fields.begin() ; itField != m_fields.end() ; itField++)
  {
    CPlotField* field = CPlotField::GetPlotField(*itField);
    string fieldName = (const char *)(field->m_name);

    plotFieldNames.InsertUnique(fieldName);

    if ((field->m_xyProps != NULL) && (m_title.IsEmpty()) )
    {
      m_title = field->m_xyProps->GetTitle();
    }

    for (itFile = field->m_internalFiles.begin() ; itFile != field->m_internalFiles.end() ; itFile++)
    {

      CInternalFiles* yfx = CPlot::GetInternalFiles(*itFile);
      //-----------------------------------
      // Get plot Title --> title of the first file
      //-----------------------------------
      if (m_title.IsEmpty())
      {
        m_title = yfx->GetTitle("").c_str();
      }

      //-----------------------------------
      // Get and control unit of X axis
      //-----------------------------------
      string varXName;
      GetAxisX(yfx, NULL, NULL, &varXName);

      unitXRead = yfx->GetUnit(varXName);


      if (assignXUnit)
      {
        m_unitX = unitXRead;
        unitXStr = m_unitX.AsString();
        m_unitXLabel = "\nUnit:\t" + wxString(m_unitX.GetText().c_str());
        assignXUnit = false;
      }
      else
      {
        string unitXReadStr = unitXRead.AsString();
        if (m_unitX.IsCompatible(unitXRead) == false)
        {
          string msg = CTools::Format("CPlot::CkeckUnits - In group field number %d, X field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis X - File name is '%s'",
                                       m_groupNumber,
                                       unitXStr.c_str(),
                                       unitXReadStr.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer("%s", e.what());
          throw (e);

        }
        if (unitXStr.compare(unitXReadStr) != 0)
        {
          m_unitXConv = true;
        }
      }
      //-----------------------------------
      // Get title of X axis
      //-----------------------------------
      string titleX;

      if (m_titleX.IsEmpty())
      {
        titleX = yfx->GetTitle(varXName);
        if (titleX.empty())
        {
          titleX = varXName;
        }
      }

      if (assignXTitle)
      {
        m_titleX += titleX.c_str() + m_unitXLabel;
        assignXTitle = false;
      }

      //--------------------------------------------------------
      // Get and control unit of Y axis --> unit of each field
      //---------------------------------------------------------
      unitYRead = yfx->GetUnit(fieldName);

      if ( assignYUnit )
      {
        m_unitY = unitYRead;
        unitYStr = m_unitY.AsString();
        m_unitYLabel = "\nUnit:\t" + wxString(m_unitY.GetText().c_str());
        assignYUnit = false;
      }
      else
      {
        string unitYReadStr = unitYRead.AsString();
        if (m_unitY.IsCompatible(unitYRead) == false)
        {
          string msg = CTools::Format("CXYPlotData::Create - In group field number %d, Y field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis Y - Field name is '%s' - File name is '%s'",
                                       m_groupNumber,
                                       unitYStr.c_str(),
                                       unitYReadStr.c_str(),
                                       fieldName.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer("%s", e.what());
          throw (e);

        }
        if (unitYStr.compare(unitYReadStr) != 0)
        {
          m_unitYConv = true;
        }
      }

      //-----------------------------------
      // Get title of Y axis (as possible)
      //-----------------------------------

      string titleY;

      if ((nrFields == 1) && (nrFiles <= 1))
      {
        if (m_titleY.IsEmpty())
        {
          titleY = yfx->GetTitle(fieldName);
          if (titleY.empty())
          {
            titleY = fieldName;
          }
        }
      }

      if (assignYTitle)
      {
        m_titleY += titleY.c_str() + m_unitYLabel;
        assignYTitle = false;
      }


    } // end for (itFile = ...

  } //  end for (itField = ...

  //CTrace::GetInstance()->SetTraceLevel(5);
  //plotFieldNames.Dump(*(CTrace::GetInstance()->GetDumpContext()));

  if (plotFieldNames.size() > 0)
  {
    for (itFile = allInternalFiles.begin() ; itFile != allInternalFiles.end() ; itFile++)
    {
      CInternalFiles* yfx = CPlot::GetInternalFiles(*itFile);

      if (yfx == NULL)
      {
        continue;
      }

      CStringArray complement;

      yfx->GetComplementVars(plotFieldNames, complement);

      CStringArray::iterator itStringArray;
      for (itStringArray = complement.begin() ; itStringArray != complement.end(); itStringArray++)
      {
        CNetCDFVarDef* v1Def = yfx->GetNetCDFVarDef(plotFieldNames.at(0));
        CNetCDFVarDef* v2Def = yfx->GetNetCDFVarDef(*itStringArray);

        if ((v1Def == NULL) || (v2Def == NULL))
        {
          continue;
        }


        if (yfx->GetFile()->HaveEqualDimNames(plotFieldNames.at(0), *itStringArray))
        {
          m_nonPlotFieldNames.InsertUnique(*itStringArray);
        }

      }

      //complement.Dump(*(CTrace::GetInstance()->GetDumpContext()));


    }

    //m_nonPlotFieldNames.Dump(*(CTrace::GetInstance()->GetDumpContext()));
  }

/*


  for (iFile = 0 ; iFile < nrFiles ; iFile++)
  {
    CInternalFilesYFX* yfx = GetInternalFilesYFX(allInternalFiles.at(iFile));
    //-----------------------------------
    // Get plot Title --> title of the first file
    //-----------------------------------
    if (m_title.IsEmpty())
    {
      m_title = yfx->GetTitle("").c_str();
    }

    //-----------------------------------
    // Get and control unit of X axis
    //-----------------------------------
    string varXName;
    GetAxisX(yfx, NULL, NULL, &varXName);

    unitXRead = yfx->GetUnit(varXName);



    //--------------------------------------------------------
    // Get and control unit of Y axis --> unit of each field
    //---------------------------------------------------------

    //int32_t iField = 0;
    int32_t nrFields = m_fields.size();
    CObArray::iterator itField;

    for (itField = m_fields.begin() ; itField != m_fields.end() ; itField++)
    {

      if (assignXUnit)
      {
        m_unitX = unitXRead;
        unitXStr = m_unitX.AsString();
        m_unitXLabel = "\nUnit:\t" + wxString(m_unitX.GetText().c_str());
        assignXUnit = false;
      }
      else
      {
        string unitXReadStr = unitXRead.AsString();
        if (m_unitX.IsCompatible(unitXRead) == false)
        {
          string msg = CTools::Format("CPlot::CkeckUnits - In group field number %d, X field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis X - File name is '%s'",
                                       m_groupNumber,
                                       unitXStr.c_str(),
                                       unitXReadStr.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer(e.what());
          throw (e);

        }
        if (unitXStr.compare(unitXReadStr) != 0)
        {
          m_unitXConv = true;
        }
      }
      //-----------------------------------
      // Get title of X axis
      //-----------------------------------
      string titleX;

      if (m_titleX.IsEmpty())
      {
        titleX = yfx->GetTitle(varXName);
        if (titleX.empty())
        {
          titleX = varXName;
        }
      }

      //if (iFile == 0)
      if (assignXTitle)
      {
        m_titleX += titleX.c_str() + m_unitXLabel;
        assignXTitle = false;
      }


      CPlotField* field = CPlotField::GetPlotField(*itField);
      string fieldName = field->m_name.c_str();

      unitYRead = yfx->GetUnit(fieldName);

      if ( assignYUnit )
      {
        m_unitY = unitYRead;
        unitYStr = m_unitY.AsString();
        m_unitYLabel = "\nUnit:\t" + wxString(m_unitY.GetText().c_str());
        assignYUnit = false;
      }
      else
      {
        string unitYReadStr = unitYRead.AsString();
        if (m_unitY.IsCompatible(unitYRead) == false)
        {
          string msg = CTools::Format("CXYPlotData::Create - In group field number %d, Y field unit are not in the same way (not compatible)"
                                      "- Expected unit '%s' and found '%s' for axis Y - Field name is '%s' - File name is '%s'",
                                       m_groupNumber,
                                       unitYStr.c_str(),
                                       unitYReadStr.c_str(),
                                       fieldName.c_str(),
                                       yfx->GetName().c_str());
          CException e(msg, BRATHL_INCONSISTENCY_ERROR);
          CTrace::Tracer(e.what());
          throw (e);

        }
        if (unitYStr.compare(unitYReadStr) != 0)
        {
          m_unitYConv = true;
        }
      }

      //-----------------------------------
      // Get title of Y axis (as possible)
      //-----------------------------------

      string titleY;

      if ((nrFields == 1) && (nrFiles <= 1))
      {
        if (m_titleY.IsEmpty())
        {
          titleY = yfx->GetTitle(fieldName);
          if (titleY.empty())
          {
            titleY = fieldName;
          }
        }
      }

      if (assignYTitle)
      {
        m_titleY += titleY.c_str() + m_unitYLabel;
        assignYTitle = false;
      }
    }
  }


*/
}