Skip to content

Commit

Permalink
Support Line Style on diagram objects
Browse files Browse the repository at this point in the history
- TODO: decide on whether Grouping should be OK
  • Loading branch information
Phillipus committed Oct 29, 2024
1 parent a204b1b commit 58e239d
Show file tree
Hide file tree
Showing 27 changed files with 511 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public ImageDescriptor getImageDescriptor() {
public boolean shouldExposeFeature(String featureName) {
if(featureName == IArchimatePackage.Literals.LINE_OBJECT__LINE_COLOR.getName() ||
featureName == IArchimatePackage.Literals.LINE_OBJECT__LINE_WIDTH.getName() ||
featureName == IDiagramModelObject.FEATURE_LINE_STYLE ||
featureName == IDiagramModelObject.FEATURE_DERIVE_ELEMENT_LINE_COLOR ||
featureName == IDiagramModelObject.FEATURE_GRADIENT) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ private void drawFigure(Graphics graphics, Color background) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setBackgroundColor(background);
graphics.fillRectangle(bounds);

Expand Down
16 changes: 10 additions & 6 deletions com.archimatetool.editor/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,13 +431,13 @@
</propertySection>
<propertySection
afterSection="lineSection"
class="com.archimatetool.editor.propertysections.LineOpacitySection"
filter="com.archimatetool.editor.propertysections.LineOpacitySection$Filter"
id="lineOpacitySection"
class="com.archimatetool.editor.propertysections.LineSection2"
filter="com.archimatetool.editor.propertysections.LineSection2$Filter"
id="lineSection2"
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
afterSection="lineSection2"
class="com.archimatetool.editor.propertysections.IconColorSection"
filter="com.archimatetool.editor.propertysections.IconColorSection$Filter"
id="iconColorSection"
Expand All @@ -451,7 +451,7 @@
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
afterSection="lineSection2"
class="com.archimatetool.editor.propertysections.GroupBorderTypeSection"
filter="com.archimatetool.editor.propertysections.GroupBorderTypeSection$Filter"
id="groupBorderTypeSection"
Expand Down Expand Up @@ -491,7 +491,7 @@
tab="appearance.tab">
</propertySection>
<propertySection
afterSection="lineOpacitySection"
afterSection="lineSection2"
class="com.archimatetool.editor.propertysections.NoteBorderTypeSection"
filter="com.archimatetool.editor.propertysections.NoteBorderTypeSection$Filter"
id="noteBorderTypeSection"
Expand Down Expand Up @@ -1345,6 +1345,10 @@
class="com.archimatetool.editor.model.compatibility.handlers.Archimate32Handler"
id="com.archimatetool.editor.compatibility.archimate32converter">
</compatibilityHandler>
<compatibilityHandler
class="com.archimatetool.editor.model.compatibility.handlers.LineStyleHandler"
id="com.archimatetool.editor.compatibility.lineStyle">
</compatibilityHandler>
</extension>
<extension
point="com.archimatetool.editor.imageExportProvider">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.archimatetool.model.IProfile;
import com.archimatetool.model.ITextAlignment;
import com.archimatetool.model.ITextPosition;
import com.archimatetool.model.impl.Grouping;



Expand All @@ -47,14 +48,17 @@ public class ArchimateDiagramModelFactory implements ICreationFactory {
public static IDiagramModelArchimateObject createDiagramModelArchimateObject(IArchimateElement element) {
IDiagramModelArchimateObject dmo = IArchimateFactory.eINSTANCE.createDiagramModelArchimateObject();
dmo.setArchimateElement(element);

// Figure Type
dmo.setType(ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DEFAULT_FIGURE_PREFIX + element.eClass().getName()));

// Add new bounds with a default user size
IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider)ObjectUIFactory.INSTANCE.getProvider(dmo);

// Add new bounds with a default user size
Dimension size = provider.getDefaultSize();
dmo.setBounds(0, 0, size.width, size.height);

// Text position and alignment
dmo.setTextPosition(provider.getDefaultTextPosition());
dmo.setTextAlignment(provider.getDefaultTextAlignment());

Expand All @@ -64,6 +68,11 @@ public static IDiagramModelArchimateObject createDiagramModelArchimateObject(IAr
// Gradient
dmo.setGradient(ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DEFAULT_GRADIENT));

// Line Style for Grouping
if(element instanceof Grouping) {
dmo.setLineStyle(IDiagramModelObject.LINE_STYLE_DASHED);
}

return dmo;
}

Expand All @@ -77,6 +86,8 @@ public static IDiagramModelArchimateConnection createDiagramModelArchimateConnec
connection.setArchimateRelationship(relation);

IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider)ObjectUIFactory.INSTANCE.getProvider(connection);

// Text alignment
connection.setTextAlignment(provider.getDefaultTextAlignment());

// Set user default colors as set in prefs
Expand Down Expand Up @@ -112,63 +123,58 @@ public Object getNewObject() {
return null;
}

boolean isSpecialization = fProfile != null && fProfile.getArchimateModel() != null;
boolean isSpecialization = fProfile != null && fProfile.getArchimateModel() != null;

EObject object = IArchimateFactory.eINSTANCE.create(fTemplate);

// Add Profile to Concept if set
if(object instanceof IArchimateConcept && isSpecialization) {
((IArchimateConcept)object).getProfiles().add(fProfile);
if(object instanceof IArchimateConcept concept && isSpecialization) {
concept.getProfiles().add(fProfile);
}

// Connection created from Relationship Template
if(object instanceof IArchimateRelationship) {
return createDiagramModelArchimateConnection((IArchimateRelationship)object);
// Archimate Connection created from Relationship Template
if(object instanceof IArchimateRelationship relationship) {
return createDiagramModelArchimateConnection(relationship);
}

// Archimate Diagram Object created from Archimate Element Template
else if(object instanceof IArchimateElement) {
IArchimateElement element = (IArchimateElement)object;
else if(object instanceof IArchimateElement element) {
element.setName(isSpecialization ? fProfile.getName() : ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate));
return createDiagramModelArchimateObject(element);
}

// Group
else if(object instanceof IDiagramModelGroup) {
IDiagramModelGroup group = (IDiagramModelGroup)object;
else if(object instanceof IDiagramModelGroup group) {
group.setName(ArchiLabelProvider.INSTANCE.getDefaultName(fTemplate));
ColorFactory.setDefaultColors(group);
// Gradient
group.setGradient(ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DEFAULT_GRADIENT));
}

// Note
else if(object instanceof IDiagramModelNote) {
IDiagramModelNote note = (IDiagramModelNote)object;
else if(object instanceof IDiagramModelNote note) {
ColorFactory.setDefaultColors(note);
// Gradient
note.setGradient(ArchiPlugin.PREFERENCES.getInt(IPreferenceConstants.DEFAULT_GRADIENT));
}

// Connection
else if(object instanceof IDiagramModelConnection) {
ColorFactory.setDefaultColors((IDiagramModelConnection)object);
else if(object instanceof IDiagramModelConnection connection) {
ColorFactory.setDefaultColors(connection);
}

IGraphicalObjectUIProvider provider = (IGraphicalObjectUIProvider)ObjectUIFactory.INSTANCE.getProvider(object);

if(object instanceof ITextAlignment) {
((ITextAlignment)object).setTextAlignment(provider.getDefaultTextAlignment());
if(object instanceof ITextAlignment textAlignment) {
textAlignment.setTextAlignment(provider.getDefaultTextAlignment());
}

if(object instanceof ITextPosition) {
((ITextPosition)object).setTextPosition(provider.getDefaultTextPosition());
if(object instanceof ITextPosition textPosition) {
textPosition.setTextPosition(provider.getDefaultTextPosition());
}

// Add new bounds with a default user size
if(object instanceof IDiagramModelObject) {
if(object instanceof IDiagramModelObject dmo) {
Dimension size = provider.getDefaultSize();
((IDiagramModelObject)object).setBounds(0, 0, size.width, size.height);
dmo.setBounds(0, 0, size.width, size.height);
}

return object;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* This program and the accompanying materials
* are made available under the terms of the License
* which accompanies this distribution in the file LICENSE.txt
*/
package com.archimatetool.editor.diagram.commands;

import com.archimatetool.editor.model.commands.FeatureCommand;
import com.archimatetool.model.IDiagramModelObject;



/**
* Line Style Command
*
* @author Phillip Beauvoir
*/
public class DiagramModelObjectLineStyleCommand extends FeatureCommand {

public DiagramModelObjectLineStyleCommand(IDiagramModelObject object, int style) {
super("Change Line Style", object,
IDiagramModelObject.FEATURE_LINE_STYLE, style, IDiagramModelObject.FEATURE_LINE_STYLE_DEFAULT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ protected void setDisabledState(Graphics graphics) {
//graphics.setLineStyle(SWT.LINE_DASH);
//graphics.setLineDash(new int[] { 4, 3 });
}

/**
* Set the line style
* @param graphics
*/
protected void setLineStyle(Graphics graphics) {
double scale = Math.min(FigureUtils.getFigureScale(this), 1.0); // only scale below 1.0

switch(getLineStyle()) {
case IDiagramModelObject.LINE_STYLE_SOLID:
default:
graphics.setLineStyle(Graphics.LINE_SOLID);
break;
case IDiagramModelObject.LINE_STYLE_DASHED:
graphics.setLineDash(new float[] { (float)(8 * scale), (float)(4 * scale) });
break;
case IDiagramModelObject.LINE_STYLE_DOTTED:
graphics.setLineDash(new float[] { (float)(2 * scale), (float)(2 * scale) });
break;
}
}

/**
* Set the UI
Expand Down Expand Up @@ -247,6 +268,10 @@ protected int getLineWidth() {
return fDiagramModelObject.getLineWidth();
}

protected int getLineStyle() {
return fDiagramModelObject.getLineStyle();
}

@Override
public void updateIconImage() {
if(getIconicDelegate() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ protected void setLineWidth(Graphics graphics, int lineWidth, Rectangle bounds)
getOwner().setLineWidth(graphics, lineWidth, bounds);
}

/**
* Set line style
* @param graphics
*/
protected void setLineStyle(Graphics graphics) {
getOwner().setLineStyle(graphics);
}

/**
* Apply a gradient to the given Graphics instance and bounds using current fill color, alpha and gradient settings
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public void drawFigure(Graphics graphics) {
// Line Width
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

if(!isEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ protected void paintFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

if(fImage != null) {
// Faster but no transparency
if(useScaledImage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ protected void drawFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setAlpha(getAlpha());

if(getDiagramModelObject().getBorderType() == IDiagramModelGroup.BORDER_TABBED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected void paintFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
if(getDiagramModelObject().getBorderType() != IDiagramModelNote.BORDER_NONE) {
setLineWidth(graphics, bounds);
setLineStyle(graphics);
}

// Fill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ protected void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

PointList points = new PointList();
points.addPoint(bounds.x + FLANGE, bounds.y);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ protected void drawFigure(Graphics graphics) {
// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

// Scale line dashes below 1.0
double scale = Math.min(FigureUtils.getGraphicsScale(graphics), 1.0);

graphics.setLineDash(new float[] { (float)(8 * scale), (float)(4 * scale) });
setLineStyle(graphics);

graphics.setBackgroundColor(getFillColor());
graphics.setForegroundColor(getLineColor());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ protected void drawFigure(Graphics graphics) {

// Set line width here so that the whole figure is constrained, otherwise SVG graphics will have overspill
setLineWidth(graphics, bounds);

setLineStyle(graphics);

graphics.setBackgroundColor(getFillColor());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ CompoundCommand createCommand(IDiagramModelComponent targetComponent) {
result.add(cmd);
}

// Line Style
if(targetUIProvider != null && targetUIProvider.shouldExposeFeature(IDiagramModelObject.FEATURE_LINE_STYLE)) {
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_LINE_STYLE, source.getLineStyle(), IDiagramModelObject.FEATURE_LINE_STYLE_DEFAULT); //$NON-NLS-1$
if(cmd.canExecute()) {
result.add(cmd);
}
}

// Gradient
if(targetUIProvider != null && targetUIProvider.shouldExposeFeature(IDiagramModelObject.FEATURE_GRADIENT)) {
cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT); //$NON-NLS-1$
Expand Down
Loading

0 comments on commit 58e239d

Please sign in to comment.