Skip to content

Commit 7739224

Browse files
committed
ensure that the bounds for a given object is only recalculated when the
conditions of the bounds change, namely when the objects change places,a nd when the workplane changes.
1 parent d52153d commit 7739224

File tree

1 file changed

+60
-53
lines changed

1 file changed

+60
-53
lines changed

src/main/java/com/commonwealthrobotics/controls/SelectionSession.java

Lines changed: 60 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public PerspectiveCamera getCamera() {
219219

220220
public boolean moveLock() {
221221
boolean moveLock = false;
222-
for (CSG sel : selected) {
222+
for (CSG sel : getSelected()) {
223223
if (sel.isMotionLock() || sel.isInGroup())
224224
moveLock = true;
225225
}
@@ -228,7 +228,7 @@ public boolean moveLock() {
228228

229229
public List<String> selectedSnapshot() {
230230
ArrayList<String> s = new ArrayList<String>();
231-
for (CSG c : selected)
231+
for (CSG c : getSelected())
232232
s.add(c.getName());
233233
return s;
234234
}
@@ -250,9 +250,10 @@ else if (isMirrorActive() && Mirror.class.isInstance(source)) {
250250
intitialization = false;
251251
setUpParametrics(currentState, source);
252252
displayCurrent();
253-
TickToc.tic("Finish On Update In Selected Session");
253+
TickToc.tic("Update memory display");
254254
updateMemoryDisplay();
255-
255+
TickToc.tic("Finish On Update In Selected Session");
256+
TickToc.toc();
256257
}
257258

258259
public void updateMemoryDisplay() {
@@ -522,7 +523,7 @@ private void displayCurrent() {
522523
displayCSG(c);
523524
}
524525
ArrayList<CSG> toRemove = new ArrayList<>();
525-
for (CSG s : selected) {
526+
for (CSG s : getSelected()) {
526527
boolean exists = false;
527528
for (CSG c : currentState) {
528529
if (c.getName().contentEquals(s.getName()) && !c.isInGroup())
@@ -532,7 +533,7 @@ private void displayCurrent() {
532533
toRemove.add(s);
533534
}
534535
}
535-
selected.removeAll(toRemove);
536+
getSelected().removeAll(toRemove);
536537
if (workplane != null)
537538
workplane.updateMeshes(getMeshes());
538539
updateControlsDisplayOfSelected();
@@ -590,15 +591,17 @@ private void setUpControls(MeshView meshView, CSG name) {
590591
throw new RuntimeException("Name can not be null");
591592
meshView.setOnMousePressed(event -> {
592593
if (event.getButton() == MouseButton.PRIMARY) {
594+
//TickToc.setEnabled(true);
595+
TickToc.tic("Start Click");
593596
if (event.isShiftDown()) {
594-
if (selected.contains(name)) {
595-
selected.remove(name);
597+
if (getSelected().contains(name)) {
598+
getSelected().remove(name);
596599
} else
597-
selected.add(name);
600+
getSelected().add(name);
598601
} else {
599-
if (!selected.contains(name)) {
600-
selected.clear();
601-
selected.add(name);
602+
if (!getSelected().contains(name)) {
603+
getSelected().clear();
604+
getSelected().add(name);
602605
}
603606
}
604607
if (getMode() != SpriteDisplayMode.Align)
@@ -607,14 +610,14 @@ private void setUpControls(MeshView meshView, CSG name) {
607610
updateControlsDisplayOfSelected();
608611
event.consume();
609612
}
613+
610614
});
611615

612616
}
613617

614618
public void updateControlsDisplayOfSelected() {
615619
parametrics.getChildren().clear();
616-
clearBoundsCache();
617-
timeline.updateSelected(selected);
620+
timeline.updateSelected(getSelected());
618621

619622
getExecutor().submit(() -> {
620623
List<CSG> cs = getCurrentState();
@@ -623,13 +626,14 @@ public void updateControlsDisplayOfSelected() {
623626
}
624627

625628
private void UpdateUIControls(List<CSG> cs) {
626-
if (selected.size() > 0) {
629+
TickToc.tic("Start UpdateUIControls");
630+
if (getSelected().size() > 0) {
627631
dropToWorkplane.setDisable(false);
628-
objectWorkplane.setDisable(selected.size() != 1);
632+
objectWorkplane.setDisable(getSelected().size() != 1);
629633

630634
shapeConfigurationHolder.getChildren().clear();
631635
shapeConfigurationHolder.getChildren().add(shapeConfigurationBox);
632-
CSG set = ((CSG) selected.toArray()[0]);
636+
CSG set = ((CSG) getSelected().toArray()[0]);
633637
if (set == null)
634638
return;
635639
Color value = set.getColor();
@@ -664,7 +668,7 @@ private void UpdateUIControls(List<CSG> cs) {
664668
}
665669
}
666670
manipulation.setUnlocked(!lockMove);
667-
shapeConfiguration.setText("Shape (" + selected.size() + ")");
671+
shapeConfiguration.setText("Shape (" + getSelected().size() + ")");
668672
List<CSG> csgs = getSelectedCSG(selectedSnapshot);
669673
if (selectedSnapshot.size() == 1 && csgs.size() > 0) {
670674
CSG sel = csgs.get(0);
@@ -740,6 +744,8 @@ private void UpdateUIControls(List<CSG> cs) {
740744
}
741745

742746
public void clearBoundsCache() {
747+
Log.debug("Clearing bounds cache ");
748+
Log.error(new Exception());
743749
inWorkplaneBounds.clear();
744750
}
745751

@@ -957,23 +963,23 @@ private void setupSnapGrid() {
957963

958964
public void clearSelection() {
959965
cancelOperationModes();
960-
selected.clear();
966+
getSelected().clear();
961967
updateControlsDisplayOfSelected();
962968
updateRobotLab.run();
963969
setKeyBindingFocus();
964970
}
965971

966972
public void selectAll(Iterable<String> names) {
967973
getExecutor().submit(() -> {
968-
selected.clear();
974+
getSelected().clear();
969975
for (CSG c : getCurrentState()) {
970976
if ((c.isInGroup() && !c.isAlwaysShow()))
971977
continue;
972978
if (c.isHide())
973979
continue;
974980
for (String s : names)
975981
if (s.contentEquals(c.getName())) {
976-
selected.add(c);
982+
getSelected().add(c);
977983
break;
978984
}
979985
}
@@ -987,13 +993,13 @@ public void selectAll(Iterable<String> names) {
987993

988994
public void selectAll() {
989995
getExecutor().submit(() -> {
990-
selected.clear();
996+
getSelected().clear();
991997
for (CSG c : getCurrentState()) {
992998
if ((c.isInGroup() && !c.isAlwaysShow()))
993999
continue;
9941000
if (c.isHide())
9951001
continue;
996-
selected.add(c);
1002+
getSelected().add(c);
9971003
}
9981004
BowlerStudio.runLater(() -> updateControlsDisplayOfSelected());
9991005
updateRobotLab.run();
@@ -1011,10 +1017,10 @@ public void setKeyBindingFocus() {
10111017

10121018
public void setToSolid() {
10131019
getExecutor().submit(() -> {
1014-
if (selected.size() == 0)
1020+
if (getSelected().size() == 0)
10151021
return;
10161022
boolean isSilid = true;
1017-
for (CSG s : selected) {
1023+
for (CSG s : getSelected()) {
10181024
CSG selectedCSG = s;
10191025
if (selectedCSG != null)
10201026
if (selectedCSG.isHole()) {
@@ -1033,7 +1039,7 @@ public void toggleTransparent() {
10331039
getExecutor().submit(() -> {
10341040
com.neuronrobotics.sdk.common.Log.debug("Toggel transparent");
10351041
ArrayList<ToSolid> toChange = new ArrayList<>();
1036-
for (Iterator<CSG> iterator = selected.iterator(); iterator.hasNext();) {
1042+
for (Iterator<CSG> iterator = getSelected().iterator(); iterator.hasNext();) {
10371043
CSG s = iterator.next();
10381044
CSG c = s;
10391045
if (!c.isHole()) {
@@ -1069,11 +1075,11 @@ public void toggleTransparent() {
10691075

10701076
public boolean isSelectedTransparent() {
10711077
double opacity = 0;
1072-
for (CSG c : selected) {
1078+
for (CSG c : getSelected()) {
10731079
if (!c.isHole())
10741080
opacity += ((PhongMaterial) c.getMesh().getMaterial()).getDiffuseColor().getOpacity();
10751081
}
1076-
return (opacity / (double) selected.size()) < 0.999;
1082+
return (opacity / (double) getSelected().size()) < 0.999;
10771083
}
10781084

10791085
public void setColor(Color value) {
@@ -1083,10 +1089,10 @@ public void setColor(Color value) {
10831089
}
10841090

10851091
public void setToHole() {
1086-
if (selected.size() == 0)
1092+
if (getSelected().size() == 0)
10871093
return;
10881094
boolean isSilid = false;
1089-
for (CSG s : selected) {
1095+
for (CSG s : getSelected()) {
10901096
if (!s.isHole()) {
10911097
isSilid = true;
10921098
}
@@ -1098,7 +1104,7 @@ public void setToHole() {
10981104
}
10991105

11001106
public TransformNR getFocusCenter() {
1101-
if (selected.size() == 0)
1107+
if (getSelected().size() == 0)
11021108
return new TransformNR();
11031109
Bounds b = getSellectedBounds();
11041110

@@ -1155,15 +1161,15 @@ private void showButtons() {
11551161
b.setDisable(false);
11561162
}
11571163
int unlockedSelected = 0;
1158-
for (CSG c : selected) {
1164+
for (CSG c : getSelected()) {
11591165
if (!c.isLock())
11601166
unlockedSelected++;
11611167
}
11621168
if (unlockedSelected > 1) {
11631169
groupButton.setDisable(false);
11641170
alignButton.setDisable(false);
11651171
}
1166-
if (selected.size() > 0 && advanced) {
1172+
if (getSelected().size() > 0 && advanced) {
11671173
advancedGroupMenu.setDisable(false);
11681174
robotLabDrawer.setDisable(false);
11691175
}
@@ -1174,7 +1180,7 @@ private void showButtons() {
11741180
}
11751181

11761182
private boolean isAGroupSelected() {
1177-
for (CSG c : selected) {
1183+
for (CSG c : getSelected()) {
11781184
if (c != null) {
11791185
if (c.isGroupResult()) {
11801186
return true;
@@ -1364,7 +1370,7 @@ public void onXor() {
13641370
com.neuronrobotics.sdk.common.Log.error("Ignoring operation because previous had not finished!");
13651371
return;
13661372
}
1367-
if (selected.size() > 1) {
1373+
if (getSelected().size() > 1) {
13681374
getExecutor().submit(() -> {
13691375
try {
13701376
List<String> selectedSnapshot = selectedSnapshot();
@@ -1403,8 +1409,8 @@ public void onXor() {
14031409

14041410
}
14051411

1406-
selected.clear();
1407-
selected.addAll(results);
1412+
getSelected().clear();
1413+
getSelected().addAll(results);
14081414
BowlerStudio.runLater(() -> updateControlsDisplayOfSelected());
14091415
updateRobotLab.run();
14101416
} catch (CadoodleConcurrencyException e) {
@@ -1427,16 +1433,16 @@ public void onGroup(boolean hull, boolean intersect) {
14271433
com.neuronrobotics.sdk.common.Log.error("Ignoring operation because previous had not finished!");
14281434
return;
14291435
}
1430-
if (selected.size() > 1 || hull) {
1436+
if (getSelected().size() > 1 || hull) {
14311437
getExecutor().submit(() -> {
14321438
Group groups = new Group().setNames(selectedSnapshot());
14331439
groups.setHull(hull);
14341440
groups.setIntersect(intersect);
14351441
try {
14361442
ap.addOp(groups).join();
14371443
List<CSG> got = ap.get().getCurrentState();
1438-
selected.clear();
1439-
selected.addAll(got);
1444+
getSelected().clear();
1445+
getSelected().addAll(got);
14401446
BowlerStudio.runLater(() -> updateControlsDisplayOfSelected());
14411447
updateRobotLab.run();
14421448
} catch (CadoodleConcurrencyException e) {
@@ -1475,8 +1481,8 @@ public void onUngroup() {
14751481
List<String> selectedSnapshot = selectedSnapshot();
14761482

14771483
if (isAGroupSelected()) {
1478-
selected.clear();
1479-
selected.addAll(toSelect);
1484+
getSelected().clear();
1485+
getSelected().addAll(toSelect);
14801486
ap.addOp(new UnGroup().setNames(selectedSnapshot));
14811487
}
14821488
updateControlsDisplayOfSelected();
@@ -1607,7 +1613,7 @@ public List<CSG> getCurrentState() {
16071613
public List<CSG> getCurrentStateSelected() {
16081614
ArrayList<CSG> back = new ArrayList<CSG>();
16091615
for (CSG c : getCurrentState()) {
1610-
for (CSG s : selected) {
1616+
for (CSG s : getSelected()) {
16111617
if (c.getName().contentEquals(s.getName()))
16121618
back.add(c);
16131619
}
@@ -1623,13 +1629,6 @@ public Bounds getSellectedBounds(List<CSG> incoming) {
16231629
return Align.getBounds(incoming, ap.get().getWorkplane(), inWorkplaneBounds);
16241630
}
16251631

1626-
public Bounds getBounds(CSG incoming, TransformNR frame) {
1627-
return Align.getBounds(Arrays.asList(incoming), frame, null);
1628-
}
1629-
1630-
public Bounds getBounds(CSG incoming, TransformNR frame, HashMap<CSG, Bounds> cache) {
1631-
return Align.getBounds(Arrays.asList(incoming), frame, cache);
1632-
}
16331632

16341633
public Bounds getBounds(DHParameterKinematics limb) {
16351634
ArrayList<CSG> parts = new ArrayList<CSG>();
@@ -1644,7 +1643,7 @@ public Bounds getBounds(DHParameterKinematics limb) {
16441643
}
16451644

16461645
public void objectWorkplane() {
1647-
if (selected.size() != 1 && !isObjectWorkplane)
1646+
if (getSelected().size() != 1 && !isObjectWorkplane)
16481647
return;
16491648
isObjectWorkplane = !isObjectWorkplane;
16501649
com.neuronrobotics.sdk.common.Log.debug("Setting Object Workplane " + isObjectWorkplane);
@@ -1694,7 +1693,7 @@ public void onDrop() {
16941693

16951694
public void moveInCameraFrame(TransformNR stateUnitVectorTmp) {
16961695
TickToc.tic("Start Move Request");
1697-
if (selected.size() == 0) {
1696+
if (getSelected().size() == 0) {
16981697
return;
16991698
}
17001699
getExecutor().submit(() -> {
@@ -2102,7 +2101,7 @@ public void setRobotLabButton(Button robotLabDrawer) {
21022101
}
21032102

21042103
public int numberSelected() {
2105-
return selected.size();
2104+
return getSelected().size();
21062105
}
21072106

21082107
/**
@@ -2159,4 +2158,12 @@ public void setExecutor(ExecutorService executor) {
21592158
this.executor = executor;
21602159
}
21612160

2161+
public LinkedHashSet<CSG> getSelected() {
2162+
return selected;
2163+
}
2164+
2165+
public void setSelected(LinkedHashSet<CSG> selected) {
2166+
this.selected = selected;
2167+
}
2168+
21622169
}

0 commit comments

Comments
 (0)