diff --git a/src/classy_blocks/modify/junction.py b/src/classy_blocks/modify/junction.py index 6417487..8660f61 100644 --- a/src/classy_blocks/modify/junction.py +++ b/src/classy_blocks/modify/junction.py @@ -5,6 +5,10 @@ from classy_blocks.modify.clamps.clamp import ClampBase +class ClampExistsError(Exception): + """Raised when adding a clamp to a junction that already has one defined""" + + class Junction: """A class that collects Cells/Blocks that share the same Vertex""" @@ -24,6 +28,9 @@ def add_cell(self, cell: Cell) -> None: return def add_clamp(self, clamp: ClampBase) -> None: + if self.clamp is not None: + raise ClampExistsError(f"Clamp already defined for junctoin {self.vertex.index}") + self.clamp = clamp @property diff --git a/tests/test_optimize/test_optimizer.py b/tests/test_optimize/test_optimizer.py index c016c90..fd6c21c 100644 --- a/tests/test_optimize/test_optimizer.py +++ b/tests/test_optimize/test_optimizer.py @@ -8,6 +8,7 @@ from classy_blocks.modify.clamps.links import TranslationLink from classy_blocks.modify.find.geometric import GeometricFinder from classy_blocks.modify.iteration import IterationDriver +from classy_blocks.modify.junction import ClampExistsError from classy_blocks.modify.optimizer import Optimizer from classy_blocks.util import functions as f from classy_blocks.util.constants import VBIG @@ -132,6 +133,12 @@ def setUp(self): self.vertex = next(iter(self.finder.find_in_sphere([0, 0, 0]))) + def test_add_junction_existing(self): + self.optimizer.release_vertex(FreeClamp(self.mesh.vertices[0])) + + with self.assertRaises(ClampExistsError): + self.optimizer.release_vertex(FreeClamp(self.mesh.vertices[0])) + def test_optimize(self): # move a point, then optimize it back to # its initial-ish position