Skip to content

Commit

Permalink
Gives objects a meaningful name
Browse files Browse the repository at this point in the history
 - LithophaneImages will be named after the image file on import
 - Create Box command will use the Label of the LithophaneImage and append
   _Box to it
 - Create Solid command will use the Label of the mesh and appends _Solid
   to it
 - Show Pointcloud command will use the Label of the LithophaneImage and
   append _PointCloud to it

fixes #12
  • Loading branch information
furti committed Aug 28, 2018
1 parent 43866ee commit d40541c
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The command imports a new Image into the document. Therefor a Dialog is shown th

Depending on the image and your machine, it might take a while for the import to finish. On my 8 years old Intel i7-2670QM it takes about 8 seconds to import the windmill image (814x1000 pixels). **FreeCAD might be unresponsive during the import**.

The name of the imported image object is hardcoded to `LithophaneImage` right now. So when importing more than one image it might be hard to distinguish the images from each other. See https://github.com/furti/FreeCAD-Lithophane/issues/12
The name of the imported image object will be taken from the image file.

**The pixel data whil be computed every time you recompute the image object!** This can happen when you change some settings of the image or force a recompute of the whole document.
For performance reasons the calculated point cloud is stored inside the FreeCAD file. So your files can get pretty big real fast when you import big images.
Expand Down Expand Up @@ -108,7 +108,7 @@ There will be a command in the future that helps you with calculating the right

Creates the Lithophane geometry in the shape of a box with the image on top of it. You have to select the LithophaneImage in the TreeView before executing the command.

The name of the resulting mesh is hardcoded to "Image" right now. See https://github.com/furti/FreeCAD-Lithophane/issues/12
The name of the resulting mesh will be taken from the selected LithophaneImage. When the selected image is named `Windmill` the resulting mesh will be named `Windmill_Box`.

![Final Geometry](./Resources/Documentation/geometry_3dview.png)

Expand Down
4 changes: 2 additions & 2 deletions create_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def GetResources(self):
'Pixmap': iconPath('CreateBox.svg')}

def Activated(self):
lithophaneImage = lithophane_utils.findSelectedImage()
lithophaneImage, imageLabel = lithophane_utils.findSelectedImage()

if lithophaneImage is None:
qtutils.showInfo("No LithophaneImage selected", "Select exactly one LithophaneImage to continue")
Expand Down Expand Up @@ -164,7 +164,7 @@ def Activated(self):
timers[-1].stop()

timers.append(Timer('Recomputing View (7/7)'))
Mesh.show(imageMesh, 'Image')
Mesh.show(imageMesh, imageLabel + '_Box')
lithophane_utils.recomputeView()
timers[-1].stop()

Expand Down
10 changes: 6 additions & 4 deletions lithophane_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import division

import math
import math, os
import FreeCAD, FreeCADGui
from pivy import coin

Expand Down Expand Up @@ -273,15 +273,17 @@ def __setstate__(self,state):


def createImage(imagePath):
a=FreeCAD.ActiveDocument.addObject("App::FeaturePython","LithophaneImage")
fileName = os.path.split(imagePath)[1]
imageName = os.path.splitext(fileName)[0]

a=FreeCAD.ActiveDocument.addObject("App::FeaturePython", imageName)
image = LithophaneImage(a, imagePath)
ViewProviderLithophaneImage(a.ViewObject)

return image

if __name__ == "__main__":
import os
imagePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), './testimages/medium.png')
imagePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'testimages', 'medium.png')

image = qtutils.readImage(imagePath)

Expand Down
4 changes: 2 additions & 2 deletions lithophane_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def findSelectedImage():
#if not isinstance(selectedObject.Proxy, LithophaneImage):
# return None

return selection[0].Proxy
return (selection[0].Proxy, selection[0].Label)

def findSelectedMesh():
selection = FreeCADGui.Selection.getSelection()
Expand All @@ -34,7 +34,7 @@ def findSelectedMesh():
if not hasattr(selectedObject, 'Mesh'):
return None

return selection[0].Mesh
return selection[0].Mesh, selection[0].Label

def vectorAtGround(vector):
return FreeCAD.Vector(vector.x, vector.y, 0)
Expand Down
4 changes: 2 additions & 2 deletions make_solid.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def GetResources(self):
'Pixmap': iconPath('MakeSolid.svg')}

def Activated(self):
mesh = lithophane_utils.findSelectedMesh()
mesh, meshLabel = lithophane_utils.findSelectedMesh()

if mesh is None:
qtutils.showInfo("No mesh selected", "Select exactly one mesh to continue")
Expand All @@ -105,7 +105,7 @@ def Activated(self):
timers[-1].stop()

timers.append(Timer('Recomputing View (5/5)'))
Part.show(shell, 'Image Solid')
Part.show(shell, meshLabel + '_Solid')
lithophane_utils.recomputeView()
timers[-1].stop()

Expand Down
2 changes: 1 addition & 1 deletion measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def GetResources(self):
'Pixmap': iconPath('Measure.svg')}

def Activated(self):
mesh = lithophane_utils.findSelectedMesh()
mesh = lithophane_utils.findSelectedMesh()[0]

if mesh is None:
qtutils.showInfo("No Mesh selected", "Select exactly one Mesh to continue")
Expand Down
4 changes: 2 additions & 2 deletions show_pointcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def GetResources(self):
'Pixmap': iconPath('ShowPointcloud.svg')}

def Activated(self):
lithophaneImage = lithophane_utils.findSelectedImage()
lithophaneImage, imageLabel = lithophane_utils.findSelectedImage()

if lithophaneImage is None:
qtutils.showInfo("No LithophaneImage selected", "Select exactly one LithophaneImage to continue")

return

showPointCloud(lithophaneImage.lines, 'ImagePointCloud')
showPointCloud(lithophaneImage.lines, imageLabel + '_PointCloud')

lithophane_utils.recomputeView()

Expand Down

0 comments on commit d40541c

Please sign in to comment.