Revision 14885
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/gui/solvers/ClosestFacilityDialog.java | ||
---|---|---|
40 | 40 |
import com.iver.cit.gvsig.graph.core.GraphException; |
41 | 41 |
import com.iver.cit.gvsig.graph.core.GvFlag; |
42 | 42 |
import com.iver.cit.gvsig.graph.core.Network; |
43 |
import com.iver.cit.gvsig.graph.solvers.Route; |
|
43 | 44 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
44 | 45 |
import com.iver.utiles.GenericFileFilter; |
45 | 46 |
|
... | ... | |
308 | 309 |
} |
309 | 310 |
|
310 | 311 |
public GvFlag getSelectedEvent(){ |
311 |
if(this.tableEvents.getSelectedRowCount()>0) |
|
312 |
if(this.tableEvents.getSelectedRowCount()>0 && this.tableEvents.getRowCount()>0)
|
|
312 | 313 |
return this.cfc.getEvent(Integer.parseInt(String.valueOf(this.events.getValueAt(this.tableEvents.getSelectedRow(), 0)))); |
313 | 314 |
else |
314 | 315 |
return null; |
... | ... | |
361 | 362 |
} |
362 | 363 |
} |
363 | 364 |
else if(source==this.buttonEventsRemove){ |
364 |
if(this.tableEvents.getSelectedRowCount()>0){ |
|
365 |
if(this.tableEvents.getSelectedRowCount()>0 && this.tableEvents.getRowCount()>0){
|
|
365 | 366 |
GvFlag flag=this.getSelectedEvent(); |
366 | 367 |
if(flag!=null){ |
367 | 368 |
this.cfc.removeEvent(flag); |
... | ... | |
621 | 622 |
// TODO Auto-generated method stub |
622 | 623 |
switch(columnIndex){ |
623 | 624 |
case 0: |
624 |
GvFlag flag=this.cfc.getEvent(Integer.parseInt(String.valueOf(this.getValueAt(rowIndex, columnIndex)))); |
|
625 |
if(flag!=null){ |
|
626 |
|
|
627 |
} |
|
628 | 625 |
break; |
629 | 626 |
|
630 | 627 |
case 1: |
631 |
this.cfc.getEvent(Integer.parseInt(String.valueOf(this.getValueAt(rowIndex, columnIndex)))).setDescription(String.valueOf(aValue));
|
|
628 |
this.cfc.getEvent(Integer.parseInt(String.valueOf(this.getValueAt(rowIndex, 0)))).setDescription(String.valueOf(aValue));
|
|
632 | 629 |
break; |
633 | 630 |
} |
634 | 631 |
} |
... | ... | |
670 | 667 |
|
671 | 668 |
public Object getValueAt(int rowIndex, int columnIndex) { |
672 | 669 |
// TODO Auto-generated method stub |
673 |
try{ |
|
674 |
GvFlag flag = this.cfc.getSolvedFacility(rowIndex); |
|
675 |
|
|
670 |
try{ |
|
676 | 671 |
switch(columnIndex){ |
677 | 672 |
case 0: |
678 |
return Integer.valueOf(flag.getIdFlag()); |
|
673 |
GvFlag flag1 = this.cfc.getSolvedFacility(rowIndex); |
|
674 |
return Integer.valueOf(flag1.getIdFlag()); |
|
679 | 675 |
case 1: |
680 |
return flag.getDescription(); |
|
676 |
GvFlag flag2 = this.cfc.getSolvedFacility(rowIndex); |
|
677 |
return flag2.getDescription(); |
|
681 | 678 |
case 2: |
682 |
return Double.valueOf(flag.getCost()); |
|
679 |
Route route=this.cfc.getSolvedRoute(rowIndex); |
|
680 |
return Double.valueOf(route.getCost()); |
|
683 | 681 |
default: |
684 | 682 |
return null; |
685 | 683 |
} |
trunk/extensions/extGraph/src/com/iver/cit/gvsig/graph/ClosestFacilityController.java | ||
---|---|---|
84 | 84 |
private ArrayList closestFacilitiesListeners; |
85 | 85 |
private FLyrVect layerFacilities; |
86 | 86 |
private boolean onlySelectedFacilities; |
87 |
private GvFlag[] events; |
|
87 | 88 |
|
88 | 89 |
public ClosestFacilityController(Network network, MapControl mpCtrl){ |
89 | 90 |
this.network=network; |
... | ... | |
95 | 96 |
this.maxFacilitiesNumber=0; |
96 | 97 |
this.toolMaxFacilitiesNumber=15; |
97 | 98 |
this.toEvent=true; |
98 |
this.solvedFacilities=new ArrayList(); |
|
99 |
this.solvedFacilities=new ArrayList(this.toolMaxFacilitiesNumber);
|
|
99 | 100 |
this.solvedRoutes=new ArrayList(); |
100 | 101 |
this.closestFacilitiesListeners=new ArrayList(); |
101 | 102 |
this.layerFacilities=null; |
... | ... | |
313 | 314 |
GvFlag flag=null; |
314 | 315 |
int rejectedFacilities=0; |
315 | 316 |
int incrementIdFlag=0; |
317 |
int fieldDescriptionIndex=-1; |
|
316 | 318 |
if(this.getSourceEvent()!=null){ |
317 | 319 |
incrementIdFlag=this.getSourceEvent().getIdFlag()+1; |
318 | 320 |
} |
319 | 321 |
double realTol = this.mpCtrl.getViewPort().toMapDistance(FlagListener.pixelTolerance); |
322 |
SelectableDataSource ds=layerFacilities.getRecordset(); |
|
323 |
FieldDescription[] fieldDesc=ds.getFieldsDescription(); |
|
324 |
if(fieldDesc!=null){ |
|
325 |
for (int i = 0; i < fieldDesc.length && fieldDescriptionIndex == -1; i++) { |
|
326 |
if(fieldDesc[i].getFieldName().equalsIgnoreCase("descript") && fieldDesc[i].getFieldType()==Types.VARCHAR){ |
|
327 |
fieldDescriptionIndex=i; |
|
328 |
} |
|
329 |
} |
|
330 |
} |
|
320 | 331 |
if(onlySelectedFacilities){ |
321 | 332 |
BitSet selection=layerFacilities.getRecordset().getSelection(); |
322 | 333 |
for(int i=selection.nextSetBit(0), j=0; i>=0; i=selection.nextSetBit(i+1), j++) { |
323 | 334 |
flag=this.createFlagFromGeometry(layerFacilities.getSource().getShape(i).toJTSGeometry(), realTol); |
324 | 335 |
if(flag==null) rejectedFacilities++; |
325 | 336 |
else{ |
337 |
if(fieldDescriptionIndex>=0 && fieldDescriptionIndex<fieldDesc.length){ |
|
338 |
Value[] values=ds.getRow(i); |
|
339 |
if(values[fieldDescriptionIndex] instanceof StringValue){ |
|
340 |
flag.setDescription(((StringValue)values[fieldDescriptionIndex]).toString()); |
|
341 |
} |
|
342 |
} |
|
326 | 343 |
flag.setIdFlag(i+incrementIdFlag); |
327 | 344 |
this.addFacility(flag); |
328 | 345 |
} |
... | ... | |
334 | 351 |
flag=this.createFlagFromGeometry(layerFacilities.getSource().getShape(i).toJTSGeometry(), realTol); |
335 | 352 |
if(flag==null) rejectedFacilities++; |
336 | 353 |
else{ |
354 |
if(fieldDescriptionIndex>=0 && fieldDescriptionIndex<fieldDesc.length){ |
|
355 |
Value[] values=ds.getRow(i); |
|
356 |
if(values[fieldDescriptionIndex] instanceof StringValue){ |
|
357 |
flag.setDescription(((StringValue)values[fieldDescriptionIndex]).toString()); |
|
358 |
} |
|
359 |
} |
|
337 | 360 |
flag.setIdFlag(i+incrementIdFlag); |
338 | 361 |
this.addFacility(flag); |
339 | 362 |
} |
... | ... | |
560 | 583 |
|
561 | 584 |
if(!added){ |
562 | 585 |
this.solvedRoutes.add(this.solvedRoutes.size(), route); |
563 |
this.solvedFacilities.add(this.solvedFacilities.size(), flag);
|
|
586 |
this.addSolvedFacility(this.solvedFacilities.size(), flag);
|
|
564 | 587 |
} |
565 | 588 |
} |
566 | 589 |
|
567 | 590 |
private void addSolvedFacility(int index, GvFlag flag){ |
568 |
if(this.solvedFacilities.get(flag.getIdFlag())==null){ |
|
569 |
this.solvedFacilities.add(index, flag); |
|
570 |
this.informListeners(SOLVEDFACILITY_ADDED, flag, null); |
|
571 |
} |
|
591 |
this.solvedFacilities.add(index, flag); |
|
592 |
this.informListeners(SOLVEDFACILITY_ADDED, flag, null); |
|
572 | 593 |
} |
573 | 594 |
|
574 | 595 |
public GvFlag getSolvedFacility(int index){ |
... | ... | |
607 | 628 |
} |
608 | 629 |
} |
609 | 630 |
|
631 |
private GvFlag[] getNetworkEvents(Network network) { |
|
632 |
return network.getFlags(); |
|
633 |
} |
|
634 |
|
|
635 |
private void restoreNetworkEvents(Network network, GvFlag[] events){ |
|
636 |
for (int i = 0; i < events.length; i++) { |
|
637 |
network.addFlag(events[i]); |
|
638 |
} |
|
639 |
} |
|
640 |
|
|
610 | 641 |
public void solve() throws GraphException, ReadDriverException{ |
611 | 642 |
this.network.removeFlagListener(this); |
643 |
this.events=this.getNetworkEvents(this.network); |
|
612 | 644 |
this.network.removeFlags(); |
613 | 645 |
this.removeSolvedFacilities(); |
614 | 646 |
int rejectedFacilities=this.loadFacilitiesFromLayer(layerFacilities, this.getOnlySelectedFacilities()); |
... | ... | |
662 | 694 |
} |
663 | 695 |
} |
664 | 696 |
} |
697 |
this.network.removeFlags(); |
|
698 |
this.restoreNetworkEvents(this.network, this.events); |
|
665 | 699 |
this.network.addFlagListener(this); |
666 | 700 |
} |
667 | 701 |
} |
Also available in: Unified diff