Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to support per-dimension scaling. #5

Merged
merged 2 commits into from Dec 18, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion scripts/Draw/Dimension/DimAligned/DimAligned.js
Expand Up @@ -159,7 +159,12 @@ DimAligned.prototype.getOperation = function(preview) {
}

var doc = this.getDocument();
var entity = new RDimAlignedEntity(doc, this.data);
var scale = this.parseScale(this.getScaleString());
var scaled_data = this.data;

scaled_data.setLinearFactor(1/scale);

var entity = new RDimAlignedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
Expand Down
7 changes: 6 additions & 1 deletion scripts/Draw/Dimension/DimRotated/DimRotated.js
Expand Up @@ -159,7 +159,12 @@ DimRotated.prototype.getOperation = function(preview) {
}

var doc = this.getDocument();
var entity = new RDimRotatedEntity(doc, this.data);
var scale = this.parseScale(this.getScaleString());
var scaled_data = this.data;

scaled_data.setLinearFactor(1/scale);

var entity = new RDimRotatedEntity(doc, scaled_data);
if (!isEntity(entity)) {
return undefined;
}
Expand Down
30 changes: 30 additions & 0 deletions scripts/Draw/Dimension/Dimension.js
Expand Up @@ -85,6 +85,8 @@ Dimension.prototype.initUiOptions = function(resume, optionsToolBar) {
lowerToleranceLineEdit.text = "";
WidgetFactory.initLineEdit(lowerToleranceLineEdit, true);

this.initScaleCombo();

// if we are resuming, restore previous values (automatic)
// it not, keep them empty.
if (!resume) {
Expand All @@ -95,6 +97,21 @@ Dimension.prototype.initUiOptions = function(resume, optionsToolBar) {
}
};

Dimension.prototype.initScaleCombo = function() {
var optionsToolBar = EAction.getOptionsToolBar();
var scaleCombo = optionsToolBar.findChild("Scale");
scaleCombo.blockSignals(true);
var prev = scaleCombo.currentText;
scaleCombo.clear();
var scales = this.getScales();
for (var i=0; i<scales.length; ++i) {
scaleCombo.addItem(scales[i]);
}
scaleCombo.currentText = prev;
scaleCombo.blockSignals(false);
};


Dimension.getMenu = function() {
var menu = EAction.getMenu(Dimension.getTitle(), "DimensionMenu");
menu.setProperty("scriptFile", Dimension.includeBasePath + "/Dimension.js");
Expand Down Expand Up @@ -203,3 +220,16 @@ Dimension.prototype.slotLowerToleranceChanged = function(text) {
this.data.setLowerTolerance(text);
}
};

Dimension.prototype.getScaleString = function() {
var optionsToolBar = EAction.getOptionsToolBar();
var scaleCombo = optionsToolBar.findChild("Scale");
return scaleCombo.currentText;
};

/**
* Parses the given scale string (e.g. "1:2") and returns the scale as number (e.g. 0.5).
*/
Dimension.prototype.parseScale = function(scaleString) {
return RMath.parseScale(scaleString);
};
46 changes: 45 additions & 1 deletion scripts/Draw/Dimension/Dimension.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>470</width>
<width>719</width>
<height>56</height>
</rect>
</property>
Expand Down Expand Up @@ -157,6 +157,50 @@
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Scale</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="Scale">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Drawing Scale</string>
</property>
<property name="editable">
<bool>true</bool>
</property>
<property name="insertPolicy">
<enum>QComboBox::NoInsert</enum>
</property>
<item>
<property name="text">
<string notr="true">1:1</string>
</property>
</item>
</widget>
</item>
</layout>
</widget>
<resources/>
Expand Down