void CImConvertCharconv::SetSystemDefaultCharsetL()
	{	
	TBuf8<KMaxMIMECharSetLength> charsetName;
	TUint charset = KDefaultPlainCharset;
	
	// Try to get the character set from the Central Repository
	TInt err = GetSystemCharsetFromCenRepL(charsetName);
	if (KErrNone != err)
		{
		// That failed, fallback to reading from the resource file
		// Check the resource file..
		RResourceFile resFile;
		OpenResourceFileL(resFile, iFs);	// NB leaves if file not found

		// make sure the resource file will be closed if anything goes wrong
		TCleanupItem close( CloseResourceFile, &resFile );
		CleanupStack::PushL( close );		
			
		HBufC8* buf = resFile.AllocReadLC( DEFAULT_SYSTEM_CHARSET );

		TResourceReader reader;
		reader.SetBuffer(buf);
		charsetName.Copy(reader.ReadTPtrC8());
		
		CleanupStack::PopAndDestroy(2,&resFile); // buf, resFile
		}

	charset = GetMimeCharsetUidL(charsetName);

	// If the character set in the resource file is not recognised. Leave..
	if (charset==KUidMsvCharsetNone || !CharsetAvailable(charset))
		User::Panic(_L("IMCM"),EImcmSystemDefaultCharsetNotSupported);
	else
		iSystemDefaultCharset=charset;
	}
EXPORT_C TInt CImConvertCharconv::PrepareToConvertToFromOurCharsetL(const TUint aUid)
	{
	if (!aUid)
		{
		iCharsetUid=DefaultCharset();
		return ETrue;
		}
	else if (CharsetAvailable(aUid))
		{
		iCharconvState = CCnvCharacterSetConverter::KStateDefault;
		iConverter.PrepareToConvertToOrFromL(aUid, *iCharsetsAvailable, iFs);
		iConverter.SetReplacementForUnconvertibleUnicodeCharactersL(KMiutUndisplayableChar);
		iCharsetUid=aUid;
		return ETrue;
		}

	iCharsetUid=KUidMsvCharsetNone;
	return EFalse; 
	}
Exemple #3
0
void ShowTrackStats(StdHepWindow *window, int trackNum)
{
    PhaseParticle *p;
    SpaceVertex *vert;
    char nameText[MAXCHAR_HEPNAM], statText[512], *stabilityText, userValueText[40];
    char titleText[40];
    XmString cStatText;
    double momentum, pt, rapidity, pseudorap, userValue;
    int outColor;
    double outVec[3];
    XmFontList fontList;
    PhaseWindow *winp = (PhaseWindow *) window;
    SpaceWindow *wins = (SpaceWindow *) window;
    
    if (trackNum == NO_TRACK) {
    	if (window->trackWindowShell)
    	    XtUnmapWidget(window->trackWindowShell);
    	return;
    }
    
    p = &window->event.particles[trackNum];
    hepnam_(&p->id, nameText, MAXCHAR_HEPNAM);
    *(char *)strchr(nameText, ' ') = '\0';
    sprintf(titleText, "%s (%d)", nameText, trackNum);  

    /* If greek font is available, use greek letters in particle name */
    GET_ONE_RSRC(window->statsLabel, XmNfontList, &fontList);
    if (CharsetAvailable("greek", fontList))
    	hepnmg_(&p->id, nameText);
    
    if (p->stable)
    	stabilityText = "stable";
    else
    	stabilityText = "unstable";
    	
    momentum = ParticleMomentum(p->px, p->py, p->pz);
    pt = ParticlePT(p->px, p->py);
    rapidity = ParticleRapidity(p->px, p->py, p->pz, p->mass);
    pseudorap = ParticlePseudorapidity(p->px, p->py, p->pz); 
/*     if (window->userMapProc) {
	(*window->userMapProc)(window->event, outVec, &outColor);
	userValue = sqrt(pow(outVec[0],2)+pow(outVec[1],2)+pow(outVec[2],2));
	sprintf(userValueText, "\nUser Value = %lf", userValue);
    } else {
    	sprintf(userValueText, "");
    } */
    
    /* In this version, no User text.. */
    sprintf(userValueText, "");
    sprintf(statText, "Particle: %s\nPx = %f\nPy = %f\nPz = %f\n\
Momentum = %f\nPt = %f\nRapidity = %f\nPseudoRapidity = %f%s",
	nameText, p->px, p->py, p->pz, momentum, pt, rapidity,
	pseudorap, userValueText);
    if (window->type == STDHEP_SPACE) { 
    /* Add one line to specify the vertex */
      vert = wins->vertices; vert += trackNum;
       sprintf(statText, "Particle: %s\nPx = %f\nPy = %f\nPz = %f\n\
Momentum = %f\nPt = %f\nRapidity = %f\nPseudoRapidity = %f\n\
\n\Origin: \nX = %f\nY = %f\nZ = %f\nLife = %f",
	nameText, p->px, p->py, p->pz, momentum, pt, rapidity,
	pseudorap,vert->x, vert->y, vert->z, vert->time);
    } 
/*
** DrawEvent
**
** Map an event to 3D segments for the spin widget.  From a 4-momentum vector,
** (i.e., the 3-momentum vector and the unique identifier from which a physical
** mass can be obtained), An array of 3-dimensional vector and track type is
** deduced).  The structure PhaseEvent is described in phase.h.  The setting
** of the displayMode toggle on the event display panel determines how the
** event is mapped onto the screen:
** 
** BY_MOMENTUM:		The length is proportional the  |P|, the norm of the 3-d
**		      	momentum vector. This is the simplest and default option.
**
** BY_PT:	 	The length of the vector is proportional to Pt, the 
**			transverse momentum. This trick greatly enhances 
**			the "high Pt" Physics in the event.
**
** BY_RAPIDITY: 	The length of the vector is propotional to the rapidity 
**			of the particle, as defined in the PDG bible.
**
** BY_PSEUDORAPIDITY:	The length of the vector is proportional to the pseudo
**			rapidity, i.e., the mass of the particle is 
**			neglected.
**
** BY_USER_ROUTINE :	The user function specified in the DisplayEvent call
**			is called to determine what the new vector ought to be... 
*/
void DrawEvent(StdHepWindow *window, int setScale)
{
    int i, maxIndex, nSegments, nns, npvis;
    int doPoints;
    double scale, innerScale, length, maxLength, outVec[3];
    SpinSegment *segment, *segments, *segdt, temp;
    SpinPoint *point, *points;
    PhaseParticle *p, *particles = window->event.particles;
    int nStable = 0, nParticles = window->event.nParticles;
    SpaceVertex *pinv, *v;
    char nameText[MAXCHAR_HEPNAM], statText[255];
    XmString cStatText;
    /* There is a very wierd Ultrix compiler problem concerning this statement:*/
    /*    PhaseEvent *event; */
    static char *unitText[6] = {"p", "Pt", "Eta", "Eta", "value", "Eta-Pt"};
    XmFontList fontList;
    PhaseWindow *winp;
    SpaceWindow *wins;
    ParaWindow *winpa;
    
    /* If a Space window, find out the number of vertices in this event, 
       so we can allocate more space to draw short segments to represent 
       a vertex.. */
       
    if (window->type == STDHEP_SPACE) {
       wins = (SpaceWindow *) window;
    /* allocate space for the maximum possible number of segments or points */
       nns = NUMPINSTETA * NUMPINSPHI * wins->numRealVertices + nParticles;
       nns += wins->nDetectorSegments;
       segments = (SpinSegment *)XtMalloc(sizeof(SpinSegment) * nns);
       doPoints = False;
     } else if (window->type == STDHEP_PARA) {
        winpa = (ParaWindow *) window;
	segments = (SpinSegment *)XtMalloc(sizeof(SpinSegment) * nParticles);
	doPoints = False;
     } else {
        winp =(PhaseWindow *) window;
        doPoints = (winp->vectorLength == 0.);
        if (doPoints)
	    points = (SpinPoint *)XtMalloc(sizeof(SpinPoint) * nParticles);
        else
	   segments = (SpinSegment *)XtMalloc(sizeof(SpinSegment) * nParticles);
     }
    
    /* Loop over all of the particles, translating them into 3-D line segments
       or points for the Spin widget.  Also find the particle of maximum value
       (for setting the scale and printing statistics), and the number of stable
       particles (for printing statistics later) */
    nSegments = 0;
    npvis = 0;
    maxLength = -1.;
    if (doPoints) {
	point = points;
	for (i=0, p=particles; i<nParticles; i++, p++) {
    	    if (p->stable)
    		nStable++;
    	    if (ParticleToSegment(winp, p, &temp, &length)) {
    	        point->x = temp.x1;
    	        point->y = temp.y1;
    	        point->z = temp.z1;
    	        point->pixel = temp.pixel;
    		point++;
    		nSegments++;
    		npvis++;
    		if (length > maxLength) {
    		    maxLength = length;
    		    maxIndex = i;
    		}
    	    }
	}
	/* Display the points */
	SpinSetPoints(window->spin, points, nSegments);
	XtFree((char *) points);
    } else {
      if (window->type == STDHEP_PHASE) {
	segment=segments;
	for (i=0, p=particles; i<nParticles; i++, p++) {
    	    if (p->stable)
    		nStable++;
    	    if (ParticleToSegment(winp, p, segment, &length)) {
    		segment++;
    		nSegments++;
    		npvis++;
    		if (length > maxLength) {
    		    maxLength = length;
    		    maxIndex = i;
    		}
    	    }
	}
       } else if (window->type == STDHEP_PARA) {
	 segment=segments;
	 for (i=0, p=particles; i<nParticles; i++, p++) {
    	    if (p->stable)
    		nStable++;
    	    if (ParticleToParaSegment(winpa, p, segment, &length)) {
    		segment++;
    		nSegments++;
    		npvis++;
    		if (length > maxLength) {
    		    maxLength = length;
    		    maxIndex = i;
    		}
    	    }
    	  }
       } else {            
	   segment=segments;
           maxLength = 0.;
	   for (i=0, p=particles, v=wins->vertices; 
	                     i<nParticles; i++, p++, v++) {
    	    if (p->stable)
    		nStable++;
    	    if (TrackToSegment(wins, p, v, segment, &length)) {
    		segment++;
    		nSegments++;
    		npvis++;
    		if (length > maxLength) {
    		    maxLength = length;
    		    maxIndex = i;
    		}
    	    }
	   }
	   if (wins->nDetectorSegments > 0) {
	    for (i=0, segdt = wins->detectorSegments;
	          i < wins->nDetectorSegments;
	           i++, segdt++, segment++, nSegments++)  
	          detectorToSegment(wins, segdt, segment);
	   } 
	   if (wins->showVertices) {
	   for (i=0, pinv=wins->realVertices;
	         i < wins->numRealVertices; i++, pinv++){
	          if (fabs((double) pinv->z) < wins->currentScale) {
	            VertexToSegment(wins, pinv, &segment);
	             nSegments += NUMPINSPHI *NUMPINSTETA;
	          } 
             }
           }
         }
	}    
	/* Display the line segments with the spin widget */
	SpinSetSegments(window->spin, segments, nSegments);
	XtFree((char *) segments);
	/* 
	* Currently, the spin widget Perspective resource is buggy, 
	* turn if off.. 
	*/
        SET_ONE_RSRC(window->spin, XmNperspectiveOn, FALSE);
    
    /* If requested, set the scale to show the data most effectively */
    if (setScale) {
    	SpinSetScale(window->spin, (maxLength > 0.) ? 1./maxLength : 1.);
    	DrawScale(window);
    }
    
    /* Fill in the statistics window */
    if (npvis == 0) {
    	sprintf(statText, "%d tracks, %d are stable.\nNo Tracks are visible",
    		nParticles, nStable);
    } else {
        if ((window->type == STDHEP_PHASE) || (window->type == STDHEP_PARA)) { 
	    GET_ONE_RSRC(window->statsLabel, XmNfontList, &fontList);
	    if (CharsetAvailable("greek", fontList)) {
    	        hepnmg_(&particles[maxIndex].id, nameText);
	    } else {
    	        hepnam_(&particles[maxIndex].id, nameText, MAXCHAR_HEPNAM);
	         *strchr(nameText, ' ') = '\0';
	    }
	    if (window->type == STDHEP_PHASE) {
	    sprintf(statText,
"%d tracks, %d are stable,\n%d are now displayed\nTrack of max. %s is a(n) %s",
    	        nParticles, nStable, nSegments,
    	        unitText[winp->displayMode], nameText);
    	    } else { 
	    sprintf(statText,
"%d tracks, %d are stable,\n%d are now displayed\nTrack of max. %s is a(n) %s",
    	        nParticles, nStable, nSegments,
    	        unitText[5], nameText);
    	    }
    	  } else {
    	    if (wins->showVertices)
    	      nns = nSegments
    	         - (NUMPINSPHI * NUMPINSTETA * wins->numRealVertices);
    	    else nns = nSegments; 
	    sprintf(statText,
"%d tracks, %d are stable,\n%d are now displayed\n %d distinct vertices found",
    	        nParticles, nStable, nns, wins->numRealVertices);
    	  }
    }
    cStatText = MultiFontString(statText);
    SET_ONE_RSRC(window->statsLabel, XmNlabelString, cStatText);
    XmStringFree(cStatText);
}