'aaaPoint2Poly.ave
'Modified from PolyfromPt.avx (Matthew Francis).
'jschmidt 5/14/01
'Modified to allow user to input size
'And to allow un-projected themes to be used
'And to load the new theme into a chosen View

viewActive = av.GetActiveDoc
thmPt = MsgBox.ListAsString (viewActive.GetThemes, "Select the Point Theme To Convert to a Polygon Theme ", "Select a Point Theme")
if (thmPt = nil) then
exit
end
if (thmPt.GetSrcName.GetSubName <> "point") then
msgbox.Error("Source Theme Must be A Point Theme","Not Point Theme")
exit
end


ftbPt = thmPt.GetFTab
t = "Polygon generation from a point theme"

if (thmPt.GetFTab.GetShapeClass.GetClassName <> "Point") then
MsgBox.Error("Please select a POINT theme and try again",t)
exit
end

thePrj = viewActive.GetProjection

labels = {"Width in Projected Units", "Height in Projected Units"}
defaults = {"500", "500"}
dim = MsgBox.MultiInput("Select the Dimensions of the Rectangles to Create","Dimensions",labels,defaults)
'MsgBox.ListAsString(dim, "Here are the Dimensions Selected:","Rectangle Dimensions")
'length = Msgbox.List(ftbPt.GetFields, "Please select length field",t)
'width = Msgbox.List(ftbPt.GetFields, "Please select width field",t)
fieldPtList = List.Make
fieldPtList = MsgBox.MultiListAsString(ftbPt.GetFields, "Please select all fields (except Shape) to be exported into the polygon theme",t)
fldPtListCount = (fieldPtList.Count - 1)
fieldPtName = List.Make
fieldPtType = List.Make
fieldPtWidth = List.Make
fieldPtPrecis = List.Make

for each i in 0 .. fldPtListCount
fieldPtN = ftbPt.FindField(fieldPtList.Get(i).asString).GetName.Clone
fieldPtT = ftbPt.FindField(fieldPtList.Get(i).asString).GetType.Clone
fieldPtW = ftbPt.FindField(fieldPtList.Get(i).asString).GetPixelWidth.Clone
fieldPtP = ftbPt.FindField(fieldPtList.Get(i).asString).GetPrecision.Clone
fieldPtName.Add(fieldPtN)
fieldPtT = ("#"+fieldPtT.AsString)
fieldPtType.Add(fieldPtT)
fieldPtWidth.Add(fieldPtW)
fieldPtPrecis.Add(fieldPtP)
end

thmPol = FileDialog.Put ("Poinarea.shp".AsFileName,"*.shp",t)
ftbPol = FTab.MakeNew(thmPol,Polygon)
mytheme = FTheme.Make(ftbPol)
ftbPol.SetEditable(TRUE)

for each i in 0 .. fldPtListCount
newPolField = Field.Make(fieldPtName.Get(i).asString,
fieldPtType.Get(i).asString.asEnum,
fieldPtWidth.Get(i),
fieldPtPrecis.Get(i))
ftbPol.AddFields({newPolField})
end
ALTfield=Field.Make("ALT_DESC",#FIELD_CHAR,50,0)
ftbPol.AddFields({ALTfield})
fieldPolList = ftbPol.GetFields
bmpPt = ftbPt.GetSelection
bmpPt.SetAll
av.ClearStatus
currentElt = 0
excludeCount = 0
for each rec in bmpPt
ptBaseu = ftbPt.ReturnValue(ftbPol.GetFields.Get(0),rec)
ptBase = ptBaseu.Returnprojected(thePrj)

numXBase = ptBase.GetX
numYBase = ptBase.GetY
' numLength = ftbPt.ReturnValue(length,rec)
' numWidth = ftbPt.ReturnValue(width,rec)
numWidth = dim.get(0).AsNumber
numLength = dim.get(1).AsNumber
newRec = ftbPol.AddRecord
shpPol = Polygon.Make({{(numXBase-(numWidth/2))@(numYBase-(numLength/2)),
(numXBase-(numWidth/2))@(numYBase+(numLength/2)),
(numXBase+(numWidth/2))@(numYBase+(numLength/2)),
(numXBase+(numWidth/2))@(numYBase-(numLength/2))}})
ftbPol.SetValue((ftbPol.GetFields.Get(0)),newRec,shpPol)

for each i in 0 .. fldPtListCount
x = i+1 'Because we are not including field(0), the polygon's "Shape" field
ftbPtFldValue = ftbPt.ReturnValue(fieldPtList.Get(i),rec)
ftbPolField = fieldPolList.Get(x).Clone
ftbPol.SetValue(ftbPolField,newRec,ftbPtFldValue)
end

eltCount = ftbPt.GetNumRecords
currentElt = currentElt + 1
av.SetStatus(currentElt / eltCount * 100)
end

ftbPol.Flush
ftbPol.SetEditable(false)
bmpPt.ClearAll

'************************************************
if (MsgBox.YesNo("Add shapefile(s) as theme(s) to a view?",
"Point to Poly",true)) then
'make a list of views
viewlist = List.Make
for each d in av.GetProject.GetDocs
if (d.Is(View)) then
viewlist.Add(d)
end
end 'for each d

'provide a choice for a new view
viewlist.Add("<New View>")

AddToView = MsgBox.ListAsString(viewlist,"Add Theme to:",
"Point to Poly")

if (AddToView <> nil) then
if (AddToView = "<New View>") then
AddToView = View.Make
AddToView.GetWin.Open
AddToView.AddTheme(mytheme)
else
AddToView.AddTheme(mytheme)
end
end
else 'don't add to view
AddtoView = nil
end


'viewactive.Addtheme(mytheme)


"il boom dei dati geografici è in corso, aspettiamoci quello delle informazioni spaziali"
#Local Intelligent Marketing#