Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Eclipse Projects
Eclipse eTrice™
Eclipse eTrice
Commits
9a221a2a
Commit
9a221a2a
authored
May 11, 2022
by
Eyrak Paen-Rochlitz
Browse files
[ui.structure] Resize and move respects element bounds and border
parent
26186c40
Changes
3
Hide whitespace changes
Inline
Side-by-side
plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/ActorContainerRefSupport.java
View file @
9a221a2a
...
...
@@ -977,23 +977,39 @@ public class ActorContainerRefSupport {
@Override
public
boolean
canMoveShape
(
IMoveShapeContext
context
)
{
boolean
canMove
=
super
.
canMoveShape
(
context
);
if
(
canMove
)
{
Object
bo
=
getBusinessObjectForPictogramElement
(
context
.
getPictogramElement
());
if
(
bo
instanceof
ActorContainerRef
)
{
ActorContainerRef
ar
=
(
ActorContainerRef
)
bo
;
ContainerShape
acShape
=
context
.
getTargetContainer
();
EObject
parent
=
acShape
.
getLink
().
getBusinessObjects
().
get
(
0
);
// TODOHRR: also check coordinates (no overlap with actor boundaries)
return
!
isInherited
(
ar
,
parent
);
}
}
if
(!
super
.
canMoveShape
(
context
))
return
false
;
Object
bo
=
getBusinessObjectForPictogramElement
(
context
.
getPictogramElement
());
if
(!(
bo
instanceof
ActorContainerRef
))
return
false
;
ActorContainerRef
ar
=
(
ActorContainerRef
)
bo
;
ContainerShape
acShape
=
context
.
getTargetContainer
();
EObject
parent
=
acShape
.
getLink
().
getBusinessObjects
().
get
(
0
);
// TODOHRR: also check coordinates (no overlap with actor boundaries)
return
canMove
;
if
(
isInherited
(
ar
,
parent
))
return
false
;
PosAndSize
parentExtent
=
DiagramUtil
.
getVisibleExtent
(
acShape
);
PosAndSize
childExtent
=
DiagramUtil
.
getVisibleExtent
(
context
.
getPictogramElement
());
if
(
parentExtent
==
null
||
childExtent
==
null
)
return
false
;
int
destX
=
context
.
getDeltaX
()+
childExtent
.
getX
();
int
destY
=
context
.
getDeltaY
()+
childExtent
.
getY
();
if
(
destX
<
parentExtent
.
getX
())
return
false
;
if
(
destY
<
parentExtent
.
getY
())
return
false
;
if
(
destX
+
childExtent
.
getW
()
>
parentExtent
.
getX
()+
parentExtent
.
getW
())
return
false
;
if
(
destY
+
childExtent
.
getH
()
>
parentExtent
.
getY
()+
parentExtent
.
getH
())
return
false
;
return
true
;
}
}
...
...
plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/DiagramUtil.java
View file @
9a221a2a
...
...
@@ -22,11 +22,13 @@ import org.eclipse.etrice.core.room.Binding;
import
org.eclipse.etrice.core.room.InterfaceItem
;
import
org.eclipse.etrice.core.room.LayerConnection
;
import
org.eclipse.etrice.core.room.StructureClass
;
import
org.eclipse.etrice.core.room.util.RoomSwitch
;
import
org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize
;
import
org.eclipse.graphiti.mm.PropertyContainer
;
import
org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm
;
import
org.eclipse.graphiti.mm.pictograms.ContainerShape
;
import
org.eclipse.graphiti.mm.pictograms.Diagram
;
import
org.eclipse.graphiti.mm.pictograms.PictogramElement
;
import
org.eclipse.graphiti.mm.pictograms.Shape
;
import
org.eclipse.graphiti.services.Graphiti
;
import
org.eclipse.graphiti.services.ILinkService
;
...
...
@@ -117,4 +119,107 @@ public class DiagramUtil {
PosAndSize
pos
=
getPosAndSize
(
element
);
return
getNearestBorder
(
pos
,
posContainer
);
}
private
static
class
VisibleExtentSwitch
extends
RoomSwitch
<
PosAndSize
>
{
private
PictogramElement
pe
;
public
VisibleExtentSwitch
(
PictogramElement
pe
)
{
this
.
pe
=
pe
;
}
@Override
public
PosAndSize
caseStructureClass
(
StructureClass
object
)
{
if
(
pe
.
getGraphicsAlgorithm
()
==
null
)
return
null
;
if
(
pe
.
getGraphicsAlgorithm
().
getGraphicsAlgorithmChildren
().
size
()
<
2
)
{
return
null
;
}
GraphicsAlgorithm
visibleGa
=
pe
.
getGraphicsAlgorithm
().
getGraphicsAlgorithmChildren
().
get
(
0
);
return
getPosAndSize
(
visibleGa
);
}
@Override
public
PosAndSize
caseInterfaceItem
(
InterfaceItem
object
)
{
if
(
pe
.
getGraphicsAlgorithm
()
==
null
)
return
null
;
if
(
pe
.
getGraphicsAlgorithm
().
getGraphicsAlgorithmChildren
().
size
()
<
1
)
{
return
null
;
}
GraphicsAlgorithm
invisible
=
pe
.
getGraphicsAlgorithm
();
GraphicsAlgorithm
visible
=
pe
.
getGraphicsAlgorithm
().
getGraphicsAlgorithmChildren
().
get
(
0
);
return
new
PosAndSize
(
visible
.
getX
()
+
invisible
.
getX
(),
visible
.
getY
()
+
invisible
.
getY
(),
visible
.
getWidth
(),
visible
.
getHeight
()
);
}
@Override
public
PosAndSize
caseActorContainerRef
(
ActorContainerRef
object
)
{
if
(
pe
.
getGraphicsAlgorithm
()
==
null
)
return
null
;
if
(
pe
.
getGraphicsAlgorithm
().
getGraphicsAlgorithmChildren
().
size
()
<
2
)
{
return
null
;
}
IPeService
peService
=
Graphiti
.
getPeService
();
GraphicsAlgorithm
invisible
=
pe
.
getGraphicsAlgorithm
();
GraphicsAlgorithm
main
=
null
;
GraphicsAlgorithm
repl
=
null
;
boolean
isReplVisible
=
false
;
for
(
GraphicsAlgorithm
ga
:
invisible
.
getGraphicsAlgorithmChildren
())
{
String
value
=
peService
.
getPropertyValue
(
ga
,
ActorContainerRefSupport
.
GRAPHIC_ITEM_KEY
);
if
(
ActorContainerRefSupport
.
MAIN_BORDER
.
equals
(
value
))
{
main
=
ga
;
}
else
if
(
ActorContainerRefSupport
.
REPL_BORDER
.
equals
(
value
))
{
repl
=
ga
;
isReplVisible
=
ga
.
getLineVisible
();
}
}
if
(
main
==
null
||
repl
==
null
)
return
null
;
if
(
isReplVisible
)
{
int
x
=
Math
.
min
(
main
.
getX
(),
repl
.
getX
());
int
y
=
Math
.
min
(
main
.
getY
(),
repl
.
getY
());
int
wTotalMain
=
main
.
getX
()+
main
.
getWidth
();
int
wTotalRepl
=
repl
.
getX
()+
repl
.
getWidth
();
int
hTotalMain
=
main
.
getY
()+
main
.
getHeight
();
int
hTotalRepl
=
repl
.
getY
()+
repl
.
getHeight
();
return
new
PosAndSize
(
x
+
invisible
.
getX
(),
y
+
invisible
.
getY
(),
wTotalMain
>
wTotalRepl
?
wTotalMain
-
x
:
wTotalRepl
-
x
,
hTotalMain
>
hTotalRepl
?
hTotalMain
-
y
:
hTotalRepl
-
y
);
}
else
{
return
new
PosAndSize
(
main
.
getX
()+
invisible
.
getX
(),
main
.
getY
()+
invisible
.
getY
(),
main
.
getWidth
(),
main
.
getHeight
());
}
}
@Override
public
PosAndSize
defaultCase
(
EObject
object
)
{
return
getPosAndSize
(
pe
.
getGraphicsAlgorithm
());
}
}
/**
* Gets the position and size of the visible bounding box of the given PictogramElement. The
* bounds will be calculated based on the GraphicsAlgorithms of the PictogramElement and the
* type of business object it is associated with.
*
* @return the visible bounds of the PictogramElement, or null if the PictogramElement was malformed
* or the corresponding business object was invalid
*/
public
static
PosAndSize
getVisibleExtent
(
PictogramElement
pe
)
{
Object
bo
=
Graphiti
.
getLinkService
().
getBusinessObjectForLinkedPictogramElement
(
pe
);
if
(!
EObject
.
class
.
isInstance
(
bo
))
return
null
;
return
new
VisibleExtentSwitch
(
pe
).
doSwitch
((
EObject
)
bo
);
}
}
plugins/org.eclipse.etrice.ui.structure/src/org/eclipse/etrice/ui/structure/support/StructureClassSupport.java
View file @
9a221a2a
...
...
@@ -28,6 +28,7 @@ import org.eclipse.etrice.ui.common.base.support.CantRemoveFeature;
import
org.eclipse.etrice.ui.common.base.support.DeleteWithoutConfirmFeature
;
import
org.eclipse.etrice.ui.common.commands.ChangeDiagramInputJob
;
import
org.eclipse.etrice.ui.structure.support.DiagramUtil.Border
;
import
org.eclipse.etrice.ui.structure.support.provider.IPositionProvider.PosAndSize
;
import
org.eclipse.graphiti.dt.IDiagramTypeProvider
;
import
org.eclipse.graphiti.features.IAddFeature
;
import
org.eclipse.graphiti.features.IDeleteFeature
;
...
...
@@ -381,11 +382,13 @@ public class StructureClassSupport {
StructureClass
sc
=
(
StructureClass
)
getBusinessObjectForPictogramElement
(
containerShape
);
for
(
Shape
childShape
:
containerShape
.
getChildren
())
{
Object
childBo
=
getBusinessObjectForPictogramElement
(
childShape
);
GraphicsAlgorithm
ga
=
childShape
.
getGraphicsAlgorithm
();
int
x
=
ga
.
getX
()+
ga
.
getWidth
()-
ActorContainerRefSupport
.
MARGIN
;
int
y
=
ga
.
getY
()+
ga
.
getHeight
()-
ActorContainerRefSupport
.
MARGIN
;
PosAndSize
childExtent
=
DiagramUtil
.
getVisibleExtent
(
childShape
);
if
(
childExtent
==
null
)
continue
;
int
x
=
childExtent
.
getX
()+
childExtent
.
getW
()+
LINE_WIDTH
;
int
y
=
childExtent
.
getY
()+
childExtent
.
getH
()+
LINE_WIDTH
;
if
(
isOnInterface
(
sc
,
childBo
))
{
Border
border
=
DiagramUtil
.
getNearestBorder
(
ga
,
containerVisibleGa
);
Border
border
=
DiagramUtil
.
getNearestBorder
(
childShape
.
getGraphicsAlgorithm
()
,
containerVisibleGa
);
switch
(
border
)
{
case
TOP:
case
BOTTOM:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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