Sketcher: UI Copy/Clone as a single dropdown toolbar icon

=========================================================

This commit provides with a single toolbar button to select between a copy and clone.

Copy just copies the constraints.
Clone modifies the dimensional constraints to geometric constraints, so that the constrained geometry follows the changes in the original object.
This commit is contained in:
Abdullah Tahiri 2015-08-15 08:05:36 +02:00 committed by wmayer
parent 97d551b551
commit 0e01764f0b
4 changed files with 484 additions and 28 deletions

View File

@ -26,6 +26,7 @@
# include <cfloat>
# include <QMessageBox>
# include <Precision.hxx>
# include <QApplication>
#endif
# include <QMessageBox>
@ -1339,23 +1340,16 @@ static const char *cursor_createcopy[]={
std::vector<AutoConstraint> sugConstr1;
};
DEF_STD_CMD_A(CmdSketcherCopy);
class SketcherCopy : public Gui::Command {
public:
SketcherCopy(const char* name);
void activate(bool clone);
};
CmdSketcherCopy::CmdSketcherCopy()
:Command("Sketcher_Copy")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("Copy");
sToolTipText = QT_TR_NOOP("Creates a copy of the geometry taking as reference the last selected point");
sWhatsThis = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "Sketcher_Copy";
sAccel = "CTRL+C";
eType = ForEdit;
}
SketcherCopy::SketcherCopy(const char* name): Command(name)
{}
void CmdSketcherCopy::activated(int iMsg)
void SketcherCopy::activate(bool clone)
{
// get the selection
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
@ -1437,9 +1431,9 @@ void CmdSketcherCopy::activated(int iMsg)
QObject::tr("A copy requires at least one selected non-external geometric element"));
return;
}
std::string geoIdList = stream.str();
// remove the last added comma and brackets to make the python list
int index = geoIdList.rfind(',');
geoIdList.resize(index);
@ -1452,16 +1446,14 @@ void CmdSketcherCopy::activated(int iMsg)
if( LastGeo->getTypeId() == Part::GeomCircle::getClassTypeId() ||
LastGeo->getTypeId() == Part::GeomEllipse::getClassTypeId() ) {
LastPointPos = Sketcher::mid;
}
else {
LastPointPos = Sketcher::start;
}
}
else {
LastPointPos = Sketcher::start;
}
}
bool clone=false;
// Ask the user if he wants to clone or to simple copy
int ret = QMessageBox::question(Gui::getMainWindow(), QObject::tr("Dimensional/Geometric constraints"),
/*int ret = QMessageBox::question(Gui::getMainWindow(), QObject::tr("Dimensional/Geometric constraints"),
QObject::tr("Do you want to clone the object, i.e. substitute dimensional constraints by geometric constraints?"),
QMessageBox::Yes, QMessageBox::No, QMessageBox::Cancel);
// use an equality constraint
@ -1471,17 +1463,169 @@ void CmdSketcherCopy::activated(int iMsg)
else if (ret == QMessageBox::Cancel) {
// do nothing
return;
}
}*/
ActivateAcceleratorHandler(getActiveGuiDocument(),new DrawSketchHandlerCopy(geoIdList, LastGeoId, LastPointPos, geoids, clone));
ActivateAcceleratorHandler(getActiveGuiDocument(),new DrawSketchHandlerCopy(geoIdList, LastGeoId, LastPointPos, geoids, clone));
}
class CmdSketcherCopy : public SketcherCopy
{
public:
CmdSketcherCopy();
virtual ~CmdSketcherCopy(){}
virtual const char* className() const
{ return "CmdSketcherCopy"; }
protected:
virtual void activated(int iMsg);
virtual bool isActive(void);
};
CmdSketcherCopy::CmdSketcherCopy()
:SketcherCopy("Sketcher_Copy")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("Copy");
sToolTipText = QT_TR_NOOP("Creates a simple copy of the geometry taking as reference the last selected point");
sWhatsThis = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "Sketcher_Copy";
sAccel = "";
eType = ForEdit;
}
void CmdSketcherCopy::activated(int iMsg)
{
activate(false);
}
bool CmdSketcherCopy::isActive(void)
{
return isSketcherAcceleratorActive( getActiveGuiDocument(), true );
}
class CmdSketcherClone : public SketcherCopy
{
public:
CmdSketcherClone();
virtual ~CmdSketcherClone(){}
virtual const char* className() const
{ return "CmdSketcherClone"; }
protected:
virtual void activated(int iMsg);
virtual bool isActive(void);
};
CmdSketcherClone::CmdSketcherClone()
:SketcherCopy("Sketcher_Clone")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("Clone");
sToolTipText = QT_TR_NOOP("Creates a clone of the geometry taking as reference the last selected point");
sWhatsThis = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "Sketcher_Clone";
sAccel = "";
eType = ForEdit;
}
void CmdSketcherClone::activated(int iMsg)
{
activate(true);
}
bool CmdSketcherClone::isActive(void)
{
return isSketcherAcceleratorActive( getActiveGuiDocument(), true );
}
DEF_STD_CMD_ACL(CmdSketcherCompCopy);
CmdSketcherCompCopy::CmdSketcherCompCopy()
: Command("Sketcher_CompCopy")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("Copy");
sToolTipText = QT_TR_NOOP("Creates a clone of the geometry taking as reference the last selected point");
sWhatsThis = "Sketcher_CompCopy";
sStatusTip = sToolTipText;
sAccel = "CTRL+C";
eType = ForEdit;
}
void CmdSketcherCompCopy::activated(int iMsg)
{
if (iMsg==0){
CmdSketcherClone sc;
sc.activate(true);
}
else if (iMsg==1) {
CmdSketcherCopy sc;
sc.activate(false);
}
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());
pcAction->setShortcut(QString::fromAscii("CTRL+C"));
}
Gui::Action * CmdSketcherCompCopy::createAction(void)
{
Gui::ActionGroup* pcAction = new Gui::ActionGroup(this, Gui::getMainWindow());
pcAction->setDropDownMenu(true);
applyCommandData(this->className(), pcAction);
QAction* clone = pcAction->addAction(QString());
clone->setIcon(Gui::BitmapFactory().pixmap("Sketcher_Clone"));
QAction* copy = pcAction->addAction(QString());
copy->setIcon(Gui::BitmapFactory().pixmap("Sketcher_Copy"));
_pcAction = pcAction;
languageChange();
pcAction->setIcon(clone->icon());
int defaultId = 0;
pcAction->setProperty("defaultAction", QVariant(defaultId));
pcAction->setShortcut(QString::fromAscii(sAccel));
return pcAction;
}
void CmdSketcherCompCopy::languageChange()
{
Command::languageChange();
if (!_pcAction)
return;
Gui::ActionGroup* pcAction = qobject_cast<Gui::ActionGroup*>(_pcAction);
QList<QAction*> a = pcAction->actions();
QAction* clone = a[0];
clone->setText(QApplication::translate("Sketcher_CompCopy","Clone"));
clone->setToolTip(QApplication::translate("Sketcher_Clone","Creates a clone of the geometry taking as reference the last selected point"));
clone->setStatusTip(QApplication::translate("Sketcher_Clone","Creates a clone of the geometry taking as reference the last selected point"));
QAction* copy = a[1];
copy->setText(QApplication::translate("Sketcher_CompCopy","Copy"));
copy->setToolTip(QApplication::translate("Sketcher_Copy","Creates a simple copy of the geometry taking as reference the last selected point"));
copy->setStatusTip(QApplication::translate("Sketcher_Copy","Creates a simple copy of the geometry taking as reference the last selected point"));
}
bool CmdSketcherCompCopy::isActive(void)
{
return isSketcherAcceleratorActive( getActiveGuiDocument(), true );
}
/* XPM */
static const char *cursor_createrectangulararray[]={
@ -1796,5 +1940,7 @@ void CreateSketcherCommandsConstraintAccel(void)
rcCmdMgr.addCommand(new CmdSketcherRestoreInternalAlignmentGeometry());
rcCmdMgr.addCommand(new CmdSketcherSymmetry());
rcCmdMgr.addCommand(new CmdSketcherCopy());
rcCmdMgr.addCommand(new CmdSketcherClone());
rcCmdMgr.addCommand(new CmdSketcherCompCopy());
rcCmdMgr.addCommand(new CmdSketcherRectangularArray());
}

View File

@ -40,6 +40,7 @@
<file>icons/Constraint_VerticalDistance_Driven.svg</file>
<file>icons/Sketcher_AlterConstruction.svg</file>
<file>icons/Sketcher_AlterFillet.svg</file>
<file>icons/Sketcher_Clone.svg</file>
<file>icons/Sketcher_CloseShape.svg</file>
<file>icons/Sketcher_Conics.svg</file>
<file>icons/Sketcher_Conics_Constr.svg</file>

View File

@ -0,0 +1,308 @@
<?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="svg2869"
sodipodi:version="0.32"
inkscape:version="0.91 r"
sodipodi:docname="Sketcher_Clone.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.1"
inkscape:export-filename="/home/user/Downloads/cad/mystuff/icons/sketcher/other_Abdullah/Sketcher_Copy_Element_1_22px.png"
inkscape:export-xdpi="30.9375"
inkscape:export-ydpi="30.9375">
<defs
id="defs2871">
<linearGradient
inkscape:collect="always"
id="linearGradient3144">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop3146" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop3148" />
</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="perspective2877" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144"
id="radialGradient5114"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144"
id="radialGradient5118"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144"
id="radialGradient5130"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<linearGradient
inkscape:collect="always"
id="linearGradient3144-9-6">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop3146-2-9" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop3148-6-5" />
</linearGradient>
<linearGradient
inkscape:collect="always"
id="linearGradient3144-0">
<stop
style="stop-color:#ffffff;stop-opacity:1;"
offset="0"
id="stop3146-0" />
<stop
style="stop-color:#ffffff;stop-opacity:0;"
offset="1"
id="stop3148-5" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144-0"
id="radialGradient3150-8"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144"
id="radialGradient3166"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144-9-6"
id="radialGradient3209"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144-9-6"
id="radialGradient4003"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144"
id="radialGradient4017"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144-0"
id="radialGradient4019"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(0.75636158,0.04652811,-0.0510977,0.69887118,89.261365,192.11757)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3144"
id="radialGradient4025"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.6985294,0,202.82863)"
cx="225.26402"
cy="672.79736"
fx="225.26402"
fy="672.79736"
r="34.345188" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="5.036384"
inkscape:cx="27.859031"
inkscape:cy="15.084939"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:document-units="px"
inkscape:grid-bbox="true"
inkscape:window-width="1920"
inkscape:window-height="995"
inkscape:window-x="0"
inkscape:window-y="28"
inkscape:window-maximized="1" />
<metadata
id="metadata2874">
<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 />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path2380"
d="M 20.434596,5.9054114 C 1.3429729,8.5126095 1.1495941,43.679445 19.114373,55.187532 l 2.311566,-1.914859 C 5.2121316,39.807692 5.5411295,13.142431 21.649787,9.0127444 z"
style="fill:#008900;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.60815412;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<path
sodipodi:type="arc"
style="fill:#ff2000;fill-opacity:1;stroke:#000000;stroke-width:5.80000019;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path2374"
sodipodi:cx="197.14285"
sodipodi:cy="655.2193"
sodipodi:rx="48.57143"
sodipodi:ry="48.57143"
d="m 245.71428,655.2193 a 48.57143,48.57143 0 1 1 -97.14286,0 48.57143,48.57143 0 1 1 97.14286,0 z"
transform="matrix(0.02723316,0.09867652,-0.09640808,0.02731828,79.829352,-29.616533)" />
<path
sodipodi:type="arc"
style="fill:url(#radialGradient3166);fill-opacity:1;stroke:none"
id="path2376"
sodipodi:cx="225.26402"
sodipodi:cy="672.79736"
sodipodi:rx="34.345188"
sodipodi:ry="23.991123"
d="m 259.60921,672.79736 a 34.345188,23.991123 0 1 1 -68.69038,0 34.345188,23.991123 0 1 1 68.69038,0 z"
transform="matrix(0.0737666,0.06967032,-0.06778387,0.07502926,49.644345,-59.911331)" />
<path
sodipodi:nodetypes="ccccc"
inkscape:connector-curvature="0"
id="path2380-1"
d="M 49.540743,7.6812595 C 30.373736,11.102103 31.82098,45.802988 50.508819,56.357055 L 52.754817,54.36526 C 35.744625,41.802858 34.831504,15.482795 50.913625,10.692633 z"
style="fill:#fce94f;fill-opacity:1;fill-rule:evenodd;stroke:#000000;stroke-width:0.60778022;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate" />
<path
sodipodi:type="arc"
style="fill:#ff2000;fill-opacity:1;stroke:#000000;stroke-width:5.80000019;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
id="path2374-1"
sodipodi:cx="197.14285"
sodipodi:cy="655.2193"
sodipodi:rx="48.57143"
sodipodi:ry="48.57143"
d="m 245.71428,655.2193 a 48.57143,48.57143 0 1 1 -97.14286,0 48.57143,48.57143 0 1 1 97.14286,0 z"
transform="matrix(-0.02682131,-0.09982615,0.09765525,-0.02693812,-37.497841,93.073794)" />
<path
sodipodi:type="arc"
style="fill:url(#radialGradient4019);fill-opacity:1;stroke:none"
id="path2376-9"
sodipodi:cx="225.26402"
sodipodi:cy="672.79736"
sodipodi:rx="34.345188"
sodipodi:ry="23.991123"
d="m 259.60921,672.79736 a 34.345188,23.991123 0 1 1 -68.69038,0 34.345188,23.991123 0 1 1 68.69038,0 z"
transform="matrix(-0.07407035,-0.07084847,0.06906165,-0.0753088,-9.5541356,121.19065)" />
<path
transform="matrix(0.02243113,0.09990701,-0.09763712,0.02240394,109.33184,-26.239796)"
d="m 245.71428,655.2193 a 48.57143,48.57143 0 1 1 -97.14286,0 48.57143,48.57143 0 1 1 97.14286,0 z"
sodipodi:ry="48.57143"
sodipodi:rx="48.57143"
sodipodi:cy="655.2193"
sodipodi:cx="197.14285"
id="path4021"
style="fill:#ff2000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:5.80000019;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
sodipodi:type="arc" />
<path
transform="matrix(0.07032347,0.07329626,-0.07134966,0.07149127,80.367199,-57.312599)"
d="m 259.60921,672.79736 a 34.345188,23.991123 0 1 1 -68.69038,0 34.345188,23.991123 0 1 1 68.69038,0 z"
sodipodi:ry="23.991123"
sodipodi:rx="34.345188"
sodipodi:cy="672.79736"
sodipodi:cx="225.26402"
id="path4023"
style="fill:url(#radialGradient4025);fill-opacity:1;stroke:none"
sodipodi:type="arc" />
<path
sodipodi:type="arc"
style="fill:#ff2000;fill-opacity:1;fill-rule:nonzero;stroke:#000000;stroke-width:5.80000019;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none;stroke-dashoffset:0;marker:none;visibility:visible;display:inline;overflow:visible;enable-background:accumulate"
id="path2339"
sodipodi:cx="197.14285"
sodipodi:cy="655.2193"
sodipodi:rx="48.57143"
sodipodi:ry="48.57143"
d="m 245.71428,655.2193 a 48.57143,48.57143 0 1 1 -97.14286,0 48.57143,48.57143 0 1 1 97.14286,0 z"
transform="matrix(0.02243113,0.09990701,-0.09763712,0.02240394,109.72993,21.376792)" />
<path
sodipodi:type="arc"
style="fill:url(#radialGradient4017);fill-opacity:1;stroke:none"
id="path2341"
sodipodi:cx="225.26402"
sodipodi:cy="672.79736"
sodipodi:rx="34.345188"
sodipodi:ry="23.991123"
d="m 259.60921,672.79736 a 34.345188,23.991123 0 1 1 -68.69038,0 34.345188,23.991123 0 1 1 68.69038,0 z"
transform="matrix(0.07032347,0.07329626,-0.07134966,0.07149127,80.765291,-9.6960118)" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -247,6 +247,7 @@ inline void SketcherAddWorkbenchTools<Gui::MenuItem>(Gui::MenuItem& consaccel){
<< "Sketcher_SelectElementsAssociatedWithConstraints"
<< "Sketcher_RestoreInternalAlignmentGeometry"
<< "Sketcher_Symmetry"
<< "Sketcher_Clone"
<< "Sketcher_Copy"
<< "Sketcher_RectangularArray";
@ -258,7 +259,7 @@ inline void SketcherAddWorkbenchTools<Gui::ToolBarItem>(Gui::ToolBarItem& consac
<< "Sketcher_SelectConstraints"
<< "Sketcher_RestoreInternalAlignmentGeometry"
<< "Sketcher_Symmetry"
<< "Sketcher_Copy"
<< "Sketcher_CompCopy"
<< "Sketcher_RectangularArray";
}