-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added state-transition table representation and support for CFG (#13)
* Added prototype * Temp UI fix and now tests should be fine * Added unit tests and made examples' description better * Trying to fix tests * Just testing * Just checking out * Added state-transition table representation and support for CFG * Added adjacency matrix view * Added base class for table views * Trying to get renaming states handled properly * Now renaming states should be handled properly * Hellings algo, part 1 * Fixed bug with changing transitions filters * Added prototype of Hellings algo implementation * Improved overall appearance * Fixed bug with opening an example * Trying to pass tests * Resolved almost all issues * Resolved issues * Small fixes * Layout fix, part 1 * Trying to improve appearance * Resolved all issues * Tables are now bigger * Fixed a bug with showing empty grammars * Added input of CFG * Improved appearance and updated localisation * Small fixes * Small fix of table layout and deleted unused imports * Fixed tables resizing * Small fixes * Now Hellings is done for finite automatons * Settings editor is now hideable from table views * Resolved small issues with CFG * Fixed bug with displaying a vertex multiple times and other small things * Test panel UI issue + bug with opening empty tests * Small fixes + added test for Hellings algo * Fixed bugs with Hellings algo * Fixed notifying when Hellings algo grammar window has at least 1 blank field * Fixed some bugs in conversion to CFG and added more tests * Fixed some UI issues and now conversion to CFG is affected by automaton changes * Fixed bug with conversion to CFG + removed scrolling for table representations * Revert "Fixed bug with conversion to CFG + removed scrolling for table representations" This reverts commit 1056d05. * Fixed all known issues * Fixed bug with displaying initial and final vertices in tables + now its possible to delete productions from Hellings grammar * Definitive tests fix * Removed 2 abundant files * Made tables resizing better * Small fix * Added files for the new wiki * Deleted useless file * Added AutomatonTableVertexView
- Loading branch information
1 parent
14f51db
commit 059f742
Showing
48 changed files
with
3,207 additions
and
143 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/automaton/constructor/controller/AlgorithmsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package automaton.constructor.controller | ||
|
||
import automaton.constructor.controller.algorithms.ConversionToCFGController | ||
import automaton.constructor.controller.algorithms.HellingsAlgoController | ||
import automaton.constructor.model.automaton.Automaton | ||
import automaton.constructor.model.automaton.FiniteAutomaton | ||
import automaton.constructor.model.automaton.PushdownAutomaton | ||
import automaton.constructor.utils.I18N | ||
import tornadofx.Controller | ||
|
||
class AlgorithmsController( | ||
private val openedAutomaton: Automaton | ||
): Controller() { | ||
fun convertToCFG() { | ||
if (openedAutomaton !is PushdownAutomaton || openedAutomaton.stacks.size > 1) { | ||
tornadofx.error(I18N.messages.getString("CFGView.Error")) | ||
return | ||
} | ||
ConversionToCFGController(openedAutomaton).convertToCFG() | ||
} | ||
|
||
fun executeHellingsAlgo() { | ||
if (openedAutomaton !is FiniteAutomaton) { | ||
tornadofx.error(I18N.messages.getString("HellingsAlgorithm.Error")) | ||
return | ||
} | ||
HellingsAlgoController(openedAutomaton).getGrammar() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/kotlin/automaton/constructor/controller/AutomatonRepresentationController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package automaton.constructor.controller | ||
|
||
import automaton.constructor.model.action.Action | ||
import automaton.constructor.model.action.ActionAvailability | ||
import automaton.constructor.model.action.ActionFailedException | ||
import automaton.constructor.model.automaton.Automaton | ||
import automaton.constructor.model.element.AutomatonElement | ||
import automaton.constructor.model.element.BuildingBlock | ||
import automaton.constructor.model.element.State | ||
import automaton.constructor.model.element.Transition | ||
import automaton.constructor.utils.I18N | ||
import automaton.constructor.view.AutomatonElementView | ||
import automaton.constructor.view.AutomatonViewContext | ||
import javafx.scene.control.ContextMenu | ||
import javafx.scene.input.MouseButton | ||
import tornadofx.* | ||
|
||
open class AutomatonRepresentationController( | ||
val automaton: Automaton, | ||
val automatonViewContext: AutomatonViewContext | ||
): Controller() { | ||
val lastSelectedElementProperty = objectProperty<AutomatonElementView?>(null).also { | ||
it.addListener { _, _, newValue -> | ||
if (newValue == null) { | ||
clearSelection() | ||
} | ||
} | ||
} | ||
var lastSelectedElement by lastSelectedElementProperty | ||
val selectedElementsViews = mutableSetOf<AutomatonElementView>() | ||
|
||
fun registerAutomatonElementView(automatonElementView: AutomatonElementView) { | ||
automatonElementView.setOnMouseClicked { | ||
it.consume() | ||
automatonElementView.requestFocus() | ||
if (it.button == MouseButton.PRIMARY) { | ||
if (it.isStillSincePress) | ||
automaton.isOutputOfTransformation?.let { transformation -> | ||
transformation.step(automatonElementView.automatonElement) | ||
return@setOnMouseClicked | ||
} | ||
lastSelectedElement = when { | ||
!it.isControlDown -> { | ||
clearSelection() | ||
selectedElementsViews.add(automatonElementView) | ||
automatonElementView.selected = true | ||
automatonElementView | ||
} | ||
automatonElementView.selected -> { | ||
selectedElementsViews.remove(automatonElementView) | ||
automatonElementView.selected = false | ||
null | ||
} | ||
else -> { | ||
selectedElementsViews.add(automatonElementView) | ||
automatonElementView.selected = true | ||
automatonElementView | ||
} | ||
} | ||
} else if (it.button == MouseButton.SECONDARY && it.isStillSincePress && automaton.allowsModificationsByUser) { | ||
fun <T : AutomatonElement> showActionsMenu(element: T, actions: List<Action<T>>) { | ||
val actionsWithAvailability = actions.map { action -> | ||
action to action.getAvailabilityFor(element) | ||
} | ||
|
||
if (actionsWithAvailability.any { (_, availability) -> availability != ActionAvailability.HIDDEN }) { | ||
ContextMenu().apply { | ||
for ((action, availability) in actionsWithAvailability) { | ||
item(action.displayName, action.keyCombination) { | ||
action { | ||
try { | ||
if (automaton.allowsModificationsByUser) | ||
action.performOn(element) | ||
} catch (exc: ActionFailedException) { | ||
error( | ||
exc.message, | ||
title = I18N.messages.getString("Dialog.error"), | ||
owner = automatonViewContext.uiComponent.currentWindow | ||
) | ||
} | ||
|
||
} | ||
isVisible = availability != ActionAvailability.HIDDEN | ||
isDisable = availability == ActionAvailability.DISABLED | ||
} | ||
} | ||
show(automatonElementView.scene.window, it.screenX, it.screenY) | ||
} | ||
clearSelection() | ||
selectedElementsViews.add(automatonElementView) | ||
automatonElementView.selected = true | ||
lastSelectedElement = automatonElementView | ||
} | ||
} | ||
when (automatonElementView.automatonElement) { | ||
is State -> showActionsMenu( | ||
automatonElementView.automatonElement, | ||
automaton.stateActions | ||
) | ||
is BuildingBlock -> showActionsMenu( | ||
automatonElementView.automatonElement, | ||
automaton.buildingBlockActions | ||
) | ||
is Transition -> showActionsMenu( | ||
automatonElementView.automatonElement, | ||
automaton.transitionActions | ||
) | ||
} | ||
} | ||
} | ||
clearSelection() | ||
selectedElementsViews.add(automatonElementView) | ||
automatonElementView.selected = true | ||
lastSelectedElement = automatonElementView | ||
} | ||
|
||
fun clearSelection() { | ||
selectedElementsViews.onEach { it.selected = false }.clear() | ||
lastSelectedElement = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/automaton/constructor/controller/algorithms/ConversionToCFGController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package automaton.constructor.controller.algorithms | ||
|
||
import automaton.constructor.model.automaton.PushdownAutomaton | ||
import automaton.constructor.utils.I18N | ||
import automaton.constructor.view.algorithms.CFGView | ||
import tornadofx.Controller | ||
|
||
class ConversionToCFGController(private val openedAutomaton: PushdownAutomaton): Controller() { | ||
fun convertToCFG() { | ||
val conversionToCFGWindow = find<CFGView>(mapOf( | ||
CFGView::grammar to openedAutomaton.convertToCFG() | ||
)) | ||
conversionToCFGWindow.title = I18N.messages.getString("CFGView.Title") | ||
conversionToCFGWindow.openWindow() | ||
} | ||
} |
Oops, something went wrong.