Only enable Commands when appropriate
Remove dupl code
This commit is contained in:
parent
ecbd8c8dc0
commit
f230967146
|
@ -81,6 +81,8 @@ SET(TechDrawGui_SRCS
|
|||
TaskSectionView.ui
|
||||
TaskSectionView.cpp
|
||||
TaskSectionView.h
|
||||
DrawGuiUtil.cpp
|
||||
DrawGuiUtil.h
|
||||
)
|
||||
SET(TechDrawGuiView_SRCS
|
||||
MDIViewPage.cpp
|
||||
|
|
|
@ -65,6 +65,7 @@
|
|||
#include <Mod/TechDraw/App/DrawViewDraft.h>
|
||||
#include <Mod/TechDraw/Gui/QGVPage.h>
|
||||
|
||||
#include "DrawGuiUtil.h"
|
||||
#include "MDIViewPage.h"
|
||||
#include "TaskProjGroup.h"
|
||||
#include "TaskSectionView.h"
|
||||
|
@ -74,60 +75,6 @@ using namespace TechDrawGui;
|
|||
using namespace std;
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// utility routines
|
||||
//===========================================================================
|
||||
|
||||
//! find a DrawPage in Selection or Document
|
||||
//TODO: code is duplicated in CommandCreateDims and CommandDecorate
|
||||
TechDraw::DrawPage* _findPage(Gui::Command* cmd)
|
||||
{
|
||||
//check if a DrawPage is currently displayed
|
||||
auto mdiView( Gui::getMainWindow()->activeWindow() );
|
||||
auto mvp( dynamic_cast<MDIViewPage *>(mdiView) );
|
||||
if (mvp) {
|
||||
return mvp->getQGVPage()->getDrawPage();
|
||||
} else {
|
||||
TechDraw::DrawPage* page(nullptr);
|
||||
|
||||
//DrawPage not displayed, check Selection and/or Document for a DrawPage
|
||||
auto drawPageType( TechDraw::DrawPage::getClassTypeId() );
|
||||
auto selPages( cmd->getSelection().getObjectsOfType(drawPageType) );
|
||||
if (selPages.empty()) { //no page in selection
|
||||
selPages = cmd->getDocument()->getObjectsOfType(drawPageType);
|
||||
if (selPages.empty()) { //no page in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"),
|
||||
QObject::tr("Create a page first."));
|
||||
return page;
|
||||
} else if (selPages.size() > 1) { //multiple pages in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Can not determine correct page."));
|
||||
return page;
|
||||
} else { //use only page in document
|
||||
page = static_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
} else if (selPages.size() > 1) { //multiple pages in selection
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Select exactly 1 page."));
|
||||
return page;
|
||||
} else { //use only page in selection
|
||||
page = static_cast<TechDraw::DrawPage *>(selPages.front());
|
||||
}
|
||||
|
||||
return page;
|
||||
}
|
||||
}
|
||||
|
||||
bool isDrawingPageActive(Gui::Document *doc)
|
||||
{
|
||||
if (doc)
|
||||
// checks if a DrawPage Viewprovider is in Edit and is in no special mode
|
||||
if (doc->getInEdit() && doc->getInEdit()->isDerivedFrom(TechDrawGui::ViewProviderPage::getClassTypeId()))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//===========================================================================
|
||||
// TechDraw_NewPageDef (default template)
|
||||
//===========================================================================
|
||||
|
@ -299,7 +246,7 @@ CmdTechDrawNewView::CmdTechDrawNewView()
|
|||
void CmdTechDrawNewView::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -350,8 +297,7 @@ void CmdTechDrawNewView::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewView::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -375,8 +321,7 @@ CmdTechDrawNewViewSection::CmdTechDrawNewViewSection()
|
|||
void CmdTechDrawNewViewSection::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
//TODO: should just use BaseView's page
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -420,8 +365,13 @@ void CmdTechDrawNewViewSection::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewViewSection::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
bool taskInProgress = false;
|
||||
if (havePage) {
|
||||
taskInProgress = Gui::Control().activeDialog();
|
||||
}
|
||||
return (havePage && haveView && !taskInProgress);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -445,7 +395,7 @@ CmdTechDrawProjGroup::CmdTechDrawProjGroup()
|
|||
void CmdTechDrawProjGroup::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -480,18 +430,18 @@ void CmdTechDrawProjGroup::activated(int iMsg)
|
|||
// create the rest of the desired views
|
||||
Gui::Control().showDialog(new TaskDlgProjGroup(multiView,true));
|
||||
|
||||
// // add the multiView to the page
|
||||
// doCommand(Doc,"App.activeDocument().%s.addView(App.activeDocument().%s)",PageName.c_str(),multiViewName.c_str());
|
||||
|
||||
updateActive();
|
||||
commitCommand();
|
||||
}
|
||||
|
||||
bool CmdTechDrawProjGroup::isActive(void)
|
||||
{
|
||||
if ( !hasActiveDocument() || Gui::Control().activeDialog())
|
||||
return false;
|
||||
return true;
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool taskInProgress = false;
|
||||
if (havePage) {
|
||||
taskInProgress = Gui::Control().activeDialog();
|
||||
}
|
||||
return (havePage && !taskInProgress);
|
||||
}
|
||||
|
||||
|
||||
|
@ -516,7 +466,7 @@ CmdTechDrawAnnotation::CmdTechDrawAnnotation()
|
|||
void CmdTechDrawAnnotation::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -532,7 +482,7 @@ void CmdTechDrawAnnotation::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawAnnotation::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
|
||||
|
@ -557,7 +507,7 @@ CmdTechDrawClip::CmdTechDrawClip()
|
|||
void CmdTechDrawClip::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -577,7 +527,7 @@ void CmdTechDrawClip::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawClip::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -589,7 +539,6 @@ DEF_STD_CMD_A(CmdTechDrawClipPlus);
|
|||
CmdTechDrawClipPlus::CmdTechDrawClipPlus()
|
||||
: Command("TechDraw_ClipPlus")
|
||||
{
|
||||
// seting the
|
||||
sGroup = QT_TR_NOOP("TechDraw");
|
||||
sMenuText = QT_TR_NOOP("&ClipPlus");
|
||||
sToolTipText = QT_TR_NOOP("Add a View to a clip group in the active drawing");
|
||||
|
@ -601,12 +550,12 @@ CmdTechDrawClipPlus::CmdTechDrawClipPlus()
|
|||
void CmdTechDrawClipPlus::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
if (selection.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select 1 DrawViewClip and 1 DrawView."));
|
||||
return;
|
||||
}
|
||||
std::vector<Gui::SelectionObject> selection = getSelection().getSelectionEx();
|
||||
if (selection.size() != 2) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Wrong selection"),
|
||||
QObject::tr("Select 1 DrawViewClip and 1 DrawView."));
|
||||
return;
|
||||
}
|
||||
|
||||
TechDraw::DrawViewClip* clip = 0;
|
||||
TechDraw::DrawView* view = 0;
|
||||
|
@ -657,7 +606,16 @@ void CmdTechDrawClipPlus::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawClipPlus::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveClip = false;
|
||||
if (havePage) {
|
||||
auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() );
|
||||
auto selClips = getDocument()->getObjectsOfType(drawClipType);
|
||||
if (!selClips.empty()) {
|
||||
haveClip = true;
|
||||
}
|
||||
}
|
||||
return (havePage && haveClip);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -721,7 +679,16 @@ void CmdTechDrawClipMinus::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawClipMinus::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveClip = false;
|
||||
if (havePage) {
|
||||
auto drawClipType( TechDraw::DrawViewClip::getClassTypeId() );
|
||||
auto selClips = getDocument()->getObjectsOfType(drawClipType);
|
||||
if (!selClips.empty()) {
|
||||
haveClip = true;
|
||||
}
|
||||
}
|
||||
return (havePage && haveClip);
|
||||
}
|
||||
|
||||
|
||||
|
@ -746,7 +713,7 @@ CmdTechDrawSymbol::CmdTechDrawSymbol()
|
|||
void CmdTechDrawSymbol::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -772,7 +739,7 @@ void CmdTechDrawSymbol::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawSymbol::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -796,7 +763,7 @@ CmdTechDrawDraftView::CmdTechDrawDraftView()
|
|||
void CmdTechDrawDraftView::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -823,7 +790,7 @@ void CmdTechDrawDraftView::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawDraftView::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -855,7 +822,7 @@ void CmdTechDrawSpreadsheet::activated(int iMsg)
|
|||
}
|
||||
std::string SpreadName = spreads.front()->getNameInDocument();
|
||||
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -872,7 +839,17 @@ void CmdTechDrawSpreadsheet::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawSpreadsheet::isActive(void)
|
||||
{
|
||||
return (getActiveGuiDocument() ? true : false);
|
||||
//need a Page and a SpreadSheet::Sheet
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveSheet = false;
|
||||
if (havePage) {
|
||||
auto spreadSheetType( Spreadsheet::Sheet::getClassTypeId() );
|
||||
auto selSheets = getDocument()->getObjectsOfType(spreadSheetType);
|
||||
if (!selSheets.empty()) {
|
||||
haveSheet = true;
|
||||
}
|
||||
}
|
||||
return (havePage && haveSheet);
|
||||
}
|
||||
|
||||
|
||||
|
@ -896,7 +873,7 @@ CmdTechDrawExportPage::CmdTechDrawExportPage()
|
|||
void CmdTechDrawExportPage::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPage(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -917,7 +894,7 @@ void CmdTechDrawExportPage::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawExportPage::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
return DrawGuiUtil::needPage(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
# include <App/DocumentObject.h>
|
||||
# include <Base/Exception.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Type.h>
|
||||
# include <Gui/Action.h>
|
||||
# include <Gui/Application.h>
|
||||
# include <Gui/BitmapFactory.h>
|
||||
|
@ -58,8 +60,9 @@
|
|||
#include <Mod/TechDraw/Gui/QGVPage.h>
|
||||
|
||||
|
||||
# include "MDIViewPage.h"
|
||||
# include "ViewProviderPage.h"
|
||||
#include "DrawGuiUtil.h"
|
||||
#include "MDIViewPage.h"
|
||||
#include "ViewProviderPage.h"
|
||||
#include "TaskLinkDim.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
@ -69,44 +72,6 @@ using namespace std;
|
|||
// utility routines
|
||||
//===========================================================================
|
||||
|
||||
//TODO: still need this as separate routine? only used in LinkDimension now
|
||||
//TODO: code is duplicated in Command and CommandDecorate
|
||||
TechDraw::DrawPage* _findPageCCD(Gui::Command* cmd)
|
||||
{
|
||||
TechDraw::DrawPage* page = 0;
|
||||
//check if a DrawPage is currently displayed
|
||||
Gui::MainWindow* w = Gui::getMainWindow();
|
||||
Gui::MDIView* mv = w->activeWindow();
|
||||
MDIViewPage* mvp = dynamic_cast<MDIViewPage*>(mv);
|
||||
if (mvp) {
|
||||
QGVPage* qp = mvp->getQGVPage();
|
||||
page = qp->getDrawPage();
|
||||
} else {
|
||||
//DrawPage not displayed, check Selection and/or Document for a DrawPage
|
||||
std::vector<App::DocumentObject*> selPages = cmd->getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (selPages.empty()) { //no page in selection
|
||||
selPages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (selPages.empty()) { //no page in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"),
|
||||
QObject::tr("Create a page first."));
|
||||
return page;
|
||||
} else if (selPages.size() > 1) { //multiple pages in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Can not determine correct page."));
|
||||
return page;
|
||||
} else { //use only page in document
|
||||
page = static_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
} else if (selPages.size() > 1) { //multiple pages in selection
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Select exactly 1 page."));
|
||||
return page;
|
||||
} else { //use only page in selection
|
||||
page = static_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
//internal functions
|
||||
bool _checkSelection(Gui::Command* cmd, unsigned maxObjs = 2);
|
||||
|
@ -116,6 +81,7 @@ int _isValidSingleEdge(Gui::Command* cmd);
|
|||
bool _isValidVertexes(Gui::Command* cmd);
|
||||
int _isValidEdgeToEdge(Gui::Command* cmd);
|
||||
bool _isValidVertexToEdge(Gui::Command* cmd);
|
||||
//bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs);
|
||||
|
||||
enum EdgeType{
|
||||
isInvalid,
|
||||
|
@ -260,8 +226,9 @@ void CmdTechDrawNewDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -348,8 +315,9 @@ void CmdTechDrawNewRadiusDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewRadiusDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -438,8 +406,9 @@ void CmdTechDrawNewDiameterDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewDiameterDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -546,8 +515,9 @@ void CmdTechDrawNewLengthDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewLengthDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -652,8 +622,9 @@ void CmdTechDrawNewDistanceXDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewDistanceXDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -757,8 +728,9 @@ void CmdTechDrawNewDistanceYDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewDistanceYDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -844,8 +816,9 @@ void CmdTechDrawNewAngleDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewAngleDimension::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//! link 3D geometry to Dimension(s) on a Page
|
||||
|
@ -871,7 +844,7 @@ CmdTechDrawLinkDimension::CmdTechDrawLinkDimension()
|
|||
void CmdTechDrawLinkDimension::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPageCCD(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -907,7 +880,13 @@ void CmdTechDrawLinkDimension::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawLinkDimension::isActive(void)
|
||||
{
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
bool taskInProgress = false;
|
||||
if (havePage) {
|
||||
taskInProgress = Gui::Control().activeDialog();
|
||||
}
|
||||
return (havePage && haveView && !taskInProgress);
|
||||
}
|
||||
|
||||
void CreateTechDrawCommandsDims(void)
|
||||
|
@ -1133,3 +1112,24 @@ bool _isValidVertexToEdge(Gui::Command* cmd) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
//bool _checkActive(Gui::Command* cmd, Base::Type classType, bool needSubs)
|
||||
//{
|
||||
// //need a page, a selected classType and [a subelement]
|
||||
// bool active = false;
|
||||
// if (cmd->hasActiveDocument()) {
|
||||
// auto drawPageType( TechDraw::DrawPage::getClassTypeId() );
|
||||
// auto selPages = cmd->getDocument()->getObjectsOfType(drawPageType);
|
||||
// if (!selPages.empty()) {
|
||||
// std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
// for (auto& s:selection) {
|
||||
// if (s.getObject()->isDerivedFrom(classType)) {
|
||||
// if (needSubs && !(s.getSubNames().empty())) {
|
||||
// active = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return active;
|
||||
//}
|
||||
|
|
|
@ -53,53 +53,13 @@
|
|||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
#include <Mod/TechDraw/Gui/QGVPage.h>
|
||||
|
||||
# include "MDIViewPage.h"
|
||||
# include "ViewProviderPage.h"
|
||||
#include "DrawGuiUtil.h"
|
||||
#include "MDIViewPage.h"
|
||||
#include "ViewProviderPage.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
using namespace std;
|
||||
|
||||
//===========================================================================
|
||||
// utility routines
|
||||
//===========================================================================
|
||||
|
||||
//TODO: code is duplicated in Command and CommandCreateDims
|
||||
TechDraw::DrawPage* _findPageCD(Gui::Command* cmd)
|
||||
{
|
||||
TechDraw::DrawPage* page = 0;
|
||||
//check if a DrawPage is currently displayed
|
||||
Gui::MainWindow* w = Gui::getMainWindow();
|
||||
Gui::MDIView* mv = w->activeWindow();
|
||||
MDIViewPage* mvp = dynamic_cast<MDIViewPage*>(mv);
|
||||
if (mvp) {
|
||||
QGVPage* qp = mvp->getQGVPage();
|
||||
page = qp->getDrawPage();
|
||||
} else {
|
||||
//DrawPage not displayed, check Selection and/or Document for a DrawPage
|
||||
std::vector<App::DocumentObject*> selPages = cmd->getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (selPages.empty()) { //no page in selection
|
||||
selPages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (selPages.empty()) { //no page in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"),
|
||||
QObject::tr("Create a page first."));
|
||||
return page;
|
||||
} else if (selPages.size() > 1) { //multiple pages in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Can not determine correct page."));
|
||||
return page;
|
||||
} else { //use only page in document
|
||||
page = dynamic_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
} else if (selPages.size() > 1) { //multiple pages in selection
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Select exactly 1 page."));
|
||||
return page;
|
||||
} else { //use only page in selection
|
||||
page = dynamic_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
//internal functions
|
||||
bool _checkSelectionHatch(Gui::Command* cmd);
|
||||
|
@ -161,8 +121,9 @@ void CmdTechDrawNewHatch::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawNewHatch::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a part selected?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
//===========================================================================
|
||||
|
@ -186,7 +147,7 @@ CmdTechDrawToggleFrame::CmdTechDrawToggleFrame()
|
|||
void CmdTechDrawToggleFrame::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
TechDraw::DrawPage* page = _findPageCD(this);
|
||||
TechDraw::DrawPage* page = DrawGuiUtil::findPage(this);
|
||||
if (!page) {
|
||||
return;
|
||||
}
|
||||
|
@ -207,8 +168,9 @@ void CmdTechDrawToggleFrame::activated(int iMsg)
|
|||
|
||||
bool CmdTechDrawToggleFrame::isActive(void)
|
||||
{
|
||||
// TODO: Also ensure that there's a page displayed?
|
||||
return hasActiveDocument();
|
||||
bool havePage = DrawGuiUtil::needPage(this);
|
||||
bool haveView = DrawGuiUtil::needView(this);
|
||||
return (havePage && haveView);
|
||||
}
|
||||
|
||||
void CreateTechDrawCommandsDecorate(void)
|
||||
|
@ -227,14 +189,14 @@ bool _checkSelectionHatch(Gui::Command* cmd) {
|
|||
std::vector<Gui::SelectionObject> selection = cmd->getSelection().getSelectionEx();
|
||||
if (selection.size() == 0) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
|
||||
QObject::tr("Select an object first"));
|
||||
QObject::tr("Select a Face first"));
|
||||
return false;
|
||||
}
|
||||
|
||||
TechDraw::DrawViewPart * objFeat = dynamic_cast<TechDraw::DrawViewPart *>(selection[0].getObject());
|
||||
if(!objFeat) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect selection"),
|
||||
QObject::tr("No Feature in selection"));
|
||||
QObject::tr("No TechDraw object in selection"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -246,10 +208,15 @@ bool _checkSelectionHatch(Gui::Command* cmd) {
|
|||
}
|
||||
|
||||
const std::vector<std::string> &SubNames = selection[0].getSubNames();
|
||||
if (SubNames.empty()) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
|
||||
QObject::tr("Can't make a Hatched area from this selection"));
|
||||
return false;
|
||||
}
|
||||
std::string gType = TechDraw::DrawUtil::getGeomTypeFromName(SubNames.at(0));
|
||||
if (!(gType == "Face")) {
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Incorrect Selection"),
|
||||
QObject::tr("Can't make a Hatched area from this selection"));
|
||||
QObject::tr("No Face in this selection"));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
135
src/Mod/TechDraw/Gui/DrawGuiUtil.cpp
Normal file
135
src/Mod/TechDraw/Gui/DrawGuiUtil.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <sstream>
|
||||
# include <cstring>
|
||||
# include <cstdlib>
|
||||
# include <exception>
|
||||
# include <boost/regex.hpp>
|
||||
# include <QString>
|
||||
# include <QStringList>
|
||||
# include <QRegExp>
|
||||
# include <QMessageBox>
|
||||
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/Document.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <App/FeaturePython.h>
|
||||
#include <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Base/Type.h>
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Control.h>
|
||||
#include <Gui/Document.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/Part/App/Part2DObject.h>
|
||||
#include <Mod/Spreadsheet/App/Sheet.h>
|
||||
|
||||
#include <Mod/TechDraw/App/DrawPage.h>
|
||||
#include <Mod/TechDraw/App/DrawViewPart.h>
|
||||
#include <Mod/TechDraw/App/DrawUtil.h>
|
||||
#include <Mod/TechDraw/App/Geometry.h>
|
||||
|
||||
#include "QGVPage.h"
|
||||
#include "MDIViewPage.h"
|
||||
#include "ViewProviderPage.h"
|
||||
#include "DrawGuiUtil.h"
|
||||
|
||||
using namespace TechDrawGui;
|
||||
|
||||
//===========================================================================
|
||||
// validate helper routines
|
||||
//===========================================================================
|
||||
TechDraw::DrawPage* DrawGuiUtil::findPage(Gui::Command* cmd)
|
||||
{
|
||||
TechDraw::DrawPage* page = 0;
|
||||
//check if a DrawPage is currently displayed
|
||||
Gui::MainWindow* w = Gui::getMainWindow();
|
||||
Gui::MDIView* mv = w->activeWindow();
|
||||
MDIViewPage* mvp = dynamic_cast<MDIViewPage*>(mv);
|
||||
if (mvp) {
|
||||
QGVPage* qp = mvp->getQGVPage();
|
||||
page = qp->getDrawPage();
|
||||
} else {
|
||||
//DrawPage not displayed, check Selection and/or Document for a DrawPage
|
||||
std::vector<App::DocumentObject*> selPages = cmd->getSelection().getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (selPages.empty()) { //no page in selection
|
||||
selPages = cmd->getDocument()->getObjectsOfType(TechDraw::DrawPage::getClassTypeId());
|
||||
if (selPages.empty()) { //no page in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("No page found"),
|
||||
QObject::tr("Create a page first."));
|
||||
return page;
|
||||
} else if (selPages.size() > 1) { //multiple pages in document
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Can not determine correct page."));
|
||||
return page;
|
||||
} else { //use only page in document
|
||||
page = static_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
} else if (selPages.size() > 1) { //multiple pages in selection
|
||||
QMessageBox::warning(Gui::getMainWindow(), QObject::tr("Too many pages"),
|
||||
QObject::tr("Select exactly 1 page."));
|
||||
return page;
|
||||
} else { //use only page in selection
|
||||
page = static_cast<TechDraw::DrawPage*>(selPages.front());
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
bool DrawGuiUtil::needPage(Gui::Command* cmd)
|
||||
{
|
||||
//need a Document and a Page
|
||||
bool active = false;
|
||||
if (cmd->hasActiveDocument()) {
|
||||
auto drawPageType( TechDraw::DrawPage::getClassTypeId() );
|
||||
auto selPages = cmd->getDocument()->getObjectsOfType(drawPageType);
|
||||
if (!selPages.empty()) {
|
||||
active = true;
|
||||
}
|
||||
}
|
||||
return active;
|
||||
}
|
||||
|
||||
bool DrawGuiUtil::needView(Gui::Command* cmd)
|
||||
{
|
||||
bool haveView = false;
|
||||
if (cmd->hasActiveDocument()) {
|
||||
auto drawPartType (TechDraw::DrawViewPart::getClassTypeId());
|
||||
auto selParts = cmd->getDocument()->getObjectsOfType(drawPartType);
|
||||
if (!selParts.empty()) {
|
||||
haveView = true;
|
||||
}
|
||||
}
|
||||
return haveView;
|
||||
}
|
40
src/Mod/TechDraw/Gui/DrawGuiUtil.h
Normal file
40
src/Mod/TechDraw/Gui/DrawGuiUtil.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
/***************************************************************************
|
||||
* Copyright (c) 2016 WandererFan <wandererfan@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef _DrawGuiUtil_h_
|
||||
#define _DrawGuiUtil_h_
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace TechDrawGui
|
||||
{
|
||||
|
||||
/// Convenient utility functions for TechDraw Gui Module
|
||||
class TechDrawExport DrawGuiUtil {
|
||||
public:
|
||||
static TechDraw::DrawPage* findPage(Gui::Command* cmd);
|
||||
static bool needPage(Gui::Command* cmd);
|
||||
static bool needView(Gui::Command* cmd);
|
||||
};
|
||||
|
||||
} //end namespace TechDrawGui
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user