int _tmain(int argc, _TCHAR* argv[])
{
	CStratege* stratege = new CStrategeB();
	CContext* context = new CContext(stratege);
	context->operation();
	return 0;
}
bool CConfigParser::ParseContexts(DOMNodeList* contextNodes, ADeviceListener& configClass)
{
	ASSERT(contextNodes->getLength() == 1);
	DOMNode* contextNode = contextNodes->item(0);
	DOMNodeList* contexts = contextNode->getChildNodes();
	for(unsigned long idx = 0; idx < contexts->getLength(); idx++)
	{
		DOMNode* currentContext = contexts->item(idx);
		wstring contextNodeName = currentContext->getNodeName();
		if(contextNodeName.compare(L"#text") == 0)
			continue;
		wstring contextName = currentContext->getAttributes()->getNamedItem(L"name")->getNodeValue();
		CContext* contextToAdd = new CContext();
		unsigned long attrLen = currentContext->getAttributes()->getLength();
		for(unsigned long attr = 0; attr < attrLen; attr++)
		{
			DOMNode* deviceContextAttr = currentContext->getAttributes()->item(attr);
			if(wcscmp(deviceContextAttr->getNodeName(), L"deviceContext") == 0)
			{
				wstring deviceContextName = deviceContextAttr->getNodeValue();
				CDeviceContext* deviceContext = configClass.GetDeviceContexts()[deviceContextName];
				IDeviceCapture* device = configClass.GetDevices()[deviceContext->GetDeviceName()];
				contextToAdd->AddDeviceContext(device, deviceContext);
			}
		}
		configClass.AddContext(contextName, contextToAdd);
	}
	return true;
}
Beispiel #3
0
 void cxios_solve_inheritance()
 {
   CTimer::get("XIOS").resume();
   CContext* context = CContext::getCurrent();
   context->solveAllInheritance(false);
   CTimer::get("XIOS").suspend();
 }
Beispiel #4
0
   void cxios_set_variable_data_char(const char* varId, int varIdSize, const char* data, int dataSizeIn, bool* isVarExisted)
   {
      std::string varIdStr, dataStr;
      if (!cstr2string(varId, varIdSize, varIdStr)) return;
      if (!cstr2string(data, dataSizeIn, dataStr))
      {
        *isVarExisted = false;
        return;
      }

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS set variable data").resume();

      CContext* context = CContext::getCurrent();
      *isVarExisted = CVariable::has(context->getId(), varIdStr);

      if (*isVarExisted)
      {
        CVariable::get(context->getId(), varIdStr)->setData<string>(dataStr);
        //CVariable::get(context->getId(), varIdStr)->sendValue();
      }

      CTimer::get("XIOS set variable data").suspend();
      CTimer::get("XIOS").suspend();
   }
Beispiel #5
0
int _tmain(int argc, _TCHAR* argv[])
{
    CContext context;

    CConcreteStrategyA *pconcreteA = new CConcreteStrategyA();
    ClientToUseContext( &context );
    context.SetStrategyObj( pconcreteA );
    ClientToUseContext( &context );

    CConcreteStrategyB *pconcreteB = new CConcreteStrategyB();
    context.SetStrategyObj( pconcreteB );
    ClientToUseContext( &context );

    CConcreteDefault *pconcrete_default = new CConcreteDefault();
    context.SetStrategyObj( pconcrete_default );
    ClientToUseContext( &context );

    context.SetStrategyObj( nullptr );
    ClientToUseContext( &context );

    delete pconcreteA;
    delete pconcreteB;
    delete pconcrete_default;

	return 0;
}
Beispiel #6
0
void CHmac32::SetKey(const Byte *key, size_t keySize)
{
  UInt32 keyTemp[kBlockSizeInWords];
  size_t i;
  for (i = 0; i < kBlockSizeInWords; i++)
    keyTemp[i] = 0;
  if(keySize > kBlockSize)
  {
    CContext sha;
    sha.Init();
    sha.Update(key, keySize);
    Byte digest[kDigestSize];
    sha.Final(digest);

    for (int i = 0 ; i < kDigestSizeInWords; i++)
      keyTemp[i] =
          ((UInt32)(digest[i * 4 + 0]) << 24) |
          ((UInt32)(digest[i * 4 + 1]) << 16) |
          ((UInt32)(digest[i * 4 + 2]) <<  8) |
          ((UInt32)(digest[i * 4 + 3]));
    keySize = kDigestSizeInWords;
  }
  else
    for (size_t i = 0; i < keySize; i++)
      keyTemp[i / 4] |= (key[i] << (24 - 8 * (i & 3)));
  for (i = 0; i < kBlockSizeInWords; i++)
    keyTemp[i] ^= 0x36363636;
  _sha.Init();
  _sha.Update(keyTemp, kBlockSizeInWords);
  for (i = 0; i < kBlockSizeInWords; i++)
    keyTemp[i] ^= 0x36363636 ^ 0x5C5C5C5C;
  _sha2.Init();
  _sha2.Update(keyTemp, kBlockSizeInWords);
}
Beispiel #7
0
  void cxios_context_close_definition()
 {
   CTimer::get("XIOS").resume();
   CTimer::get("XIOS close definition").resume();
   CContext* context = CContext::getCurrent();
   context->closeDefinition();
   CTimer::get("XIOS close definition").suspend();
   CTimer::get("XIOS").suspend();
 }
Beispiel #8
0
 void cxios_context_finalize()
 {
   CTimer::get("XIOS").resume();
   CTimer::get("XIOS context finalize").resume();
   CContext* context = CContext::getCurrent();
   context->finalize();
   CTimer::get("XIOS context finalize").suspend();
   CTimer::get("XIOS").suspend();
 }
Beispiel #9
0
   void cxios_context_is_initialized(const char* context_id , int len_context_id, bool* initialized)
   {
     std::string str;

     if (!cstr2string(context_id, len_context_id, str)) return;
     CTimer::get("XIOS").resume();
     CContext* context = CContext::get(str, str);
     *initialized=context->isInitialized();
     CTimer::get("XIOS").suspend();
   }
void CDrawLine::PaintHandles( CContext &dc )
{
	dc.SelectBrush(cBLACK);
	dc.SelectPen(PS_SOLID,0,cBLACK);

	CDRect r1(m_point_a.x-2,m_point_a.y-2,m_point_a.x+2,m_point_a.y+2);
	CDRect r2(m_point_b.x-2,m_point_b.y-2,m_point_b.x+2,m_point_b.y+2);
	dc.Rectangle(r1);
	dc.Rectangle(r2);
}
Beispiel #11
0
void* create(IConfig* config, IFactory* factory)
{
    CContext* context = new CContext(config, factory);
    if (!context->create())
    {
        delete context;
        context = NULL;
    }

    return context;
}
Beispiel #12
0
   void cxios_write_data_k80(const char* fieldid, int fieldid_size, double* data_k8, int data_Xsize)
   {
      std::string fieldid_str;
      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS send field").resume();
      CContext* context = CContext::getCurrent();
      if (!context->hasServer && !context->client->isAttachedModeEnabled())
        context->checkBuffersAndListen();
      CArray<double, 1> data(data_k8, shape(data_Xsize), neverDeleteData);
      CField::get(fieldid_str)->setData(data);
      CTimer::get("XIOS send field").suspend();
      CTimer::get("XIOS").suspend();
   }
void CDrawRectOutline::PaintHandles( CContext &dc )
{
	// Put some handles around this object
	CDRect r(m_point_a.x,m_point_a.y,m_point_b.x,m_point_b.y);

	dc.PaintTracker( r );
}
Beispiel #14
0
void CDrawBlockRotate::Paint(CContext &dc, paint_options options)
{
	// Draw marquee
	dc.SelectBrush();
	if (m_point_a.x < m_point_b.x)
	{
		dc.SelectPen(PS_MARQUEE, 1, cBLOCK);
	}
	else
	{
		// Other marquee pen for right to left selection
		dc.SelectPen(PS_MARQUEE2, 1, cBLOCK);
	}

	dc.SetROP2(R2_COPYPEN);
	dc.Rectangle(theArea);
}
Beispiel #15
0
   void cxios_get_variable_data_logic(const char* varId, int varIdSize, bool* data, bool* isVarExisted)
   {
      std::string varIdStr;
      if (!cstr2string(varId, varIdSize, varIdStr)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS get variable data").resume();

      CContext* context = CContext::getCurrent();
      *isVarExisted = CVariable::has(context->getId(), varIdStr);

      if (*isVarExisted)
      {
        *data = CVariable::get(context->getId(), varIdStr)->getData<bool>();
      }

      CTimer::get("XIOS get variable data").suspend();
      CTimer::get("XIOS").suspend();
   }
void CDrawMetaFile::Paint(CContext &dc,paint_options options)
{

  CDPoint sma = m_point_a;
  CDPoint smb = m_point_b;

  CDRect drect(sma.x,sma.y,smb.x,smb.y);
  CRect rect = dc.GetTransform().Scale( drect );
  int rotmir = dc.GetTransform().GetRotMir();

  CImage *pImage = m_pDesign->GetOptions()->GetImage(m_metafile);
  if (pImage)
  {
	  pImage->Paint( *dc.GetDC(), rect, rotmir );
  }
  else
  {
	  CImage::PaintInvalid( *dc.GetDC(), rect );
  }
}
Beispiel #17
0
   void cxios_read_data_k43(const char* fieldid, int fieldid_size, float* data_k4, int data_Xsize, int data_Ysize, int data_Zsize)
   {
      std::string fieldid_str;
      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS recv field").resume();

      CContext* context = CContext::getCurrent();
      if (!context->hasServer && !context->client->isAttachedModeEnabled())
        context->checkBuffersAndListen();

      CArray<double, 3> data(data_Xsize, data_Ysize, data_Zsize);
      CField::get(fieldid_str)->getData(data);
      CArray<float, 3> data_tmp(data_k4, shape(data_Xsize, data_Ysize, data_Zsize), neverDeleteData);
      data_tmp = data;

      CTimer::get("XIOS recv field").suspend();
      CTimer::get("XIOS").suspend();
    }
Beispiel #18
0
   void cxios_get_variable_data_char(const char* varId, int varIdSize, char* data, int dataSizeIn, bool* isVarExisted)
   {
      std::string varIdStr;
      if (!cstr2string(varId, varIdSize, varIdStr)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS get variable data").resume();

      CContext* context = CContext::getCurrent();
      *isVarExisted = CVariable::has(context->getId(), varIdStr);

      if (*isVarExisted)
      {
        int dataSizeOut = CVariable::get(context->getId(), varIdStr)->getData<string>().length();
        strncpy(data, CVariable::get(context->getId(), varIdStr)->getData<string>().c_str(), std::min(dataSizeIn, dataSizeOut));
      }

      CTimer::get("XIOS get variable data").suspend();
      CTimer::get("XIOS").suspend();
   }
STDMETHODIMP CPermissionChecker::HasAccess(
    BSTR bstrLocalUrl,
    VARIANT_BOOL *pfRetVal)
{
	HRESULT rc = E_FAIL;

	try
	{
		if (bstrLocalUrl == NULL || pfRetVal == NULL)
			return ::ReportError(E_POINTER);

		*pfRetVal = VARIANT_FALSE;

		CContext cxt;
		if ( cxt.Init( CContext::get_Server ) != S_OK )
		{
			return ::ReportError( E_NOINTERFACE );
		}

		// Map logical filename to a physical filesystem name
		CComBSTR bstrPhysicalFile;
		HRESULT  hr = cxt.Server()->MapPath(bstrLocalUrl, &bstrPhysicalFile);

		if (SUCCEEDED(hr))
			*pfRetVal = ::DoesUserHaveAccessToFile(bstrPhysicalFile);
		else // failed to map as URL, try as regular path
			*pfRetVal = ::DoesUserHaveAccessToFile(bstrLocalUrl);

	    rc = S_OK;
	}
	catch( alloc_err& )
	{
		rc = E_OUTOFMEMORY;
	}
	catch( ... )
	{
		rc = E_FAIL;
	}
	return rc;
}
Beispiel #20
0
   void cxios_write_data_k47(const char* fieldid, int fieldid_size, float* data_k4,
                             int data_0size, int data_1size, int data_2size,
                             int data_3size, int data_4size, int data_5size,
                             int data_6size)
   {
      std::string fieldid_str;
      if (!cstr2string(fieldid, fieldid_size, fieldid_str)) return;

      CTimer::get("XIOS").resume();
      CTimer::get("XIOS send field").resume();

      CContext* context = CContext::getCurrent();
      if (!context->hasServer && !context->client->isAttachedModeEnabled())
        context->checkBuffersAndListen();

      CArray<float, 7> data_tmp(data_k4, shape(data_0size, data_1size, data_2size, data_3size, data_4size, data_5size, data_6size), neverDeleteData);
      CArray<double, 7> data(data_0size, data_1size, data_2size, data_3size, data_4size, data_5size, data_6size);
      data = data_tmp;
      CField::get(fieldid_str)->setData(data);

      CTimer::get("XIOS send field").suspend();
      CTimer::get("XIOS").suspend();
    }
Beispiel #21
0
void DoNew()
{
    //LiftState.h, LiftState.cpp, OpenningState.h, CloseingState.h, RunningState.h, StoppingState.h
    //Context.h, Context.cpp
    CContext context;
    CLifeState::SetContext(&context);
    context.SetLifeState(CContext::pClosingState);
    context.Close();
    context.Open();
    context.Run();
    context.Stop();
    context.Close();
    context.Close();
    context.Open();
    context.Stop();
    context.Run();
    context.Stop();
}
Beispiel #22
0
BOOL CElemCycleStep::bExecuteNumExchange(int iNum,CElemList *pListExchange, BOOL bCanRead, BOOL bCanWrite,CEnumInterface &EnumInterface)
{
	BOOL bReturn = TRUE;
	CElemExchangeJbus *pElem = NULL;
	BYTE aBuffer[10240];
	CContext Context;
	int iNbrTrame;
	long iSizeToWrite;
	long iSizeToRead;
	int iNbrRetry = NBR_RETRY_EXCHANGE;
	CThreadInterface *pInterface = NULL;

	iNbrTrame = pListExchange->iGetCount();

	if ((iNum < iNbrTrame) && (iNum > -1))
	{
		if (pElem = (CElemExchangeJbus*)pListExchange->pGetAt(iNum))
		{
			if (pElem->m_pTrameJbusRQ && pElem->m_pTrameJbusRP)
			{
				if (pElem->m_pTrameJbusRQ->bAccessAllowed(bCanRead,bCanWrite))
				{

					if (pInterface = EnumInterface.pGetSelectedInterface(pElem->m_pTrameJbusRQ->ucGetNumDest()))
					{
						iNbrRetry = NBR_RETRY_EXCHANGE;
						do
						{
							Context.Reset(TRUE,NULL,aBuffer,sizeof(aBuffer),pInterface->bGetModeInteger(),FALSE);
							iSizeToWrite = pElem->m_pTrameJbusRQ->iGetStreamSize(Context);
							if (iSizeToWrite < sizeof(aBuffer))
							{
								if (bReturn = pElem->m_pTrameJbusRQ->bSerialize(Context))
								{
									iSizeToWrite = Context.iGetCurrentSize();
									iSizeToRead = pElem->m_pTrameJbusRP->iGetStreamSize(Context);
									if (iSizeToRead < Context.m_iSize)
									{
										
										if (bReturn = pInterface->bWriteAndRead(iNum,Context.m_pBuffStart,iSizeToWrite,aBuffer,iSizeToRead,Context.m_iSize, &iSizeToRead,FALSE))
										{
											bReturn = pElem->m_pTrameJbusRP->bUpdateData(aBuffer,iSizeToRead,Context.m_bModeInteger);
											if (!bReturn) 
											{
												TRACE_DEBUG(eDebug,eCycle,_T(__FILE__),_T(__FUNCTION__),__LINE__,_T("Error bUpdateData: %s"),szGetLabel());
											}
											

										}
										Sleep(DW_DELAI_INTER_TRAME);// delai inter-trame
										
									}
									else
									{
										TRACE_DEBUG(eDebug,eConfig,_T(__FILE__),_T(__FUNCTION__),__LINE__,_T("taille buffer d'échange trop petit, taille buffer = %d, taille trame = %d"),Context.m_iSize,iSizeToRead);
									}
								}
							}
						}
						while (!bReturn && (iNbrRetry-- > 0));
					}
				}
			}

		}
	}
	else
		TRACE_LOG_MSG(_T("(iNum < iNbrTrame) && (iNum > -1)"));

	if (!bReturn) 
	{
		TRACE_DEBUG(eError,eCycle,_T(__FILE__),_T(__FUNCTION__),__LINE__,_T("Erreur de com avec la carte n°%u"), (pElem)?pElem->m_pTrameJbusRQ->ucGetNumDest():99);
	}
	return bReturn;
}
Beispiel #23
0
BOOL CElemCycleStep::bFindRqAndExecuteFromIHM(long lExtraHeader,BOOL bCanRead, BOOL bCanWrite,BYTE *pBufferIn,long lSizeIn,BYTE *pBufferOut, long *plSizeOut,long lSizeOutMax,CEnumInterface &EnumInterface)
{
	BOOL bReturn = FALSE;
	CElemExchangeJbus *pElem = NULL;
	CContext Context;
	int iNbrTrame;
	int iNbrRetry = NBR_RETRY_EXCHANGE;
	CThreadInterface *pInterface = NULL;

	// recherche de l'interface de sortie
	pInterface = EnumInterface.pGetSelectedInterface(*pBufferIn);
	*plSizeOut = 0;

	if (pInterface)
	{
		// si c'est un message de l'IHM
		if (EnumInterface.bSelectedInterfaceIsSocketIHM(pInterface)) 
		{
			iNbrTrame = m_ListExchangeRealTime.iGetCount();
			if ((lExtraHeader > -1) && (lExtraHeader < iNbrTrame))
			{
				if (pElem = (CElemExchangeJbus*)m_ListExchangeRealTime.pGetAt(lExtraHeader))
				{
					if (pElem->m_pTrameJbusRQ && pElem->m_pTrameJbusRP)
					{
						if (pElem->m_pTrameJbusRQ->bAccessAllowed(bCanRead,bCanWrite))
						{
							// verif de la taille en retour
							Context.Reset(TRUE,NULL,pBufferOut,lSizeOutMax,pInterface->bGetModeInteger(),FALSE);
							if (pElem->m_pTrameJbusRP->iGetStreamSize(Context) <= lSizeOutMax)
							{
								// verif si c'est la bonne trame et mise à jour
								if (bReturn = pElem->m_pTrameJbusRQ->bUpdateData(pBufferIn,lSizeIn,Context.m_bModeInteger))
								{
									// recup de la reponse RP
									*plSizeOut = pElem->m_pTrameJbusRP->iGetStreamSize(Context);
									if (pElem->m_pTrameJbusRP->bSerialize(Context))
									{
										bReturn = TRUE;
									}
								}
							}
						}
					}
				}
			}
		}
		// trame pas pour cette interface
		else /// carte io ou mesure
		{
			do
			{
				// ecriture et lecture sur l'interface serie (IO ou mesure
				if (bReturn = pInterface->bWriteAndRead(-1,pBufferIn,lSizeIn,pBufferOut,lSizeOutMax,lSizeOutMax,plSizeOut,TRUE))
				{
					// recup de la taille du buffer de sortie a retransmettre vers IHM en l'état
				}
			}
			while (!bReturn && (iNbrRetry-- > 0));
		}
	}

	if (!bReturn) 
	{
		TRACE_DEBUG(eDebug,eComSocket,_T(__FILE__),_T(__FUNCTION__),__LINE__,_T("Error: %s"),szGetLabel());
		TRACE_DEBUG_IHM(eError,eComSocket,eErrorFindRqAndExecuteFromIHM);
	}
	return bReturn;
}
STDMETHODIMP CAdRotator::get_GetAdvertisement(BSTR bstrVirtualPath, BSTR * pVal)
{
	SCODE rc = E_FAIL;
    
	try
	{
		USES_CONVERSION;

		CContext cxt;
		rc = cxt.Init( CContext::get_Server );
		if ( !FAILED(rc) )
		{
			CComBSTR bstrPhysicalPath;
			// determine the physical path
			if ( ( rc = cxt.Server()->MapPath( bstrVirtualPath, &bstrPhysicalPath ) ) == S_OK )
			{
				_TCHAR* szPath = OLE2T( bstrPhysicalPath );

				CAdFilePtr pAdFile = AdFile( szPath );
				
				if ( pAdFile.IsValid() )
				{
					// refresh the ad file (make sure it's up to date)
					pAdFile->Refresh();

					// block all writers
					CReader rdr( *pAdFile );

					// if the border hasn't been set, use the default from the ad file
					short nBorder;
					if ( m_nBorder < 0 )
					{
						nBorder = pAdFile->Border();
					}
					else
					{
						nBorder = m_nBorder;
					}

					CAdDescPtr pAd = pAdFile->RandomAd();
					if ( pAd.IsValid() )
					{
						// write out the HTML line for this ad
						StringOutStream ss;

						if ( m_bClickable && ( pAd->m_strLink.size() > 1 ) )
						{
							// use the href format
							ss	<< _T("<A HREF=\"") << pAdFile->Redirector()
								<< _T("?url=") << pAd->m_strLink
								<< _T("&image=") << pAd->m_strGif
								<< _T("\" ") << m_strTargetFrame << _T(">");
						}
						
						// now fill in the rest
						ss	<< _T("<IMG SRC=\"") << pAd->m_strGif
							<< _T("\" ALT=\"") << pAd->m_strAlt
							<< _T("\" WIDTH=") << pAdFile->Width()
							<< _T(" HEIGHT=") << pAdFile->Height();

						if ( pAdFile->HSpace() != CAdFile::defaultHSpace )
						{
							ss << _T(" HSPACE=") << pAdFile->HSpace();
						}
						if ( pAdFile->VSpace() != CAdFile::defaultVSpace )
						{
							ss << _T(" VSPACE=") << pAdFile->VSpace();
						}

						ss << _T(" BORDER=") << nBorder << _T(">");

						if ( m_bClickable && ( pAd->m_strLink.size() > 1 ) )
						{
							// put the trailing tag on
							ss << _T("</A>");
						}

						String str = ss.toString();
						
						if ( pVal )
						{
							if ( *pVal )
							{
								::SysFreeString( *pVal );
							}
							*pVal = T2BSTR( str.c_str() );
							THROW_IF_NULL( *pVal );
							rc = S_OK;
						}
						else
						{
							rc = E_POINTER;
						}
					}
				}
			}
		}
		else
		{
			_ASSERT(0);
			RaiseException( IDS_ERROR_NOSVR );
		}   // end if got server
	}
	catch ( alloc_err& )
	{
		rc = E_OUTOFMEMORY;
	}
	catch ( ... )
	{
		rc = E_FAIL;
	}
	return rc;
}
Beispiel #25
0
// Display the power item on the screen!
void CDrawPower::Paint(CContext &dc, paint_options options)
{
	int spacing;
	CDPoint pa, pb, pc, pd, pos = m_point_a;

	CalcLayout();

	dc.SelectFont(*m_pDesign->GetOptions()->GetFont(fPIN), 2);
	dc.SetROP2(R2_COPYPEN);
	dc.SetTextColor(m_pDesign->GetOptions()->GetUserColor().Get(CUserColor::POWER));

	if (which != 0) spacing = POWER_SIZE * 2 + POWER_SIZE / 4;
	else spacing = POWER_SIZE + POWER_SIZE / 4;

	// Find out which way round the power object goes
	switch (dir)
	{
		case 0: // Top
			pa = CDPoint(pos.x, pos.y - POWER_SIZE);
			pb = CDPoint(pos.x - POWER_SIZE / 2, pos.y - POWER_SIZE);
			pc = CDPoint(pos.x + POWER_SIZE / 2 + 1, pos.y - POWER_SIZE);
			pd = CDPoint(pos.x, pos.y - POWER_SIZE * 2);
			break;
		case 1: // Bottom
			pa = CDPoint(pos.x, pos.y + POWER_SIZE);
			pb = CDPoint(pos.x - POWER_SIZE / 2, pos.y + POWER_SIZE);
			pc = CDPoint(pos.x + POWER_SIZE / 2 + 1, pos.y + POWER_SIZE);
			pd = CDPoint(pos.x, pos.y + POWER_SIZE * 2);
			break;
		case 2: // Left
			pa = CDPoint(pos.x - POWER_SIZE, pos.y);
			pb = CDPoint(pos.x - POWER_SIZE, pos.y - POWER_SIZE / 2);
			pc = CDPoint(pos.x - POWER_SIZE, pos.y + POWER_SIZE / 2 + 1);
			pd = CDPoint(pos.x - POWER_SIZE * 2, pos.y);
			break;
		case 3: // Right
			pa = CDPoint(pos.x + POWER_SIZE, pos.y);
			pb = CDPoint(pos.x + POWER_SIZE, pos.y - POWER_SIZE / 2);
			pc = CDPoint(pos.x + POWER_SIZE, pos.y + POWER_SIZE / 2 + 1);
			pd = CDPoint(pos.x + POWER_SIZE * 2, pos.y);
			break;
	}

	dc.TextOut(str, TextPos, options);

	switch (options)
	{
		case draw_selected:
		case draw_selectable:
			dc.SelectPen(PS_SOLID, 1, cSELECT);
			break;
		default:
			dc.SelectPen(PS_SOLID, 1, cLINE);
	}

	dc.SelectBrush();

	// Draw the main line of the power item
	switch (which)
	{
		case 0: // Draw the Bar
			dc.MoveTo(pb);
			dc.LineTo(pc);
			break;
		case 1: // Draw the Circle
			dc.Ellipse(CDRect(pb.x - (pa.x - pd.x), pb.y - (pa.y - pd.y), pc.x, pc.y));
			break;
		case 2: // Draw the Wave
			// The PolyBezier function is not implemented in MFC!
			// So this hack has to be used....
		{
			CDPoint pts[4];
			pts[0] = CDPoint(pb.x + (pd.x - pa.x) / 2, pb.y + (pd.y - pa.y) / 2);
			pts[1] = CDPoint(pd.x + (pb.x - pa.x) / 2, pd.y + (pb.y - pa.y) / 2);
			pts[2] = CDPoint(pa.x + (pc.x - pa.x) / 2, pa.y + (pc.y - pa.y) / 2);
			pts[3] = CDPoint(pc.x - (pa.x - pd.x) / 2, pc.y - (pa.y - pd.y) / 2);
			dc.PolyBezier(pts, 4);
		}
			break;
		case 3: // Draw the Arrow
			dc.MoveTo(pb);
			dc.LineTo(pc);
			dc.MoveTo(pb);
			dc.LineTo(pd);
			dc.LineTo(pc);
			break;
		case 4: // Draw the Earth
			dc.MoveTo(pb);
			dc.LineTo(pc);
			dc.MoveTo(CDPoint(pb.x - (pb.x - pd.x) / 2, pb.y - (pb.y - pd.y) / 2));
			dc.LineTo(CDPoint(pc.x - (pc.x - pd.x) / 2, pc.y - (pc.y - pd.y) / 2));
			dc.MoveTo(CDPoint(pd.x - (pb.x - pa.x) / 4, pd.y - (pb.y - pa.y) / 4));
			dc.LineTo(CDPoint(pd.x + (pb.x - pa.x) / 4, pd.y + (pb.y - pa.y) / 4));
			break;
	}

	// Draw the bits that all power items have in comman
	dc.MoveTo(pos);
	dc.LineTo(pa);

	if (is_stuck)
	{
		// Draw a nice circle to show the stickness...
		dc.PaintConnectPoint(m_point_b);

		// Do we need a junction
		if (is_junction)
		{
			int js = JUNCTION_SIZE;
			CDPoint br, tl;
			br = CDPoint(m_point_b.x + js, m_point_b.y + js);
			tl = CDPoint(m_point_b.x - js, m_point_b.y - js);

			dc.SetROP2(R2_COPYPEN);

			dc.SelectPen(PS_SOLID, 1, m_pDesign->GetOptions()->GetUserColor().Get(CUserColor::JUNCTION));
			dc.SelectBrush(m_pDesign->GetOptions()->GetUserColor().Get(CUserColor::JUNCTION));
			dc.Ellipse1(CDRect(tl.x, tl.y, br.x, br.y));
		}
	}

}
// Display the line on the screen!
void CDrawLine::Paint(CContext &dc,paint_options options)
{
	if (m_use_default_style)
	{
		switch (xtype)
		{
		case xWire:
			dc.SelectPen( PS_SOLID,1, m_pDesign->GetOptions()->GetUserColor().Get( CUserColor::WIRE ), options );
			break;
		case xBus:
			dc.SelectPen( PS_SOLID,5, m_pDesign->GetOptions()->GetUserColor().Get( CUserColor::BUS ), options );
			break;
		default:
			dc.SelectPen(m_pDesign->GetOptions()->GetStyle(m_style), options);
			break;
		}
	}
	else
	{
		dc.SelectPen(m_pDesign->GetOptions()->GetStyle(m_style), options);
	}

  dc.SetROP2(R2_COPYPEN);

  dc.MoveTo(m_point_a);

  if (!m_segment) {
	  switch (g_EditToolBar.m_DrawLineEdit.mode) {
		case 1: dc.LineTo(CDPoint(m_point_b.x,m_point_a.y));
			break;
		case 2:	dc.LineTo(CDPoint(m_point_a.x,m_point_b.y));
			break;
	  }
  }
  dc.LineTo(m_point_b);

  if (is_stuck)
  {
	  // Draw a nice circle to show the stickness...
	  dc.PaintConnectPoint( m_point_b );

	  // Do we need a junction
	  if (is_junction)
	  {
	    int js=JUNCTION_SIZE;
		CDPoint br,tl;
		br=CDPoint(m_point_b.x+js+1,m_point_b.y+js+1);
		tl=CDPoint(m_point_b.x-js,m_point_b.y-js);

		dc.SetROP2(R2_COPYPEN);

		dc.SelectPen(PS_SOLID,1,m_pDesign->GetOptions()->GetUserColor().Get( CUserColor::JUNCTION) );
		dc.SelectBrush(m_pDesign->GetOptions()->GetUserColor().Get( CUserColor::JUNCTION));
  	    dc.Ellipse(CDRect(tl.x,tl.y,br.x,br.y));
	  }
  }

}
Beispiel #27
0
void destroy(void* server)
{
    CContext* context = static_cast<CContext*>(server);
    context->destroy();
    delete context;
}
Beispiel #28
0
CContext::CContext(const CContext& context)
{
  v8::HandleScope handle_scope(v8::Isolate::GetCurrent());

  m_context.Reset(context.Handle()->GetIsolate(), context.Handle());
}
Beispiel #29
0
   //! Initialize a file in order to write into it
   void CFile::initFile(void)
   {
      CContext* context = CContext::getCurrent();
      const CDate& currentDate = context->calendar->getCurrentDate();
      CContextServer* server = context->server;

      lastSync  = currentDate;
      lastSplit = currentDate;
      if (!split_freq.isEmpty())
      {
        StdString keySuffix("CContext_"+CContext::getCurrent()->getId()+"::CFile_"+getFileOutputName()+"::") ; 
        if (context->registryIn->foundKey(keySuffix+"splitStart") && context->registryIn->foundKey(keySuffix+"splitEnd"))
        {
          CDate savedSplitStart(*context->getCalendar()), savedSplitEnd(*context->getCalendar());
          context->registryIn->getKey(keySuffix+"splitStart", savedSplitStart);
          context->registryIn->getKey(keySuffix+"splitEnd",   savedSplitEnd);

          if (savedSplitStart <= lastSplit && lastSplit <= savedSplitEnd)
            lastSplit = savedSplitStart;
        }
      }
      isOpen = false;

      allDomainEmpty = true;

//      if (!record_offset.isEmpty() && record_offset < 0)
//        ERROR("void CFile::initFile(void)",
//              "Invalid 'record_offset', this attribute cannot be negative.");
      const int recordOffset = record_offset.isEmpty() ? 0 : record_offset;

      // set<CAxis*> setAxis;
      // set<CDomain*> setDomains;
      set<StdString> setAxis;
      set<StdString> setDomains;
      
      std::vector<CField*>::iterator it, end = this->enabledFields.end();
      for (it = this->enabledFields.begin(); it != end; it++)
      {
         CField* field = *it;
         allDomainEmpty &= !field->grid->doGridHaveDataToWrite();
         std::vector<CAxis*> vecAxis = field->grid->getAxis();
         for (size_t i = 0; i < vecAxis.size(); ++i)
            setAxis.insert(vecAxis[i]->getAxisOutputName());
            // setAxis.insert(vecAxis[i]);
         std::vector<CDomain*> vecDomains = field->grid->getDomains();
         for (size_t i = 0; i < vecDomains.size(); ++i)
            setDomains.insert(vecDomains[i]->getDomainOutputName());
            // setDomains.insert(vecDomains[i]);

         field->resetNStep(recordOffset);
      }
      nbAxis = setAxis.size();
      nbDomains = setDomains.size();

      // create sub communicator for file
      int color = allDomainEmpty ? 0 : 1;
      MPI_Comm_split(server->intraComm, color, server->intraCommRank, &fileComm);
      if (allDomainEmpty) MPI_Comm_free(&fileComm);

      // if (time_counter.isEmpty()) time_counter.setValue(time_counter_attr::centered);
      if (time_counter_name.isEmpty()) time_counter_name = "time_counter";
    }