-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The command lets the user choose either the new length or width of the image. Afterwards it adjusts the ppi value to get close to the user entered size. Also adds the new feature to the documentation #7
- Loading branch information
Showing
9 changed files
with
229 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Dialog</class> | ||
<widget class="QDialog" name="Dialog"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>300</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Dialog</string> | ||
</property> | ||
<layout class="QFormLayout" name="formLayout"> | ||
<item row="1" column="0"> | ||
<widget class="QLabel" name="label"> | ||
<property name="text"> | ||
<string>Length (X)</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="1" column="1"> | ||
<widget class="QDoubleSpinBox" name="LengthBox"> | ||
<property name="suffix"> | ||
<string>mm</string> | ||
</property> | ||
<property name="maximum"> | ||
<double>100000.000000000000000</double> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="1"> | ||
<widget class="QDoubleSpinBox" name="WidthBox"> | ||
<property name="suffix"> | ||
<string>mm</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="3" column="0" colspan="2"> | ||
<widget class="Line" name="line"> | ||
<property name="orientation"> | ||
<enum>Qt::Horizontal</enum> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="2" column="0"> | ||
<widget class="QLabel" name="label_2"> | ||
<property name="text"> | ||
<string>Width (Y)</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item row="0" column="0" colspan="2"> | ||
<widget class="QLabel" name="InfoLabel"> | ||
<property name="font"> | ||
<font> | ||
<weight>75</weight> | ||
<bold>true</bold> | ||
</font> | ||
</property> | ||
<property name="text"> | ||
<string/> | ||
</property> | ||
</widget> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import FreeCAD, FreeCADGui | ||
|
||
import lithophane_utils | ||
from utils.resource_utils import iconPath, uiPath | ||
from utils.format_utils import formatLength | ||
import utils.qtutils as qtutils | ||
|
||
class ScalePanel(): | ||
def __init__(self, image, freeCadObject): | ||
self.image = image | ||
self.freeCadObject = freeCadObject | ||
self.originalLength = image.length() | ||
self.originalWidth = image.width() | ||
self.scaleFactor = 1 | ||
|
||
self.form = FreeCADGui.PySideUic.loadUi(uiPath('scale_dialog.ui')) | ||
|
||
self.LengthBox = self.form.LengthBox | ||
self.WidthBox = self.form.WidthBox | ||
self.InfoLabel = self.form.InfoLabel | ||
self.LengthBox.setValue(self.originalLength) | ||
self.WidthBox.setValue(self.originalWidth) | ||
|
||
self.LengthBox.valueChanged.connect(self.lengthChanged) | ||
self.WidthBox.valueChanged.connect(self.widthChanged) | ||
|
||
def accept(self): | ||
FreeCADGui.Control.closeDialog() | ||
|
||
if self.scaleFactor != 1: | ||
self.InfoLabel.setText('The image is recomputed. This might take a while...') | ||
qtutils.processEvents() | ||
|
||
originalPpi = self.freeCadObject.ppi | ||
|
||
# smaller ppi means larger image. So division not multiplication | ||
self.freeCadObject.ppi = originalPpi / self.scaleFactor | ||
|
||
lithophane_utils.recomputeView() | ||
|
||
def reject(self): | ||
FreeCADGui.Control.closeDialog() | ||
|
||
def lengthChanged(self): | ||
self.updateScaleFactor(self.originalLength, self.LengthBox.value()) | ||
|
||
newWidth = self.originalWidth * self.scaleFactor | ||
|
||
if self.WidthBox.value() != newWidth: | ||
self.WidthBox.setValue(newWidth) | ||
|
||
def widthChanged(self): | ||
self.updateScaleFactor(self.originalWidth, self.WidthBox.value()) | ||
|
||
newLength = self.originalLength * self.scaleFactor | ||
|
||
if self.LengthBox.value() != newLength: | ||
self.LengthBox.setValue(newLength) | ||
|
||
def updateScaleFactor(self, old, new): | ||
self.scaleFactor = new / old | ||
|
||
class ScaleCommand: | ||
toolbarName = 'Image_Tools' | ||
commandName = 'Scale_Image' | ||
|
||
def GetResources(self): | ||
return {'MenuText': "Scale", | ||
'ToolTip' : "Adjusts the dpi value to scale the final geometry", | ||
'Pixmap': iconPath('Scale.svg')} | ||
|
||
def Activated(self): | ||
(image, label, freeCadObject) = lithophane_utils.findSelectedImage(includeObject=True) | ||
|
||
if image is None: | ||
qtutils.showInfo("No LithophaneImage selected", "Select exactly one LithophaneImage to continue") | ||
|
||
return | ||
|
||
panel = ScalePanel(image, freeCadObject) | ||
FreeCADGui.Control.showDialog(panel) | ||
|
||
def IsActive(self): | ||
"""There should be at least an active document.""" | ||
return not FreeCAD.ActiveDocument is None | ||
|
||
if __name__ == "__main__": | ||
command = ScaleCommand(); | ||
|
||
if command.IsActive(): | ||
command.Activated() | ||
else: | ||
qtutils.showInfo("No open Document", "There is no open document") | ||
else: | ||
import toolbars | ||
toolbars.toolbarManager.registerCommand(ScaleCommand()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
import FreeCAD | ||
from os import path | ||
|
||
utils_path = path.join(path.dirname(path.realpath(__file__)), '../Resources/Icons') | ||
resources_path = path.join(path.dirname(path.realpath(__file__)), '../Resources') | ||
icons_path = path.join(resources_path, 'Icons') | ||
ui_path = path.join(resources_path, 'UI') | ||
|
||
def iconPath(name): | ||
f = path.join(utils_path, name) | ||
f = path.join(icons_path, name) | ||
|
||
return f | ||
|
||
def uiPath(name): | ||
f = path.join(ui_path, name) | ||
|
||
return f |