📄 clrr.cpp
字号:
#include "stdafx.h"
#include "CLRR.h"
#include "stdio.h"
#include "math.h"
extern "C" IACTIVEMODEL __declspec(dllexport) * createactivemodel (CHAR *device, ILICENCESERVER *ils)
{
ils->authorize (0x10000100,0x72);
return new POWER;
}
extern "C" VOID __declspec(dllexport) deleteactivemodel (IACTIVEMODEL *model)
{
delete (POWER *)model;
}
extern "C" ISPICEMODEL __declspec(dllexport) * createspicemodel (CHAR *device, ILICENCESERVER *ils)
{
ils->authorize(0x10000100,0x72);
return new POWER;
}
extern "C" VOID __declspec(dllexport) deletespicemodel (ISPICEMODEL *model)
{
delete (POWER *)model;
}
POWER::POWER()
{
MaxPower=9999999.9999999;
CurrentPower=0.0;
InternalResistor=0.0001;
G=1.0/InternalResistor;
DifferVoltage=0.0;
Current=0.0;
FILE* pFile=fopen("C:\\WINDOWS\\system32\\ProteusPower.txt","r");
if(pFile==NULL)
MessageBox(NULL,"您所使用的\"POWER\"器件是由\"宋培林\"开发的。\n由于您所使用的\"POWER\"器件是Demo版本,所以每次仿真都会弹出这个报告。","监测报告",MB_OK);
else
fclose(pFile);
}
POWER::~POWER()
{
}
INT POWER::isanalog (CHAR *pinname)
{
return 1;
}
VOID POWER::setup (IINSTANCE *instance, ISPICECKT *spiceckt)
{
ins=instance;
ckt=spiceckt;
char *str=ins->getstrval("AUTHOR","?");
int res=strcmp(str,"宋培林(不可改动,否则...)");
if(res!=0)
{
ins->fatal("\"POWER\"器件是由\"宋培林\"开发的,您改动了版权信息!崩溃!");
}
CP=instance->getspicenode("1",TRUE);
CN=instance->getspicenode("2",TRUE);
VP=instance->getspicenode("3",TRUE);
VN=instance->getspicenode("4",TRUE);
RF=instance->getspicenode("5",TRUE);
VOUT1=instance->getspicenode("6",TRUE);
VOUT2=instance->getspicenode("7",TRUE);
NodeCPCP=spiceckt->allocsmp(CP,CP);
NodeCNCN=spiceckt->allocsmp(CN,CN);
NodeCPCN=spiceckt->allocsmp(CP,CN);
NodeCNCP=spiceckt->allocsmp(CN,CP);
/////////////////////////////////////
BranchM=spiceckt->newcurnode(instance->id(),"BranchM");
NodeMPB=spiceckt->allocsmp(VOUT1, BranchM);
NodeMNB=spiceckt->allocsmp(VN, BranchM);
NodeMBP=spiceckt->allocsmp(BranchM, VOUT1);
NodeMBN=spiceckt->allocsmp(BranchM, VN);
BranchE=spiceckt->newcurnode(instance->id(),"BranchE");
NodeEPB=spiceckt->allocsmp(VOUT2, BranchE);
NodeENB=spiceckt->allocsmp(VN, BranchE);
NodeEBP=spiceckt->allocsmp(BranchE, VOUT2);
NodeEBN=spiceckt->allocsmp(BranchE, VN);
////////////////////////////////////////
OldTime=(REALTIME)0.0;
}
VOID POWER::runctrl (RUNMODES mode)
{
}
VOID POWER::actuate (REALTIME time, ACTIVESTATE newstate)
{
}
BOOL POWER::indicate (REALTIME time, ACTIVEDATA *newstate)
{
return TRUE;
}
VOID POWER::dcload (REALTIME time, SPICEMODES mode, DOUBLE *oldrhs, DOUBLE *newrhs)
{
int itemp=0;
*NodeCPCP+=G;
*NodeCNCN+=G;
*NodeCPCN-=G;
*NodeCNCP-=G;
DifferVoltage=fabs(oldrhs[VP]-oldrhs[VN]);
Current=fabs((oldrhs[CP]-oldrhs[CN])*G);
CurrentPower+=DifferVoltage*Current*(time-OldTime);
if(CurrentPower>=MaxPower)
CurrentPower=MaxPower;
OldTime=time;
expptr=&itemp;
mantissa=frexp(CurrentPower,expptr);
*NodeMPB+=1.0;
*NodeMNB-=1.0;
*NodeMBP+=1.0;
*NodeMBN-=1.0;
newrhs[BranchM]+=mantissa;
*NodeEPB+=1.0;
*NodeENB-=1.0;
*NodeEBP+=1.0;
*NodeEBN-=1.0;
newrhs[BranchE]+=double(itemp+25.0)/50.0;
return;
}
VOID POWER::acload (SPICEFREQ omega, DOUBLE *rhs, DOUBLE *irhs)
{
}
VOID POWER::trunc (REALTIME time, REALTIME *newtimestep)
{
}
VOID POWER::accept (REALTIME time, DOUBLE *rhs)
{
}
VOID POWER::initialize (ICOMPONENT *cpt)
{
component = cpt;
}
ISPICEMODEL *POWER::getspicemodel (CHAR *)
{
return this;
}
IDSIMMODEL *POWER::getdsimmodel (CHAR *)
{
return NULL;
}
VOID POWER::plot (ACTIVESTATE state)
{
component->drawsymbol(-1);
component->setpencolour(RGB(0,255,0));
component->setpenwidth(8);
component->setbrushcolour(RGB(0,64,0));
component->drawbox(100,-220,900,-120);
component->settextcolour(RGB(0,255,0));
component->settextsize(100);
/*if( (CurrentPower>=0)&&(CurrentPower<10) )
{
sprintf(str,"%s%0.7f",str10,CurrentPower);
}
else if( (CurrentPower>=10)&&(CurrentPower<100) )
{
sprintf(str,"%s%0.7f",str100,CurrentPower);
}
else if( (CurrentPower>=100)&&(CurrentPower<1000) )
{
sprintf(str,"%s%0.7f",str1000,CurrentPower);
}
else if( (CurrentPower>=1000)&&(CurrentPower<10000) )
{
sprintf(str,"%s%0.7f",str10000,CurrentPower);
}
else if( (CurrentPower>=10000)&&(CurrentPower<100000) )
{
sprintf(str,"%s%0.7f",str100000,CurrentPower);
}
else if( (CurrentPower>=100000)&&(CurrentPower<1000000) )
{
sprintf(str,"%s%0.7f",str1000000,CurrentPower);
}
else if( (CurrentPower>=1000000)&&(CurrentPower<10000000) )
{
sprintf(str,"%s%0.7f",str10000000,CurrentPower);
}
else
{
sprintf(str," Error! ");
}*/
component->drawtext(140,-170,0,TXJ_LEFT|TXJ_MIDDLE,str);
}
VOID POWER::animate (INT element, ACTIVEDATA *data)
{
component->setpencolour(RGB(0,255,0));
component->setpenwidth(8);
component->setbrushcolour(RGB(0,64,0));
component->drawbox(100,-220,900,-120);
component->settextcolour(RGB(0,255,0));
component->settextsize(100);
if( (CurrentPower>=0)&&(CurrentPower<10) )
{
sprintf(str,"%s%0.7f",str10,CurrentPower);
}
else if( (CurrentPower>=10)&&(CurrentPower<100) )
{
sprintf(str,"%s%0.7f",str100,CurrentPower);
}
else if( (CurrentPower>=100)&&(CurrentPower<1000) )
{
sprintf(str,"%s%0.7f",str1000,CurrentPower);
}
else if( (CurrentPower>=1000)&&(CurrentPower<10000) )
{
sprintf(str,"%s%0.7f",str10000,CurrentPower);
}
else if( (CurrentPower>=10000)&&(CurrentPower<100000) )
{
sprintf(str,"%s%0.7f",str100000,CurrentPower);
}
else if( (CurrentPower>=100000)&&(CurrentPower<1000000) )
{
sprintf(str,"%s%0.7f",str1000000,CurrentPower);
}
else if( (CurrentPower>=1000000)&&(CurrentPower<10000000) )
{
sprintf(str,"%s%0.7f",str10000000,CurrentPower);
}
else
{
sprintf(str," Error! ");
}
component->drawtext(140,-170,0,TXJ_LEFT|TXJ_MIDDLE,str);
}
BOOL POWER::actuate (WORD key, INT x, INT y, DWORD flags)
{
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -