Skip to content

Commit

Permalink
Sketcher: Extension of Copy/Array functionality to clone
Browse files Browse the repository at this point in the history
=============================================================

This commit allows the user to select in advance whether he wants a simple copy or a clone.

This involves substitution of dimensional constraints in the copies by equality and parallel constraints.

Terminology change for Arrays, now it is Rectangular array
  • Loading branch information
abdullahtahiriyo authored and wwmayer committed Aug 30, 2015
1 parent 6ea93a4 commit 97d551b
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 74 deletions.
51 changes: 41 additions & 10 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -2011,7 +2011,7 @@ int SketchObject::addSymmetric(const std::vector<int> &geoIdList, int refGeoId,
return Geometry.getSize()-1;
}

int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3d& displacement, int csize/*=2*/, int rsize/*=1*/,
int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3d& displacement, bool clone /*=false*/, int csize/*=2*/, int rsize/*=1*/,
bool constraindisplacement /*= false*/, double perpscale /*= 1.0*/)
{
const std::vector< Part::Geometry * > &geovals = getInternalGeometry();
Expand Down Expand Up @@ -2153,10 +2153,29 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3

if( (*it)->Second == Constraint::GeoUndef /*&& (*it)->Third == Constraint::GeoUndef*/) {
if( ((*it)->Type != Sketcher::DistanceX && (*it)->Type != Sketcher::DistanceY ) ||
(*it)->FirstPos == Sketcher::none ) { // if it is not a point locking DistanceX/Y
Constraint *constNew = (*it)->clone();
constNew->First = geoIdMap[(*it)->First];
newconstrVals.push_back(constNew);
(*it)->FirstPos == Sketcher::none ) { // if it is not a point locking DistanceX/Y
if (((*it)->Type == Sketcher::DistanceX ||
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Distance ||
(*it)->Type == Sketcher::Radius ) && clone ) {
// Distances on a single Element are mapped to equality constraints in clone mode
Constraint *constNew = (*it)->clone();
constNew->Type = Sketcher::Equal;
constNew->Second = geoIdMap[(*it)->First]; // first is already (*it->First)
newconstrVals.push_back(constNew);
}
else if ((*it)->Type == Sketcher::Angle && clone){
// Angles on a single Element are mapped to parallel constraints in clone mode
Constraint *constNew = (*it)->clone();
constNew->Type = Sketcher::Parallel;
constNew->Second = geoIdMap[(*it)->First]; // first is already (*it->First)
newconstrVals.push_back(constNew);
}
else {
Constraint *constNew = (*it)->clone();
constNew->First = geoIdMap[(*it)->First];
newconstrVals.push_back(constNew);
}
}
}
else { // other geoids intervene in this constraint
Expand All @@ -2165,10 +2184,23 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3

if(sit != geoIdList.end()) { // Second is also in the list
if( (*it)->Third == Constraint::GeoUndef ) {
Constraint *constNew = (*it)->clone();
constNew->First = geoIdMap[(*it)->First];
constNew->Second = geoIdMap[(*it)->Second];
newconstrVals.push_back(constNew);
if (((*it)->Type == Sketcher::DistanceX ||
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Distance) && ((*it)->First == (*it)->Second) && clone ) {
// Distances on a two Elements, which must be points of the same line are mapped to equality constraints in clone mode
Constraint *constNew = (*it)->clone();
constNew->Type = Sketcher::Equal;
constNew->FirstPos = Sketcher::none;
constNew->Second = geoIdMap[(*it)->First]; // first is already (*it->First)
constNew->SecondPos = Sketcher::none;
newconstrVals.push_back(constNew);
}
else {
Constraint *constNew = (*it)->clone();
constNew->First = geoIdMap[(*it)->First];
constNew->Second = geoIdMap[(*it)->Second];
newconstrVals.push_back(constNew);
}
}
else {
std::vector<int>::const_iterator tit=std::find(geoIdList.begin(), geoIdList.end(), (*it)->Third);
Expand All @@ -2188,7 +2220,6 @@ int SketchObject::addCopy(const std::vector<int> &geoIdList, const Base::Vector3
}

// handle inter-geometry constraints
// example: App.ActiveDocument.Sketch.addArray([0,1], App.Vector(150,150,0),3,4,True)
if(constraindisplacement){

// add a construction line
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/SketchObject.h
Expand Up @@ -155,7 +155,7 @@ class SketcherExport SketchObject : public Part::Part2DObject
/// with default parameters adds a copy of the geometric elements displaced by the displacement vector.
/// It creates an array of csize elements in the direction of the displacement vector by rsize elements in the
/// direction perpendicular to the displacement vector, wherein the modulus of this perpendicular vector is scaled by perpscale.
int addCopy(const std::vector<int> &geoIdList, const Base::Vector3d& displacement, int csize=2, int rsize=1, bool constraindisplacement = false, double perpscale = 1.0);
int addCopy(const std::vector<int> &geoIdList, const Base::Vector3d& displacement, bool clone=false, int csize=2, int rsize=1, bool constraindisplacement = false, double perpscale = 1.0);
/// Exposes all internal geometry of an object supporting internal geometry
/*!
* \return -1 on error
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Sketcher/App/SketchObjectPy.xml
Expand Up @@ -142,7 +142,7 @@
<UserDocu>add a copy of geometric objects to the sketch displaced by a vector3d</UserDocu>
</Documentation>
</Methode>
<Methode Name="addArray">
<Methode Name="addRectangularArray">
<Documentation>
<UserDocu>add an array of size cols by rows where each element is a copy of the selected geometric objects displaced by a vector3d in the cols direction and by a vector perpendicular to it in the rows direction</UserDocu>
</Documentation>
Expand Down
15 changes: 10 additions & 5 deletions src/Mod/Sketcher/App/SketchObjectPyImp.cpp
Expand Up @@ -759,6 +759,7 @@ PyObject* SketchObjectPy::addSymmetric(PyObject *args)
PyObject *pcObj;
int refGeoId;
int refPosId = Sketcher::none;

if (!PyArg_ParseTuple(args, "Oi|i", &pcObj, &refGeoId, &refPosId))
return 0;

Expand Down Expand Up @@ -795,8 +796,9 @@ PyObject* SketchObjectPy::addSymmetric(PyObject *args)
PyObject* SketchObjectPy::addCopy(PyObject *args)
{
PyObject *pcObj, *pcVect;
PyObject* clone= Py_False;

if (!PyArg_ParseTuple(args, "OO!", &pcObj, &(Base::VectorPy::Type), &pcVect))
if (!PyArg_ParseTuple(args, "OO!|O!", &pcObj, &(Base::VectorPy::Type), &pcVect, &PyBool_Type, &clone))
return 0;

Base::Vector3d vect = static_cast<Base::VectorPy*>(pcVect)->value();
Expand All @@ -810,7 +812,7 @@ PyObject* SketchObjectPy::addCopy(PyObject *args)
geoIdList.push_back(PyInt_AsLong((*it).ptr()));
}

int ret = this->getSketchObjectPtr()->addCopy(geoIdList,vect) + 1;
int ret = this->getSketchObjectPtr()->addCopy(geoIdList, vect, PyObject_IsTrue(clone) ? true : false) + 1;

if(ret == -1)
throw Py::TypeError("Copy operation unsuccessful!");
Expand All @@ -830,14 +832,16 @@ PyObject* SketchObjectPy::addCopy(PyObject *args)
throw Py::TypeError(error);
}

PyObject* SketchObjectPy::addArray(PyObject *args)
PyObject* SketchObjectPy::addRectangularArray(PyObject *args)
{
PyObject *pcObj, *pcVect;
int rows,cols;
double perpscale=1.0;
PyObject* constraindisplacement= Py_False;
PyObject* clone= Py_False;

if (!PyArg_ParseTuple(args, "OO!ii|O!d", &pcObj, &(Base::VectorPy::Type), &pcVect,&rows,&cols, &PyBool_Type, &constraindisplacement,&perpscale))
if (!PyArg_ParseTuple(args, "OO!O!ii|O!d", &pcObj, &(Base::VectorPy::Type), &pcVect,
&PyBool_Type, &clone, &rows, &cols, &PyBool_Type, &constraindisplacement,&perpscale))
return 0;

Base::Vector3d vect = static_cast<Base::VectorPy*>(pcVect)->value();
Expand All @@ -851,7 +855,8 @@ PyObject* SketchObjectPy::addArray(PyObject *args)
geoIdList.push_back(PyInt_AsLong((*it).ptr()));
}

int ret = this->getSketchObjectPtr()->addCopy(geoIdList,vect,rows,cols, PyObject_IsTrue(constraindisplacement) ? true : false, perpscale) + 1;
int ret = this->getSketchObjectPtr()->addCopy(geoIdList,vect, PyObject_IsTrue(clone) ? true : false,
rows, cols, PyObject_IsTrue(constraindisplacement) ? true : false, perpscale) + 1;

if(ret == -1)
throw Py::TypeError("Copy operation unsuccessful!");
Expand Down
8 changes: 4 additions & 4 deletions src/Mod/Sketcher/Gui/CMakeLists.txt
Expand Up @@ -37,7 +37,7 @@ set(SketcherGui_MOC_HDRS
TaskDlgEditSketch.h
SketchOrientationDialog.h
SketcherSettings.h
SketchLinearArrayDialog.h
SketchRectangularArrayDialog.h
PropertyConstraintListItem.h
)
fc_wrap_cpp(SketcherGui_MOC_SRCS ${SketcherGui_MOC_HDRS})
Expand All @@ -55,7 +55,7 @@ set(SketcherGui_UIC_SRCS
InsertDatum.ui
SketchOrientationDialog.ui
SketcherSettings.ui
SketchLinearArrayDialog.ui
SketchRectangularArrayDialog.ui
)
qt4_wrap_ui(SketcherGui_UIC_HDRS ${SketcherGui_UIC_SRCS})

Expand Down Expand Up @@ -112,8 +112,8 @@ SET(SketcherGui_SRCS
SketchOrientationDialog.h
SketcherSettings.cpp
SketcherSettings.h
SketchLinearArrayDialog.h
SketchLinearArrayDialog.cpp
SketchRectangularArrayDialog.h
SketchRectangularArrayDialog.cpp
TaskDlgEditSketch.cpp
TaskDlgEditSketch.h
ViewProviderPython.cpp
Expand Down
74 changes: 47 additions & 27 deletions src/Mod/Sketcher/Gui/CommandSketcherTools.cpp
Expand Up @@ -28,6 +28,8 @@
# include <Precision.hxx>
#endif

# include <QMessageBox>

#include <Base/Console.h>
#include <App/Application.h>
#include <Gui/Application.h>
Expand All @@ -47,7 +49,7 @@
#include <Mod/Sketcher/App/SketchObject.h>

#include "ViewProviderSketch.h"
#include "SketchLinearArrayDialog.h"
#include "SketchRectangularArrayDialog.h"

using namespace std;
using namespace SketcherGui;
Expand Down Expand Up @@ -1232,8 +1234,8 @@ static const char *cursor_createcopy[]={
class DrawSketchHandlerCopy: public DrawSketchHandler
{
public:
DrawSketchHandlerCopy(string geoidlist, int origingeoid, Sketcher::PointPos originpos, int nelements): geoIdList(geoidlist), OriginGeoId (origingeoid),
OriginPos(originpos), nElements(nelements), Mode(STATUS_SEEK_First), EditCurve(2){}
DrawSketchHandlerCopy(string geoidlist, int origingeoid, Sketcher::PointPos originpos, int nelements, bool clone): geoIdList(geoidlist), OriginGeoId (origingeoid),
OriginPos(originpos), nElements(nelements), Clone(clone), Mode(STATUS_SEEK_First), EditCurve(2){}
virtual ~DrawSketchHandlerCopy(){}
/// mode table
enum SelectMode {
Expand Down Expand Up @@ -1295,10 +1297,10 @@ static const char *cursor_createcopy[]={

try{
Gui::Command::doCommand(
Gui::Command::Doc, "App.ActiveDocument.%s.addCopy(%s,App.Vector(%f,%f,0))",
Gui::Command::Doc, "App.ActiveDocument.%s.addCopy(%s,App.Vector(%f,%f,0),%s)",
sketchgui->getObject()->getNameInDocument(),
geoIdList.c_str(), vector.fX, vector.fY
);
geoIdList.c_str(), vector.fX, vector.fY,
(Clone?"True":"False"));

Gui::Command::commitCommand();
}
Expand Down Expand Up @@ -1332,6 +1334,7 @@ static const char *cursor_createcopy[]={
int OriginGeoId;
Sketcher::PointPos OriginPos;
int nElements;
bool Clone;
std::vector<Base::Vector2D> EditCurve;
std::vector<AutoConstraint> sugConstr1;
};
Expand Down Expand Up @@ -1455,7 +1458,22 @@ void CmdSketcherCopy::activated(int iMsg)
}
}

ActivateAcceleratorHandler(getActiveGuiDocument(),new DrawSketchHandlerCopy(geoIdList, LastGeoId, LastPointPos, geoids));
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"),
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
if (ret == QMessageBox::Yes) {
clone = true;
}
else if (ret == QMessageBox::Cancel) {
// do nothing
return;
}

ActivateAcceleratorHandler(getActiveGuiDocument(),new DrawSketchHandlerCopy(geoIdList, LastGeoId, LastPointPos, geoids, clone));
}


Expand All @@ -1466,7 +1484,7 @@ bool CmdSketcherCopy::isActive(void)
}

/* XPM */
static const char *cursor_createlineararray[]={
static const char *cursor_createrectangulararray[]={
"32 32 3 1",
"+ c white",
"# c red",
Expand Down Expand Up @@ -1504,15 +1522,15 @@ static const char *cursor_createlineararray[]={
"................................",
"................................"};

class DrawSketchHandlerLinearArray: public DrawSketchHandler
class DrawSketchHandlerRectangularArray: public DrawSketchHandler
{
public:
DrawSketchHandlerLinearArray(string geoidlist, int origingeoid, Sketcher::PointPos originpos, int nelements,
int rows,int cols,bool constraintSeparation,
bool equalVerticalHorizontalSpacing ): geoIdList(geoidlist), OriginGeoId (origingeoid),
DrawSketchHandlerRectangularArray(string geoidlist, int origingeoid, Sketcher::PointPos originpos, int nelements, bool clone,
int rows, int cols, bool constraintSeparation,
bool equalVerticalHorizontalSpacing ): geoIdList(geoidlist), OriginGeoId (origingeoid), Clone(clone),
Rows(rows), Cols(cols), ConstraintSeparation(constraintSeparation), EqualVerticalHorizontalSpacing(equalVerticalHorizontalSpacing),
OriginPos(originpos), nElements(nelements), Mode(STATUS_SEEK_First), EditCurve(2){}
virtual ~DrawSketchHandlerLinearArray(){}
virtual ~DrawSketchHandlerRectangularArray(){}
/// mode table
enum SelectMode {
STATUS_SEEK_First, /**< enum value ----. */
Expand All @@ -1521,7 +1539,7 @@ static const char *cursor_createlineararray[]={

virtual void activated(ViewProviderSketch *sketchgui)
{
setCursor(QPixmap(cursor_createlineararray),7,7);
setCursor(QPixmap(cursor_createrectangulararray),7,7);
Origin = static_cast<Sketcher::SketchObject *>(sketchgui->getObject())->getPoint(OriginGeoId, OriginPos);
EditCurve[0] = Base::Vector2D(Origin.x,Origin.y);
}
Expand Down Expand Up @@ -1573,9 +1591,10 @@ static const char *cursor_createlineararray[]={

try{
Gui::Command::doCommand(
Gui::Command::Doc, "App.ActiveDocument.%s.addArray(%s, App.Vector(%f,%f,0),%d,%d,%s,%f)",
Gui::Command::Doc, "App.ActiveDocument.%s.addRectangularArray(%s, App.Vector(%f,%f,0),%s,%d,%d,%s,%f)",
sketchgui->getObject()->getNameInDocument(),
geoIdList.c_str(), vector.fX, vector.fY,
(Clone?"True":"False"),
Cols, Rows,
(ConstraintSeparation?"True":"False"),
(EqualVerticalHorizontalSpacing?1.0:0.5));
Expand Down Expand Up @@ -1612,6 +1631,7 @@ static const char *cursor_createlineararray[]={
int OriginGeoId;
Sketcher::PointPos OriginPos;
int nElements;
bool Clone;
int Rows;
int Cols;
bool ConstraintSeparation;
Expand All @@ -1621,23 +1641,23 @@ static const char *cursor_createlineararray[]={
};


DEF_STD_CMD_A(CmdSketcherLinearArray);
DEF_STD_CMD_A(CmdSketcherRectangularArray);

CmdSketcherLinearArray::CmdSketcherLinearArray()
:Command("Sketcher_LinearArray")
CmdSketcherRectangularArray::CmdSketcherRectangularArray()
:Command("Sketcher_RectangularArray")
{
sAppModule = "Sketcher";
sGroup = QT_TR_NOOP("Sketcher");
sMenuText = QT_TR_NOOP("LinearArray");
sToolTipText = QT_TR_NOOP("Creates a lineararray of the geometry taking as reference the last selected point");
sMenuText = QT_TR_NOOP("Rectangular Array");
sToolTipText = QT_TR_NOOP("Creates an rectangular array pattern of the geometry taking as reference the last selected point");
sWhatsThis = sToolTipText;
sStatusTip = sToolTipText;
sPixmap = "Sketcher_LinearArray";
sPixmap = "Sketcher_RectangularArray";
sAccel = "";
eType = ForEdit;
}

void CmdSketcherLinearArray::activated(int iMsg)
void CmdSketcherRectangularArray::activated(int iMsg)
{
// get the selection
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
Expand Down Expand Up @@ -1741,11 +1761,11 @@ void CmdSketcherLinearArray::activated(int iMsg)
}

// Pop-up asking for values
SketchLinearArrayDialog * slad = new SketchLinearArrayDialog();

SketchRectangularArrayDialog * slad = new SketchRectangularArrayDialog();
if( slad->exec() == QDialog::Accepted )
ActivateAcceleratorHandler(getActiveGuiDocument(),
new DrawSketchHandlerLinearArray(geoIdList, LastGeoId, LastPointPos, geoids,
new DrawSketchHandlerRectangularArray(geoIdList, LastGeoId, LastPointPos, geoids, slad->Clone,
slad->Rows, slad->Cols, slad->ConstraintSeparation,
slad->EqualVerticalHorizontalSpacing));

Expand All @@ -1755,7 +1775,7 @@ void CmdSketcherLinearArray::activated(int iMsg)



bool CmdSketcherLinearArray::isActive(void)
bool CmdSketcherRectangularArray::isActive(void)
{
return isSketcherAcceleratorActive( getActiveGuiDocument(), true );
}
Expand All @@ -1776,5 +1796,5 @@ void CreateSketcherCommandsConstraintAccel(void)
rcCmdMgr.addCommand(new CmdSketcherRestoreInternalAlignmentGeometry());
rcCmdMgr.addCommand(new CmdSketcherSymmetry());
rcCmdMgr.addCommand(new CmdSketcherCopy());
rcCmdMgr.addCommand(new CmdSketcherLinearArray());
rcCmdMgr.addCommand(new CmdSketcherRectangularArray());
}

0 comments on commit 97d551b

Please sign in to comment.