Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Instrument Control
Protos
Nomad 3D
nomad-3d-editor
Commits
e2623097
Commit
e2623097
authored
Jan 25, 2019
by
legoc
Browse files
Added move components operation
parent
b8b33c4b
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/fr/ill/ics/n3d/gui/EditorMenuBar.java
View file @
e2623097
...
...
@@ -21,6 +21,7 @@ import fr.ill.ics.n3d.model.Component;
import
fr.ill.ics.n3d.model.ConfigParams
;
import
fr.ill.ics.n3d.model.ReferenceAxis
;
import
fr.ill.ics.n3d.model.ReferenceAxisList
;
import
fr.ill.ics.n3d.operations.MoveComponentsOperation
;
import
fr.ill.ics.n3d.operations.NewComponentOperation
;
import
fr.ill.ics.n3d.operations.Operations
;
import
fr.ill.ics.n3d.operations.OperationsSerializer
;
...
...
@@ -1250,6 +1251,119 @@ public class EditorMenuBar extends MenuBar {
stage
.
showAndWait
();
});
///////////////////////////////////////////////////////////////////////////////////////
// Move components menu
MenuItem
moveComponentsItem
=
new
MenuItem
(
"Move Components"
);
moveComponentsItem
.
setOnAction
(
event
->
{
if
(!
modelLoaded
())
{
return
;
}
///////////////////////////////////////////////////////////////////////////////////
// Parent
Label
parentLabel
=
new
Label
(
"New Parent : "
);
ObservableList
<
String
>
assemblyComponents
=
FXCollections
.
observableArrayList
(
getAssemblyComponentNames
());
ComboBox
<
String
>
parentBox
=
new
ComboBox
<
String
>(
assemblyComponents
);
parentBox
.
getSelectionModel
().
select
(
0
);
///////////////////////////////////////////////////////////////////////////////////
// Layout
GridPane
scenePane
=
new
GridPane
();
scenePane
.
setAlignment
(
Pos
.
CENTER
);
Scene
scene
=
new
Scene
(
scenePane
);
Stage
stage
=
new
Stage
(
StageStyle
.
UTILITY
);
stage
.
setTitle
(
"Move Components"
);
stage
.
setScene
(
scene
);
stage
.
initOwner
(
Nomad3DEditor
.
getInstance
().
getStage
());
GridPane
mainPane
=
new
GridPane
();
mainPane
.
setVgap
(
5
);
mainPane
.
setHgap
(
10
);
mainPane
.
setAlignment
(
Pos
.
CENTER
);
scenePane
.
addRow
(
0
,
mainPane
);
GridPane
.
setMargin
(
mainPane
,
new
Insets
(
10
));
GridPane
movePane
=
new
GridPane
();
movePane
.
setVgap
(
5
);
movePane
.
setHgap
(
10
);
movePane
.
setAlignment
(
Pos
.
CENTER
);
scenePane
.
addRow
(
0
,
movePane
);
GridPane
.
setMargin
(
movePane
,
new
Insets
(
10
));
movePane
.
addRow
(
1
,
parentLabel
,
parentBox
);
Button
okButton
=
new
Button
(
"OK"
);
okButton
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
// Check the selection.
if
(
Nomad3DEditor
.
getInstance
().
getModel
()
==
null
||
Nomad3DEditor
.
getInstance
().
getModel
().
getRoot
()
==
null
)
{
return
;
}
HashSet
<
Component
>
selectedComponents
=
Component
.
excludeComponentsWithParentIn
(
Nomad3DEditor
.
getInstance
().
getModel
().
getSelection
());
if
(
selectedComponents
.
isEmpty
())
{
Alert
alert
=
new
Alert
(
AlertType
.
WARNING
);
alert
.
setTitle
(
editAxisItem
.
getText
());
alert
.
setContentText
(
"Empty selection."
);
alert
.
showAndWait
();
return
;
}
// Get the names.
String
newParentComponentName
=
parentBox
.
getSelectionModel
().
getSelectedItem
();
Component
newParentComponent
=
Nomad3DEditor
.
getInstance
().
getModel
().
findComponent
(
newParentComponentName
);
// Create the operation.
MoveComponentsOperation
operation
=
new
MoveComponentsOperation
(
newParentComponentName
);
// Iterate the components to move.
for
(
Component
component
:
selectedComponents
)
{
// Modify the operation by getting the name of the parent before it changes.
operation
.
addMovedComponent
(
component
.
getName
(),
component
.
getParent
().
getName
());
// Move the component.
newParentComponent
.
addChild
(
component
);
}
// Update the scene.
updateScene
();
// Save the operation.
Operations
.
getInstance
().
addOperation
(
operation
);
// Change the title.
updateModified
(
true
);
// Close the stage.
stage
.
close
();
}
});
Button
cancelButton
=
new
Button
(
"Cancel"
);
cancelButton
.
setCancelButton
(
true
);
cancelButton
.
setOnAction
(
new
EventHandler
<
ActionEvent
>()
{
@Override
public
void
handle
(
ActionEvent
event
)
{
stage
.
close
();
}
});
GridPane
buttonPane
=
new
GridPane
();
buttonPane
.
setHgap
(
10
);
buttonPane
.
setAlignment
(
Pos
.
CENTER
);
buttonPane
.
addRow
(
0
,
okButton
,
cancelButton
);
mainPane
.
addRow
(
0
,
movePane
);
mainPane
.
addRow
(
1
,
buttonPane
);
stage
.
showAndWait
();
});
...
...
@@ -1773,7 +1887,7 @@ public class EditorMenuBar extends MenuBar {
Menu
componentsMenu
=
new
Menu
(
"Components"
);
componentsMenu
.
getItems
().
addAll
(
regroupComponentsItem
,
subdivideComponentItem
,
insertComponentItem
);
this
.
edit
.
getItems
().
addAll
(
undoItem
,
new
SeparatorMenuItem
(),
editAxisItem
,
displayAxisItem
,
editMaterialItem
,
new
SeparatorMenuItem
(),
componentsMenu
,
addComponentItem
,
removeComponentsItem
,
renameComponentItem
);
this
.
edit
.
getItems
().
addAll
(
undoItem
,
new
SeparatorMenuItem
(),
editAxisItem
,
displayAxisItem
,
editMaterialItem
,
new
SeparatorMenuItem
(),
componentsMenu
,
addComponentItem
,
removeComponentsItem
,
renameComponentItem
,
moveComponentsItem
);
this
.
view
=
new
Menu
(
"View"
);
Menu
cameraMenu
=
new
Menu
(
"Camera"
);
...
...
@@ -2202,10 +2316,12 @@ public class EditorMenuBar extends MenuBar {
*/
private
void
getAssemblyComponentNames
(
ArrayList
<
String
>
result
,
Component
component
)
{
if
(!
component
.
isLeaf
())
{
// Get the lead component and those that were added.
if
(!
component
.
isLeaf
()
||
component
.
isAdded
())
{
result
.
add
(
component
.
getName
());
}
// Traverse the components recursively.
for
(
Component
child
:
component
.
getChildren
())
{
getAssemblyComponentNames
(
result
,
child
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment