Gui: allow SelectionSingleton::hasSubSelection() check for sub-element
This is used by relative link command activation for sub-element selection
This commit is contained in:
@@ -197,7 +197,7 @@ void StdCmdLinkMakeGroup::activated(int option) {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEF_STD_CMD(StdCmdLinkMake)
|
||||
DEF_STD_CMD_A(StdCmdLinkMake)
|
||||
|
||||
StdCmdLinkMake::StdCmdLinkMake()
|
||||
: Command("Std_LinkMake")
|
||||
@@ -211,6 +211,10 @@ StdCmdLinkMake::StdCmdLinkMake()
|
||||
sPixmap = "Link";
|
||||
}
|
||||
|
||||
bool StdCmdLinkMake::isActive() {
|
||||
return !!App::GetApplication().getActiveDocument();
|
||||
}
|
||||
|
||||
void StdCmdLinkMake::activated(int) {
|
||||
auto doc = App::GetApplication().getActiveDocument();
|
||||
if(!doc) {
|
||||
@@ -263,7 +267,7 @@ StdCmdLinkMakeRelative::StdCmdLinkMakeRelative()
|
||||
{
|
||||
sGroup = QT_TR_NOOP("Link");
|
||||
sMenuText = QT_TR_NOOP("Make relative link");
|
||||
sToolTipText = QT_TR_NOOP("Create a relative link of two selected objects");
|
||||
sToolTipText = QT_TR_NOOP("Create a sub-object or sub-element link");
|
||||
sWhatsThis = "Std_LinkMakeRelative";
|
||||
sStatusTip = sToolTipText;
|
||||
eType = AlterDoc;
|
||||
@@ -271,7 +275,7 @@ StdCmdLinkMakeRelative::StdCmdLinkMakeRelative()
|
||||
}
|
||||
|
||||
bool StdCmdLinkMakeRelative::isActive() {
|
||||
return Selection().hasSubSelection();
|
||||
return Selection().hasSubSelection(0,true);
|
||||
}
|
||||
|
||||
void StdCmdLinkMakeRelative::activated(int) {
|
||||
|
||||
@@ -437,7 +437,7 @@ bool SelectionSingleton::hasSelection(const char* doc, bool resolve) const
|
||||
return false;
|
||||
}
|
||||
|
||||
bool SelectionSingleton::hasSubSelection(const char* doc) const
|
||||
bool SelectionSingleton::hasSubSelection(const char* doc, bool subElement) const
|
||||
{
|
||||
App::Document *pcDoc = 0;
|
||||
if(!doc || strcmp(doc,"*")!=0) {
|
||||
@@ -446,11 +446,14 @@ bool SelectionSingleton::hasSubSelection(const char* doc) const
|
||||
return false;
|
||||
}
|
||||
for(auto &sel : _SelList) {
|
||||
if((!pcDoc || pcDoc == sel.pDoc)
|
||||
&& sel.pObject != sel.pResolvedObject)
|
||||
{
|
||||
if(pcDoc && pcDoc != sel.pDoc)
|
||||
continue;
|
||||
if(sel.SubName.empty())
|
||||
continue;
|
||||
if(subElement && sel.SubName.back()!='.')
|
||||
return true;
|
||||
if(sel.pObject != sel.pResolvedObject)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1794,7 +1797,7 @@ PyMethodDef SelectionSingleton::Methods[] = {
|
||||
{"hasSelection", (PyCFunction) SelectionSingleton::sHasSelection, METH_VARARGS,
|
||||
"hasSelection(docName=None, resolve=False) -- check if there is any selection\n"},
|
||||
{"hasSubSelection", (PyCFunction) SelectionSingleton::sHasSubSelection, METH_VARARGS,
|
||||
"hasSubSelection(docName=None) -- check if there is any selection with subname\n"},
|
||||
"hasSubSelection(docName=None,subElement=False) -- check if there is any selection with subname\n"},
|
||||
{"getSelectionFromStack",(PyCFunction) SelectionSingleton::sGetSelectionFromStack, METH_VARARGS,
|
||||
"getSelectionFromStack(docName=None,resolve=1,index=0) -- Return a list of SelectionObjects from selection stack\n"
|
||||
"\ndocName - document name. None means the active document, and '*' means all document"
|
||||
@@ -2271,11 +2274,13 @@ PyObject *SelectionSingleton::sHasSelection(PyObject * /*self*/, PyObject *args)
|
||||
PyObject *SelectionSingleton::sHasSubSelection(PyObject * /*self*/, PyObject *args)
|
||||
{
|
||||
const char *doc = 0;
|
||||
if (!PyArg_ParseTuple(args, "|s",&doc))
|
||||
PyObject *subElement = Py_False;
|
||||
if (!PyArg_ParseTuple(args, "|sO!",&doc,&PyBool_Type,&subElement))
|
||||
return NULL; // NULL triggers exception
|
||||
|
||||
PY_TRY {
|
||||
return Py::new_reference_to(Py::Boolean(Selection().hasSubSelection(doc)));
|
||||
return Py::new_reference_to(
|
||||
Py::Boolean(Selection().hasSubSelection(doc,PyObject_IsTrue(subElement))));
|
||||
} PY_CATCH;
|
||||
}
|
||||
|
||||
|
||||
@@ -506,7 +506,19 @@ public:
|
||||
std::vector<SelObj> getCompleteSelection(int resolve=1) const;
|
||||
bool hasSelection() const;
|
||||
bool hasSelection(const char* doc, bool resolve=true) const;
|
||||
bool hasSubSelection(const char *doc=0) const;
|
||||
|
||||
/** Check if there is any sub-element selection
|
||||
*
|
||||
* @param doc: optional document to check for selection
|
||||
* @param subElement: whether to count sub-element only selection
|
||||
*
|
||||
* Example sub selections are face, edge or vertex. If \c resolve is false,
|
||||
* then sub-object (i.e. a group child object) selection is also counted
|
||||
* even if it selects the whole sub-object.
|
||||
*/
|
||||
bool hasSubSelection(const char *doc=0, bool subElement=false) const;
|
||||
|
||||
/// Check if there is any pre-selection
|
||||
bool hasPreselection() const;
|
||||
|
||||
/// Size of selected entities for all documents
|
||||
|
||||
Reference in New Issue
Block a user