示例#1
0
short GridWindClick(DialogPtr dialog, short itemNum, long lParam, VOIDPTR data)
{	
	long menuID_menuItem;
	switch (itemNum) {
		case M18OK:
		{	
			short timeZone = GetPopSelection(dialog, M18bTIMEZONEPOPUP);
			Seconds timeShift = sharedWMover->timeGrid->fTimeShift;
			long timeShiftInHrs;
			
			short angleUnits = GetPopSelection(dialog, M18ANGLEUNITSPOPUP);
			
			timeShiftInHrs = EditText2Long(dialog, M18bTIMESHIFT);
			if (timeShiftInHrs < -12 || timeShiftInHrs > 14)	// what should limits be?
			{
				printError("Time offsets must be in the range -12 : 14");
				MySelectDialogItemText(dialog, M18bTIMESHIFT,0,100);
				break;
			}
			
			//mygetitext(dialog, M18bFILENAME, sharedWMover->fFileName, kPtCurUserNameLen-1);
			mygetitext(dialog, M18bFILENAME, sharedWMover->timeGrid->fVar.userName, kPtCurUserNameLen-1);
			sharedWMover -> bActive = GetButton(dialog, M18ACTIVE);
			sharedWMover->bShowArrows = GetButton(dialog, M18bSHOWARROWS);
			sharedWMover->fArrowScale = EditText2Float(dialog, M18bARROWSCALE);
			
			sharedWMover -> fAngleScale = EditText2Float(dialog,M18ANGLESCALE);
			if (angleUnits==2) sharedWMover->fAngleScale *= PI/180.;		
			sharedWMover -> fSpeedScale = EditText2Float(dialog,M18SPEEDSCALE);
			sharedWMover -> fUncertainStartTime = (long) round(EditText2Float(dialog,M18UNCERTAINSTARTTIME)*3600);
			
			sharedWMover -> fDuration = EditText2Float(dialog, M18DURATION) * 3600;
			
			if (timeZone>1) sharedWMover->timeGrid->fTimeShift =(long)( EditText2Float(dialog, M18bTIMESHIFT)*3600);
			else sharedWMover->timeGrid->fTimeShift = 0;	// file is in local time
			
			//if (model->GetStartTime() != startTime || model->GetModelTime()!=model->GetStartTime())
			//if (timeShift != sharedWMover->fTimeShift || sharedWMover->GetTimeValue(0) != model->GetStartTime())
			// code goes here, if decide to use this check GetTimeValue is using new fTimeShift...
			//{
			//Seconds timeValZero = sharedWMover->GetTimeValue(0), startTime = model->GetStartTime();
			if (timeShift != sharedWMover->timeGrid->fTimeShift && sharedWMover->timeGrid->GetTimeValue(0) != model->GetStartTime())
			{
				model->SetStartTime(model->GetStartTime() + (sharedWMover->timeGrid->fTimeShift-timeShift));
				//model->SetStartTime(sharedWMover->GetTimeValue(0));
				//sNetCDFDialogMover->SetInterval(errmsg);
				model->NewDirtNotification(DIRTY_RUNBAR); // must reset the runbar
			}
			//}
			sharedWMover->timeGrid->fAllowExtrapolationInTime = GetButton(dialog, M18bEXTRAPOLATECHECKBOX);
			// code goes here, check interval?
			return M18OK;
		}
		case M18CANCEL: return M18CANCEL;
			
		case M18ACTIVE:
		case M18bSHOWARROWS:
		case M18bEXTRAPOLATECHECKBOX:
			ToggleButton(dialog, itemNum);
			break;
			
		case M18bARROWSCALE:
		case M18DURATION:
		case M18UNCERTAINSTARTTIME:
		case M18ANGLESCALE:
		case M18SPEEDSCALE:
			CheckNumberTextItem(dialog, itemNum, TRUE);
			break;
			
		case M18ANGLEUNITSPOPUP:
			PopClick(dialog, itemNum, &menuID_menuItem);
			break;
			
		case M18bTIMESHIFT:
			CheckNumberTextItemAllowingNegative(dialog, itemNum, TRUE);	// decide whether to allow half hours
			break;
			
		case M18bTIMEZONEPOPUP:
			PopClick(dialog, itemNum, &menuID_menuItem);
			ShowGridWindMoverDialogItems(dialog);
			if (GetPopSelection(dialog, M18bTIMEZONEPOPUP) == 2) MySelectDialogItemText(dialog, M18bTIMESHIFT, 0, 100);
			break;
			
		case M18bGMTOFFSETS:
		{
			char gmtStr[512], gmtStr2[512];
			strcpy(gmtStr,"Standard time offsets from GMT\n\nHawaiian Standard -10 hrs\nAlaska Standard -9 hrs\n");
			strcat(gmtStr,"Pacific Standard -8 hrs\nMountain Standard -7 hrs\nCentral Standard -6 hrs\nEastern Standard -5 hrs\nAtlantic Standard -4 hrs\n");
			strcpy(gmtStr2,"Daylight time offsets from GMT\n\nHawaii always in standard time\nAlaska Daylight -8 hrs\n");
			strcat(gmtStr2,"Pacific Daylight -7 hrs\nMountain Daylight -6 hrs\nCentral Daylight -5 hrs\nEastern Daylight -4 hrs\nAtlantic Daylight -3 hrs");
			//printNote(gmtStr);
			short buttonSelected  = MULTICHOICEALERT2(1691,gmtStr,gmtStr2,TRUE);
			switch(buttonSelected){
				case 1:// ok
					//return -1;// 
					break;  
				case 3: // cancel
					//return -1;// 
					break;
			}
			break;
		}
	}
	
	return noErr;
}
示例#2
0
short GridCurrentMoverSettingsClick(DialogPtr dialog, short itemNum, long lParam, VOIDPTR data)
{
	long menuID_menuItem;
	switch (itemNum) {
		case M33OK:
		{
			char errmsg[256];
			short timeZone = GetPopSelection(dialog, M33TIMEZONEPOPUP);
			Seconds timeShift = sGridCurrentDialogMover->timeGrid->fTimeShift;
			float arrowDepth = EditText2Float(dialog, M33ARROWDEPTH), maxDepth=0;
			float maxDepthForExtrapolation = EditText2Float(dialog, M33EXTRAPOLATETOVALUE);
			double tempAlong, tempCross, tempDuration, tempStart;
			long timeShiftInHrs;
			Boolean extrapolateVertically = GetButton(dialog, M33EXTRAPOLATEVERTCHECKBOX);
			//Boolean extrapolateVertically = false;
			Boolean showBottomVel = GetButton(dialog, M33VELOCITYATBOTTOMCHECKBOX);
			TMap *map = sGridCurrentDialogMover -> GetMoverMap();
			
			if (showBottomVel) arrowDepth = -2;	//check maxDepth>0
			if (map)
			{
				maxDepth = map -> GetMaxDepth2();	// 2D vs 3D ?
				//arrowDepth = EditText2Float(dialog, M33ARROWDEPTH);
				if (arrowDepth > maxDepth)
				{
					char errStr[64];
					sprintf(errStr,"The maximum depth of the region is %g meters.",maxDepth);
					printError(errStr);
					break;
				}
			}
			else
			{	// only need this if doing something 3D
				maxDepth = ((TimeGridVelRect*) (sGridCurrentDialogMover -> timeGrid)) -> GetMaxDepth();
				//maxDepth = 1000;
				if (arrowDepth > maxDepth)
				{
					char errStr[64];
					sprintf(errStr,"The maximum depth of the region is %g meters.",maxDepth);
					printError(errStr);
					break;
				}
			}
			
			strcpy(errmsg,"");
			tempAlong = EditText2Float(dialog, M33ALONG);
			tempCross = EditText2Float(dialog, M33CROSS);
			tempDuration = EditText2Float(dialog, M33DURATION);
			tempStart = EditText2Float(dialog, M33STARTTIME);
			if(tempAlong <= 0 || tempCross <= 0) strcpy(errmsg,"The uncertainty must be greater than zero.");	
			else if(tempAlong > 100 || tempCross > 100)	strcpy(errmsg,"The uncertainty cannot exceed 100%.");
			
			if(errmsg[0])
			{
				printError(errmsg);
				if (tempAlong <= 0 || (tempAlong > 100 && tempCross > 0)) MySelectDialogItemText(dialog, M33ALONG,0,100);
				else MySelectDialogItemText(dialog, M33CROSS,0,100);
				break;
			}
			
			if(tempDuration < 1) strcpy(errmsg,"The uncertainty duration must be at least 1 hour.");	// maximum?
			if(errmsg[0])
			{
				printError(errmsg);
				MySelectDialogItemText(dialog, M33DURATION,0,100);
				break;
			}
			
			timeShiftInHrs = EditText2Long(dialog, M33TIMESHIFT);
			if (timeShiftInHrs < -12 || timeShiftInHrs > 14)	// what should limits be?
			{
				printError("Time offsets must be in the range -12 : 14");
				MySelectDialogItemText(dialog, M33TIMESHIFT,0,100);
				break;
			}
			
			if (extrapolateVertically)
			{
				if (maxDepthForExtrapolation==0)
				{
					if (maxDepth>0) 
						sprintf(errmsg,"Either set a max depth for extrapolation or turn off option. The maximum depth of the region is %g meters.",maxDepth);
					else
						sprintf(errmsg,"Either set a max depth for extrapolation or turn off option");
					printNote(errmsg);
					break;
				}
				if (maxDepth>0 && maxDepthForExtrapolation>maxDepth)
				{
					sprintf(errmsg,"The maximum depth of the region is %g meters.",maxDepth);
					printNote(errmsg);
					break;
				}
			}
			mygetitext(dialog, M33NAME, sGridCurrentDialogMover->timeGrid->fVar.userName, kPtCurUserNameLen-1);
			sGridCurrentDialogMover->bActive = GetButton(dialog, M33ACTIVE);
			sGridCurrentDialogMover->fVar.bShowArrows = GetButton(dialog, M33SHOWARROWS);
			sGridCurrentDialogMover->fVar.arrowScale = EditText2Float(dialog, M33ARROWSCALE);
			sGridCurrentDialogMover->fVar.arrowDepth = arrowDepth;
			//sGridCurrentDialogMover->timeGrid->fVar.fileScaleFactor = EditText2Float(dialog, M33SCALE);
			sGridCurrentDialogMover->fVar.curScale = EditText2Float(dialog, M33SCALE);
			
			if (sGridCurrentDialogMover->fVar.alongCurUncertainty != tempAlong || sGridCurrentDialogMover->fVar.crossCurUncertainty != tempCross
				|| sGridCurrentDialogMover->fVar.startTimeInHrs != tempStart || sGridCurrentDialogMover->fVar.durationInHrs != tempDuration)
				sDialogUncertaintyChanged2 = true;
			sGridCurrentDialogMover->fVar.alongCurUncertainty = EditText2Float(dialog, M33ALONG)/100;
			sGridCurrentDialogMover->fVar.crossCurUncertainty = EditText2Float(dialog, M33CROSS)/100;
			//sNetCDFDialogMover->fVar.uncertMinimumInMPS = EditText2Float(dialog, M33MINCURRENT);
			sGridCurrentDialogMover->fVar.startTimeInHrs = EditText2Float(dialog, M33STARTTIME);
			sGridCurrentDialogMover->fVar.durationInHrs = EditText2Float(dialog, M33DURATION);
			
			sGridCurrentDialogMover->fDownCurUncertainty = -sGridCurrentDialogMover->fVar.alongCurUncertainty; 
			sGridCurrentDialogMover->fUpCurUncertainty = sGridCurrentDialogMover->fVar.alongCurUncertainty; 	
			sGridCurrentDialogMover->fRightCurUncertainty = sGridCurrentDialogMover->fVar.crossCurUncertainty;  
			sGridCurrentDialogMover->fLeftCurUncertainty = -sGridCurrentDialogMover->fVar.crossCurUncertainty; 
			sGridCurrentDialogMover->fDuration = sGridCurrentDialogMover->fVar.durationInHrs * 3600.;  
			sGridCurrentDialogMover->fUncertainStartTime = (long) (sGridCurrentDialogMover->fVar.startTimeInHrs * 3600.); 
			//if (timeZone>1) sNetCDFDialogMover->fTimeShift = EditText2Long(dialog, M33TIMESHIFT)*3600*-1;
			if (timeZone>1) sGridCurrentDialogMover->timeGrid->fTimeShift =(long)( EditText2Float(dialog, M33TIMESHIFT)*3600);
			else sGridCurrentDialogMover->timeGrid->fTimeShift = 0;	// file is in local time
			
			//if (model->GetStartTime() != startTime || model->GetModelTime()!=model->GetStartTime())
			// code goes here, should also check if start time has been shifted correctly already (if there is another current)
			//if (timeShift != sNetCDFDialogMover->fTimeShift || sNetCDFDialogMover->GetTimeValue(0) != model->GetStartTime())
			// GetTImeValue adds in the time shift
			// What if time zone hasn't changed but start time has from loading in a different file??
			if ((timeShift != sGridCurrentDialogMover->timeGrid->fTimeShift && sGridCurrentDialogMover->timeGrid->GetTimeValue(0) != model->GetStartTime()))
			{
				//model->SetModelTime(model->GetModelTime() - (sNetCDFDialogMover->fTimeShift-timeShift));
				if (model->GetStartTime() + sGridCurrentDialogMover->timeGrid->fTimeShift - timeShift == sGridCurrentDialogMover->timeGrid->GetTimeValue(0))
					model->SetStartTime(model->GetStartTime() + (sGridCurrentDialogMover->timeGrid->fTimeShift-timeShift));
				//model->SetStartTime(sNetCDFDialogMover->GetTimeValue(0));	// just in case a different file has been loaded in the meantime, but what if user doesn't want start time to change???
				//sNetCDFDialogMover->SetInterval(errmsg);
				model->NewDirtNotification(DIRTY_RUNBAR); // must reset the runbar
			}
			sGridCurrentDialogMover->timeGrid->fAllowExtrapolationInTime = GetButton(dialog, M33EXTRAPOLATECHECKBOX);
			((TimeGridVelRect*) (sGridCurrentDialogMover->timeGrid))->fAllowVerticalExtrapolationOfCurrents = GetButton(dialog, M33EXTRAPOLATEVERTCHECKBOX);
			// code goes here, add box to dialog to input desired depth to extrapolate to 
			if (((TimeGridVelRect*) (sGridCurrentDialogMover->timeGrid))-> fAllowVerticalExtrapolationOfCurrents) ((TimeGridVelRect*) (sGridCurrentDialogMover->timeGrid))->fMaxDepthForExtrapolation = EditText2Float(dialog, M33EXTRAPOLATETOVALUE); 
			else ((TimeGridVelRect*) (sGridCurrentDialogMover->timeGrid))->fMaxDepthForExtrapolation = 0.;
			
			return M33OK;
		}
			
		case M33CANCEL: 
			return M33CANCEL;
			
		case M33ACTIVE:
		case M33SHOWARROWS:
		case M33EXTRAPOLATECHECKBOX:
			ToggleButton(dialog, itemNum);
			break;
			
		case M33VELOCITYATBOTTOMCHECKBOX:	// code goes here, showhide the M33ARROWDEPTH, M33ARROWDEPTHUNITS
			ToggleButton(dialog, itemNum);
			ShowHideVerticalExtrapolationDialogItems2(dialog);
			if (!GetButton(dialog,M33VELOCITYATBOTTOMCHECKBOX))
			Float2EditText(dialog, M33ARROWDEPTH, 0, 6);
			break;
			
		case M33EXTRAPOLATEVERTCHECKBOX:
			ToggleButton(dialog, itemNum);
			ShowHideVerticalExtrapolationDialogItems2(dialog);
			break;
			
		case M33ARROWSCALE:
		case M33ARROWDEPTH:
			//case M33SCALE:
		case M33ALONG:
		case M33CROSS:
			//case M33MINCURRENT:
		case M33STARTTIME:
		case M33DURATION:
			//case M33TIMESHIFT:
		case M33EXTRAPOLATETOVALUE:
			CheckNumberTextItem(dialog, itemNum, TRUE);
			break;
		case M33SCALE:
		case M33TIMESHIFT:
			CheckNumberTextItemAllowingNegative(dialog, itemNum, TRUE);	// decide whether to allow half hours
			break;
			
		case M33TIMEZONEPOPUP:
			PopClick(dialog, itemNum, &menuID_menuItem);
			ShowGridCurrentMoverDialogItems(dialog);
			if (GetPopSelection(dialog, M33TIMEZONEPOPUP) == 2) MySelectDialogItemText(dialog, M33TIMESHIFT, 0, 100);
			break;
			
		case M33GMTOFFSETS:
		{
			char gmtStr[512], gmtStr2[512];
			strcpy(gmtStr,"Standard time offsets from GMT\n\nHawaiian Standard -10 hrs\nAlaska Standard -9 hrs\n");
			strcat(gmtStr,"Pacific Standard -8 hrs\nMountain Standard -7 hrs\nCentral Standard -6 hrs\nEastern Standard -5 hrs\nAtlantic Standard -4 hrs\n");
			strcpy(gmtStr2,"Daylight time offsets from GMT\n\nHawaii always in standard time\nAlaska Daylight -8 hrs\n");
			strcat(gmtStr2,"Pacific Daylight -7 hrs\nMountain Daylight -6 hrs\nCentral Daylight -5 hrs\nEastern Daylight -4 hrs\nAtlantic Daylight -3 hrs");
			//printNote(gmtStr);
			short buttonSelected  = MULTICHOICEALERT2(1691,gmtStr,gmtStr2,TRUE);
			switch(buttonSelected){
				case 1:// ok
					//return -1;// 
					break;  
				case 3: // cancel
					//return -1;// 
					break;
			}
			break;
		}
			
		case M33REPLACEMOVER:
		{
			//sGridCurrentDialogMover->ReplaceMover();
			//mysetitext(dialog, M33NAME, sGridCurrentDialogMover->fVar.userName); // use short file name for now		
		}
	}
	
	return 0;
}