PartGui: add 2D Offset feature creation command

(made offset toolbar button into a dropdown button)

Icon for 2D offset was copied from Draft workbench.
This commit is contained in:
DeepSOIC 2016-09-02 00:52:41 +03:00 committed by wmayer
parent e3ca28baa8
commit c5f642e44a
4 changed files with 283 additions and 4 deletions

View File

@ -1474,8 +1474,8 @@ CmdPartOffset::CmdPartOffset()
{
sAppModule = "Part";
sGroup = QT_TR_NOOP("Part");
sMenuText = QT_TR_NOOP("Offset...");
sToolTipText = QT_TR_NOOP("Utility to offset");
sMenuText = QT_TR_NOOP("3D Offset...");
sToolTipText = QT_TR_NOOP("Part_Offset: Utility to offset in 3D");
sWhatsThis = "Part_Offset";
sStatusTip = sToolTipText;
sPixmap = "Part_Offset";
@ -1510,6 +1510,147 @@ bool CmdPartOffset::isActive(void)
return (objectsSelected && !Gui::Control().activeDialog());
}
//===========================================================================
// Part_Offset2D
//===========================================================================
DEF_STD_CMD_A(CmdPartOffset2D);
CmdPartOffset2D::CmdPartOffset2D()
: Command("Part_Offset2D")
{
sAppModule = "Part";
sGroup = QT_TR_NOOP("Part");
sMenuText = QT_TR_NOOP("2D Offset...");
sToolTipText = QT_TR_NOOP("Part_Offset2D: Utility to offset planar shapes");
sWhatsThis = "Part_Offset2D";
sStatusTip = sToolTipText;
sPixmap = "Part_Offset2D";
}
void CmdPartOffset2D::activated(int iMsg)
{
App::DocumentObject* shape = getSelection().getObjectsOfType(Part::Feature::getClassTypeId()).front();
std::string offset = getUniqueObjectName("Offset2D");
openCommand("Make 2D Offset");
doCommand(Doc,"App.ActiveDocument.addObject(\"Part::Offset2D\",\"%s\")",offset.c_str());
doCommand(Doc,"App.ActiveDocument.%s.Source = App.ActiveDocument.%s" ,offset.c_str(), shape->getNameInDocument());
doCommand(Doc,"App.ActiveDocument.%s.Value = 1.0",offset.c_str());
updateActive();
//if (isActiveObjectValid())
// doCommand(Gui,"Gui.ActiveDocument.hide(\"%s\")",shape->getNameInDocument());
doCommand(Gui,"Gui.ActiveDocument.setEdit('%s')",offset.c_str());
//commitCommand();
adjustCameraPosition();
copyVisual(offset.c_str(), "ShapeColor", shape->getNameInDocument());
copyVisual(offset.c_str(), "LineColor" , shape->getNameInDocument());
copyVisual(offset.c_str(), "PointColor", shape->getNameInDocument());
}
bool CmdPartOffset2D::isActive(void)
{
Base::Type partid = Base::Type::fromName("Part::Feature");
bool objectsSelected = Gui::Selection().countObjectsOfType(partid) == 1;
return (objectsSelected && !Gui::Control().activeDialog());
}
//===========================================================================
// Part_CompOffset (dropdown toolbar button for Offset features)
//===========================================================================
DEF_STD_CMD_ACL(CmdPartCompOffset);
CmdPartCompOffset::CmdPartCompOffset()
: Command("Part_CompOffset")
{
sAppModule = "Part";
sGroup = QT_TR_NOOP("Part");
sMenuText = QT_TR_NOOP("Offset:");
sToolTipText = QT_TR_NOOP("Tools to offset shapes (construct parallel shapes)");
sWhatsThis = "Part_CompOffset";
sStatusTip = sToolTipText;
}
void CmdPartCompOffset::activated(int iMsg)
{
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
if (iMsg==0)
rcCmdMgr.runCommandByName("Part_Offset");
else if (iMsg==1)
rcCmdMgr.runCommandByName("Part_Offset2D");
else
return;
// Since the default icon is reset when enabing/disabling the command we have
// to explicitly set the icon of the used command.
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
QList<QAction*> a = pcAction->actions();
assert(iMsg < a.size());
pcAction->setIcon(a[iMsg]->icon());
}
Gui::Action * CmdPartCompOffset::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
applyCommandData(this->className(), pcAction);
QAction* cmd0 = pcAction->addAction(QString());
cmd0->setIcon(Gui::BitmapFactory().pixmap("Part_Offset"));
QAction* cmd1 = pcAction->addAction(QString());
cmd1->setIcon(Gui::BitmapFactory().pixmap("Part_Offset2D"));
_pcAction = pcAction;
languageChange();
pcAction->setIcon(cmd0->icon());
int defaultId = 0;
pcAction->setProperty("defaultAction", QVariant(defaultId));
return pcAction;
}
void CmdPartCompOffset::languageChange()
{
Command::languageChange();
if (!_pcAction)
return;
Gui::CommandManager &rcCmdMgr = Gui::Application::Instance->commandManager();
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
QList<QAction*> a = pcAction->actions();
Gui::Command* cmdOffset = rcCmdMgr.getCommandByName("Part_Offset");
if (cmdOffset) {
QAction* cmd0 = a[0];
cmd0->setText(QApplication::translate("Part_Offset", cmdOffset->getMenuText()));
cmd0->setToolTip(QApplication::translate("Part_Offset", cmdOffset->getToolTipText()));
cmd0->setStatusTip(QApplication::translate("Part_Offset", cmdOffset->getStatusTip()));
}
Gui::Command* cmdOffset2D = rcCmdMgr.getCommandByName("Part_Offset2D");
if (cmdOffset2D) {
QAction* cmd1 = a[1];
cmd1->setText(QApplication::translate("Part_Offset", cmdOffset2D->getMenuText()));
cmd1->setToolTip(QApplication::translate("Part_Offset", cmdOffset2D->getToolTipText()));
cmd1->setStatusTip(QApplication::translate("Part_Offset", cmdOffset2D->getStatusTip()));
}
}
bool CmdPartCompOffset::isActive(void)
{
Base::Type partid = Base::Type::fromName("Part::Feature");
bool objectsSelected = Gui::Selection().countObjectsOfType(partid) == 1;
return (objectsSelected && !Gui::Control().activeDialog());
}
//===========================================================================
// Part_Thickness
//===========================================================================
@ -2076,6 +2217,8 @@ void CreatePartCommands(void)
rcCmdMgr.addCommand(new CmdPartLoft());
rcCmdMgr.addCommand(new CmdPartSweep());
rcCmdMgr.addCommand(new CmdPartOffset());
rcCmdMgr.addCommand(new CmdPartOffset2D());
rcCmdMgr.addCommand(new CmdPartCompOffset());
rcCmdMgr.addCommand(new CmdPartThickness());
rcCmdMgr.addCommand(new CmdCheckGeometry());
rcCmdMgr.addCommand(new CmdColorPerFace());

View File

@ -23,6 +23,7 @@
<file>icons/Part_Mirror.svg</file>
<file>icons/Part_MirrorPNG.png</file>
<file>icons/Part_Offset.svg</file>
<file>icons/Part_Offset2D.svg</file>
<file>icons/Part_Revolve.svg</file>
<file>icons/Part_RuledSurface.svg</file>
<file>icons/Part_Section.svg</file>

View File

@ -0,0 +1,135 @@
<?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="svg3136"
sodipodi:version="0.32"
inkscape:version="0.48.2 r9819"
sodipodi:docname="Draft_Offset.not.svg.zip"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1">
<defs
id="defs3138">
<linearGradient
id="linearGradient3841">
<stop
style="stop-color:#0619c0;stop-opacity:1;"
offset="0"
id="stop3843" />
<stop
style="stop-color:#379cfb;stop-opacity:1;"
offset="1"
id="stop3845" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3841"
id="linearGradient4235"
x1="8"
y1="31.75"
x2="52"
y2="31.75"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3841"
id="linearGradient4243"
x1="19.25"
y1="31.75"
x2="37"
y2="31.75"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#linearGradient3841"
id="linearGradient4246"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.1390891,0,0,0.1390891,-116.65366,-325.33528)"
x1="844.9165"
y1="2560.25"
x2="1270.7085"
y2="2560.25" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8284271"
inkscape:cx="27.631036"
inkscape:cy="28.001052"
inkscape:current-layer="layer1"
showgrid="false"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1280"
inkscape:window-height="941"
inkscape:window-x="0"
inkscape:window-y="30"
showguides="true"
inkscape:guide-bbox="true"
inkscape:window-maximized="1">
<inkscape:grid
type="xygrid"
id="grid4167" />
</sodipodi:namedview>
<metadata
id="metadata3141">
<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>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
id="path4210"
style="opacity:0.6;fill:none;stroke:#000000;stroke-width:7;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 31,43 c 4.14214,0 7.5,-3.357865 7.5,-7.5 l 0,-10 -12.5,0 -6.25,6.25 M 8.5,20.500001 18.5,10.5 l 35,0 0,25 C 53.5,47.926406 43.426408,58 31,58"
inkscape:connector-curvature="0"
sodipodi:nodetypes="csccccccsc" />
<path
id="path4173"
style="color:#000000;fill:none;stroke:#000000;stroke-width:7;stroke-linecap:butt;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
d="m 7,18.000001 10,-10.0000012 35,0 L 52,33 C 52,45.426406 41.926408,55.5 29.5,55.5"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
id="path4198"
style="fill:none;stroke:#000000;stroke-width:7;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
d="m 29.5,40.5 c 4.14214,0 7.5,-3.357865 7.5,-7.5 l 0,-10 -12.5,0 -6.25,6.25"
inkscape:connector-curvature="0"
sodipodi:nodetypes="ccccc" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
d="m 29.5,40.5 c 4.14214,0 7.5,-3.357865 7.5,-7.5 l 0,-10 -12.5,0 -6.25,6.25"
style="fill:none;stroke:url(#linearGradient4243);stroke-width:4;stroke-linecap:square;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0"
id="path4217" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
d="m 7,18.000001 10,-10.0000012 35,0 L 52,33 C 52,45.426406 41.926408,55.5 29.5,55.5"
style="color:#000000;fill:none;stroke:url(#linearGradient4235);stroke-width:4;stroke-linecap:square;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path4219" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -86,7 +86,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Part_CrossSections" << "Part_Compound" << "Part_MakeFace" << "Part_Extrude"
<< "Part_Revolve" << "Part_Mirror" << "Part_Fillet" << "Part_Chamfer"
<< "Part_RuledSurface" << "Part_Loft" << "Part_Sweep"
<< "Part_Offset" << "Part_Thickness" << "Separator" << "Part_EditAttachment";
<< "Part_Offset" << "Part_Offset2D" << "Part_Thickness" << "Separator" << "Part_EditAttachment";
Gui::MenuItem* measure = new Gui::MenuItem;
root->insertItem(item,measure);
@ -122,7 +122,7 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
tool->setCommand("Part tools");
*tool << "Part_Extrude" << "Part_Revolve" << "Part_Mirror" << "Part_Fillet"
<< "Part_Chamfer" << "Part_RuledSurface" << "Part_Loft" << "Part_Sweep"
<< "Part_Offset" << "Part_Thickness";
<< "Part_CompOffset" << "Part_Thickness";
Gui::ToolBarItem* boolop = new Gui::ToolBarItem(root);
boolop->setCommand("Boolean");