APSF,0 //################################################################################ // Name: RPEHLM_Prefix // Purpose: Standard library of routines to support RPEHLM authored scripts //################################################################################ //================================================================================ // Declarations //================================================================================ //-------------------------------------------------------------------------------- // Const declarations //-------------------------------------------------------------------------------- //Plan constants const cNoPlan = 0 const cMinPlan = 1 const cScratchPlan = "_RPEHLM_Blank.apd" const cPlanFileExt = ".apd" //Object constants const cNoObject = 0 const cMinObject = 1 //Object copy operation flags const cObjCopyAll = 0 const cObjCopyHighlighted = 1 const cObjCopySelected = 2 //Misc. constants const cSilentOn = false const cSilentOff = true const cUserCanceled = -1 //User cancel flag value //-------------------------------------------------------------------------------- // Class declarations //-------------------------------------------------------------------------------- //class ObjectFields // dim Catalog as string // dim Dec as double // dim ForceHighlight as boolean // dim ID as string // dim Magnitude as double // dim Magnitude2 as double // dim Name as string // dim Notes as string // dim Period as double // dim PosAngle as double // dim RA as double // dim Selected as boolean // dim Separation as double // dim Size as string // dim Spectral as string // dim Type as string // dim User1 as string // dim User2 as string // dim User3 as string // dim User4 as string //end class //=============================================================================== // Subs and Functions //=============================================================================== //------------------------------------------------------------------------------- // Name: GetPlanIDbyName // Purpose: Return a PlanID associated with the submitted Plan name // Returns: PlanID or 0 if no matching name is found // Notes : PlanName should include the '.apd' suffix //------------------------------------------------------------------------------- function GetPlanIDbyName (PlanName as string, byref PlanID as integer) as boolean dim PlanIndex as integer PlanID = cNoPlan for PlanIndex = cMinPlan to nPlans if GetPlanName(PlanIndex) = PlanName then PlanID = PlanIndex exit end if next return PlanID > cNoPlan end function //------------------------------------------------------------------ // Name: ChoosePlan // Purpose: Return a selected plan name, or an error condition // Detail: If more than one plan is loaded, allow the user to // select which plan to use. // If one plan is available, select that plan without user // intervention. // If no plans are available, return an error // Returns: Name - Name of the selected plan (empty if Flag=False) // Flag - -1 = user cancel // 0 = no plans loaded // 1..nPlans = selected plan ID // Notes: Hopefully nPlans() cannot return negative values!!! //------------------------------------------------------------------ function ChoosePlan (byref Name as string) as integer const cIgnorePlanPrefix = "_RPEHLM" //All plans with this prefix will not be listed dim Flag as integer = cNoPlan //Returned status flag (-1=user cancel, 0=no plans loaded, 1..nPlans=selected plan ID) dim PlanIndex as integer //Plan list counter dim PlanNames(-1) as string //Plan list holding array select case nPlans() //Select from how many plans are available case cNoPlan //No plans available so return error condition Flag = cNoPlan Name = "" case cMinPlan //Only one plan available so return it's name if left(GetPlanName(cMinPlan),len(cIgnorePlanPrefix)) = cIgnorePlanPrefix then //...unless it's ignored Flag = cNoPlan //...in which case, set the NoPlan error conditions Name = "" else Flag = cMinPlan Name = GetPlanName(cMinPlan) end if else //Build a popup list, choose one, make it current and return the name for PlanIndex = cMinPlan to nPlans() //...build the list if left(GetPlanName(PlanIndex),len(cIgnorePlanPrefix)) <> cIgnorePlanPrefix then PlanNames.append GetPlanName(PlanIndex) end if next SetPopupParameter("Select Plan:", 0, PlanNames) if EditParameters("Plan selection") then //...choose a plan Flag = GetPlanNumber(PlanNames(GetPopupParameter("Select Plan:"))) //...get the plan ID Name = GetPlanName(Flag) //...get the plan Name SelectPlan (Flag) //...make the selected plan current else //If the user Cancels the dialogue Flag = cUserCanceled //... set up the error conditions Name = "" end if end select return Flag end function //-------------------------------------------------------------------------------- // Name : LoadScratchPlan // Purpose: Remove all objects from a Plan // Returns: The scratch plan ID number // 0 - if the scratch plan is not loaded // Notes : Nothing happens if the scratch plan is already loaded //-------------------------------------------------------------------------------- function LoadScratchPlan (Clean as boolean) as integer dim ScratchPlanID as integer dim CurrentPlanID as integer ScratchPlanID = GetPlanNumber(cScratchPlan) //See if the scratch plan is already loaded if ScratchPlanID = cNoPlan then //If the scratch plan is not loaded then CurrentPlanID = CurrentPlanNumber // stash the current plan ID ScratchPlanID = OpenPlan(cScratchPlan) // load the scratch plan if (ScratchPlanID > cNoPlan) and Clean then // If the scratch plan was loaded and Clean is set DeletePlanObjects(ScratchPlanID) // erase all objects from scratch plan end if SelectPlan(CurrentPlanID) // Restore the stashed selected plan else if Clean then DeletePlanObjects(ScratchPlanID) end if end if return ScratchPlanID //Return the scratch plan ID or error condition end function //-------------------------------------------------------------------------------- // Name : DumpScratchPlan // Purpose: Unload a scratch plan without saving it // Returns: The scratch plan ID number (no idea what I'll use this for :) // 0 - if the scratch plan is not loaded //-------------------------------------------------------------------------------- function DumpScratchPlan () as integer dim PlanID as integer PlanID=GetPlanNumber(cScratchPlan) if PlanID > cNoPlan then DeletePlanObjects(PlanID) //Scratch Plan should always be empty ClosePlan(PlanID, cSilentOff) end if return PlanID end function //-------------------------------------------------------------------------------- // Name : DeletePlanObjects // Purpose: Remove all objects from a Plan //-------------------------------------------------------------------------------- sub DeletePlanObjects (PlanID as integer) dim ObjIndex as double dim CurrentPlan as integer CurrentPlan=CurrentPlanNumber SelectPlan(PlanID) //Need sanity check? if nObjects > cNoObject then StartProgress("Emptying "+GetPlanName(PlanID), false, nObjects) for ObjIndex = nObjects downto cMinObject Obj(ObjIndex).Delete if UpdateProgress(ObjIndex) then end if next StopProgress() end if SelectPlan(CurrentPlan) end sub //-------------------------------------------------------------------------------- // Name : StashObjectData // Purpose: Make a copy of the indexed object data //-------------------------------------------------------------------------------- //function StashObjectData (PlanID as integer, ObjectID as double) as ObjectFields // dim PObj as APPlanObject // dim ObjStash as ObjectFields // ObjStash = New ObjectFields // SelectPlan(PlanID) // if (ObjectID > 0) and (ObjectID <= nObjects) then // PObj=Obj(ObjectID) // ObjStash.Catalog = PObj.Catalog // ObjStash.Dec = PObj.Dec // ObjStash.ForceHighlight = PObj.ForceHighlight // ObjStash.ID = PObj.ID // ObjStash.Magnitude = PObj.Magnitude // ObjStash.Magnitude2 = PObj.Magnitude2 // ObjStash.Name = PObj.Name // ObjStash.Notes = PObj.Notes // ObjStash.Period = PObj.Period // ObjStash.PosAngle = PObj.PosAngle // ObjStash.RA = PObj.RA // ObjStash.Selected = PObj.Selected // ObjStash.Separation = PObj.Separation // ObjStash.Size = PObj.Size // ObjStash.Spectral = PObj.Spectral // ObjStash.Type = PObj.Type // ObjStash.User1 = PObj.User1 // ObjStash.User2 = PObj.User2 // ObjStash.User3 = PObj.User3 // ObjStash.User4 = PObj.User4 // else // print "ERROR: ObjectID out of range [" + str(ObjectID) + "]" // exit // end if // return ObjStash //end function //-------------------------------------------------------------------------------- // Name : CreateNewObject // Purpose: Create a new object in the required plan //-------------------------------------------------------------------------------- //function CreateNewObject(PlanID as integer, ObjStash as ObjectFields) as APPlanObject // dim PObj as APPlanObject // //Should check to see if PlanID is valid // SelectPlan(PlanID) // PObj = NewObject() // //Should have some error handling code here! (in case Object creation fails) // PObj.Catalog = ObjStash.Catalog // PObj.Dec = ObjStash.Dec // PObj.ForceHighlight = ObjStash.ForceHighlight // PObj.ID = ObjStash.ID // PObj.Magnitude = ObjStash.Magnitude // PObj.Magnitude2 = ObjStash.Magnitude2 // PObj.Name = ObjStash.Name // PObj.Notes = ObjStash.Notes // PObj.Period = ObjStash.Period // PObj.PosAngle = ObjStash.PosAngle // PObj.RA = ObjStash.RA // PObj.Selected = ObjStash.Selected // PObj.Separation = ObjStash.Separation // PObj.Size = ObjStash.Size // PObj.Spectral = ObjStash.Spectral // PObj.Type = ObjStash.Type // PObj.User1 = ObjStash.User1 // PObj.User2 = ObjStash.User2 // PObj.User3 = ObjStash.User3 // PObj.User4 = ObjStash.User4 // return PObj //end function //-------------------------------------------------------------------------------- // Name : CopyPlanToPlan // Purpose: Copy the contents of one plan to another //-------------------------------------------------------------------------------- sub CopyPlanToPlan (SourcePlanID as integer, DestinationPlanID as integer, CopyObjectFlag as integer) const cNoCopy = false const cYesCopy = true dim ObjectIndex as double dim CopyFlag as boolean = cNoCopy dim CurrentPlanID as integer dim ObjectData as APPlanObjectData dim i as integer CurrentPlanID = CurrentPlanNumber SelectPlan(SourcePlanID) //Debug(" CurrentPlanID: "+str(CurrentPlanID)) //Debug(" CopyObjectFlag: "+str(CopyObjectFlag)) //Debug(" nObjects: "+str(nObjects)) StartProgress ("Copying from "+GetPlanName(SourcePlanID)+" to "+GetPlanName(DestinationPlanID), true, nObjects) for ObjectIndex = cMinObject to nObjects //Debug(" ObjectIndex: "+str(ObjectIndex)) select case CopyObjectFlag case cObjCopyAll //All CopyFlag = cYesCopy case cObjCopyHighlighted //Highlighted CopyFlag = Obj(ObjectIndex).IsHighlighted case cObjCopySelected //Selected CopyFlag = Obj(ObjectIndex).Selected else CopyFlag = cNoCopy end select if CopyFlag then //PlanObject = CreateNewObject(DestinationPlanID, StashObjectData(SourcePlanID, ObjectIndex)) SelectPlan(SourcePlanID) ObjectData=Obj(ObjectIndex).Contents SelectPlan(DestinationPlanID) NewObject.Contents=ObjectData SelectPlan(SourcePlanID) end if if UpdateProgress(ObjectIndex) then exit end if next StopProgress() end sub