asm4 parse feature

This commit is contained in:
IDONTSUDO 2023-03-03 19:02:46 +03:00
parent 6fcd2566b5
commit 3d3a063a5d
6 changed files with 474 additions and 143 deletions

2
.gitignore vendored
View file

@ -102,3 +102,5 @@ ENV/
# blender backup files
*.blend1
install_plugin_cad.sh
.vscode

View file

@ -13,6 +13,8 @@
# License along with this library. If not, see <http://www.gnu.org/licenses/>.
import FreeCAD
import Tools
from usecases.asm4parser_usecase import Asm4StructureParseUseCase
if FreeCAD.GuiUp:
import FreeCADGui
from pivy import coin
@ -309,7 +311,11 @@ Tools.spawnClassCommand("FrameCommand",
{"Pixmap": str(os.path.join(icondir, "frame.svg")),
"MenuText": "Make a free frame",
"ToolTip": "Make a freestanding reference frame."})
Tools.spawnClassCommand("ASM4StructureParsing",
Asm4StructureParseUseCase().initParse,
{"Pixmap": str(os.path.join(icondir, "assembly4.svg")),
"MenuText": "Make a ASM4 parsing",
"ToolTip": "Make a ASM4 1"})
Tools.spawnClassCommand("SelectedPartFrameCommand",
makeSelectedPartFrames,
{"Pixmap": str(os.path.join(icondir, "partframe.svg")),

View file

@ -37,6 +37,7 @@ class Frames(Workbench):
import Frames
self.framecommands = [
"FrameCommand",
"ASM4StructureParsing",
"SelectedPartFrameCommand",
"AllPartFramesCommand",
"FeatureFrameCommand"

View file

@ -0,0 +1,411 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="64"
height="64"
id="svg3559"
version="1.1"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="Model.svg"
viewBox="0 0 64 64">
<defs
id="defs3561">
<linearGradient
id="linearGradient4383-1"
inkscape:collect="always">
<stop
id="stop69725"
offset="0"
style="stop-color:#c4a000;stop-opacity:1" />
<stop
id="stop69727"
offset="1"
style="stop-color:#fce94f;stop-opacity:1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient4383">
<stop
style="stop-color:#3465a4;stop-opacity:1"
offset="0"
id="stop4385" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop4387" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4383-1"
id="linearGradient4389"
x1="20.243532"
y1="37.588112"
x2="17.243532"
y2="27.588112"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-1.243533,-2.588112)" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient73208"
id="linearGradient4399"
x1="48.714352"
y1="45.585785"
x2="44.714352"
y2="34.585785"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(1.2856487,1.4142136)" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4383-3"
id="linearGradient4389-0"
x1="27.243532"
y1="54.588112"
x2="21.243532"
y2="30.588112"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-1.243533,-2.588112)" />
<linearGradient
inkscape:collect="always"
id="linearGradient4383-3">
<stop
style="stop-color:#3465a4;stop-opacity:1"
offset="0"
id="stop4385-1" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop4387-2" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4393-9"
id="linearGradient4399-7"
x1="48.714352"
y1="45.585785"
x2="40.714352"
y2="24.585787"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(1.2856487,1.4142136)" />
<linearGradient
inkscape:collect="always"
id="linearGradient4393-9">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop4395-8" />
<stop
style="stop-color:#3465a4;stop-opacity:1"
offset="1"
id="stop4397-1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient73208"
id="linearGradient69042"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-12.714351,-17.585786)"
x1="48.714352"
y1="45.585785"
x2="44.714352"
y2="34.585785" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4383-1"
id="linearGradient69056"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(-1.243533,-2.588112)"
x1="27.243532"
y1="54.588112"
x2="22.243532"
y2="40.588112" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4383"
id="linearGradient69709"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(21.756467,-5.588112)"
x1="20.243532"
y1="37.588112"
x2="17.243532"
y2="27.588112" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient4383"
id="linearGradient69717"
gradientUnits="userSpaceOnUse"
gradientTransform="translate(1.2856487,1.4142136)"
x1="50.714352"
y1="25.585787"
x2="48.714352"
y2="20.585787" />
<linearGradient
inkscape:collect="always"
id="linearGradient73208">
<stop
style="stop-color:#c4a000;stop-opacity:1"
offset="0"
id="stop73210" />
<stop
style="stop-color:#edd400;stop-opacity:1"
offset="1"
id="stop73212" />
</linearGradient>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="10"
inkscape:cx="8.35"
inkscape:cy="27.079831"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="2160"
inkscape:window-height="1104"
inkscape:window-x="225"
inkscape:window-y="66"
inkscape:window-maximized="0"
inkscape:snap-global="true">
<inkscape:grid
type="xygrid"
id="grid3007"
empspacing="4"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true"
spacingx="0.5"
spacingy="0.5" />
</sodipodi:namedview>
<metadata
id="metadata3564">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
<dc:title>Path-Stock</dc:title>
<dc:date>2015-07-04</dc:date>
<dc:relation>http://www.freecadweb.org/wiki/index.php?title=Artwork</dc:relation>
<dc:publisher>
<cc:Agent>
<dc:title>FreeCAD</dc:title>
</cc:Agent>
</dc:publisher>
<dc:identifier>FreeCAD/src/Mod/Path/Gui/Resources/icons/Path-Stock.svg</dc:identifier>
<dc:rights>
<cc:Agent>
<dc:title>FreeCAD LGPL2+</dc:title>
</cc:Agent>
</dc:rights>
<cc:license>https://www.gnu.org/copyleft/lesser.html</cc:license>
<dc:contributor>
<cc:Agent>
<dc:title>[agryson] Alexander Gryson</dc:title>
</cc:Agent>
</dc:contributor>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer"
style="display:inline">
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69052"
d="m 9,35 0,-14 14,5 0,14 z"
style="fill:url(#linearGradient4389);fill-opacity:1.0;fill-rule:nonzero;stroke:#0b1521;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
style="fill:url(#linearGradient69056);fill-opacity:1.0;fill-rule:nonzero;stroke:#0b1521;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="M 9,49 9,35 37,45 37,59 Z"
id="path4381"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:url(#linearGradient4399);fill-opacity:1.0;fill-rule:nonzero;stroke:#0b1521;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="M 37,59 37,45 55,28 55,41 Z"
id="path4391"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:#fce94f;fill-opacity:1;fill-rule:nonzero;stroke:#0b1521;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="M 9,21 29,5 42,10 23,26 Z"
id="path4403"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 11.008035,47.60627 11,38 l 24,8 0.0081,10.184812 z"
id="path4381-7"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:none;stroke:#edd400;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 39.005041,54.16825 39,46 53,33 l 0.0021,7.176847 z"
id="path4391-0"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69038"
d="M 23,40 42,23 55,28 37,45 Z"
style="fill:#fce94f;fill-opacity:1;fill-rule:nonzero;stroke:#0b1521;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69040"
d="m 23,40 0,-14 8,-7 0,14 z"
style="fill:url(#linearGradient69042);fill-opacity:1.0;fill-rule:nonzero;stroke:#0b1521;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69044"
d="m 25,36 0,-9 4,-3.5 0,9 z"
style="fill:none;stroke:#edd400;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69048"
d="M 11.008,33.60627 11,24 l 10,3 0,10 z"
style="fill:none;stroke:#fce94f;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
style="fill:url(#linearGradient69709);fill-opacity:1.0;fill-rule:nonzero;stroke:#302b00;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none"
d="m 31,33 0,-14 13,5 0,14.5 z"
id="path69705"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 33,32 0,-10 9,3 0,10.5 z"
id="path69707"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69715"
d="M 44,38.5 44,24 55,15 55,28 Z"
style="fill:url(#linearGradient69717);fill-opacity:1.0;fill-rule:nonzero;stroke:#302b00;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69719"
d="m 46,34 0,-9 7,-6 0,8 z"
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path69721"
d="m 31,19 11,-9 13,5 -11,9 z"
style="fill:#729fcf;fill-opacity:1;fill-rule:nonzero;stroke:#302b00;stroke-width:2;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="temporal"
style="display:none;opacity:0.58800001"
sodipodi:insensitive="true">
<path
inkscape:connector-curvature="0"
id="path68967"
d="M 9,35 9,49"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
sodipodi:nodetypes="cc" />
<path
inkscape:connector-curvature="0"
id="path68971"
d="M 9,35 37,45"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
sodipodi:nodetypes="cc"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 55,28 0,13"
id="path68973"
inkscape:connector-curvature="0" />
<path
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 37,45 55,28"
id="path68977"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path68983"
d="M 23,40 23,26"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path68985"
d="m 29,5 13,5"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 23,26 42,10"
id="path68989"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 19,13 29,5"
id="path68993"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 55,15 -9,8"
id="path68997"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path69030"
d="M 42,23 42,10"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 42,23 14,5"
id="path69034"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path69036"
d="M 23,40 42,23"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
sodipodi:nodetypes="cc"
inkscape:connector-curvature="0"
id="path69711"
d="m 23,10 19,0"
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" />
<path
style="fill:#ef2929;fill-rule:evenodd;stroke:#ef2929;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 34,17 0,13"
id="path69713"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cc" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 15 KiB

View file

@ -1,142 +0,0 @@
import FreeCAD as App
import uuid
collision_squares_labels = []
meshCoordinates = []
detailSquares = {}
class ClearWorkSpaceDocument(object):
def call(self):
for key in detailSquares:
for renderPrimitive in detailSquares[key]:
primitivePart = App.ActiveDocument.getObjectsByLabel(renderPrimitive.cadLabel)[0]
App.ActiveDocument.removeObject(primitivePart.Name)
class MeshGeometryCoordinateModel(object):
def __init__(self, x, y, z, label,):
self.x = x
self.y = y
self.z = z
self.label = label
self.cadLabel = ''
def initializePrimitivesByCoordinate(self):
uuidDoc = str(uuid.uuid1())
App.ActiveDocument.addObject("Part::Box", "Box")
App.ActiveDocument.ActiveObject.Label = uuidDoc
App.ActiveDocument.recompute()
part = App.ActiveDocument.getObjectsByLabel(uuidDoc)[0]
collision_squares_labels.append(uuidDoc)
part.Width = 2
part.Height = 2
part.Length = 2
part.Placement = App.Placement(
App.Vector(self.x - 1, self.y - 1, self.z - 1),
App.Rotation(App.Vector(0.00, 0.00, 1.00), 0.00))
if(detailSquares.get(self.label) is None):
detailSquares[self.label] = []
detailSquares[self.label].append(self)
self.cadLabel = uuidDoc
App.ActiveDocument.recompute()
class FreeCadMetaModel(object):
def __init__(self, label, vertex) -> None:
self.label = label
self.vertex = vertex
class InitPartsParseUseCase():
def call(self) -> list[FreeCadMetaModel]:
product_details = []
for part in App.ActiveDocument.Objects:
if part is not None:
model = FreeCadMetaModel(part.Label,part.Shape.Vertexes)
if(model is not None):
product_details.append(model)
return product_details
class GetCollisionAtPrimitives(object):
def call(self,freeCadMetaModels: list[FreeCadMetaModel] ):
for model in freeCadMetaModels:
activePart = App.ActiveDocument.getObjectsByLabel(model.label)[0]
for key in detailSquares:
if(model.label != key):
for renderPrimitive in detailSquares[key]:
primitivePart = App.ActiveDocument.getObjectsByLabel(renderPrimitive.cadLabel)[0]
collisionResult:int = int(activePart.Shape.distToShape(primitivePart.Shape)[0])
# print(collisionResult)
if(collisionResult == 0):
print(model.label+ ' ' + renderPrimitive.label)
class GetPartPrimitiveCoordinatesUseCase(object):
def call(self,freeCadMetaModels: list[FreeCadMetaModel]) -> list[MeshGeometryCoordinateModel]:
meshCoordinates:list[MeshGeometryCoordinateModel] = []
for model in freeCadMetaModels:
vertexesDetail = model.vertex
labelDetail = model.label
for coords in vertexesDetail:
detailVertex = MeshGeometryCoordinateModel(
coords.X,
coords.Y,
coords.Z,
labelDetail,
)
meshCoordinates.append(detailVertex)
return meshCoordinates
class RenderPrimitiveUseCase(object):
def call(self,meshModels :list[MeshGeometryCoordinateModel]) -> None:
for mesh in meshModels:
mesh.initializePrimitivesByCoordinate()
class RenderPrimitivesScenario(object):
def __init__(
self,
initPartsParseUseCase: InitPartsParseUseCase,
getPartPrimitiveCoordinatesUseCase:GetPartPrimitiveCoordinatesUseCase,
renderPrimitiveUseCase:RenderPrimitiveUseCase,
getCollisionAtPrimitives:GetCollisionAtPrimitives,
clearWorkSpaceDocument:ClearWorkSpaceDocument,
) -> None:
self.initPartsParseUseCase = initPartsParseUseCase
self.getPartPrimitiveCoordinatesUseCase = getPartPrimitiveCoordinatesUseCase
self.renderPrimitiveUseCase = renderPrimitiveUseCase
self.getCollisionAtPrimitives = getCollisionAtPrimitives
self.clearWorkSpaceDocument = clearWorkSpaceDocument
def call(self) -> None:
parts = self.initPartsParseUseCase.call()
meshCoordinates = self.getPartPrimitiveCoordinatesUseCase.call(parts)
self.renderPrimitiveUseCase.call(meshCoordinates)
self.getCollisionAtPrimitives.call(parts)
self.clearWorkSpaceDocument.call()
def main() -> None:
RenderPrimitivesScenario(
InitPartsParseUseCase(),
GetPartPrimitiveCoordinatesUseCase(),
RenderPrimitiveUseCase(),
GetCollisionAtPrimitives(),
ClearWorkSpaceDocument(),
).call()
main()

View file

@ -0,0 +1,53 @@
import FreeCAD as App
class Asm4StructureParseUseCase:
_parts = []
_label = []
def getSubPartsLabel(self, group):
groupLabel = []
for el in group:
if str(el) == '<Part::PartFeature>':
groupLabel.append(el.Label)
return groupLabel
def parseLabel(self, nextGroup, label, level=2, nextGroupParse=0):
if nextGroup.__len__() == nextGroupParse:
return
else:
groupParts = []
for el in nextGroup:
if str(el) == '<App::Link object>':
groupParts.append(el)
for el in groupParts:
if str(el) == '<App::Link object>':
label.append({
"level": level,
"attachedTo": el.AttachedTo.split('#'),
"label": el.Label,
"axis": self.getSubPartsLabel(el.Group)
})
def initParse(self):
model = App.ActiveDocument.RootObjects[1]
self._label.append({
"level": 1,
"attachedTo": "Parent Assembly",
"label": model.Label,
"axis": self.getSubPartsLabel(model.Group)
})
for parent in model.Group:
if str(parent) == '<App::Link object>':
self._label.append({
"level": 1,
"attachedTo": parent.AttachedTo.split('#'),
"label": parent.Label,
"axis": self.getSubPartsLabel(parent.Group)
})
print(self._label)