# ToolScript looking for the street$ entered by the user # # The following symbols are predefined # class VIEW View {use to access the view the tool script is attached to} # class GROUP Group {use to access the group being viewed if the script is run from a group view} # class LAYOUT Layout {use to access the layout being viewed if the script is run from a layout view} # numeric TooIsActive Will be 0 if tool is inactive or 1 if tool is active # class XmForm dlgform; class XmList poslist; VECTOR V; VECTOR VTown; class GRE_LAYER_VECTOR layer; numeric nmax; #max lines able to find string street$; #word to look for numeric nline; #number of lines found numeric ncode; #one code at the beginning array numeric linelist[nmax]; #contains the numelement number of the lines found array numeric codelist[nmax,2]; #contains the different zip codes in odd indices and the number of a line corresponding in the even indices numeric setDefaultWhenClose = false; #Retreive the group containing the vector layer used to find the street func GetVector(namegroup$, namelayer$, VECTOR Vect){ class GRE_GROUP group; group = Layout.FirstGroup; while (group.Name != "" && group.Name != namegroup$) { group = group.NextGroup; } if (group.Name == "") { PopupMessage("Group " + namegroup$ + " not found"); return false; } # now the group is correct #retrieving the layer used to find the street layer = group.FirstLayer; while (layer.Name != "" && layer.Name != namelayer$) { layer = layer.NextLayer; } if (layer.Name == "") { PopupMessage("Layer " + namelayer$ + " not found"); return false; } # now the layer is correct DispGetVectorFromLayer(Vect, layer); return true; } # Zoom to selected position proc DoZoom () { #Finding the element numbers of this street (not sure that they are sorted) local selpos; if (nline == 0) return; selpos = poslist.GetFirstSelectedPos(); array numeric streetline[1]; numeric nstreetline = 0; numeric i, curcode; for i=1 to nline { curcode = V.line[linelist[i]].TRONCON_ROUTE.INSEE_COMD; if (curcode == codelist[selpos,1]) { nstreetline = nstreetline+1; ResizeArrayPreserve(streetline, nstreetline); streetline[nstreetline] = linelist[i]; } } ViewSetMessage(View, NumToStr(nstreetline) + " lines found for this street"); #Zoom in to the lines class GRE_VECTOR_LINES vll; vll = layer.Line; vll.HighlightMultiple(nstreetline, streetline); View.DisableRedraw = 1; layer.ZoomToHighlighted(); if (ViewGetMapScale(View) < 30000) { ViewSetMapScale(View, 30000); } View.DisableRedraw = 0; ViewRedraw(View); }#DoZoom # New Request proc DoNew () { poslist.DeleteAllItems(); nline = 0; ncode = 0; #asking to enter the name of a street (or a word contained in it) street$ = PopupString("Enter all or part of the name of the street to search for", ""); if (street$ == "") return; street$ = toupper$(street$); #looking for a line containing street$ in its NOM_RUE_D or NOM_RUE_G attributes of the TRONCON_ROUTE table for i=1 to NumVectorLines(V) { #class DATABASE DB = V.line[i].TRONCON_ROUTE; if (V.line[i].TRONCON_ROUTE.NOM_RUE_D$ contains street$ or V.line[i].TRONCON_ROUTE.NOM_RUE_G$ contains street$) { nline = nline+1; linelist[nline] = i; }#if }#i ViewSetMessage(View, NumToStr(nline) + " lines found"); if (nline == 0) { #no element corresponding found PopupMessage("No streets found containing this word!"); return; } #Some streets are found : find the different ones (by zip code) #Assertion : not 2 streets with the same name in a town #Limits : don't take into account the streets separating 2 towns (the right zip code INSEE_COMD and the left one INSEE_COMG are different) numeric j, found; for i=1 to nline { found = false; curcode = V.line[linelist[i]].TRONCON_ROUTE.INSEE_COMD; j=1; while (!found and j<=ncode) { #looks if code already found if (codelist[j,1] == curcode) { found = true; }#if j = j+1; }#while if (!found) { #new street ncode = ncode+1; codelist[ncode,1] = curcode; codelist[ncode,2] = linelist[i]; }#if }#i #Retrieve the table containing the names of the towns array numeric townnames[ncode]; #VTown.point[townname[i]].ZONE_HABITAT.INSEE == V.line[codelist[i,2]].TRONCON_ROUTE.INSEE_COMD; numeric npts = NumVectorPoints(VTown); ResizeArrayClear(townnames, ncode); for i=1 to ncode { curcode = V.line[codelist[i,2]].TRONCON_ROUTE.INSEE_COMD; j = 1; found = false; townnames[i] = 0; #init while (!found and j<=npts) { if (VTown.point[j].ZONE_HABITAT.INSEE == curcode) { townnames[i] = j; found = true; } j = j+1; } if (townnames[i] == 0) { #error PopupMessage("Town name corresponding to " + NumToStr(curcode) + " not found"); } }#i string name$, zip$, town$; for i = 1 to ncode { name$ = V.line[codelist[i,2]].TRONCON_ROUTE.NOM_RUE_D$; zip$ = " (" + NumToStr(codelist[i,1]) + ")"; town$ = ", " + street$ = toupper$(VTown.point[townnames[i]].ZONE_HABITAT.TOPONYME$); poslist.AddItem(name$ + town$ + zip$); } poslist.SelectPos(1); }#DoNew # Close the window, switching to default tool proc DoClose () { if (setDefaultWhenClose) { setDefaultWhenClose = false; View.SetDefaultTool(); } } # Called the first time the tool is activated. func OnInitialize () { dlgform = CreateFormDialog("Search for a street",View.Form); WidgetAddCallback(dlgform.Shell.PopdownCallback,DoClose); dlgform.Width = 200; class PushButtonItem btnItemNew; class PushButtonItem btnItemZoom; class PushButtonItem btnItemClose; btnItemNew = CreatePushButtonItem("New search",DoNew); btnItemNew.IconName = "new"; btnItemZoom = CreatePushButtonItem("Highlight the street",DoZoom); btnItemZoom.IconName = "apply_query"; btnItemClose = CreatePushButtonItem("Close",DoClose); btnItemClose.IconName = "delete"; # Icon button rows are automatically attached to their parent form on the left # and right. The "right" widget is unattached by setting the attachment to itself. class XmRowColumn btnrowaction; btnrowaction = CreateIconButtonRow(dlgform,btnItemNew,btnItemZoom); btnrowaction.TopWidget = dlgform; btnrowaction.TopOffset = 4; # btnrowaction.LeftWidget = btnrowaction; btnrowaction.LeftOffset = 8; btnrowaction.RightOffset = 4; class XmSeparator btnsep; btnsep = CreateHorizontalSeparator(dlgform); btnsep.TopWidget = btnrowaction; btnsep.TopOffset = 4; btnsep.LeftWidget = dlgform; btnsep.RightWidget = dlgform; poslist = CreateScrolledList(dlgform); poslist.TopOffset = 4; poslist.SelectionPolicy = "BROWSE_SELECT"; poslist.VisibleItemCount = 5; WidgetAddCallback(poslist.DefaultActionCallback,DoZoom); class XmScrolledWindow sw; sw = poslist.parent; sw.TopWidget = btnsep; sw.LeftWidget = dlgform; sw.RightWidget = dlgform; sw.BottomWidget = dlgform; } # OnInitialize # Called when tool is to be destroyed, will not be called if tool was never activated. func OnDestroy () { DestroyWidget(dlgform); } # end of OnDestroy # Called when tool is deactivated (usually when switching to another tool). proc OnDeactivate () { setDefaultWhenClose = false; # SetPopupDialogParent(0); dlgform.managed = 0; } # end of OnDeactivate # Called when tool is activated. func OnActivate () { #Check the layout if (Layout.Name != "Level22") { PopupMessage("Fonction uniquement disponible dans le Mini SIG!"); return (-1); } dlgform.managed = 1; #retreiving the vector object containning the name of the towns #have to do it before retrieving the streets because of the global variable "layer" if ( !GetVector("Administratif", "Towns", VTown) ) { return (-1); } if ( !GetVector("Communications", "Minor Roads", V) ) { return (-1); } nmax = 1000; ResizeArrayClear(linelist, nmax); ResizeArrayClear(codelist, nmax, 2); SetPopupDialogParent(dlgform); setDefaultWhenClose = true; } # end of OnActivate