void ChatUDPSocket::readyRead (){ QByteArray buffer; buffer.resize(mUdpSocket->pendingDatagramSize()); QHostAddress sender; quint16 senderPort; mUdpSocket->readDatagram(buffer.data(), buffer.size(), &sender, &senderPort); qDebug() << "message from : " << sender.toString(); qDebug() << "message port : " << senderPort; qDebug() << "message : " << buffer; QList<QByteArray> packList = buffer.split(':'); QString pType(packList[0].trimmed().toLower()); QUuid pUuid(packList[1]); QString pContent(packList[2]); qDebug() << pType; if(pType == "request") { // request message QByteArray data; data.append("response:"); data.append(pUuid.toString()).append(":"); data.append("accepted"); mUdpSocket->writeDatagram(data, sender, ChatPort); mUdpSocket->flush(); emit receiveSuccess(pContent); } else if (pType == "response") { // response message if(pContent.trimmed().toLower() == "accepted") { emit sendSuccess(pUuid); } } }
void Forces::CalcDens(){ // 3d if(VAR_IF_TYPE(Tens.CalcMode,CALC_3d)){ double PosRel[3]; for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ PosRel[d] = pPos(p,d) - (pEdge(d)*.5 - Tens.RefPos[d]); PosRel[d] -= floor(PosRel[d]*pInvEdge(d))*pEdge(d); } int sx = (int)(PosRel[0]*pInvEdge(0)*Tens.NSlab); int sy = (int)(PosRel[1]*pInvEdge(1)*Tens.NSlab); int sz = (int)(PosRel[2]*pInvEdge(2)*Tens.NSlab); int v = (sx*Tens.NSlab+sy)*Tens.NSlab+sz; int t = pType(p); if(t > 1) continue; Tens.Dens[t][v] += 1.; } } // 2d else if(VAR_IF_TYPE(Tens.CalcMode,CALC_2d)){ double PosRel[3]; for(int p=0;p<pNPart();p++){ PosRel[CLat1] = pPos(p,CLat1) - Tens.RefPos[CLat1]; PosRel[CLat2] = pPos(p,CLat2) - Tens.RefPos[CLat2]; PosRel[CNorm] = pPos(p,CNorm) + (pEdge(CNorm)*.5 - Tens.RefPos[CNorm]); for(int d=0;d<3;d++){ PosRel[d] -= floor(PosRel[d]*pInvEdge(d))*pEdge(d); } int sr = (int)(hypot(PosRel[CLat1],PosRel[CLat2])*Tens.EdgeInv[0]*Tens.NSlab); int sz = (int)(PosRel[CNorm]*pInvEdge(CNorm)*Tens.NSlab); if(sr < 0 || sr >= Tens.NSlab) continue; if(sz < 0 || sz >= Tens.NSlab) continue; int v = (sr*Tens.NSlab+sz); int t = pType(p); if(t > 1) continue; Tens.Dens[t][v] += 1.; //printf("%d %d %d %lf\n",sr,sz,v,Tens.Dens[t][v]); } } }
void ElPoly::IsoLine(int NSample,double *IsoLevel,int NIso,int How){ int NPairF = 1;//NFile[1]-NFile[0]; double OldPos[3] = {pNanoPos(0,0),pNanoPos(0,1),pNanoPos(0,2)}; double DensEl = SQR(NSample)/(pVol()*NPairF); double Dens = 13.3; //IsoLevel *= NPairF; for(int ff=NFile[0];ff<NFile[1];ff+=NPairF){ double *Plot = (double *)calloc(SQR(NSample),sizeof(double)); double Min = 0.; double Max = 0.; double Pos[3]; for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_PART))return; for(int b=0;b<pNBlock();b++){ for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){ if(pType(p) != 0)continue; for(int d=0;d<3;d++){ Pos[d] = pPos(p,d) - (pNanoPos(0,d)-.5*pEdge(d)); Pos[d] -= floor(Pos[d]*pInvEdge(d))*pEdge(d); } int sx = (int)(Pos[CLat1]*pInvEdge(CLat1)*NSample); int sy = (int)(Pos[CLat2]*pInvEdge(CLat2)*NSample); int sTot = sx*NSample+sy; if(How==0)//particle file Plot[sTot] += DensEl; else Plot[sTot] += pPos(p,CNorm); if(Max < Plot[sTot]) Max = Plot[sTot]; if(Min > Plot[sTot]) Min = Plot[sTot]; } } printf("Min %lf Max %lf DensEl %lf\n",Min,Max,DensEl); } Matrice Mask(5,5); Mask.FillGaussian(.5,3.); Mask.Print(); int NDim = 2; int IfMinImConv = 1; Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); char FString[60]; sprintf(FString,"IsoSurf%05d.dat",ff); FILE *F2Write = fopen(FString,"w"); fprintf(F2Write,"#l(%lf %lf %lf) v[%d] d[part]\n",pEdge(0),pEdge(1),pEdge(2),NSample); HeaderNano(F2Write); IsoLine(F2Write,Plot,NSample,IsoLevel,NIso); free(Plot); fclose(F2Write); } }
void CMemSpyDeviceWideOperations::PerformFinalOperationL() { #ifdef _DEBUG RDebug::Printf( "CMemSpyDeviceWideOperations::PerformFinalOperationL() - START" ); #endif iObserver.HandleDeviceWideOperationEvent( MMemSpyDeviceWideOperationsObserver::EOperationCompleting, 0, KNullDesC ); // Carry out any remaining final one-shot operation TPtrC pType( KNullDesC ); switch( iOperation ) { case EEntireDeviceHeapInfoCompact: // Entire operation is performed here pType.Set( KMemSpyUiCompactHeap ); iObserver.HandleDeviceWideOperationEvent( MMemSpyDeviceWideOperationsObserver::EOperationProgressStart, 0, pType ); iEngine.HelperHeap().OutputHeapInfoForDeviceL(); break; case EEntireDeviceStackInfoCompact: // Entire operation is performed here pType.Set( KMemSpyUiCompactStack ); iObserver.HandleDeviceWideOperationEvent( MMemSpyDeviceWideOperationsObserver::EOperationProgressStart, 0, pType ); iEngine.HelperStack().OutputStackInfoForDeviceL(); break; case EPerEntityHeapInfo: // Complete op by outputting kernel heap summary pType.Set( KMemSpyUiThreadNameKernel ); iObserver.HandleDeviceWideOperationEvent( MMemSpyDeviceWideOperationsObserver::EOperationProgressStart, 0, pType ); iEngine.HelperHeap().OutputHeapInfoKernelL(); break; case EPerEntityHeapData: // Complete op by outputting kernel heap data // TODO: Uncomment after kernel heap dump is fixed // pType.Set( KMemSpyUiThreadNameKernel ); // iObserver.HandleDeviceWideOperationEvent( MMemSpyDeviceWideOperationsObserver::EOperationProgressStart, 0, pType ); // iEngine.HelperHeap().OutputHeapDataKernelL(); break; default: break; } // Report progress iObserver.HandleDeviceWideOperationEvent( MMemSpyDeviceWideOperationsObserver::EOperationProgressEnd, 1, pType ); #ifdef _DEBUG RDebug::Print( _L("CMemSpyDeviceWideOperations::PerformFinalOperationL() - END - pType: %S"), &pType ); #endif }
int ElPoly::From3To2d(int NSample,double Param){ char FName[120]; for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_NANO)); sprintf(FName,"ProjOnSurf%05d.dat",f); FILE *FLine = fopen(FName,"w"); fprintf(FLine,"# l(%lf %lf %lf) d[part]\n",1.,pEdge(CLat2)*pInvEdge(CLat1),.5); for(int p=0;p<pNPart();p++){ if(pType(p) != 0) continue; fprintf(FLine,"{x(%lf %lf %lf) v(%lf %lf %lf)}\n",pPos(p,CLat1)*pInvEdge(CLat1),pPos(p,CLat2)*pInvEdge(CLat1),.5,pVel(p,0),pVel(p,1),pVel(p,2)); } fclose(FLine); } printf("\n"); }
/** Call InterBSpline2d to update the particle position; */ void VarData::SmoothGrid(int NSample){ double *PlotIn = (double *)calloc(SQR(NSample),sizeof(double)); double *PlotOut = (double *)calloc(SQR(NSample),sizeof(double)); for(int nx=0;nx<NSample;nx++){ for(int ny=0;ny<NSample;ny++){ int n = nx*NSample+ny; PlotIn[n] = Pm[n].Pos[2]; } } InterBSpline2D(PlotIn,PlotOut,NSample,NSample); for(int nx=0;nx<NSample;nx++){ for(int ny=0;ny<NSample;ny++){ int n = nx*NSample+ny; if(pType(n) != 0) continue; Pm[n].Pos[2] = PlotOut[n]; } } free(PlotIn); free(PlotOut); }
void Forces::CalcTens(){ if(!VAR_IF_TYPE(SysAlloc,ALL_FORCES)){ printf("Forces not allocated\n"); return; } ClearDens(); AddDens(0,pNPart()); SumDens(0,pNPart()); double Dist = 0.; double DistRelBA[4]; for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ Fm[p].Dir[d] = 0.; } } // non bonded double Pos[3]; for(int p1=0;p1<pNPart();p1++){ for(Pc->SetCurr(p1);Pc->IfCurr();Pc->NextCurr()){ int p2 = Pc->p2Curr; if(p2 <= p1) continue; Pc->Dist2Curr(DistRelBA); if(DistRelBA[3] > Kf.CutOff2) continue; double Dist = sqrt(DistRelBA[3]); double Force = 0.; for(int t=0;t<pNType();t++){ Force += MInt->Coeff(pType(p1),pType(p2),t)*(Dens3[p1*pNType()+t]+Dens3[p2*pNType()+t]); } Force *= DerWei3(Dist,pWei3Par())*2./3.; Force += DerWei2(Dist,pWei2Par())*MInt->Coeff(pType(p1),pType(p2)); SumTens(p1,p2,Force,DistRelBA); Force /= -Dist; SigErr(Force > 5000.,"Forces over the limit %lf\n",Force); for(int d=0;d<3;d++){ Fm[p1].Dir[d] += Force*DistRelBA[d]; Fm[p2].Dir[d] -= Force*DistRelBA[d]; } } } // bonded double DistRelBC[4]; double Pre[12]; for(int b=0;b<pNBlock();b++){ for(int c=0;c<pNChain(b);c++){ for(int p=c*pNPCh(b);p<(c+1)*pNPCh(b)-1;p++){ TwoPartDist(p+1,p,DistRelBA); double ForceSp = pkSpr()*(1. - pSprRest()/DistRelBA[3]); SumTens(p,p+1,ForceSp,DistRelBA); for(int d=0;d<3;d++){ Fm[p].Dir[d] += ForceSp*DistRelBA[d]; Fm[p+1].Dir[d] -= ForceSp*DistRelBA[d]; } if(p < (c+1)*pNPCh(b)-2){ TwoPartDist(p+2,p+1,DistRelBC); double CosAngle = 0.; for(int d=0;d<3;d++){ DistRelBA[d] /= DistRelBA[3]; DistRelBC[d] /= DistRelBC[3]; CosAngle += DistRelBA[d]*DistRelBC[d]; } double PreFactBA = pkBen()/DistRelBA[3]; double PreFactBC = pkBen()/DistRelBC[3]; for(int d=0;d<3;d++){ Fm[p+0].Dir[d] += PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle); Fm[p+1].Dir[d] -= PreFactBA*(DistRelBC[d]-DistRelBA[d]*CosAngle); Fm[p+1].Dir[d] += PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle); Fm[p+2].Dir[d] -= PreFactBC*(DistRelBA[d]-DistRelBC[d]*CosAngle); Pre[d ] = DistRelBA[d]*pkBen()*(DistRelBC[d]-DistRelBA[d]*CosAngle); Pre[d+6] = DistRelBC[d]*pkBen()*(DistRelBA[d]-DistRelBC[d]*CosAngle); } Pre[ 3] = DistRelBA[0]*pkBen()*(DistRelBC[1]-DistRelBA[1]*CosAngle); Pre[ 4] = DistRelBA[0]*pkBen()*(DistRelBC[2]-DistRelBA[2]*CosAngle); Pre[ 5] = DistRelBA[1]*pkBen()*(DistRelBC[2]-DistRelBA[2]*CosAngle); Pre[ 9] = DistRelBC[0]*pkBen()*(DistRelBA[1]-DistRelBC[1]*CosAngle); Pre[10] = DistRelBC[0]*pkBen()*(DistRelBA[2]-DistRelBC[2]*CosAngle); Pre[11] = DistRelBC[1]*pkBen()*(DistRelBA[2]-DistRelBC[2]*CosAngle); SumTens(p,p+1,Pre); SumTens(p+1,p+2,Pre+6); } } } } return; //external double Pot[3]; double PosBf[3]; double dr[4]; double NPos[3]; for(int n=0;n<pNNano();n++){ Point2Shape(Nano[n].Shape); for(int p=0;p<pNPart();p++){ pPos(p,Pos); double Dr2 = NanoDist2(Pos,n); double InvDist = 1./Dr2; double Cons = Potential(Dr2,0,pType(p),Pot); for(int d=0;d<3;d++){ dr[d] = Nano[n].Pos[d] - pPos(p,d); if(dr[d] > .5*pInvEdge(d)) dr[d] -= pEdge(d); if(dr[d] < -.5*pInvEdge(d)) dr[d] += pEdge(d); } double Norm = SQR(Nano[n].Rad)/(SQR(dr[0]) + SQR(dr[1]) + SQR(dr[2])); Norm = sqrt(Norm); for(int d=0;d<3;d++){ NPos[d] = NPos[d] + dr[d]*Norm; Fm[p].Dir[d] += Cons*dr[d]*InvDist; Pre[d ] = Cons*dr[d]*dr[d]*InvDist; } Pre[3] = Cons*dr[0]*dr[1]*InvDist; Pre[4] = Cons*dr[0]*dr[2]*InvDist; Pre[5] = Cons*dr[1]*dr[2]*InvDist; SumTens(NPos,Pos,Pre); } } }
EXPORT_C void CMemSpyEngineHelperHeap::OutputCellListingUserL( const CMemSpyThread& aThread ) { // Suspend the process iEngine.ProcessSuspendLC( aThread.Process().Id() ); // Free cells RArray<TMemSpyDriverFreeCell> freeCells; CleanupClosePushL( freeCells ); // Info section TMemSpyHeapInfo heapInfo; const TInt error = iEngine.Driver().GetHeapInfoUser( heapInfo, aThread.Id(), freeCells ); if ( error == KErrNone ) { UpdateSharedHeapInfoL( aThread.Process().Id(), aThread.Id(), heapInfo ); } if ( error == KErrNone && heapInfo.Type() != TMemSpyHeapInfo::ETypeUnknown ) { // Get thread name for context const TFullName pName( aThread.FullName() ); // Begin a new data stream _LIT( KMemSpyFolder, "Heap\\Cell List" ); _LIT( KMemSpyContext, "Cell List - %S" ); HBufC* context = HBufC::NewLC( KMaxFileName ); TPtr pContext( context->Des() ); pContext.Format( KMemSpyContext, &pName ); iEngine.Sink().DataStreamBeginL( pContext, KMemSpyFolder ); CleanupStack::PopAndDestroy( context ); // Set prefix for overall listing iEngine.Sink().OutputPrefixSetFormattedLC( KMemSpyPrefixCellList, &pName ); // Start new section _LIT(KHeader, "CELL LISTING"); iEngine.Sink().OutputSectionHeadingL( KHeader, '=' ); // Prepare temp buffers TBuf<KMaxFullName + 100> printFormat; HBufC* tempBuffer = HBufC::NewLC( 2048 ); TPtr pTempBuffer( tempBuffer->Des() ); // Print initial info OutputHeapInfoL( heapInfo, pName, &freeCells ); // Code segments (needed for map file reading...) _LIT(KCellListCodeSegInfoFormat, "CodeSegs - "); iEngine.HelperCodeSegment().OutputCodeSegmentsL( aThread.Process().Id(), printFormat, KCellListCodeSegInfoFormat, '-', ETrue ); // Now walk the heap! TInt r = iEngine.Driver().WalkHeapInit( aThread.Id() ); if ( r == KErrNone ) { _LIT(KHeader2, "Cells"); iEngine.Sink().OutputSectionHeadingL( KHeader2, '-' ); TMemSpyDriverCellType cellType; TAny* cellAddress; TInt cellLength; TInt cellNestingLevel; TInt cellAllocationNumber; TInt cellHeaderSize; TAny* cellPayloadAddress; TBuf8<4> cellData; // r = iEngine.Driver().WalkHeapNextCell( aThread.Id(), cellType, cellAddress, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress ); while( r == KErrNone ) { TUint fourByteCellData = 0; TPtrC pType(KNullDesC); // if (cellType & EMemSpyDriverAllocatedCellMask) { r = iEngine.Driver().WalkHeapReadCellData( cellAddress, cellData, 4 ); if ( r == KErrNone ) { fourByteCellData = DescriptorAsDWORD( cellData ); } pType.Set(KCellTypeGoodAllocatedCell); } else if (cellType & EMemSpyDriverFreeCellMask) { pType.Set(KCellTypeGoodFreeCell); } else if (cellType & EMemSpyDriverBadCellMask) { switch (cellType) { case EMemSpyDriverHeapBadAllocatedCellSize: pType.Set(KCellTypeBadAllocatedCellSize); break; case EMemSpyDriverHeapBadAllocatedCellAddress: pType.Set(KCellTypeBadAllocatedCellAddress); break; case EMemSpyDriverHeapBadFreeCellAddress: pType.Set(KCellTypeBadFreeCellAddress); break; case EMemSpyDriverHeapBadFreeCellSize: pType.Set(KCellTypeBadFreeCellSize); break; default: pType.Set(KCellTypeBad); break; } } else { pType.Set(KCellTypeUnknown); } if ( r == KErrNone ) { pTempBuffer.Format( KCellListLineFormat, &pType, cellAddress, cellLength, cellAllocationNumber, cellNestingLevel, fourByteCellData, cellPayloadAddress, cellHeaderSize ); iEngine.Sink().OutputLineL( pTempBuffer ); // r = iEngine.Driver().WalkHeapNextCell( aThread.Id(), cellType, cellAddress, cellLength, cellNestingLevel, cellAllocationNumber, cellHeaderSize, cellPayloadAddress ); } } // iEngine.Driver().WalkHeapClose(); } CleanupStack::PopAndDestroy( tempBuffer ); CleanupStack::PopAndDestroy(); // clear prefix iEngine.Sink().DataStreamEndL(); } CleanupStack::PopAndDestroy( &freeCells ); CleanupStack::PopAndDestroy(); // resume process }
void TypeInference::inferTypes( ValueDef& valueDef, StaticContextPtr& pMemberCtx, const LogPtr& pLog) { switch (valueDef.getValueType()) { case OBJECT_INIT: { const ObjectInitValueDef& objectInitDef = static_cast<const ObjectInitValueDef&>(valueDef); TypePtr pType = TypePtr( new ReferenceType(OBJECT_REF_TYPE, objectInitDef.getClassName())); valueDef.setInferredType(pType); const map<const wstring, ActualParamDefPtr>& actualParamsMap = objectInitDef.getActualParamsMap(); map<const wstring, ActualParamDefPtr>::const_iterator it; for (it = actualParamsMap.begin(); it != actualParamsMap.end(); it++) { const ActualParamDefPtr& pActualParamDef = (*it).second; const ValueDefPtr& pParamValueDef = pActualParamDef->getValue(); inferTypes(*pParamValueDef, pMemberCtx, pLog); } } break; case ARRAY_INIT: { const ArrayInitValueDef& arrayInitDef = static_cast<const ArrayInitValueDef&>(valueDef); valueDef.setInferredType(arrayInitDef.getDeclaredType()); const list<ValueDefPtr>& arrayValues = arrayInitDef.getValues(); list<ValueDefPtr>::const_iterator it; for (it = arrayValues.begin(); it != arrayValues.end(); it++) { const ValueDefPtr& pArrayValue = *it; inferTypes(*pArrayValue, pMemberCtx, pLog); } } break; case LITERAL: { const LiteralValueDef& literalDef = static_cast<const LiteralValueDef&>(valueDef); switch (literalDef.getLiteralType()) { case INTEGER_LITERAL: valueDef.setInferredType(P_INTEGER_TYPE); break; case FLOAT_LITERAL: valueDef.setInferredType(P_FLOAT_TYPE); break; case STRING_LITERAL: valueDef.setInferredType(P_STRING_TYPE); break; default: assert(false); break; } } break; case REFERENCE_PATH: { const ReferencePathValueDef& referencePathDef = static_cast<const ReferencePathValueDef&>(valueDef); const list<const wstring>& path = referencePathDef.getReferencePath(); StaticContextEntryPtr pEntry; TypePtr pCurrentType; list<const wstring>::const_iterator it; wstring parentPath(L""); for (it = path.begin(); it != path.end(); it++) { const wstring& pathElement = *it; if (it == path.begin()) { CStaticContextEntryPtr pEntry; if (!pMemberCtx->lookup(pathElement, pEntry)) { boost::wformat f(L"Unable to resolve name %1%"); f % pathElement; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NameNotInContext, f.str()); return; } else { switch (pEntry->getStaticEntryType()) { case CLASS_DEF_CTX_ENTRY: { TypePtr pType(new ReferenceType(CLASS_REF_TYPE, pEntry->getName())); pCurrentType = pType; } break; case INTERFACE_DEF_CTX_ENTRY: { TypePtr pType(new ReferenceType(CLASS_REF_TYPE, pEntry->getName())); pCurrentType = pType; } break; case VARIABLE_DEF_CTX_ENTRY: { VariableDeclDefPtr pVariableDef; pEntry->getVariable(pVariableDef); if (pMemberCtx->isStatic() && !pVariableDef->isStatic()) { boost::wformat f(L"Cannot refer to a non static variable from an static context: %1%"); f % pathElement; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NonStaticVarRef, f.str()); return; } else { pCurrentType = pVariableDef->getDeclaredType(); } } break; case FORMAL_PARAM_DEF_CTX_ENTRY: { if (pMemberCtx->isStatic()) { boost::wformat f(L"Cannot refer to a class parameter from an static context: %1%"); f % pathElement; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NonStaticParamRef, f.str()); return; } FormalParamDefPtr pFormalParamDef; pEntry->getFormalParam(pFormalParamDef); pCurrentType = pFormalParamDef->getType(); } break; default: assert(false); return; } } } else { assert(pCurrentType.get() != NULL); StaticContextPtr pRootCtx; pMemberCtx->getRootContext(pRootCtx); if (!followPathElement( *pCurrentType, *pRootCtx, pathElement, pCurrentType)) { boost::wformat f(L"%1% is not a member of %2%"); f % pathElement % parentPath; pLog->log(referencePathDef, msg::ErrAnaTypeInfer_NotAMember, f.str()); return; } } if (parentPath.size()) { parentPath.append(L"."); } parentPath.append(pathElement); } assert(pCurrentType.get() != NULL); valueDef.setInferredType(pCurrentType); } break; default: assert(false); break; } }
/** * Builds a list of commands for the right click on Editor Chunk Item operation. * * @return Returns the list of commands. */ std::vector<std::string> PropertiesHelper::command() { propMap_.clear(); std::vector<std::string> links; int index = 0; for (int i=0; i < propCount(); i++) { DataDescription* pDD = pType()->property( i ); if (!pDD->editable()) continue; if ( isUserDataObjectLink(i) ) { PyObjectPtr ob( propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); std::string uniqueId = PyString_AsString( PyTuple_GetItem( ob.getObject(), 0 ) ); if ( !uniqueId.empty() ) { links.push_back( "#"+propName(i) ); links.push_back( "#"+uniqueId ); links.push_back( "Delete Link" ); propMap_[index++] = PropertyIndex( i ); links.push_back( "##" ); links.push_back( "##" ); } } else if ( isUserDataObjectLinkArray(i) ) { PyObjectPtr ob( propGetPy( i ), PyObjectPtr::STEAL_REFERENCE ); SequenceDataType* dataType = static_cast<SequenceDataType*>( pDD->dataType() ); ArrayPropertiesHelper propArray; propArray.init( pItem(), &(dataType->getElemType()), ob.getObject()); int numProps = propArray.propCount(); if ( numProps > 0 ) { links.push_back( "#"+propName(i) ); links.push_back( "Delete All" ); propMap_[index++] = PropertyIndex( i ); links.push_back( "" ); // Iterate through the array of links for(int j = 0; j < numProps; j++) { PyObjectPtr link( propArray.propGetPy( j ), PyObjectPtr::STEAL_REFERENCE ); std::string uniqueId = PyString_AsString( PyTuple_GetItem( link.getObject(), 0 ) ); if ( !uniqueId.empty() ) { links.push_back( "#"+uniqueId ); links.push_back( "Delete Link" ); PropertyIndex pi( i ); pi.append( j ); propMap_[index++] = pi; links.push_back( "##" ); } } links.push_back( "##" ); } } } return links; }
void ElPoly::DefineSkin(int NSample){ std::list<Weighted_point> l; FT shrinkfactor = 0.5; double *Plot = new double[pNType()*CUBE(NSample)]; double *Count = new double[CUBE(NSample)]; double Thre = 10.; double Radius = pEdge(0)/(double)NSample; for(int p=0;p<pNPart();p++){ int t = pType(p); int vx = (int)(pPos(p,0)/pEdge(0)*NSample); int vy = (int)(pPos(p,1)/pEdge(1)*NSample); int vz = (int)(pPos(p,2)/pEdge(2)*NSample); int vTot = (vz*NSample+vy)*NSample+vx; Plot[vTot*pNType()+t] += 1.; } double *Norm = (double *)calloc(pNType(),sizeof(double)); for(int t=0;t<pNType();t++){ for(int v=0;v<CUBE(NSample);v++){ if(Norm[t] < Plot[v*pNType()+t]) Norm[t] = Plot[v*pNType()+t]; } Norm[t] = Norm[t] <= 0. ? 1. : Norm[t]; } for(int vx=0;vx<NSample;vx++){ double x = vx*pEdge(0)/(double)NSample; for(int vy=0;vy<NSample;vy++){ double y = vy*pEdge(1)/(double)NSample; for(int vz=0;vz<NSample;vz++){ double z = vz*pEdge(2)/(double)NSample; int vTot = (vz*NSample+vy)*NSample+vx; if(Plot[vTot*pNType()] > Thre){ l.push_front(Weighted_point(Bare_point(x,y,z),Radius)); } } } } Polyhedron Polyhe; Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); CGAL::mesh_skin_surface_3(skin_surface, Polyhe); // CGAL::subdivide_skin_surface_mesh_3(skin_surface, Polyhe); // std::ofstream out("mesh.off"); // out << Polyhe; glDeleteLists(Dr->Particles,1); Dr->Particles = glGenLists(1); glNewList(Dr->Particles,GL_COMPILE); // Polyhedron::Facet_iterator fcUp = Polyhe.facets_begin(); // for(;fcUp != Polyhe.facets_end(); ++fcUp){ // Polyhedron::Supports_facet_halfedge = fcUp.halfedge(); // //Halfedge_around_facet_circulator heUp = fcUp.halfedge(); // } // for (Vertex_iterator vit = Polyhe.vertices_begin();vit != Polyhe.vertices_end(); vit++){ // // Vector n = policy.normal(vit); // // n = n/sqrt(n*n); // cout << vit->point() << std::endl; // Halfedge_iterator heUp = Polyhe.halfedges_begin(); // for(;heUp != Polyhe.halfedges_end(); ++heUp){ // //Polyhedron::Halfedge_handle Half = *heUp; // Vertex_handle veUp = heUp->vertex(); // K::Point_3 pf1 = vit->point(); // } // } CGAL::Inverse_index<Vertex_handle> index(Polyhe.vertices_begin(), Polyhe.vertices_end()); for(Facet_iterator fi = Polyhe.facets_begin();fi != Polyhe.facets_end(); ++fi) { HFC hc = fi->facet_begin(); HFC hc_end = hc; Polyhedron::Vertex_handle vf1 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf2 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf3 = (*hc).vertex(); hc++; K::Point_3 pf1 = vf1->point(); K::Point_3 pf2 = vf2->point(); K::Point_3 pf3 = vf3->point(); Vettore v1(pf1.x(),pf1.y(),pf1.z()); Vettore v2(pf2.x(),pf2.y(),pf2.z()); Vettore v3(pf3.x(),pf3.y(),pf3.z()); Vettore vN(3); v1.Mult(InvScaleUn); v2.Mult(InvScaleUn); v3.Mult(InvScaleUn); vN = (v1-v2) ^ (v3-v2); //if(vN.Norm() > 2.*AreaMean) continue; double Sfumatura = .3*Mat->Casuale(); glColor4f(0.1,.4+Sfumatura,0.2,1.); //glColor4f(HueUp[p].r,HueUp[p].g,HueUp[p].b,HueUp[p].a); DrTria(&v1,&v2,&v3,&vN); glColor4f(1.,.0,0.,1.); DrTriaContour(&v1,&v2,&v3); // glPushMatrix();//Particle // glBegin(GL_LINES); // do { // Polyhedron::Vertex_handle vh = (*hc).vertex(); // K::Point_3 pf1 = vh->point(); // glVertex3d(pf1.x(),pf1.y(),pf1.z()); // } while (++hc != hc_end); // glEnd(); // glPopMatrix();//Particle } glEndList(); // Tr tr; // 3D-Delaunay triangulation // C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // Surface_3 surface(sphere_function,Sphere_3(CGAL::ORIGIN, 2.)); // Surface_mesh_default_criteria_3<Tr> criteria(30., 0.1,0.1); // // meshing surface // make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); // std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; // DT dt; // for(int c=0;c<Gen->NChain;c++){ // if(CHAIN_IF_TYPE(Ch[c].Type,CHAIN_UP) )continue; // Point_3<K> ChPos(pPos(c,CLat1),pPos(c,CLat2),pPos(c,CNorm)); // dt.insert(ChPos); // } // Face_iterator fcTr = dt.finite_faces_begin(); // glDeleteLists(Dr->Particles,1); // Dr->Particles = glGenLists(1); // glNewList(Dr->Particles,GL_COMPILE); // for(;fcTr != dt.faces_end(); ++fcTr){ // Vertex_handle vf1 = fcTr->vertex(0), // vf2 = fcTr->vertex(1),vf3 = fcTr->vertex(2); // Point pf1 = vf1->point(); // Point pf2 = vf2->point(); // Point pf3 = vf3->point(); // Vettore v1(pf1.x() - pf2.x(),pf1.y() - pf2.y(),pf1.z()-pf2.z()); // Vettore v2(pf3.x() - pf2.x(),pf3.y() - pf2.y(),pf1.z()-pf2.z()); // Vettore vN(3); // vN = v1 ^ v2; // DrTira(v1,v2,v3,vN); // } // glEndList(); }
/** Simple Monte Carlo to find the best position and radius of the osculating torus. The area and position of the torus are hence redifined counting how many hydrophilic beads are inside the torus. */ void ElPoly::StalkArea(){ FILE *FNano = fopen("NanoPosA.sh","w"); FILE *StalkArea = fopen("StalkArea.dat","w"); FILE *AreaS = fopen("AreaS.dat","w"); double OldPos[5] = {pNanoPos(0,0),pNanoPos(0,1),pNanoPos(0,2),Nano->Rad,Nano->Height}; int NBin = 36; double *Count = (double *)calloc(NBin*NBin,sizeof(double)); double RadTorus = 1.;//Nano->Rad; //fprintf(AreaS,"#l(%lf %lf %lf) \n",2.*Nano->Height,2.*Nano->Height,10.); fprintf(AreaS,"#l(%lf %lf %lf) \n",pEdge(0),pEdge(1),pEdge(2)); HeaderNano(AreaS); char FName[60]; for(int f=NFile[0];f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_NO)) return; SetNNano(1); if(StalkPos(OldPos)) continue; //Nano->Pos[CNorm] = pCm(CNorm); //Nano->Pos[CNorm] -= floor(Nano->Pos[CNorm]*pInvEdge(CNorm))*pEdge(CNorm); double Cm[3] = {0.,0.,0.}; double CountCm = 0; int nPart = 0; double Pos[3]; //counts the particles inside the torus for(int p=0;p<pNPart();p++){ for(int d=0;d<3;d++){ Pos[d] = pPos(p,d) - Nano->Pos[d]; Pos[d] -= floor(pPos(p,d)*pInvEdge(d))*pEdge(d); } double Rad = hypot(Pos[CLat1],Pos[CLat2]); if(Rad > Nano->Height) continue; if(fabs(Pos[CNorm]) > RadTorus) continue; // fprintf(AreaS,"{t[%d 0 %d] x(%lf %lf %lf)",nPart++,pType(p),pPos(p,0),pPos(p,1),pPos(p,2)); // if(Ln[p].NLink > 0) fprintf(AreaS,"l[%d]",p-Ln[p].Link[0]+nPart+1); // fprintf(AreaS,"}\n"); if(pType(p) == 1) continue; for(int d=0;d<3;d++){ Cm[d] += pPos(p,d); } CountCm += 1.; int vx = (int)(Pos[CLat1]/(2.*Nano->Height)*NBin); vx += NBin/2; if(vx < 0 || vx >= NBin) continue; int vy = (int)(Pos[CLat2]/(2.*Nano->Height)*NBin); vy += NBin/2; if(vy < 0 || vy >= NBin) continue; Count[vx*NBin+vy] += 1.; } double Area = 0.; double Norm = 0.; for(int vx=0;vx<NBin;vx++){ for(int vy=0;vy<NBin;vy++){ if(Count[vx*NBin+vy] < 1.) continue; // double x = vx*Nano->Height*2./(double)NBin; // double y = vy*Nano->Height*2./(double)NBin; // fprintf(AreaS,"{t[%d 0 2] x(%lf %lf %lf)}\n",nPart++,x+pNanoPos(0,0)-Nano->Height,y+pNanoPos(0,1)-Nano->Height,pNanoPos(0,2)); Area += 1.; } } if(CountCm <= 0.){ printf("No particles in the torus %s\n",cFile[f]); return; } Nano->Area = SQR(2.*Nano->Height)*Area/(double)(SQR(NBin)); for(int d=0;d<3;d++){ Cm[d] /= CountCm; } Cm[CNorm] = pCm(CNorm); //fprintf(AreaS,"%lf %lf %lf\n",Cm[0]-Nano->Pos[0],Cm[1]-Nano->Pos[1],Cm[2]-Nano->Pos[2]); for(int d=0;d<3;d++){ Nano->Pos[d] = Cm[d] - floor(Cm[d]*pInvEdge(d))*pEdge(d); fprintf(StalkArea,"%lf %lf\n",pTime(),Nano->Area); } SetNanoBkf(0); Nano->Height = Nano->Rad + sqrt(Nano->Area/DUE_PI); char String[120]; StringNano(String,0); fprintf(StalkArea,"%lf %lf\n",pTime(),Nano->Area); fprintf(FNano,"sed '/Rigid/c\\%s' %s > Ciccia.dat\n",String,cFile[f]); fprintf(FNano,"mv Ciccia.dat %s\n",cFile[f]); sprintf(FName,"Centered%05d.dat",f); //Write(FName); //HeaderNano(AreaS); } fclose(AreaS); fclose(StalkArea); fclose(FNano); free(Count); printf("\n"); }
void ElPoly::IsoSurf(int NSample,double *IsoLevel,int NIso){ int NPairF = NFile[1]-NFile[0]; double OldPos[3] = {pNanoPos(0,0),pNanoPos(0,1),pNanoPos(0,2)}; double DensEl = CUB(NSample)/(pVol()*NPairF); double Dens = 13.3; FILE *FNano = fopen("NanoPos.txt","w"); //IsoLevel *= NPairF; for(int ff=NFile[0];ff<NFile[1];ff+=NPairF){ double *Plot = (double *)calloc(CUBE(NSample),sizeof(double)); double Min = 0.; double Max = 0.; VAR_TRIANGLE *Triang = NULL; double Pos[3]; for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ Processing(f); if(OpenRisk(cFile[f],BF_PART))return; for(int b=0;b<pNBlock();b++){ for(int p=Block[b].InitIdx;p<Block[b].EndIdx;p++){ if(pType(p) != 0)continue; for(int d=0;d<3;d++){ Pos[d] = pPos(p,d) - (pNanoPos(0,d)-.5*pEdge(d)); Pos[d] -= floor(Pos[d]*pInvEdge(d))*pEdge(d); } int sx = (int)(Pos[0]*pInvEdge(0)*NSample); int sy = (int)(Pos[1]*pInvEdge(1)*NSample); int sz = (int)(Pos[2]*pInvEdge(2)*NSample); int sTot = (sx*NSample+sy)*NSample+sz; Plot[sTot] += DensEl; if(Max < Plot[sTot]) Max = Plot[sTot]; if(Min > Plot[sTot]) Min = Plot[sTot]; } } } Matrice Mask(3,3,3); Mask.FillGaussian(.5,3.); Mask.Print(); int NDim = 3; int IfMinImConv = 1; Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); Mask.ConvoluteMatrix(Plot,NSample,NDim,IfMinImConv); // ConvoluteMatrix(Plot,NSample,&Mask,3); // ConvoluteMatrix(Plot,NSample,&Mask,3); char FString[256]; sprintf(FString,"IsoSurf%05d.dat",ff); FILE *F2Write = fopen(FString,"w"); fprintf(F2Write,"#l(%lf %lf %lf) v[%d] d[polygon]\n",pEdge(0),pEdge(1),pEdge(2),NSample); HeaderNano(F2Write); int NTri = 0; for(int i=0;i<NIso;i++){ printf("Min %lf Max %lf IsoLevel %lf DensEl %lf\n",Min,Max,IsoLevel[i],DensEl); Triang = MarchingCubes(Plot,NSample,IsoLevel[i],&NTri); for(int t=0;t<NTri;t++){ for(int i=0;i<3;i++){ int l1 = t*3 + (i+1)%3; int l2 = t*3 + (i+2)%3; for(int d=0;d<3;d++) Pos[d] = Triang[t].p[i].x[d]; int sx = (int)(Pos[0]*pInvEdge(0)*NSample); int sy = (int)(Pos[1]*pInvEdge(1)*NSample); int sz = (int)(Pos[2]*pInvEdge(2)*NSample); int sTot = (sx*NSample+sy)*NSample+sz; fprintf(F2Write,"{t[%d %d %d] ",sTot,t,0); fprintf(F2Write,"x(%lf %lf %lf) ",Pos[0],Pos[1],Pos[2]); fprintf(F2Write,"v(%lf %lf %lf) ",Triang[t].n[i].x[0],Triang[t].n[i].x[1],Triang[t].n[i].x[2]); fprintf(F2Write,"l[%d] l[%d]}\n",l1,l2); } } } fclose(F2Write); free(Plot); free(Triang);continue; int NVertex = CUBE(2*NSample-1); double *WeightL = (double *) calloc(NVertex,sizeof(double)); NormalWeight(Triang,WeightL,NSample,NTri); double CmStalk[3] = {0.,0.,0.};//OldPos[0],OldPos[1],OldPos[2]}; double CountStalk = 0.; for(int t=0;t<NTri;t++){ for(int v=0;v<3;v++){ int vRef = Triang[t].v[v]; for(int d=0;d<3;d++){ CmStalk[d] = Triang[t].p[v].x[d]*WeightL[vRef]; } CountStalk += WeightL[vRef]; } } free(WeightL); free(Triang); if(CountStalk <= 0.) CountStalk = 1.; for(int d=0;d<3;d++){ CmStalk[d] /= CountStalk; } pPos(CmStalk); SetNNano(1); for(int d=0;d<3;d++){ Nano->Pos[d] = CmStalk[d]; OldPos[d] = Nano->Pos[d]; } SetNanoBkf(0); Nano->Axis[0] = 0.; Nano->Axis[1] = 0.; Nano->Axis[2] = 1.; Nano->Rad = .5; Nano->Height = 4.; Nano->Hamaker = 1.; Nano->OffSet = 1.; Nano->Shape = SHAPE_STALK; for(int f=ff;f<ff+NPairF&&f<NFile[1];f++){ char String[120]; StringNano(String,0); fprintf(FNano,"sed '/Rigid/c\\%s' %s > Ciccia.dat\n",String,cFile[f]); fprintf(FNano,"mv Ciccia.dat %s\n",cFile[f]); //command("chmod u+x %s\n","NanoPos.txt"); //SubNanoHeader(cFile[f]); } printf("\n"); } fclose(FNano); }
int ElPoly::ProjectionF(int NBin,int Coord){ if(Coord > 4 || Coord <0) return 1; int NType = 5; double *Plot = (double *)calloc(NBin*NBin*NType,sizeof(double)); double InvNBin = 1./(double)NBin; double RefPos[3] = {0.,0.,0.}; for(int d=0;d<3;d++){ RefPos[d] = Nano->Pos[d]-.5*pEdge(d); } if(Coord == 3){ RefPos[0]=pCm(0);RefPos[1]=pCm(1);RefPos[2]=pCm(2); } SetEdge(.5*MIN(pEdge(CLat1),pEdge(CLat2)),3); for(int f=NFile[0];f<NFile[1];f++){ Processing(f); OpenRisk(cFile[f],BF_PART); ShiftSys(SHIFT_CM); int NPlot = 0; //---Projects-against-one-coordinate-- if(Coord < 3){ int coord1 = (Coord+1)%3; int coord2 = (Coord+2)%3; for(int p=0;p<pNPart();p++){ double x = pPos(p,coord1) - RefPos[coord1]; x -= floor(x*pInvEdge(coord1))*pEdge(coord1); double y = pPos(p,coord2) - RefPos[coord2]; y -= floor(y*pInvEdge(coord2))*pEdge(coord2); int v = (int)(NBin*x*pInvEdge(coord1)); if( v < 0 || v >= NBin) continue; int vv = (int)(NBin*y*pInvEdge(coord2)); if( vv < 0 || vv >= NBin) continue; int t = pType(p); if( t < 0 || t > 3) continue; if( CHAIN_IF_TYPE(Ch[pChain(p)].Type,CHAIN_ADDED) ) Plot[(v*NBin+vv)*NType+3] += 1.; Plot[(v*NBin+vv)*NType+t] += 1.; if(p<pNPart()-1) if(pType(p+1) == 1 && pType(p) == 0) Plot[(v*NBin+vv)*NType+4] += 1.; } } //---Projects-against-the-radial-coordinate-- else if(Coord == 3){ SetEdge(.5*MAX((pEdge(CLat1)),(pEdge(CLat2))),3); for(int p=0;p<pNPart();p++){ double x = pPos(p,CLat1) - RefPos[CLat1]; x -= floor(x*pInvEdge(CLat1))*pEdge(CLat1); double y = pPos(p,CLat2) - RefPos[CLat2]; y -= floor(y*pInvEdge(CLat2))*pEdge(CLat2); double z = pPos(p,CNorm) - RefPos[CNorm]; z -= floor(z*pInvEdge(CNorm))*pEdge(CNorm); double r = sqrt(SQR(x)+SQR(y)); int v = (int)(NBin*r*pInvEdge(3)); if( v < 0 || v >= NBin) continue; int vv = (int)(NBin*pPos(p,CNorm)/pEdge(CNorm)); if( vv < 0 || vv >= NBin) continue; int t = pType(p); if( t < 0 || t > 3) continue; if( CHAIN_IF_TYPE(Ch[pChain(p)].Type,CHAIN_ADDED) ) Plot[(v*NBin+vv)*NType+3] += 1.; Plot[(v*NBin+vv)*NType+t] += 1.; if(p<pNPart()-1) if(pType(p+1) == 1 && pType(p) == 0) Plot[(v*NBin+vv)*NType+4] += 1.; } } } printf("\n"); //-----writes-the-output-file------------------- FILE *FileToWrite = NULL; FileToWrite = fopen("Projection.xyd","w"); fprintf(FileToWrite,"#l(%lf %lf %lf) v[%d] d[%s]\n",pEdge(CLat1),pEdge(CLat2),pEdge(CNorm),NBin,ChooseDraw(EL_QUAD1)); int coord1 = (Coord+1)%3; int coord2 = (Coord+2)%3; if(Coord == 3){ coord1 = 3; coord2 = CNorm; } double Max[NType]; for(int t=0;t<NType;t++){ Max[t] = Plot[t]; for(int v=0;v<NBin;v++) for(int vv=0;vv<NBin;vv++) if(Max[t] < Plot[(v*NBin+vv)*NType+t]) Max[t] = Plot[(v*NBin+vv)*NType+t]; Max[t] = Max[t] <= 0. ? 1. : Max[t]; } //for(int t=0;t<NType-1;t++){ for(int t=0;t<1;t++){ for(int v=0;v<NBin;v++){ for(int vv=0;vv<NBin;vv++){ int p = (v*NBin+vv)*NType+t; int c = 0; if(Plot[p] < .1) continue; double x = (v)*InvNBin*pEdge(CLat1); double y = (vv)*InvNBin*pEdge(CLat2); double dens = Plot[p]/Max[t]*5.+.5*pEdge(CNorm); double NanoAdded = 0.;//Plot[p]/Max[t]+Plot[((v*NBin+vv)*NType+3]/Max[3]; double Phob = t == 0 ? Plot[(v*NBin+vv)*NType+0]/Max[0] : 0.; double Phil = t == 1 ? Plot[(v*NBin+vv)*NType+1]/Max[1] : 0.; fprintf(FileToWrite,"{t[%d %d %d] x(%lf %lf %lf) v(%lf %lf %lf)}\n",p,c,t,x,y,dens,NanoAdded,Phob,Phil); } } } free(Plot); fclose(FileToWrite); return 0; }
pStatement Statement::parse() { if (currentToken().type == TT_NAMESPACE) { nextToken(); _namespace = new_Namespace()->parse(); } else if(currentToken().type == TT_TYPEDEF) { } else if(currentToken().type == TT_STRUCT || currentToken().type == TT_CLASS) { isClass = true; if(currentToken().type == TT_STRUCT) { isStruct = true; } nextToken(); _namespace = new_Namespace(); _namespace->statementsBlock = new_StatementsBlock(); _namespace->id = currentToken().strVal; pType newType = pType(new Type(owner, false) ); pExprResult res = owner->new_ExprResult(); res->evalType = ERT_TYPE; res->type = newType; newType->definition = this; owner->parsingStatementsBlockStack.back()->vars[_namespace->id] = res; _namespace->parse(); if(currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken(), "Expected semicolon"); } nextToken(); } else if (currentToken().type == TT_BRACE_OPEN) { this->sb = new_StatementsBlock()->parse(); } else if (currentToken().type == TT_BREAK || currentToken().type == TT_RETURN || currentToken().type == TT_ECHO || currentToken().type == TT_CONTINUE) { isSpecial = true; specialType = currentToken().type; nextToken(); if (specialType == TT_RETURN || specialType == TT_ECHO) { expr = new_Expr()->parse(); } if (currentToken().type != TT_SEMICOLON) { throwTokenExpected(TT_SEMICOLON); } nextToken(); } else if (currentToken().type == TT_IF) { isSpecial = true; specialType = currentToken().type; nextToken(); expr = new_Expr()->parse(); statement1 = new_Statement()->parse(); if (currentToken().type == TT_ELSE) { nextToken(); statement2 = new_Statement()->parse(); } } else if (currentToken().type == TT_WHILE) { localStatementsBlock = new_StatementsBlock(); owner->parsingStatementsBlockStack.push_back(localStatementsBlock); isSpecial = true; specialType = currentToken().type; if (nextToken().type != TT_PARENTHESIS_OPEN) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); expr = new_Expr()->parse(); if (currentToken().type != TT_PARENTHESIS_CLOSE) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); statement1 = new_Statement()->parse(); owner->parsingStatementsBlockStack.pop_back(); } else if (currentToken().type == TT_FOR) { localStatementsBlock = new_StatementsBlock(); owner->parsingStatementsBlockStack.push_back(localStatementsBlock); isSpecial = true; specialType = currentToken().type; if (nextToken().type != TT_PARENTHESIS_OPEN) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); statement1 = new_Statement()->parse(); expr = new_Expr()->parse(); if (currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); expr2 = new_Expr()->parse(); if (currentToken().type != TT_PARENTHESIS_CLOSE) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); statement2 = new_Statement()->parse(); owner->parsingStatementsBlockStack.pop_back(); } else { tryParse([this]() { tn = new_Typename()->parse(); pVarDeclarationAllowDefault vd = new_VarDeclarationAllowDefault()->parse(); if (owner->currentToken().type == TT_PARENTHESIS_OPEN) { if (!vd->canBeFunctionDeclaration() ) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); this->function = pFunction(new Function(owner, vd->vd->id) ); this->function->args = new_FunctionArgs()->parse(); if (currentToken().type == TT_PARENTHESIS_CLOSE) { if (nextToken().type == ';') { this->function->statementsBlock = nullptr; } else { this->function->statementsBlock = new_StatementsBlock()->parse(); for (auto vd: this->function->args->vds) { this->function->statementsBlock->vars[vd->vd->id] = nullptr; } } } else { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken(), "Unexpeted token"); } } else { if (currentToken().type == TT_COMMA || currentToken().type == TT_SEMICOLON) { vds.push_back(vd); } while (currentToken().type == TT_COMMA) { nextToken(); vds.push_back(new_VarDeclarationAllowDefault()->parse() ); } if (currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); } }, [this](exception &e) { vds.clear(); tn = nullptr; expr = new_Expr()->parse(); this->function = nullptr; if (currentToken().type != TT_SEMICOLON) { Parser::get()->parsingException(__FUNCTION__, __FILE__, __LINE__, currentToken() ); } nextToken(); }); } return pStatement(this); }
/** * This method returns the default value for a property. * * @param index The index of the property in pType. * @return The default vaule as a PyObject. */ PyObjectPtr PropertiesHelper::propGetDefault( int index ) { return pType()->property(index)->dataType()->pDefaultValue(); }
QStringList FMPDFFontExtractor::list() { if(!document) return mfont.keys(); if(cachedList) return mfont.keys(); else cachedList = true; PoDoFo::TCIVecObjects objIt( document->GetObjects().begin() ); PoDoFo::PdfName pType("Type"); PoDoFo::PdfName pSubtype("Subtype"); PoDoFo::PdfName pFont("Font"); PoDoFo::PdfName pType1("Type1"); PoDoFo::PdfName pTrueType("TrueType"); PoDoFo::PdfName pFontDescriptor( "FontDescriptor" ); PoDoFo::PdfName pFontFile( "FontFile" ); PoDoFo::PdfName pFontFile3( "FontFile3" ); PoDoFo::PdfName pFontName( "FontName" ); while( objIt != document->GetObjects().end() ) { PoDoFo::PdfObject* obj(*objIt); if ( obj->IsDictionary() ) { if(obj->GetIndirectKey(pType)) { PoDoFo::PdfName type( obj->GetIndirectKey(pType)->GetName() ); if(type == pFont) { if(obj->GetIndirectKey( pSubtype )) { PoDoFo::PdfName subtype ( obj->GetIndirectKey( pSubtype )->GetName() ); if ((subtype == pType1) || (subtype == pTrueType)) { PoDoFo::PdfObject * fontDescriptor ( obj->GetIndirectKey ( pFontDescriptor ) ); if (fontDescriptor ) { bool hasFile(false); PoDoFo::PdfObject * fontFile ( fontDescriptor->GetIndirectKey ( pFontFile ) ); if ( !fontFile ) { fontFile = fontDescriptor->GetIndirectKey(pFontFile3) ; if ( !fontFile ) qWarning ( "Font not embedded not supported yet" ); else hasFile = true; } else hasFile = true; if(hasFile) { PoDoFo::PdfName fontName(fontDescriptor->GetIndirectKey(pFontName)->GetName()); if(1) { QString n(QString::fromStdString( fontName.GetName() )); mfont[n] = fontFile; // we know naming it pfb is wrong mType[n] = (subtype == pType1) ? "pfb" : "ttf"; } else qDebug()<<"Error: no /FontName key"; } } } } } } } objIt++; } return mfont.keys(); }