import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.jface.resource.JFaceResources;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.simantics.Simantics;
+import org.simantics.db.Session;
import org.simantics.db.exception.DatabaseException;
import org.simantics.plant3d.Activator;
import org.simantics.plant3d.ontology.Plant3D;
public class ComponentSelectionDialog extends Dialog implements ISelectionChangedListener {
+ private static final String DIALOG = "ComponentSelectionDialog"; //$NON-NLS-1$
+
+ private IDialogSettings dialogSettings;
+
+ private double lengthFactor = 1.0;
+
private ResourceManager resourceManager;
private String libUri;
private Text lengthText;
// Turn component
private Text angleText;
- // Rotated In-line, or turn conponent.
+ // Rotated In-line, or turn component.
private Text rotationAngleText;
// Input for new PipeRun
private Double diameter;
+ private Double thickness;
private Double turnRadius;
private Text diameterText;
+ private Text thicknessText;
private Text turnRadiusText;
+
+ // Validation message label
+ private Label validationLabel;
// Position selection
private Button startButton;
this.libUri = libUri;
usedNames = new HashSet<>();
+
+ setShellStyle(getShellStyle() | SWT.RESIZE);
+
+ IDialogSettings settings = Activator.getDefault().getDialogSettings();
+ dialogSettings = settings.getSection(DIALOG);
+ if (dialogSettings == null)
+ dialogSettings = settings.addNewSection(DIALOG);
}
+ public void setLengthFactor(double lengthFactor) {
+ this.lengthFactor = lengthFactor;
+ }
+
+ @Override
+ protected IDialogSettings getDialogBoundsSettings() {
+ return dialogSettings;
+ }
+
@Override
protected void configureShell(Shell newShell) {
super.configureShell(newShell);
}
protected List<Item> getItems(Class<?> c, String libUri) throws DatabaseException {
+ Session session = Simantics.getSession();
if (InlineComponent.class.equals(c)) {
- return P3DUtil.getInlines(libUri);
+ return P3DUtil.getInlines(session, libUri);
} else if (TurnComponent.class.equals(c)) {
- return P3DUtil.getTurns(libUri);
+ return P3DUtil.getTurns(session, libUri);
} else if (EndComponent.class.equals(c)) {
- return P3DUtil.getEnds(libUri);
+ return P3DUtil.getEnds(session, libUri);
} else {
return null;
}
turns = P3DUtil.filterUserComponents(turns);
inlines = P3DUtil.filterUserComponents(inlines);
- ExpandBar expandBar = new ExpandBar(composite, SWT.NONE);
+ ExpandBar expandBar = new ExpandBar(composite, SWT.V_SCROLL);
ExpandItem inlineItem = new ExpandItem(expandBar, SWT.NONE);
inlineItem.setText("Inline");
endViewer.addSelectionChangedListener(this);
GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).span(2, 1).applyTo(expandBar);
- GridDataFactory.fillDefaults().minSize(500, 500).hint(500, 500).applyTo(composite);
+ GridDataFactory.fillDefaults().grab(true, true).minSize(500, 500).hint(500, 500).applyTo(composite);
Label label = new Label(composite, SWT.NONE);
label.setText("Position");
label.setText("Diameter");
diameterText = new Text(composite, SWT.SINGLE | SWT.BORDER);
label = new Label(composite, SWT.NONE);
- label.setText("Turn Radius");
+ label.setText("Wall thickness");
+ thicknessText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+ label = new Label(composite, SWT.NONE);
+ label.setText("Turn radius");
turnRadiusText = new Text(composite, SWT.SINGLE | SWT.BORDER);
+
+ validationLabel = new Label(composite, SWT.NONE);
+ validationLabel.setText("");
lengthText.setEnabled(false);
angleText.setEnabled(false);
rotationAngleText.setEnabled(false);
turnRadiusText.setEnabled(false);
diameterText.setEnabled(false);
+ thicknessText.setEnabled(false);
nameText.addKeyListener(new KeyAdapter() {
@Override
@Override
public void keyReleased(KeyEvent e) {
try {
- length = Double.parseDouble(lengthText.getText());
+ length = Double.parseDouble(lengthText.getText()) / lengthFactor;
} catch (NumberFormatException err) {
length = null;
}
@Override
public void keyReleased(KeyEvent e) {
try {
- diameter = Double.parseDouble(diameterText.getText());
+ diameter = Double.parseDouble(diameterText.getText()) / lengthFactor;
} catch (NumberFormatException err) {
diameter = null;
}
validate();
}
});
+
+ thicknessText.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyReleased(KeyEvent e) {
+ try {
+ thickness = Double.parseDouble(thicknessText.getText()) / lengthFactor;
+ } catch (NumberFormatException err) {
+ thickness = null;
+ }
+ validate();
+ }
+ });
turnRadiusText.addKeyListener(new KeyAdapter() {
@Override
public void keyReleased(KeyEvent e) {
try {
- turnRadius = Double.parseDouble(turnRadiusText.getText());
+ turnRadius = Double.parseDouble(turnRadiusText.getText()) / lengthFactor;
} catch (NumberFormatException err) {
turnRadius = null;
}
horizFillData.applyTo(angleText);
horizFillData.applyTo(rotationAngleText);
horizFillData.applyTo(diameterText);
+ horizFillData.applyTo(thicknessText);
horizFillData.applyTo(turnRadiusText);
+
+ GridDataFactory.fillDefaults().span(2, 1).align(SWT.END, SWT.END).grab(true, false).applyTo(validationLabel);
if (!allowed.contains(PositionType.NEXT) && !allowed.contains(PositionType.PREVIOUS)) {
turnViewer.getList().setEnabled(false);
filterAllowed.clear();
Set<PositionType> filterAllowed = new HashSet<PositionType>();
boolean ok = true;
+ String msg = null;
+
+ if (name.isEmpty() || usedNames.contains(name)) {
+ ok = false;
+ if (msg == null) {
+ if (name.isEmpty())
+ msg = "Please provide a valid name";
+ else
+ msg = "Name \"" + name + "\" is already in use";
+ }
+ }
+
if (selected == null) {
ok = false;
} else if (selected.isCode()) {// TODO : instead of disabling the button, we should filter the content.
angleText.setEnabled(false);
rotationAngleText.setEnabled(selected.isRotated());
ok = false;
-
+ if (msg == null) msg = "Cannot split a straight pipe with a straight pipe";
} else {
lengthText.setEnabled(true);
angleText.setEnabled(false);
rotationAngleText.setEnabled(selected.isRotated());
- if (length == null)
+ if (length == null || length <= 0.0) {
ok = false;
+ if (msg == null) msg = "Please provide a valid length";
+ }
}
} else if (selected.getType() == Type.TURN) {
filterAllowed.add(PositionType.NEXT);
lengthText.setEnabled(false);
angleText.setEnabled(true);
rotationAngleText.setEnabled(true);
- if (angle == null)
+ if (angle == null) {
ok = false;
+ if (msg == null) msg = "Please provide a turn angle";
+ }
} else {
// this should not happen, since end components should not have variable, or
// modifiable flag.
if (selected.isSizeChange()) {
turnRadiusText.setEnabled(true);
diameterText.setEnabled(true);
- if (diameter == null || turnRadius == null)
+ thicknessText.setEnabled(true);
+ if (diameter == null || diameter <= 0.0) {
+ ok = false;
+ if (msg == null) msg = "Please provide a valid diameter";
+ }
+ if (turnRadius == null || diameter != null && turnRadius < diameter / 2) {
+ ok = false;
+ if (msg == null) msg = "Please provide a valid turn radius";
+ }
+ if (thickness == null || thickness < 0.0 || diameter != null && thickness >= diameter / 2) {
ok = false;
+ if (msg == null) msg = "Please provide a valid wall thickness";
+ }
} else {
turnRadiusText.setEnabled(false);
diameterText.setEnabled(false);
this.filterAllowed.add(t);
}
- if (name.isEmpty() || usedNames.contains(name))
- ok = false;
+ validationLabel.setText(msg != null ? msg : "");
+ validationLabel.requestLayout();
getButton(OK).setEnabled(ok);
}
return lenghtAdjustable;
}
+ public Double getThickness() {
+ return thickness;
+ }
+
}