add OCC defeaturing to PartWB Gui

This commit is contained in:
tomate44
2018-07-03 13:47:31 +02:00
committed by wmayer
parent 1f63d6a103
commit d5db3ff588
4 changed files with 352 additions and 0 deletions

View File

@@ -26,6 +26,7 @@
# include <QDir>
# include <QFileInfo>
# include <QLineEdit>
# include <QTextStream>
# include <QInputDialog>
# include <Standard_math.hxx>
#endif
@@ -39,6 +40,7 @@
#include <Gui/MainWindow.h>
#include <Gui/Selection.h>
#include <Gui/WaitCursor.h>
#include <Gui/SelectionFilter.h>
#include "../App/PartFeature.h"
#include "../App/TopoShape.h"
@@ -259,6 +261,99 @@ bool CmdPartRefineShape::isActive(void)
return Gui::Selection().countObjectsOfType(partid) > 0;
}
//===========================================================================
// Part_Defeaturing
//===========================================================================
DEF_STD_CMD_A(CmdPartDefeaturing);
CmdPartDefeaturing::CmdPartDefeaturing()
: Command("Part_Defeaturing")
{
sAppModule = "Part";
sGroup = QT_TR_NOOP("Part");
sMenuText = QT_TR_NOOP("Defeaturing");
sToolTipText = QT_TR_NOOP("Remove feature from a shape");
sWhatsThis = "Part_Defeaturing";
sStatusTip = sToolTipText;
sPixmap = "Part_Defeaturing";
}
void CmdPartDefeaturing::activated(int iMsg)
{
Q_UNUSED(iMsg);
Gui::WaitCursor wc;
Base::Type partid = Base::Type::fromName("Part::Feature");
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx(0, partid);
openCommand("Defeaturing");
for (std::vector<Gui::SelectionObject>::iterator it = objs.begin(); it != objs.end(); ++it) {
try {
std::string shape;
shape.append("sh=App.");
shape.append(it->getDocName());
shape.append(".");
shape.append(it->getFeatName());
shape.append(".Shape\n");
std::string faces;
std::vector<std::string> subnames = it->getSubNames();
for (std::vector<std::string>::iterator sub = subnames.begin(); sub != subnames.end(); ++sub) {
faces.append("sh.");
faces.append(*sub);
faces.append(",");
}
doCommand(Doc,"\nsh = App.getDocument('%s').%s.Shape\n"
"nsh = sh.defeaturing([%s])\n"
"if not sh.isPartner(nsh):\n"
"\t\tdefeat = App.ActiveDocument.addObject('Part::Feature','Defeatured').Shape = nsh\n"
"\t\tGui.ActiveDocument.%s.hide()\n"
"else:\n"
"\t\tFreeCAD.Console.PrintError('Defeaturing failed\\n')",
it->getDocName(),
it->getFeatName(),
faces.c_str(),
it->getFeatName());
}
catch (const Base::Exception& e) {
Base::Console().Warning("%s: %s\n", it->getFeatName(), e.what());
}
}
commitCommand();
updateActive();
}
bool CmdPartDefeaturing::isActive(void)
{
Base::Type partid = Base::Type::fromName("Part::Feature");
std::vector<Gui::SelectionObject> objs = Gui::Selection().getSelectionEx(0, partid);
for (std::vector<Gui::SelectionObject>::iterator it = objs.begin(); it != objs.end(); ++it) {
std::vector<std::string> subnames = it->getSubNames();
for (std::vector<std::string>::iterator sub = subnames.begin(); sub != subnames.end(); ++sub) {
if (sub->substr(0,4) == "Face") {
#if OCC_VERSION_HEX < 0x070300
return true;
#else
return false;
#endif
}
}
}
return false;
}
// {
// if (getActiveGuiDocument())
// #if OCC_VERSION_HEX < 0x060900
// return false;
// #else
// return true;
// #endif
// else
// return false;
// }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void CreateSimplePartCommands(void)
@@ -268,4 +363,5 @@ void CreateSimplePartCommands(void)
rcCmdMgr.addCommand(new CmdPartShapeFromMesh());
rcCmdMgr.addCommand(new CmdPartSimpleCopy());
rcCmdMgr.addCommand(new CmdPartRefineShape());
rcCmdMgr.addCommand(new CmdPartDefeaturing());
}

View File

@@ -41,6 +41,7 @@
<file>icons/preferences-part_design.svg</file>
<file>icons/Tree_Part.svg</file>
<file>icons/Part_CheckGeometry.svg</file>
<file>icons/Part_Defeaturing.svg</file>
<file>icons/Part_Ellipse_Parametric.svg</file>
<file>icons/Part_Helix_Parametric.svg</file>
<file>icons/Part_Spiral_Parametric.svg</file>

View File

@@ -0,0 +1,253 @@
<?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="64px"
height="64px"
id="svg2980"
sodipodi:version="0.32"
inkscape:version="0.92.3 (2405546, 2018-03-11)"
sodipodi:docname="Part_Defeaturing.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1">
<defs
id="defs2982">
<linearGradient
inkscape:collect="always"
id="linearGradient3794">
<stop
style="stop-color:#000000;stop-opacity:1;"
offset="0"
id="stop3796" />
<stop
style="stop-color:#000000;stop-opacity:0;"
offset="1"
id="stop3798" />
</linearGradient>
<linearGradient
id="linearGradient3864">
<stop
id="stop3866"
offset="0"
style="stop-color:#71b2f8;stop-opacity:1;" />
<stop
id="stop3868"
offset="1"
style="stop-color:#002795;stop-opacity:1;" />
</linearGradient>
<inkscape:perspective
sodipodi:type="inkscape:persp3d"
inkscape:vp_x="0 : 32 : 1"
inkscape:vp_y="0 : 1000 : 0"
inkscape:vp_z="64 : 32 : 1"
inkscape:persp3d-origin="32 : 21.333333 : 1"
id="perspective2988" />
<linearGradient
gradientTransform="translate(0,-4)"
inkscape:collect="always"
xlink:href="#linearGradient3767"
id="linearGradient3773"
x1="22.116516"
y1="55.717518"
x2="17.328547"
y2="21.31134"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
id="linearGradient3767">
<stop
style="stop-color:#3465a4;stop-opacity:1"
offset="0"
id="stop3769" />
<stop
style="stop-color:#729fcf;stop-opacity:1"
offset="1"
id="stop3771" />
</linearGradient>
<linearGradient
gradientTransform="translate(0,-4)"
inkscape:collect="always"
xlink:href="#linearGradient3777"
id="linearGradient3783"
x1="53.896763"
y1="51.179787"
x2="47.502235"
y2="21.83742"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
id="linearGradient3777">
<stop
style="stop-color:#204a87;stop-opacity:1"
offset="0"
id="stop3779" />
<stop
style="stop-color:#3465a4;stop-opacity:1"
offset="1"
id="stop3781" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3794"
id="radialGradient3800"
cx="1"
cy="45"
fx="1"
fy="45"
r="41"
gradientTransform="matrix(0.93348213,-2.2905276e-8,0,0.28687573,0.06651751,32.090592)"
gradientUnits="userSpaceOnUse" />
<filter
inkscape:collect="always"
style="color-interpolation-filters:sRGB"
id="filter4897"
x="-0.045917604"
width="1.0918352"
y="-0.050280244"
height="1.1005605">
<feGaussianBlur
inkscape:collect="always"
stdDeviation="0.90909257"
id="feGaussianBlur4899" />
</filter>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="3.4052734"
inkscape:cx="-7.4791701"
inkscape:cy="-52.789184"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="3840"
inkscape:window-height="2063"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:snap-bbox="true"
inkscape:snap-nodes="false"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid2991"
empspacing="2"
visible="true"
enabled="true"
snapvisiblegridlinesonly="true" />
</sodipodi:namedview>
<metadata
id="metadata2985">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:creator>
<cc:Agent>
<dc:title>[triplus]</dc:title>
</cc:Agent>
</dc:creator>
<dc:title></dc:title>
<dc:date>2016-02-26</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/Part/Gui/Resources/icons/PartWorkbench.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;opacity:0.7">
<ellipse
style="fill:url(#radialGradient3800);fill-opacity:1;stroke:none"
id="path3024"
transform="matrix(0.73170732,0,0,0.80769231,31.268293,15.153846)"
cx="1"
cy="45"
rx="41"
ry="13" />
<path
style="fill:#729fcf;stroke:#0b1521;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1"
d="M 3,13 37,19 61,11 31,7 Z"
id="path2993"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:url(#linearGradient3783);fill-opacity:1;stroke:#0b1521;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-opacity:1"
d="M 61,11 V 47 L 37,57 V 19 Z"
id="path2995"
inkscape:connector-curvature="0" />
<path
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc"
id="path3825"
d="m 3,13 34,6 V 57 L 3,51 Z"
style="display:inline;overflow:visible;visibility:visible;fill:url(#linearGradient3773);fill-opacity:1;fill-rule:evenodd;stroke:#0b1521;stroke-width:2;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1;marker:none;enable-background:accumulate" />
<path
style="fill:none;stroke:#729fcf;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 5,15.42772 0.00867,33.919116 30.008671,5.268799 -0.0087,-33.933614 z"
id="path3765"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
style="fill:none;stroke:#3465a4;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 39.01243,20.433833 -0.01226,33.535301 20.001105,-8.300993 3.6e-4,-31.867363 z"
id="path3775"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
</g>
<g
inkscape:groupmode="layer"
id="layer2"
inkscape:label="Layer 2">
<path
sodipodi:nodetypes="cccccccc"
inkscape:connector-curvature="0"
id="path4645"
d="m 33.938382,54.968942 3.811752,5.132361 C 63.687198,48.508689 57.912776,11.463609 22.281971,26.588764 L 22.716269,16.708074 6.2739087,33.016699 28.639153,41.431467 24.468924,33.4329 c 25.262449,-12.441655 31.688854,9.191766 9.469458,21.536042 z"
style="fill:none;stroke:#ffffff;stroke-width:4.91338583;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;opacity:0.8;filter:url(#filter4897)" />
<path
style="fill:#ff0000;stroke:none;stroke-width:1.44778562;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 33.938382,54.968942 3.811752,5.132361 C 63.687198,48.508689 57.912776,11.463609 22.281971,26.588764 L 22.716269,16.708074 6.2739087,33.016699 28.639153,41.431467 24.468924,33.4329 c 25.262449,-12.441655 31.688854,9.191766 9.469458,21.536042 z"
id="path3734"
inkscape:connector-curvature="0"
sodipodi:nodetypes="cccccccc" />
<path
sodipodi:nodetypes="cccccccc"
inkscape:connector-curvature="0"
id="path4851"
d="m 33.938382,54.968942 3.811752,5.132361 C 63.687198,48.508689 57.912776,11.463609 22.281971,26.588764 L 22.716269,16.708074 6.2739087,33.016699 28.639153,41.431467 24.468924,33.4329 c 25.262449,-12.441655 31.688854,9.191766 9.469458,21.536042 z"
style="fill:none;stroke:#000000;stroke-width:1.88976378;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@@ -106,6 +106,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Part_SimpleCopy"
<< "Part_RefineShape"
<< "Part_CheckGeometry"
<< "Part_Defeaturing"
<< "Separator"
<< bop << join << split << compound
<< "Separator"
@@ -188,6 +189,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
<< "Part_CompJoinFeatures"
<< "Part_CompSplitFeatures"
<< "Part_CheckGeometry"
<< "Part_Defeaturing"
<< "Part_Section"
<< "Part_CrossSections";