Skip to content

Commit

Permalink
Merge v0.50.7 #462 from development
Browse files Browse the repository at this point in the history
v0.50.7
  • Loading branch information
Zolko-123 authored Jan 31, 2024
2 parents e650110 + ba381d2 commit dbda6f5
Show file tree
Hide file tree
Showing 12 changed files with 604 additions and 337 deletions.
24 changes: 14 additions & 10 deletions Asm4_Measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,33 +560,37 @@ def addSelection(self, document, obj, element, position):
subShape = selEx[0].SubObjects[0]
# we have selected an LCS, this needs special treatment
if selObj.TypeId == 'PartDesign::CoordinateSystem':
globalPlacement = App.Placement()
'''
# get the selection hierarchy
( obj, tree ) = Asm4.getSelectionTree()
# double-check, should always be true
if selObj == obj:
# first object is always in the current document
doc = App.ActiveDocument
globalPlacement = App.Placement()
# we parse the tree and cumulate the Placements
for objName in tree:
obj = doc.getObject(objName)
# Groups don't have Placement properties, ignore
if hasattr(obj,'Placement'):
globalPlacement *= obj.Placement
# check whether *this* object is a link to an *external* doc
# if *this* object is a link to an *external* document, switch to that document
# necessary because links can be in the *current* document also
if obj.isDerivedFrom('App::Link') and obj.LinkedObject.Document != App.ActiveDocument:
doc = obj.LinkedObject.Document
# else, keep the same document
else:
pass
# create a point at the origin of the LCS
base = globalPlacement.Base
PtS = self.drawPoint( App.Vector(base.x,base.y,base.z) )
subShape = PtS.Shape
# something went wrong, shouldn't have happened
else:
subShape = None
FCC.PrintMessage('subShape = None\n')
'''
# from https://forum.freecad.org/viewtopic.php?p=569083#p569083
# retType=3 returns the placement. Check the doc string for more info
# simplyfied version for single selection
path = selEx[0].SubElementNames[0]
globalPlacement = selEx[0].Object.getSubObject(path, retType=3)
# create a point at the origin of the LCS
base = globalPlacement.Base
PtS = self.drawPoint( App.Vector(base.x,base.y,base.z) )
subShape = PtS.Shape
# if valid selection
if subShape.isValid() and ('Face' in str(subShape) or 'Edge' in str(subShape) or 'Vertex' in str(subShape)):
# clear the result area
Expand Down
6 changes: 4 additions & 2 deletions Asm4_libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,10 @@ def getSelectionTree(index=0):
retval = ( selObj, None )
# objects at the document root don't have a selection tree
if len(Gui.Selection.getSelectionEx("", 0)[0].SubElementNames) >= index:
# we only treat thefirst selected object
# we only treat the first selected object
# TODO : are we sure about that ? Shouldn't this be [index] ?
# this is a dot-separated list of the selection hierarchy
# selList = Gui.Selection.getSelectionEx("", 0)[index].SubElementNames[0]
selList = Gui.Selection.getSelectionEx("", 0)[0].SubElementNames[index]
# this is the final tree table
# this first element will be overwritten later
Expand All @@ -304,7 +306,7 @@ def getSelectionTree(index=0):
topObj = App.ActiveDocument.getObject(selTree[1])
rootObj = topObj.getParentGeoFeatureGroup()
selTree[0] = rootObj.Name
# all went well, we return the selected object and it's tree
# all went well, we return the selected object and its tree
retval = ( selObj, selTree )
return retval

Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Release notes

* 2024.01.31 (**0.50.7**) :
Merged BoM and PartInfo code from JonasThomas (still doesn't seem to work !)
Simplyfied globalPlacement for LCS in Asm4_Measure
Removed "Donate" button (recieved 55€ altogether, a BIG thank-you to all the donors, but it's not worth the trouble)
Show Origin planes for PartDesign Bodies, with colors

* 2023.12.05 (**0.50.6**) :
Fixed measurements with LCS

Expand Down
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# FreeCAD Assembly 4 workbench

Current version 0.50.6
Current version 0.50.7


## Overview
Expand Down Expand Up @@ -63,9 +63,4 @@ Release notes can be found in the [CHANGELOG.md](CHANGELOG.md) file.
## License
LGPLv2.1 (see [LICENSE](LICENSE))

## Donate
Here some links if you wish to contribute financially :

[![PayPal Donate](Resources/media/PayPal_Donate.svg)](https://www.paypal.com/donate/?hosted_button_id=P9V4M2SBXX9HQ)


2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Assembly 4 Workbench for FreeCAD
v0.50.6
v0.50.7
166 changes: 134 additions & 32 deletions infoKeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,142 @@
#
# LGPL

import os, json
# The intent to infoKeys.py is to allow for allow for user customization but also a basic core functionality so #that minimum part list can be extracted in part theory partInfoUser and InfoToolTup user could be blank and it #should till work.



import os, json
import Asm4_libs as Asm4
import FreeCAD as App
# import infoPartCmd

partInfo = [
'Document',
'PartName',
'Reference',
'PartLength',
'PartWidth',
'PartVolume']

infoToolTip = {
'Document': 'Document or File name',
'PartName': 'Part Name',
'Reference': 'Part Reference',
'PartLength': 'Cut length of the raw material',
'PartWidth': 'Width of the raw material',
'PartVolume': 'Object dimensions (x, y, z)'}

partInfo_Invisible = [
'FastenerDiameter',
'FastenerLenght',
'FastenerType']

infoToolTip_Invisible = {
'FastenerDiameter': 'Fastener diameter',
'FastenerLenght': 'Fastener length',
'FastenerType': 'Fastener type'}

ConfUserDir = os.path.join(App.getUserAppDataDir(),'Templates')
ConfUserFilename = "Asm4_infoPartConf.json"
ConfUserFilejson = os.path.join(ConfUserDir, ConfUserFilename)


#UserAdded fields and routines should be defined this is file.
# if you make modifications to this, you'll want to delete the Json file
# Then you'll need to go into the gui and



partInfoUserAdded = [
'FileName']
''' Implement this later
'DrawnBy',
'DrawnDate',
'CheckedBy',
'CheckDate']
'''

infoToolTipUserAdded ={
'FileName': 'File Name'}
'''
'DrawnBy': 'Drawn By',
'DrawnDate': 'Drawn Date',
'CheckedBy': ' Checked By',
'CheckDate': 'Check Date'}
'''



#infoPartCmd has base values that get used if this function fails
def AssignCustomerValuesIntoUserFieldsForPartWithSingleBody(part, doc, singleBodyOfPart):
#Different people have different use cases
#basic functionality should work if an exception is thrown.
#JT I made some very specfic customizations for my work flow which work for me.
#

if '/home/jonasthomas' in doc.FileName:
#
jtCustomizations(part, doc, singleBodyOfPart)

else:

#The parts list will still generate from functions within infopartcmd
raise NotImplementedError("Function not implemented yet")



def jtCustomizations(part, doc, singleBodyOfPart):
# People are going to want to have there own customization and may not want to share
# I don't have a problem sharing my system, but it may not be for everyone.
# If this code makes it into zolko's repo and you want to modify this, please reach out to me,
# otherwise feel free to made your own function either in this file, if you want to share or..
# point to another file that's not in th e ASM4 repo and exclude it from git.

# Basic explanation of my file numbering system
# Q-003-S_0-01.FCStd
# Everything up to the first _ is the base partIDa
# If a .FCstd contains more than one part It is appended with a :1
# After the _ is the revision
# Within the base part ID there is a project id in this instance Q
# and incremental counter (TODO need to automated that eventually)
# Also a sub classication. Currently done manually
# C is file with multiple parts
# S is a sub assembly
# A is the major assembly in the sub folder
file_name = os.path.basename(doc.FileName)
elements = file_name.split('_')
print (file_name)
if len(elements) == 1:
base_part_id = elements[0].split('.')[0]
revision = 'None'
else:
base_part_id, revision_with_extension = elements
revision = revision_with_extension.split('.')[0]
part.FileName = file_name
part.DrawingName = base_part_id
part.DrawingRevision = revision

print("Base Part ID:", base_part_id)
print("Revision:", revision)

# Todo in my business rules base_part_id should be the PartID unless there are multiple parts in the drawing.
# in that case the base_part_id should be prepended by a :1 :2 .etc
# As some point I'll build the logic to assign validate that those numbers match the object At this point I through an exception if the actual numbering looks weird
# and throw an exception so the part number can be fixed.
# note the part number in the base object not the assembly is the one that is used.
#
# Check if base_part_id is a substring of part.Label
partIdtoAdd ="JT business rule violation"

if part.Type == 'Assembly':
partIdtoAdd = base_part_id
# leave part Label alone that contains the assembly name.
part.PartDescription = part.Label
else:

if base_part_id == part.Label:
# this can happen where there is only one part in a file
partIdtoAdd = part.Label
else:
if not(base_part_id in part.Label):
print (f'base_part_id={base_part_id}')
print (f'part.Label = {part.Label}')
message =f"PartID:{part.Label}\n is supposed to contain \n {base_part_id} Please fix the part number."
print (message)
Asm4.warningBox(message)
else:
if not(':' in part.Label):
message= f"If PartID:{part.Label} is not = { base_part_id} is should contain a : separator /nPlease fix the part number in the root folder for that part./n(JT Business rules"
print (message)
Asm4.warningBox(message)
else:
# Subtract base_part_id and '.' from part.Label and check if the result is an unsigned integer
remaining_part = part.Label.replace(base_part_id + ":", "")
if not remaining_part.isdigit():
message =f"The remaining part of part.Label is not an unsigned integer. Please fix the part number in the root folder for that part."
print (message)
Asm4.warningBox(message)
else:
#if we code to here JT business rules on the part number where followed
partIdtoAdd = part.Label

# todo need to deal with the situation where we have more than one part in a table.
if singleBodyOfPart is not None:
part.PartDescription = singleBodyOfPart.Label
else:
part.PartDescription ="Multi Body Part(Not implemented)"
part.PartID = partIdtoAdd




'''
Expand Down
Loading

0 comments on commit dbda6f5

Please sign in to comment.